[clang] [llvm] [clang] Add "debug_transparent" attribute (PR #109490)
@@ -109,6 +110,21 @@ static bool IsArtificial(VarDecl const *VD) { cast(VD->getDeclContext())->isImplicit()); } +static bool usesDebugTransparent(const Decl *D, const CodeGenModule &CGM) { + if (!D) +return false; + + if (auto *attr = D->getAttr()) { Michael137 wrote: ah right, missed that https://github.com/llvm/llvm-project/pull/109490 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][RISCV] Introduce command line options for RISC-V Zicfilp CFI (PR #109784)
https://github.com/kito-cheng approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/109784 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][RISCV] Introduce command line options for RISC-V Zicfilp CFI (PR #109784)
mylai-mtk wrote: > Could you update this PR? > https://github.com/llvm/llvm-project/commit/4579272e057e6ec77a2a660384080e1f57a17cf0 > is generally LGTM, but I assume this should process within this PR :) Sure, I'm just a few minutes behind you XD https://github.com/llvm/llvm-project/pull/109784 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] Fix installation w/ ENABLE_RUNTIME_SUBNORMAL (PR #109926)
@@ -221,8 +221,10 @@ if( ENABLE_RUNTIME_SUBNORMAL ) TARGET ${file} INPUTS ${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/${file}.ll ) -install( FILES $ ARCHIVE - DESTINATION "${CMAKE_INSTALL_DATADIR}/clc" ) +install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/$ frasercrmck wrote: It doesn't appear to work ``` Target "subnormal_disable" is not an executable or library. ``` I think this section of the documentation alludes to this: ``` quote These expressions look up information about artifacts associated with a given target tgt. Unless otherwise stated, this can be any runtime artifact, namely: * An executable target created by add_executable(). * A shared library target (.so, .dll but not their .lib import library) created by add_library(). * A static library target created by add_library(). ``` These files are created by `add_custom_command`. That might be why we create our own `TARGET_FILE` property on these targets, to mimic this built-in `TARGET_FILE` behaviour? https://github.com/llvm/llvm-project/pull/109926 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] Fix installation w/ ENABLE_RUNTIME_SUBNORMAL (PR #109926)
@@ -221,8 +221,10 @@ if( ENABLE_RUNTIME_SUBNORMAL ) TARGET ${file} INPUTS ${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/${file}.ll ) -install( FILES $ ARCHIVE - DESTINATION "${CMAKE_INSTALL_DATADIR}/clc" ) +install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/$ frasercrmck wrote: Arguably we should set `TARGET_FILE` on the absolute path to the targets' files, but I can't foresee what knock-on impacts this would have. https://github.com/llvm/llvm-project/pull/109926 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][RISCV] Add preprocessor macros for Zicfilp CFI scheme (PR #109600)
https://github.com/mylai-mtk updated https://github.com/llvm/llvm-project/pull/109600 >From 4579272e057e6ec77a2a660384080e1f57a17cf0 Mon Sep 17 00:00:00 2001 From: Ming-Yi Lai Date: Wed, 4 Sep 2024 18:40:48 +0800 Subject: [PATCH 1/2] [clang][RISCV] Introduce command line options for Zicfilp-backed forward-edge CFI This patch enables the following command line flags for RISC-V targets: + `-fcf-protection=branch` turns on forward-edge control-flow integrity conditioning on RISC-V targets with Zicfilp extension + `-mcf-branch-label-scheme=unlabeled|func-sig` selects the label scheme used in the forward-edge CFI conditioning --- .../clang/Basic/CFProtectionOptions.def | 15 .../include/clang/Basic/CFProtectionOptions.h | 38 clang/include/clang/Basic/CodeGenOptions.def | 2 + clang/include/clang/Basic/CodeGenOptions.h| 1 + clang/include/clang/Basic/LangOptions.def | 2 + clang/include/clang/Basic/LangOptions.h | 2 + clang/include/clang/Basic/TargetInfo.h| 8 ++ clang/include/clang/Driver/Options.td | 4 + clang/lib/Basic/TargetInfo.cpp| 15 clang/lib/Basic/Targets/RISCV.h | 22 + clang/lib/CodeGen/CodeGenModule.cpp | 10 +++ clang/lib/Driver/ToolChains/Clang.cpp | 4 + clang/lib/Frontend/CompilerInvocation.cpp | 40 + .../test/CodeGen/RISCV/riscv-cf-protection.c | 86 +++ 14 files changed, 249 insertions(+) create mode 100644 clang/include/clang/Basic/CFProtectionOptions.def create mode 100644 clang/include/clang/Basic/CFProtectionOptions.h create mode 100644 clang/test/CodeGen/RISCV/riscv-cf-protection.c diff --git a/clang/include/clang/Basic/CFProtectionOptions.def b/clang/include/clang/Basic/CFProtectionOptions.def new file mode 100644 index 00..b9df2de7f7eba0 --- /dev/null +++ b/clang/include/clang/Basic/CFProtectionOptions.def @@ -0,0 +1,15 @@ +//===-- CFProtectionOptions.def - cf-protection options -*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + + +#ifdef CF_BRANCH_LABEL_SCHEME +CF_BRANCH_LABEL_SCHEME(Unlabeled, unlabeled) +CF_BRANCH_LABEL_SCHEME(FuncSig, func-sig) + +#undef CF_BRANCH_LABEL_SCHEME +#endif // #ifdef CF_BRANCH_LABEL_SCHEME diff --git a/clang/include/clang/Basic/CFProtectionOptions.h b/clang/include/clang/Basic/CFProtectionOptions.h new file mode 100644 index 00..13f46d4c13e7e7 --- /dev/null +++ b/clang/include/clang/Basic/CFProtectionOptions.h @@ -0,0 +1,38 @@ +//===--- CFProtectionOptions.h --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// This file defines constants for -fcf-protection and other related flags. +// +//===--===// + +#ifndef LLVM_CLANG_BASIC_CFPROTECTIONOPTIONS_H +#define LLVM_CLANG_BASIC_CFPROTECTIONOPTIONS_H + +#include "llvm/Support/ErrorHandling.h" + +namespace clang { + +enum class CFBranchLabelSchemeKind { + Default, +#define CF_BRANCH_LABEL_SCHEME(Kind, FlagVal) Kind, +#include "clang/Basic/CFProtectionOptions.def" +}; + +static inline const char * +getCFBranchLabelSchemeFlagVal(const CFBranchLabelSchemeKind Scheme) { +#define CF_BRANCH_LABEL_SCHEME(Kind, FlagVal) \ + if (Scheme == CFBranchLabelSchemeKind::Kind) \ +return #FlagVal; +#include "clang/Basic/CFProtectionOptions.def" + + llvm::report_fatal_error("invalid scheme"); +} + +} // namespace clang + +#endif // #ifndef LLVM_CLANG_BASIC_CFPROTECTIONOPTIONS_H diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def index b600198998d85b..de7ae73f8a603b 100644 --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -110,6 +110,8 @@ CODEGENOPT(CFProtectionReturn , 1, 0) ///< if -fcf-protection is ///< set to full or return. CODEGENOPT(CFProtectionBranch , 1, 0) ///< if -fcf-protection is ///< set to full or branch. +ENUM_CODEGENOPT(CFBranchLabelScheme, CFBranchLabelSchemeKind, 2, +CFBranchLabelSchemeKind::Default) ///< if -mcf-branch-label-scheme is set. CODEGENOPT(FunctionReturnThunks, 1, 0) ///< -mfunction-return={keep|thunk-extern} CODEGENOPT(IndirectBranchCSPrefix, 1, 0) ///< if -mindirect-branch-cs-prefix
[clang] [Clang][RISCV] Add preprocessor macros for Zicfilp CFI scheme (PR #109600)
mylai-mtk wrote: Update: Always support `-fcf-protection=branch` for RISC-V targets https://github.com/llvm/llvm-project/pull/109600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][RISCV] Add preprocessor macros for Zicfilp CFI scheme (PR #109600)
https://github.com/mylai-mtk updated https://github.com/llvm/llvm-project/pull/109600 >From 1a0aed20421b58114332975ad7d7fff90a21014a Mon Sep 17 00:00:00 2001 From: Ming-Yi Lai Date: Wed, 4 Sep 2024 18:40:48 +0800 Subject: [PATCH 1/2] [clang][RISCV] Introduce command line options for Zicfilp-backed forward-edge CFI This patch enables the following command line flags for RISC-V targets: + `-fcf-protection=branch` turns on forward-edge control-flow integrity conditioning on RISC-V targets with Zicfilp extension + `-mcf-branch-label-scheme=unlabeled|func-sig` selects the label scheme used in the forward-edge CFI conditioning --- .../clang/Basic/CFProtectionOptions.def | 15 +++ .../include/clang/Basic/CFProtectionOptions.h | 38 clang/include/clang/Basic/CodeGenOptions.def | 2 + clang/include/clang/Basic/CodeGenOptions.h| 1 + clang/include/clang/Basic/LangOptions.def | 2 + clang/include/clang/Basic/LangOptions.h | 2 + clang/include/clang/Basic/TargetInfo.h| 8 ++ clang/include/clang/Driver/Options.td | 4 + clang/lib/Basic/TargetInfo.cpp| 15 +++ clang/lib/Basic/Targets/RISCV.h | 22 + clang/lib/CodeGen/CodeGenModule.cpp | 10 ++ clang/lib/Driver/ToolChains/Clang.cpp | 4 + clang/lib/Frontend/CompilerInvocation.cpp | 40 .../test/CodeGen/RISCV/riscv-cf-protection.c | 94 +++ 14 files changed, 257 insertions(+) create mode 100644 clang/include/clang/Basic/CFProtectionOptions.def create mode 100644 clang/include/clang/Basic/CFProtectionOptions.h create mode 100644 clang/test/CodeGen/RISCV/riscv-cf-protection.c diff --git a/clang/include/clang/Basic/CFProtectionOptions.def b/clang/include/clang/Basic/CFProtectionOptions.def new file mode 100644 index 00..b9df2de7f7eba0 --- /dev/null +++ b/clang/include/clang/Basic/CFProtectionOptions.def @@ -0,0 +1,15 @@ +//===-- CFProtectionOptions.def - cf-protection options -*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + + +#ifdef CF_BRANCH_LABEL_SCHEME +CF_BRANCH_LABEL_SCHEME(Unlabeled, unlabeled) +CF_BRANCH_LABEL_SCHEME(FuncSig, func-sig) + +#undef CF_BRANCH_LABEL_SCHEME +#endif // #ifdef CF_BRANCH_LABEL_SCHEME diff --git a/clang/include/clang/Basic/CFProtectionOptions.h b/clang/include/clang/Basic/CFProtectionOptions.h new file mode 100644 index 00..13f46d4c13e7e7 --- /dev/null +++ b/clang/include/clang/Basic/CFProtectionOptions.h @@ -0,0 +1,38 @@ +//===--- CFProtectionOptions.h --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// This file defines constants for -fcf-protection and other related flags. +// +//===--===// + +#ifndef LLVM_CLANG_BASIC_CFPROTECTIONOPTIONS_H +#define LLVM_CLANG_BASIC_CFPROTECTIONOPTIONS_H + +#include "llvm/Support/ErrorHandling.h" + +namespace clang { + +enum class CFBranchLabelSchemeKind { + Default, +#define CF_BRANCH_LABEL_SCHEME(Kind, FlagVal) Kind, +#include "clang/Basic/CFProtectionOptions.def" +}; + +static inline const char * +getCFBranchLabelSchemeFlagVal(const CFBranchLabelSchemeKind Scheme) { +#define CF_BRANCH_LABEL_SCHEME(Kind, FlagVal) \ + if (Scheme == CFBranchLabelSchemeKind::Kind) \ +return #FlagVal; +#include "clang/Basic/CFProtectionOptions.def" + + llvm::report_fatal_error("invalid scheme"); +} + +} // namespace clang + +#endif // #ifndef LLVM_CLANG_BASIC_CFPROTECTIONOPTIONS_H diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def index b600198998d85b..de7ae73f8a603b 100644 --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -110,6 +110,8 @@ CODEGENOPT(CFProtectionReturn , 1, 0) ///< if -fcf-protection is ///< set to full or return. CODEGENOPT(CFProtectionBranch , 1, 0) ///< if -fcf-protection is ///< set to full or branch. +ENUM_CODEGENOPT(CFBranchLabelScheme, CFBranchLabelSchemeKind, 2, +CFBranchLabelSchemeKind::Default) ///< if -mcf-branch-label-scheme is set. CODEGENOPT(FunctionReturnThunks, 1, 0) ///< -mfunction-return={keep|thunk-extern} CODEGENOPT(IndirectBranchCSPrefix, 1, 0) ///< if -mindirect-branch-cs-prefix
[clang-tools-extra] [clangd] Improve filtering logic for undesired proto symbols (PR #110091)
https://github.com/kadircet created https://github.com/llvm/llvm-project/pull/110091 This used to filter any names with `_` in them, apart from enum-constants. Resulting in discrepancies in behavior when we had fields that have `_` in the name, or for accessors like `set_`, `has_`. The logic seems to be trying to filter mangled names for nested entries, so adjusted logic to only do so for top-level decls, while still preserving some public top-level helpers. Heuristics are still leaning towards false-negatives, e.g. if a top-level entity has `_` in its name (`message Foo_Bar {}`), it'll be filtered, or an enum that prefixes its type name to constants (`enum Foo { Foo_OK }`). From 48e17de386d504f01cf89dba1f7bd445b4ce78e4 Mon Sep 17 00:00:00 2001 From: Kadir Cetinkaya Date: Thu, 26 Sep 2024 10:55:49 +0200 Subject: [PATCH] [clangd] Improve filtering logic for undesired proto symbols This used to filter any names with `_` in them, apart from enum-constants. Resulting in discrepancies in behavior when we had fields that have `_` in the name, or for accessors like `set_`, `has_`. The logic seems to be trying to filter mangled names for nested entries, so adjusted logic to only do so for top-level decls, while still preserving some public top-level helpers. Heuristics are still leaning towards false-negatives, e.g. if a top-level entity has `_` in its name (`message Foo_Bar {}`), it'll be filtered, or an enum that prefixes its type name to constants (`enum Foo { Foo_OK }`). --- .../clangd/index/SymbolCollector.cpp | 68 +++ .../clangd/unittests/SymbolCollectorTests.cpp | 65 +++--- 2 files changed, 111 insertions(+), 22 deletions(-) diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp b/clang-tools-extra/clangd/index/SymbolCollector.cpp index a76894cf0855f3..60739032eab003 100644 --- a/clang-tools-extra/clangd/index/SymbolCollector.cpp +++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp @@ -41,6 +41,7 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" @@ -75,18 +76,61 @@ bool isPrivateProtoDecl(const NamedDecl &ND) { if (ND.getIdentifier() == nullptr) return false; auto Name = ND.getIdentifier()->getName(); - if (!Name.contains('_')) -return false; - // Nested proto entities (e.g. Message::Nested) have top-level decls - // that shouldn't be used (Message_Nested). Ignore them completely. - // The nested entities are dangling type aliases, we may want to reconsider - // including them in the future. - // For enum constants, SOME_ENUM_CONSTANT is not private and should be - // indexed. Outer_INNER is private. This heuristic relies on naming style, it - // will include OUTER_INNER and exclude some_enum_constant. - // FIXME: the heuristic relies on naming style (i.e. no underscore in - // user-defined names) and can be improved. - return (ND.getKind() != Decl::EnumConstant) || llvm::any_of(Name, islower); + // There are some internal helpers like _internal_set_foo(); + if (Name.contains("_internal_")) +return true; + + // https://protobuf.dev/reference/cpp/cpp-generated/#nested-types + // Nested entities (messages/enums) has two names, one at the top-level scope, + // with a mangled name created by prepending all the outer types. These names + // are almost never preferred by the developers, so exclude them from index. + // e.g. + // message Foo { + // message Bar {} + // enum E { A } + // } + // yields: + // class Foo_Bar {}; + // enum Foo_E { Foo_E_A }; + // class Foo { + // using Bar = Foo_Bar; + // static constexpr Foo_E A = Foo_E_A; + // }; + + // We get rid of Foo_Bar and Foo_E by discarding any top-level entries with + // `_` in the name. This relies on original message/enum not having `_` in the + // name. Hence might go wrong in certain cases. + if (ND.getDeclContext()->isNamespace()) { +// Strip off some known public suffix helpers for enums, rest of the helpers +// are generated inside record decls so we don't care. +// https://protobuf.dev/reference/cpp/cpp-generated/#enum +Name.consume_back("_descriptor"); +Name.consume_back("_IsValid"); +Name.consume_back("_Name"); +Name.consume_back("_Parse"); +Name.consume_back("_MIN"); +Name.consume_back("_MAX"); +Name.consume_back("_ARRAYSIZE"); +return Name.contains('_'); + } + + // EnumConstantDecls need some special attention, despite being nested in a + // TagDecl, they might still have mangled names. We filter those by checking + // if it has parent's name as a prefix. + // This might go wrong if a nested entity has a name that starts with parent's + // name, e.g: enum Foo { Foo_X }. + if (llvm::isa(&ND)) { +auto *DC = llvm::cast(ND.getDeclContext()); +if (!DC || !DC->getIdentifier())
[clang-tools-extra] [clangd] Improve filtering logic for undesired proto symbols (PR #110091)
kadircet wrote: https://reviews.llvm.org/D46751 for context from the original patch https://github.com/llvm/llvm-project/pull/110091 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Improve filtering logic for undesired proto symbols (PR #110091)
llvmbot wrote: @llvm/pr-subscribers-clang-tools-extra @llvm/pr-subscribers-clangd Author: kadir çetinkaya (kadircet) Changes This used to filter any names with `_` in them, apart from enum-constants. Resulting in discrepancies in behavior when we had fields that have `_` in the name, or for accessors like `set_`, `has_`. The logic seems to be trying to filter mangled names for nested entries, so adjusted logic to only do so for top-level decls, while still preserving some public top-level helpers. Heuristics are still leaning towards false-negatives, e.g. if a top-level entity has `_` in its name (`message Foo_Bar {}`), it'll be filtered, or an enum that prefixes its type name to constants (`enum Foo { Foo_OK }`). --- Full diff: https://github.com/llvm/llvm-project/pull/110091.diff 2 Files Affected: - (modified) clang-tools-extra/clangd/index/SymbolCollector.cpp (+56-12) - (modified) clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp (+55-10) ``diff diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp b/clang-tools-extra/clangd/index/SymbolCollector.cpp index a76894cf0855f3..60739032eab003 100644 --- a/clang-tools-extra/clangd/index/SymbolCollector.cpp +++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp @@ -41,6 +41,7 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" @@ -75,18 +76,61 @@ bool isPrivateProtoDecl(const NamedDecl &ND) { if (ND.getIdentifier() == nullptr) return false; auto Name = ND.getIdentifier()->getName(); - if (!Name.contains('_')) -return false; - // Nested proto entities (e.g. Message::Nested) have top-level decls - // that shouldn't be used (Message_Nested). Ignore them completely. - // The nested entities are dangling type aliases, we may want to reconsider - // including them in the future. - // For enum constants, SOME_ENUM_CONSTANT is not private and should be - // indexed. Outer_INNER is private. This heuristic relies on naming style, it - // will include OUTER_INNER and exclude some_enum_constant. - // FIXME: the heuristic relies on naming style (i.e. no underscore in - // user-defined names) and can be improved. - return (ND.getKind() != Decl::EnumConstant) || llvm::any_of(Name, islower); + // There are some internal helpers like _internal_set_foo(); + if (Name.contains("_internal_")) +return true; + + // https://protobuf.dev/reference/cpp/cpp-generated/#nested-types + // Nested entities (messages/enums) has two names, one at the top-level scope, + // with a mangled name created by prepending all the outer types. These names + // are almost never preferred by the developers, so exclude them from index. + // e.g. + // message Foo { + // message Bar {} + // enum E { A } + // } + // yields: + // class Foo_Bar {}; + // enum Foo_E { Foo_E_A }; + // class Foo { + // using Bar = Foo_Bar; + // static constexpr Foo_E A = Foo_E_A; + // }; + + // We get rid of Foo_Bar and Foo_E by discarding any top-level entries with + // `_` in the name. This relies on original message/enum not having `_` in the + // name. Hence might go wrong in certain cases. + if (ND.getDeclContext()->isNamespace()) { +// Strip off some known public suffix helpers for enums, rest of the helpers +// are generated inside record decls so we don't care. +// https://protobuf.dev/reference/cpp/cpp-generated/#enum +Name.consume_back("_descriptor"); +Name.consume_back("_IsValid"); +Name.consume_back("_Name"); +Name.consume_back("_Parse"); +Name.consume_back("_MIN"); +Name.consume_back("_MAX"); +Name.consume_back("_ARRAYSIZE"); +return Name.contains('_'); + } + + // EnumConstantDecls need some special attention, despite being nested in a + // TagDecl, they might still have mangled names. We filter those by checking + // if it has parent's name as a prefix. + // This might go wrong if a nested entity has a name that starts with parent's + // name, e.g: enum Foo { Foo_X }. + if (llvm::isa(&ND)) { +auto *DC = llvm::cast(ND.getDeclContext()); +if (!DC || !DC->getIdentifier()) + return false; +auto CtxName = DC->getIdentifier()->getName(); +return !CtxName.empty() && Name.consume_front(CtxName) && + Name.consume_front("_"); + } + + // Now we're only left with fields/methods without an `_internal_` in the + // name, they're intended for public use. + return false; } // We only collect #include paths for symbols that are suitable for global code diff --git a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp index 0666be95b6b9ee..785a2fb29446b7 100644 --- a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp +++ b/clang-tools-extra/clangd/unittests/SymbolColl
[clang] [clang][RISCV] Introduce command line options for RISC-V Zicfilp CFI (PR #109784)
@@ -198,6 +198,21 @@ TargetInfo::checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const { return false; } +CFBranchLabelSchemeKind TargetInfo::getDefaultCFBranchLabelScheme() const { + // if this hook is called, the target should override it to return a + // non-default scheme + llvm::report_fatal_error("not implemented"); +} + +bool TargetInfo::checkCFBranchLabelSchemeSupported( +const CFBranchLabelSchemeKind Scheme, DiagnosticsEngine &Diags) const { + Diags.Report(diag::err_opt_not_valid_on_target) mylai-mtk wrote: Guard against `Default` https://github.com/llvm/llvm-project/pull/109784 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [Flang][Driver] Enable the -B option (PR #109965)
https://github.com/kiranchandramohan updated https://github.com/llvm/llvm-project/pull/109965 >From 3af5907719193ebc5b251b4681c137827550a1d0 Mon Sep 17 00:00:00 2001 From: Kiran Chandramohan Date: Wed, 25 Sep 2024 11:43:40 + Subject: [PATCH 1/2] [Flang][Driver] Enable the -B option The option provides the search prefix for executables, libraries and data files. The option is implemented in the common portion of the Driver and only needs to be enabled in Flang. Test added is a copy of the relevant test in Clang. --- clang/include/clang/Driver/Options.td | 1 + flang/test/Driver/B-opt.f90 | 23 +++ .../B_opt_tree/dir1/i386-unknown-linux-ld | 0 flang/test/Driver/Inputs/B_opt_tree/dir1/ld | 0 flang/test/Driver/Inputs/B_opt_tree/dir2/ld | 0 .../Driver/Inputs/B_opt_tree/dir3/prefix-ld | 0 6 files changed, 24 insertions(+) create mode 100644 flang/test/Driver/B-opt.f90 create mode 100755 flang/test/Driver/Inputs/B_opt_tree/dir1/i386-unknown-linux-ld create mode 100755 flang/test/Driver/Inputs/B_opt_tree/dir1/ld create mode 100755 flang/test/Driver/Inputs/B_opt_tree/dir2/ld create mode 100755 flang/test/Driver/Inputs/B_opt_tree/dir3/prefix-ld diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 002f60350543d9..020f4f92e8735a 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -816,6 +816,7 @@ def _DASH_DASH : Option<["--"], "", KIND_REMAINING_ARGS>, def A : JoinedOrSeparate<["-"], "A">, Flags<[RenderJoined]>, Group; def B : JoinedOrSeparate<["-"], "B">, MetaVarName<"">, +Visibility<[ClangOption, FlangOption]>, HelpText<"Search $prefix$file for executables, libraries, and data files. " "If $prefix is a directory, search $prefix/$file">; def gcc_install_dir_EQ : Joined<["--"], "gcc-install-dir=">, diff --git a/flang/test/Driver/B-opt.f90 b/flang/test/Driver/B-opt.f90 new file mode 100644 index 00..a749b5e08e8d52 --- /dev/null +++ b/flang/test/Driver/B-opt.f90 @@ -0,0 +1,23 @@ +! Check -B driver option. +! +! Target triple prefix is not detected for -B. +! RUN: %flang %s -### -o %t.o -target i386-unknown-linux \ +! RUN: -B %S/Inputs/B_opt_tree/dir1 -fuse-ld=ld 2>&1 \ +! RUN: | FileCheck --check-prefix=CHECK-B-OPT-TRIPLE %s +! CHECK-B-OPT-TRIPLE-NOT: "{{.*}}/Inputs/B_opt_tree/dir1{{/|}}i386-unknown-linux-ld" +! +! RUN: %flang %s -### -o %t.o -target i386-unknown-linux \ +! RUN: -B %S/Inputs/B_opt_tree/dir2 -fuse-ld=ld 2>&1 \ +! RUN: | FileCheck --check-prefix=CHECK-B-OPT-DIR %s +! CHECK-B-OPT-DIR: "{{.*}}/Inputs/B_opt_tree/dir2{{/|}}ld" +! +! RUN: %flang %s -### -o %t.o -target i386-unknown-linux \ +! RUN: -B %S/Inputs/B_opt_tree/dir3/prefix- -fuse-ld=ld 2>&1 \ +! RUN: | FileCheck --check-prefix=CHECK-B-OPT-PREFIX %s +! CHECK-B-OPT-PREFIX: "{{.*}}/Inputs/B_opt_tree/dir3{{/|}}prefix-ld" +! +! RUN: %flang %s -### -o %t.o -target i386-unknown-linux \ +! RUN: -B %S/Inputs/B_opt_tree/dir3/prefix- \ +! RUN: -B %S/Inputs/B_opt_tree/dir2 2>&1 -fuse-ld=ld \ +! RUN: | FileCheck --check-prefix=CHECK-B-OPT-MULT %s +! CHECK-B-OPT-MULT: "{{.*}}/Inputs/B_opt_tree/dir3{{/|}}prefix-ld" diff --git a/flang/test/Driver/Inputs/B_opt_tree/dir1/i386-unknown-linux-ld b/flang/test/Driver/Inputs/B_opt_tree/dir1/i386-unknown-linux-ld new file mode 100755 index 00..e69de29bb2d1d6 diff --git a/flang/test/Driver/Inputs/B_opt_tree/dir1/ld b/flang/test/Driver/Inputs/B_opt_tree/dir1/ld new file mode 100755 index 00..e69de29bb2d1d6 diff --git a/flang/test/Driver/Inputs/B_opt_tree/dir2/ld b/flang/test/Driver/Inputs/B_opt_tree/dir2/ld new file mode 100755 index 00..e69de29bb2d1d6 diff --git a/flang/test/Driver/Inputs/B_opt_tree/dir3/prefix-ld b/flang/test/Driver/Inputs/B_opt_tree/dir3/prefix-ld new file mode 100755 index 00..e69de29bb2d1d6 >From 76e8842e0d0bdd6fc1882d8d22a1efa1c86b13a5 Mon Sep 17 00:00:00 2001 From: Kiran Chandramohan Date: Thu, 26 Sep 2024 09:34:34 + Subject: [PATCH 2/2] Use --target instead of target --- clang/test/Driver/B-opt.c | 10 +- flang/test/Driver/B-opt.f90 | 8 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/clang/test/Driver/B-opt.c b/clang/test/Driver/B-opt.c index df85dee4b70407..48139e71a90011 100644 --- a/clang/test/Driver/B-opt.c +++ b/clang/test/Driver/B-opt.c @@ -1,28 +1,28 @@ // Check -B driver option. /// Target triple prefix is not detected for -B. -// RUN: %clang %s -### -o %t.o -target i386-unknown-linux \ +// RUN: %clang %s -### -o %t.o --target=i386-unknown-linux \ // RUN: -B %S/Inputs/B_opt_tree/dir1 -fuse-ld=ld 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-B-OPT-TRIPLE %s // CHECK-B-OPT-TRIPLE-NOT: "{{.*}}/Inputs/B_opt_tree/dir1{{/|}}i386-unknown-linux-ld" // -// RUN: %clang %s -### -o %t.o -target i386-unknown-linux \ +// RUN: %clang %s -### -o %t.o -
[clang] [flang] [Flang][Driver] Enable the -B option (PR #109965)
@@ -0,0 +1,23 @@ +! Check -B driver option. +! +! Target triple prefix is not detected for -B. +! RUN: %flang %s -### -o %t.o -target i386-unknown-linux \ kiranchandramohan wrote: Thanks. Done. Modified tests for both drivers. https://github.com/llvm/llvm-project/pull/109965 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [FMV][RISCV] Add __riscv_feature_bits.length check (PR #110098)
llvmbot wrote: @llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-codegen Author: Piyou Chen (BeMg) Changes This patch add a condition that check the `__riscv_feature_bits.length` before access `__riscv_feature_bits.features`. It updates the resolver function as the following structure. ``` if (__riscv_feature_bits.features.length <= llvm::RISCVISAInfo::FeatureBitSize) { if (FeaturesConditionVersion1) return Version1; else if (FeaturesConditionVersion2) return Version2; else if (FeaturesConditionVersion3) return Version3; ... } return DefaultVersion; ``` --- Patch is 46.17 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/110098.diff 5 Files Affected: - (modified) clang/lib/CodeGen/CGBuiltin.cpp (+26-7) - (modified) clang/lib/CodeGen/CodeGenFunction.cpp (+23-9) - (modified) clang/lib/CodeGen/CodeGenFunction.h (+1) - (modified) clang/test/CodeGen/attr-target-clones-riscv.c (+112-72) - (modified) clang/test/CodeGenCXX/attr-target-clones-riscv.cpp (+112-72) ``diff diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 249aead33ad73d..6af6f166575142 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -14534,8 +14534,9 @@ Value *CodeGenFunction::EmitRISCVCpuSupports(const CallExpr *E) { return EmitRISCVCpuSupports(ArrayRef(FeatureStr)); } -static Value *loadRISCVFeatureBits(unsigned Index, CGBuilderTy &Builder, - CodeGenModule &CGM) { +static Value *loadRISCVFeatureBitsCommon(ArrayRef GEPIndices, + CGBuilderTy &Builder, + CodeGenModule &CGM) { llvm::Type *Int32Ty = Builder.getInt32Ty(); llvm::Type *Int64Ty = Builder.getInt64Ty(); llvm::ArrayType *ArrayOfInt64Ty = @@ -14544,14 +14545,32 @@ static Value *loadRISCVFeatureBits(unsigned Index, CGBuilderTy &Builder, llvm::Constant *RISCVFeaturesBits = CGM.CreateRuntimeVariable(StructTy, "__riscv_feature_bits"); cast(RISCVFeaturesBits)->setDSOLocal(true); - Value *IndexVal = llvm::ConstantInt::get(Int32Ty, Index); - llvm::Value *GEPIndices[] = {Builder.getInt32(0), Builder.getInt32(1), - IndexVal}; Value *Ptr = Builder.CreateInBoundsGEP(StructTy, RISCVFeaturesBits, GEPIndices); - Value *FeaturesBit = + Value *FeaturesVal = Builder.CreateAlignedLoad(Int64Ty, Ptr, CharUnits::fromQuantity(8)); - return FeaturesBit; + return FeaturesVal; +} + +static Value *loadRISCVFeatureBitsLength(CGBuilderTy &Builder, + CodeGenModule &CGM) { + llvm::Value *GEPIndices[] = {Builder.getInt32(0), Builder.getInt32(0)}; + return loadRISCVFeatureBitsCommon(GEPIndices, Builder, CGM); +} + +static Value *loadRISCVFeatureBits(unsigned Index, CGBuilderTy &Builder, + CodeGenModule &CGM) { + llvm::Type *Int32Ty = Builder.getInt32Ty(); + Value *IndexVal = llvm::ConstantInt::get(Int32Ty, Index); + llvm::Value *GEPIndices[] = {Builder.getInt32(0), Builder.getInt32(1), + IndexVal}; + return loadRISCVFeatureBitsCommon(GEPIndices, Builder, CGM); +} + +llvm::Value *CodeGenFunction::EmitRISCVFeatureBitsLengthCond() { + return Builder.CreateICmpULE( + loadRISCVFeatureBitsLength(Builder, CGM), + Builder.getInt64(llvm::RISCVISAInfo::FeatureBitSize)); } Value *CodeGenFunction::EmitRISCVCpuSupports(ArrayRef FeaturesStrs) { diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index eda96f3e352ce3..9e558195aa6daa 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -2945,6 +2945,10 @@ void CodeGenFunction::EmitRISCVMultiVersionResolver( getPriorityFromAttrString(RHS.Conditions.Features[0]); }); + llvm::BasicBlock *LengthBlock = CurBlock; + llvm::BasicBlock *VersionBlock = createBasicBlock("version_begin", Resolver); + CurBlock = VersionBlock; + // Check the each candidate function. for (unsigned Index = 0; Index < CurrOptions.size(); Index++) { @@ -2970,22 +2974,28 @@ void CodeGenFunction::EmitRISCVMultiVersionResolver( // (__riscv_feature_bits.features[i] & REQUIRED_BITMASK) == // REQUIRED_BITMASK // +// First, check __riscv_feature_bits.length <= +// llvm::RISCVISAInfo::FeatureBitSize. This ensures that the +// __riscv_feature_bits object at runtime has the same length as on the +// compiler side. +// +// Second, // When condition is met, return this version of the function. // Otherwise, try the next version. // -// if (FeaturesConditionVersion1) +// +// if (__riscv_feature_bits.features.length <= +// llvm::RISCVISAInfo::FeatureBitSize) { +// if (FeaturesConditionVersion1) // return Version1; -// else
[clang] [FMV][RISCV] Add __riscv_feature_bits.length check (PR #110098)
https://github.com/BeMg created https://github.com/llvm/llvm-project/pull/110098 This patch add a condition that check the `__riscv_feature_bits.length` before access `__riscv_feature_bits.features`. It updates the resolver function as the following structure. ``` if (__riscv_feature_bits.features.length <= llvm::RISCVISAInfo::FeatureBitSize) { if (FeaturesConditionVersion1) return Version1; else if (FeaturesConditionVersion2) return Version2; else if (FeaturesConditionVersion3) return Version3; ... } return DefaultVersion; ``` >From 838c6669d2f4464b9b528b0d633ad363b92e3b57 Mon Sep 17 00:00:00 2001 From: Piyou Chen Date: Thu, 26 Sep 2024 02:16:56 -0700 Subject: [PATCH] [FMV][RISCV] Check FeatureBits.length before test all version --- clang/lib/CodeGen/CGBuiltin.cpp | 33 +++- clang/lib/CodeGen/CodeGenFunction.cpp | 32 ++- clang/lib/CodeGen/CodeGenFunction.h | 1 + clang/test/CodeGen/attr-target-clones-riscv.c | 184 +++--- .../CodeGenCXX/attr-target-clones-riscv.cpp | 184 +++--- 5 files changed, 274 insertions(+), 160 deletions(-) diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 249aead33ad73d..6af6f166575142 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -14534,8 +14534,9 @@ Value *CodeGenFunction::EmitRISCVCpuSupports(const CallExpr *E) { return EmitRISCVCpuSupports(ArrayRef(FeatureStr)); } -static Value *loadRISCVFeatureBits(unsigned Index, CGBuilderTy &Builder, - CodeGenModule &CGM) { +static Value *loadRISCVFeatureBitsCommon(ArrayRef GEPIndices, + CGBuilderTy &Builder, + CodeGenModule &CGM) { llvm::Type *Int32Ty = Builder.getInt32Ty(); llvm::Type *Int64Ty = Builder.getInt64Ty(); llvm::ArrayType *ArrayOfInt64Ty = @@ -14544,14 +14545,32 @@ static Value *loadRISCVFeatureBits(unsigned Index, CGBuilderTy &Builder, llvm::Constant *RISCVFeaturesBits = CGM.CreateRuntimeVariable(StructTy, "__riscv_feature_bits"); cast(RISCVFeaturesBits)->setDSOLocal(true); - Value *IndexVal = llvm::ConstantInt::get(Int32Ty, Index); - llvm::Value *GEPIndices[] = {Builder.getInt32(0), Builder.getInt32(1), - IndexVal}; Value *Ptr = Builder.CreateInBoundsGEP(StructTy, RISCVFeaturesBits, GEPIndices); - Value *FeaturesBit = + Value *FeaturesVal = Builder.CreateAlignedLoad(Int64Ty, Ptr, CharUnits::fromQuantity(8)); - return FeaturesBit; + return FeaturesVal; +} + +static Value *loadRISCVFeatureBitsLength(CGBuilderTy &Builder, + CodeGenModule &CGM) { + llvm::Value *GEPIndices[] = {Builder.getInt32(0), Builder.getInt32(0)}; + return loadRISCVFeatureBitsCommon(GEPIndices, Builder, CGM); +} + +static Value *loadRISCVFeatureBits(unsigned Index, CGBuilderTy &Builder, + CodeGenModule &CGM) { + llvm::Type *Int32Ty = Builder.getInt32Ty(); + Value *IndexVal = llvm::ConstantInt::get(Int32Ty, Index); + llvm::Value *GEPIndices[] = {Builder.getInt32(0), Builder.getInt32(1), + IndexVal}; + return loadRISCVFeatureBitsCommon(GEPIndices, Builder, CGM); +} + +llvm::Value *CodeGenFunction::EmitRISCVFeatureBitsLengthCond() { + return Builder.CreateICmpULE( + loadRISCVFeatureBitsLength(Builder, CGM), + Builder.getInt64(llvm::RISCVISAInfo::FeatureBitSize)); } Value *CodeGenFunction::EmitRISCVCpuSupports(ArrayRef FeaturesStrs) { diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index eda96f3e352ce3..9e558195aa6daa 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -2945,6 +2945,10 @@ void CodeGenFunction::EmitRISCVMultiVersionResolver( getPriorityFromAttrString(RHS.Conditions.Features[0]); }); + llvm::BasicBlock *LengthBlock = CurBlock; + llvm::BasicBlock *VersionBlock = createBasicBlock("version_begin", Resolver); + CurBlock = VersionBlock; + // Check the each candidate function. for (unsigned Index = 0; Index < CurrOptions.size(); Index++) { @@ -2970,22 +2974,28 @@ void CodeGenFunction::EmitRISCVMultiVersionResolver( // (__riscv_feature_bits.features[i] & REQUIRED_BITMASK) == // REQUIRED_BITMASK // +// First, check __riscv_feature_bits.length <= +// llvm::RISCVISAInfo::FeatureBitSize. This ensures that the +// __riscv_feature_bits object at runtime has the same length as on the +// compiler side. +// +// Second, // When condition is met, return this version of the function. // Otherwise, try the next version. // -// if (FeaturesConditionVersion1) +// +// if (__riscv_feature_bits.features.length <= +// llvm::RISCVISAInfo::FeatureBitSize) { +// if (F
[clang] [FMV][RISCV] Add __riscv_feature_bits.length check (PR #110098)
llvmbot wrote: @llvm/pr-subscribers-backend-risc-v Author: Piyou Chen (BeMg) Changes This patch add a condition that check the `__riscv_feature_bits.length` before access `__riscv_feature_bits.features`. It updates the resolver function as the following structure. ``` if (__riscv_feature_bits.features.length <= llvm::RISCVISAInfo::FeatureBitSize) { if (FeaturesConditionVersion1) return Version1; else if (FeaturesConditionVersion2) return Version2; else if (FeaturesConditionVersion3) return Version3; ... } return DefaultVersion; ``` --- Patch is 46.17 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/110098.diff 5 Files Affected: - (modified) clang/lib/CodeGen/CGBuiltin.cpp (+26-7) - (modified) clang/lib/CodeGen/CodeGenFunction.cpp (+23-9) - (modified) clang/lib/CodeGen/CodeGenFunction.h (+1) - (modified) clang/test/CodeGen/attr-target-clones-riscv.c (+112-72) - (modified) clang/test/CodeGenCXX/attr-target-clones-riscv.cpp (+112-72) ``diff diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 249aead33ad73d..6af6f166575142 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -14534,8 +14534,9 @@ Value *CodeGenFunction::EmitRISCVCpuSupports(const CallExpr *E) { return EmitRISCVCpuSupports(ArrayRef(FeatureStr)); } -static Value *loadRISCVFeatureBits(unsigned Index, CGBuilderTy &Builder, - CodeGenModule &CGM) { +static Value *loadRISCVFeatureBitsCommon(ArrayRef GEPIndices, + CGBuilderTy &Builder, + CodeGenModule &CGM) { llvm::Type *Int32Ty = Builder.getInt32Ty(); llvm::Type *Int64Ty = Builder.getInt64Ty(); llvm::ArrayType *ArrayOfInt64Ty = @@ -14544,14 +14545,32 @@ static Value *loadRISCVFeatureBits(unsigned Index, CGBuilderTy &Builder, llvm::Constant *RISCVFeaturesBits = CGM.CreateRuntimeVariable(StructTy, "__riscv_feature_bits"); cast(RISCVFeaturesBits)->setDSOLocal(true); - Value *IndexVal = llvm::ConstantInt::get(Int32Ty, Index); - llvm::Value *GEPIndices[] = {Builder.getInt32(0), Builder.getInt32(1), - IndexVal}; Value *Ptr = Builder.CreateInBoundsGEP(StructTy, RISCVFeaturesBits, GEPIndices); - Value *FeaturesBit = + Value *FeaturesVal = Builder.CreateAlignedLoad(Int64Ty, Ptr, CharUnits::fromQuantity(8)); - return FeaturesBit; + return FeaturesVal; +} + +static Value *loadRISCVFeatureBitsLength(CGBuilderTy &Builder, + CodeGenModule &CGM) { + llvm::Value *GEPIndices[] = {Builder.getInt32(0), Builder.getInt32(0)}; + return loadRISCVFeatureBitsCommon(GEPIndices, Builder, CGM); +} + +static Value *loadRISCVFeatureBits(unsigned Index, CGBuilderTy &Builder, + CodeGenModule &CGM) { + llvm::Type *Int32Ty = Builder.getInt32Ty(); + Value *IndexVal = llvm::ConstantInt::get(Int32Ty, Index); + llvm::Value *GEPIndices[] = {Builder.getInt32(0), Builder.getInt32(1), + IndexVal}; + return loadRISCVFeatureBitsCommon(GEPIndices, Builder, CGM); +} + +llvm::Value *CodeGenFunction::EmitRISCVFeatureBitsLengthCond() { + return Builder.CreateICmpULE( + loadRISCVFeatureBitsLength(Builder, CGM), + Builder.getInt64(llvm::RISCVISAInfo::FeatureBitSize)); } Value *CodeGenFunction::EmitRISCVCpuSupports(ArrayRef FeaturesStrs) { diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index eda96f3e352ce3..9e558195aa6daa 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -2945,6 +2945,10 @@ void CodeGenFunction::EmitRISCVMultiVersionResolver( getPriorityFromAttrString(RHS.Conditions.Features[0]); }); + llvm::BasicBlock *LengthBlock = CurBlock; + llvm::BasicBlock *VersionBlock = createBasicBlock("version_begin", Resolver); + CurBlock = VersionBlock; + // Check the each candidate function. for (unsigned Index = 0; Index < CurrOptions.size(); Index++) { @@ -2970,22 +2974,28 @@ void CodeGenFunction::EmitRISCVMultiVersionResolver( // (__riscv_feature_bits.features[i] & REQUIRED_BITMASK) == // REQUIRED_BITMASK // +// First, check __riscv_feature_bits.length <= +// llvm::RISCVISAInfo::FeatureBitSize. This ensures that the +// __riscv_feature_bits object at runtime has the same length as on the +// compiler side. +// +// Second, // When condition is met, return this version of the function. // Otherwise, try the next version. // -// if (FeaturesConditionVersion1) +// +// if (__riscv_feature_bits.features.length <= +// llvm::RISCVISAInfo::FeatureBitSize) { +// if (FeaturesConditionVersion1) // return Version1; -// else if (FeaturesConditionVersi
[clang] [FMV][RISCV] Add __riscv_feature_bits.length check (PR #110098)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff 23487be4903630a4c06160562fb939f6389aa99d 838c6669d2f4464b9b528b0d633ad363b92e3b57 --extensions h,c,cpp -- clang/lib/CodeGen/CGBuiltin.cpp clang/lib/CodeGen/CodeGenFunction.cpp clang/lib/CodeGen/CodeGenFunction.h clang/test/CodeGen/attr-target-clones-riscv.c clang/test/CodeGenCXX/attr-target-clones-riscv.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 9e558195aa..6589d1eeb8 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -2979,7 +2979,7 @@ void CodeGenFunction::EmitRISCVMultiVersionResolver( // __riscv_feature_bits object at runtime has the same length as on the // compiler side. // -// Second, +// Second, // When condition is met, return this version of the function. // Otherwise, try the next version. // `` https://github.com/llvm/llvm-project/pull/110098 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [FMV][RISCV] Add __riscv_feature_bits.length check (PR #110098)
https://github.com/BeMg updated https://github.com/llvm/llvm-project/pull/110098 >From 838c6669d2f4464b9b528b0d633ad363b92e3b57 Mon Sep 17 00:00:00 2001 From: Piyou Chen Date: Thu, 26 Sep 2024 02:16:56 -0700 Subject: [PATCH 1/2] [FMV][RISCV] Check FeatureBits.length before test all version --- clang/lib/CodeGen/CGBuiltin.cpp | 33 +++- clang/lib/CodeGen/CodeGenFunction.cpp | 32 ++- clang/lib/CodeGen/CodeGenFunction.h | 1 + clang/test/CodeGen/attr-target-clones-riscv.c | 184 +++--- .../CodeGenCXX/attr-target-clones-riscv.cpp | 184 +++--- 5 files changed, 274 insertions(+), 160 deletions(-) diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 249aead33ad73d..6af6f166575142 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -14534,8 +14534,9 @@ Value *CodeGenFunction::EmitRISCVCpuSupports(const CallExpr *E) { return EmitRISCVCpuSupports(ArrayRef(FeatureStr)); } -static Value *loadRISCVFeatureBits(unsigned Index, CGBuilderTy &Builder, - CodeGenModule &CGM) { +static Value *loadRISCVFeatureBitsCommon(ArrayRef GEPIndices, + CGBuilderTy &Builder, + CodeGenModule &CGM) { llvm::Type *Int32Ty = Builder.getInt32Ty(); llvm::Type *Int64Ty = Builder.getInt64Ty(); llvm::ArrayType *ArrayOfInt64Ty = @@ -14544,14 +14545,32 @@ static Value *loadRISCVFeatureBits(unsigned Index, CGBuilderTy &Builder, llvm::Constant *RISCVFeaturesBits = CGM.CreateRuntimeVariable(StructTy, "__riscv_feature_bits"); cast(RISCVFeaturesBits)->setDSOLocal(true); - Value *IndexVal = llvm::ConstantInt::get(Int32Ty, Index); - llvm::Value *GEPIndices[] = {Builder.getInt32(0), Builder.getInt32(1), - IndexVal}; Value *Ptr = Builder.CreateInBoundsGEP(StructTy, RISCVFeaturesBits, GEPIndices); - Value *FeaturesBit = + Value *FeaturesVal = Builder.CreateAlignedLoad(Int64Ty, Ptr, CharUnits::fromQuantity(8)); - return FeaturesBit; + return FeaturesVal; +} + +static Value *loadRISCVFeatureBitsLength(CGBuilderTy &Builder, + CodeGenModule &CGM) { + llvm::Value *GEPIndices[] = {Builder.getInt32(0), Builder.getInt32(0)}; + return loadRISCVFeatureBitsCommon(GEPIndices, Builder, CGM); +} + +static Value *loadRISCVFeatureBits(unsigned Index, CGBuilderTy &Builder, + CodeGenModule &CGM) { + llvm::Type *Int32Ty = Builder.getInt32Ty(); + Value *IndexVal = llvm::ConstantInt::get(Int32Ty, Index); + llvm::Value *GEPIndices[] = {Builder.getInt32(0), Builder.getInt32(1), + IndexVal}; + return loadRISCVFeatureBitsCommon(GEPIndices, Builder, CGM); +} + +llvm::Value *CodeGenFunction::EmitRISCVFeatureBitsLengthCond() { + return Builder.CreateICmpULE( + loadRISCVFeatureBitsLength(Builder, CGM), + Builder.getInt64(llvm::RISCVISAInfo::FeatureBitSize)); } Value *CodeGenFunction::EmitRISCVCpuSupports(ArrayRef FeaturesStrs) { diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index eda96f3e352ce3..9e558195aa6daa 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -2945,6 +2945,10 @@ void CodeGenFunction::EmitRISCVMultiVersionResolver( getPriorityFromAttrString(RHS.Conditions.Features[0]); }); + llvm::BasicBlock *LengthBlock = CurBlock; + llvm::BasicBlock *VersionBlock = createBasicBlock("version_begin", Resolver); + CurBlock = VersionBlock; + // Check the each candidate function. for (unsigned Index = 0; Index < CurrOptions.size(); Index++) { @@ -2970,22 +2974,28 @@ void CodeGenFunction::EmitRISCVMultiVersionResolver( // (__riscv_feature_bits.features[i] & REQUIRED_BITMASK) == // REQUIRED_BITMASK // +// First, check __riscv_feature_bits.length <= +// llvm::RISCVISAInfo::FeatureBitSize. This ensures that the +// __riscv_feature_bits object at runtime has the same length as on the +// compiler side. +// +// Second, // When condition is met, return this version of the function. // Otherwise, try the next version. // -// if (FeaturesConditionVersion1) +// +// if (__riscv_feature_bits.features.length <= +// llvm::RISCVISAInfo::FeatureBitSize) { +// if (FeaturesConditionVersion1) // return Version1; -// else if (FeaturesConditionVersion2) +// else if (FeaturesConditionVersion2) // return Version2; -// else if (FeaturesConditionVersion3) +// else if (FeaturesConditionVersion3) // return Version3; -// ... -// else -// return DefaultVersion; +// ... +// } +// return DefaultVersion; -// TODO: Add a condition to check the length before accessing elements. -// With
[clang-tools-extra] [clang-tidy] Portability Template Virtual Member Function Check (PR #110099)
https://github.com/isuckatcs created https://github.com/llvm/llvm-project/pull/110099 Per C++ ``[temp.inst#11]``: "It is unspecified whether or not an implementation implicitly instantiates a virtual member function of a class template if the virtual member function would not otherwise be instantiated." In the following snippets the virtual member function is not instantiated by gcc and clang, but it is instantiated by MSVC, so while the snippet is accepted by the former compilers, it is rejected by the latter. (See [godbolt](https://godbolt.org/z/3rssYsndK)) ```c++ template struct CrossPlatformError { virtual ~CrossPlatformError() = default; static void used() {} virtual void unused() { T MSVCError = this; }; }; int main() { CrossPlatformError::used(); return 0; } ``` Cross-platform projects that need to support MSVC on Windows might see compiler errors because certain virtual member functions are instantiated, which are not instantiated by other compilers on other platforms. This check highlights such virtual member functions. >From 9cdba3e947705053b14f8eeca39c281fd18e21ce Mon Sep 17 00:00:00 2001 From: isuckatcs <65320245+isucka...@users.noreply.github.com> Date: Thu, 26 Sep 2024 11:43:10 +0200 Subject: [PATCH] [clang-tidy] Portability Template Virtual Member Function Check --- .../clang-tidy/portability/CMakeLists.txt | 1 + .../portability/PortabilityTidyModule.cpp | 3 + .../TemplateVirtualMemberFunctionCheck.cpp| 49 +++ .../TemplateVirtualMemberFunctionCheck.h | 36 + clang-tools-extra/docs/ReleaseNotes.rst | 7 + .../docs/clang-tidy/checks/list.rst | 1 + .../template-virtual-member-function.rst | 33 + .../template-virtual-member-function.cpp | 134 ++ 8 files changed, 264 insertions(+) create mode 100644 clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.cpp create mode 100644 clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.h create mode 100644 clang-tools-extra/docs/clang-tidy/checks/portability/template-virtual-member-function.rst create mode 100644 clang-tools-extra/test/clang-tidy/checkers/portability/template-virtual-member-function.cpp diff --git a/clang-tools-extra/clang-tidy/portability/CMakeLists.txt b/clang-tools-extra/clang-tidy/portability/CMakeLists.txt index 01a86d686daa76..df08cf2c8e292c 100644 --- a/clang-tools-extra/clang-tidy/portability/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/portability/CMakeLists.txt @@ -9,6 +9,7 @@ add_clang_library(clangTidyPortabilityModule RestrictSystemIncludesCheck.cpp SIMDIntrinsicsCheck.cpp StdAllocatorConstCheck.cpp + TemplateVirtualMemberFunctionCheck.cpp LINK_LIBS clangTidy diff --git a/clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp b/clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp index b3759a754587d7..316b98b46cf3f2 100644 --- a/clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp @@ -12,6 +12,7 @@ #include "RestrictSystemIncludesCheck.h" #include "SIMDIntrinsicsCheck.h" #include "StdAllocatorConstCheck.h" +#include "TemplateVirtualMemberFunctionCheck.h" namespace clang::tidy { namespace portability { @@ -25,6 +26,8 @@ class PortabilityModule : public ClangTidyModule { "portability-simd-intrinsics"); CheckFactories.registerCheck( "portability-std-allocator-const"); +CheckFactories.registerCheck( +"portability-template-virtual-member-function"); } }; diff --git a/clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.cpp b/clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.cpp new file mode 100644 index 00..6b7b50798798fa --- /dev/null +++ b/clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.cpp @@ -0,0 +1,49 @@ +//===--- TemplateVirtualMemberFunctionCheck.cpp - clang-tidy +//---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "TemplateVirtualMemberFunctionCheck.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::portability { + +void TemplateVirtualMemberFunctionCheck::registerMatchers(MatchFinder *Finder) { + Finder->addMatcher(classTemplateSpecializationDecl().bind("specialization"), + this); +} + +void TemplateVirtualMemberFunctionCheck::check( +const MatchFinder::MatchResult &Result) { + const auto *MatchedDecl = + Result.Nodes.getNodeAs("specialization"); + + if (MatchedDecl->isExplicitSpeci
[clang-tools-extra] [clang-tidy] Portability Template Virtual Member Function Check (PR #110099)
llvmbot wrote: @llvm/pr-subscribers-clang-tools-extra Author: None (isuckatcs) Changes Per C++ ``[temp.inst#11]``: "It is unspecified whether or not an implementation implicitly instantiates a virtual member function of a class template if the virtual member function would not otherwise be instantiated." In the following snippets the virtual member function is not instantiated by gcc and clang, but it is instantiated by MSVC, so while the snippet is accepted by the former compilers, it is rejected by the latter. (See [godbolt](https://godbolt.org/z/3rssYsndK)) ```c++ templatestruct CrossPlatformError { virtual ~CrossPlatformError() = default; static void used() {} virtual void unused() { T MSVCError = this; }; }; int main() { CrossPlatformError ::used(); return 0; } ``` Cross-platform projects that need to support MSVC on Windows might see compiler errors because certain virtual member functions are instantiated, which are not instantiated by other compilers on other platforms. This check highlights such virtual member functions. --- Full diff: https://github.com/llvm/llvm-project/pull/110099.diff 8 Files Affected: - (modified) clang-tools-extra/clang-tidy/portability/CMakeLists.txt (+1) - (modified) clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp (+3) - (added) clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.cpp (+49) - (added) clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.h (+36) - (modified) clang-tools-extra/docs/ReleaseNotes.rst (+7) - (modified) clang-tools-extra/docs/clang-tidy/checks/list.rst (+1) - (added) clang-tools-extra/docs/clang-tidy/checks/portability/template-virtual-member-function.rst (+33) - (added) clang-tools-extra/test/clang-tidy/checkers/portability/template-virtual-member-function.cpp (+134) ``diff diff --git a/clang-tools-extra/clang-tidy/portability/CMakeLists.txt b/clang-tools-extra/clang-tidy/portability/CMakeLists.txt index 01a86d686daa76..df08cf2c8e292c 100644 --- a/clang-tools-extra/clang-tidy/portability/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/portability/CMakeLists.txt @@ -9,6 +9,7 @@ add_clang_library(clangTidyPortabilityModule RestrictSystemIncludesCheck.cpp SIMDIntrinsicsCheck.cpp StdAllocatorConstCheck.cpp + TemplateVirtualMemberFunctionCheck.cpp LINK_LIBS clangTidy diff --git a/clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp b/clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp index b3759a754587d7..316b98b46cf3f2 100644 --- a/clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp @@ -12,6 +12,7 @@ #include "RestrictSystemIncludesCheck.h" #include "SIMDIntrinsicsCheck.h" #include "StdAllocatorConstCheck.h" +#include "TemplateVirtualMemberFunctionCheck.h" namespace clang::tidy { namespace portability { @@ -25,6 +26,8 @@ class PortabilityModule : public ClangTidyModule { "portability-simd-intrinsics"); CheckFactories.registerCheck( "portability-std-allocator-const"); +CheckFactories.registerCheck( +"portability-template-virtual-member-function"); } }; diff --git a/clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.cpp b/clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.cpp new file mode 100644 index 00..6b7b50798798fa --- /dev/null +++ b/clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.cpp @@ -0,0 +1,49 @@ +//===--- TemplateVirtualMemberFunctionCheck.cpp - clang-tidy +//---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "TemplateVirtualMemberFunctionCheck.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::portability { + +void TemplateVirtualMemberFunctionCheck::registerMatchers(MatchFinder *Finder) { + Finder->addMatcher(classTemplateSpecializationDecl().bind("specialization"), + this); +} + +void TemplateVirtualMemberFunctionCheck::check( +const MatchFinder::MatchResult &Result) { + const auto *MatchedDecl = + Result.Nodes.getNodeAs("specialization"); + + if (MatchedDecl->isExplicitSpecialization()) +return; + + for (auto &&Method : MatchedDecl->methods()) { +if (!Method->isVirtual()) + continue; + +if (const auto *Dtor = llvm::dyn_cast(Method); +Dtor && Dtor->isDefaulted()) + continue; + +if (!Method->isUsed()) { + diag(Method->getLocation(), + "unspecified virtual member function in
[clang-tools-extra] [clang-tidy] Portability Template Virtual Member Function Check (PR #110099)
llvmbot wrote: @llvm/pr-subscribers-clang-tidy Author: None (isuckatcs) Changes Per C++ ``[temp.inst#11]``: "It is unspecified whether or not an implementation implicitly instantiates a virtual member function of a class template if the virtual member function would not otherwise be instantiated." In the following snippets the virtual member function is not instantiated by gcc and clang, but it is instantiated by MSVC, so while the snippet is accepted by the former compilers, it is rejected by the latter. (See [godbolt](https://godbolt.org/z/3rssYsndK)) ```c++ templatestruct CrossPlatformError { virtual ~CrossPlatformError() = default; static void used() {} virtual void unused() { T MSVCError = this; }; }; int main() { CrossPlatformError ::used(); return 0; } ``` Cross-platform projects that need to support MSVC on Windows might see compiler errors because certain virtual member functions are instantiated, which are not instantiated by other compilers on other platforms. This check highlights such virtual member functions. --- Full diff: https://github.com/llvm/llvm-project/pull/110099.diff 8 Files Affected: - (modified) clang-tools-extra/clang-tidy/portability/CMakeLists.txt (+1) - (modified) clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp (+3) - (added) clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.cpp (+49) - (added) clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.h (+36) - (modified) clang-tools-extra/docs/ReleaseNotes.rst (+7) - (modified) clang-tools-extra/docs/clang-tidy/checks/list.rst (+1) - (added) clang-tools-extra/docs/clang-tidy/checks/portability/template-virtual-member-function.rst (+33) - (added) clang-tools-extra/test/clang-tidy/checkers/portability/template-virtual-member-function.cpp (+134) ``diff diff --git a/clang-tools-extra/clang-tidy/portability/CMakeLists.txt b/clang-tools-extra/clang-tidy/portability/CMakeLists.txt index 01a86d686daa76..df08cf2c8e292c 100644 --- a/clang-tools-extra/clang-tidy/portability/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/portability/CMakeLists.txt @@ -9,6 +9,7 @@ add_clang_library(clangTidyPortabilityModule RestrictSystemIncludesCheck.cpp SIMDIntrinsicsCheck.cpp StdAllocatorConstCheck.cpp + TemplateVirtualMemberFunctionCheck.cpp LINK_LIBS clangTidy diff --git a/clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp b/clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp index b3759a754587d7..316b98b46cf3f2 100644 --- a/clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp @@ -12,6 +12,7 @@ #include "RestrictSystemIncludesCheck.h" #include "SIMDIntrinsicsCheck.h" #include "StdAllocatorConstCheck.h" +#include "TemplateVirtualMemberFunctionCheck.h" namespace clang::tidy { namespace portability { @@ -25,6 +26,8 @@ class PortabilityModule : public ClangTidyModule { "portability-simd-intrinsics"); CheckFactories.registerCheck( "portability-std-allocator-const"); +CheckFactories.registerCheck( +"portability-template-virtual-member-function"); } }; diff --git a/clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.cpp b/clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.cpp new file mode 100644 index 00..6b7b50798798fa --- /dev/null +++ b/clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.cpp @@ -0,0 +1,49 @@ +//===--- TemplateVirtualMemberFunctionCheck.cpp - clang-tidy +//---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "TemplateVirtualMemberFunctionCheck.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::portability { + +void TemplateVirtualMemberFunctionCheck::registerMatchers(MatchFinder *Finder) { + Finder->addMatcher(classTemplateSpecializationDecl().bind("specialization"), + this); +} + +void TemplateVirtualMemberFunctionCheck::check( +const MatchFinder::MatchResult &Result) { + const auto *MatchedDecl = + Result.Nodes.getNodeAs("specialization"); + + if (MatchedDecl->isExplicitSpecialization()) +return; + + for (auto &&Method : MatchedDecl->methods()) { +if (!Method->isVirtual()) + continue; + +if (const auto *Dtor = llvm::dyn_cast(Method); +Dtor && Dtor->isDefaulted()) + continue; + +if (!Method->isUsed()) { + diag(Method->getLocation(), + "unspecified virtual member function instantia
[clang] [clang-tools-extra] [clang] Extend diagnose_if to accept more detailed warning information (PR #70976)
@@ -489,13 +485,7 @@ static DiagnosticIDs::Level toLevel(diag::Severity SV) { DiagnosticIDs::Level DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, SourceLocation Loc, const DiagnosticsEngine &Diag) const { - // Handle custom diagnostics, which cannot be mapped. kadircet wrote: ok, putting together a revert for https://github.com/llvm/llvm-project/commit/e39205654dc11c50bd117e8ccac243a641ebd71f https://github.com/llvm/llvm-project/pull/70976 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][RISCV] Add preprocessor macros for Zicfilp CFI scheme (PR #109600)
@@ -134,6 +134,25 @@ class RISCVTargetInfo : public TargetInfo { bool validateGlobalRegisterVariable(StringRef RegName, unsigned RegSize, bool &HasSizeMismatch) const override; + + bool checkCFProtectionBranchSupported() const override { +return ISAInfo->hasExtension("zicfilp"); mylai-mtk wrote: Fixed: Always return supported for `-fcf-protection=branch`. https://github.com/llvm/llvm-project/pull/109600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][RISCV] Add preprocessor macros for Zicfilp CFI scheme (PR #109600)
@@ -224,6 +225,34 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions &Opts, else Builder.defineMacro("__riscv_32e"); } + + if (Opts.CFProtectionBranch) { +if (checkCFProtectionBranchSupported()) { + auto Scheme = Opts.getCFBranchLabelScheme(); + if (checkCFBranchLabelSchemeSupported(Scheme)) { +if (Scheme == CFBranchLabelSchemeKind::Default) + Scheme = getDefaultCFBranchLabelScheme(); + +Builder.defineMacro("__riscv_landing_pad", "1"); +switch (Scheme) { +case CFBranchLabelSchemeKind::Unlabeled: + Builder.defineMacro("__riscv_landing_pad_unlabeled", "1"); + break; +case CFBranchLabelSchemeKind::FuncSig: + Builder.defineMacro("__riscv_landing_pad_func_sig", "1"); + break; +case CFBranchLabelSchemeKind::Default: + llvm_unreachable("default cf-branch-label scheme should already be " + "transformed to other scheme"); +} + } else +Diags.Report(diag::err_opt_not_valid_on_target) +<< (Twine("-mcf-branch-label-scheme=") + +getCFBranchLabelSchemeFlagVal(Scheme)) + .str(); +} else + Diags.Report(diag::err_opt_not_valid_on_target) << "cf-protection=branch"; mylai-mtk wrote: No longer relevant: Code removed. https://github.com/llvm/llvm-project/pull/109600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Clang][LLVM][AArch64] Add intrinsic for MOVT SME2 instruction (PR #97602)
https://github.com/CarolineConcatto updated https://github.com/llvm/llvm-project/pull/97602 >From ac405d7516ea92cf3c63220d1bdf0677dd7dd372 Mon Sep 17 00:00:00 2001 From: Caroline Concatto Date: Wed, 3 Jul 2024 15:55:45 + Subject: [PATCH 1/6] [Clang][LLVM][AArch64] Add intrinsic for MOVT SME2 instruction This patch adds these intrinsics: // Variants are also available for: // [_s8], [_u16], [_s16], [_u32], [_s32], [_u64], [_s64] // [_bf16], [_f16], [_f32], [_f64] void svwrite_lane_zt[_u8](uint64_t zt0, svuint8_t zt, uint64_t idx) __arm_streaming __arm_inout("zt0"); void svwrite_zt[_u8](uint64_t zt0, svuint8_t zt) __arm_streaming __arm_inout("zt0"); according to PR#324[1] [1]https://github.com/ARM-software/acle/pull/324 --- clang/include/clang/Basic/arm_sme.td | 6 + .../acle_sme2_write_lane_zt.c | 401 ++ .../aarch64-sme2-intrinsics/acle_sme2_imm.cpp | 15 +- llvm/include/llvm/IR/IntrinsicsAArch64.td | 9 + .../Target/AArch64/AArch64ISelLowering.cpp| 2 + .../lib/Target/AArch64/AArch64SMEInstrInfo.td | 2 +- llvm/lib/Target/AArch64/SMEInstrFormats.td| 42 +- .../AArch64/sme2-intrinsics-read-zt.ll| 162 +++ 8 files changed, 636 insertions(+), 3 deletions(-) create mode 100644 clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_write_lane_zt.c create mode 100644 llvm/test/CodeGen/AArch64/sme2-intrinsics-read-zt.ll diff --git a/clang/include/clang/Basic/arm_sme.td b/clang/include/clang/Basic/arm_sme.td index ae6b55e98827ff..52997f67b5cd9f 100644 --- a/clang/include/clang/Basic/arm_sme.td +++ b/clang/include/clang/Basic/arm_sme.td @@ -817,4 +817,10 @@ multiclass ZAReadzArray{ defm SVREADZ_VG2 : ZAReadzArray<"2">; defm SVREADZ_VG4 : ZAReadzArray<"4">; + +let SMETargetGuard = "sme2,sme-lutv2" in { + def SVLUTI4_ZT_X4 : SInst<"svluti4_zt_{d}_x4", "4i2.u", "cUc", MergeNone, "aarch64_sme_luti4_zt_x4", [IsStreaming, IsInZT0], [ImmCheck<0, ImmCheck0_0>]>; + def SVWRITE_LANE_ZT : SInst<"svwrite_lane_zt[_{d}]", "vidi", "cUcsUsiUilUlfhdb", MergeNone, "aarch64_sme_write_lane_zt", [IsStreaming, IsInOutZT0], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_3>]>; + def SVWRITE_ZT : SInst<"svwrite_zt[_{d}]", "vid", "cUcsUsiUilUlfhdb", MergeNone, "aarch64_sme_write_zt", [IsStreaming, IsInOutZT0], [ImmCheck<0, ImmCheck0_0>]>; +} } // let SVETargetGuard = InvalidMode diff --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_write_lane_zt.c b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_write_lane_zt.c new file mode 100644 index 00..9bdc3481953a21 --- /dev/null +++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_write_lane_zt.c @@ -0,0 +1,401 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5 +// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +bf16 -target-feature +sme -target-feature +sme2 -target-feature +sme-lutv2 -O2 -Werror -Wall -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -x c++ -triple aarch64-none-linux-gnu -target-feature +bf16 -target-feature +sme -target-feature +sme2 -target-feature +sme-lutv2 -O2 -Werror -Wall -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK-CXX +// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu -target-feature +bf16 -target-feature +sme -target-feature +sme2 -target-feature +sme-lutv2 -O2 -Werror -Wall -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -x c++ -triple aarch64-none-linux-gnu -target-feature +bf16 -target-feature +sme -target-feature +sme2 -target-feature +sme-lutv2 -O2 -Werror -Wall -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK-CXX + +// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +bf16 -target-feature +sme -target-feature +sme2 -target-feature +sme-lutv2 -O2 -S -Werror -Wall -o /dev/null %s +// REQUIRES: aarch64-registered-target + +#ifdef SVE_OVERLOADED_FORMS +#define SVE_ACLE_FUNC(A1,A2_UNUSED) A1 +#else +#define SVE_ACLE_FUNC(A1,A2) A1##A2 +#endif + +#include + +// CHECK-LABEL: define dso_local void @test_write_lane_zt_u8_1( +// CHECK-SAME: [[V:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT:tail call void @llvm.aarch64.sme.write.lane.zt.nxv16i8(i32 0, [[V]], i32 1) +// CHECK-NEXT:ret void +// +// CHECK-CXX-LABEL: define dso_local void @_Z23test_write_lane_zt_u8_1u11__SVUint8_t( +// CHECK-CXX-SAME: [[V:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] { +// CHECK-CXX-NEXT: [[ENTRY:.*:]] +// CHECK-CXX-NEXT:tail call void @llvm.aarch64.sme.write.lane.zt.nxv16i8(i32 0, [[V]], i32 1) +// CHECK-CXX-NEXT:ret void +// +void test_write_lane_zt_u8_1(svuint8_t v) __arm_streaming __arm_inout("zt0") { + SVE_ACLE_FUNC(svwrite_lane_zt, _u8)(0, v, 1); +} + +// CHECK-LABEL: define dso_local void @test_write_lane_zt_s8_2( +// CHECK-SAME: [[V:%.*]]) local_unnamed_addr #[[ATTR0]] { +// CHECK-NEXT: [
[clang] e7569b3 - [clang] [Modules] Don't assume an overriden module file can not be out-of-date
Author: Chuanqi Xu Date: 2024-09-26T15:59:02+08:00 New Revision: e7569b30861cce7064fdc7b0e3ad1ee80fbc1fa7 URL: https://github.com/llvm/llvm-project/commit/e7569b30861cce7064fdc7b0e3ad1ee80fbc1fa7 DIFF: https://github.com/llvm/llvm-project/commit/e7569b30861cce7064fdc7b0e3ad1ee80fbc1fa7.diff LOG: [clang] [Modules] Don't assume an overriden module file can not be out-of-date There is an assertion in ModuleFile assumes that an overriden module file can't be out of date. But it is not seriously true in the case clangd. e.g., the source files are overriden, but clangd relies on if the files are out of date to trigger rebuilding preamble. And techniquely, overriden doesn't imply it can't be out of date. This was found during the use clangd of a large code base with modules. Although I failed to reproduce an example, I feel it is fine to land this directly for this particular case. Added: Modified: clang/include/clang/Serialization/ModuleFile.h Removed: diff --git a/clang/include/clang/Serialization/ModuleFile.h b/clang/include/clang/Serialization/ModuleFile.h index 3e920c0f683601..30e7f6b3e57bd8 100644 --- a/clang/include/clang/Serialization/ModuleFile.h +++ b/clang/include/clang/Serialization/ModuleFile.h @@ -88,13 +88,13 @@ class InputFile { InputFile(FileEntryRef File, bool isOverridden = false, bool isOutOfDate = false) { -assert(!(isOverridden && isOutOfDate) && - "an overridden cannot be out-of-date"); unsigned intVal = 0; -if (isOverridden) - intVal = Overridden; -else if (isOutOfDate) +// Make isOutOfDate with higher priority than isOverridden. +// It is possible if the recorded hash value mismatches. +if (isOutOfDate) intVal = OutOfDate; +else if (isOverridden) + intVal = Overridden; Val.setPointerAndInt(&File.getMapEntry(), intVal); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [ItaniumMangle] Use mangleType instead of mangleNameOrStandardSubstitution in mangleCXXCtorVTable function (PR #109970)
https://github.com/tcwzxx updated https://github.com/llvm/llvm-project/pull/109970 >From f9a25251087a160f2dc9e7f589aeb7b215bef60f Mon Sep 17 00:00:00 2001 From: tcwzxx Date: Wed, 25 Sep 2024 19:19:08 +0800 Subject: [PATCH] Rename mangleNameOrStandardSubstitution to mangleCXXRecordDecl and add Record to the substitution --- clang/lib/AST/ItaniumMangle.cpp | 18 ++ clang/test/CodeGenCXX/mangle.cpp | 24 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp index b6e1da0c3192da..2c3321ad564781 100644 --- a/clang/lib/AST/ItaniumMangle.cpp +++ b/clang/lib/AST/ItaniumMangle.cpp @@ -464,7 +464,7 @@ class CXXNameMangler { void mangleSeqID(unsigned SeqID); void mangleName(GlobalDecl GD); void mangleType(QualType T); - void mangleNameOrStandardSubstitution(const NamedDecl *ND); + void mangleCXXRecordDecl(const CXXRecordDecl *Record); void mangleLambdaSig(const CXXRecordDecl *Lambda); void mangleModuleNamePrefix(StringRef Name, bool IsPartition = false); void mangleVendorQualifier(StringRef Name); @@ -3029,9 +3029,11 @@ void CXXNameMangler::mangleType(QualType T) { addSubstitution(T); } -void CXXNameMangler::mangleNameOrStandardSubstitution(const NamedDecl *ND) { - if (!mangleStandardSubstitution(ND)) -mangleName(ND); +void CXXNameMangler::mangleCXXRecordDecl(const CXXRecordDecl *Record) { + if (mangleSubstitution(Record)) +return; + mangleName(Record); + addSubstitution(Record); } void CXXNameMangler::mangleType(const BuiltinType *T) { @@ -7309,7 +7311,7 @@ void ItaniumMangleContextImpl::mangleCXXVTable(const CXXRecordDecl *RD, // ::= TV # virtual table CXXNameMangler Mangler(*this, Out); Mangler.getStream() << "_ZTV"; - Mangler.mangleNameOrStandardSubstitution(RD); + Mangler.mangleCXXRecordDecl(RD); } void ItaniumMangleContextImpl::mangleCXXVTT(const CXXRecordDecl *RD, @@ -7317,7 +7319,7 @@ void ItaniumMangleContextImpl::mangleCXXVTT(const CXXRecordDecl *RD, // ::= TT # VTT structure CXXNameMangler Mangler(*this, Out); Mangler.getStream() << "_ZTT"; - Mangler.mangleNameOrStandardSubstitution(RD); + Mangler.mangleCXXRecordDecl(RD); } void ItaniumMangleContextImpl::mangleCXXCtorVTable(const CXXRecordDecl *RD, @@ -7327,10 +7329,10 @@ void ItaniumMangleContextImpl::mangleCXXCtorVTable(const CXXRecordDecl *RD, // ::= TC _ CXXNameMangler Mangler(*this, Out); Mangler.getStream() << "_ZTC"; - Mangler.mangleNameOrStandardSubstitution(RD); + Mangler.mangleCXXRecordDecl(RD); Mangler.getStream() << Offset; Mangler.getStream() << '_'; - Mangler.mangleNameOrStandardSubstitution(Type); + Mangler.mangleCXXRecordDecl(Type); } void ItaniumMangleContextImpl::mangleCXXRTTI(QualType Ty, raw_ostream &Out) { diff --git a/clang/test/CodeGenCXX/mangle.cpp b/clang/test/CodeGenCXX/mangle.cpp index d0800af55c87e8..848b026028be76 100644 --- a/clang/test/CodeGenCXX/mangle.cpp +++ b/clang/test/CodeGenCXX/mangle.cpp @@ -11,6 +11,8 @@ struct Y { }; //CHECK: @pr5966_i = external global //CHECK: @_ZL8pr5966_j = internal global +//CHECK: @_ZTCN6test624InstE0_NS_1A4ImplINS1_4WrapEEE + // CHECK-LABEL: define{{.*}} zeroext i1 @_ZplRK1YRA100_P1X bool operator+(const Y&, X* (&xs)[100]) { return false; } @@ -1214,3 +1216,25 @@ namespace test61 { // CHECK-LABEL: @_ZN6test611fINS_1XEEEvNT_1Y1aENS3_1bE template void f(int, int); } + +namespace test62 { +namespace A { + +class VBase { + public: + virtual ~VBase() {}; +}; + +struct Wrap {}; + +template +class Impl : public virtual VBase { + public: +}; + +} // namespace A + +struct Inst : public A::Impl {}; + +void Test() { Inst a; } +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] FixedAddressChecker: no warning if system macro is used (PR #108993)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `lldb-aarch64-ubuntu` running on `linaro-lldb-aarch64-ubuntu` while building `clang` at step 6 "test". Full details are available at: https://lab.llvm.org/buildbot/#/builders/59/builds/5613 Here is the relevant piece of the build log for the reference ``` Step 6 (test) failure: build (failure) ... PASS: lldb-api :: functionalities/thread/concurrent_events/TestConcurrentDelayedCrashWithBreakpointSignal.py (611 of 2032) PASS: lldb-api :: functionalities/thread/concurrent_events/TestConcurrentDelayedCrashWithBreakpointWatchpoint.py (612 of 2032) PASS: lldb-api :: functionalities/thread/concurrent_events/TestConcurrentManyBreakpoints.py (613 of 2032) PASS: lldb-api :: functionalities/thread/concurrent_events/TestConcurrentSignalBreak.py (614 of 2032) PASS: lldb-api :: functionalities/thread/concurrent_events/TestConcurrentNWatchNBreak.py (615 of 2032) PASS: lldb-api :: functionalities/thread/concurrent_events/TestConcurrentSignalDelayBreak.py (616 of 2032) PASS: lldb-api :: functionalities/thread/concurrent_events/TestConcurrentManyCrash.py (617 of 2032) PASS: lldb-api :: functionalities/thread/concurrent_events/TestConcurrentManySignals.py (618 of 2032) PASS: lldb-api :: functionalities/thread/concurrent_events/TestConcurrentManyWatchpoints.py (619 of 2032) PASS: lldb-api :: functionalities/thread/concurrent_events/TestConcurrentSignalWatch.py (620 of 2032) FAIL: lldb-api :: functionalities/thread/concurrent_events/TestConcurrentSignalWatchBreak.py (621 of 2032) TEST 'lldb-api :: functionalities/thread/concurrent_events/TestConcurrentSignalWatchBreak.py' FAILED Script: -- /usr/bin/python3.10 /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/dotest.py -u CXXFLAGS -u CFLAGS --env ARCHIVER=/usr/local/bin/llvm-ar --env OBJCOPY=/usr/bin/llvm-objcopy --env LLVM_LIBS_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./lib --env LLVM_INCLUDE_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/include --env LLVM_TOOLS_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin --arch aarch64 --build-dir /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex --lldb-module-cache-dir /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api --clang-module-cache-dir /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex/module-cache-clang/lldb-api --executable /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/lldb --compiler /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/clang --dsymutil /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/dsymutil --llvm-tools-dir /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin --lldb-obj-root /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb --lldb-libs-dir /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./lib /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/functionalities/thread/concurrent_events -p TestConcurrentSignalWatchBreak.py -- Exit Code: 1 Command Output (stdout): -- lldb version 20.0.0git (https://github.com/llvm/llvm-project.git revision ae54a00cc1eb64a0300e190ccdc46ae9b31d2835) clang revision ae54a00cc1eb64a0300e190ccdc46ae9b31d2835 llvm revision ae54a00cc1eb64a0300e190ccdc46ae9b31d2835 Skipping the following test categories: ['libc++', 'dsym', 'gmodules', 'debugserver', 'objc'] Watchpoint 1 hit: old value: 0 new value: 1 -- Command Output (stderr): -- FAIL: LLDB (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: test (TestConcurrentSignalWatchBreak.ConcurrentSignalWatchBreak) == FAIL: test (TestConcurrentSignalWatchBreak.ConcurrentSignalWatchBreak) Test a signal/watchpoint/breakpoint in multiple threads. -- Traceback (most recent call last): File "/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/packages/Python/lldbsuite/test/decorators.py", line 148, in wrapper return func(*args, **kwargs) File "/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/functionalities/thread/concurrent_events/TestConcurrentSignalWatchBreak.py", line 15, in test self.do_thread_actions( File "/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/packages/Python/lldbsuite/test/concurrent_base.py", line 333, in do_thread_actions self.assertEqual( AssertionError: 1 != 2 : Expected 1 stops due to signal delivery, but got 2 Config=aarch64-/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang -- Ran 1 test in 0.628s ``` https://github.com/llvm/llvm-project/pull/108993 _
[clang] [clang][RISCV] Introduce command line options for RISC-V Zicfilp CFI (PR #109784)
kito-cheng wrote: Could you update this PR? https://github.com/llvm/llvm-project/pull/109600/commits/4579272e057e6ec77a2a660384080e1f57a17cf0 is generally LGTM, but I assume this should process within this PR :) https://github.com/llvm/llvm-project/pull/109784 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][RISCV] Add preprocessor macros for Zicfilp CFI scheme (PR #109600)
@@ -0,0 +1,90 @@ +// Default cf-branch-label-scheme is func-sig +// RUN: %clang --target=riscv32 -menable-experimental-extensions \ +// RUN: -march=rv32i_zicfilp1p0 -fcf-protection=branch -E -dM %s -o - \ +// RUN: | FileCheck --check-prefix=CHECK-ZICFILP-FUNC-SIG %s +// RUN: %clang --target=riscv64 -menable-experimental-extensions \ +// RUN: -march=rv64i_zicfilp1p0 -fcf-protection=branch -E -dM %s -o - \ +// RUN: | FileCheck --check-prefix=CHECK-ZICFILP-FUNC-SIG %s + +// RUN: %clang --target=riscv32 -menable-experimental-extensions \ +// RUN: -march=rv32i_zicfilp1p0 -fcf-protection=branch \ +// RUN: -mcf-branch-label-scheme=unlabeled -E -dM %s -o - \ +// RUN: | FileCheck --check-prefix=CHECK-ZICFILP-UNLABELED %s + +// RUN: %clang --target=riscv32 -menable-experimental-extensions \ +// RUN: -march=rv32i_zicfilp1p0 -fcf-protection=branch \ +// RUN: -mcf-branch-label-scheme=func-sig -E -dM %s -o - \ +// RUN: | FileCheck --check-prefix=CHECK-ZICFILP-FUNC-SIG %s + +// RUN: %clang --target=riscv32 -menable-experimental-extensions \ +// RUN: -march=rv32i_zicfilp1p0 -mcf-branch-label-scheme=unlabeled -c %s \ +// RUN: -o /dev/null 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-UNLABELED-SCHEME-UNUSED %s + +// RUN: %clang --target=riscv32 -menable-experimental-extensions \ +// RUN: -march=rv32i_zicfilp1p0 -mcf-branch-label-scheme=func-sig -c %s \ +// RUN: -o /dev/null 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FUNC-SIG-SCHEME-UNUSED %s + +// RUN: not %clang --target=riscv32 -fcf-protection=branch \ +// RUN: -mcf-branch-label-scheme=unlabeled -c %s -o /dev/null 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-BRANCH-PROT-INVALID %s + +// RUN: not %clang --target=riscv32 -fcf-protection=branch \ +// RUN: -mcf-branch-label-scheme=func-sig -c %s -o /dev/null 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-BRANCH-PROT-INVALID %s + +// RUN: %clang --target=riscv32 -mcf-branch-label-scheme=unlabeled -c %s \ +// RUN: -o /dev/null 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-UNLABELED-SCHEME-UNUSED %s + +// RUN: %clang --target=riscv32 -mcf-branch-label-scheme=func-sig -c %s \ +// RUN: -o /dev/null 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FUNC-SIG-SCHEME-UNUSED %s + +// RUN: %clang --target=riscv64 -menable-experimental-extensions \ +// RUN: -march=rv64i_zicfilp1p0 -fcf-protection=branch \ +// RUN: -mcf-branch-label-scheme=unlabeled -E -dM %s -o - \ +// RUN: | FileCheck --check-prefix=CHECK-ZICFILP-UNLABELED %s + +// RUN: %clang --target=riscv64 -menable-experimental-extensions \ +// RUN: -march=rv64i_zicfilp1p0 -fcf-protection=branch \ +// RUN: -mcf-branch-label-scheme=func-sig -E -dM %s -o - \ +// RUN: | FileCheck --check-prefix=CHECK-ZICFILP-FUNC-SIG %s + +// RUN: %clang --target=riscv64 -menable-experimental-extensions \ +// RUN: -march=rv64i_zicfilp1p0 -mcf-branch-label-scheme=unlabeled -c %s \ +// RUN: -o /dev/null 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-UNLABELED-SCHEME-UNUSED %s + +// RUN: %clang --target=riscv64 -menable-experimental-extensions \ +// RUN: -march=rv64i_zicfilp1p0 -mcf-branch-label-scheme=func-sig -c %s \ +// RUN: -o /dev/null 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FUNC-SIG-SCHEME-UNUSED %s + +// RUN: not %clang --target=riscv64 -fcf-protection=branch \ +// RUN: -mcf-branch-label-scheme=unlabeled -c %s -o /dev/null 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-BRANCH-PROT-INVALID %s + +// RUN: not %clang --target=riscv64 -fcf-protection=branch \ +// RUN: -mcf-branch-label-scheme=func-sig -c %s -o /dev/null 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-BRANCH-PROT-INVALID %s + +// RUN: %clang --target=riscv64 -mcf-branch-label-scheme=unlabeled -c %s \ +// RUN: -o /dev/null 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-UNLABELED-SCHEME-UNUSED %s + +// RUN: %clang --target=riscv64 -mcf-branch-label-scheme=func-sig -c %s \ +// RUN: -o /dev/null 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-FUNC-SIG-SCHEME-UNUSED %s + +// CHECK-ZICFILP-UNLABELED-DAG: __riscv_landing_pad 1{{$}} +// CHECK-ZICFILP-UNLABELED-DAG: __riscv_landing_pad_unlabeled 1{{$}} +// CHECK-ZICFILP-FUNC-SIG-DAG: __riscv_landing_pad 1{{$}} +// CHECK-ZICFILP-FUNC-SIG-DAG: __riscv_landing_pad_func_sig 1{{$}} +// CHECK-BRANCH-PROT-INVALID: error: option 'cf-protection=branch' cannot be +// CHECK-BRANCH-PROT-INVALID-SAME: specified on this target +// CHECK-UNLABELED-SCHEME-UNUSED: warning: argument unused during compilation: +// CHECK-UNLABELED-SCHEME-UNUSED-SAME: '-mcf-branch-label-scheme=unlabeled' +// CHECK-FUNC-SIG-SCHEME-UNUSED: warning: argument unused during compilation: +// CHECK-FUNC-SIG-SCHEME-UNUSED-SAME: '-mcf-branch-label-scheme=func-sig' mylai-mtk wrote: Fixed: Since `-fcf-protection=branch` is always supported for RISC-V targets, landing pad macros are no longer absent in the cases of 'no zicfilp + `-fcf-protection=branch`', and this renders all landing pad
[clang] [clang][RISCV] Introduce command line options for RISC-V Zicfilp CFI (PR #109784)
https://github.com/mylai-mtk updated https://github.com/llvm/llvm-project/pull/109784 >From 7aaeaef35f63665bc943efca7ef1b603137522eb Mon Sep 17 00:00:00 2001 From: Ming-Yi Lai Date: Wed, 4 Sep 2024 18:40:48 +0800 Subject: [PATCH] [clang][RISCV] Introduce command line options for Zicfilp-backed forward-edge CFI This patch enables the following command line flags for RISC-V targets: + `-fcf-protection=branch` turns on forward-edge control-flow integrity conditioning on RISC-V targets with Zicfilp extension + `-mcf-branch-label-scheme=unlabeled|func-sig` selects the label scheme used in the forward-edge CFI conditioning --- .../clang/Basic/CFProtectionOptions.def | 15 +++ .../include/clang/Basic/CFProtectionOptions.h | 38 clang/include/clang/Basic/CodeGenOptions.def | 2 + clang/include/clang/Basic/CodeGenOptions.h| 1 + clang/include/clang/Basic/LangOptions.def | 2 + clang/include/clang/Basic/LangOptions.h | 2 + clang/include/clang/Basic/TargetInfo.h| 8 ++ clang/include/clang/Driver/Options.td | 4 + clang/lib/Basic/TargetInfo.cpp| 15 +++ clang/lib/Basic/Targets/RISCV.h | 22 + clang/lib/CodeGen/CodeGenModule.cpp | 10 ++ clang/lib/Driver/ToolChains/Clang.cpp | 4 + clang/lib/Frontend/CompilerInvocation.cpp | 40 .../test/CodeGen/RISCV/riscv-cf-protection.c | 94 +++ 14 files changed, 257 insertions(+) create mode 100644 clang/include/clang/Basic/CFProtectionOptions.def create mode 100644 clang/include/clang/Basic/CFProtectionOptions.h create mode 100644 clang/test/CodeGen/RISCV/riscv-cf-protection.c diff --git a/clang/include/clang/Basic/CFProtectionOptions.def b/clang/include/clang/Basic/CFProtectionOptions.def new file mode 100644 index 00..b9df2de7f7eba0 --- /dev/null +++ b/clang/include/clang/Basic/CFProtectionOptions.def @@ -0,0 +1,15 @@ +//===-- CFProtectionOptions.def - cf-protection options -*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + + +#ifdef CF_BRANCH_LABEL_SCHEME +CF_BRANCH_LABEL_SCHEME(Unlabeled, unlabeled) +CF_BRANCH_LABEL_SCHEME(FuncSig, func-sig) + +#undef CF_BRANCH_LABEL_SCHEME +#endif // #ifdef CF_BRANCH_LABEL_SCHEME diff --git a/clang/include/clang/Basic/CFProtectionOptions.h b/clang/include/clang/Basic/CFProtectionOptions.h new file mode 100644 index 00..13f46d4c13e7e7 --- /dev/null +++ b/clang/include/clang/Basic/CFProtectionOptions.h @@ -0,0 +1,38 @@ +//===--- CFProtectionOptions.h --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// This file defines constants for -fcf-protection and other related flags. +// +//===--===// + +#ifndef LLVM_CLANG_BASIC_CFPROTECTIONOPTIONS_H +#define LLVM_CLANG_BASIC_CFPROTECTIONOPTIONS_H + +#include "llvm/Support/ErrorHandling.h" + +namespace clang { + +enum class CFBranchLabelSchemeKind { + Default, +#define CF_BRANCH_LABEL_SCHEME(Kind, FlagVal) Kind, +#include "clang/Basic/CFProtectionOptions.def" +}; + +static inline const char * +getCFBranchLabelSchemeFlagVal(const CFBranchLabelSchemeKind Scheme) { +#define CF_BRANCH_LABEL_SCHEME(Kind, FlagVal) \ + if (Scheme == CFBranchLabelSchemeKind::Kind) \ +return #FlagVal; +#include "clang/Basic/CFProtectionOptions.def" + + llvm::report_fatal_error("invalid scheme"); +} + +} // namespace clang + +#endif // #ifndef LLVM_CLANG_BASIC_CFPROTECTIONOPTIONS_H diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def index b600198998d85b..de7ae73f8a603b 100644 --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -110,6 +110,8 @@ CODEGENOPT(CFProtectionReturn , 1, 0) ///< if -fcf-protection is ///< set to full or return. CODEGENOPT(CFProtectionBranch , 1, 0) ///< if -fcf-protection is ///< set to full or branch. +ENUM_CODEGENOPT(CFBranchLabelScheme, CFBranchLabelSchemeKind, 2, +CFBranchLabelSchemeKind::Default) ///< if -mcf-branch-label-scheme is set. CODEGENOPT(FunctionReturnThunks, 1, 0) ///< -mfunction-return={keep|thunk-extern} CODEGENOPT(IndirectBranchCSPrefix, 1, 0) ///< if -mindirect-branch-cs-prefix //
[clang] [clang][RISCV] Introduce command line options for RISC-V Zicfilp CFI (PR #109784)
https://github.com/mylai-mtk updated https://github.com/llvm/llvm-project/pull/109784 >From baa87159eb5b6966841bac0a8a089f4ce63d66e2 Mon Sep 17 00:00:00 2001 From: Ming-Yi Lai Date: Wed, 4 Sep 2024 18:40:48 +0800 Subject: [PATCH] [clang][RISCV] Introduce command line options for Zicfilp-backed forward-edge CFI This patch enables the following command line flags for RISC-V targets: + `-fcf-protection=branch` turns on forward-edge control-flow integrity conditioning on RISC-V targets with Zicfilp extension + `-mcf-branch-label-scheme=unlabeled|func-sig` selects the label scheme used in the forward-edge CFI conditioning --- .../clang/Basic/CFProtectionOptions.def | 15 +++ .../include/clang/Basic/CFProtectionOptions.h | 38 clang/include/clang/Basic/CodeGenOptions.def | 2 + clang/include/clang/Basic/CodeGenOptions.h| 1 + clang/include/clang/Basic/LangOptions.def | 2 + clang/include/clang/Basic/LangOptions.h | 2 + clang/include/clang/Basic/TargetInfo.h| 8 ++ clang/include/clang/Driver/Options.td | 4 + clang/lib/Basic/TargetInfo.cpp| 16 clang/lib/Basic/Targets/RISCV.h | 22 + clang/lib/CodeGen/CodeGenModule.cpp | 10 ++ clang/lib/Driver/ToolChains/Clang.cpp | 4 + clang/lib/Frontend/CompilerInvocation.cpp | 40 .../test/CodeGen/RISCV/riscv-cf-protection.c | 94 +++ 14 files changed, 258 insertions(+) create mode 100644 clang/include/clang/Basic/CFProtectionOptions.def create mode 100644 clang/include/clang/Basic/CFProtectionOptions.h create mode 100644 clang/test/CodeGen/RISCV/riscv-cf-protection.c diff --git a/clang/include/clang/Basic/CFProtectionOptions.def b/clang/include/clang/Basic/CFProtectionOptions.def new file mode 100644 index 00..b9df2de7f7eba0 --- /dev/null +++ b/clang/include/clang/Basic/CFProtectionOptions.def @@ -0,0 +1,15 @@ +//===-- CFProtectionOptions.def - cf-protection options -*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + + +#ifdef CF_BRANCH_LABEL_SCHEME +CF_BRANCH_LABEL_SCHEME(Unlabeled, unlabeled) +CF_BRANCH_LABEL_SCHEME(FuncSig, func-sig) + +#undef CF_BRANCH_LABEL_SCHEME +#endif // #ifdef CF_BRANCH_LABEL_SCHEME diff --git a/clang/include/clang/Basic/CFProtectionOptions.h b/clang/include/clang/Basic/CFProtectionOptions.h new file mode 100644 index 00..13f46d4c13e7e7 --- /dev/null +++ b/clang/include/clang/Basic/CFProtectionOptions.h @@ -0,0 +1,38 @@ +//===--- CFProtectionOptions.h --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// This file defines constants for -fcf-protection and other related flags. +// +//===--===// + +#ifndef LLVM_CLANG_BASIC_CFPROTECTIONOPTIONS_H +#define LLVM_CLANG_BASIC_CFPROTECTIONOPTIONS_H + +#include "llvm/Support/ErrorHandling.h" + +namespace clang { + +enum class CFBranchLabelSchemeKind { + Default, +#define CF_BRANCH_LABEL_SCHEME(Kind, FlagVal) Kind, +#include "clang/Basic/CFProtectionOptions.def" +}; + +static inline const char * +getCFBranchLabelSchemeFlagVal(const CFBranchLabelSchemeKind Scheme) { +#define CF_BRANCH_LABEL_SCHEME(Kind, FlagVal) \ + if (Scheme == CFBranchLabelSchemeKind::Kind) \ +return #FlagVal; +#include "clang/Basic/CFProtectionOptions.def" + + llvm::report_fatal_error("invalid scheme"); +} + +} // namespace clang + +#endif // #ifndef LLVM_CLANG_BASIC_CFPROTECTIONOPTIONS_H diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def index b600198998d85b..de7ae73f8a603b 100644 --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -110,6 +110,8 @@ CODEGENOPT(CFProtectionReturn , 1, 0) ///< if -fcf-protection is ///< set to full or return. CODEGENOPT(CFProtectionBranch , 1, 0) ///< if -fcf-protection is ///< set to full or branch. +ENUM_CODEGENOPT(CFBranchLabelScheme, CFBranchLabelSchemeKind, 2, +CFBranchLabelSchemeKind::Default) ///< if -mcf-branch-label-scheme is set. CODEGENOPT(FunctionReturnThunks, 1, 0) ///< -mfunction-return={keep|thunk-extern} CODEGENOPT(IndirectBranchCSPrefix, 1, 0) ///< if -mindirect-branch-cs-prefix /
[clang-tools-extra] [clangd] Improve filtering logic for undesired proto symbols (PR #110091)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff 7645d9c77d390cff68ec2d253bc5b23c37bc665f 48e17de386d504f01cf89dba1f7bd445b4ce78e4 --extensions cpp -- clang-tools-extra/clangd/index/SymbolCollector.cpp clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp `` View the diff from clang-format here. ``diff diff --git a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp index 785a2fb294..e8088cb37f 100644 --- a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp +++ b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp @@ -258,7 +258,6 @@ TEST_F(ShouldCollectSymbolTest, NoPrivateProtoSymbol) { // with parent's name. EXPECT_FALSE(shouldCollect("nx::Foo::Foo_VAL2")); EXPECT_FALSE(shouldCollect("nx::Foo_VAL2")); - } TEST_F(ShouldCollectSymbolTest, DoubleCheckProtoHeaderComment) { `` https://github.com/llvm/llvm-project/pull/110091 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] Fix installation w/ ENABLE_RUNTIME_SUBNORMAL (PR #109926)
https://github.com/frasercrmck edited https://github.com/llvm/llvm-project/pull/109926 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] Fix installation w/ ENABLE_RUNTIME_SUBNORMAL (PR #109926)
https://github.com/frasercrmck edited https://github.com/llvm/llvm-project/pull/109926 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] Fix installation w/ ENABLE_RUNTIME_SUBNORMAL (PR #109926)
@@ -221,8 +221,10 @@ if( ENABLE_RUNTIME_SUBNORMAL ) TARGET ${file} INPUTS ${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/${file}.ll ) -install( FILES $ ARCHIVE - DESTINATION "${CMAKE_INSTALL_DATADIR}/clc" ) +install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/$ frasercrmck wrote: I've updated the patch to set `TARGET_FILE` absolutely. https://github.com/llvm/llvm-project/pull/109926 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] Fix installation w/ ENABLE_RUNTIME_SUBNORMAL (PR #109926)
https://github.com/frasercrmck updated https://github.com/llvm/llvm-project/pull/109926 >From 567ea02fda22989a5af89746dbc5ed6eac0a43d9 Mon Sep 17 00:00:00 2001 From: Fraser Cormack Date: Wed, 25 Sep 2024 09:18:10 +0100 Subject: [PATCH] [libclc] Fix installation w/ ENABLE_RUNTIME_SUBNORMAL The ARCHIVE artifact kind is not valid for install(FILES ...). Additionally, install wasn't resolving the target's TARGET_FILE properly and was trying to find it in the top-level build directory, rather than in the libclc binary directory. This is because our TARGET_FILE properties were being set to relative paths. The cmake behaviour they are trying to mimic - $ - provides an absolute path. As such this patch updates instances where we set the TARGET_FILE property to return an absolute path. --- libclc/CMakeLists.txt| 12 +++- libclc/cmake/modules/AddLibclc.cmake | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt index 1bf7eb2ca7ed7e..260e4d433a1d49 100644 --- a/libclc/CMakeLists.txt +++ b/libclc/CMakeLists.txt @@ -221,8 +221,10 @@ if( ENABLE_RUNTIME_SUBNORMAL ) TARGET ${file} INPUTS ${CMAKE_CURRENT_SOURCE_DIR}/generic/lib/${file}.ll ) -install( FILES $ ARCHIVE - DESTINATION "${CMAKE_INSTALL_DATADIR}/clc" ) +install( + FILES $ + DESTINATION "${CMAKE_INSTALL_DATADIR}/clc" +) endforeach() endif() @@ -426,9 +428,9 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} ) add_custom_target( ${builtins_opt_lib_tgt} ALL DEPENDS ${builtins_opt_lib_tgt}.bc ) - set_target_properties( ${builtins_opt_lib_tgt} -PROPERTIES TARGET_FILE ${builtins_opt_lib_tgt}.bc - FOLDER "libclc/Device IR/Opt" + set_target_properties( ${builtins_opt_lib_tgt} PROPERTIES +TARGET_FILE ${CMAKE_CURRENT_BINARY_DIR}/${builtins_opt_lib_tgt}.bc +FOLDER "libclc/Device IR/Opt" ) set( builtins_opt_lib $ ) diff --git a/libclc/cmake/modules/AddLibclc.cmake b/libclc/cmake/modules/AddLibclc.cmake index 839815d8cc6fff..f2032660ba99b0 100644 --- a/libclc/cmake/modules/AddLibclc.cmake +++ b/libclc/cmake/modules/AddLibclc.cmake @@ -113,7 +113,7 @@ function(link_bc) add_custom_target( ${ARG_TARGET} ALL DEPENDS ${ARG_TARGET}.bc ) set_target_properties( ${ARG_TARGET} PROPERTIES -TARGET_FILE ${ARG_TARGET}.bc +TARGET_FILE ${CMAKE_CURRENT_BINARY_DIR}/${ARG_TARGET}.bc FOLDER "libclc/Device IR/Linking" ) endfunction() ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][RISCV] Introduce command line options for RISC-V Zicfilp CFI (PR #109784)
@@ -198,6 +198,21 @@ TargetInfo::checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const { return false; } +CFBranchLabelSchemeKind TargetInfo::getDefaultCFBranchLabelScheme() const { + // if this hook is called, the target should override it to return a + // non-default scheme + llvm::report_fatal_error("not implemented"); +} + +bool TargetInfo::checkCFBranchLabelSchemeSupported( +const CFBranchLabelSchemeKind Scheme, DiagnosticsEngine &Diags) const { + Diags.Report(diag::err_opt_not_valid_on_target) mylai-mtk wrote: Fixed https://github.com/llvm/llvm-project/pull/109784 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [AArch64] Split FeatureMTE to FEAT_MTE and FEAT_MTE2. (PR #109299)
labrinea wrote: > I don't quite get the code, but it seems that +mte or +mte2 may be emitted in > disassembly and/or supported by the assembler? They are supported in assembler for the sole purpose of providing more informative error messages. https://github.com/llvm/llvm-project/pull/109299 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ARM] Fix musttail calls (PR #109943)
@@ -12658,10 +12658,10 @@ This instruction requires several arguments: the return value of the callee is returned to the caller's caller, even if a void return type is in use. - Both markers imply that the callee does not access allocas from the caller. - The ``tail`` marker additionally implies that the callee does not access - varargs from the caller. Calls marked ``musttail`` must obey the following - additional rules: + Both markers imply that the callee does not access allocas or ``byval`` + arguments from the caller. The ``tail`` marker additionally implies that the ostannard wrote: That was my intention, but the wording here didn't allow it. I've split the langref change out into #110093, and updated the wording. I'll leave the old patch in here for now to avoid a force-push. https://github.com/llvm/llvm-project/pull/109943 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][x86] Add constexpr support for BMI/TBM BEXTR intrinsics (PR #109577)
RKSimon wrote: ping - any thoughts on this? https://github.com/llvm/llvm-project/pull/109577 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Portability Template Virtual Member Function Check (PR #110099)
github-actions[bot] wrote: ⚠️ We detected that you are using a GitHub private e-mail address to contribute to the repo. Please turn off [Keep my email addresses private](https://github.com/settings/emails) setting in your account. See [LLVM Discourse](https://discourse.llvm.org/t/hidden-emails-on-github-should-we-do-something-about-it) for more information. https://github.com/llvm/llvm-project/pull/110099 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Index][USR][NFC] Allow customizing langopts for USR generation (PR #109574)
steakhal wrote: For example the following code would get different USRs in C and C++: ```c++ static int f1(int* x); // USR in C: c:input.cc@F@f1 // USR in C++: c:input.cc@F@f1#*I# ``` So by having this patch, it would be possible to generate the C++ USR even if the AST (thus the ASTContext) was produced for a C compiler invocation. https://github.com/llvm/llvm-project/pull/109574 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][RISCV] Introduce command line options for RISC-V Zicfilp CFI (PR #109784)
https://github.com/kito-cheng approved this pull request. Still LGTM https://github.com/llvm/llvm-project/pull/109784 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [FMV][RISCV] Add __riscv_feature_bits.length check (PR #110098)
@@ -2970,22 +2974,28 @@ void CodeGenFunction::EmitRISCVMultiVersionResolver( // (__riscv_feature_bits.features[i] & REQUIRED_BITMASK) == // REQUIRED_BITMASK // +// First, check __riscv_feature_bits.length <= +// llvm::RISCVISAInfo::FeatureBitSize. This ensures that the +// __riscv_feature_bits object at runtime has the same length as on the +// compiler side. +// +// Second, // When condition is met, return this version of the function. // Otherwise, try the next version. // -// if (FeaturesConditionVersion1) +// +// if (__riscv_feature_bits.features.length <= jrtc27 wrote: >=, surely? But also this should be per set of features being tested, and >specific to the min length needed for that, not apply to all versions. >Otherwise if the compiler learns about a new word but is run on an older OS it >will stop using optimised versions. https://github.com/llvm/llvm-project/pull/110098 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [FMV][RISCV] Add __riscv_feature_bits.length check (PR #110098)
https://github.com/jrtc27 edited https://github.com/llvm/llvm-project/pull/110098 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ARM] [AArch32] Add support for Arm China STAR-MC1 CPU (PR #110085)
https://github.com/AlbertHuang-CPU updated https://github.com/llvm/llvm-project/pull/110085 >From a0c620f312382391cdc5e444a0c847cb2ebd23aa Mon Sep 17 00:00:00 2001 From: albhua01 Date: Thu, 26 Sep 2024 15:22:09 +0800 Subject: [PATCH 1/2] [ARM] [AArch32] Add support for Arm China STAR-MC1 CPU --- llvm/include/llvm/TargetParser/ARMTargetParser.def | 1 + llvm/lib/Target/ARM/ARMProcessors.td | 10 ++ llvm/lib/TargetParser/Host.cpp | 6 ++ llvm/unittests/TargetParser/TargetParserTest.cpp | 5 - 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/llvm/include/llvm/TargetParser/ARMTargetParser.def b/llvm/include/llvm/TargetParser/ARMTargetParser.def index e5a1ce54fd46a7..95dc24931e00c0 100644 --- a/llvm/include/llvm/TargetParser/ARMTargetParser.def +++ b/llvm/include/llvm/TargetParser/ARMTargetParser.def @@ -337,6 +337,7 @@ ARM_CPU_NAME("cortex-m4", ARMV7EM, FK_FPV4_SP_D16, true, ARM::AEK_NONE) ARM_CPU_NAME("cortex-m7", ARMV7EM, FK_FPV5_D16, false, ARM::AEK_NONE) ARM_CPU_NAME("cortex-m23", ARMV8MBaseline, FK_NONE, false, ARM::AEK_NONE) ARM_CPU_NAME("cortex-m33", ARMV8MMainline, FK_FPV5_SP_D16, false, ARM::AEK_DSP) +ARM_CPU_NAME("star-mc1", ARMV8MMainline, FK_FPV5_SP_D16, false, ARM::AEK_DSP) ARM_CPU_NAME("cortex-m35p", ARMV8MMainline, FK_FPV5_SP_D16, false, ARM::AEK_DSP) ARM_CPU_NAME("cortex-m55", ARMV8_1MMainline, FK_FP_ARMV8_FULLFP16_D16, false, (ARM::AEK_DSP | ARM::AEK_SIMD | ARM::AEK_FP | ARM::AEK_FP16)) diff --git a/llvm/lib/Target/ARM/ARMProcessors.td b/llvm/lib/Target/ARM/ARMProcessors.td index a66a2c0b1981d8..293f1fabda7b4c 100644 --- a/llvm/lib/Target/ARM/ARMProcessors.td +++ b/llvm/lib/Target/ARM/ARMProcessors.td @@ -362,6 +362,16 @@ def : ProcessorModel<"cortex-m33", CortexM4Model, [ARMv8mMainline, FeatureHasNoBranchPredictor, FeatureFixCMSE_CVE_2021_35465]>; +def : ProcessorModel<"star-mc1", CortexM4Model, [ARMv8mMainline, + FeatureDSP, + FeatureFPARMv8_D16_SP, + FeaturePrefLoopAlign32, + FeatureHasSlowFPVMLx, + FeatureHasSlowFPVFMx, + FeatureUseMISched, + FeatureHasNoBranchPredictor, + FeatureFixCMSE_CVE_2021_35465]>; + def : ProcessorModel<"cortex-m35p", CortexM4Model, [ARMv8mMainline, FeatureDSP, FeatureFPARMv8_D16_SP, diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp index 616e4eda1dd29d..1500c71f4039b5 100644 --- a/llvm/lib/TargetParser/Host.cpp +++ b/llvm/lib/TargetParser/Host.cpp @@ -342,6 +342,12 @@ StringRef sys::detail::getHostCPUNameForARM(StringRef ProcCpuinfoContent) { } } + if (Implementer == "0x63") { // Arm China. +return StringSwitch(Part) +.Case("0x132", "star-mc1") +.Default("generic"); + } + if (Implementer == "0x6d") { // Microsoft Corporation. // The Microsoft Azure Cobalt 100 CPU is handled as a Neoverse N2. return StringSwitch(Part) diff --git a/llvm/unittests/TargetParser/TargetParserTest.cpp b/llvm/unittests/TargetParser/TargetParserTest.cpp index 13db80ab5c68ea..7b86290a71ee4a 100644 --- a/llvm/unittests/TargetParser/TargetParserTest.cpp +++ b/llvm/unittests/TargetParser/TargetParserTest.cpp @@ -490,6 +490,9 @@ INSTANTIATE_TEST_SUITE_P( ARMCPUTestParams("cortex-m33", "armv8-m.main", "fpv5-sp-d16", ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP, "8-M.Mainline"), +ARMCPUTestParams("star-mc1", "armv8-m.main", "fpv5-sp-d16", + ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP, + "8-M.Mainline"), ARMCPUTestParams("cortex-m35p", "armv8-m.main", "fpv5-sp-d16", ARM::AEK_HWDIVTHUMB | ARM::AEK_DSP, "8-M.Mainline"), @@ -518,7 +521,7 @@ INSTANTIATE_TEST_SUITE_P( "7-S")), ARMCPUTestParams::PrintToStringParamName); -static constexpr unsigned NumARMCPUArchs = 92; +static constexpr unsigned NumARMCPUArchs = 93; TEST(TargetParserTest, testARMCPUArchList) { SmallVector List; >From 2cdf4d670f6e958baa1f2450e34c4060d4d4aee1 Mon Sep 17 00:00:00 2001 From: albhua01 Date: Thu, 26 Sep 2024 18:03:47 +0800 Subject: [PATCH 2/2] amending for review comment --- clang/test/Misc/target
[clang] [clang][RISCV] Introduce command line options for RISC-V Zicfilp CFI (PR #109784)
mylai-mtk wrote: Thanks :D https://github.com/llvm/llvm-project/pull/109784 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 9f33eb8 - [clang][RISCV] Introduce command line options for RISC-V Zicfilp CFI
Author: Ming-Yi Lai Date: 2024-09-26T18:30:43+08:00 New Revision: 9f33eb861a3d17fd92163ee894f7cd9f256d03fb URL: https://github.com/llvm/llvm-project/commit/9f33eb861a3d17fd92163ee894f7cd9f256d03fb DIFF: https://github.com/llvm/llvm-project/commit/9f33eb861a3d17fd92163ee894f7cd9f256d03fb.diff LOG: [clang][RISCV] Introduce command line options for RISC-V Zicfilp CFI This patch enables the following command line flags for RISC-V targets: + `-fcf-protection=branch` turns on forward-edge control-flow integrity conditioning + `-mcf-branch-label-scheme=unlabeled|func-sig` selects the label scheme used in the forward-edge CFI conditioning Added: clang/include/clang/Basic/CFProtectionOptions.def clang/include/clang/Basic/CFProtectionOptions.h clang/test/CodeGen/RISCV/riscv-cf-protection.c Modified: clang/include/clang/Basic/CodeGenOptions.def clang/include/clang/Basic/CodeGenOptions.h clang/include/clang/Basic/LangOptions.def clang/include/clang/Basic/LangOptions.h clang/include/clang/Basic/TargetInfo.h clang/include/clang/Driver/Options.td clang/lib/Basic/TargetInfo.cpp clang/lib/Basic/Targets/RISCV.h clang/lib/CodeGen/CodeGenModule.cpp clang/lib/Driver/ToolChains/Clang.cpp clang/lib/Frontend/CompilerInvocation.cpp Removed: diff --git a/clang/include/clang/Basic/CFProtectionOptions.def b/clang/include/clang/Basic/CFProtectionOptions.def new file mode 100644 index 00..b9df2de7f7eba0 --- /dev/null +++ b/clang/include/clang/Basic/CFProtectionOptions.def @@ -0,0 +1,15 @@ +//===-- CFProtectionOptions.def - cf-protection options -*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + + +#ifdef CF_BRANCH_LABEL_SCHEME +CF_BRANCH_LABEL_SCHEME(Unlabeled, unlabeled) +CF_BRANCH_LABEL_SCHEME(FuncSig, func-sig) + +#undef CF_BRANCH_LABEL_SCHEME +#endif // #ifdef CF_BRANCH_LABEL_SCHEME diff --git a/clang/include/clang/Basic/CFProtectionOptions.h b/clang/include/clang/Basic/CFProtectionOptions.h new file mode 100644 index 00..13f46d4c13e7e7 --- /dev/null +++ b/clang/include/clang/Basic/CFProtectionOptions.h @@ -0,0 +1,38 @@ +//===--- CFProtectionOptions.h --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// This file defines constants for -fcf-protection and other related flags. +// +//===--===// + +#ifndef LLVM_CLANG_BASIC_CFPROTECTIONOPTIONS_H +#define LLVM_CLANG_BASIC_CFPROTECTIONOPTIONS_H + +#include "llvm/Support/ErrorHandling.h" + +namespace clang { + +enum class CFBranchLabelSchemeKind { + Default, +#define CF_BRANCH_LABEL_SCHEME(Kind, FlagVal) Kind, +#include "clang/Basic/CFProtectionOptions.def" +}; + +static inline const char * +getCFBranchLabelSchemeFlagVal(const CFBranchLabelSchemeKind Scheme) { +#define CF_BRANCH_LABEL_SCHEME(Kind, FlagVal) \ + if (Scheme == CFBranchLabelSchemeKind::Kind) \ +return #FlagVal; +#include "clang/Basic/CFProtectionOptions.def" + + llvm::report_fatal_error("invalid scheme"); +} + +} // namespace clang + +#endif // #ifndef LLVM_CLANG_BASIC_CFPROTECTIONOPTIONS_H diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def index 2893377e5a38be..eac831278ee20d 100644 --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -111,6 +111,8 @@ CODEGENOPT(CFProtectionReturn , 1, 0) ///< if -fcf-protection is ///< set to full or return. CODEGENOPT(CFProtectionBranch , 1, 0) ///< if -fcf-protection is ///< set to full or branch. +ENUM_CODEGENOPT(CFBranchLabelScheme, CFBranchLabelSchemeKind, 2, +CFBranchLabelSchemeKind::Default) ///< if -mcf-branch-label-scheme is set. CODEGENOPT(FunctionReturnThunks, 1, 0) ///< -mfunction-return={keep|thunk-extern} CODEGENOPT(IndirectBranchCSPrefix, 1, 0) ///< if -mindirect-branch-cs-prefix ///< is set. diff --git a/clang/include/clang/Basic/CodeGenOptions.h b/clang/include/clang/Basic/CodeGenOptions.h index 814d4d4c99e575..2dcf98b465661e 100644 --- a/clang/include/clang/Basic/CodeGenOptions.h +++ b/clang/include/clang/Basic/CodeGenOptions.h @@ -13,6 +13,7 @@ #if
[clang] [clang][RISCV] Introduce command line options for RISC-V Zicfilp CFI (PR #109784)
https://github.com/mylai-mtk closed https://github.com/llvm/llvm-project/pull/109784 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Add fake use emission to Clang with -fextend-lifetimes (PR #110102)
https://github.com/SLTozer created https://github.com/llvm/llvm-project/pull/110102 Following the [previous patch](https://github.com/llvm/llvm-project/pull/11) which adds the "extend lifetimes" flag without (almost) any functionality, this patch adds the real feature by allowing Clang to emit fake uses. These are emitted as a new form of cleanup, set for variable addresses, which just emits a fake use intrinsic when the variable falls out of scope. The code for achieving this is simple, with most of the logic centered on determining whether to emit a fake use for a given address, and on ensuring that fake uses are ignored in a few cases. All code originally written by @wolfy1961, while I'll be handling the review. >From e04a16c6d51539421dd134f7524641e843f5d555 Mon Sep 17 00:00:00 2001 From: Stephen Tozer Date: Wed, 25 Sep 2024 16:55:39 +0100 Subject: [PATCH] [Clang] Add fake use emission to Clang with -fextend-lifetimes Following the previous patch which adds the "extend lifetimes" flag without (almost) any functionality, this patch adds the real feature by allowing Clang to emit fake uses. These are emitted as a new form of cleanup, set for variable addresses, which just emits a fake use intrinsic when the variable falls out of scope. The code for achieving this is simple, with most of the logic centered on determining whether to emit a fake use for a given address, and on ensuring that fake uses are ignored in a few cases. --- clang/lib/CodeGen/CGCall.cpp | 30 ++ clang/lib/CodeGen/CGCleanup.cpp | 7 ++- clang/lib/CodeGen/CGCleanup.h | 8 +++ clang/lib/CodeGen/CGDecl.cpp | 69 +++ clang/lib/CodeGen/CodeGenFunction.cpp | 6 +- clang/lib/CodeGen/CodeGenFunction.h | 16 ++ clang/lib/CodeGen/CodeGenModule.h | 4 ++ clang/lib/CodeGen/EHScopeStack.h | 9 ++- clang/test/CodeGen/extend-liveness1.c | 29 ++ clang/test/CodeGen/extend-liveness2.cpp | 34 +++ clang/test/CodeGen/fake-use-determinism.c | 18 ++ clang/test/CodeGen/fake-use-lambda.cpp| 43 ++ clang/test/CodeGen/fake-use-landingpad.c | 16 ++ clang/test/CodeGen/fake-use-noreturn.cpp | 27 + clang/test/CodeGen/fake-use-return-line.c | 15 + clang/test/CodeGen/fake-use-sanitizer.cpp | 37 clang/test/CodeGen/fake-use-scalar.c | 22 clang/test/CodeGen/fake-use-small-aggs.c | 24 clang/test/CodeGen/fake-use-while.c | 18 ++ clang/test/CodeGen/fake-use.cpp | 44 +++ clang/test/CodeGen/no-fake-use-O0.cpp | 50 21 files changed, 509 insertions(+), 17 deletions(-) create mode 100644 clang/test/CodeGen/extend-liveness1.c create mode 100644 clang/test/CodeGen/extend-liveness2.cpp create mode 100644 clang/test/CodeGen/fake-use-determinism.c create mode 100644 clang/test/CodeGen/fake-use-lambda.cpp create mode 100644 clang/test/CodeGen/fake-use-landingpad.c create mode 100644 clang/test/CodeGen/fake-use-noreturn.cpp create mode 100644 clang/test/CodeGen/fake-use-return-line.c create mode 100644 clang/test/CodeGen/fake-use-sanitizer.cpp create mode 100644 clang/test/CodeGen/fake-use-scalar.c create mode 100644 clang/test/CodeGen/fake-use-small-aggs.c create mode 100644 clang/test/CodeGen/fake-use-while.c create mode 100644 clang/test/CodeGen/fake-use.cpp create mode 100644 clang/test/CodeGen/no-fake-use-O0.cpp diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 4ae981e4013e9c..13c556a4e20a13 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -3566,16 +3566,26 @@ static llvm::StoreInst *findDominatingStoreToReturnValue(CodeGenFunction &CGF) { llvm::BasicBlock *IP = CGF.Builder.GetInsertBlock(); if (IP->empty()) return nullptr; -// Look at directly preceding instruction, skipping bitcasts and lifetime -// markers. -for (llvm::Instruction &I : make_range(IP->rbegin(), IP->rend())) { - if (isa(&I)) -continue; - if (auto *II = dyn_cast(&I)) -if (II->getIntrinsicID() == llvm::Intrinsic::lifetime_end) - continue; - - return GetStoreIfValid(&I); + // Look at directly preceding instruction, skipping bitcasts, lifetime + // markers, and fake uses and their operands. + const llvm::Instruction *LoadIntoFakeUse = nullptr; + for (llvm::Instruction &I : make_range(IP->rbegin(), IP->rend())) { + // Ignore instructions that are just loads for fake uses; the load should + // immediately precede the fake use, so we only need to remember the + // operand for the last fake use seen. + if (LoadIntoFakeUse == &I) + continue; + if (isa(&I)) + continue; + if (auto *II = dyn_cast(&I)) { + if (II->getIntrinsicID() == llvm::Intrinsic::lifetime_end) + continue; + + if (II->getIntrinsicID() == llvm::Intrinsic::fake_use) { +
[clang] [Clang][Driver] Add option to provide path for multilib's YAML config file (PR #109640)
@@ -1,79 +1,79 @@ -// RUN: %clang -print-multi-flags-experimental --target=aarch64-linux -fc++-abi=itanium -fsanitize=address | FileCheck --check-prefix=CHECK-LINUX %s +// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml -print-multi-flags-experimental --target=aarch64-linux -fc++-abi=itanium -fsanitize=address | FileCheck --check-prefix=CHECK-LINUX %s ostannard wrote: This is needed since #105684 allows reporting errors from multilib.yaml for option combination there is no library for. This causes the tests to fail when building clang as part of https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm, which has a multilib.yaml which uses that feature. Adding the option here makes the tests independent of other parts of the toolchain it is built into. https://github.com/llvm/llvm-project/pull/109640 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] return first Decl for CanonicalDecl in TranslationUnitDecl (PR #110101)
https://github.com/Vipul-Cariappa created https://github.com/llvm/llvm-project/pull/110101 Return the first `Decl` when using `TranslationUnitDecl::getCanonicalDecl` >From 43d0e353e6e5870cf601ea83d072d8c05dbe94eb Mon Sep 17 00:00:00 2001 From: Vipul Cariappa Date: Thu, 26 Sep 2024 10:28:02 + Subject: [PATCH] [clang] return first Decl for CanonicalDecl in TranslationUnitDecl --- clang/include/clang/AST/Decl.h | 4 1 file changed, 4 insertions(+) diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h index 0600ecc4d14a18..7ff35d73df5997 100644 --- a/clang/include/clang/AST/Decl.h +++ b/clang/include/clang/AST/Decl.h @@ -133,6 +133,10 @@ class TranslationUnitDecl : public Decl, static TranslationUnitDecl *castFromDeclContext(const DeclContext *DC) { return static_cast(const_cast(DC)); } + + /// Retrieves the canonical declaration of this translation unit. + TranslationUnitDecl *getCanonicalDecl() override { return getFirstDecl(); } + const TranslationUnitDecl *getCanonicalDecl() const { return getFirstDecl(); } }; /// Represents a `#pragma comment` line. Always a child of ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] return first Decl for CanonicalDecl in TranslationUnitDecl (PR #110101)
github-actions[bot] wrote: Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using `@` followed by their GitHub username. If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html). You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/). https://github.com/llvm/llvm-project/pull/110101 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Add fake use emission to Clang with -fextend-lifetimes (PR #110102)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Stephen Tozer (SLTozer) Changes Following the [previous patch](https://github.com/llvm/llvm-project/pull/11) which adds the "extend lifetimes" flag without (almost) any functionality, this patch adds the real feature by allowing Clang to emit fake uses. These are emitted as a new form of cleanup, set for variable addresses, which just emits a fake use intrinsic when the variable falls out of scope. The code for achieving this is simple, with most of the logic centered on determining whether to emit a fake use for a given address, and on ensuring that fake uses are ignored in a few cases. All code originally written by @wolfy1961, while I'll be handling the review. --- Patch is 26.63 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/110102.diff 21 Files Affected: - (modified) clang/lib/CodeGen/CGCall.cpp (+20-10) - (modified) clang/lib/CodeGen/CGCleanup.cpp (+5-2) - (modified) clang/lib/CodeGen/CGCleanup.h (+8) - (modified) clang/lib/CodeGen/CGDecl.cpp (+69) - (modified) clang/lib/CodeGen/CodeGenFunction.cpp (+3-3) - (modified) clang/lib/CodeGen/CodeGenFunction.h (+16) - (modified) clang/lib/CodeGen/CodeGenModule.h (+4) - (modified) clang/lib/CodeGen/EHScopeStack.h (+7-2) - (added) clang/test/CodeGen/extend-liveness1.c (+29) - (added) clang/test/CodeGen/extend-liveness2.cpp (+34) - (added) clang/test/CodeGen/fake-use-determinism.c (+18) - (added) clang/test/CodeGen/fake-use-lambda.cpp (+43) - (added) clang/test/CodeGen/fake-use-landingpad.c (+16) - (added) clang/test/CodeGen/fake-use-noreturn.cpp (+27) - (added) clang/test/CodeGen/fake-use-return-line.c (+15) - (added) clang/test/CodeGen/fake-use-sanitizer.cpp (+37) - (added) clang/test/CodeGen/fake-use-scalar.c (+22) - (added) clang/test/CodeGen/fake-use-small-aggs.c (+24) - (added) clang/test/CodeGen/fake-use-while.c (+18) - (added) clang/test/CodeGen/fake-use.cpp (+44) - (added) clang/test/CodeGen/no-fake-use-O0.cpp (+50) ``diff diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 4ae981e4013e9c..13c556a4e20a13 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -3566,16 +3566,26 @@ static llvm::StoreInst *findDominatingStoreToReturnValue(CodeGenFunction &CGF) { llvm::BasicBlock *IP = CGF.Builder.GetInsertBlock(); if (IP->empty()) return nullptr; -// Look at directly preceding instruction, skipping bitcasts and lifetime -// markers. -for (llvm::Instruction &I : make_range(IP->rbegin(), IP->rend())) { - if (isa(&I)) -continue; - if (auto *II = dyn_cast(&I)) -if (II->getIntrinsicID() == llvm::Intrinsic::lifetime_end) - continue; - - return GetStoreIfValid(&I); + // Look at directly preceding instruction, skipping bitcasts, lifetime + // markers, and fake uses and their operands. + const llvm::Instruction *LoadIntoFakeUse = nullptr; + for (llvm::Instruction &I : make_range(IP->rbegin(), IP->rend())) { + // Ignore instructions that are just loads for fake uses; the load should + // immediately precede the fake use, so we only need to remember the + // operand for the last fake use seen. + if (LoadIntoFakeUse == &I) + continue; + if (isa(&I)) + continue; + if (auto *II = dyn_cast(&I)) { + if (II->getIntrinsicID() == llvm::Intrinsic::lifetime_end) + continue; + + if (II->getIntrinsicID() == llvm::Intrinsic::fake_use) { + LoadIntoFakeUse = dyn_cast(II->getArgOperand(0)); + continue; + } + } return GetStoreIfValid(&I); } return nullptr; } diff --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp index 5d253c92a38a81..82532e182bebbd 100644 --- a/clang/lib/CodeGen/CGCleanup.cpp +++ b/clang/lib/CodeGen/CGCleanup.cpp @@ -112,11 +112,11 @@ void EHScopeStack::deallocate(size_t Size) { StartOfData += llvm::alignTo(Size, ScopeStackAlignment); } -bool EHScopeStack::containsOnlyLifetimeMarkers( +bool EHScopeStack::containsOnlyNoopCleanups( EHScopeStack::stable_iterator Old) const { for (EHScopeStack::iterator it = begin(); stabilize(it) != Old; it++) { EHCleanupScope *cleanup = dyn_cast(&*it); -if (!cleanup || !cleanup->isLifetimeMarker()) +if (!cleanup || !(cleanup->isLifetimeMarker() || cleanup->isFakeUse())) return false; } @@ -154,6 +154,7 @@ void *EHScopeStack::pushCleanup(CleanupKind Kind, size_t Size) { bool IsNormalCleanup = Kind & NormalCleanup; bool IsEHCleanup = Kind & EHCleanup; bool IsLifetimeMarker = Kind & LifetimeMarker; + bool IsFakeUse = Kind & FakeUse; // Per C++ [except.terminate], it is implementation-defined whether none, // some, or all cleanups are called before std::terminate. Thus, when @@ -176,6 +177,8 @@ void *EHScopeStack::pushCleanup(CleanupKind Kind, size_t Size) { InnermostEHScope = stab
[clang] [clang] return first Decl for CanonicalDecl in TranslationUnitDecl (PR #110101)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Vipul Cariappa (Vipul-Cariappa) Changes Return the first `Decl` when using `TranslationUnitDecl::getCanonicalDecl` --- Full diff: https://github.com/llvm/llvm-project/pull/110101.diff 1 Files Affected: - (modified) clang/include/clang/AST/Decl.h (+4) ``diff diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h index 0600ecc4d14a18..7ff35d73df5997 100644 --- a/clang/include/clang/AST/Decl.h +++ b/clang/include/clang/AST/Decl.h @@ -133,6 +133,10 @@ class TranslationUnitDecl : public Decl, static TranslationUnitDecl *castFromDeclContext(const DeclContext *DC) { return static_cast(const_cast(DC)); } + + /// Retrieves the canonical declaration of this translation unit. + TranslationUnitDecl *getCanonicalDecl() override { return getFirstDecl(); } + const TranslationUnitDecl *getCanonicalDecl() const { return getFirstDecl(); } }; /// Represents a `#pragma comment` line. Always a child of `` https://github.com/llvm/llvm-project/pull/110101 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] 2ad435f - Revert "[clang] Extend diagnose_if to accept more detailed warning information (#70976)"
Author: Kadir Cetinkaya Date: 2024-09-26T12:16:07+02:00 New Revision: 2ad435f9f6fb792d9b010ddf56ca3ea26fbf5f15 URL: https://github.com/llvm/llvm-project/commit/2ad435f9f6fb792d9b010ddf56ca3ea26fbf5f15 DIFF: https://github.com/llvm/llvm-project/commit/2ad435f9f6fb792d9b010ddf56ca3ea26fbf5f15.diff LOG: Revert "[clang] Extend diagnose_if to accept more detailed warning information (#70976)" This reverts commit e39205654dc11c50bd117e8ccac243a641ebd71f. There are further discussions in https://github.com/llvm/llvm-project/pull/70976, happening for past two weeks. Since there were no responses for couple weeks now, reverting until author is back. Added: Modified: clang-tools-extra/clangd/Diagnostics.cpp clang-tools-extra/clangd/Diagnostics.h clang-tools-extra/clangd/ParsedAST.cpp clang-tools-extra/clangd/Preamble.cpp clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp clang/include/clang/Basic/Attr.td clang/include/clang/Basic/Diagnostic.h clang/include/clang/Basic/DiagnosticCategories.h clang/include/clang/Basic/DiagnosticIDs.h clang/include/clang/Basic/DiagnosticSemaKinds.td clang/lib/Basic/Diagnostic.cpp clang/lib/Basic/DiagnosticIDs.cpp clang/lib/Frontend/LogDiagnosticPrinter.cpp clang/lib/Frontend/SerializedDiagnosticPrinter.cpp clang/lib/Frontend/TextDiagnosticPrinter.cpp clang/lib/Sema/Sema.cpp clang/lib/Sema/SemaCUDA.cpp clang/lib/Sema/SemaDeclAttr.cpp clang/lib/Sema/SemaOverload.cpp clang/lib/Sema/SemaTemplateInstantiateDecl.cpp clang/lib/Serialization/ASTReader.cpp clang/lib/Serialization/ASTWriter.cpp clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp clang/test/Sema/diagnose_if.c clang/tools/diagtool/ListWarnings.cpp clang/tools/diagtool/ShowEnabledWarnings.cpp clang/tools/libclang/CXStoredDiagnostic.cpp flang/lib/Frontend/TextDiagnosticPrinter.cpp Removed: clang/test/SemaCXX/diagnose_if-warning-group.cpp diff --git a/clang-tools-extra/clangd/Diagnostics.cpp b/clang-tools-extra/clangd/Diagnostics.cpp index a8214acc50558d..a59d1e7ac84096 100644 --- a/clang-tools-extra/clangd/Diagnostics.cpp +++ b/clang-tools-extra/clangd/Diagnostics.cpp @@ -577,17 +577,7 @@ std::vector StoreDiags::take(const clang::tidy::ClangTidyContext *Tidy) { for (auto &Diag : Output) { if (const char *ClangDiag = getDiagnosticCode(Diag.ID)) { // Warnings controlled by -Wfoo are better recognized by that name. - const StringRef Warning = [&] { -if (OrigSrcMgr) { - return OrigSrcMgr->getDiagnostics() - .getDiagnosticIDs() - ->getWarningOptionForDiag(Diag.ID); -} -if (!DiagnosticIDs::IsCustomDiag(Diag.ID)) - return DiagnosticIDs{}.getWarningOptionForDiag(Diag.ID); -return StringRef{}; - }(); - + StringRef Warning = DiagnosticIDs::getWarningOptionForDiag(Diag.ID); if (!Warning.empty()) { Diag.Name = ("-W" + Warning).str(); } else { @@ -904,23 +894,20 @@ void StoreDiags::flushLastDiag() { Output.push_back(std::move(*LastDiag)); } -bool isDiagnosticSuppressed(const clang::Diagnostic &Diag, -const llvm::StringSet<> &Suppress, -const LangOptions &LangOpts) { +bool isBuiltinDiagnosticSuppressed(unsigned ID, + const llvm::StringSet<> &Suppress, + const LangOptions &LangOpts) { // Don't complain about header-only stuff in mainfiles if it's a header. // FIXME: would be cleaner to suppress in clang, once we decide whether the //behavior should be to silently-ignore or respect the pragma. - if (Diag.getID() == diag::pp_pragma_sysheader_in_main_file && - LangOpts.IsHeaderFile) + if (ID == diag::pp_pragma_sysheader_in_main_file && LangOpts.IsHeaderFile) return true; - if (const char *CodePtr = getDiagnosticCode(Diag.getID())) { + if (const char *CodePtr = getDiagnosticCode(ID)) { if (Suppress.contains(normalizeSuppressedCode(CodePtr))) return true; } - StringRef Warning = - Diag.getDiags()->getDiagnosticIDs()->getWarningOptionForDiag( - Diag.getID()); + StringRef Warning = DiagnosticIDs::getWarningOptionForDiag(ID); if (!Warning.empty() && Suppress.contains(Warning)) return true; return false; diff --git a/clang-tools-extra/clangd/Diagnostics.h b/clang-tools-extra/clangd/Diagnostics.h index c45d8dc3aa6ce6..d4c0478c63a5cf 100644 --- a/clang-tools-extra/clangd/Diagnostics.h +++ b/clang-tools-extra/clangd/Diagnostics.h @@ -181,11 +181,11 @@ class StoreDiags : public DiagnosticConsumer { }; /// Determine whether a (non-clang-tidy) diagnostic is suppressed by config. -bool isDiagnosticSuppressed(const clang::Diagnostic &Diag, -const llvm::StringSet<> &Suppressed, -
[clang] 2ad435f - Revert "[clang] Extend diagnose_if to accept more detailed warning information (#70976)"
Author: Kadir Cetinkaya Date: 2024-09-26T12:16:07+02:00 New Revision: 2ad435f9f6fb792d9b010ddf56ca3ea26fbf5f15 URL: https://github.com/llvm/llvm-project/commit/2ad435f9f6fb792d9b010ddf56ca3ea26fbf5f15 DIFF: https://github.com/llvm/llvm-project/commit/2ad435f9f6fb792d9b010ddf56ca3ea26fbf5f15.diff LOG: Revert "[clang] Extend diagnose_if to accept more detailed warning information (#70976)" This reverts commit e39205654dc11c50bd117e8ccac243a641ebd71f. There are further discussions in https://github.com/llvm/llvm-project/pull/70976, happening for past two weeks. Since there were no responses for couple weeks now, reverting until author is back. Added: Modified: clang-tools-extra/clangd/Diagnostics.cpp clang-tools-extra/clangd/Diagnostics.h clang-tools-extra/clangd/ParsedAST.cpp clang-tools-extra/clangd/Preamble.cpp clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp clang/include/clang/Basic/Attr.td clang/include/clang/Basic/Diagnostic.h clang/include/clang/Basic/DiagnosticCategories.h clang/include/clang/Basic/DiagnosticIDs.h clang/include/clang/Basic/DiagnosticSemaKinds.td clang/lib/Basic/Diagnostic.cpp clang/lib/Basic/DiagnosticIDs.cpp clang/lib/Frontend/LogDiagnosticPrinter.cpp clang/lib/Frontend/SerializedDiagnosticPrinter.cpp clang/lib/Frontend/TextDiagnosticPrinter.cpp clang/lib/Sema/Sema.cpp clang/lib/Sema/SemaCUDA.cpp clang/lib/Sema/SemaDeclAttr.cpp clang/lib/Sema/SemaOverload.cpp clang/lib/Sema/SemaTemplateInstantiateDecl.cpp clang/lib/Serialization/ASTReader.cpp clang/lib/Serialization/ASTWriter.cpp clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp clang/test/Sema/diagnose_if.c clang/tools/diagtool/ListWarnings.cpp clang/tools/diagtool/ShowEnabledWarnings.cpp clang/tools/libclang/CXStoredDiagnostic.cpp flang/lib/Frontend/TextDiagnosticPrinter.cpp Removed: clang/test/SemaCXX/diagnose_if-warning-group.cpp diff --git a/clang-tools-extra/clangd/Diagnostics.cpp b/clang-tools-extra/clangd/Diagnostics.cpp index a8214acc50558d..a59d1e7ac84096 100644 --- a/clang-tools-extra/clangd/Diagnostics.cpp +++ b/clang-tools-extra/clangd/Diagnostics.cpp @@ -577,17 +577,7 @@ std::vector StoreDiags::take(const clang::tidy::ClangTidyContext *Tidy) { for (auto &Diag : Output) { if (const char *ClangDiag = getDiagnosticCode(Diag.ID)) { // Warnings controlled by -Wfoo are better recognized by that name. - const StringRef Warning = [&] { -if (OrigSrcMgr) { - return OrigSrcMgr->getDiagnostics() - .getDiagnosticIDs() - ->getWarningOptionForDiag(Diag.ID); -} -if (!DiagnosticIDs::IsCustomDiag(Diag.ID)) - return DiagnosticIDs{}.getWarningOptionForDiag(Diag.ID); -return StringRef{}; - }(); - + StringRef Warning = DiagnosticIDs::getWarningOptionForDiag(Diag.ID); if (!Warning.empty()) { Diag.Name = ("-W" + Warning).str(); } else { @@ -904,23 +894,20 @@ void StoreDiags::flushLastDiag() { Output.push_back(std::move(*LastDiag)); } -bool isDiagnosticSuppressed(const clang::Diagnostic &Diag, -const llvm::StringSet<> &Suppress, -const LangOptions &LangOpts) { +bool isBuiltinDiagnosticSuppressed(unsigned ID, + const llvm::StringSet<> &Suppress, + const LangOptions &LangOpts) { // Don't complain about header-only stuff in mainfiles if it's a header. // FIXME: would be cleaner to suppress in clang, once we decide whether the //behavior should be to silently-ignore or respect the pragma. - if (Diag.getID() == diag::pp_pragma_sysheader_in_main_file && - LangOpts.IsHeaderFile) + if (ID == diag::pp_pragma_sysheader_in_main_file && LangOpts.IsHeaderFile) return true; - if (const char *CodePtr = getDiagnosticCode(Diag.getID())) { + if (const char *CodePtr = getDiagnosticCode(ID)) { if (Suppress.contains(normalizeSuppressedCode(CodePtr))) return true; } - StringRef Warning = - Diag.getDiags()->getDiagnosticIDs()->getWarningOptionForDiag( - Diag.getID()); + StringRef Warning = DiagnosticIDs::getWarningOptionForDiag(ID); if (!Warning.empty() && Suppress.contains(Warning)) return true; return false; diff --git a/clang-tools-extra/clangd/Diagnostics.h b/clang-tools-extra/clangd/Diagnostics.h index c45d8dc3aa6ce6..d4c0478c63a5cf 100644 --- a/clang-tools-extra/clangd/Diagnostics.h +++ b/clang-tools-extra/clangd/Diagnostics.h @@ -181,11 +181,11 @@ class StoreDiags : public DiagnosticConsumer { }; /// Determine whether a (non-clang-tidy) diagnostic is suppressed by config. -bool isDiagnosticSuppressed(const clang::Diagnostic &Diag, -const llvm::StringSet<> &Suppressed, -
[clang] [llvm] [ARM] [AArch32] Add support for Arm China STAR-MC1 CPU (PR #110085)
https://github.com/jthackray edited https://github.com/llvm/llvm-project/pull/110085 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ARM] Fix musttail calls (PR #109943)
@@ -0,0 +1,321 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 +; RUN: llc -mtriple=armv7a-none-eabi %s -o - | FileCheck %s + +declare i32 @many_args_callee(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5) + +define i32 @many_args_tail(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5) { +; CHECK-LABEL: many_args_tail: +; CHECK: @ %bb.0: +; CHECK-NEXT:mov r0, #5 +; CHECK-NEXT:mov r1, #2 +; CHECK-NEXT:str r0, [sp] +; CHECK-NEXT:mov r0, #6 +; CHECK-NEXT:str r0, [sp, #4] +; CHECK-NEXT:mov r0, #1 +; CHECK-NEXT:mov r2, #3 +; CHECK-NEXT:mov r3, #4 +; CHECK-NEXT:b many_args_callee + %ret = tail call i32 @many_args_callee(i32 1, i32 2, i32 3, i32 4, i32 5, i32 6) + ret i32 %ret +} + +define i32 @many_args_musttail(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5) { +; CHECK-LABEL: many_args_musttail: +; CHECK: @ %bb.0: +; CHECK-NEXT:mov r0, #5 +; CHECK-NEXT:mov r1, #2 +; CHECK-NEXT:str r0, [sp] +; CHECK-NEXT:mov r0, #6 +; CHECK-NEXT:str r0, [sp, #4] +; CHECK-NEXT:mov r0, #1 +; CHECK-NEXT:mov r2, #3 +; CHECK-NEXT:mov r3, #4 +; CHECK-NEXT:b many_args_callee + %ret = musttail call i32 @many_args_callee(i32 1, i32 2, i32 3, i32 4, i32 5, i32 6) + ret i32 %ret +} + +; This function has more arguments than it's tail-callee. This isn't valid for +; the musttail attribute, but can still be tail-called as a non-guaranteed +; optimisation, because the outgoing arguments to @many_args_callee fit in the +; stack space allocated by the caller of @more_args_tail. +define i32 @more_args_tail(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6) { +; CHECK-LABEL: more_args_tail: +; CHECK: @ %bb.0: +; CHECK-NEXT:mov r0, #5 +; CHECK-NEXT:mov r1, #2 +; CHECK-NEXT:str r0, [sp] +; CHECK-NEXT:mov r0, #6 +; CHECK-NEXT:str r0, [sp, #4] +; CHECK-NEXT:mov r0, #1 +; CHECK-NEXT:mov r2, #3 +; CHECK-NEXT:mov r3, #4 +; CHECK-NEXT:b many_args_callee + %ret = tail call i32 @many_args_callee(i32 1, i32 2, i32 3, i32 4, i32 5, i32 6) + ret i32 %ret +} + +; Again, this isn't valid for musttail, but can be tail-called in practice +; because the stack size if the same. +define i32 @different_args_tail(i64 %0, i64 %1, i64 %2) { +; CHECK-LABEL: different_args_tail: +; CHECK: @ %bb.0: +; CHECK-NEXT:mov r0, #5 +; CHECK-NEXT:mov r1, #2 +; CHECK-NEXT:str r0, [sp] +; CHECK-NEXT:mov r0, #6 +; CHECK-NEXT:str r0, [sp, #4] +; CHECK-NEXT:mov r0, #1 +; CHECK-NEXT:mov r2, #3 +; CHECK-NEXT:mov r3, #4 +; CHECK-NEXT:b many_args_callee + %ret = tail call i32 @many_args_callee(i32 1, i32 2, i32 3, i32 4, i32 5, i32 6) + ret i32 %ret +} + +; Here, the caller requires less stack space for it's arguments than the +; callee, so it would not ba valid to do a tail-call. +define i32 @fewer_args_tail(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) { +; CHECK-LABEL: fewer_args_tail: +; CHECK: @ %bb.0: +; CHECK-NEXT:.save {r11, lr} +; CHECK-NEXT:push {r11, lr} +; CHECK-NEXT:.pad #8 +; CHECK-NEXT:sub sp, sp, #8 +; CHECK-NEXT:mov r1, #6 +; CHECK-NEXT:mov r0, #5 +; CHECK-NEXT:strd r0, r1, [sp] +; CHECK-NEXT:mov r0, #1 +; CHECK-NEXT:mov r1, #2 +; CHECK-NEXT:mov r2, #3 +; CHECK-NEXT:mov r3, #4 +; CHECK-NEXT:bl many_args_callee +; CHECK-NEXT:add sp, sp, #8 +; CHECK-NEXT:pop {r11, pc} + %ret = tail call i32 @many_args_callee(i32 1, i32 2, i32 3, i32 4, i32 5, i32 6) + ret i32 %ret +} + +declare void @sret_callee(ptr sret({ double, double }) align 8) + +; Functions which return by sret can be tail-called because the incoming sret +; pointer gets passed through to the callee. +define void @sret_caller_tail(ptr sret({ double, double }) align 8 %result) { +; CHECK-LABEL: sret_caller_tail: +; CHECK: @ %bb.0: @ %entry +; CHECK-NEXT:b sret_callee +entry: + tail call void @sret_callee(ptr sret({ double, double }) align 8 %result) + ret void +} + +define void @sret_caller_musttail(ptr sret({ double, double }) align 8 %result) { +; CHECK-LABEL: sret_caller_musttail: +; CHECK: @ %bb.0: @ %entry +; CHECK-NEXT:b sret_callee +entry: + musttail call void @sret_callee(ptr sret({ double, double }) align 8 %result) + ret void +} + +%large_struct = type { [20 x i32] } +declare void @large_callee(%large_struct* byval(%large_struct) align 4) + +; Functions with sret parameters can be tail-called, because the value is +; actually passed in registers and the stack in the same way for the caller and +; callee. Within @large_caller the first 16 bytes of the argument are spilled +; to the local stack frame, but for the tail-call they are passed in r0-r3, so +; it's safe to de-allocate that memory before the call. Most of the code +; generated for this isn't needed, but that's a missed optimisation, not a +; correctness issue. +define void @large_caller(%large_struct* byval(%lar
[clang] [llvm] [ARM] [AArch32] Add support for Arm China STAR-MC1 CPU (PR #110085)
@@ -362,6 +362,16 @@ def : ProcessorModel<"cortex-m33", CortexM4Model, [ARMv8mMainline, FeatureHasNoBranchPredictor, FeatureFixCMSE_CVE_2021_35465]>; +def : ProcessorModel<"star-mc1", CortexM4Model, [ARMv8mMainline, + FeatureDSP, + FeatureFPARMv8_D16_SP, + FeaturePrefLoopAlign32, + FeatureHasSlowFPVMLx, + FeatureHasSlowFPVFMx, + FeatureUseMISched, + FeatureHasNoBranchPredictor, + FeatureFixCMSE_CVE_2021_35465]>; jthackray wrote: Could you add the following to `llvm/test/CodeGen/ARM/cmse-cve-2021-35465.ll`: ``` ; RUN: llc %s -o - -mtriple=thumbv8m.main -mcpu=star-mc1 -verify-machineinstrs | \ ; RUN: FileCheck %s --check-prefix=CHECK-8M-FP-CVE-2021-35465 ; RUN: llc %s -o - -mtriple=thumbv8m.main -mcpu=star-mc1 -mattr=-fpregs -verify-machineinstrs | \ ; RUN: FileCheck %s --check-prefix=CHECK-8M-NOFP-CVE-2021-35465 ``` https://github.com/llvm/llvm-project/pull/110085 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ARM] [AArch32] Add support for Arm China STAR-MC1 CPU (PR #110085)
https://github.com/jthackray commented: Could you add `star-mc1` to clang/test/Driver/arm-cortex-cpus-2.c? https://github.com/llvm/llvm-project/pull/110085 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ARM] [AArch32] Add support for Arm China STAR-MC1 CPU (PR #110085)
https://github.com/jthackray edited https://github.com/llvm/llvm-project/pull/110085 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ARM] [AArch32] Add support for Arm China STAR-MC1 CPU (PR #110085)
https://github.com/jthackray commented: Another possible addition would be to `clang/test/Driver/arm-v8m.c`: ``` // RUN: %clang -target arm-none-none-eabi -mcpu=star-mc1 %s -### -c 2>&1 | FileCheck %s --check-prefix=V8M_MAINLINE_STAR_MC1_DSP // RUN: %clang -target arm-none-none-eabi -mcpu=star-mc1 -mbig-endian %s -### -c 2>&1 | FileCheck %s --check-prefix=EBV8M_MAINLINE_STAR_MC1_DSP // V8M_MAINLINE_STAR_MC1_DSP: "-cc1"{{.*}} "-triple" "thumbv8m.main-{{.*}} "-target-cpu" "star-mc1" // EBV8M_MAINLINE_STAR_MC1_DSP: "-cc1"{{.*}} "-triple" "thumbebv8m.main-{{.*}} "-target-cpu" "star-mc1" ``` https://github.com/llvm/llvm-project/pull/110085 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][x86] Add constexpr support for BMI/TBM BEXTR intrinsics (PR #109577)
https://github.com/phoebewang approved this pull request. LGTM. https://github.com/llvm/llvm-project/pull/109577 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Add fake use emission to Clang with -fextend-lifetimes (PR #110102)
https://github.com/SLTozer updated https://github.com/llvm/llvm-project/pull/110102 >From 7d8646edb373c38ee761de2c338c45b967a423e7 Mon Sep 17 00:00:00 2001 From: Stephen Tozer Date: Wed, 25 Sep 2024 16:55:39 +0100 Subject: [PATCH] [Clang] Add fake use emission to Clang with -fextend-lifetimes Following the previous patch which adds the "extend lifetimes" flag without (almost) any functionality, this patch adds the real feature by allowing Clang to emit fake uses. These are emitted as a new form of cleanup, set for variable addresses, which just emits a fake use intrinsic when the variable falls out of scope. The code for achieving this is simple, with most of the logic centered on determining whether to emit a fake use for a given address, and on ensuring that fake uses are ignored in a few cases. --- clang/lib/CodeGen/CGCall.cpp | 17 +- clang/lib/CodeGen/CGCleanup.cpp | 7 ++- clang/lib/CodeGen/CGCleanup.h | 8 +++ clang/lib/CodeGen/CGDecl.cpp | 69 +++ clang/lib/CodeGen/CodeGenFunction.cpp | 6 +- clang/lib/CodeGen/CodeGenFunction.h | 16 ++ clang/lib/CodeGen/CodeGenModule.h | 4 ++ clang/lib/CodeGen/EHScopeStack.h | 9 ++- clang/test/CodeGen/extend-liveness1.c | 29 ++ clang/test/CodeGen/extend-liveness2.cpp | 34 +++ clang/test/CodeGen/fake-use-determinism.c | 18 ++ clang/test/CodeGen/fake-use-lambda.cpp| 43 ++ clang/test/CodeGen/fake-use-landingpad.c | 16 ++ clang/test/CodeGen/fake-use-noreturn.cpp | 27 + clang/test/CodeGen/fake-use-return-line.c | 15 + clang/test/CodeGen/fake-use-sanitizer.cpp | 37 clang/test/CodeGen/fake-use-scalar.c | 22 clang/test/CodeGen/fake-use-small-aggs.c | 24 clang/test/CodeGen/fake-use-while.c | 18 ++ clang/test/CodeGen/fake-use.cpp | 44 +++ clang/test/CodeGen/no-fake-use-O0.cpp | 50 21 files changed, 503 insertions(+), 10 deletions(-) create mode 100644 clang/test/CodeGen/extend-liveness1.c create mode 100644 clang/test/CodeGen/extend-liveness2.cpp create mode 100644 clang/test/CodeGen/fake-use-determinism.c create mode 100644 clang/test/CodeGen/fake-use-lambda.cpp create mode 100644 clang/test/CodeGen/fake-use-landingpad.c create mode 100644 clang/test/CodeGen/fake-use-noreturn.cpp create mode 100644 clang/test/CodeGen/fake-use-return-line.c create mode 100644 clang/test/CodeGen/fake-use-sanitizer.cpp create mode 100644 clang/test/CodeGen/fake-use-scalar.c create mode 100644 clang/test/CodeGen/fake-use-small-aggs.c create mode 100644 clang/test/CodeGen/fake-use-while.c create mode 100644 clang/test/CodeGen/fake-use.cpp create mode 100644 clang/test/CodeGen/no-fake-use-O0.cpp diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 4ae981e4013e9c..26441b4135529d 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -3566,15 +3566,26 @@ static llvm::StoreInst *findDominatingStoreToReturnValue(CodeGenFunction &CGF) { llvm::BasicBlock *IP = CGF.Builder.GetInsertBlock(); if (IP->empty()) return nullptr; -// Look at directly preceding instruction, skipping bitcasts and lifetime -// markers. +// Look at directly preceding instruction, skipping bitcasts, lifetime +// markers, and fake uses and their operands. +const llvm::Instruction *LoadIntoFakeUse = nullptr; for (llvm::Instruction &I : make_range(IP->rbegin(), IP->rend())) { + // Ignore instructions that are just loads for fake uses; the load should + // immediately precede the fake use, so we only need to remember the + // operand for the last fake use seen. + if (LoadIntoFakeUse == &I) +continue; if (isa(&I)) continue; - if (auto *II = dyn_cast(&I)) + if (auto *II = dyn_cast(&I)) { if (II->getIntrinsicID() == llvm::Intrinsic::lifetime_end) continue; +if (II->getIntrinsicID() == llvm::Intrinsic::fake_use) { + LoadIntoFakeUse = dyn_cast(II->getArgOperand(0)); + continue; +} + } return GetStoreIfValid(&I); } return nullptr; diff --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp index 5d253c92a38a81..82532e182bebbd 100644 --- a/clang/lib/CodeGen/CGCleanup.cpp +++ b/clang/lib/CodeGen/CGCleanup.cpp @@ -112,11 +112,11 @@ void EHScopeStack::deallocate(size_t Size) { StartOfData += llvm::alignTo(Size, ScopeStackAlignment); } -bool EHScopeStack::containsOnlyLifetimeMarkers( +bool EHScopeStack::containsOnlyNoopCleanups( EHScopeStack::stable_iterator Old) const { for (EHScopeStack::iterator it = begin(); stabilize(it) != Old; it++) { EHCleanupScope *cleanup = dyn_cast(&*it); -if (!cleanup || !cleanup->isLifetimeMarker()) +if (!cleanup || !(cleanup->isLifetimeMarker() || cleanup->isFakeUs
[clang] [llvm] [ARM] Fix musttail calls (PR #109943)
@@ -5112,7 +5112,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo, RawAddress SRetAlloca = RawAddress::invalid(); llvm::Value *UnusedReturnSizePtr = nullptr; if (RetAI.isIndirect() || RetAI.isInAlloca() || RetAI.isCoerceAndExpand()) { -if (IsVirtualFunctionPointerThunk && RetAI.isIndirect()) { +if ((IsVirtualFunctionPointerThunk && RetAI.isIndirect()) || IsMustTail) { ostannard wrote: I think `isIndirect()` is the only case needed for `IsMustTail`, so I'll change the code to limit it to that, matching the `IsVirtualFunctionPointerThunk` check. https://github.com/llvm/llvm-project/pull/109943 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] return first Decl for CanonicalDecl in TranslationUnitDecl (PR #110101)
Vipul-Cariappa wrote: ping @vgvassilev https://github.com/llvm/llvm-project/pull/110101 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [X86] Enable constexpr on LZCNT & BMI intrinsics (PR #94161)
RKSimon wrote: @aniplcc Are you still wanting to work on this? Otherwise I'd like to commandeer and complete the patch to get it into trunk. https://github.com/llvm/llvm-project/pull/94161 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][RISCV] Add preprocessor macros for Zicfilp CFI scheme (PR #109600)
https://github.com/mylai-mtk updated https://github.com/llvm/llvm-project/pull/109600 >From 35532cf0a9cc855fe5f0a4eefd4c343687a595dc Mon Sep 17 00:00:00 2001 From: Ming-Yi Lai Date: Fri, 10 May 2024 14:16:59 +0800 Subject: [PATCH] [clang][RISCV] Add Zicfilp CFI scheme preprocessor macros These macros allow assembly files to know which CFI label to use when the target has Zicfilp enabled. --- clang/lib/Basic/Targets/RISCV.cpp | 19 + .../test/CodeGen/RISCV/riscv-cf-protection.c | 79 +++ 2 files changed, 98 insertions(+) diff --git a/clang/lib/Basic/Targets/RISCV.cpp b/clang/lib/Basic/Targets/RISCV.cpp index b6ea4440507ea1..b9199e3bc77d34 100644 --- a/clang/lib/Basic/Targets/RISCV.cpp +++ b/clang/lib/Basic/Targets/RISCV.cpp @@ -224,6 +224,25 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions &Opts, else Builder.defineMacro("__riscv_32e"); } + + if (Opts.CFProtectionBranch) { +auto Scheme = Opts.getCFBranchLabelScheme(); +if (Scheme == CFBranchLabelSchemeKind::Default) + Scheme = getDefaultCFBranchLabelScheme(); + +Builder.defineMacro("__riscv_landing_pad", "1"); +switch (Scheme) { +case CFBranchLabelSchemeKind::Unlabeled: + Builder.defineMacro("__riscv_landing_pad_unlabeled", "1"); + break; +case CFBranchLabelSchemeKind::FuncSig: + Builder.defineMacro("__riscv_landing_pad_func_sig", "1"); + break; +case CFBranchLabelSchemeKind::Default: + llvm_unreachable("default cf-branch-label scheme should already be " + "transformed to other scheme"); +} + } } static constexpr Builtin::Info BuiltinInfo[] = { diff --git a/clang/test/CodeGen/RISCV/riscv-cf-protection.c b/clang/test/CodeGen/RISCV/riscv-cf-protection.c index 3a9855a3d2f011..db7b65061658c0 100644 --- a/clang/test/CodeGen/RISCV/riscv-cf-protection.c +++ b/clang/test/CodeGen/RISCV/riscv-cf-protection.c @@ -1,71 +1,143 @@ +// RUN: %clang --target=riscv32 -menable-experimental-extensions \ +// RUN: -march=rv32i_zicfilp1p0 -fcf-protection=branch \ +// RUN: -mcf-branch-label-scheme=unlabeled -E -dM %s -o - | FileCheck \ +// RUN: --check-prefixes=LPAD-MACRO,UNLABELED-MACRO %s + // RUN: %clang --target=riscv32 -menable-experimental-extensions \ // RUN: -march=rv32i_zicfilp1p0 -fcf-protection=branch \ // RUN: -mcf-branch-label-scheme=unlabeled -S -emit-llvm %s -o - | FileCheck \ // RUN: --check-prefixes=BRANCH-PROT-FLAG,UNLABELED-FLAG %s +// RUN: %clang --target=riscv32 -menable-experimental-extensions \ +// RUN: -march=rv32i_zicfilp1p0 -fcf-protection=branch \ +// RUN: -mcf-branch-label-scheme=func-sig -E -dM %s -o - | FileCheck \ +// RUN: --check-prefixes=LPAD-MACRO,FUNC-SIG-MACRO %s + // RUN: %clang --target=riscv32 -menable-experimental-extensions \ // RUN: -march=rv32i_zicfilp1p0 -fcf-protection=branch \ // RUN: -mcf-branch-label-scheme=func-sig -S -emit-llvm %s -o - | FileCheck \ // RUN: --check-prefixes=BRANCH-PROT-FLAG,FUNC-SIG-FLAG %s +// RUN: %clang --target=riscv32 -menable-experimental-extensions \ +// RUN: -march=rv32i_zicfilp1p0 -mcf-branch-label-scheme=unlabeled -E -dM %s \ +// RUN: -o - 2>&1 | FileCheck \ +// RUN: --check-prefixes=NO-MACRO,UNLABELED-SCHEME-UNUSED %s + // RUN: %clang --target=riscv32 -menable-experimental-extensions \ // RUN: -march=rv32i_zicfilp1p0 -mcf-branch-label-scheme=unlabeled -S \ // RUN: -emit-llvm %s -o - 2>&1 | FileCheck \ // RUN: --check-prefixes=NO-FLAG,UNLABELED-SCHEME-UNUSED %s +// RUN: %clang --target=riscv32 -menable-experimental-extensions \ +// RUN: -march=rv32i_zicfilp1p0 -mcf-branch-label-scheme=func-sig -E -dM %s \ +// RUN: -o - 2>&1 | FileCheck \ +// RUN: --check-prefixes=NO-MACRO,FUNC-SIG-SCHEME-UNUSED %s + // RUN: %clang --target=riscv32 -menable-experimental-extensions \ // RUN: -march=rv32i_zicfilp1p0 -mcf-branch-label-scheme=func-sig -S \ // RUN: -emit-llvm %s -o - 2>&1 | FileCheck \ // RUN: --check-prefixes=NO-FLAG,FUNC-SIG-SCHEME-UNUSED %s +// RUN: %clang --target=riscv32 -fcf-protection=branch \ +// RUN: -mcf-branch-label-scheme=unlabeled -E -dM -emit-llvm %s -o - | \ +// RUN: FileCheck --check-prefixes=LPAD-MACRO,UNLABELED-MACRO %s + // RUN: %clang --target=riscv32 -fcf-protection=branch \ // RUN: -mcf-branch-label-scheme=unlabeled -S -emit-llvm %s -o - | FileCheck \ // RUN: --check-prefixes=BRANCH-PROT-FLAG,UNLABELED-FLAG %s +// RUN: %clang --target=riscv32 -fcf-protection=branch \ +// RUN: -mcf-branch-label-scheme=func-sig -E -dM %s -o - | FileCheck \ +// RUN: --check-prefixes=LPAD-MACRO,FUNC-SIG-MACRO %s + // RUN: %clang --target=riscv32 -fcf-protection=branch \ // RUN: -mcf-branch-label-scheme=func-sig -S -emit-llvm %s -o - | FileCheck \ // RUN: --check-prefixes=BRANCH-PROT-FLAG,FUNC-SIG-FLAG %s +// RUN: %clang --target=riscv32 -mcf-branch-label-scheme=unlabeled -E -dM %s \ +// RUN: -o - 2>&1 | FileCheck \ +// RUN: --check-prefixes=NO-MACRO,UNLABELED-SCHEME-UNUSED %s + // RUN: %clang --target=riscv32 -mcf-branc
[clang] [flang] [llvm] [flang][driver] rename flang-new to flang (PR #110023)
DavidSpickett wrote: > Is there a symbolic link flang-new -> flang? We would like to have a > transitional period. Compiler Explorer would also appreciate this. Though I should be able to get it switched to the new name within a week or two. https://github.com/llvm/llvm-project/pull/110023 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Add fake use emission to Clang with -fextend-lifetimes (PR #110102)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff 22829f757dc76b23071d9438ae9c6ddc3e966db0 e04a16c6d51539421dd134f7524641e843f5d555 --extensions cpp,c,h -- clang/test/CodeGen/extend-liveness1.c clang/test/CodeGen/extend-liveness2.cpp clang/test/CodeGen/fake-use-determinism.c clang/test/CodeGen/fake-use-lambda.cpp clang/test/CodeGen/fake-use-landingpad.c clang/test/CodeGen/fake-use-noreturn.cpp clang/test/CodeGen/fake-use-return-line.c clang/test/CodeGen/fake-use-sanitizer.cpp clang/test/CodeGen/fake-use-scalar.c clang/test/CodeGen/fake-use-small-aggs.c clang/test/CodeGen/fake-use-while.c clang/test/CodeGen/fake-use.cpp clang/test/CodeGen/no-fake-use-O0.cpp clang/lib/CodeGen/CGCall.cpp clang/lib/CodeGen/CGCleanup.cpp clang/lib/CodeGen/CGCleanup.h clang/lib/CodeGen/CGDecl.cpp clang/lib/CodeGen/CodeGenFunction.cpp clang/lib/CodeGen/CodeGenFunction.h clang/lib/CodeGen/CodeGenModule.h clang/lib/CodeGen/EHScopeStack.h `` View the diff from clang-format here. ``diff diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 13c556a4e2..26441b4135 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -3566,26 +3566,27 @@ static llvm::StoreInst *findDominatingStoreToReturnValue(CodeGenFunction &CGF) { llvm::BasicBlock *IP = CGF.Builder.GetInsertBlock(); if (IP->empty()) return nullptr; - // Look at directly preceding instruction, skipping bitcasts, lifetime - // markers, and fake uses and their operands. - const llvm::Instruction *LoadIntoFakeUse = nullptr; - for (llvm::Instruction &I : make_range(IP->rbegin(), IP->rend())) { - // Ignore instructions that are just loads for fake uses; the load should - // immediately precede the fake use, so we only need to remember the - // operand for the last fake use seen. - if (LoadIntoFakeUse == &I) - continue; - if (isa(&I)) - continue; - if (auto *II = dyn_cast(&I)) { - if (II->getIntrinsicID() == llvm::Intrinsic::lifetime_end) - continue; - - if (II->getIntrinsicID() == llvm::Intrinsic::fake_use) { - LoadIntoFakeUse = dyn_cast(II->getArgOperand(0)); - continue; - } - } return GetStoreIfValid(&I); +// Look at directly preceding instruction, skipping bitcasts, lifetime +// markers, and fake uses and their operands. +const llvm::Instruction *LoadIntoFakeUse = nullptr; +for (llvm::Instruction &I : make_range(IP->rbegin(), IP->rend())) { + // Ignore instructions that are just loads for fake uses; the load should + // immediately precede the fake use, so we only need to remember the + // operand for the last fake use seen. + if (LoadIntoFakeUse == &I) +continue; + if (isa(&I)) +continue; + if (auto *II = dyn_cast(&I)) { +if (II->getIntrinsicID() == llvm::Intrinsic::lifetime_end) + continue; + +if (II->getIntrinsicID() == llvm::Intrinsic::fake_use) { + LoadIntoFakeUse = dyn_cast(II->getArgOperand(0)); + continue; +} + } + return GetStoreIfValid(&I); } return nullptr; } `` https://github.com/llvm/llvm-project/pull/110102 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 82ce829 - [clang][bytecode] Don't call dtors of anonymous unions (#110087)
Author: Timm Baeder Date: 2024-09-26T12:50:53+02:00 New Revision: 82ce8296b8024f1fb549c4b2dfcf736f809e19b7 URL: https://github.com/llvm/llvm-project/commit/82ce8296b8024f1fb549c4b2dfcf736f809e19b7 DIFF: https://github.com/llvm/llvm-project/commit/82ce8296b8024f1fb549c4b2dfcf736f809e19b7.diff LOG: [clang][bytecode] Don't call dtors of anonymous unions (#110087) Added: Modified: clang/lib/AST/ByteCode/Compiler.cpp clang/lib/AST/ByteCode/Record.cpp clang/lib/AST/ByteCode/Record.h clang/test/AST/ByteCode/cxx23.cpp Removed: diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index e54b6568d7060b..6e3ea6bd070bc1 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -5302,6 +5302,9 @@ bool Compiler::compileDestructor(const CXXDestructorDecl *Dtor) { } for (const Record::Base &Base : llvm::reverse(R->bases())) { +if (Base.R->isAnonymousUnion()) + continue; + if (!this->emitGetPtrBase(Base.Offset, SourceInfo{})) return false; if (!this->emitRecordDestruction(Base.R)) @@ -6147,6 +6150,7 @@ bool Compiler::emitComplexComparison(const Expr *LHS, const Expr *RHS, template bool Compiler::emitRecordDestruction(const Record *R) { assert(R); + assert(!R->isAnonymousUnion()); const CXXDestructorDecl *Dtor = R->getDestructor(); if (!Dtor || Dtor->isTrivial()) return true; @@ -6202,6 +6206,9 @@ bool Compiler::emitDestruction(const Descriptor *Desc) { } assert(Desc->ElemRecord); + if (Desc->ElemRecord->isAnonymousUnion()) +return true; + return this->emitRecordDestruction(Desc->ElemRecord); } diff --git a/clang/lib/AST/ByteCode/Record.cpp b/clang/lib/AST/ByteCode/Record.cpp index ec1b55da347af6..0c06bec7e5508e 100644 --- a/clang/lib/AST/ByteCode/Record.cpp +++ b/clang/lib/AST/ByteCode/Record.cpp @@ -16,7 +16,8 @@ Record::Record(const RecordDecl *Decl, BaseList &&SrcBases, FieldList &&SrcFields, VirtualBaseList &&SrcVirtualBases, unsigned VirtualSize, unsigned BaseSize) : Decl(Decl), Bases(std::move(SrcBases)), Fields(std::move(SrcFields)), - BaseSize(BaseSize), VirtualSize(VirtualSize), IsUnion(Decl->isUnion()) { + BaseSize(BaseSize), VirtualSize(VirtualSize), IsUnion(Decl->isUnion()), + IsAnonymousUnion(IsUnion && Decl->isAnonymousStructOrUnion()) { for (Base &V : SrcVirtualBases) VirtualBases.push_back({V.Decl, V.Offset + BaseSize, V.Desc, V.R}); diff --git a/clang/lib/AST/ByteCode/Record.h b/clang/lib/AST/ByteCode/Record.h index 83e15b125f77a9..7a5c482e4efccd 100644 --- a/clang/lib/AST/ByteCode/Record.h +++ b/clang/lib/AST/ByteCode/Record.h @@ -54,6 +54,8 @@ class Record final { const std::string getName() const; /// Checks if the record is a union. bool isUnion() const { return IsUnion; } + /// Checks if the record is an anonymous union. + bool isAnonymousUnion() const { return IsAnonymousUnion; } /// Returns the size of the record. unsigned getSize() const { return BaseSize; } /// Returns the full size of the record, including records. @@ -134,6 +136,8 @@ class Record final { unsigned VirtualSize; /// If this record is a union. bool IsUnion; + /// If this is an anonymous union. + bool IsAnonymousUnion; }; } // namespace interp diff --git a/clang/test/AST/ByteCode/cxx23.cpp b/clang/test/AST/ByteCode/cxx23.cpp index 756eec5b825605..9d7e9d753e6d2f 100644 --- a/clang/test/AST/ByteCode/cxx23.cpp +++ b/clang/test/AST/ByteCode/cxx23.cpp @@ -238,3 +238,34 @@ namespace TwosComplementShifts { static_assert(-3 >> 1 == -2); static_assert(-7 >> 1 == -4); } + +namespace AnonUnionDtor { + struct A { +A (); +~A(); + }; + + template + struct opt + { +union { // all20-note {{is not literal}} + char c; + T data; +}; + +constexpr opt() {} + +constexpr ~opt() { + if (engaged) + data.~T(); + } + +bool engaged = false; + }; + + consteval void foo() { +opt a; // all20-error {{variable of non-literal type}} + } + + void bar() { foo(); } +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][bytecode] Don't call dtors of anonymous unions (PR #110087)
https://github.com/tbaederr closed https://github.com/llvm/llvm-project/pull/110087 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ARM] Fix musttail calls (PR #109943)
https://github.com/ostannard updated https://github.com/llvm/llvm-project/pull/109943 >From f96d3a1a44ade11f5a9879b49bb3d5296c4b225e Mon Sep 17 00:00:00 2001 From: Oliver Stannard Date: Thu, 9 May 2024 12:58:41 +0100 Subject: [PATCH 01/11] [ARM] Re-generate a test --- llvm/test/CodeGen/ARM/fp-arg-shuffle.ll | 24 1 file changed, 24 insertions(+) diff --git a/llvm/test/CodeGen/ARM/fp-arg-shuffle.ll b/llvm/test/CodeGen/ARM/fp-arg-shuffle.ll index 4996cc8ecbf022..36f5a4b30af409 100644 --- a/llvm/test/CodeGen/ARM/fp-arg-shuffle.ll +++ b/llvm/test/CodeGen/ARM/fp-arg-shuffle.ll @@ -1,8 +1,32 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4 ; RUN: llc -mtriple=arm-eabi -mattr=+neon -float-abi=soft %s -o - | FileCheck %s ; CHECK: function1 ; CHECK-NOT: vmov define double @function1(double %a, double %b, double %c, double %d, double %e, double %f) nounwind noinline ssp { +; CHECK-LABEL: function1: +; CHECK: @ %bb.0: @ %entry +; CHECK-NEXT:.save {r4, r5, r11, lr} +; CHECK-NEXT:push {r4, r5, r11, lr} +; CHECK-NEXT:.pad #32 +; CHECK-NEXT:sub sp, sp, #32 +; CHECK-NEXT:add lr, sp, #64 +; CHECK-NEXT:vldr d16, [sp, #56] +; CHECK-NEXT:str r2, [sp, #16] +; CHECK-NEXT:ldm lr, {r4, r5, r12, lr} +; CHECK-NEXT:str r3, [sp, #20] +; CHECK-NEXT:mov r3, r5 +; CHECK-NEXT:str r0, [sp, #24] +; CHECK-NEXT:mov r0, r12 +; CHECK-NEXT:str r1, [sp, #28] +; CHECK-NEXT:mov r1, lr +; CHECK-NEXT:mov r2, r4 +; CHECK-NEXT:vldr d17, [sp, #48] +; CHECK-NEXT:vstmia sp, {d16, d17} +; CHECK-NEXT:bl function2 +; CHECK-NEXT:add sp, sp, #32 +; CHECK-NEXT:pop {r4, r5, r11, lr} +; CHECK-NEXT:mov pc, lr entry: %call = tail call double @function2(double %f, double %e, double %d, double %c, double %b, double %a) nounwind ret double %call >From 5d8d80070c9e660d1fe59a1d02fba3f5bc1a0217 Mon Sep 17 00:00:00 2001 From: Oliver Stannard Date: Tue, 24 Sep 2024 10:46:47 +0100 Subject: [PATCH 02/11] [ARM] Fix comment typo --- llvm/lib/Target/ARM/ARMISelLowering.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Target/ARM/ARMISelLowering.cpp b/llvm/lib/Target/ARM/ARMISelLowering.cpp index a03928b618df03..7bc62969624e7a 100644 --- a/llvm/lib/Target/ARM/ARMISelLowering.cpp +++ b/llvm/lib/Target/ARM/ARMISelLowering.cpp @@ -2407,8 +2407,8 @@ ARMTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI, isTailCall = false; // For both the non-secure calls and the returns from a CMSE entry function, - // the function needs to do some extra work afte r the call, or before the - // return, respectively, thus it cannot end with atail call + // the function needs to do some extra work after the call, or before the + // return, respectively, thus it cannot end with a tail call if (isCmseNSCall || AFI->isCmseNSEntryFunction()) isTailCall = false; >From 855d73d6a3852aa013576e8bf7fb679a955d9260 Mon Sep 17 00:00:00 2001 From: Oliver Stannard Date: Thu, 9 May 2024 13:00:46 +0100 Subject: [PATCH 03/11] [ARM] Add debug trace for tail-call optimisation There are lots of reasons a call might not be eligible for tail-call optimisation, this adds debug trace to help understand the compiler's decisions here. --- llvm/lib/Target/ARM/ARMISelLowering.cpp | 62 +++-- 1 file changed, 47 insertions(+), 15 deletions(-) diff --git a/llvm/lib/Target/ARM/ARMISelLowering.cpp b/llvm/lib/Target/ARM/ARMISelLowering.cpp index 7bc62969624e7a..b7d52a69cdb9ab 100644 --- a/llvm/lib/Target/ARM/ARMISelLowering.cpp +++ b/llvm/lib/Target/ARM/ARMISelLowering.cpp @@ -3046,8 +3046,10 @@ bool ARMTargetLowering::IsEligibleForTailCallOptimization( for (const CCValAssign &AL : ArgLocs) if (AL.isRegLoc()) AddressRegisters.erase(AL.getLocReg()); -if (AddressRegisters.empty()) +if (AddressRegisters.empty()) { + LLVM_DEBUG(dbgs() << "false (no reg to hold function pointer)\n"); return false; +} } // Look for obvious safe cases to perform tail call optimization that do not @@ -3056,18 +3058,25 @@ bool ARMTargetLowering::IsEligibleForTailCallOptimization( // Exception-handling functions need a special set of instructions to indicate // a return to the hardware. Tail-calling another function would probably // break this. - if (CallerF.hasFnAttribute("interrupt")) + if (CallerF.hasFnAttribute("interrupt")) { + LLVM_DEBUG(dbgs() << "false (interrupt attribute)\n"); return false; + } - if (canGuaranteeTCO(CalleeCC, getTargetMachine().Options.GuaranteedTailCallOpt)) + if (canGuaranteeTCO(CalleeCC, getTargetMachine().Options.GuaranteedTailCallOpt)) { +LLVM_DEBUG(dbgs() << (CalleeCC == CallerCC ? "true" : "false") + << " (guaranteed tail-call CC)\n"); return CalleeCC == CallerCC; + } // Also avoid sibcall optimization if either ca
[clang] [clang-tools-extra] [clang] Extend diagnose_if to accept more detailed warning information (PR #70976)
mikaelholmen wrote: Thanks @kadircet https://github.com/llvm/llvm-project/pull/70976 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Driver][AArch64] Add support for aarch64-amazon-linux triple (PR #109263)
peterwaller-arm wrote: @MaskRay please would you kindly reconsider aarch64-amazon-linux triple as an exception given the presence of x86_64 equivalent? I've explored that `LLVM_DEFAULT_TARGET_TRIPLE` if unspecified comes from `LLVM_INFERRED_HOST_TRIPLE` which comes from config.guess in here: https://github.com/llvm/llvm-project/blob/592adb0b24aca2ccc88d9f5f1c427361897d1172/llvm/cmake/modules/GetHostTriple.cmake#L49 config.guess is copy of an external project with a different license; this is what reports `aarch64-unknown-linux-gnu`. For the time being it would seem fair to put aarch64 on the same footing as x86_64 here. https://github.com/llvm/llvm-project/pull/109263 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] return first Decl for CanonicalDecl in TranslationUnitDecl (PR #110101)
vgvassilev wrote: Can we add a unittest under clang/unittest/Interpreter? https://github.com/llvm/llvm-project/pull/110101 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] nonblocking/nonallocating attributes: 2nd pass caller/callee analysis (PR #99656)
https://github.com/Sirraide approved this pull request. I think that was everything, so lgtm. Since this is a rather big pr tho, I’d like for someone else to approve it too before we merge it. https://github.com/llvm/llvm-project/pull/99656 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [sanitizer] Document AddressSanitizer security considerations (PR #100937)
@@ -351,6 +353,14 @@ There are several limitations: * Check groups (like ``undefined``) can't be used in suppressions file, only fine-grained checks are supported. +Security Considerations +=== + +UndefinedBehaviorSanitizer's runtime is meant for testing purposes and its usage vitalybuka wrote: there is also trap mode which should be acceptable for production https://github.com/llvm/llvm-project/pull/100937 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [sanitizer] Document AddressSanitizer security considerations (PR #100937)
vitalybuka wrote: Don't forget to click "re-request review" after updating PRs, or it's not displayed as pending review request. https://github.com/llvm/llvm-project/pull/100937 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add "AllowShortNamespacesOnASingleLine" option (PR #105597)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff c557d8520413476221a4f3bf2b7b3fed17681691 ad1fdbb0131b10acf213b7fe49b0421856eadbc8 --extensions cpp,h -- clang/include/clang/Format/Format.h clang/lib/Format/Format.cpp clang/lib/Format/UnwrappedLineFormatter.cpp clang/unittests/Format/ConfigParseTest.cpp clang/unittests/Format/FormatTest.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp index 6b57f80056..300bd770f9 100644 --- a/clang/lib/Format/UnwrappedLineFormatter.cpp +++ b/clang/lib/Format/UnwrappedLineFormatter.cpp @@ -660,8 +660,7 @@ private: return 0; // Check that the line after the inner result starts with a closing brace // which we are permitted to merge into one line. - if (I[N]->First->is(tok::r_brace) && - !I[N]->First->MustBreakBefore && + if (I[N]->First->is(tok::r_brace) && !I[N]->First->MustBreakBefore && !I[MergedLines + 1]->Last->is(tok::comment) && nextNLinesFitInto(I, I + N + 1, Limit)) { return N; `` https://github.com/llvm/llvm-project/pull/105597 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][bytecode] Don't call dtors of anonymous unions (PR #110087)
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/110087 None >From d54a46d9ccc3eed3be0d319f26c49f069a68a9e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Thu, 26 Sep 2024 09:41:33 +0200 Subject: [PATCH] [clang][bytecode] Don't call dtors of anonymous unions --- clang/lib/AST/ByteCode/Compiler.cpp | 7 +++ clang/lib/AST/ByteCode/Record.cpp | 3 ++- clang/lib/AST/ByteCode/Record.h | 4 clang/test/AST/ByteCode/cxx23.cpp | 31 + 4 files changed, 44 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index e54b6568d7060b..6e3ea6bd070bc1 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -5302,6 +5302,9 @@ bool Compiler::compileDestructor(const CXXDestructorDecl *Dtor) { } for (const Record::Base &Base : llvm::reverse(R->bases())) { +if (Base.R->isAnonymousUnion()) + continue; + if (!this->emitGetPtrBase(Base.Offset, SourceInfo{})) return false; if (!this->emitRecordDestruction(Base.R)) @@ -6147,6 +6150,7 @@ bool Compiler::emitComplexComparison(const Expr *LHS, const Expr *RHS, template bool Compiler::emitRecordDestruction(const Record *R) { assert(R); + assert(!R->isAnonymousUnion()); const CXXDestructorDecl *Dtor = R->getDestructor(); if (!Dtor || Dtor->isTrivial()) return true; @@ -6202,6 +6206,9 @@ bool Compiler::emitDestruction(const Descriptor *Desc) { } assert(Desc->ElemRecord); + if (Desc->ElemRecord->isAnonymousUnion()) +return true; + return this->emitRecordDestruction(Desc->ElemRecord); } diff --git a/clang/lib/AST/ByteCode/Record.cpp b/clang/lib/AST/ByteCode/Record.cpp index ec1b55da347af6..0c06bec7e5508e 100644 --- a/clang/lib/AST/ByteCode/Record.cpp +++ b/clang/lib/AST/ByteCode/Record.cpp @@ -16,7 +16,8 @@ Record::Record(const RecordDecl *Decl, BaseList &&SrcBases, FieldList &&SrcFields, VirtualBaseList &&SrcVirtualBases, unsigned VirtualSize, unsigned BaseSize) : Decl(Decl), Bases(std::move(SrcBases)), Fields(std::move(SrcFields)), - BaseSize(BaseSize), VirtualSize(VirtualSize), IsUnion(Decl->isUnion()) { + BaseSize(BaseSize), VirtualSize(VirtualSize), IsUnion(Decl->isUnion()), + IsAnonymousUnion(IsUnion && Decl->isAnonymousStructOrUnion()) { for (Base &V : SrcVirtualBases) VirtualBases.push_back({V.Decl, V.Offset + BaseSize, V.Desc, V.R}); diff --git a/clang/lib/AST/ByteCode/Record.h b/clang/lib/AST/ByteCode/Record.h index 83e15b125f77a9..7a5c482e4efccd 100644 --- a/clang/lib/AST/ByteCode/Record.h +++ b/clang/lib/AST/ByteCode/Record.h @@ -54,6 +54,8 @@ class Record final { const std::string getName() const; /// Checks if the record is a union. bool isUnion() const { return IsUnion; } + /// Checks if the record is an anonymous union. + bool isAnonymousUnion() const { return IsAnonymousUnion; } /// Returns the size of the record. unsigned getSize() const { return BaseSize; } /// Returns the full size of the record, including records. @@ -134,6 +136,8 @@ class Record final { unsigned VirtualSize; /// If this record is a union. bool IsUnion; + /// If this is an anonymous union. + bool IsAnonymousUnion; }; } // namespace interp diff --git a/clang/test/AST/ByteCode/cxx23.cpp b/clang/test/AST/ByteCode/cxx23.cpp index 756eec5b825605..9d7e9d753e6d2f 100644 --- a/clang/test/AST/ByteCode/cxx23.cpp +++ b/clang/test/AST/ByteCode/cxx23.cpp @@ -238,3 +238,34 @@ namespace TwosComplementShifts { static_assert(-3 >> 1 == -2); static_assert(-7 >> 1 == -4); } + +namespace AnonUnionDtor { + struct A { +A (); +~A(); + }; + + template + struct opt + { +union { // all20-note {{is not literal}} + char c; + T data; +}; + +constexpr opt() {} + +constexpr ~opt() { + if (engaged) + data.~T(); + } + +bool engaged = false; + }; + + consteval void foo() { +opt a; // all20-error {{variable of non-literal type}} + } + + void bar() { foo(); } +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] f3111cc - [clang][bytecode][NFC] Remove a useless cast
Author: Timm Bäder Date: 2024-09-26T09:43:38+02:00 New Revision: f3111cc77bea8d4f6b3ca90ee5457cff5faeb3fc URL: https://github.com/llvm/llvm-project/commit/f3111cc77bea8d4f6b3ca90ee5457cff5faeb3fc DIFF: https://github.com/llvm/llvm-project/commit/f3111cc77bea8d4f6b3ca90ee5457cff5faeb3fc.diff LOG: [clang][bytecode][NFC] Remove a useless cast getDecl() now always returns a ValueDecl. Added: Modified: clang/lib/AST/ByteCode/MemberPointer.cpp Removed: diff --git a/clang/lib/AST/ByteCode/MemberPointer.cpp b/clang/lib/AST/ByteCode/MemberPointer.cpp index 0fe94db97a3c40..dfc8583e464abf 100644 --- a/clang/lib/AST/ByteCode/MemberPointer.cpp +++ b/clang/lib/AST/ByteCode/MemberPointer.cpp @@ -79,7 +79,7 @@ APValue MemberPointer::toAPValue(const ASTContext &ASTCtx) const { if (hasBase()) return Base.toAPValue(ASTCtx); - return APValue(cast(getDecl()), /*IsDerivedMember=*/false, + return APValue(getDecl(), /*IsDerivedMember=*/false, /*Path=*/{}); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][bytecode] Don't call dtors of anonymous unions (PR #110087)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/110087.diff 4 Files Affected: - (modified) clang/lib/AST/ByteCode/Compiler.cpp (+7) - (modified) clang/lib/AST/ByteCode/Record.cpp (+2-1) - (modified) clang/lib/AST/ByteCode/Record.h (+4) - (modified) clang/test/AST/ByteCode/cxx23.cpp (+31) ``diff diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index e54b6568d7060b..6e3ea6bd070bc1 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -5302,6 +5302,9 @@ bool Compiler::compileDestructor(const CXXDestructorDecl *Dtor) { } for (const Record::Base &Base : llvm::reverse(R->bases())) { +if (Base.R->isAnonymousUnion()) + continue; + if (!this->emitGetPtrBase(Base.Offset, SourceInfo{})) return false; if (!this->emitRecordDestruction(Base.R)) @@ -6147,6 +6150,7 @@ bool Compiler::emitComplexComparison(const Expr *LHS, const Expr *RHS, template bool Compiler::emitRecordDestruction(const Record *R) { assert(R); + assert(!R->isAnonymousUnion()); const CXXDestructorDecl *Dtor = R->getDestructor(); if (!Dtor || Dtor->isTrivial()) return true; @@ -6202,6 +6206,9 @@ bool Compiler::emitDestruction(const Descriptor *Desc) { } assert(Desc->ElemRecord); + if (Desc->ElemRecord->isAnonymousUnion()) +return true; + return this->emitRecordDestruction(Desc->ElemRecord); } diff --git a/clang/lib/AST/ByteCode/Record.cpp b/clang/lib/AST/ByteCode/Record.cpp index ec1b55da347af6..0c06bec7e5508e 100644 --- a/clang/lib/AST/ByteCode/Record.cpp +++ b/clang/lib/AST/ByteCode/Record.cpp @@ -16,7 +16,8 @@ Record::Record(const RecordDecl *Decl, BaseList &&SrcBases, FieldList &&SrcFields, VirtualBaseList &&SrcVirtualBases, unsigned VirtualSize, unsigned BaseSize) : Decl(Decl), Bases(std::move(SrcBases)), Fields(std::move(SrcFields)), - BaseSize(BaseSize), VirtualSize(VirtualSize), IsUnion(Decl->isUnion()) { + BaseSize(BaseSize), VirtualSize(VirtualSize), IsUnion(Decl->isUnion()), + IsAnonymousUnion(IsUnion && Decl->isAnonymousStructOrUnion()) { for (Base &V : SrcVirtualBases) VirtualBases.push_back({V.Decl, V.Offset + BaseSize, V.Desc, V.R}); diff --git a/clang/lib/AST/ByteCode/Record.h b/clang/lib/AST/ByteCode/Record.h index 83e15b125f77a9..7a5c482e4efccd 100644 --- a/clang/lib/AST/ByteCode/Record.h +++ b/clang/lib/AST/ByteCode/Record.h @@ -54,6 +54,8 @@ class Record final { const std::string getName() const; /// Checks if the record is a union. bool isUnion() const { return IsUnion; } + /// Checks if the record is an anonymous union. + bool isAnonymousUnion() const { return IsAnonymousUnion; } /// Returns the size of the record. unsigned getSize() const { return BaseSize; } /// Returns the full size of the record, including records. @@ -134,6 +136,8 @@ class Record final { unsigned VirtualSize; /// If this record is a union. bool IsUnion; + /// If this is an anonymous union. + bool IsAnonymousUnion; }; } // namespace interp diff --git a/clang/test/AST/ByteCode/cxx23.cpp b/clang/test/AST/ByteCode/cxx23.cpp index 756eec5b825605..9d7e9d753e6d2f 100644 --- a/clang/test/AST/ByteCode/cxx23.cpp +++ b/clang/test/AST/ByteCode/cxx23.cpp @@ -238,3 +238,34 @@ namespace TwosComplementShifts { static_assert(-3 >> 1 == -2); static_assert(-7 >> 1 == -4); } + +namespace AnonUnionDtor { + struct A { +A (); +~A(); + }; + + template + struct opt + { +union { // all20-note {{is not literal}} + char c; + T data; +}; + +constexpr opt() {} + +constexpr ~opt() { + if (engaged) + data.~T(); + } + +bool engaged = false; + }; + + consteval void foo() { +opt a; // all20-error {{variable of non-literal type}} + } + + void bar() { foo(); } +} `` https://github.com/llvm/llvm-project/pull/110087 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] ae54a00 - [clang][analyzer] FixedAddressChecker: no warning if system macro is used (#108993)
Author: Balázs Kéri Date: 2024-09-26T09:49:29+02:00 New Revision: ae54a00cc1eb64a0300e190ccdc46ae9b31d2835 URL: https://github.com/llvm/llvm-project/commit/ae54a00cc1eb64a0300e190ccdc46ae9b31d2835 DIFF: https://github.com/llvm/llvm-project/commit/ae54a00cc1eb64a0300e190ccdc46ae9b31d2835.diff LOG: [clang][analyzer] FixedAddressChecker: no warning if system macro is used (#108993) Added: Modified: clang/lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp clang/test/Analysis/Inputs/system-header-simulator.h clang/test/Analysis/ptr-arith.c Removed: diff --git a/clang/lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp index 7aefcdc6d358aa..e7fde3edc7f9ee 100644 --- a/clang/lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp @@ -48,6 +48,9 @@ void FixedAddressChecker::checkPreStmt(const BinaryOperator *B, if (!RV.isConstant() || RV.isZeroConstant()) return; + if (C.getSourceManager().isInSystemMacro(B->getRHS()->getBeginLoc())) +return; + if (ExplodedNode *N = C.generateNonFatalErrorNode()) { // FIXME: improve grammar in the following strings: constexpr llvm::StringLiteral Msg = diff --git a/clang/test/Analysis/Inputs/system-header-simulator.h b/clang/test/Analysis/Inputs/system-header-simulator.h index 8fd51449ecc0a4..fadc09f65d5365 100644 --- a/clang/test/Analysis/Inputs/system-header-simulator.h +++ b/clang/test/Analysis/Inputs/system-header-simulator.h @@ -154,3 +154,11 @@ void _Exit(int status) __attribute__ ((__noreturn__)); #define EOF (-1) #define offsetof(t, d) __builtin_offsetof(t, d) + +struct sigaction { + void (*sa_handler)(int); +}; +#define SIGINT 2 +#defineSIG_IGN (void (*)(int))1 + +int sigaction(int, const struct sigaction *restrict, struct sigaction *restrict); diff --git a/clang/test/Analysis/ptr-arith.c b/clang/test/Analysis/ptr-arith.c index f99dfabb073666..020a5006292306 100644 --- a/clang/test/Analysis/ptr-arith.c +++ b/clang/test/Analysis/ptr-arith.c @@ -1,6 +1,8 @@ // RUN: %clang_analyze_cc1 -analyzer-checker=alpha.core.FixedAddr,alpha.core.PointerArithm,debug.ExprInspection -Wno-pointer-to-int-cast -verify -triple x86_64-apple-darwin9 -Wno-tautological-pointer-compare -analyzer-config eagerly-assume=false %s // RUN: %clang_analyze_cc1 -analyzer-checker=alpha.core.FixedAddr,alpha.core.PointerArithm,debug.ExprInspection -Wno-pointer-to-int-cast -verify -triple i686-apple-darwin9 -Wno-tautological-pointer-compare -analyzer-config eagerly-assume=false %s +#include "Inputs/system-header-simulator.h" + void clang_analyzer_eval(int); void clang_analyzer_dump(int); @@ -35,9 +37,20 @@ domain_port (const char *domain_b, const char *domain_e, return port; } +#define FIXED_VALUE (int*) 0x + void f4(void) { int *p; p = (int*) 0x1; // expected-warning{{Using a fixed address is not portable because that address will probably not be valid in all environments or platforms}} + long x = 0x10100; + x += 10; + p = (int*) x; // expected-warning{{Using a fixed address is not portable because that address will probably not be valid in all environments or platforms}} + + struct sigaction sa; + sa.sa_handler = SIG_IGN; // no warning (exclude macros defined in system header) + sigaction(SIGINT, &sa, NULL); + + p = FIXED_VALUE; // expected-warning{{Using a fixed address is not portable because that address will probably not be valid in all environments or platforms}} } void f5(void) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] FixedAddressChecker: no warning if system macro is used (PR #108993)
https://github.com/balazske closed https://github.com/llvm/llvm-project/pull/108993 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add "AllowShortNamespacesOnASingleLine" option (PR #105597)
https://github.com/galenelias updated https://github.com/llvm/llvm-project/pull/105597 >From 4118b7dde9adbee7b6aaf5d094d34cb6b64f6c77 Mon Sep 17 00:00:00 2001 From: Galen Elias Date: Wed, 21 Aug 2024 16:33:42 -0700 Subject: [PATCH 1/9] clang-format: Add "AllowShortNamespacesOnASingleLine" option This addresses: https://github.com/llvm/llvm-project/issues/101363 which is a resurrection of a previously opened but never completed review: https://reviews.llvm.org/D11851 The feature is to allow code like the following not to be broken across multiple lines: ``` namespace foo { class bar; } namespace foo { namespace bar { class baz; } } ``` Code like this is commonly used for forward declarations, which are ideally kept compact. This is also apparently the format that include-what-you-use will insert for forward declarations. --- clang/include/clang/Format/Format.h | 5 + clang/lib/Format/Format.cpp | 3 + clang/lib/Format/UnwrappedLineFormatter.cpp | 82 ++ clang/unittests/Format/FormatTest.cpp | 112 4 files changed, 202 insertions(+) diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h index 2af1d4065c3cc1..c96fc4d1d9557b 100644 --- a/clang/include/clang/Format/Format.h +++ b/clang/include/clang/Format/Format.h @@ -972,6 +972,11 @@ struct FormatStyle { /// \version 3.7 bool AllowShortLoopsOnASingleLine; + /// If ``true``, ``namespace a { class b; }`` can be put on a single a single + /// line. + /// \version 19 + bool AllowShortNamespacesOnASingleLine; + /// Different ways to break after the function definition return type. /// This option is **deprecated** and is retained for backwards compatibility. enum DefinitionReturnTypeBreakingStyle : int8_t { diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 97fac41cdd3008..495b727e609df6 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -952,6 +952,8 @@ template <> struct MappingTraits { Style.AllowShortLambdasOnASingleLine); IO.mapOptional("AllowShortLoopsOnASingleLine", Style.AllowShortLoopsOnASingleLine); +IO.mapOptional("AllowShortNamespacesOnASingleLine", + Style.AllowShortNamespacesOnASingleLine); IO.mapOptional("AlwaysBreakAfterDefinitionReturnType", Style.AlwaysBreakAfterDefinitionReturnType); IO.mapOptional("AlwaysBreakBeforeMultilineStrings", @@ -1457,6 +1459,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) { LLVMStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never; LLVMStyle.AllowShortLambdasOnASingleLine = FormatStyle::SLS_All; LLVMStyle.AllowShortLoopsOnASingleLine = false; + LLVMStyle.AllowShortNamespacesOnASingleLine = false; LLVMStyle.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_None; LLVMStyle.AlwaysBreakBeforeMultilineStrings = false; LLVMStyle.AttributeMacros.push_back("__capability"); diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp index 1804c1437fd41d..971eac1978bb71 100644 --- a/clang/lib/Format/UnwrappedLineFormatter.cpp +++ b/clang/lib/Format/UnwrappedLineFormatter.cpp @@ -420,6 +420,15 @@ class LineJoiner { TheLine->First != LastNonComment) { return MergeShortFunctions ? tryMergeSimpleBlock(I, E, Limit) : 0; } + +if (TheLine->Last->is(tok::l_brace)) { + if (Style.AllowShortNamespacesOnASingleLine && + TheLine->First->is(tok::kw_namespace)) { +if (unsigned result = tryMergeNamespace(I, E, Limit)) + return result; + } +} + // Try to merge a control statement block with left brace unwrapped. if (TheLine->Last->is(tok::l_brace) && FirstNonComment != TheLine->Last && FirstNonComment->isOneOf(tok::kw_if, tok::kw_while, tok::kw_for, @@ -616,6 +625,62 @@ class LineJoiner { return 1; } + unsigned tryMergeNamespace(SmallVectorImpl::const_iterator I, + SmallVectorImpl::const_iterator E, + unsigned Limit) { +if (Limit == 0) + return 0; +if (I[1]->InPPDirective != (*I)->InPPDirective || +(I[1]->InPPDirective && I[1]->First->HasUnescapedNewline)) { + return 0; +} +if (I + 2 == E || I[2]->Type == LT_Invalid) + return 0; + +Limit = limitConsideringMacros(I + 1, E, Limit); + +if (!nextTwoLinesFitInto(I, Limit)) + return 0; + +// Check if it's a namespace inside a namespace, and call recursively if so +// '3' is the sizes of the whitespace and closing brace for " _inner_ }" +if (I[1]->First->is(tok::kw_namespace)) { + if (I[1]->Last->is(TT_LineComment)) +return 0; + + unsigned inner_limit = Limit - I[1]->Last->TotalLength - 3; + unsigned inner_result = tryMergeNamespace(I + 1, E, inner_limit); + if (!inner_result) +
[clang] [llvm] [HLSL] Allow resource type attributes only on __hlsl_resource_t (PR #110079)
https://github.com/hekota updated https://github.com/llvm/llvm-project/pull/110079 >From 970aab0a930e38dfd266c01065112602bb274a5e Mon Sep 17 00:00:00 2001 From: Helena Kotas Date: Wed, 25 Sep 2024 15:48:18 -0700 Subject: [PATCH 1/4] [HLSL] Allow resource type attributes only on __hlsl_resource_t --- clang/include/clang/AST/Type.h| 4 +- .../clang/Basic/DiagnosticSemaKinds.td| 1 + clang/include/clang/Sema/SemaHLSL.h | 2 +- clang/lib/AST/ASTContext.cpp | 4 +- clang/lib/Sema/HLSLExternalSemaSource.cpp | 72 +-- clang/lib/Sema/SemaHLSL.cpp | 10 ++- clang/lib/Sema/SemaType.cpp | 2 +- clang/test/AST/HLSL/RWBuffer-AST.hlsl | 22 ++ clang/test/AST/HLSL/StructuredBuffer-AST.hlsl | 22 ++ .../CodeGenHLSL/buffer-array-operator.hlsl| 3 + .../implicit-norecurse-attrib.hlsl| 2 +- .../hlsl_contained_type_attr_error.hlsl | 4 ++ .../ParserHLSL/hlsl_is_rov_attr_error.hlsl| 4 ++ .../hlsl_raw_buffer_attr_error.hlsl | 4 ++ .../hlsl_resource_class_attr_error.hlsl | 3 + .../hlsl_resource_handle_attrs.hlsl | 6 +- .../Types/Traits/IsIntangibleType.hlsl| 3 + 17 files changed, 85 insertions(+), 83 deletions(-) diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h index dc87b84153e74a..67e75652a16649 100644 --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -6191,7 +6191,9 @@ class HLSLAttributedResourceType : public Type, public llvm::FoldingSetNode { HLSLAttributedResourceType(QualType Canon, QualType Wrapped, QualType Contained, const Attributes &Attrs) - : Type(HLSLAttributedResource, Canon, Wrapped->getDependence()), + : Type(HLSLAttributedResource, Canon, + Contained.isNull() ? TypeDependence::None +: Contained->getDependence()), WrappedType(Wrapped), ContainedType(Contained), Attrs(Attrs) {} public: diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index e4e04bff8b5120..a9b2042fcff4e3 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -12394,6 +12394,7 @@ def err_hlsl_packoffset_alignment_mismatch : Error<"packoffset at 'y' not match def err_hlsl_pointers_unsupported : Error< "%select{pointers|references}0 are unsupported in HLSL">; def err_hlsl_missing_resource_class : Error<"HLSL resource needs to have [[hlsl::resource_class()]] attribute">; +def err_hlsl_attribute_needs_intangible_type: Error<"attribute %0 can be used only on HLSL intangible type %1">; def err_hlsl_operator_unsupported : Error< "the '%select{&|*|->}0' operator is unsupported in HLSL">; diff --git a/clang/include/clang/Sema/SemaHLSL.h b/clang/include/clang/Sema/SemaHLSL.h index e088254c566d3e..311cd58bbcac2c 100644 --- a/clang/include/clang/Sema/SemaHLSL.h +++ b/clang/include/clang/Sema/SemaHLSL.h @@ -70,7 +70,7 @@ class SemaHLSL : public SemaBase { void handleShaderAttr(Decl *D, const ParsedAttr &AL); void handleResourceBindingAttr(Decl *D, const ParsedAttr &AL); void handleParamModifierAttr(Decl *D, const ParsedAttr &AL); - bool handleResourceTypeAttr(const ParsedAttr &AL); + bool handleResourceTypeAttr(QualType T, const ParsedAttr &AL); bool CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); QualType ProcessResourceTypeAttributes(QualType Wrapped); diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index fd8aa8de79b49f..ced18e1617e248 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -2272,8 +2272,8 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const { #include "clang/Basic/AMDGPUTypes.def" #define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id: #include "clang/Basic/HLSLIntangibleTypes.def" - Width = 0; - Align = 8; + Width = Target->getPointerWidth(LangAS::Default); + Align = Target->getPointerAlign(LangAS::Default); break; } break; diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp b/clang/lib/Sema/HLSLExternalSemaSource.cpp index d19f79b6ddefcd..e72da9a071fb71 100644 --- a/clang/lib/Sema/HLSLExternalSemaSource.cpp +++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp @@ -117,33 +117,30 @@ struct BuiltinTypeDeclBuilder { if (Record->isCompleteDefinition()) return *this; +ASTContext &Ctx = S.getASTContext(); TypeSourceInfo *ElementTypeInfo = nullptr; -QualType Ty = Record->getASTContext().VoidPtrTy; +QualType ElemTy = Ctx.Char8Ty; if (Template) { if (const auto *TTD = dyn_cast( Template->getTemplateParameters()->getParam(0))) { -Ty = Record->getASTContext().getPointerType( -QualType(TTD->getTypeForDecl(), 0)); -
[clang] c511cc0 - [AArch64] Implement NEON vscale intrinsics (#100347)
Author: Lukacma Date: 2024-09-26T16:39:18+01:00 New Revision: c511cc099af6c25dc226af1e15b63e16295a790b URL: https://github.com/llvm/llvm-project/commit/c511cc099af6c25dc226af1e15b63e16295a790b DIFF: https://github.com/llvm/llvm-project/commit/c511cc099af6c25dc226af1e15b63e16295a790b.diff LOG: [AArch64] Implement NEON vscale intrinsics (#100347) This patch implements following intrinsics: ``` float16x4_t vscale_f16(float16x4_t vn, int16x4_t vm) float16x8_t vscaleq_f16(float16x8_t vn, int16x8_t vm) float32x2_t vscale_f32(float32x2_t vn, int32x2_t vm) float32x4_t vscaleq_f32(float32x4_t vn, int32x4_t vm) float64x2_t vscaleq_f64(float64x2_t vn, int64x2_t vm) ``` as defined in https://github.com/ARM-software/acle/pull/323 Co-authored-by: Hassnaa Hamdi Added: clang/test/CodeGen/aarch64-neon-fp8-intrinsics/acle_neon_fscale.c llvm/test/CodeGen/AArch64/neon-fp8-fscale.ll Modified: clang/include/clang/Basic/arm_neon.td clang/lib/CodeGen/CGBuiltin.cpp llvm/include/llvm/IR/IntrinsicsAArch64.td llvm/lib/Target/AArch64/AArch64InstrFormats.td llvm/lib/Target/AArch64/AArch64InstrInfo.td Removed: diff --git a/clang/include/clang/Basic/arm_neon.td b/clang/include/clang/Basic/arm_neon.td index 92f39744f3d084..8652b5e3a9c901 100644 --- a/clang/include/clang/Basic/arm_neon.td +++ b/clang/include/clang/Basic/arm_neon.td @@ -2126,3 +2126,9 @@ let ArchGuard = "defined(__aarch64__)", TargetGuard = "neon,faminmax" in { def FAMIN : WInst<"vamin", "...", "fhQdQfQh">; def FAMAX : WInst<"vamax", "...", "fhQdQfQh">; } + +let ArchGuard = "defined(__aarch64__)", TargetGuard = "fp8,neon" in { + // fscale + def FSCALE_V128 : WInst<"vscale", "..(.S)", "QdQfQh">; + def FSCALE_V64 : WInst<"vscale", "(.q)(.q)(.qS)", "fh">; +} \ No newline at end of file diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 249aead33ad73d..9033cd1ccd781d 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -13573,6 +13573,14 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID, Int = Intrinsic::aarch64_neon_famax; return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "famax"); } + case NEON::BI__builtin_neon_vscale_f16: + case NEON::BI__builtin_neon_vscaleq_f16: + case NEON::BI__builtin_neon_vscale_f32: + case NEON::BI__builtin_neon_vscaleq_f32: + case NEON::BI__builtin_neon_vscaleq_f64: { +Int = Intrinsic::aarch64_neon_fp8_fscale; +return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "fscale"); + } } } diff --git a/clang/test/CodeGen/aarch64-neon-fp8-intrinsics/acle_neon_fscale.c b/clang/test/CodeGen/aarch64-neon-fp8-intrinsics/acle_neon_fscale.c new file mode 100644 index 00..b50d30876a7c51 --- /dev/null +++ b/clang/test/CodeGen/aarch64-neon-fp8-intrinsics/acle_neon_fscale.c @@ -0,0 +1,58 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4 +#include + +// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +neon -target-feature +fp8 -O3 -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +neon -target-feature +fp8 -S -O3 -o /dev/null %s + +// CHECK-LABEL: define dso_local <4 x half> @test_vscale_f16( +// CHECK-SAME: <4 x half> noundef [[VN:%.*]], <4 x i16> noundef [[VM:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[FSCALE2_I:%.*]] = tail call <4 x half> @llvm.aarch64.neon.fp8.fscale.v4f16(<4 x half> [[VN]], <4 x i16> [[VM]]) +// CHECK-NEXT:ret <4 x half> [[FSCALE2_I]] +// +float16x4_t test_vscale_f16(float16x4_t vn, int16x4_t vm) { + return vscale_f16(vn, vm); +} + +// CHECK-LABEL: define dso_local <8 x half> @test_vscaleq_f16( +// CHECK-SAME: <8 x half> noundef [[VN:%.*]], <8 x i16> noundef [[VM:%.*]]) local_unnamed_addr #[[ATTR0]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[FSCALE2_I:%.*]] = tail call <8 x half> @llvm.aarch64.neon.fp8.fscale.v8f16(<8 x half> [[VN]], <8 x i16> [[VM]]) +// CHECK-NEXT:ret <8 x half> [[FSCALE2_I]] +// +float16x8_t test_vscaleq_f16(float16x8_t vn, int16x8_t vm) { + return vscaleq_f16(vn, vm); + +} + +// CHECK-LABEL: define dso_local <2 x float> @test_vscale_f32( +// CHECK-SAME: <2 x float> noundef [[VN:%.*]], <2 x i32> noundef [[VM:%.*]]) local_unnamed_addr #[[ATTR0]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[FSCALE2_I:%.*]] = tail call <2 x float> @llvm.aarch64.neon.fp8.fscale.v2f32(<2 x float> [[VN]], <2 x i32> [[VM]]) +// CHECK-NEXT:ret <2 x float> [[FSCALE2_I]] +// +float32x2_t test_vscale_f32(float32x2_t vn, int32x2_t vm) { + return vscale_f32(vn, vm); + +} + +// CHECK-LABEL: define dso_local <4 x float> @test_vscaleq_f32( +// CHECK-SAME: <4 x float> noundef [[VN:%.*]], <4 x i32> noundef [[VM:%.*]]) local_unnamed_addr #[[ATTR0]] { +// CHECK-NEXT: entry: +// CHECK-NE
[clang] [llvm] [AArch64] Implement NEON vscale intrinsics (PR #100347)
https://github.com/Lukacma closed https://github.com/llvm/llvm-project/pull/100347 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20][Modules] Fix non-determinism in serialized AST (PR #110131)
eaeltsin wrote: I cannot reproduce the non-determinism on top of this patch any more. Thanks for the fix! Please submit at your earliest convenience. https://github.com/llvm/llvm-project/pull/110131 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Clang][LLVM][AArch64] Add intrinsic for LUTI4 SME2 instruction (#97755) (PR #109953)
https://github.com/SpencerAbson approved this pull request. Thanks, there is some conflict from the [FSCALE work](https://github.com/llvm/llvm-project/pull/100128/files), but this LGTM. https://github.com/llvm/llvm-project/pull/109953 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add clang/docs/FunctionEffectAnalysis.rst. (PR #109855)
@@ -0,0 +1,503 @@ + +Function Effect Analysis + + +Introduction + + +Clang Function Effect Analysis is a C++ language extension which can warn about "unsafe" +constructs. The feature is currently tailored for the Performance Constraint attributes, +``nonblocking`` and ``nonallocating``; functions with these attributes are verified as not +containing any language constructs or calls to other functions which violate the constraint. +(See :doc:`AttributeReference`.) + + +The ``nonblocking`` and ``nonallocating`` attributes + + +Attribute syntax + + +The ``nonblocking`` and ``nonallocating`` attributes apply to function types, allowing them to be +attached to functions, blocks, function pointers, lambdas, and member functions. + +.. code-block:: c++ + + // Functions + void nonblockingFunction() [[clang::nonblocking]]; + void nonallocatingFunction() [[clang::nonallocating]]; + + // Function pointers + void (*nonblockingFunctionPtr)() [[clang::nonblocking]]; + + // Typedefs, type aliases. + typedef void (*NBFunctionPtrTypedef)() [[clang::nonblocking]]; + using NBFunctionPtrTypeAlias_gnu = __attribute__((nonblocking)) void (*)(); + using NBFunctionPtrTypeAlias_std = void (*)() [[clang::nonblocking]]; + + // C++ methods + struct Struct { +void NBMethod() [[clang::nonblocking]]; + }; + + // C++ lambdas + auto nbLambda = []() [[clang::nonblocking]] {}; + + // Blocks + void (^nbBlock)() = ^() [[clang::nonblocking]] {}; + +The attribute applies only to the function itself. In particular, it does not apply to any nested +functions or declarations, such as blocks, lambdas, and local classes. + +This document uses the C++/C23 syntax ``[[clang::nonblocking]]``, since it parallels the placement +of the ``noexcept`` specifier, and the attributes have other similarities to ``noexcept``. The GNU +``__attribute__((nonblocking))`` syntax is also supported. Note that it requires a different +placement on a C++ type alias. + +Like ``noexcept``, ``nonblocking`` and ``nonallocating`` have an optional argument, a compile-time +constant boolean expression. By default, the argument is true, so ``[[clang::nonblocking(true)]]`` +is equivalent to ``[[clang::nonblocking]]``, and declares the function type as never locking. + + +Attribute semantics +--- + +Together with ``noexcept``, the ``nonallocating`` and ``nonblocking`` attributes define an ordered +series of performance constraints. From weakest to strongest: + +- ``noexcept`` (as per the C++ standard): The function type will never throw an exception. +- ``nonallocating``: The function type will never allocate memory on the heap, and never throw an + exception. +- ``nonblocking``: The function type will never block on a lock, never allocate memory on the heap, + and never throw an exception. + +``nonblocking`` includes the ``nonallocating`` guarantee. + +``nonblocking`` and ``nonallocating`` include the ``noexcept`` guarantee, but the presence of either +attribute does not implicitly specify ``noexcept``. (It would be inappropriate for a Clang +attribute, ignored by non-Clang compilers, to imply a standard language feature.) + +``nonblocking(true)`` and ``nonallocating(true)`` apply to function *types*, and by extension, to +function-like declarations. When applied to a declaration with a body, the compiler verifies the +function, as described in the section "Analysis and warnings", below. Functions without an explicit +performance constraint are not verified. + +``nonblocking(false)`` and ``nonallocating(false)`` are synonyms for the attributes ``blocking`` and +``allocating``. They can be used on a function-like declaration to explicitly disable any potential +inference of ``nonblocking`` or ``nonallocating`` during verification. (Inference is described later +in this document). ``nonblocking(false)`` and ``nonallocating(false)`` are legal, but superfluous +when applied to a function *type*. ``float (int) [[nonblocking(false)]]`` and ``float (int)`` are +identical types. + +For all functions with no explicit performance constraint, the worst is assumed, that the function +allocates memory and potentially blocks, unless it can be inferred otherwise, as described in the dougsonos wrote: @Sirraide, despite my being a former English major who dropped out to hack on computers and play in bands, I don't mind having my writing picked apart at all! Thanks :) https://github.com/llvm/llvm-project/pull/109855 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add clang/docs/FunctionEffectAnalysis.rst. (PR #109855)
@@ -0,0 +1,503 @@ + +Function Effect Analysis + + +Introduction + + +Clang Function Effect Analysis is a C++ language extension which can warn about "unsafe" +constructs. The feature is currently tailored for the Performance Constraint attributes, +``nonblocking`` and ``nonallocating``; functions with these attributes are verified as not +containing any language constructs or calls to other functions which violate the constraint. +(See :doc:`AttributeReference`.) + + +The ``nonblocking`` and ``nonallocating`` attributes + + +Attribute syntax + + +The ``nonblocking`` and ``nonallocating`` attributes apply to function types, allowing them to be +attached to functions, blocks, function pointers, lambdas, and member functions. + +.. code-block:: c++ + + // Functions + void nonblockingFunction() [[clang::nonblocking]]; + void nonallocatingFunction() [[clang::nonallocating]]; + + // Function pointers + void (*nonblockingFunctionPtr)() [[clang::nonblocking]]; + + // Typedefs, type aliases. + typedef void (*NBFunctionPtrTypedef)() [[clang::nonblocking]]; + using NBFunctionPtrTypeAlias_gnu = __attribute__((nonblocking)) void (*)(); + using NBFunctionPtrTypeAlias_std = void (*)() [[clang::nonblocking]]; + + // C++ methods + struct Struct { +void NBMethod() [[clang::nonblocking]]; + }; + + // C++ lambdas + auto nbLambda = []() [[clang::nonblocking]] {}; + + // Blocks + void (^nbBlock)() = ^() [[clang::nonblocking]] {}; + +The attribute applies only to the function itself. In particular, it does not apply to any nested +functions or declarations, such as blocks, lambdas, and local classes. + +This document uses the C++/C23 syntax ``[[clang::nonblocking]]``, since it parallels the placement +of the ``noexcept`` specifier, and the attributes have other similarities to ``noexcept``. The GNU +``__attribute__((nonblocking))`` syntax is also supported. Note that it requires a different +placement on a C++ type alias. + +Like ``noexcept``, ``nonblocking`` and ``nonallocating`` have an optional argument, a compile-time +constant boolean expression. By default, the argument is true, so ``[[clang::nonblocking(true)]]`` +is equivalent to ``[[clang::nonblocking]]``, and declares the function type as never locking. + + +Attribute semantics +--- + +Together with ``noexcept``, the ``nonallocating`` and ``nonblocking`` attributes define an ordered +series of performance constraints. From weakest to strongest: + +- ``noexcept`` (as per the C++ standard): The function type will never throw an exception. +- ``nonallocating``: The function type will never allocate memory on the heap, and never throw an + exception. +- ``nonblocking``: The function type will never block on a lock, never allocate memory on the heap, + and never throw an exception. + +``nonblocking`` includes the ``nonallocating`` guarantee. + +``nonblocking`` and ``nonallocating`` include the ``noexcept`` guarantee, but the presence of either +attribute does not implicitly specify ``noexcept``. (It would be inappropriate for a Clang +attribute, ignored by non-Clang compilers, to imply a standard language feature.) + +``nonblocking(true)`` and ``nonallocating(true)`` apply to function *types*, and by extension, to +function-like declarations. When applied to a declaration with a body, the compiler verifies the +function, as described in the section "Analysis and warnings", below. Functions without an explicit +performance constraint are not verified. + +``nonblocking(false)`` and ``nonallocating(false)`` are synonyms for the attributes ``blocking`` and +``allocating``. They can be used on a function-like declaration to explicitly disable any potential +inference of ``nonblocking`` or ``nonallocating`` during verification. (Inference is described later +in this document). ``nonblocking(false)`` and ``nonallocating(false)`` are legal, but superfluous +when applied to a function *type*. ``float (int) [[nonblocking(false)]]`` and ``float (int)`` are +identical types. + +For all functions with no explicit performance constraint, the worst is assumed, that the function +allocates memory and potentially blocks, unless it can be inferred otherwise, as described in the +discussion of verification. + +The following list describes the meanings of all permutations of the two attributes and arguments: + +- ``nonblocking(true)`` + ``nonallocating(true)``: valid; ``nonallocating(true)`` is superfluous but + does not contradict the guarantee. +- ``nonblocking(true)`` + ``nonallocating(false)``: error, contradictory. +- ``nonblocking(false)`` + ``nonallocating(true)``: valid; the function does not allocate memory, + but may lock for other reasons. +- ``nonblocking(false)`` + ``nonallocating(false)``: valid. dougsonos wrote: I had this as a table in the
[clang] Fix "[AArch64] Implement NEON vscale intrinsics" (PR #110136)
https://github.com/Lukacma created https://github.com/llvm/llvm-project/pull/110136 This patch fixes failure of acle_neon_fscale.c in non-aarch64 targets. >From 32586c6e8ad4bab6bb27c85c30868ff34064f4a2 Mon Sep 17 00:00:00 2001 From: Lukacma Date: Thu, 26 Sep 2024 16:53:51 +0100 Subject: [PATCH] Update acle_neon_fscale.c --- .../test/CodeGen/aarch64-neon-fp8-intrinsics/acle_neon_fscale.c | 1 + 1 file changed, 1 insertion(+) diff --git a/clang/test/CodeGen/aarch64-neon-fp8-intrinsics/acle_neon_fscale.c b/clang/test/CodeGen/aarch64-neon-fp8-intrinsics/acle_neon_fscale.c index b50d30876a7c51..2fba776c30ccf1 100644 --- a/clang/test/CodeGen/aarch64-neon-fp8-intrinsics/acle_neon_fscale.c +++ b/clang/test/CodeGen/aarch64-neon-fp8-intrinsics/acle_neon_fscale.c @@ -1,3 +1,4 @@ +// REQUIRES: aarch64-registered-target // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4 #include ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AArch64] Implement NEON vscale intrinsics (PR #100347)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `openmp-offload-sles-build-only` running on `rocm-worker-hw-04-sles` while building `clang,llvm` at step 6 "Add check check-clang". Full details are available at: https://lab.llvm.org/buildbot/#/builders/140/builds/7532 Here is the relevant piece of the build log for the reference ``` Step 6 (Add check check-clang) failure: test (failure) TEST 'Clang :: CodeGen/aarch64-neon-fp8-intrinsics/acle_neon_fscale.c' FAILED Exit Code: 2 Command Output (stderr): -- RUN: at line 4: /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/clang -cc1 -internal-isystem /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/lib/clang/20/include -nostdsysteminc -triple aarch64-none-linux-gnu -target-feature +neon -target-feature +fp8 -O3 -emit-llvm -o - /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/CodeGen/aarch64-neon-fp8-intrinsics/acle_neon_fscale.c | /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/FileCheck /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/CodeGen/aarch64-neon-fp8-intrinsics/acle_neon_fscale.c + /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/clang -cc1 -internal-isystem /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/lib/clang/20/include -nostdsysteminc -triple aarch64-none-linux-gnu -target-feature +neon -target-feature +fp8 -O3 -emit-llvm -o - /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/CodeGen/aarch64-neon-fp8-intrinsics/acle_neon_fscale.c + /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/FileCheck /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/CodeGen/aarch64-neon-fp8-intrinsics/acle_neon_fscale.c /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/CodeGen/aarch64-neon-fp8-intrinsics/acle_neon_fscale.c:2:10: fatal error: 'arm_neon.h' file not found 2 | #include | ^~~~ 1 error generated. FileCheck error: '' is empty. FileCheck command line: /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/FileCheck /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/CodeGen/aarch64-neon-fp8-intrinsics/acle_neon_fscale.c -- ``` https://github.com/llvm/llvm-project/pull/100347 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AArch64] Implement NEON vscale intrinsics (PR #100347)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `clang-cmake-x86_64-avx512-linux` running on `avx512-intel64` while building `clang,llvm` at step 7 "ninja check 1". Full details are available at: https://lab.llvm.org/buildbot/#/builders/133/builds/4312 Here is the relevant piece of the build log for the reference ``` Step 7 (ninja check 1) failure: stage 1 checked (failure) TEST 'Clang :: CodeGen/aarch64-neon-fp8-intrinsics/acle_neon_fscale.c' FAILED Exit Code: 2 Command Output (stderr): -- RUN: at line 4: /localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/stage1/bin/clang -cc1 -internal-isystem /localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/stage1/lib/clang/20/include -nostdsysteminc -triple aarch64-none-linux-gnu -target-feature +neon -target-feature +fp8 -O3 -emit-llvm -o - /localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/llvm/clang/test/CodeGen/aarch64-neon-fp8-intrinsics/acle_neon_fscale.c | /localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/stage1/bin/FileCheck /localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/llvm/clang/test/CodeGen/aarch64-neon-fp8-intrinsics/acle_neon_fscale.c + /localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/stage1/bin/clang -cc1 -internal-isystem /localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/stage1/lib/clang/20/include -nostdsysteminc -triple aarch64-none-linux-gnu -target-feature +neon -target-feature +fp8 -O3 -emit-llvm -o - /localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/llvm/clang/test/CodeGen/aarch64-neon-fp8-intrinsics/acle_neon_fscale.c + /localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/stage1/bin/FileCheck /localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/llvm/clang/test/CodeGen/aarch64-neon-fp8-intrinsics/acle_neon_fscale.c /localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/llvm/clang/test/CodeGen/aarch64-neon-fp8-intrinsics/acle_neon_fscale.c:2:10: fatal error: 'arm_neon.h' file not found 2 | #include | ^~~~ 1 error generated. FileCheck error: '' is empty. FileCheck command line: /localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/stage1/bin/FileCheck /localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/llvm/clang/test/CodeGen/aarch64-neon-fp8-intrinsics/acle_neon_fscale.c -- ``` https://github.com/llvm/llvm-project/pull/100347 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Fix "[AArch64] Implement NEON vscale intrinsics" (PR #110136)
https://github.com/Lukacma closed https://github.com/llvm/llvm-project/pull/110136 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits