[clang] Add flag to opt out of wasm-opt (PR #95208)
mh4ck-Thales wrote: @sbc100 I tried to limit the scope of this new option to Wasm using the corresponding group in `Options.td` (https://github.com/ThalesGroup/llvm-project/blob/8c7052d5da074eb1d754aeddc4257d33e4e299aa/clang/include/clang/Driver/Options.td#L222), but for some reason I was unable to make it work. @sunfishcode Is there a kind of deprecation process in LLVM, when we can warn of breaking changes ? Otherwise not sure how to handle it. https://github.com/llvm/llvm-project/pull/95208 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC][Clang] Move functions of BranchProtectionInfo out of line (PR #98329)
DanielKristofKiss wrote: in some build config `TargetInfo.cpp` is built without dependency to `LLVM-Core`. https://github.com/llvm/llvm-project/pull/98329 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [WebAssembly] Disable running `wasm-opt` on components (PR #98373)
mh4ck-Thales wrote: The tests for the use of `wasm-opt` are hard to integrate into the LLVM project as `wasm-opt` is not part of the LLVM toolchain itself (which is the initial use case for the new `--no-wasm-opt` flag: as LLVM is not distributed with `wasm-opt` by default a same compilation command silently resulted of different binaries depending on the presence or not of `wasm-opt`...). I guess maybe one can hack the test suite in some way for this specific case, or maybe a suitable solution could be found to integrate `wasm-opt` into the LLVM distributions. @alexcrichton would it be relevant to open an issue in the binaryen repo for the support of Wasm components? https://github.com/llvm/llvm-project/pull/98373 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC][Clang] Move functions of BranchProtectionInfo out of line (PR #98329)
nikic wrote: > in some build config `TargetInfo.cpp` is built without dependency to > `LLVM-Core`. Okay, that means that putting this code inside Basic/ is a layering violation. You need to move it into CodeGen/. Probably best to revert the whole change in the meantime. https://github.com/llvm/llvm-project/pull/98329 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC][Clang] Move functions of BranchProtectionInfo out of line (PR #98329)
DanielKristofKiss wrote: > > in some build config `TargetInfo.cpp` is built without dependency to > > `LLVM-Core`. > > Okay, that means that putting this code inside Basic/ is a layering > violation. You need to move it into CodeGen/. Probably best to revert the > whole change in the meantime. Already reverted, I'm on it. https://github.com/llvm/llvm-project/pull/98329 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Don't crash if input file is not a module. (PR #98439)
https://github.com/ChuanqiXu9 edited https://github.com/llvm/llvm-project/pull/98439 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Don't crash if input file is not a module. (PR #98439)
https://github.com/ChuanqiXu9 approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/98439 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Don't crash if input file is not a module. (PR #98439)
@@ -226,6 +226,7 @@ def err_module_map_not_found : Error<"module map file '%0' not found">, def err_missing_module_name : Error< "no module name provided; specify one with -fmodule-name=">, DefaultFatal; +def err_file_is_not_module : Error<"file '%0' is not a module">, DefaultFatal; ChuanqiXu9 wrote: ```suggestion def err_file_is_not_module : Error<"file '%0' is not a module file">, DefaultFatal; ``` https://github.com/llvm/llvm-project/pull/98439 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Don't crash if input file is not a module. (PR #98439)
https://github.com/chestnykh updated https://github.com/llvm/llvm-project/pull/98439 >From 716e8b7b71422b5850d2f9c3710a28bcf18ffccb Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Thu, 11 Jul 2024 09:55:55 +0300 Subject: [PATCH 1/3] [Clang] Don't crash if input file is not a module. Currently clang crashes with `-module-file-info` and input file which is not a module Emit error instead of segfaulting. Fix #98365 --- clang/include/clang/Basic/DiagnosticFrontendKinds.td | 1 + clang/lib/Frontend/FrontendActions.cpp | 10 -- clang/test/Frontend/module-file-info-not-a-module.c | 3 +++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 clang/test/Frontend/module-file-info-not-a-module.c diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td index 85c32e55bdab3..029ae6457699e 100644 --- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td +++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td @@ -226,6 +226,7 @@ def err_module_map_not_found : Error<"module map file '%0' not found">, def err_missing_module_name : Error< "no module name provided; specify one with -fmodule-name=">, DefaultFatal; +def err_file_is_not_module : Error<"file '%0' is not a module">, DefaultFatal; def err_missing_module : Error< "no module named '%0' declared in module map file '%1'">, DefaultFatal; def err_no_submodule : Error<"no submodule named %0 in module '%1'">; diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index 4f064321997a2..ddefa07569c55 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -841,9 +841,15 @@ static StringRef ModuleKindName(Module::ModuleKind MK) { } void DumpModuleInfoAction::ExecuteAction() { - assert(isCurrentFileAST() && "dumping non-AST?"); - // Set up the output file. CompilerInstance &CI = getCompilerInstance(); + + // Don't process files of type other than module to avoid crash + if (!isCurrentFileAST()) { +CI.getDiagnostics().Report(diag::err_file_is_not_module) << getCurrentFile(); +return; + } + + // Set up the output file. StringRef OutputFileName = CI.getFrontendOpts().OutputFile; if (!OutputFileName.empty() && OutputFileName != "-") { std::error_code EC; diff --git a/clang/test/Frontend/module-file-info-not-a-module.c b/clang/test/Frontend/module-file-info-not-a-module.c new file mode 100644 index 0..67eba2a27051b --- /dev/null +++ b/clang/test/Frontend/module-file-info-not-a-module.c @@ -0,0 +1,3 @@ +// RUN: not %clang_cc1 -module-file-info %s 2>&1 | FileCheck %s + +// CHECK: fatal error: file '{{.*}}module-file-info-not-a-module.c' is not a module >From 7995f53068f6b2831f20f1b4519fe0cd924b Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Thu, 11 Jul 2024 10:00:31 +0300 Subject: [PATCH 2/3] [Clang] Correct code style --- clang/lib/Frontend/FrontendActions.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index ddefa07569c55..e70210d55fe28 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -845,7 +845,8 @@ void DumpModuleInfoAction::ExecuteAction() { // Don't process files of type other than module to avoid crash if (!isCurrentFileAST()) { -CI.getDiagnostics().Report(diag::err_file_is_not_module) << getCurrentFile(); +CI.getDiagnostics().Report(diag::err_file_is_not_module) +<< getCurrentFile(); return; } >From 0e2e2e6916e46c8167b6a0edbe2e09f83af37e8d Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Thu, 11 Jul 2024 10:30:15 +0300 Subject: [PATCH 3/3] [Clang] Extend description of the diagnostic --- clang/include/clang/Basic/DiagnosticFrontendKinds.td | 2 +- clang/test/Frontend/module-file-info-not-a-module.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td index 029ae6457699e..12a4617c64d87 100644 --- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td +++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td @@ -226,7 +226,7 @@ def err_module_map_not_found : Error<"module map file '%0' not found">, def err_missing_module_name : Error< "no module name provided; specify one with -fmodule-name=">, DefaultFatal; -def err_file_is_not_module : Error<"file '%0' is not a module">, DefaultFatal; +def err_file_is_not_module : Error<"file '%0' is not a module file">, DefaultFatal; def err_missing_module : Error< "no module named '%0' declared in module map file '%1'">, DefaultFatal; def err_no_submodule : Error<"no submodule named %0 in module '%1'">; diff --git a/clang/test/Frontend/module-file-info-not-a-module.c b/clang/test/Frontend/module-file-info-not-a-module.c inde
[clang] [Clang] Don't crash if input file is not a module. (PR #98439)
@@ -226,6 +226,7 @@ def err_module_map_not_found : Error<"module map file '%0' not found">, def err_missing_module_name : Error< "no module name provided; specify one with -fmodule-name=">, DefaultFatal; +def err_file_is_not_module : Error<"file '%0' is not a module">, DefaultFatal; chestnykh wrote: Done. Extended the description https://github.com/llvm/llvm-project/pull/98439 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 00fd188 - [C++20][Modules] static data members of template classes should be allowed in header units (#98309)
Author: Dmitry Polukhin Date: 2024-07-11T08:29:09+01:00 New Revision: 00fd188f3744ce7511ebc41260f3fcf34a80ae6b URL: https://github.com/llvm/llvm-project/commit/00fd188f3744ce7511ebc41260f3fcf34a80ae6b DIFF: https://github.com/llvm/llvm-project/commit/00fd188f3744ce7511ebc41260f3fcf34a80ae6b.diff LOG: [C++20][Modules] static data members of template classes should be allowed in header units (#98309) Summary: There is no sense to report these cases as an error or add `inline` explicitly in these cases, if it is not required in normal headers. Similar to #60079. Test Plan: check-clang Added: Modified: clang/lib/Sema/SemaDecl.cpp clang/test/CXX/module/module.import/p6.cpp Removed: diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index d1c7b9d5ae507..66eeaa8e6f777 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -13313,7 +13313,8 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) { if (getLangOpts().CPlusPlusModules && currentModuleIsHeaderUnit() && !VDecl->isInvalidDecl() && VDecl->isThisDeclarationADefinition() && VDecl->getFormalLinkage() == Linkage::External && !VDecl->isInline() && - !VDecl->isTemplated() && !isa(VDecl)) { + !VDecl->isTemplated() && !isa(VDecl) && + !VDecl->getInstantiatedFromStaticDataMember()) { Diag(VDecl->getLocation(), diag::err_extern_def_in_header_unit); VDecl->setInvalidDecl(); } diff --git a/clang/test/CXX/module/module.import/p6.cpp b/clang/test/CXX/module/module.import/p6.cpp index 0ed8b5958dffe..cb2d799e5b565 100644 --- a/clang/test/CXX/module/module.import/p6.cpp +++ b/clang/test/CXX/module/module.import/p6.cpp @@ -67,3 +67,13 @@ void* tmpl_fn_ok inline int foo (int a) { return tmpl_OK (a); } + +template struct S2 { static int v; }; +template int S2::v = 10; + +template bool b() { +bool b1 = S2::v == 10; +return b1 && true; +} + +inline bool B = b(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C++20][Modules] static data members of template classes should be allowed in header units (PR #98309)
https://github.com/dmpolukhin closed https://github.com/llvm/llvm-project/pull/98309 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Don't crash if input file is not a module. (PR #98439)
@@ -226,6 +226,7 @@ def err_module_map_not_found : Error<"module map file '%0' not found">, def err_missing_module_name : Error< "no module name provided; specify one with -fmodule-name=">, DefaultFatal; +def err_file_is_not_module : Error<"file '%0' is not a module">, DefaultFatal; chestnykh wrote: @ChuanqiXu9 FYI i don't have commit access so when PR is ready please commit it https://github.com/llvm/llvm-project/pull/98439 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Don't crash if input file is not a module. (PR #98439)
@@ -226,6 +226,7 @@ def err_module_map_not_found : Error<"module map file '%0' not found">, def err_missing_module_name : Error< "no module name provided; specify one with -fmodule-name=">, DefaultFatal; +def err_file_is_not_module : Error<"file '%0' is not a module">, DefaultFatal; ChuanqiXu9 wrote: OK, I'll commit it. https://github.com/llvm/llvm-project/pull/98439 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [PAC][AArch64] Support init/fini array signing (PR #96478)
kovdan01 wrote: Ping: would be glad to see feedback on the changes from those who are interested. https://github.com/llvm/llvm-project/pull/96478 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PAC][clang][Driver] Add signed GOT flag (PR #96160)
kovdan01 wrote: Ping: would be glad to see feedback on the changes from those who are interested. https://github.com/llvm/llvm-project/pull/96160 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] fix bug that undefined internal is a warning only for -pedantic-errors (PR #98016)
ccrownhill wrote: Ah I see. Thank you for the suggestions! I also tried the same for `_Alignof` but was put off by the errors generated by the `-pedantic-errors` flag. But I guess I can just check that I don't get the `undefined-internal` error. For the other two I had something similar but that still misses this point: — part of the expression in a generic association that is not the result expression of its generic selection But that might also be because I don't understand this point well enough. I don't see which expression is there that is not the controlling expression and not a result expression. Also, I was thinking that it would be best to group all tests into one file since they all test just one feature. What do you think of that? https://github.com/llvm/llvm-project/pull/98016 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Emit bad shift warnings (PR #70307)
https://github.com/budimirarandjelovicsyrmia updated https://github.com/llvm/llvm-project/pull/70307 From 0dd1a3e2b45a8c918217e62fe844b91dbb51df8e Mon Sep 17 00:00:00 2001 From: budimirarandjelovicsyrmia Date: Thu, 26 Oct 2023 10:39:52 +0200 Subject: [PATCH] [clang] Emit bad shift warnings --- clang/docs/ReleaseNotes.rst| 2 ++ clang/lib/AST/ExprConstant.cpp | 7 ++ clang/lib/Sema/SemaExpr.cpp| 35 +++--- clang/test/C/drs/dr0xx.c | 3 ++- clang/test/C/drs/dr2xx.c | 7 -- clang/test/Sema/builtins.c | 4 +-- clang/test/Sema/constant-builtins-2.c | 12 ++--- clang/test/Sema/integer-overflow.c | 2 ++ clang/test/Sema/shift-count-negative.c | 8 ++ clang/test/Sema/shift-count-overflow.c | 9 +++ clang/test/Sema/shift-negative-value.c | 13 ++ clang/test/Sema/vla-2.c| 6 +++-- clang/test/SemaCXX/enum.cpp| 16 +++- clang/test/SemaCXX/shift.cpp | 2 +- 14 files changed, 104 insertions(+), 22 deletions(-) create mode 100644 clang/test/Sema/shift-count-negative.c create mode 100644 clang/test/Sema/shift-count-overflow.c create mode 100644 clang/test/Sema/shift-negative-value.c diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index cfec1cd14a6fc..6adf57da42e65 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -705,6 +705,8 @@ Improvements to Clang's diagnostics - For the ARM target, calling an interrupt handler from another function is now an error. #GH95359. +- Clang now diagnoses integer constant expressions that are folded to a constant value as an extension in more circumstances. Fixes #GH59863 + Improvements to Clang's time-trace -- diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index e0c9ef68cb448..0aeac9d03eed3 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -2859,6 +2859,9 @@ static bool handleIntIntBinOp(EvalInfo &Info, const BinaryOperator *E, else if (LHS.countl_zero() < SA) Info.CCEDiag(E, diag::note_constexpr_lshift_discards); } +if (Info.EvalStatus.Diag && !Info.EvalStatus.Diag->empty() && +Info.getLangOpts().CPlusPlus11) + return false; Result = LHS << SA; return true; } @@ -2882,6 +2885,10 @@ static bool handleIntIntBinOp(EvalInfo &Info, const BinaryOperator *E, if (SA != RHS) Info.CCEDiag(E, diag::note_constexpr_large_shift) << RHS << E->getType() << LHS.getBitWidth(); + +if (Info.EvalStatus.Diag && !Info.EvalStatus.Diag->empty() && +Info.getLangOpts().CPlusPlus11) + return false; Result = LHS >> SA; return true; } diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 63496b327da4d..d6b85cbcaf56b 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -11078,7 +11078,7 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult &LHS, ExprResult &RHS, if (Right.isNegative()) { S.DiagRuntimeBehavior(Loc, RHS.get(), S.PDiag(diag::warn_shift_negative) -<< RHS.get()->getSourceRange()); + << RHS.get()->getSourceRange()); return; } @@ -11093,7 +11093,7 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult &LHS, ExprResult &RHS, if (Right.uge(LeftSize)) { S.DiagRuntimeBehavior(Loc, RHS.get(), S.PDiag(diag::warn_shift_gt_typewidth) -<< RHS.get()->getSourceRange()); + << RHS.get()->getSourceRange()); return; } @@ -11126,7 +11126,7 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult &LHS, ExprResult &RHS, if (Left.isNegative()) { S.DiagRuntimeBehavior(Loc, LHS.get(), S.PDiag(diag::warn_shift_lhs_negative) -<< LHS.get()->getSourceRange()); + << LHS.get()->getSourceRange()); return; } @@ -16964,11 +16964,38 @@ Sema::VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, // Circumvent ICE checking in C++11 to avoid evaluating the expression twice // in the non-ICE case. if (!getLangOpts().CPlusPlus11 && E->isIntegerConstantExpr(Context)) { +SmallVector Notes; if (Result) - *Result = E->EvaluateKnownConstIntCheckOverflow(Context); + *Result = E->EvaluateKnownConstIntCheckOverflow(Context, &Notes); if (!isa(E)) E = Result ? ConstantExpr::Create(Context, E, APValue(*Result)) : ConstantExpr::Create(Context, E); + +if (Notes.empty()) + return E; + +// If our only note is the usual "invalid subexpression" note, just point +// the caret at its location rather than producing an essentially +// redundant note. +if (Notes.siz
[clang] [LoongArch][clang] Modify `loongarch-msimd.c` to avoid `grep -o`. NFC (PR #98442)
https://github.com/ylzsx created https://github.com/llvm/llvm-project/pull/98442 https://lab.llvm.org/buildbot/#/builders/64/builds/250/steps/6/logs/FAIL__Clang__loongarch-msimd_c >From 238cbc3a0e5f7a407e4512fb5ac0d33fb7d65150 Mon Sep 17 00:00:00 2001 From: yangzhaoxin Date: Thu, 11 Jul 2024 15:29:44 +0800 Subject: [PATCH] [LoongArch][clang] Modify `loongarch-msimd.c` to avoid `grep -o`. NFC https://lab.llvm.org/buildbot/#/builders/64/builds/250/steps/6/logs/FAIL__Clang__loongarch-msimd_c --- clang/test/Driver/loongarch-msimd.c | 42 +++-- 1 file changed, 4 insertions(+), 38 deletions(-) diff --git a/clang/test/Driver/loongarch-msimd.c b/clang/test/Driver/loongarch-msimd.c index 984f3e8bf2bfc..cd463300c8747 100644 --- a/clang/test/Driver/loongarch-msimd.c +++ b/clang/test/Driver/loongarch-msimd.c @@ -2,128 +2,94 @@ /// COM: -msimd=none // RUN: %clang --target=loongarch64 -mlasx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=LSX,LASX // RUN: %clang --target=loongarch64 -mlasx -mlsx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=LSX,LASX // RUN: %clang --target=loongarch64 -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX // RUN: %clang --target=loongarch64 -mlasx -mno-lasx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX // RUN: %clang --target=loongarch64 -mlasx -mno-lasx -mlsx -mno-lsx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX // RUN: %clang --target=loongarch64 -mlasx -mno-lasx -mno-lsx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX // RUN: %clang --target=loongarch64 -mlsx -mno-lsx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX // RUN: %clang --target=loongarch64 -mno-lasx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX // RUN: %clang --target=loongarch64 -mno-lasx -mlsx -mno-lsx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX // RUN: %clang --target=loongarch64 -mno-lasx -mno-lsx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX // RUN: %clang --target=loongarch64 -mno-lsx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX // RUN: %clang --target=loongarch64 -mlasx -mno-lasx -mlsx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=LSX,NOLASX // RUN: %clang --target=loongarch64 -mno-lasx -mlsx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=LSX,NOLASX // RUN: %clang --target=loongarch64 -mlsx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=LSX,NOLASX /// COM: -msimd=lsx // RUN: %clang --target=loongarch64 -mlasx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=LSX,LASX // RUN: %clang --target=loongarch64 -mlasx -mlsx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=LSX,LASX // RUN: %clang --target=loongarch64 -mlasx -mno-lasx -mno-lsx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX // RUN: %clang --target=loongarch64 -mlsx -mno-lsx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX // RUN: %clang --target=loongarch64 -mno-lasx -mlsx -mno-lsx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-targe
[clang] [LoongArch][clang] Modify `loongarch-msimd.c` to avoid `grep -o`. NFC (PR #98442)
llvmbot wrote: @llvm/pr-subscribers-clang-driver @llvm/pr-subscribers-clang Author: Zhaoxin Yang (ylzsx) Changes https://lab.llvm.org/buildbot/#/builders/64/builds/250/steps/6/logs/FAIL__Clang__loongarch-msimd_c --- Full diff: https://github.com/llvm/llvm-project/pull/98442.diff 1 Files Affected: - (modified) clang/test/Driver/loongarch-msimd.c (+4-38) ``diff diff --git a/clang/test/Driver/loongarch-msimd.c b/clang/test/Driver/loongarch-msimd.c index 984f3e8bf2bfc..cd463300c8747 100644 --- a/clang/test/Driver/loongarch-msimd.c +++ b/clang/test/Driver/loongarch-msimd.c @@ -2,128 +2,94 @@ /// COM: -msimd=none // RUN: %clang --target=loongarch64 -mlasx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=LSX,LASX // RUN: %clang --target=loongarch64 -mlasx -mlsx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=LSX,LASX // RUN: %clang --target=loongarch64 -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX // RUN: %clang --target=loongarch64 -mlasx -mno-lasx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX // RUN: %clang --target=loongarch64 -mlasx -mno-lasx -mlsx -mno-lsx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX // RUN: %clang --target=loongarch64 -mlasx -mno-lasx -mno-lsx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX // RUN: %clang --target=loongarch64 -mlsx -mno-lsx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX // RUN: %clang --target=loongarch64 -mno-lasx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX // RUN: %clang --target=loongarch64 -mno-lasx -mlsx -mno-lsx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX // RUN: %clang --target=loongarch64 -mno-lasx -mno-lsx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX // RUN: %clang --target=loongarch64 -mno-lsx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX // RUN: %clang --target=loongarch64 -mlasx -mno-lasx -mlsx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=LSX,NOLASX // RUN: %clang --target=loongarch64 -mno-lasx -mlsx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=LSX,NOLASX // RUN: %clang --target=loongarch64 -mlsx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=LSX,NOLASX /// COM: -msimd=lsx // RUN: %clang --target=loongarch64 -mlasx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=LSX,LASX // RUN: %clang --target=loongarch64 -mlasx -mlsx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=LSX,LASX // RUN: %clang --target=loongarch64 -mlasx -mno-lasx -mno-lsx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX // RUN: %clang --target=loongarch64 -mlsx -mno-lsx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX // RUN: %clang --target=loongarch64 -mno-lasx -mlsx -mno-lsx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX // RUN: %clang --target=loongarch64 -mno-lasx -mno-lsx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]
[clang] [WebAssembly] Disable running `wasm-opt` on components (PR #98373)
pavelsavara wrote: could shell script named `wasm-opt` on PATH and doing nothing do the trick ? Or even better it could write it's arguments into some file, so that they could be asserted in the test. 2c https://github.com/llvm/llvm-project/pull/98373 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] fix bug that undefined internal is a warning only for -pedantic-errors (PR #98016)
https://github.com/ccrownhill updated https://github.com/llvm/llvm-project/pull/98016 >From 5dd2bb12dee26ba93d927ad1cd99fa610f9ace97 Mon Sep 17 00:00:00 2001 From: ccrownhill Date: Mon, 8 Jul 2024 11:42:37 +0100 Subject: [PATCH 1/4] fix bug that undefined internal is a warning only for -pedantic-errors --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 +- clang/test/Sema/undefined_internal.c | 11 +++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 clang/test/Sema/undefined_internal.c diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 44fd51ec9abc9..ae3dbedd01693 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -6013,7 +6013,7 @@ def note_deleted_assign_field : Note< "because field %2 is of %select{reference|const-qualified}4 type %3">; // These should be errors. -def warn_undefined_internal : Warning< +def warn_undefined_internal : ExtWarn< "%select{function|variable}0 %q1 has internal linkage but is not defined">, InGroup>; def err_undefined_internal_type : Error< diff --git a/clang/test/Sema/undefined_internal.c b/clang/test/Sema/undefined_internal.c new file mode 100644 index 0..1b6c3a4b76e05 --- /dev/null +++ b/clang/test/Sema/undefined_internal.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s -pedantic-errors + +static void f(void); // expected-error {{function 'f' has internal linkage but is not defined}} + +int main(void) +{ +f; +// expected-note@-1 {{used here}} +// expected-warning@-2 {{expression result unused}} +} + >From 9e679ac9c2c669b595d361516b7e499e0b0457ba Mon Sep 17 00:00:00 2001 From: ccrownhill Date: Wed, 10 Jul 2024 12:06:28 +0100 Subject: [PATCH 2/4] add to change of undefined_internal to error for -pedantic-errors to release notes --- clang/docs/ReleaseNotes.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 838cb69f647ee..a4146aeee25de 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -554,6 +554,9 @@ Attribute Changes in Clang Improvements to Clang's diagnostics --- +- Clang now emits an error instead of a warning for `undefined_internal` + when compiling with `-pedantic-errors` to conform to the C standard + - Clang now applies syntax highlighting to the code snippets it prints. >From b553d87a675cac5d60df2b1fdc586d6b7af6b687 Mon Sep 17 00:00:00 2001 From: ccrownhill Date: Wed, 10 Jul 2024 19:04:17 +0200 Subject: [PATCH 3/4] add more tests for undefined internals --- ...undefined_internal.c => undefined-internal-basic.c} | 0 clang/test/Sema/undefined-internal-generic-selection.c | 10 ++ clang/test/Sema/undefined-internal-sizeof.c| 10 ++ clang/test/Sema/undefined-internal-typeof.c| 10 ++ 4 files changed, 30 insertions(+) rename clang/test/Sema/{undefined_internal.c => undefined-internal-basic.c} (100%) create mode 100644 clang/test/Sema/undefined-internal-generic-selection.c create mode 100644 clang/test/Sema/undefined-internal-sizeof.c create mode 100644 clang/test/Sema/undefined-internal-typeof.c diff --git a/clang/test/Sema/undefined_internal.c b/clang/test/Sema/undefined-internal-basic.c similarity index 100% rename from clang/test/Sema/undefined_internal.c rename to clang/test/Sema/undefined-internal-basic.c diff --git a/clang/test/Sema/undefined-internal-generic-selection.c b/clang/test/Sema/undefined-internal-generic-selection.c new file mode 100644 index 0..0a2b4b61e68e7 --- /dev/null +++ b/clang/test/Sema/undefined-internal-generic-selection.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s -pedantic-errors + +// expected-no-diagnostics + +static int f(void); + +int main(void) +{ +int x = _Generic(f(), int: 10, short: 20); +} diff --git a/clang/test/Sema/undefined-internal-sizeof.c b/clang/test/Sema/undefined-internal-sizeof.c new file mode 100644 index 0..f609473b1341c --- /dev/null +++ b/clang/test/Sema/undefined-internal-sizeof.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s -pedantic-errors + +// expected-no-diagnostics + +static int f(void); + +int main(void) +{ +int x = sizeof f(); +} diff --git a/clang/test/Sema/undefined-internal-typeof.c b/clang/test/Sema/undefined-internal-typeof.c new file mode 100644 index 0..51c682ef7e942 --- /dev/null +++ b/clang/test/Sema/undefined-internal-typeof.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c23 -pedantic-errors + +// expected-no-diagnostics + +static int f(void); + +int main(void) +{ +typeof(f()) x; +} >From 72a5f4084167b9c1930adbd3756450e5e908b674 Mon Sep 17 00:00:00 2001 From: ccrownhill Date: Thu, 11 Jul 2024 10:17:58 +0200 Subject: [PATCH 4/4] cover alignof as
[clang] fix bug that undefined internal is a warning only for -pedantic-errors (PR #98016)
ccrownhill wrote: Since one error message will occlude others I had to split the files as I did in the latest commit. I have added one for the `_Alignof` case checking for the errors I was getting in godbolt while also checking that no `undefined-internal` error occurred. Lastly, I added the one illegal use case of `_Generic` from @AaronBallman 's suggestions. I think this should cover everything. What do you think? https://github.com/llvm/llvm-project/pull/98016 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] [WIP] Added builtin_alloca right Address Space for OpenCL (PR #95750)
https://github.com/vg0204 updated https://github.com/llvm/llvm-project/pull/95750 >From cbe656fa6db50319e74c0fab166538518506974e Mon Sep 17 00:00:00 2001 From: vg0204 Date: Mon, 17 Jun 2024 11:20:02 +0530 Subject: [PATCH 1/6] [Clang] [WIP] Added builtin_alloca support for OpenCL1.2 and below The __builtin_alloca was returning a flat pointer with no address space when compiled using openCL1.2 or below but worked fine with openCL2.0 and above. This accounts to the fact that later uses the concept of generic address space which supports cast to other address space(i.e to private address space which is used for stack allocation) . So, in case of openCL1.2 and below __built_alloca is supposed to return pointer to private address space to eliminate the need of casting as not supported here. Thus,it requires redefintion of the builtin function with appropraite return pointer to appropriate address space. --- clang/lib/Sema/SemaExpr.cpp | 23 +- clang/test/CodeGenOpenCL/builtins-alloca.cl | 86 + clang/test/CodeGenOpenCL/memcpy.cl | 0 3 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 clang/test/CodeGenOpenCL/builtins-alloca.cl mode change 100644 => 100755 clang/test/CodeGenOpenCL/memcpy.cl diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 4db8b4130c3c7..bb63020dadb83 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -6231,7 +6231,10 @@ bool Sema::CheckArgsForPlaceholders(MultiExprArg args) { /// it does not contain any pointer arguments without /// an address space qualifer. Otherwise the rewritten /// FunctionDecl is returned. -/// TODO: Handle pointer return types. +/// +/// Pointer return type with no explicit address space is assigned the +/// default address space where pointer points to based on the language +/// option used to compile it. static FunctionDecl *rewriteBuiltinFunctionDecl(Sema *Sema, ASTContext &Context, FunctionDecl *FDecl, MultiExprArg ArgExprs) { @@ -6275,13 +6278,27 @@ static FunctionDecl *rewriteBuiltinFunctionDecl(Sema *Sema, ASTContext &Context, OverloadParams.push_back(Context.getPointerType(PointeeType)); } + QualType ReturnTy = FT->getReturnType(); + QualType OverloadReturnTy = ReturnTy; + if (ReturnTy->isPointerType() && + !ReturnTy->getPointeeType().hasAddressSpace()) { +if (Sema->getLangOpts().OpenCL) { + NeedsNewDecl = true; + + QualType ReturnPtTy = ReturnTy->getPointeeType(); + LangAS defClAS = Context.getDefaultOpenCLPointeeAddrSpace(); + ReturnPtTy = Context.getAddrSpaceQualType(ReturnPtTy, defClAS); + OverloadReturnTy = Context.getPointerType(ReturnPtTy); +} + } + if (!NeedsNewDecl) return nullptr; FunctionProtoType::ExtProtoInfo EPI; EPI.Variadic = FT->isVariadic(); - QualType OverloadTy = Context.getFunctionType(FT->getReturnType(), -OverloadParams, EPI); + QualType OverloadTy = + Context.getFunctionType(OverloadReturnTy, OverloadParams, EPI); DeclContext *Parent = FDecl->getParent(); FunctionDecl *OverloadDecl = FunctionDecl::Create( Context, Parent, FDecl->getLocation(), FDecl->getLocation(), diff --git a/clang/test/CodeGenOpenCL/builtins-alloca.cl b/clang/test/CodeGenOpenCL/builtins-alloca.cl new file mode 100644 index 0..74a86955f2e4f --- /dev/null +++ b/clang/test/CodeGenOpenCL/builtins-alloca.cl @@ -0,0 +1,86 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5 +// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL1.2 -emit-llvm -o - | FileCheck --check-prefix=OPENCL12 %s +// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL2.0 -emit-llvm -o - | FileCheck --check-prefix=OPENCL20 %s +// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL3.0 -emit-llvm -o - | FileCheck --check-prefix=OPENCL30 %s +// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL3.0 -cl-ext=+__opencl_c_generic_address_space -emit-llvm -o - | FileCheck --check-prefix=OPENCL30-EXT %s + +// OPENCL12-LABEL: define dso_local ptr addrspace(5) @test1( +// OPENCL12-SAME: ) #[[ATTR0:[0-9]+]] { +// OPENCL12-NEXT: [[ENTRY:.*:]] +// OPENCL12-NEXT:[[ALLOC_PTR:%.*]] = alloca ptr addrspace(5), align 4, addrspace(5) +// OPENCL12-NEXT:[[TMP0:%.*]] = alloca i8, i64 128, align 8, addrspace(5) +// OPENCL12-NEXT:store ptr addrspace(5) [[TMP0]], ptr addrspace(5) [[ALLOC_PTR]], align 4 +// OPENCL12-NEXT:[[TMP1:%.*]] = load ptr addrspace(5), ptr addrspace(5) [[ALLOC_PTR]], align 4 +// OPENCL12-NEXT:ret ptr addrspace(5) [[TMP1]] +// +// OPENCL20-LABEL: define dso_local ptr @test1( +// OPENCL20-SAME: ) #[[ATTR0:[0-9]+]] { +// OPENCL20-NEXT: [[ENTRY:.*:]] +// OPENCL20-NEXT:
[clang] [Clang] [WIP] Added builtin_alloca right Address Space for OpenCL (PR #95750)
@@ -1981,6 +1981,26 @@ static bool OpenCLBuiltinToAddr(Sema &S, unsigned BuiltinID, CallExpr *Call) { return false; } +// In OpenCL, __builtin_alloca_* should return a pointer to address space +// that corresponds to the stack address space i.e private address space. +static bool OpenCLBuiltinAllocaAddrSpace(Sema &S, CallExpr *TheCall) { + QualType RT = TheCall->getType(); + if (!RT->isPointerType() || RT->getPointeeType().hasAddressSpace()) +return true; + + if (S.getLangOpts().OpenCL) { +RT = RT->getPointeeType(); + +// Stack Address space corresponds to private address space. +LangAS openCLStackAS = LangAS::opencl_private; vg0204 wrote: Done https://github.com/llvm/llvm-project/pull/95750 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [llvm][AArch64] apple-m4 is armv9.2-a (PR #98267)
@@ -161,14 +161,10 @@ struct CpuInfo { StringRef Name; // Name, as written for -mcpu. const ArchInfo &Arch; AArch64::ExtensionBitset - DefaultExtensions; // Default extensions for this CPU. These will be - // ORd with the architecture defaults. + DefaultExtensions; // Default extensions for this CPU. AArch64::ExtensionBitset getImpliedExtensions() const { -AArch64::ExtensionBitset ImpliedExts; -ImpliedExts |= DefaultExtensions; -ImpliedExts |= Arch.DefaultExts; -return ImpliedExts; +return DefaultExtensions; tmatheson-arm wrote: IIUC, the idea here is that we don't want to add the architecture's default extensions to the CPU, because they are not mandatory, and there's no way to disable them for a CPU that chooses not to implement. This is why all the CPUs have had their list of features expanded. https://github.com/llvm/llvm-project/pull/98267 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [llvm][AArch64] apple-m4 is armv9.2-a (PR #98267)
https://github.com/tmatheson-arm edited https://github.com/llvm/llvm-project/pull/98267 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [llvm][AArch64] apple-m4 is armv9.2-a (PR #98267)
https://github.com/tmatheson-arm approved this pull request. LGTM. I haven't checked all the CPU feature changes, but the tests give a lot of confidence. I also haven't checked all the TRMs but the changes there make sense given the MEC/RME architecture changes. https://github.com/llvm/llvm-project/pull/98267 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [llvm][AArch64] apple-m4 is armv9.2-a (PR #98267)
@@ -1626,7 +1628,7 @@ INSTANTIATE_TEST_SUITE_P( AArch64::AEK_FP16FML, AArch64::AEK_SHA3,AArch64::AEK_BF16, AArch64::AEK_I8MM,AArch64::AEK_JSCVT, AArch64::AEK_FCMA, AArch64::AEK_PAUTH, AArch64::AEK_PERFMON, AArch64::AEK_HCX}), -AArch64CPUTestParams("apple-m4", "armv8.7-a", +AArch64CPUTestParams("apple-m4", "armv9.2-a", tmatheson-arm wrote: Doesn't look like the Optimisation Guide has been updated for the M4 yet. https://github.com/llvm/llvm-project/pull/98267 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [lldb] [llvm] [llvm][TargetParser] Return StringMap from getHostCPUFeatures (PR #97824)
https://github.com/tmatheson-arm approved this pull request. https://github.com/llvm/llvm-project/pull/97824 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] bf4167f - [Clang] Don't crash if input file is not a module. (#98439)
Author: Dmitriy Chestnykh Date: 2024-07-11T16:48:58+08:00 New Revision: bf4167fd1d06ff68da2cbea210a4ccfa045694d3 URL: https://github.com/llvm/llvm-project/commit/bf4167fd1d06ff68da2cbea210a4ccfa045694d3 DIFF: https://github.com/llvm/llvm-project/commit/bf4167fd1d06ff68da2cbea210a4ccfa045694d3.diff LOG: [Clang] Don't crash if input file is not a module. (#98439) Currently clang crashes with `-module-file-info` and input file which is not a module Emit error instead of segfaulting. Fix #98365 Added: clang/test/Frontend/module-file-info-not-a-module.c Modified: clang/include/clang/Basic/DiagnosticFrontendKinds.td clang/lib/Frontend/FrontendActions.cpp Removed: diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td index 85c32e55bdab3..12a4617c64d87 100644 --- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td +++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td @@ -226,6 +226,7 @@ def err_module_map_not_found : Error<"module map file '%0' not found">, def err_missing_module_name : Error< "no module name provided; specify one with -fmodule-name=">, DefaultFatal; +def err_file_is_not_module : Error<"file '%0' is not a module file">, DefaultFatal; def err_missing_module : Error< "no module named '%0' declared in module map file '%1'">, DefaultFatal; def err_no_submodule : Error<"no submodule named %0 in module '%1'">; diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index 4f064321997a2..e70210d55fe28 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -841,9 +841,16 @@ static StringRef ModuleKindName(Module::ModuleKind MK) { } void DumpModuleInfoAction::ExecuteAction() { - assert(isCurrentFileAST() && "dumping non-AST?"); - // Set up the output file. CompilerInstance &CI = getCompilerInstance(); + + // Don't process files of type other than module to avoid crash + if (!isCurrentFileAST()) { +CI.getDiagnostics().Report(diag::err_file_is_not_module) +<< getCurrentFile(); +return; + } + + // Set up the output file. StringRef OutputFileName = CI.getFrontendOpts().OutputFile; if (!OutputFileName.empty() && OutputFileName != "-") { std::error_code EC; diff --git a/clang/test/Frontend/module-file-info-not-a-module.c b/clang/test/Frontend/module-file-info-not-a-module.c new file mode 100644 index 0..f8a114ea79976 --- /dev/null +++ b/clang/test/Frontend/module-file-info-not-a-module.c @@ -0,0 +1,3 @@ +// RUN: not %clang_cc1 -module-file-info %s 2>&1 | FileCheck %s + +// CHECK: fatal error: file '{{.*}}module-file-info-not-a-module.c' is not a module file ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Don't crash if input file is not a module. (PR #98439)
https://github.com/ChuanqiXu9 closed https://github.com/llvm/llvm-project/pull/98439 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [ObjC][CodeGen] Assume a for-in loop is in bounds and cannot overflow (PR #94885)
https://github.com/davidchisnall updated https://github.com/llvm/llvm-project/pull/94885 >From e818620af0a9732d7c0e96b85d7ec1f5a8afc297 Mon Sep 17 00:00:00 2001 From: Rose Date: Sat, 8 Jun 2024 22:30:53 -0400 Subject: [PATCH] [ObjC][CodeGen] Assume a for-in loop is in bounds and cannot overflow When accessing data in the buffer, we know we won't overrun the buffer, so we know it is inbounds. In addition, we know that the addition to increase the index is also NUW because the buffer's end has to be unsigned-greater-than 0, which becomes untrue if the bounds ever has an unsigned wrap. --- clang/lib/CodeGen/CGObjC.cpp | 4 ++-- clang/test/CodeGenObjC/arc-foreach.m | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp index 281b2d9795f6c..80a64d8e4cdd9 100644 --- a/clang/lib/CodeGen/CGObjC.cpp +++ b/clang/lib/CodeGen/CGObjC.cpp @@ -1952,7 +1952,7 @@ void CodeGenFunction::EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S){ Builder.CreateLoad(StateItemsPtr, "stateitems"); // Fetch the value at the current index from the buffer. - llvm::Value *CurrentItemPtr = Builder.CreateGEP( + llvm::Value *CurrentItemPtr = Builder.CreateInBoundsGEP( ObjCIdType, EnumStateItems, index, "currentitem.ptr"); llvm::Value *CurrentItem = Builder.CreateAlignedLoad(ObjCIdType, CurrentItemPtr, getPointerAlign()); @@ -2028,7 +2028,7 @@ void CodeGenFunction::EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S){ // First we check in the local buffer. llvm::Value *indexPlusOne = - Builder.CreateAdd(index, llvm::ConstantInt::get(NSUIntegerTy, 1)); + Builder.CreateNUWAdd(index, llvm::ConstantInt::get(NSUIntegerTy, 1)); // If we haven't overrun the buffer yet, we can continue. // Set the branch weights based on the simplifying assumption that this is diff --git a/clang/test/CodeGenObjC/arc-foreach.m b/clang/test/CodeGenObjC/arc-foreach.m index 71edc5161303c..9f7b60aef7a1b 100644 --- a/clang/test/CodeGenObjC/arc-foreach.m +++ b/clang/test/CodeGenObjC/arc-foreach.m @@ -53,7 +53,7 @@ void test0(NSArray *array) { // CHECK-LP64: [[T0:%.*]] = getelementptr inbounds [[STATE_T]], ptr [[STATE]], i32 0, i32 1 // CHECK-LP64-NEXT: [[T1:%.*]] = load ptr, ptr [[T0]] -// CHECK-LP64-NEXT: [[T2:%.*]] = getelementptr ptr, ptr [[T1]], i64 +// CHECK-LP64-NEXT: [[T2:%.*]] = getelementptr inbounds ptr, ptr [[T1]], i64 // CHECK-LP64-NEXT: [[T3:%.*]] = load ptr, ptr [[T2]] // CHECK-LP64-NEXT: store ptr [[T3]], ptr [[X]] @@ -100,7 +100,7 @@ void test1(NSArray *array) { // CHECK-LP64: [[T0:%.*]] = getelementptr inbounds [[STATE_T]], ptr [[STATE]], i32 0, i32 1 // CHECK-LP64-NEXT: [[T1:%.*]] = load ptr, ptr [[T0]] -// CHECK-LP64-NEXT: [[T2:%.*]] = getelementptr ptr, ptr [[T1]], i64 +// CHECK-LP64-NEXT: [[T2:%.*]] = getelementptr inbounds ptr, ptr [[T1]], i64 // CHECK-LP64-NEXT: [[T3:%.*]] = load ptr, ptr [[T2]] // CHECK-LP64-NEXT: call ptr @llvm.objc.initWeak(ptr [[X]], ptr [[T3]]) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [WebAssembly] Disable running `wasm-opt` on components (PR #98373)
mh4ck-Thales wrote: A shell script would work. I don't know how easy it is to create a shell script inside the test suite and use it though, and it would be nice if this fake wasm-opt script could be unique across several tests, to ensure the consistency of those. https://github.com/llvm/llvm-project/pull/98373 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][driver] Fix -print-libgcc-file-name on Darwin platforms (PR #98325)
@@ -356,6 +363,12 @@ class LLVM_LIBRARY_VISIBILITY Darwin : public MachO { void addProfileRTLibs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override; + // Return the full path of the compiler-rt library on a Darwin MachO system. + // Those are under /lib/darwin/<...>(.dylib|.a). Xazax-hun wrote: While `-print-libgcc-file-name` can only output the `.a` version, there are other callers of this API that query the dylib. https://github.com/llvm/llvm-project/pull/98325 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][driver] Fix -print-libgcc-file-name on Darwin platforms (PR #98325)
@@ -1303,18 +1288,55 @@ void MachO::AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs, // rpaths. This is currently true from this place, but we need to be // careful if this function is ever called before user's rpaths are emitted. if (Opts & RLO_AddRPath) { -assert(DarwinLibName.ends_with(".dylib") && "must be a dynamic library"); +assert(StringRef(P).ends_with(".dylib") && "must be a dynamic library"); // Add @executable_path to rpath to support having the dylib copied with // the executable. CmdArgs.push_back("-rpath"); CmdArgs.push_back("@executable_path"); -// Add the path to the resource dir to rpath to support using the dylib -// from the default location without copying. +// Add the compiler-rt library's directory to rpath to support using the +// dylib from the default location without copying. CmdArgs.push_back("-rpath"); -CmdArgs.push_back(Args.MakeArgString(Dir)); +CmdArgs.push_back(Args.MakeArgString(llvm::sys::path::parent_path(P))); + } +} + +std::string MachO::getCompilerRT(const ArgList &, StringRef Component, + FileType Type) const { + assert(Type != ToolChain::FT_Object && + "it doesn't make sense to ask for the compiler-rt library name as an " + "object file"); + SmallString<64> MachOLibName = StringRef("libclang_rt"); + // On MachO, the builtins component is not in the library name + if (Component != "builtins") { +MachOLibName += '.'; +MachOLibName += Component; + } + MachOLibName += Type == ToolChain::FT_Shared ? "_dynamic.dylib" : ".a"; Xazax-hun wrote: While `-print-libgcc-file-name` can only output the `.a` version, there are other callers of this API that query the dylib. https://github.com/llvm/llvm-project/pull/98325 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Don't crash if input file is not a module. (PR #98439)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `clang-hip-vega20` running on `hip-vega20-0` while building `clang` at step 3 "annotate". Full details are available at: https://lab.llvm.org/buildbot/#/builders/123/builds/1610 Here is the relevant piece of the build log for the reference: ``` Step 3 (annotate) failure: '../llvm-zorg/zorg/buildbot/builders/annotated/hip-build.sh --jobs=' (failure) ... [36/38] : && /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang++ -O3 -DNDEBUG External/HIP/CMakeFiles/InOneWeekend-hip-6.0.2.dir/workload/ray-tracing/InOneWeekend/main.cc.o -o External/HIP/InOneWeekend-hip-6.0.2 --rocm-path=/buildbot/Externals/hip/rocm-6.0.2 --hip-link -rtlib=compiler-rt -unwindlib=libgcc -frtlib-add-rpath && cd /buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP && /usr/local/bin/cmake -E create_symlink /buildbot/llvm-test-suite/External/HIP/InOneWeekend.reference_output /buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP/InOneWeekend.reference_output-hip-6.0.2 [37/38] /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang++ -DNDEBUG -O3 -DNDEBUG -w -Werror=date-time --rocm-path=/buildbot/Externals/hip/rocm-6.0.2 --offload-arch=gfx908 --offload-arch=gfx90a --offload-arch=gfx1030 --offload-arch=gfx1100 -xhip -mfma -MD -MT External/HIP/CMakeFiles/TheNextWeek-hip-6.0.2.dir/workload/ray-tracing/TheNextWeek/main.cc.o -MF External/HIP/CMakeFiles/TheNextWeek-hip-6.0.2.dir/workload/ray-tracing/TheNextWeek/main.cc.o.d -o External/HIP/CMakeFiles/TheNextWeek-hip-6.0.2.dir/workload/ray-tracing/TheNextWeek/main.cc.o -c /buildbot/llvm-test-suite/External/HIP/workload/ray-tracing/TheNextWeek/main.cc [38/38] : && /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/clang++ -O3 -DNDEBUG External/HIP/CMakeFiles/TheNextWeek-hip-6.0.2.dir/workload/ray-tracing/TheNextWeek/main.cc.o -o External/HIP/TheNextWeek-hip-6.0.2 --rocm-path=/buildbot/Externals/hip/rocm-6.0.2 --hip-link -rtlib=compiler-rt -unwindlib=libgcc -frtlib-add-rpath && cd /buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP && /usr/local/bin/cmake -E create_symlink /buildbot/llvm-test-suite/External/HIP/TheNextWeek.reference_output /buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP/TheNextWeek.reference_output-hip-6.0.2 + build_step 'Testing HIP test-suite' + echo '@@@BUILD_STEP Testing HIP test-suite@@@' @@@BUILD_STEP Testing HIP test-suite@@@ + ninja -v check-hip-simple [0/1] cd /buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP && /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/llvm-lit -sv empty-hip-6.0.2.test with-fopenmp-hip-6.0.2.test saxpy-hip-6.0.2.test InOneWeekend-hip-6.0.2.test TheNextWeek-hip-6.0.2.test blender.test -- Testing: 6 tests, 6 workers -- Testing: 0.. 10.. 20.. 30.. 40.. FAIL: test-suite :: External/HIP/InOneWeekend-hip-6.0.2.test (4 of 6) TEST 'test-suite :: External/HIP/InOneWeekend-hip-6.0.2.test' FAILED /buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/tools/timeit-target --timeout 7200 --limit-core 0 --limit-cpu 7200 --limit-file-size 209715200 --limit-rss-size 838860800 --append-exitstatus --redirect-output /buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP/Output/InOneWeekend-hip-6.0.2.test.out --redirect-input /dev/null --summary /buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP/Output/InOneWeekend-hip-6.0.2.test.time /buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP/InOneWeekend-hip-6.0.2 cd /buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP ; /buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/tools/fpcmp-target /buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP/Output/InOneWeekend-hip-6.0.2.test.out InOneWeekend.reference_output-hip-6.0.2 + cd /buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP + /buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/tools/fpcmp-target /buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP/Output/InOneWeekend-hip-6.0.2.test.out InOneWeekend.reference_output-hip-6.0.2 /buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/tools/fpcmp-target: Comparison failed, textual difference between 'M' and 'i' /usr/bin/strip: /bin/bash.stripped: Bad file descriptor Testing: 0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. Failed Tests (1): test-suite :: External/HIP/InOneWeekend-hip-6.0.2.test Testing Time: 377.66s Total Discovered Tests: 6 Passed: 5 (83.33%) Failed: 1 (16.67%) FAILED: External/HIP/CMakeFiles/check-hip-simple-hip-6.0.2 cd /buildbot/hip-vega20-0/clang-hip-vega20/test-suite-build/External/HIP && /buildbot/hip-vega20-0/clang-hip-vega20/llvm/bin/llvm-lit -sv empty-hip-6.0.2.test with-fopenmp-hip-6.0.2.test saxpy-hip-6.0.2.test InOneWeekend-hip-6.0.2.test TheNextWeek-hip
[clang] [clang] Inject tokens containing #embed back into token stream (PR #97274)
@@ -3644,9 +3644,11 @@ bool Sema::CheckLoopHintExpr(Expr *E, SourceLocation Loc, bool AllowZero) { ExprResult Sema::ActOnNumericConstant(const Token &Tok, Scope *UDLScope) { // Fast path for a single digit (which is quite common). A single digit // cannot have a trigraph, escaped newline, radix prefix, or suffix. - if (Tok.getLength() == 1) { + if (Tok.getLength() == 1 || Tok.getKind() == tok::binary_data) { const char Val = PP.getSpellingOfSingleCharacterNumericConstant(Tok); -return ActOnIntegerConstant(Tok.getLocation(), Val-'0'); +return ActOnIntegerConstant( +Tok.getLocation(), +(Tok.getKind() == tok::binary_data) ? Val : Val - '0'); cor3ntin wrote: can we move that to PP.getSpellingOfSingleCharacterNumericConstant? https://github.com/llvm/llvm-project/pull/97274 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Inject tokens containing #embed back into token stream (PR #97274)
@@ -1018,6 +1018,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind, // primary-expression case tok::numeric_constant: cor3ntin wrote: These cases ```cpp [[clang::availability( #embed "smth.txt" )]] void f(); struct S { virtual void f() = #embed "zero.bin" ; }; ``` However, it's a bit ambiguous whether these should be supported at all in the proposed C++ wording for embed. I sent a mail to the C++ committee It's probably fine to ignore that for now, the patch is a great improvement as it is https://github.com/llvm/llvm-project/pull/97274 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [safestack] Various Solaris fixes (PR #98001)
rorth wrote: > > The problem is that -u __safestack_init was passed to the linker after the > > corresponding version of libclang_rt.safestack-*.a. Since the Solaris > > linker (like Unix linkers for decades) respect > > I agree this part should be extracted since it affects other systems. Other > parts are Solaris specific and since the support is currently broken, it is > safe to combine changes. We also don't have Solaris build bots, so the > change, if correctly restricted to Solaris, would not cause any problems. We sure have Solaris buildbots, both [Solaris/sparcv9](https://lab.llvm.org/buildbot/#/builders/13) and [Solaris/amd64](https://lab.llvm.org/staging/#/builders/94). Actually, two parts of the patch do affect non-Solaris targets: - The SPARC enablement, which is covered by Linux/sparc64 testing, and - adding some (otherwise unused) `sanitizer_common` objects to `libclang_rt.safestack-*.a`. This was tested on both Linux/x86_64 and Linux/sparc64, and I'm resonably certain that unused objects in an archive lib won't affect other targets. https://github.com/llvm/llvm-project/pull/98001 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libclang/python] Refactor enum usage (PR #95608)
DeinAlptraum wrote: *Ping\* @Endilll how should we proceed with this? https://github.com/llvm/llvm-project/pull/95608 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] CTAD: use index and depth to retrieve template parameter for TemplateParamsReferencedInTemplateArgumentList (PR #98013)
https://github.com/hokein updated https://github.com/llvm/llvm-project/pull/98013 >From c9297f8abe8d480fdcd3ba6d6598268fef74ddb4 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Mon, 8 Jul 2024 13:19:13 +0200 Subject: [PATCH 1/2] [clang] CTAD: use index and depth to retrieve template parameters in TemplateParamsReferencedInTemplateArgumentList. --- clang/lib/Sema/SemaTemplate.cpp| 31 +++--- clang/test/AST/ast-dump-ctad-alias.cpp | 25 + 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 3d8cf750c12c1..196a5cc10ce40 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -2754,20 +2754,34 @@ struct ConvertConstructorToDeductionGuideTransform { // Find all template parameters that appear in the given DeducedArgs. // Return the indices of the template parameters in the TemplateParams. SmallVector TemplateParamsReferencedInTemplateArgumentList( -ArrayRef TemplateParams, +const TemplateParameterList* TemplateParamsList, ArrayRef DeducedArgs) { struct TemplateParamsReferencedFinder : public RecursiveASTVisitor { +const TemplateParameterList* TemplateParamList; llvm::DenseSet TemplateParams; llvm::DenseSet ReferencedTemplateParams; -TemplateParamsReferencedFinder(ArrayRef TemplateParams) -: TemplateParams(TemplateParams.begin(), TemplateParams.end()) {} +TemplateParamsReferencedFinder( +const TemplateParameterList *TemplateParamList) +: TemplateParamList(TemplateParamList), + TemplateParams(TemplateParamList->begin(), TemplateParamList->end()) { +} bool VisitTemplateTypeParmType(TemplateTypeParmType *TTP) { - MarkAppeared(TTP->getDecl()); + // We use the index and depth to retrieve the corresponding template + // parameter from the parameter list. + // Note that Clang may not preserve type sugar during template argument + // deduction. In such cases, the TTP is a canonical TemplateTypeParamType, + // which only retains its index and depth information. + if (TTP->getDepth() == TemplateParamList->getDepth() && + TTP->getIndex() < TemplateParamList->size()) { +ReferencedTemplateParams.insert( +TemplateParamList->getParam(TTP->getIndex())); + } return true; } + bool VisitDeclRefExpr(DeclRefExpr *DRE) { MarkAppeared(DRE->getFoundDecl()); return true; @@ -2784,12 +2798,13 @@ SmallVector TemplateParamsReferencedInTemplateArgumentList( ReferencedTemplateParams.insert(ND); } }; - TemplateParamsReferencedFinder Finder(TemplateParams); + TemplateParamsReferencedFinder Finder(TemplateParamsList); Finder.TraverseTemplateArguments(DeducedArgs); SmallVector Results; - for (unsigned Index = 0; Index < TemplateParams.size(); ++Index) { -if (Finder.ReferencedTemplateParams.contains(TemplateParams[Index])) + for (unsigned Index = 0; Index < TemplateParamsList->size(); ++Index) { +if (Finder.ReferencedTemplateParams.contains( +TemplateParamsList->getParam(Index))) Results.push_back(Index); } return Results; @@ -3149,7 +3164,7 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef, } auto DeducedAliasTemplateParams = TemplateParamsReferencedInTemplateArgumentList( - AliasTemplate->getTemplateParameters()->asArray(), DeducedArgs); + AliasTemplate->getTemplateParameters(), DeducedArgs); // All template arguments null by default. SmallVector TemplateArgsForBuildingFPrime( F->getTemplateParameters()->size()); diff --git a/clang/test/AST/ast-dump-ctad-alias.cpp b/clang/test/AST/ast-dump-ctad-alias.cpp index 6f07a62e9a069..adccad97a205b 100644 --- a/clang/test/AST/ast-dump-ctad-alias.cpp +++ b/clang/test/AST/ast-dump-ctad-alias.cpp @@ -99,3 +99,28 @@ BFoo b2(1.0, 2.0); // CHECK-NEXT: | | |-ParmVarDecl {{.*}} 'type-parameter-0-0' // CHECK-NEXT: | | `-ParmVarDecl {{.*}} 'type-parameter-0-0' // CHECK-NEXT: | `-CXXDeductionGuideDecl {{.*}} implicit used 'auto (double, double) -> Foo' implicit_instantiation + +namespace GH90209 { +template +struct List { + List(int); +}; + +template +struct TemplatedClass { + TemplatedClass(T1); +}; + +template +TemplatedClass(T1) -> TemplatedClass>; + +template +using ATemplatedClass = TemplatedClass>; + +ATemplatedClass test(1); +// Verify that we have a correct template parameter list for the deduction guide. +// +// CHECK: FunctionTemplateDecl {{.*}} +// CHECK-NEXT: |-TemplateTypeParmDecl {{.*}} class depth 0 index 0 T2 +// CHECK-NEXT: |-TypeTraitExpr {{.*}} 'bool' __is_deducible +} // namespace GH90209 \ No newline at end of file >From 7626982d97d7f0f088af95be371f65d5a0f02ee9 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Thu, 11 Jul 2024 11:09:55 +0200 Subject: [PATCH 2/2] Address review comment. --- clang/lib/Sema/SemaTempl
[clang] [clang] CTAD: use index and depth to retrieve template parameter for TemplateParamsReferencedInTemplateArgumentList (PR #98013)
https://github.com/hokein edited https://github.com/llvm/llvm-project/pull/98013 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] CTAD: use index and depth to retrieve template parameter for TemplateParamsReferencedInTemplateArgumentList (PR #98013)
@@ -2653,20 +2653,34 @@ struct ConvertConstructorToDeductionGuideTransform { // Find all template parameters that appear in the given DeducedArgs. // Return the indices of the template parameters in the TemplateParams. SmallVector TemplateParamsReferencedInTemplateArgumentList( -ArrayRef TemplateParams, +const TemplateParameterList* TemplateParamsList, hokein wrote: > In fact, TemplateParameterList will just return the depth of its first > parameter. I think it is fine, my understanding is that all parameters within a template parameter list should have the same depth, https://github.com/llvm/llvm-project/pull/98013 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] CTAD: use index and depth to retrieve template parameter for TemplateParamsReferencedInTemplateArgumentList (PR #98013)
https://github.com/hokein commented: Thanks for the review. https://github.com/llvm/llvm-project/pull/98013 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] CTAD: use index and depth to retrieve template parameter for TemplateParamsReferencedInTemplateArgumentList (PR #98013)
@@ -99,3 +99,28 @@ BFoo b2(1.0, 2.0); // CHECK-NEXT: | | |-ParmVarDecl {{.*}} 'type-parameter-0-0' // CHECK-NEXT: | | `-ParmVarDecl {{.*}} 'type-parameter-0-0' // CHECK-NEXT: | `-CXXDeductionGuideDecl {{.*}} implicit used 'auto (double, double) -> Foo' implicit_instantiation + +namespace GH90209 { +template +struct List { + List(int); +}; + +template +struct TemplatedClass { + TemplatedClass(T1); +}; + +template +TemplatedClass(T1) -> TemplatedClass>; + +template +using ATemplatedClass = TemplatedClass>; + +ATemplatedClass test(1); +// Verify that we have a correct template parameter list for the deduction guide. +// +// CHECK: FunctionTemplateDecl {{.*}} +// CHECK-NEXT: |-TemplateTypeParmDecl {{.*}} class depth 0 index 0 T2 +// CHECK-NEXT: |-TypeTraitExpr {{.*}} 'bool' __is_deducible +} // namespace GH90209 hokein wrote: Done. https://github.com/llvm/llvm-project/pull/98013 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] CTAD: use index and depth to retrieve template parameter for TemplateParamsReferencedInTemplateArgumentList (PR #98013)
@@ -2653,20 +2653,34 @@ struct ConvertConstructorToDeductionGuideTransform { // Find all template parameters that appear in the given DeducedArgs. // Return the indices of the template parameters in the TemplateParams. SmallVector TemplateParamsReferencedInTemplateArgumentList( -ArrayRef TemplateParams, +const TemplateParameterList* TemplateParamsList, ArrayRef DeducedArgs) { struct TemplateParamsReferencedFinder : public RecursiveASTVisitor { +const TemplateParameterList* TemplateParamList; llvm::DenseSet TemplateParams; llvm::DenseSet ReferencedTemplateParams; -TemplateParamsReferencedFinder(ArrayRef TemplateParams) -: TemplateParams(TemplateParams.begin(), TemplateParams.end()) {} +TemplateParamsReferencedFinder( +const TemplateParameterList *TemplateParamList) +: TemplateParamList(TemplateParamList), + TemplateParams(TemplateParamList->begin(), TemplateParamList->end()) { +} bool VisitTemplateTypeParmType(TemplateTypeParmType *TTP) { - MarkAppeared(TTP->getDecl()); + // We use the index and depth to retrieve the corresponding template + // parameter from the parameter list. + // Note that Clang may not preserve type sugar during template argument + // deduction. In such cases, the TTP is a canonical TemplateTypeParamType, + // which only retains its index and depth information. hokein wrote: Done. https://github.com/llvm/llvm-project/pull/98013 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] CTAD: use index and depth to retrieve template parameter for TemplateParamsReferencedInTemplateArgumentList (PR #98013)
@@ -2653,20 +2653,34 @@ struct ConvertConstructorToDeductionGuideTransform { // Find all template parameters that appear in the given DeducedArgs. // Return the indices of the template parameters in the TemplateParams. SmallVector TemplateParamsReferencedInTemplateArgumentList( -ArrayRef TemplateParams, +const TemplateParameterList* TemplateParamsList, ArrayRef DeducedArgs) { struct TemplateParamsReferencedFinder : public RecursiveASTVisitor { +const TemplateParameterList* TemplateParamList; llvm::DenseSet TemplateParams; llvm::DenseSet ReferencedTemplateParams; -TemplateParamsReferencedFinder(ArrayRef TemplateParams) -: TemplateParams(TemplateParams.begin(), TemplateParams.end()) {} +TemplateParamsReferencedFinder( +const TemplateParameterList *TemplateParamList) +: TemplateParamList(TemplateParamList), + TemplateParams(TemplateParamList->begin(), TemplateParamList->end()) { +} bool VisitTemplateTypeParmType(TemplateTypeParmType *TTP) { - MarkAppeared(TTP->getDecl()); + // We use the index and depth to retrieve the corresponding template + // parameter from the parameter list. + // Note that Clang may not preserve type sugar during template argument + // deduction. In such cases, the TTP is a canonical TemplateTypeParamType, + // which only retains its index and depth information. + if (TTP->getDepth() == TemplateParamList->getDepth() && hokein wrote: I'm not aware of any issues with non-type parameter cases, I think the AST preserves enough information. However, for consistency, I have switched the implementation to always use depth and index to retrieve the template parameter declaration, which simplifies the code a bit. Please take a second look. https://github.com/llvm/llvm-project/pull/98013 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC][Clang] Move set functions out BranchProtectionInfo. (PR #98451)
https://github.com/DanielKristofKiss created https://github.com/llvm/llvm-project/pull/98451 To reduce build times move them to TargetCodeGenInfo. Refactor of #98329 >From 2ffaf35f09be03e7374bde3d97ee798b01e7e3d1 Mon Sep 17 00:00:00 2001 From: Daniel Kiss Date: Thu, 11 Jul 2024 10:29:24 +0200 Subject: [PATCH] [NFC][Clang] Move setfunctions of BranchProtectionInfo. Move the to TargetCodeGenInfo. Refactor of #98329 --- clang/include/clang/Basic/TargetInfo.h | 23 --- clang/lib/CodeGen/TargetInfo.cpp | 23 +++ clang/lib/CodeGen/TargetInfo.h | 9 - clang/lib/CodeGen/Targets/AArch64.cpp | 2 +- clang/lib/CodeGen/Targets/ARM.cpp | 4 ++-- 5 files changed, 34 insertions(+), 27 deletions(-) diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h index cf7628553647c..a58fb5f979272 100644 --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -32,9 +32,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSet.h" #include "llvm/Frontend/OpenMP/OMPGridValues.h" -#include "llvm/IR/Attributes.h" #include "llvm/IR/DerivedTypes.h" -#include "llvm/IR/Function.h" #include "llvm/Support/DataTypes.h" #include "llvm/Support/Error.h" #include "llvm/Support/VersionTuple.h" @@ -1410,7 +1408,6 @@ class TargetInfo : public TransferrableTargetInfo, bool BranchProtectionPAuthLR; bool GuardedControlStack; - protected: const char *getSignReturnAddrStr() const { switch (SignReturnAddr) { case LangOptions::SignReturnAddressScopeKind::None: @@ -1433,7 +1430,6 @@ class TargetInfo : public TransferrableTargetInfo, llvm_unreachable("Unexpected SignReturnAddressKeyKind"); } - public: BranchProtectionInfo() : SignReturnAddr(LangOptions::SignReturnAddressScopeKind::None), SignKey(LangOptions::SignReturnAddressKeyKind::AKey), @@ -1454,25 +1450,6 @@ class TargetInfo : public TransferrableTargetInfo, BranchProtectionPAuthLR = LangOpts.BranchProtectionPAuthLR; GuardedControlStack = LangOpts.GuardedControlStack; } - -void setFnAttributes(llvm::Function &F) { - llvm::AttrBuilder FuncAttrs(F.getContext()); - setFnAttributes(FuncAttrs); - F.addFnAttrs(FuncAttrs); -} - -void setFnAttributes(llvm::AttrBuilder &FuncAttrs) { - if (SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None) { -FuncAttrs.addAttribute("sign-return-address", getSignReturnAddrStr()); -FuncAttrs.addAttribute("sign-return-address-key", getSignKeyStr()); - } - if (BranchTargetEnforcement) -FuncAttrs.addAttribute("branch-target-enforcement"); - if (BranchProtectionPAuthLR) -FuncAttrs.addAttribute("branch-protection-pauth-lr"); - if (GuardedControlStack) -FuncAttrs.addAttribute("guarded-control-stack"); -} }; /// Determine if the Architecture in this TargetInfo supports branch diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp index 60224d458f6a2..9ccf0dea9a738 100644 --- a/clang/lib/CodeGen/TargetInfo.cpp +++ b/clang/lib/CodeGen/TargetInfo.cpp @@ -19,6 +19,7 @@ #include "clang/CodeGen/CGFunctionInfo.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/Twine.h" +#include "llvm/IR/Function.h" #include "llvm/IR/Type.h" #include "llvm/Support/raw_ostream.h" @@ -206,6 +207,28 @@ llvm::Value *TargetCodeGenInfo::createEnqueuedBlockKernel( return F; } +void TargetCodeGenInfo::setFnAttributes( +const TargetInfo::BranchProtectionInfo &BPI, llvm::Function &F) const { + llvm::AttrBuilder FuncAttrs(F.getContext()); + setFnAttributes(BPI, FuncAttrs); + F.addFnAttrs(FuncAttrs); +} + +void TargetCodeGenInfo::setFnAttributes( +const TargetInfo::BranchProtectionInfo &BPI, +llvm::AttrBuilder &FuncAttrs) const { + if (BPI.SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None) { +FuncAttrs.addAttribute("sign-return-address", BPI.getSignReturnAddrStr()); +FuncAttrs.addAttribute("sign-return-address-key", BPI.getSignKeyStr()); + } + if (BPI.BranchTargetEnforcement) +FuncAttrs.addAttribute("branch-target-enforcement"); + if (BPI.BranchProtectionPAuthLR) +FuncAttrs.addAttribute("branch-protection-pauth-lr"); + if (BPI.GuardedControlStack) +FuncAttrs.addAttribute("guarded-control-stack"); +} + namespace { class DefaultTargetCodeGenInfo : public TargetCodeGenInfo { public: diff --git a/clang/lib/CodeGen/TargetInfo.h b/clang/lib/CodeGen/TargetInfo.h index f242d9e36ed40..78c2f94508f8e 100644 --- a/clang/lib/CodeGen/TargetInfo.h +++ b/clang/lib/CodeGen/TargetInfo.h @@ -15,11 +15,12 @@ #define LLVM_CLANG_LIB_CODEGEN_TARGETINFO_H #include "CGBuilder.h" -#include "CodeGenModule.h" #include "CGValue.h" +#include "CodeGenModule.h" #include "clang/AST/Type.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/SyncScope.h" +#include "clang/Basic/Ta
[clang] [NFC][Clang] Move set functions out BranchProtectionInfo. (PR #98451)
llvmbot wrote: @llvm/pr-subscribers-backend-aarch64 Author: Daniel Kiss (DanielKristofKiss) Changes To reduce build times move them to TargetCodeGenInfo. Refactor of #98329 --- Full diff: https://github.com/llvm/llvm-project/pull/98451.diff 5 Files Affected: - (modified) clang/include/clang/Basic/TargetInfo.h (-23) - (modified) clang/lib/CodeGen/TargetInfo.cpp (+23) - (modified) clang/lib/CodeGen/TargetInfo.h (+8-1) - (modified) clang/lib/CodeGen/Targets/AArch64.cpp (+1-1) - (modified) clang/lib/CodeGen/Targets/ARM.cpp (+2-2) ``diff diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h index cf7628553647c..a58fb5f979272 100644 --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -32,9 +32,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSet.h" #include "llvm/Frontend/OpenMP/OMPGridValues.h" -#include "llvm/IR/Attributes.h" #include "llvm/IR/DerivedTypes.h" -#include "llvm/IR/Function.h" #include "llvm/Support/DataTypes.h" #include "llvm/Support/Error.h" #include "llvm/Support/VersionTuple.h" @@ -1410,7 +1408,6 @@ class TargetInfo : public TransferrableTargetInfo, bool BranchProtectionPAuthLR; bool GuardedControlStack; - protected: const char *getSignReturnAddrStr() const { switch (SignReturnAddr) { case LangOptions::SignReturnAddressScopeKind::None: @@ -1433,7 +1430,6 @@ class TargetInfo : public TransferrableTargetInfo, llvm_unreachable("Unexpected SignReturnAddressKeyKind"); } - public: BranchProtectionInfo() : SignReturnAddr(LangOptions::SignReturnAddressScopeKind::None), SignKey(LangOptions::SignReturnAddressKeyKind::AKey), @@ -1454,25 +1450,6 @@ class TargetInfo : public TransferrableTargetInfo, BranchProtectionPAuthLR = LangOpts.BranchProtectionPAuthLR; GuardedControlStack = LangOpts.GuardedControlStack; } - -void setFnAttributes(llvm::Function &F) { - llvm::AttrBuilder FuncAttrs(F.getContext()); - setFnAttributes(FuncAttrs); - F.addFnAttrs(FuncAttrs); -} - -void setFnAttributes(llvm::AttrBuilder &FuncAttrs) { - if (SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None) { -FuncAttrs.addAttribute("sign-return-address", getSignReturnAddrStr()); -FuncAttrs.addAttribute("sign-return-address-key", getSignKeyStr()); - } - if (BranchTargetEnforcement) -FuncAttrs.addAttribute("branch-target-enforcement"); - if (BranchProtectionPAuthLR) -FuncAttrs.addAttribute("branch-protection-pauth-lr"); - if (GuardedControlStack) -FuncAttrs.addAttribute("guarded-control-stack"); -} }; /// Determine if the Architecture in this TargetInfo supports branch diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp index 60224d458f6a2..9ccf0dea9a738 100644 --- a/clang/lib/CodeGen/TargetInfo.cpp +++ b/clang/lib/CodeGen/TargetInfo.cpp @@ -19,6 +19,7 @@ #include "clang/CodeGen/CGFunctionInfo.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/Twine.h" +#include "llvm/IR/Function.h" #include "llvm/IR/Type.h" #include "llvm/Support/raw_ostream.h" @@ -206,6 +207,28 @@ llvm::Value *TargetCodeGenInfo::createEnqueuedBlockKernel( return F; } +void TargetCodeGenInfo::setFnAttributes( +const TargetInfo::BranchProtectionInfo &BPI, llvm::Function &F) const { + llvm::AttrBuilder FuncAttrs(F.getContext()); + setFnAttributes(BPI, FuncAttrs); + F.addFnAttrs(FuncAttrs); +} + +void TargetCodeGenInfo::setFnAttributes( +const TargetInfo::BranchProtectionInfo &BPI, +llvm::AttrBuilder &FuncAttrs) const { + if (BPI.SignReturnAddr != LangOptions::SignReturnAddressScopeKind::None) { +FuncAttrs.addAttribute("sign-return-address", BPI.getSignReturnAddrStr()); +FuncAttrs.addAttribute("sign-return-address-key", BPI.getSignKeyStr()); + } + if (BPI.BranchTargetEnforcement) +FuncAttrs.addAttribute("branch-target-enforcement"); + if (BPI.BranchProtectionPAuthLR) +FuncAttrs.addAttribute("branch-protection-pauth-lr"); + if (BPI.GuardedControlStack) +FuncAttrs.addAttribute("guarded-control-stack"); +} + namespace { class DefaultTargetCodeGenInfo : public TargetCodeGenInfo { public: diff --git a/clang/lib/CodeGen/TargetInfo.h b/clang/lib/CodeGen/TargetInfo.h index f242d9e36ed40..78c2f94508f8e 100644 --- a/clang/lib/CodeGen/TargetInfo.h +++ b/clang/lib/CodeGen/TargetInfo.h @@ -15,11 +15,12 @@ #define LLVM_CLANG_LIB_CODEGEN_TARGETINFO_H #include "CGBuilder.h" -#include "CodeGenModule.h" #include "CGValue.h" +#include "CodeGenModule.h" #include "clang/AST/Type.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/SyncScope.h" +#include "clang/Basic/TargetInfo.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringRef.h" @@ -413,6 +414,12 @@ class TargetCodeGenInfo { return nullptr; } + void setFnAttributes(const TargetInfo::Branc
[clang] eb61956 - [ObjC][CodeGen] Assume a for-in loop is in bounds and cannot overflow (#94885)
Author: AtariDreams Date: 2024-07-11T10:21:14+01:00 New Revision: eb61956d1a039d9cb03e0d041f33ab2ecc80519e URL: https://github.com/llvm/llvm-project/commit/eb61956d1a039d9cb03e0d041f33ab2ecc80519e DIFF: https://github.com/llvm/llvm-project/commit/eb61956d1a039d9cb03e0d041f33ab2ecc80519e.diff LOG: [ObjC][CodeGen] Assume a for-in loop is in bounds and cannot overflow (#94885) When accessing data in the buffer, we know we won't overrun the buffer, so we know it is inbounds. In addition, we know that the addition to increase the index is also NUW because the buffer's end has to be unsigned-greater-than 0, which becomes untrue if the bounds ever has an unsigned wrap. Added: Modified: clang/lib/CodeGen/CGObjC.cpp clang/test/CodeGenObjC/arc-foreach.m Removed: diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp index 281b2d9795f6c..80a64d8e4cdd9 100644 --- a/clang/lib/CodeGen/CGObjC.cpp +++ b/clang/lib/CodeGen/CGObjC.cpp @@ -1952,7 +1952,7 @@ void CodeGenFunction::EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S){ Builder.CreateLoad(StateItemsPtr, "stateitems"); // Fetch the value at the current index from the buffer. - llvm::Value *CurrentItemPtr = Builder.CreateGEP( + llvm::Value *CurrentItemPtr = Builder.CreateInBoundsGEP( ObjCIdType, EnumStateItems, index, "currentitem.ptr"); llvm::Value *CurrentItem = Builder.CreateAlignedLoad(ObjCIdType, CurrentItemPtr, getPointerAlign()); @@ -2028,7 +2028,7 @@ void CodeGenFunction::EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S){ // First we check in the local buffer. llvm::Value *indexPlusOne = - Builder.CreateAdd(index, llvm::ConstantInt::get(NSUIntegerTy, 1)); + Builder.CreateNUWAdd(index, llvm::ConstantInt::get(NSUIntegerTy, 1)); // If we haven't overrun the buffer yet, we can continue. // Set the branch weights based on the simplifying assumption that this is diff --git a/clang/test/CodeGenObjC/arc-foreach.m b/clang/test/CodeGenObjC/arc-foreach.m index 71edc5161303c..9f7b60aef7a1b 100644 --- a/clang/test/CodeGenObjC/arc-foreach.m +++ b/clang/test/CodeGenObjC/arc-foreach.m @@ -53,7 +53,7 @@ void test0(NSArray *array) { // CHECK-LP64: [[T0:%.*]] = getelementptr inbounds [[STATE_T]], ptr [[STATE]], i32 0, i32 1 // CHECK-LP64-NEXT: [[T1:%.*]] = load ptr, ptr [[T0]] -// CHECK-LP64-NEXT: [[T2:%.*]] = getelementptr ptr, ptr [[T1]], i64 +// CHECK-LP64-NEXT: [[T2:%.*]] = getelementptr inbounds ptr, ptr [[T1]], i64 // CHECK-LP64-NEXT: [[T3:%.*]] = load ptr, ptr [[T2]] // CHECK-LP64-NEXT: store ptr [[T3]], ptr [[X]] @@ -100,7 +100,7 @@ void test1(NSArray *array) { // CHECK-LP64: [[T0:%.*]] = getelementptr inbounds [[STATE_T]], ptr [[STATE]], i32 0, i32 1 // CHECK-LP64-NEXT: [[T1:%.*]] = load ptr, ptr [[T0]] -// CHECK-LP64-NEXT: [[T2:%.*]] = getelementptr ptr, ptr [[T1]], i64 +// CHECK-LP64-NEXT: [[T2:%.*]] = getelementptr inbounds ptr, ptr [[T1]], i64 // CHECK-LP64-NEXT: [[T3:%.*]] = load ptr, ptr [[T2]] // CHECK-LP64-NEXT: call ptr @llvm.objc.initWeak(ptr [[X]], ptr [[T3]]) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [ObjC][CodeGen] Assume a for-in loop is in bounds and cannot overflow (PR #94885)
https://github.com/davidchisnall closed https://github.com/llvm/llvm-project/pull/94885 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 55c0048 - [Clang][Driver] Skip empty strings in getAArch64MultilibFlags (#97827)
Author: Simon Tatham Date: 2024-07-11T10:28:05+01:00 New Revision: 55c00485eb05dfa75d4a20efff2131edd111066d URL: https://github.com/llvm/llvm-project/commit/55c00485eb05dfa75d4a20efff2131edd111066d DIFF: https://github.com/llvm/llvm-project/commit/55c00485eb05dfa75d4a20efff2131edd111066d.diff LOG: [Clang][Driver] Skip empty strings in getAArch64MultilibFlags (#97827) In a multilib setting, if you compile with a command line such as `clang --target=aarch64-none-elf -march=armv8.9-a+rcpc3`, `getAArch64MultilibFlags` returns an ill-formed string containing two consecutive `+` signs, of the form `...+rcpc++rcpc3+...`, causing later stages of multilib selection to get confused. The `++` arises from the entry in `AArch64::Extensions` for the SubtargetFeature `rcpc-immo`, which is a dependency of the `rcpc3` SubtargetFeature, but doesn't have an _extension_ name for the purposes of the `-march=foo+bar` option. So its `UserVisibleName` field is the empty string. To fix this, I've excluded extensions from consideration in `getAArch64MultilibFlags` if they have an empty `UserVisibleName`. Since the input to this function is not derived from a completely general set of SubtargetFeatures, but from a set that has only just been converted _from_ a clang driver command line, the only extensions skipped by this check should be cases like this one, where the anonymous extension was only included because it was a dependency of one mentioned explicitly. I've also made the analogous change in `getARMMultilibFlags`. I don't think it's necessary right now, because the architecture extensions for ARM (defined in `ARMTargetParser.def` rather than Tablegen) don't include any anonymous ones. But it seems sensible to add the check anyway, in case future refactoring introduces anonymous array elements in the same way that AArch64 did, and also in case someone writes a function for another platform by using either of these as example code. Added: clang/test/Driver/aarch64-multilib-rcpc3.c Modified: clang/lib/Driver/ToolChain.cpp Removed: diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index 977e08390800d..85ae4d2a26fee 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -195,11 +195,13 @@ static void getAArch64MultilibFlags(const Driver &D, UnifiedFeatures.end()); std::vector MArch; for (const auto &Ext : AArch64::Extensions) -if (FeatureSet.contains(Ext.PosTargetFeature)) - MArch.push_back(Ext.UserVisibleName.str()); +if (!Ext.UserVisibleName.empty()) + if (FeatureSet.contains(Ext.PosTargetFeature)) +MArch.push_back(Ext.UserVisibleName.str()); for (const auto &Ext : AArch64::Extensions) -if (FeatureSet.contains(Ext.NegTargetFeature)) - MArch.push_back(("no" + Ext.UserVisibleName).str()); +if (!Ext.UserVisibleName.empty()) + if (FeatureSet.contains(Ext.NegTargetFeature)) +MArch.push_back(("no" + Ext.UserVisibleName).str()); StringRef ArchName; for (const auto &ArchInfo : AArch64::ArchInfos) if (FeatureSet.contains(ArchInfo->ArchFeature)) @@ -221,11 +223,13 @@ static void getARMMultilibFlags(const Driver &D, UnifiedFeatures.end()); std::vector MArch; for (const auto &Ext : ARM::ARCHExtNames) -if (FeatureSet.contains(Ext.Feature)) - MArch.push_back(Ext.Name.str()); +if (!Ext.Name.empty()) + if (FeatureSet.contains(Ext.Feature)) +MArch.push_back(Ext.Name.str()); for (const auto &Ext : ARM::ARCHExtNames) -if (FeatureSet.contains(Ext.NegFeature)) - MArch.push_back(("no" + Ext.Name).str()); +if (!Ext.Name.empty()) + if (FeatureSet.contains(Ext.NegFeature)) +MArch.push_back(("no" + Ext.Name).str()); MArch.insert(MArch.begin(), ("-march=" + Triple.getArchName()).str()); Result.push_back(llvm::join(MArch, "+")); diff --git a/clang/test/Driver/aarch64-multilib-rcpc3.c b/clang/test/Driver/aarch64-multilib-rcpc3.c new file mode 100644 index 0..88b23de5a6510 --- /dev/null +++ b/clang/test/Driver/aarch64-multilib-rcpc3.c @@ -0,0 +1,17 @@ +// RUN: %clang --target=aarch64-none-elf -march=armv8.9-a+rcpc3 -print-multi-flags-experimental -c %s 2>&1 | FileCheck %s + +// The purpose of this regression test is to make sure that when +// compile options are converted into multilib selection flags, no +// empty strings are accidentally included in the +// -march=armv8.9-a+foo+bar+baz string, leading to two consecutive + +// signs. With +rcpc3 in the input, this used to generate an empty +// string for the anonymous architecture extension corresponding to +// the SubtargetFeature 'rcpc-immo', which is a dependency of rcpc3 +// but has no separate extension name for use on command lines. So we +// check that the two named rcpc options appear, and that no ++
[clang] [Clang][Driver] Skip empty strings in getAArch64MultilibFlags (PR #97827)
https://github.com/statham-arm closed https://github.com/llvm/llvm-project/pull/97827 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [ObjC][CodeGen] Assume a for-in loop is in bounds and cannot overflow (PR #94885)
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/1385 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/TestConcurrentDelayWatchBreak.py (612 of 1992) PASS: lldb-api :: functionalities/thread/concurrent_events/TestConcurrentDelayedCrashWithBreakpointWatchpoint.py (613 of 1992) PASS: lldb-api :: functionalities/thread/concurrent_events/TestConcurrentDelayedCrashWithBreakpointSignal.py (614 of 1992) PASS: lldb-api :: functionalities/progress_reporting/TestTrimmedProgressReporting.py (615 of 1992) PASS: lldb-api :: functionalities/thread/concurrent_events/TestConcurrentManyCrash.py (616 of 1992) PASS: lldb-api :: functionalities/thread/concurrent_events/TestConcurrentManyBreakpoints.py (617 of 1992) PASS: lldb-api :: functionalities/thread/concurrent_events/TestConcurrentSignalBreak.py (618 of 1992) PASS: lldb-api :: functionalities/thread/concurrent_events/TestConcurrentNWatchNBreak.py (619 of 1992) PASS: lldb-api :: functionalities/thread/concurrent_events/TestConcurrentSignalDelayBreak.py (620 of 1992) PASS: lldb-api :: functionalities/thread/concurrent_events/TestConcurrentSignalDelayWatch.py (621 of 1992) FAIL: lldb-api :: functionalities/thread/concurrent_events/TestConcurrentSignalNWatchNBreak.py (622 of 1992) TEST 'lldb-api :: functionalities/thread/concurrent_events/TestConcurrentSignalNWatchNBreak.py' FAILED Script: -- /usr/bin/python3.8 /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 TestConcurrentSignalNWatchNBreak.py -- Exit Code: 1 Command Output (stdout): -- lldb version 19.0.0git (https://github.com/llvm/llvm-project.git revision eb61956d1a039d9cb03e0d041f33ab2ecc80519e) clang revision eb61956d1a039d9cb03e0d041f33ab2ecc80519e llvm revision eb61956d1a039d9cb03e0d041f33ab2ecc80519e Skipping the following test categories: ['libc++', 'dsym', 'gmodules', 'debugserver', 'objc'] Watchpoint 1 hit: old value: 0 new value: 1 Watchpoint 1 hit: old value: 1 new value: 1 Watchpoint 1 hit: old value: 1 new value: 1 Watchpoint 1 hit: old value: 1 new value: 1 Watchpoint 1 hit: old value: 1 new value: 1 -- Command Output (stderr): -- FAIL: LLDB (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: test (TestConcurrentSignalNWatchNBreak.ConcurrentSignalNWatchNBreak) ``` https://github.com/llvm/llvm-project/pull/94885 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [lldb] [llvm] [llvm][TargetParser] Return StringMap from getHostCPUFeatures (PR #97824)
https://github.com/DavidSpickett updated https://github.com/llvm/llvm-project/pull/97824 >From 7ebe4e487b763ff26fbab6d75aa7c8694d63e8b1 Mon Sep 17 00:00:00 2001 From: David Spickett Date: Fri, 5 Jul 2024 08:42:22 + Subject: [PATCH 1/9] [llvm][TargetParser] Return optional from getHostCPUFeatures Previously this took a reference to a map and returned a bool to say whether it succeeded. This is an optional but with more steps. The only reason to keep it that way was if someone was appending to an existing map, but all callers made a new map before calling it. --- clang/lib/Driver/ToolChains/Arch/ARM.cpp | 6 ++-- clang/lib/Driver/ToolChains/Arch/X86.cpp | 6 ++-- lldb/utils/lit-cpuid/lit-cpuid.cpp| 21 +++--- llvm/include/llvm/TargetParser/Host.h | 14 - llvm/lib/CodeGen/CommandFlags.cpp | 16 -- .../Orc/JITTargetMachineBuilder.cpp | 8 ++--- llvm/lib/Target/TargetMachineC.cpp| 5 ++-- llvm/lib/TargetParser/Host.cpp| 29 --- 8 files changed, 54 insertions(+), 51 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp b/clang/lib/Driver/ToolChains/Arch/ARM.cpp index 8ae22cc37a136..77adbf3865ab1 100644 --- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp +++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp @@ -591,9 +591,9 @@ llvm::ARM::FPUKind arm::getARMTargetFeatures(const Driver &D, // Add CPU features for generic CPUs if (CPUName == "native") { -llvm::StringMap HostFeatures; -if (llvm::sys::getHostCPUFeatures(HostFeatures)) - for (auto &F : HostFeatures) +if (std::optional> HostFeatures = +llvm::sys::getHostCPUFeatures()) + for (auto &F : *HostFeatures) Features.push_back( Args.MakeArgString((F.second ? "+" : "-") + F.first())); } else if (!CPUName.empty()) { diff --git a/clang/lib/Driver/ToolChains/Arch/X86.cpp b/clang/lib/Driver/ToolChains/Arch/X86.cpp index 92821b2a82dae..e4adfcac23ca0 100644 --- a/clang/lib/Driver/ToolChains/Arch/X86.cpp +++ b/clang/lib/Driver/ToolChains/Arch/X86.cpp @@ -131,9 +131,9 @@ void x86::getX86TargetFeatures(const Driver &D, const llvm::Triple &Triple, // If -march=native, autodetect the feature list. if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_march_EQ)) { if (StringRef(A->getValue()) == "native") { - llvm::StringMap HostFeatures; - if (llvm::sys::getHostCPUFeatures(HostFeatures)) -for (auto &F : HostFeatures) + if (std::optional> HostFeatures = + llvm::sys::getHostCPUFeatures()) +for (auto &F : *HostFeatures) Features.push_back( Args.MakeArgString((F.second ? "+" : "-") + F.first())); } diff --git a/lldb/utils/lit-cpuid/lit-cpuid.cpp b/lldb/utils/lit-cpuid/lit-cpuid.cpp index be322cb6aa42a..16743164e6a5d 100644 --- a/lldb/utils/lit-cpuid/lit-cpuid.cpp +++ b/lldb/utils/lit-cpuid/lit-cpuid.cpp @@ -15,22 +15,23 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/TargetParser/Host.h" +#include + using namespace llvm; int main(int argc, char **argv) { #if defined(__i386__) || defined(_M_IX86) || \ defined(__x86_64__) || defined(_M_X64) - StringMap features; - - if (!sys::getHostCPUFeatures(features)) + if (std::optional> features = + sys::getHostCPUFeatures(features)) { +if ((*features)["sse"]) + outs() << "sse\n"; +if ((*features)["avx"]) + outs() << "avx\n"; +if ((*features)["avx512f"]) + outs() << "avx512f\n"; + } else return 1; - - if (features["sse"]) -outs() << "sse\n"; - if (features["avx"]) -outs() << "avx\n"; - if (features["avx512f"]) -outs() << "avx512f\n"; #endif return 0; diff --git a/llvm/include/llvm/TargetParser/Host.h b/llvm/include/llvm/TargetParser/Host.h index af72045a8fe67..d68655835a323 100644 --- a/llvm/include/llvm/TargetParser/Host.h +++ b/llvm/include/llvm/TargetParser/Host.h @@ -13,6 +13,7 @@ #ifndef LLVM_TARGETPARSER_HOST_H #define LLVM_TARGETPARSER_HOST_H +#include #include namespace llvm { @@ -47,13 +48,12 @@ namespace sys { /// The particular format of the names are target dependent, and suitable for /// passing as -mattr to the target which matches the host. /// - /// \param Features - A string mapping feature names to either - /// true (if enabled) or false (if disabled). This routine makes no guarantees - /// about exactly which features may appear in this map, except that they are - /// all valid LLVM feature names. - /// - /// \return - True on success. - bool getHostCPUFeatures(StringMap &Features); + /// \return - If feature detection succeeds, a string map mapping feature + /// names to either true (if enabled) or false (if disabled). This routine + /// makes no guarantees about exactly which features may appear in this map, + /// except that they are all valid LLVM feature names. If feature detection + /// fails, an
[clang] [lldb] [llvm] [llvm][TargetParser] Return StringMap from getHostCPUFeatures (PR #97824)
@@ -20,16 +20,15 @@ using namespace llvm; int main(int argc, char **argv) { #if defined(__i386__) || defined(_M_IX86) || \ defined(__x86_64__) || defined(_M_X64) - StringMap features; - - if (!sys::getHostCPUFeatures(features)) + const StringMap features = sys::getHostCPUFeatures(features); + if (features.empty()) return 1; - if (features["sse"]) + if (features->lookup("sse")) DavidSpickett wrote: It doesn't, I forgot to rebuild on x86. Fixed this and removed the parameter that's no longer needed. https://github.com/llvm/llvm-project/pull/97824 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 18e70a4 - [llvm][TargetParser] Return StringMap from getHostCPUFeatures (#97824)
Author: David Spickett Date: 2024-07-11T10:32:43+01:00 New Revision: 18e70a4d5042299054dae7d3995f6ccd8f4112b3 URL: https://github.com/llvm/llvm-project/commit/18e70a4d5042299054dae7d3995f6ccd8f4112b3 DIFF: https://github.com/llvm/llvm-project/commit/18e70a4d5042299054dae7d3995f6ccd8f4112b3.diff LOG: [llvm][TargetParser] Return StringMap from getHostCPUFeatures (#97824) Previously this took a reference to a map and returned a bool to say whether it succeeded. We can return a StringMap instead, as all callers but 1 simply iterated the map if the bool was true, and passed in empty maps as the starting point. lldb's lit-cpuid did specifically check whether the call failed, but due to the way the x86 routines work this works out the same as checking if the returned map is empty. Added: Modified: clang/lib/Driver/ToolChains/Arch/ARM.cpp clang/lib/Driver/ToolChains/Arch/X86.cpp lldb/utils/lit-cpuid/lit-cpuid.cpp llvm/include/llvm/TargetParser/Host.h llvm/lib/CodeGen/CommandFlags.cpp llvm/lib/ExecutionEngine/Orc/JITTargetMachineBuilder.cpp llvm/lib/Target/TargetMachineC.cpp llvm/lib/TargetParser/Host.cpp Removed: diff --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp b/clang/lib/Driver/ToolChains/Arch/ARM.cpp index 8ae22cc37a136..a6041b809b80b 100644 --- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp +++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp @@ -591,11 +591,9 @@ llvm::ARM::FPUKind arm::getARMTargetFeatures(const Driver &D, // Add CPU features for generic CPUs if (CPUName == "native") { -llvm::StringMap HostFeatures; -if (llvm::sys::getHostCPUFeatures(HostFeatures)) - for (auto &F : HostFeatures) -Features.push_back( -Args.MakeArgString((F.second ? "+" : "-") + F.first())); +for (auto &F : llvm::sys::getHostCPUFeatures()) + Features.push_back( + Args.MakeArgString((F.second ? "+" : "-") + F.first())); } else if (!CPUName.empty()) { // This sets the default features for the specified CPU. We certainly don't // want to override the features that have been explicitly specified on the diff --git a/clang/lib/Driver/ToolChains/Arch/X86.cpp b/clang/lib/Driver/ToolChains/Arch/X86.cpp index 92821b2a82dae..9fca7864b2546 100644 --- a/clang/lib/Driver/ToolChains/Arch/X86.cpp +++ b/clang/lib/Driver/ToolChains/Arch/X86.cpp @@ -131,11 +131,9 @@ void x86::getX86TargetFeatures(const Driver &D, const llvm::Triple &Triple, // If -march=native, autodetect the feature list. if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_march_EQ)) { if (StringRef(A->getValue()) == "native") { - llvm::StringMap HostFeatures; - if (llvm::sys::getHostCPUFeatures(HostFeatures)) -for (auto &F : HostFeatures) - Features.push_back( - Args.MakeArgString((F.second ? "+" : "-") + F.first())); + for (auto &F : llvm::sys::getHostCPUFeatures()) +Features.push_back( +Args.MakeArgString((F.second ? "+" : "-") + F.first())); } } diff --git a/lldb/utils/lit-cpuid/lit-cpuid.cpp b/lldb/utils/lit-cpuid/lit-cpuid.cpp index be322cb6aa42a..55f6dfd8ea906 100644 --- a/lldb/utils/lit-cpuid/lit-cpuid.cpp +++ b/lldb/utils/lit-cpuid/lit-cpuid.cpp @@ -20,16 +20,15 @@ using namespace llvm; int main(int argc, char **argv) { #if defined(__i386__) || defined(_M_IX86) || \ defined(__x86_64__) || defined(_M_X64) - StringMap features; - - if (!sys::getHostCPUFeatures(features)) + const StringMap features = sys::getHostCPUFeatures(); + if (features.empty()) return 1; - if (features["sse"]) + if (features.lookup("sse")) outs() << "sse\n"; - if (features["avx"]) + if (features.lookup("avx")) outs() << "avx\n"; - if (features["avx512f"]) + if (features.lookup("avx512f")) outs() << "avx512f\n"; #endif diff --git a/llvm/include/llvm/TargetParser/Host.h b/llvm/include/llvm/TargetParser/Host.h index af72045a8fe67..a639b093f21bd 100644 --- a/llvm/include/llvm/TargetParser/Host.h +++ b/llvm/include/llvm/TargetParser/Host.h @@ -47,13 +47,12 @@ namespace sys { /// The particular format of the names are target dependent, and suitable for /// passing as -mattr to the target which matches the host. /// - /// \param Features - A string mapping feature names to either - /// true (if enabled) or false (if disabled). This routine makes no guarantees - /// about exactly which features may appear in this map, except that they are - /// all valid LLVM feature names. - /// - /// \return - True on success. - bool getHostCPUFeatures(StringMap &Features); + /// \return - A string map mapping feature names to either true (if enabled) + /// or false (if disabled). This routine makes no guarantees about exactly + /// which features may appear in this map, except that they are all valid LLVM + /// feature names. The map can be empty, fo
[clang] [lldb] [llvm] [llvm][TargetParser] Return StringMap from getHostCPUFeatures (PR #97824)
https://github.com/DavidSpickett closed https://github.com/llvm/llvm-project/pull/97824 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [ObjC][CodeGen] Assume a for-in loop is in bounds and cannot overflow (PR #94885)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `flang-aarch64-dylib` running on `linaro-flang-aarch64-dylib` while building `clang` at step 5 "build-unified-tree". Full details are available at: https://lab.llvm.org/buildbot/#/builders/50/builds/971 Here is the relevant piece of the build log for the reference: ``` Step 5 (build-unified-tree) failure: build (failure) ... 496.986 [2330/1/4239] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/CXType.cpp.o 497.815 [2329/1/4240] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/Indexing.cpp.o 497.885 [2328/1/4241] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/FatalErrorHandler.cpp.o 498.456 [2327/1/4242] Building CXX object tools/clang/tools/libclang/CMakeFiles/libclang.dir/Rewrite.cpp.o 498.581 [2326/1/4243] Building CXX object tools/clang/tools/amdgpu-arch/CMakeFiles/amdgpu-arch.dir/AMDGPUArchByHSA.cpp.o 498.714 [2325/1/4244] Building CXX object tools/clang/tools/amdgpu-arch/CMakeFiles/amdgpu-arch.dir/AMDGPUArch.cpp.o 498.856 [2324/1/4245] Building CXX object tools/clang/tools/amdgpu-arch/CMakeFiles/amdgpu-arch.dir/AMDGPUArchByHIP.cpp.o 498.964 [2323/1/4246] Building CXX object tools/clang/tools/nvptx-arch/CMakeFiles/nvptx-arch.dir/NVPTXArch.cpp.o 499.055 [2322/1/4247] Building FIREnumAttr.cpp.inc... 508.390 [2321/1/4248] Building CXX object tools/flang/lib/Optimizer/Dialect/CUF/CMakeFiles/obj.CUFDialect.dir/CUFOps.cpp.o FAILED: tools/flang/lib/Optimizer/Dialect/CUF/CMakeFiles/obj.CUFDialect.dir/CUFOps.cpp.o /usr/local/bin/c++ -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/tcwg-buildbot/worker/flang-aarch64-dylib/build/tools/flang/lib/Optimizer/Dialect/CUF -I/home/tcwg-buildbot/worker/flang-aarch64-dylib/llvm-project/flang/lib/Optimizer/Dialect/CUF -I/home/tcwg-buildbot/worker/flang-aarch64-dylib/llvm-project/flang/include -I/home/tcwg-buildbot/worker/flang-aarch64-dylib/build/tools/flang/include -I/home/tcwg-buildbot/worker/flang-aarch64-dylib/build/include -I/home/tcwg-buildbot/worker/flang-aarch64-dylib/llvm-project/llvm/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-dylib/llvm-project/llvm/../mlir/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-dylib/build/tools/mlir/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-dylib/build/tools/clang/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-dylib/llvm-project/llvm/../clang/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Wno-deprecated-copy -Wno-string-conversion -Wno-ctad-maybe-unsupported -Wno-unused-command-line-argument -Wstring-conversion -Wcovered-switch-default -Wno-nested-anon-types -O3 -DNDEBUG -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -std=c++17 -MD -MT tools/flang/lib/Optimizer/Dialect/CUF/CMakeFiles/obj.CUFDialect.dir/CUFOps.cpp.o -MF tools/flang/lib/Optimizer/Dialect/CUF/CMakeFiles/obj.CUFDialect.dir/CUFOps.cpp.o.d -o tools/flang/lib/Optimizer/Dialect/CUF/CMakeFiles/obj.CUFDialect.dir/CUFOps.cpp.o -c /home/tcwg-buildbot/worker/flang-aarch64-dylib/llvm-project/flang/lib/Optimizer/Dialect/CUF/CUFOps.cpp In file included from /home/tcwg-buildbot/worker/flang-aarch64-dylib/llvm-project/flang/lib/Optimizer/Dialect/CUF/CUFOps.cpp:13: In file included from /home/tcwg-buildbot/worker/flang-aarch64-dylib/llvm-project/flang/include/flang/Optimizer/Dialect/CUF/CUFOps.h:14: /home/tcwg-buildbot/worker/flang-aarch64-dylib/llvm-project/flang/include/flang/Optimizer/Dialect/FIRType.h:71:10: fatal error: 'flang/Optimizer/Dialect/FIROpsTypes.h.inc' file not found 71 | #include "flang/Optimizer/Dialect/FIROpsTypes.h.inc" | ^~~ 1 error generated. ninja: build stopped: subcommand failed. ``` https://github.com/llvm/llvm-project/pull/94885 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [ObjC][CodeGen] Assume a for-in loop is in bounds and cannot overflow (PR #94885)
davidchisnall wrote: Those CI failures look unrelated. https://github.com/llvm/llvm-project/pull/94885 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] CTAD: use index and depth to retrieve template parameter for TemplateParamsReferencedInTemplateArgumentList (PR #98013)
https://github.com/hokein updated https://github.com/llvm/llvm-project/pull/98013 >From c9297f8abe8d480fdcd3ba6d6598268fef74ddb4 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Mon, 8 Jul 2024 13:19:13 +0200 Subject: [PATCH 1/3] [clang] CTAD: use index and depth to retrieve template parameters in TemplateParamsReferencedInTemplateArgumentList. --- clang/lib/Sema/SemaTemplate.cpp| 31 +++--- clang/test/AST/ast-dump-ctad-alias.cpp | 25 + 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 3d8cf750c12c1..196a5cc10ce40 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -2754,20 +2754,34 @@ struct ConvertConstructorToDeductionGuideTransform { // Find all template parameters that appear in the given DeducedArgs. // Return the indices of the template parameters in the TemplateParams. SmallVector TemplateParamsReferencedInTemplateArgumentList( -ArrayRef TemplateParams, +const TemplateParameterList* TemplateParamsList, ArrayRef DeducedArgs) { struct TemplateParamsReferencedFinder : public RecursiveASTVisitor { +const TemplateParameterList* TemplateParamList; llvm::DenseSet TemplateParams; llvm::DenseSet ReferencedTemplateParams; -TemplateParamsReferencedFinder(ArrayRef TemplateParams) -: TemplateParams(TemplateParams.begin(), TemplateParams.end()) {} +TemplateParamsReferencedFinder( +const TemplateParameterList *TemplateParamList) +: TemplateParamList(TemplateParamList), + TemplateParams(TemplateParamList->begin(), TemplateParamList->end()) { +} bool VisitTemplateTypeParmType(TemplateTypeParmType *TTP) { - MarkAppeared(TTP->getDecl()); + // We use the index and depth to retrieve the corresponding template + // parameter from the parameter list. + // Note that Clang may not preserve type sugar during template argument + // deduction. In such cases, the TTP is a canonical TemplateTypeParamType, + // which only retains its index and depth information. + if (TTP->getDepth() == TemplateParamList->getDepth() && + TTP->getIndex() < TemplateParamList->size()) { +ReferencedTemplateParams.insert( +TemplateParamList->getParam(TTP->getIndex())); + } return true; } + bool VisitDeclRefExpr(DeclRefExpr *DRE) { MarkAppeared(DRE->getFoundDecl()); return true; @@ -2784,12 +2798,13 @@ SmallVector TemplateParamsReferencedInTemplateArgumentList( ReferencedTemplateParams.insert(ND); } }; - TemplateParamsReferencedFinder Finder(TemplateParams); + TemplateParamsReferencedFinder Finder(TemplateParamsList); Finder.TraverseTemplateArguments(DeducedArgs); SmallVector Results; - for (unsigned Index = 0; Index < TemplateParams.size(); ++Index) { -if (Finder.ReferencedTemplateParams.contains(TemplateParams[Index])) + for (unsigned Index = 0; Index < TemplateParamsList->size(); ++Index) { +if (Finder.ReferencedTemplateParams.contains( +TemplateParamsList->getParam(Index))) Results.push_back(Index); } return Results; @@ -3149,7 +3164,7 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef, } auto DeducedAliasTemplateParams = TemplateParamsReferencedInTemplateArgumentList( - AliasTemplate->getTemplateParameters()->asArray(), DeducedArgs); + AliasTemplate->getTemplateParameters(), DeducedArgs); // All template arguments null by default. SmallVector TemplateArgsForBuildingFPrime( F->getTemplateParameters()->size()); diff --git a/clang/test/AST/ast-dump-ctad-alias.cpp b/clang/test/AST/ast-dump-ctad-alias.cpp index 6f07a62e9a069..adccad97a205b 100644 --- a/clang/test/AST/ast-dump-ctad-alias.cpp +++ b/clang/test/AST/ast-dump-ctad-alias.cpp @@ -99,3 +99,28 @@ BFoo b2(1.0, 2.0); // CHECK-NEXT: | | |-ParmVarDecl {{.*}} 'type-parameter-0-0' // CHECK-NEXT: | | `-ParmVarDecl {{.*}} 'type-parameter-0-0' // CHECK-NEXT: | `-CXXDeductionGuideDecl {{.*}} implicit used 'auto (double, double) -> Foo' implicit_instantiation + +namespace GH90209 { +template +struct List { + List(int); +}; + +template +struct TemplatedClass { + TemplatedClass(T1); +}; + +template +TemplatedClass(T1) -> TemplatedClass>; + +template +using ATemplatedClass = TemplatedClass>; + +ATemplatedClass test(1); +// Verify that we have a correct template parameter list for the deduction guide. +// +// CHECK: FunctionTemplateDecl {{.*}} +// CHECK-NEXT: |-TemplateTypeParmDecl {{.*}} class depth 0 index 0 T2 +// CHECK-NEXT: |-TypeTraitExpr {{.*}} 'bool' __is_deducible +} // namespace GH90209 \ No newline at end of file >From 7626982d97d7f0f088af95be371f65d5a0f02ee9 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Thu, 11 Jul 2024 11:09:55 +0200 Subject: [PATCH 2/3] Address review comment. --- clang/lib/Sema/SemaTempl
[clang] [LoongArch][clang] Modify `loongarch-msimd.c` to avoid `grep -o`. NFC (PR #98442)
https://github.com/SixWeining approved this pull request. https://github.com/llvm/llvm-project/pull/98442 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 74b933c - [LoongArch][clang] Modify `loongarch-msimd.c` to avoid `grep -o`. NFC (#98442)
Author: Zhaoxin Yang Date: 2024-07-11T17:43:38+08:00 New Revision: 74b933c28e777fdc04e50f5f96e4f7a4ad1e79a6 URL: https://github.com/llvm/llvm-project/commit/74b933c28e777fdc04e50f5f96e4f7a4ad1e79a6 DIFF: https://github.com/llvm/llvm-project/commit/74b933c28e777fdc04e50f5f96e4f7a4ad1e79a6.diff LOG: [LoongArch][clang] Modify `loongarch-msimd.c` to avoid `grep -o`. NFC (#98442) Address buildbot failure: https://lab.llvm.org/buildbot/#/builders/64/builds/250/steps/6/logs/FAIL__Clang__loongarch-msimd_c Added: Modified: clang/test/Driver/loongarch-msimd.c Removed: diff --git a/clang/test/Driver/loongarch-msimd.c b/clang/test/Driver/loongarch-msimd.c index 984f3e8bf2bfc..cd463300c8747 100644 --- a/clang/test/Driver/loongarch-msimd.c +++ b/clang/test/Driver/loongarch-msimd.c @@ -2,128 +2,94 @@ /// COM: -msimd=none // RUN: %clang --target=loongarch64 -mlasx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=LSX,LASX // RUN: %clang --target=loongarch64 -mlasx -mlsx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=LSX,LASX // RUN: %clang --target=loongarch64 -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX // RUN: %clang --target=loongarch64 -mlasx -mno-lasx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX // RUN: %clang --target=loongarch64 -mlasx -mno-lasx -mlsx -mno-lsx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX // RUN: %clang --target=loongarch64 -mlasx -mno-lasx -mno-lsx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX // RUN: %clang --target=loongarch64 -mlsx -mno-lsx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX // RUN: %clang --target=loongarch64 -mno-lasx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX // RUN: %clang --target=loongarch64 -mno-lasx -mlsx -mno-lsx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX // RUN: %clang --target=loongarch64 -mno-lasx -mno-lsx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX // RUN: %clang --target=loongarch64 -mno-lsx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX // RUN: %clang --target=loongarch64 -mlasx -mno-lasx -mlsx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=LSX,NOLASX // RUN: %clang --target=loongarch64 -mno-lasx -mlsx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=LSX,NOLASX // RUN: %clang --target=loongarch64 -mlsx -msimd=none -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=LSX,NOLASX /// COM: -msimd=lsx // RUN: %clang --target=loongarch64 -mlasx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=LSX,LASX // RUN: %clang --target=loongarch64 -mlasx -mlsx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=LSX,LASX // RUN: %clang --target=loongarch64 -mlasx -mno-lasx -mno-lsx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX // RUN: %clang --target=loongarch64 -mlsx -mno-lsx -msimd=lsx -fsyntax-only %s -### 2>&1 | \ -// RUN: grep -o '"-target-feature" "+[[:alnum:]]\+"' | sort -r | \ // RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX // RUN: %clang --target=loongarch64 -mno-lasx -mlsx -mno-lsx -msimd=lsx -fsyntax-only %s -#
[clang] [LoongArch][clang] Modify `loongarch-msimd.c` to avoid `grep -o`. NFC (PR #98442)
https://github.com/SixWeining closed https://github.com/llvm/llvm-project/pull/98442 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] CTAD: use index and depth to retrieve template parameter for TemplateParamsReferencedInTemplateArgumentList (PR #98013)
@@ -99,3 +99,28 @@ BFoo b2(1.0, 2.0); // CHECK-NEXT: | | |-ParmVarDecl {{.*}} 'type-parameter-0-0' // CHECK-NEXT: | | `-ParmVarDecl {{.*}} 'type-parameter-0-0' // CHECK-NEXT: | `-CXXDeductionGuideDecl {{.*}} implicit used 'auto (double, double) -> Foo' implicit_instantiation + +namespace GH90209 { +template +struct List { + List(int); +}; + +template +struct TemplatedClass { + TemplatedClass(T1); +}; + +template +TemplatedClass(T1) -> TemplatedClass>; + +template +using ATemplatedClass = TemplatedClass>; + +ATemplatedClass test(1); +// Verify that we have a correct template parameter list for the deduction guide. +// +// CHECK: FunctionTemplateDecl {{.*}} +// CHECK-NEXT: |-TemplateTypeParmDecl {{.*}} class depth 0 index 0 T2 +// CHECK-NEXT: |-TypeTraitExpr {{.*}} 'bool' __is_deducible +} // namespace GH90209 mizvekov wrote: The GitHub editor still shows the missing newline at end of file marker. https://github.com/llvm/llvm-project/pull/98013 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] CTAD: use index and depth to retrieve template parameter for TemplateParamsReferencedInTemplateArgumentList (PR #98013)
@@ -2653,20 +2653,34 @@ struct ConvertConstructorToDeductionGuideTransform { // Find all template parameters that appear in the given DeducedArgs. // Return the indices of the template parameters in the TemplateParams. SmallVector TemplateParamsReferencedInTemplateArgumentList( -ArrayRef TemplateParams, +const TemplateParameterList* TemplateParamsList, ArrayRef DeducedArgs) { struct TemplateParamsReferencedFinder : public RecursiveASTVisitor { +const TemplateParameterList* TemplateParamList; llvm::DenseSet TemplateParams; llvm::DenseSet ReferencedTemplateParams; -TemplateParamsReferencedFinder(ArrayRef TemplateParams) -: TemplateParams(TemplateParams.begin(), TemplateParams.end()) {} +TemplateParamsReferencedFinder( +const TemplateParameterList *TemplateParamList) +: TemplateParamList(TemplateParamList), + TemplateParams(TemplateParamList->begin(), TemplateParamList->end()) { +} bool VisitTemplateTypeParmType(TemplateTypeParmType *TTP) { - MarkAppeared(TTP->getDecl()); + // We use the index and depth to retrieve the corresponding template + // parameter from the parameter list. + // Note that Clang may not preserve type sugar during template argument + // deduction. In such cases, the TTP is a canonical TemplateTypeParamType, + // which only retains its index and depth information. + if (TTP->getDepth() == TemplateParamList->getDepth() && mizvekov wrote: The NTTP case is trickier to test, as we don't canonicalize expressions the same way we do types and templates, but in some situations, you could have an NTTP which was uniqued pointing to a specific parameter, but this is misleading and you should disregard that and look at only the depth and index. But I would expect template template parameters to behave similarly as type parameters here, and it should be just as straightforward to test, so I think it would b e worth a try. https://github.com/llvm/llvm-project/pull/98013 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CGRecordLayout] Remove dependency on isZeroSize (PR #96422)
Michael137 wrote: Some of the libc++ tests seem to be crashing on the x86_64 bot (can repro this on my x86_64 at home, not aarch64 though). Looks like they're segfaulting trying to access the member of an empty class. E.g., in ``` Process 1370440 stopped * thread #1, name = 't.tmp.exe', stop reason = signal SIGSEGV: invalid address (fault address: 0x20) frame #0: 0x60c3 t.tmp.exe`std::__1::operator==[abi:se19](__x=0x7fffdd10, __y=0x7fffdcd0) at error_code.h:97:25 94 } 95 96 inline _LIBCPP_HIDE_FROM_ABI bool operator==(const error_code& __x, const error_condition& __y) _NOEXCEPT { -> 97 return __x.category().equivalent(__x.value(), __y) || __y.category().equivalent(__x, __y.value()); 98 } 99 100 #if _LIBCPP_STD_VER <= 17 (lldb) dis -pc t.tmp.exe`std::__1::operator==[abi:se19](std::__1::error_code const&, std::__1::error_condition const&): -> 0x60c3 <+51>: callq *0x20(%rax) 0x60c6 <+54>: movb %al, %cl 0x60c8 <+56>: movb $0x1, %al 0x60ca <+58>: testb $0x1, %cl (lldb) ``` https://github.com/llvm/llvm-project/pull/96422 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] CTAD: use index and depth to retrieve template parameter for TemplateParamsReferencedInTemplateArgumentList (PR #98013)
https://github.com/mizvekov approved this pull request. LGTM, sans: * missing newline at end of test file * A similar test for template template parameter. https://github.com/llvm/llvm-project/pull/98013 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libclang/python] Refactor enum usage (PR #95608)
https://github.com/Endilll commented: Sorry for not getting back to you earlier. https://github.com/llvm/llvm-project/pull/95608 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libclang/python] Refactor enum usage (PR #95608)
https://github.com/Endilll edited https://github.com/llvm/llvm-project/pull/95608 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libclang/python] Refactor enum usage (PR #95608)
@@ -611,51 +612,25 @@ def register(value, name): ### Cursor Kinds ### -class BaseEnumeration: +class BaseEnumeration(Enum): """ Common base class for named enumerations held in sync with Index.h values. - -Subclasses must define their own _kinds and _name_map members, as: -_kinds = [] -_name_map = None -These values hold the per-subclass instances and value-to-name mappings, -respectively. - """ -def __init__(self, value): -if value >= len(self.__class__._kinds): -self.__class__._kinds += [None] * (value - len(self.__class__._kinds) + 1) -if self.__class__._kinds[value] is not None: -raise ValueError( -"{0} value {1} already loaded".format(str(self.__class__), value) -) -self.value = value -self.__class__._kinds[value] = self -self.__class__._name_map = None def from_param(self): return self.value -@property -def name(self): -"""Get the enumeration name of this cursor kind.""" -if self._name_map is None: -self._name_map = {} -for key, value in self.__class__.__dict__.items(): -if isinstance(value, self.__class__): -self._name_map[value] = key -return self._name_map[self] - @classmethod def from_id(cls, id): -if id < 0 or id >= len(cls._kinds) or cls._kinds[id] is None: -raise ValueError("Unknown template argument kind %d" % id) -return cls._kinds[id] +try: +return cls(id) +except ValueError: +raise ValueError("Unknown %s %d" % (cls.__name__, id)) from None Endilll wrote: Changing error messages is not breaking, because we don't promise their stability anywhere as far as I know. Given that those are error messages about enums, I think such a change would belong to this PR if you want to move in this direction. On a separate note, do we even need `from None` here? I think it's implicit anyway. https://github.com/llvm/llvm-project/pull/95608 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [LoongArch][clang] Add support for option `-msimd=` and macro `__loongarch_simd_width`. (PR #97984)
ylzsx wrote: > Hi, this test is failing on the AIX bot > https://lab.llvm.org/buildbot/#/builders/64/builds/250/steps/6/logs/FAIL__Clang__loongarch-msimd_c > > The reason is that -o is not a supported option with grep on AIX. Would you > be able to adapt the test to avoid piping and use input redirection (so that > the builtin grep is used, for example here: > https://github.com/llvm/llvm-project/pull/83184/files. I'm not sure if this > works with grep though) or use another command like sed? @jakeegan Already fixed, see https://github.com/llvm/llvm-project/pull/98442. https://github.com/llvm/llvm-project/pull/97984 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libclang/python] Refactor enum usage (PR #95608)
https://github.com/DeinAlptraum updated https://github.com/llvm/llvm-project/pull/95608 >From 35bfcfbc69ee812c59350440b7b15c5e23ad1307 Mon Sep 17 00:00:00 2001 From: Jannick Kremer Date: Fri, 14 Jun 2024 22:12:09 +0100 Subject: [PATCH 1/4] [libclang/python] Refactor enum usage Use Python's builtin enum class instead of writing our own. This is preparation for strict typing in PR #78114 --- clang/bindings/python/clang/cindex.py | 1670 - .../python/tests/cindex/test_enums.py | 14 +- 2 files changed, 768 insertions(+), 916 deletions(-) diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py index b3d51e4d2a668..aacfc333723c4 100644 --- a/clang/bindings/python/clang/cindex.py +++ b/clang/bindings/python/clang/cindex.py @@ -68,6 +68,7 @@ import collections.abc import os +from enum import Enum # Python 3 strings are unicode, translate them to/from utf8 for C-interop. @@ -611,51 +612,25 @@ def register(value, name): ### Cursor Kinds ### -class BaseEnumeration: +class BaseEnumeration(Enum): """ Common base class for named enumerations held in sync with Index.h values. - -Subclasses must define their own _kinds and _name_map members, as: -_kinds = [] -_name_map = None -These values hold the per-subclass instances and value-to-name mappings, -respectively. - """ -def __init__(self, value): -if value >= len(self.__class__._kinds): -self.__class__._kinds += [None] * (value - len(self.__class__._kinds) + 1) -if self.__class__._kinds[value] is not None: -raise ValueError( -"{0} value {1} already loaded".format(str(self.__class__), value) -) -self.value = value -self.__class__._kinds[value] = self -self.__class__._name_map = None def from_param(self): return self.value -@property -def name(self): -"""Get the enumeration name of this cursor kind.""" -if self._name_map is None: -self._name_map = {} -for key, value in self.__class__.__dict__.items(): -if isinstance(value, self.__class__): -self._name_map[value] = key -return self._name_map[self] - @classmethod def from_id(cls, id): -if id < 0 or id >= len(cls._kinds) or cls._kinds[id] is None: -raise ValueError("Unknown template argument kind %d" % id) -return cls._kinds[id] +try: +return cls(id) +except ValueError: +raise ValueError("Unknown %s %d" % (cls.__name__, id)) from None def __repr__(self): return "%s.%s" % ( -self.__class__, +self.__class__.__name__, self.name, ) @@ -665,14 +640,10 @@ class CursorKind(BaseEnumeration): A CursorKind describes the kind of entity that a cursor points to. """ -# The required BaseEnumeration declarations. -_kinds = [] -_name_map = None - @staticmethod def get_all_kinds(): """Return all CursorKind enumeration instances.""" -return [x for x in CursorKind._kinds if not x is None] +return list(CursorKind) def is_declaration(self): """Test if this is a declaration kind.""" @@ -710,822 +681,820 @@ def is_unexposed(self): """Test if this is an unexposed kind.""" return conf.lib.clang_isUnexposed(self) -def __repr__(self): -return "CursorKind.%s" % (self.name,) - -### -# Declaration Kinds +### +# Declaration Kinds -# A declaration whose specific kind is not exposed via this interface. -# -# Unexposed declarations have the same operations as any other kind of -# declaration; one can extract their location information, spelling, find their -# definitions, etc. However, the specific kind of the declaration is not -# reported. -CursorKind.UNEXPOSED_DECL = CursorKind(1) +# A declaration whose specific kind is not exposed via this interface. +# +# Unexposed declarations have the same operations as any other kind of +# declaration; one can extract their location information, spelling, find +# their definitions, etc. However, the specific kind of the declaration is +# not reported. +UNEXPOSED_DECL = 1 -# A C or C++ struct. -CursorKind.STRUCT_DECL = CursorKind(2) +# A C or C++ struct. +STRUCT_DECL = 2 -# A C or C++ union. -CursorKind.UNION_DECL = CursorKind(3) +# A C or C++ union. +UNION_DECL = 3 -# A C++ class. -CursorKind.CLASS_DECL = CursorKind(4) +# A C++ class. +CLASS_DECL = 4 -# An enumeration. -CursorKind.ENUM_DECL = CursorKind(5) +# An enumeration. +ENUM_DECL = 5 -# A field (in C) or non-static data member (in C++) in a struct, union, or C++ -# class. -CursorKind.FIELD_DECL = CursorKind(6) +# A field (in C) or non-static data member (in C++) in a struct, union, or +# C++ class.
[clang] [libclang/python] Refactor enum usage (PR #95608)
@@ -611,51 +612,25 @@ def register(value, name): ### Cursor Kinds ### -class BaseEnumeration: +class BaseEnumeration(Enum): """ Common base class for named enumerations held in sync with Index.h values. - -Subclasses must define their own _kinds and _name_map members, as: -_kinds = [] -_name_map = None -These values hold the per-subclass instances and value-to-name mappings, -respectively. - """ -def __init__(self, value): -if value >= len(self.__class__._kinds): -self.__class__._kinds += [None] * (value - len(self.__class__._kinds) + 1) -if self.__class__._kinds[value] is not None: -raise ValueError( -"{0} value {1} already loaded".format(str(self.__class__), value) -) -self.value = value -self.__class__._kinds[value] = self -self.__class__._name_map = None def from_param(self): return self.value -@property -def name(self): -"""Get the enumeration name of this cursor kind.""" -if self._name_map is None: -self._name_map = {} -for key, value in self.__class__.__dict__.items(): -if isinstance(value, self.__class__): -self._name_map[value] = key -return self._name_map[self] - @classmethod def from_id(cls, id): -if id < 0 or id >= len(cls._kinds) or cls._kinds[id] is None: -raise ValueError("Unknown template argument kind %d" % id) -return cls._kinds[id] +try: +return cls(id) +except ValueError: +raise ValueError("Unknown %s %d" % (cls.__name__, id)) from None DeinAlptraum wrote: Thank you for the feedback! I've removed the `try`-`except` block now so we're just using the `Enum` error message Irrelevant now, but regarding `from None`: This effectively removes the previous exception context. Since we are re-raising an exception here, we would get both the exception we raised ourselves _and_ the exception that we caught here. E.g. currently we get ``` >>> cindex.TokenKind.from_id(5) Traceback (most recent call last): File "", line 1, in File "/data/shared/programming/repos/llvm-project/clang/bindings/python/clang/cindex.py", line 589, in from_id raise ValueError("Unknown %s %d" % (cls.__name__, id)) from None ValueError: Unknown TokenKind 5 ``` and without the `from None` we would get ``` >>> cindex.TokenKind.from_id(5) Traceback (most recent call last): File "/data/shared/programming/repos/llvm-project/clang/bindings/python/clang/cindex.py", line 587, in from_id return cls(id) ^^^ File "/usr/lib/python3.12/enum.py", line 757, in __call__ return cls.__new__(cls, value) ^^^ File "/usr/lib/python3.12/enum.py", line 1171, in __new__ raise ve_exc ValueError: 5 is not a valid TokenKind During handling of the above exception, another exception occurred: Traceback (most recent call last): File "", line 1, in File "/data/shared/programming/repos/llvm-project/clang/bindings/python/clang/cindex.py", line 589, in from_id raise ValueError("Unknown %s %d" % (cls.__name__, id)) ValueError: Unknown TokenKind 5 ``` https://github.com/llvm/llvm-project/pull/95608 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Implement function pointer type discrimination (PR #96992)
kovdan01 wrote: @ahatanak It would be nice if you explicitly mention the flag name `-fptrauth-function-pointer-type-discrimination` in commit message - I think it might be useful when grepping output of git log. https://github.com/llvm/llvm-project/pull/96992 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][driver] Fix -print-libgcc-file-name on Darwin platforms (PR #98325)
https://github.com/Xazax-hun updated https://github.com/llvm/llvm-project/pull/98325 From 9f3c99e278193af99d6a8928612f517be95aa6a6 Mon Sep 17 00:00:00 2001 From: Gabor Horvath Date: Mon, 8 Jul 2024 11:18:02 +0100 Subject: [PATCH] Fix --print-libgcc-file-name on Darwin platforms On Darwin, --print-libgcc-file-name was returning a nonsensical result. It would return the name of the library that would be used by the default toolchain implementation, but that was something that didn't exist on Darwin. Fixing this requires initializing the Darwin toolchain before processing `--print-libgcc-file-name`. Previously, the Darwin toolchain would only be initialized when building the jobs for this compilation, which is too late since `--print-libgcc-file-name` requires the toolchain to be initialized in order to provide the right results. rdar://90633749 --- clang/include/clang/Driver/Driver.h | 5 +- clang/lib/Driver/Driver.cpp | 8 +- clang/lib/Driver/ToolChains/Darwin.cpp| 65 - clang/lib/Driver/ToolChains/Darwin.h | 13 +++ .../darwin-embedded-print-libgcc-file-name.c | 27 ++ .../Driver/darwin-print-libgcc-file-name.c| 91 +++ 6 files changed, 185 insertions(+), 24 deletions(-) create mode 100644 clang/test/Driver/darwin-embedded-print-libgcc-file-name.c create mode 100644 clang/test/Driver/darwin-print-libgcc-file-name.c diff --git a/clang/include/clang/Driver/Driver.h b/clang/include/clang/Driver/Driver.h index cc1538372d5f8..04b46782467d6 100644 --- a/clang/include/clang/Driver/Driver.h +++ b/clang/include/clang/Driver/Driver.h @@ -628,8 +628,9 @@ class Driver { /// treated before building actions or binding tools. /// /// \return Whether any compilation should be built for this - /// invocation. - bool HandleImmediateArgs(const Compilation &C); + /// invocation. The compilation can only be modified when + /// this function returns false. + bool HandleImmediateArgs(Compilation &C); /// ConstructAction - Construct the appropriate action to do for /// \p Phase on the \p Input, taking in to account arguments diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 221e222bdd47d..cb1bc7e36d39d 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -2128,7 +2128,7 @@ void Driver::HandleAutocompletions(StringRef PassedFlags) const { llvm::outs() << llvm::join(SuggestedCompletions, "\n") << '\n'; } -bool Driver::HandleImmediateArgs(const Compilation &C) { +bool Driver::HandleImmediateArgs(Compilation &C) { // The order these options are handled in gcc is all over the place, but we // don't expect inconsistencies w.r.t. that to matter in practice. @@ -2271,6 +2271,12 @@ bool Driver::HandleImmediateArgs(const Compilation &C) { if (C.getArgs().hasArg(options::OPT_print_libgcc_file_name)) { ToolChain::RuntimeLibType RLT = TC.GetRuntimeLibType(C.getArgs()); const llvm::Triple Triple(TC.ComputeEffectiveClangTriple(C.getArgs())); +// The 'Darwin' toolchain is initialized only when its arguments are +// computed. Get the default arguments for OFK_None to ensure that +// initialization is performed before trying to access properties of +// the toolchain in the functions below. +// FIXME: Remove when darwin's toolchain is initialized during construction. +C.getArgsForToolChain(&TC, Triple.getArchName(), Action::OFK_None); RegisterEffectiveTriple TripleRAII(TC, Triple); switch (RLT) { case ToolChain::RLT_CompilerRT: diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp index f354b0974d5f2..c6f9d7beffb1d 100644 --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -1272,23 +1272,8 @@ unsigned DarwinClang::GetDefaultDwarfVersion() const { void MachO::AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs, StringRef Component, RuntimeLinkOptions Opts, bool IsShared) const { - SmallString<64> DarwinLibName = StringRef("libclang_rt."); - // On Darwin the builtins component is not in the library name. - if (Component != "builtins") { -DarwinLibName += Component; -if (!(Opts & RLO_IsEmbedded)) - DarwinLibName += "_"; - } - - DarwinLibName += getOSLibraryNameSuffix(); - DarwinLibName += IsShared ? "_dynamic.dylib" : ".a"; - SmallString<128> Dir(getDriver().ResourceDir); - llvm::sys::path::append(Dir, "lib", "darwin"); - if (Opts & RLO_IsEmbedded) -llvm::sys::path::append(Dir, "macho_embedded"); - - SmallString<128> P(Dir); - llvm::sys::path::append(P, DarwinLibName); + std::string P = getCompilerRT( + Args, Component, IsShared ? ToolChain::FT_Shared : ToolChain::FT_Static); // For now, allow missing resource libraries to support developers who may // not have compiler-rt checked out or integrated into their build (unless @@
[clang] [clang][driver] Fix -print-libgcc-file-name on Darwin platforms (PR #98325)
@@ -2230,6 +2239,7 @@ bool Driver::HandleImmediateArgs(const Compilation &C) { } if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) { +initDarwinTarget(); Xazax-hun wrote: I removed this change for now because I think we should probably fix this separately. Only adding the early init did not change the behavior for the cases we are interested in. https://github.com/llvm/llvm-project/pull/98325 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AArch64] Implement GCS ACLE intrinsics (PR #96903)
https://github.com/john-brawn-arm updated https://github.com/llvm/llvm-project/pull/96903 >From 123ebe17131fcfc7662be6759327b311e90fb16d Mon Sep 17 00:00:00 2001 From: John Brawn Date: Tue, 25 Jun 2024 15:35:18 +0100 Subject: [PATCH 1/3] [AArch64] Implement GCS ACLE intrinsics This adds intrinsics defined in ARM-software/acle#260 Doing this requires some changes to the GCS instruction definitions, as these intrinsics make use of how some instructions don't modify the input register when GCS is disabled, and they need to be correctly marked with mayLoad/mayStore/hasSideEffects for instruction selection to work. --- clang/include/clang/Basic/BuiltinsAArch64.def | 6 ++ clang/lib/Headers/arm_acle.h | 27 + clang/test/CodeGen/aarch64-gcs.c | 57 +++ llvm/include/llvm/IR/IntrinsicsAArch64.td | 17 ++ llvm/lib/Target/AArch64/AArch64InstrInfo.td | 22 +-- llvm/test/CodeGen/AArch64/gcs-intrinsics.ll | 49 6 files changed, 173 insertions(+), 5 deletions(-) create mode 100644 clang/test/CodeGen/aarch64-gcs.c create mode 100644 llvm/test/CodeGen/AArch64/gcs-intrinsics.ll diff --git a/clang/include/clang/Basic/BuiltinsAArch64.def b/clang/include/clang/Basic/BuiltinsAArch64.def index 5fb199b1b2b03..8c48437e86315 100644 --- a/clang/include/clang/Basic/BuiltinsAArch64.def +++ b/clang/include/clang/Basic/BuiltinsAArch64.def @@ -49,6 +49,7 @@ BUILTIN(__builtin_arm_wfe, "v", "") BUILTIN(__builtin_arm_wfi, "v", "") BUILTIN(__builtin_arm_sev, "v", "") BUILTIN(__builtin_arm_sevl, "v", "") +BUILTIN(__builtin_arm_chkfeat, "WUiWUi", "") // Like __builtin_trap but provide an 16-bit immediate reason code (which goes into `brk #N`). BUILTIN(__builtin_arm_trap, "vUIs", "nr") @@ -136,6 +137,11 @@ TARGET_BUILTIN(__builtin_arm_st64b, "vv*WUiC*", "n", "ls64") TARGET_BUILTIN(__builtin_arm_st64bv, "WUiv*WUiC*", "n", "ls64") TARGET_BUILTIN(__builtin_arm_st64bv0, "WUiv*WUiC*", "n", "ls64") +// Armv9.3-A Guarded Control Stack +TARGET_BUILTIN(__builtin_arm_gcspopm, "WUiWUi", "n", "gcs") +TARGET_BUILTIN(__builtin_arm_gcsss1, "vvC*", "n", "gcs") +TARGET_BUILTIN(__builtin_arm_gcsss2, "vC*vC*", "n", "gcs") + TARGET_HEADER_BUILTIN(_BitScanForward, "UcUNi*UNi", "nh", INTRIN_H, ALL_MS_LANGUAGES, "") TARGET_HEADER_BUILTIN(_BitScanReverse, "UcUNi*UNi", "nh", INTRIN_H, ALL_MS_LANGUAGES, "") TARGET_HEADER_BUILTIN(_BitScanForward64, "UcUNi*ULLi", "nh", INTRIN_H, ALL_MS_LANGUAGES, "") diff --git a/clang/lib/Headers/arm_acle.h b/clang/lib/Headers/arm_acle.h index 5785954c9171a..4d3e8a30013cd 100644 --- a/clang/lib/Headers/arm_acle.h +++ b/clang/lib/Headers/arm_acle.h @@ -75,6 +75,14 @@ static __inline__ void __attribute__((__always_inline__, __nodebug__)) __yield(v #define __dbg(t) __builtin_arm_dbg(t) #endif +#if defined(__ARM_64BIT_STATE) && __ARM_64BIT_STATE +#define _CHKFEAT_GCS 1 +static __inline__ uint64_t __attribute__((__always_inline__, __nodebug__)) +__chkfeat(uint64_t __features) { + return __builtin_arm_chkfeat(__features) ^ __features; +} +#endif + /* 7.5 Swap */ static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__)) __swp(uint32_t __x, volatile uint32_t *__p) { @@ -855,6 +863,25 @@ __rndrrs(uint64_t *__p) { } #endif +/* 11.2 Guarded Control Stack intrinsics */ +#if defined(__ARM_64BIT_STATE) && __ARM_64BIT_STATE +static __inline__ void * __attribute__((__always_inline__, __nodebug__)) +__gcspr() { + return (void *)__builtin_arm_rsr64("gcspr_el0"); +} + +static __inline__ uint64_t __attribute__((__always_inline__, __nodebug__, target("gcs"))) +__gcspopm() { + return __builtin_arm_gcspopm(0); +} + +static __inline__ const void * __attribute__((__always_inline__, __nodebug__, target("gcs"))) +__gcsss(const void *__stack) { + __builtin_arm_gcsss1(__stack); + return __builtin_arm_gcsss2(0); +} +#endif + #if defined(__cplusplus) } #endif diff --git a/clang/test/CodeGen/aarch64-gcs.c b/clang/test/CodeGen/aarch64-gcs.c new file mode 100644 index 0..e19946cf72f7f --- /dev/null +++ b/clang/test/CodeGen/aarch64-gcs.c @@ -0,0 +1,57 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 2 +// RUN: %clang_cc1 -triple aarch64-eabi -target-feature +gcs -emit-llvm %s -o - | FileCheck %s + +#include + +// CHECK-LABEL: define dso_local i64 @test_chkfeat +// CHECK-SAME: () #[[ATTR0:[0-9]+]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[__FEATURES_ADDR_I:%.*]] = alloca i64, align 8 +// CHECK-NEXT:store i64 1, ptr [[__FEATURES_ADDR_I]], align 8 +// CHECK-NEXT:[[TMP0:%.*]] = load i64, ptr [[__FEATURES_ADDR_I]], align 8 +// CHECK-NEXT:[[TMP1:%.*]] = call i64 @llvm.aarch64.chkfeat(i64 [[TMP0]]) +// CHECK-NEXT:[[TMP2:%.*]] = load i64, ptr [[__FEATURES_ADDR_I]], align 8 +// CHECK-NEXT:[[XOR_I:%.*]] = xor i64 [[TMP1]], [[TMP2]] +// CHECK-NEXT:ret i64 [[XOR_I]] +// +uint64_t test_chkfeat() { + return __chkfeat(_CHKFEAT_GCS); +}
[clang] [llvm] [AArch64] Implement GCS ACLE intrinsics (PR #96903)
john-brawn-arm wrote: I've added a new change to work around a problem in intrinsic handling that's detailed in https://discourse.llvm.org/t/intrinsic-with-sideeffect-is-optimized-out/66053 (I previously had this workaround in, but removed it because it looked like it was no longer needed, but actually I just hadn't tested it enough). https://github.com/llvm/llvm-project/pull/96903 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Ignore requires expr in bugprone-assignment-in-if-condition (PR #98079)
https://github.com/njames93 approved this pull request. https://github.com/llvm/llvm-project/pull/98079 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AArch64] Implement GCS ACLE intrinsics (PR #96903)
john-brawn-arm wrote: > Thanks, LGTM. > > As a follow-up, can you check that the instructions generated from this > builtin do inhibit the machine outliner? Maybe all GCS-modifying functions > have to inhibit the machine outliner, I'm not 100% sure. The GCS instructions don't inhibit the machine outliner, but I don't think the machine outliner is a problem. From the perspective of what instructions get executed the only difference when things get outlined is that there's an extra (non-bl) branch instruction, and that won't do anything to the gcs stack. https://github.com/llvm/llvm-project/pull/96903 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-doc] Improve performance by adding a short circuit (PR #96809)
PeterChou1 wrote: Ok nevermind, disregard the above comment I was wrong about the mechanism of the bug. the source of this bug comes from the way clang-doc handles C code, particularly anonymous typedef in C. When clang-doc encounters an anonymous typedef in C it incorrectly serializes its a name as a simple example running clang-doc on this file test.c ``` /** * Foo anon typedef */ typedef struct {} Foo; ``` running this file with clang-doc will interpret Foo as @nonymous_record_XXX. The reason why that is because when checking anonymous typedef name we're explicitly casting it to a CXXDecl see code [here](https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-doc/Serialize.cpp#L664). This becomes a problem when we run the LLVM compilation database. As an example a record that we were not properly serializing before was LLVMOrcCDependenceMapPair. When clang-doc runs the compilation database of LLVM it encounters code running under example code OrcV2CBindingsRemovableCode.c. This file causes recursiveASTVisitor to visit LLVMOrcCDependenceMapPair but because its c code its name is not found and it is incorrectly serialized into @nonymous_record_X. Normally this is not an issue for clang-doc since we'll visit the record multiple times and the next time we visit it clang-doc will correctly fill in the name of the declaration. But this patch changes that behaviour since we're only visiting the a typedef declaration at most once we now incorrectly serialized what was LLVMOrcCDependenceMapPair to @nonymous_record_X https://github.com/llvm/llvm-project/pull/96809 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Extend lifetime bound analysis to support assignments (PR #96475)
zmodem wrote: We're seeing some -Wdangling-assignment warnings after this change, and they all seem to be false positives so far: https://crbug.com/350808950 It's not a huge deal if there are just a few, but figured it's worth mentioning. https://github.com/llvm/llvm-project/pull/96475 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AARCH64][SVE] Add intrinsics for SVE LUTI instructions (PR #97058)
https://github.com/Lukacma updated https://github.com/llvm/llvm-project/pull/97058 >From 4a6c4033f7deddcd4094ebde81402960de85bd80 Mon Sep 17 00:00:00 2001 From: Marian Lukac Date: Fri, 28 Jun 2024 10:13:16 + Subject: [PATCH 1/3] [AARCH64][SVE] Add intrinsics for SVE LUTI instructions --- clang/include/clang/Basic/arm_sve.td | 21 +- .../aarch64-sve2-intrinsics/acle_sve2_luti.c | 336 ++ .../acle_sve2_imm_lane.cpp| 32 ++ llvm/include/llvm/IR/IntrinsicsAArch64.td | 20 ++ llvm/lib/Target/AArch64/SVEInstrFormats.td| 37 +- .../CodeGen/AArch64/sve2-intrinsics-luti.ll | 107 ++ 6 files changed, 551 insertions(+), 2 deletions(-) create mode 100644 clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_luti.c create mode 100644 llvm/test/CodeGen/AArch64/sve2-intrinsics-luti.ll diff --git a/clang/include/clang/Basic/arm_sve.td b/clang/include/clang/Basic/arm_sve.td index 94c093d891156..dc999a5bbb3d8 100644 --- a/clang/include/clang/Basic/arm_sve.td +++ b/clang/include/clang/Basic/arm_sve.td @@ -1939,6 +1939,25 @@ def SVTBL2_BF16 : SInst<"svtbl2[_{d}]", "d2u", "b", MergeNone, "", [VerifyRunti def SVTBX_BF16 : SInst<"svtbx[_{d}]", "dddu", "b", MergeNone, "aarch64_sve_tbx", [VerifyRuntimeMode]>; } + + +// SVE2 - Lookup table +let SVETargetGuard = "sve2,lut", SMETargetGuard = "sme2,lut" in { + def SVLUTI2_B : SInst<"svluti2_lane[_{d}]", "dd[i", "cUc", MergeNone, "aarch64_sve_luti2_lane", [VerifyRuntimeMode], [ImmCheck<2, ImmCheck0_3>]>; + def SVLUTI2_H : SInst<"svluti2_lane[_{d}]", "dd[i", "sUsh", MergeNone, "aarch64_sve_luti2_lane", [VerifyRuntimeMode], [ImmCheck<2, ImmCheck0_7>]>; + + def SVLUTI4_B : SInst<"svluti4_lane[_{d}]", "dd[i", "cUc", MergeNone, "aarch64_sve_luti4_lane", [VerifyRuntimeMode], [ImmCheck<2, ImmCheck0_1>]>; + def SVLUTI4_H : SInst<"svluti4_lane[_{d}]", "dd[i", "sUsh", MergeNone, "aarch64_sve_luti4_lane", [VerifyRuntimeMode], [ImmCheck<2, ImmCheck0_3>]>; + + def SVLUTI4_x2 : SInst<"svluti4_lane[_{d}]_x2", "d2.d[i", "sUsh", MergeNone, "aarch64_sve_luti4_lane_x2", [VerifyRuntimeMode], [ImmCheck<2, ImmCheck0_3>]>; +} + +let SVETargetGuard = "sve2,lut,bf16", SMETargetGuard = "sme2,lut,bf16" in { + def SVLUTI2_BF16 : SInst<"svluti2_lane[_{d}]", "dd[i", "b", MergeNone, "aarch64_sve_luti2_lane", [ VerifyRuntimeMode], [ImmCheck<2, ImmCheck0_7>]>; + def SVLUTI4_BF16 : SInst<"svluti4_lane[_{d}]", "dd[i", "b", MergeNone, "aarch64_sve_luti4_lane", [ VerifyRuntimeMode], [ImmCheck<2, ImmCheck0_3>]>; + def SVLUTI4_BF16_x2 : SInst<"svluti4_lane[_{d}]_x2", "d2.d[i", "b", MergeNone, "aarch64_sve_luti4_lane_x2", [ VerifyRuntimeMode], [ImmCheck<2, ImmCheck0_3>]>; +} + // SVE2 - Optional @@ -2384,4 +2403,4 @@ let SVETargetGuard = "sve2p1", SMETargetGuard = "sme2" in { def SVBFMLSLB_LANE : SInst<"svbfmlslb_lane[_{d}]", "dd$$i", "f", MergeNone, "aarch64_sve_bfmlslb_lane", [IsOverloadNone, VerifyRuntimeMode], [ImmCheck<3, ImmCheck0_7>]>; def SVBFMLSLT_LANE : SInst<"svbfmlslt_lane[_{d}]", "dd$$i", "f", MergeNone, "aarch64_sve_bfmlslt_lane", [IsOverloadNone, VerifyRuntimeMode], [ImmCheck<3, ImmCheck0_7>]>; -} +} \ No newline at end of file diff --git a/clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_luti.c b/clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_luti.c new file mode 100644 index 0..d19246cba2d37 --- /dev/null +++ b/clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_luti.c @@ -0,0 +1,336 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py +// REQUIRES: aarch64-registered-target +// RUN: %clang_cc1 -fclang-abi-compat=latest -triple aarch64-none-linux-gnu \ +// RUN: -target-feature +sme -target-feature +sme2 -target-feature +lut -target-feature +bf16 -O1 -Werror -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -fclang-abi-compat=latest -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu \ +// RUN: -target-feature +sve -target-feature +sve2 -target-feature +lut -target-feature +bf16 -O1 -Werror -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -fclang-abi-compat=latest -triple aarch64-none-linux-gnu \ +// RUN: -target-feature +sve -target-feature +sve2 -target-feature +lut -target-feature +bf16 -O1 -Werror -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefix=CPP-CHECK +// RUN: %clang_cc1 -fclang-abi-compat=latest -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu \ +// RUN: -target-feature +sve -target-feature +sve2 -target-feature +lut -target-feature +bf16 -O1 -Werror -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefix=CPP-CHECK +#include + +#if defined __ARM_FEATURE_SME +#define MODE_ATTR __arm_streaming +#else +#define MODE_ATTR +#endif + +#ifdef SVE_OVERLOADED_FORMS +// A simple used,unused... macro, long enough to represent any SVE builtin. +#d
[clang] [llvm] [AARCH64][SVE] Add intrinsics for SVE LUTI instructions (PR #97058)
@@ -10349,6 +10349,16 @@ multiclass sve2_luti2_vector_index { let Inst{23-22} = idx{2-1}; let Inst{12}= idx{0}; } + Lukacma wrote: Done https://github.com/llvm/llvm-project/pull/97058 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Emit bad shift warnings (PR #70307)
AaronBallman wrote: @budimirarandjelovicsyrmia -- do you need someone to land these changes on your behalf? https://github.com/llvm/llvm-project/pull/70307 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Extend lifetime bound analysis to support assignments (PR #96475)
hokein wrote: > We're seeing some -Wdangling-assignment warnings after this change, and they > all seem to be false positives so far: https://crbug.com/350808950 It's not a > huge deal if there are just a few, but figured it's worth mentioning. Thanks for the report. That's interesting. Technically it is a dangling assignment. The tricky bit is that the pointer being assigned is in a system header (implementation details of the system macro `A2CW`). Clang by default [suppresses diagnostics](https://clang.llvm.org/docs/UsersManual.html#controlling-diagnostics-in-system-headers) in system headers, but we emit this diagnostic on the temporary object (which is in user code), so it is not suppressed. I ran the diagnostic on the Google internal codebase, and I haven't found false positives so far. The only interesting case is [this issue](https://github.com/llvm/llvm-project/issues/97471), but that is a rare case where we should adjust the code. So, I believe there should not be many cases like this. https://github.com/llvm/llvm-project/pull/96475 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AArch64] Implement GCS ACLE intrinsics (PR #96903)
https://github.com/lenary approved this pull request. LGTM. https://github.com/llvm/llvm-project/pull/96903 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] fix bug that undefined internal is a warning only for -pedantic-errors (PR #98016)
AaronBallman wrote: > For the other two I had something similar but that still misses this point: > — part of the expression in a generic association that is not the result > expression of its generic > selection > But that might also be because I don't understand this point well enough. I > don't see which expression is there that is not the controlling expression > and not a result expression. Given: `_Generic(foo, bar : baz)`, `foo` is the controlling expression, `bar` is the generic association, and assuming `foo` is of type `bar`, then `baz` is the result expression of the generic selection. https://github.com/llvm/llvm-project/pull/98016 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Fix safestack -u ordering (PR #98468)
https://github.com/rorth created https://github.com/llvm/llvm-project/pull/98468 When re-enabling safestack testing on Solaris after the unexplained b0260c5b1052f8e3ff1ec77dc42a11f42da762cc, all tests `FAIL`ed to link: ``` Undefined first referenced symbol in file __safestack_unsafe_stack_ptrbuffer-copy-vla.o __safestack_init(command line) ld: fatal: symbol referencing errors ``` The problem is that `-u __safestack_init` was passed to the linker after the corresponding version of `libclang_rt.safestack-*.a`. Since the Solaris linker (like Unix linkers for decades) respects the command line argument order (unlike e.g. GNU ld which uses GNU getopt), this cannot work. Fixed by moving the `-u` arg further to the front. Two affected testcases were fixed accordingly. Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, `x86_64-pc-linux-gnu`, and `sparc64-unknown-linux-gnu`. >From 88dfd3a550b50333d782a192c19a1e5418ecdf6d Mon Sep 17 00:00:00 2001 From: Rainer Orth Date: Thu, 11 Jul 2024 13:41:01 +0200 Subject: [PATCH] [clang][Driver] Fix safestack -u ordering When re-enabling safestack testing on Solaris after the unexplained b0260c5b1052f8e3ff1ec77dc42a11f42da762cc, all tests `FAIL`ed to link: ``` Undefined first referenced symbol in file __safestack_unsafe_stack_ptrbuffer-copy-vla.o __safestack_init(command line) ld: fatal: symbol referencing errors ``` The problem is that `-u __safestack_init` was passed to the linker after the corresponding version of `libclang_rt.safestack-*.a`. Since the Solaris linker (like Unix linkers for decades) respects the command line argument order (unlike e.g. GNU ld which uses GNU getopt), this cannot work. Fixed by moving the `-u` arg further to the front. Two affected testcases were fixed accordingly. Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, `x86_64-pc-linux-gnu`, and `sparc64-unknown-linux-gnu`. --- clang/lib/Driver/ToolChains/CommonArgs.cpp | 10 ++ clang/test/Driver/ohos.c | 2 +- clang/test/Driver/sanitizer-ld.c | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 80a2b2bf31183..019df16a909f4 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -1534,6 +1534,12 @@ bool tools::addSanitizerRuntimes(const ToolChain &TC, const ArgList &Args, RequiredSymbols); } + // -u options must be added before the runtime libs that resolve them. + for (auto S : RequiredSymbols) { +CmdArgs.push_back("-u"); +CmdArgs.push_back(Args.MakeArgString(S)); + } + // Inject libfuzzer dependencies. if (SanArgs.needsFuzzer() && SanArgs.linkRuntimes() && !Args.hasArg(options::OPT_shared)) { @@ -1566,10 +1572,6 @@ bool tools::addSanitizerRuntimes(const ToolChain &TC, const ArgList &Args, addSanitizerRuntime(TC, Args, CmdArgs, RT, false, false); AddExportDynamic |= !addSanitizerDynamicList(TC, Args, CmdArgs, RT); } - for (auto S : RequiredSymbols) { -CmdArgs.push_back("-u"); -CmdArgs.push_back(Args.MakeArgString(S)); - } // If there is a static runtime with no dynamic list, force all the symbols // to be dynamic to be sure we export sanitizer interface functions. if (AddExportDynamic) diff --git a/clang/test/Driver/ohos.c b/clang/test/Driver/ohos.c index b1ce61e7227b6..8de4e6de57f7f 100644 --- a/clang/test/Driver/ohos.c +++ b/clang/test/Driver/ohos.c @@ -95,8 +95,8 @@ // RUN: | FileCheck %s -check-prefix=CHECK-SAFESTACK // CHECK-SAFESTACK: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]" // CHECK-SAFESTACK: "-fsanitize=safe-stack" -// CHECK-SAFESTACK: "[[RESOURCE_DIR]]{{/|}}lib{{/|}}arm-liteos-ohos{{/|}}libclang_rt.safestack.a" // CHECK-SAFESTACK: "__safestack_init" +// CHECK-SAFESTACK: "[[RESOURCE_DIR]]{{/|}}lib{{/|}}arm-liteos-ohos{{/|}}libclang_rt.safestack.a" // RUN: %clang %s -### --target=arm-liteos \ // RUN: -fsanitize=address 2>&1 \ diff --git a/clang/test/Driver/sanitizer-ld.c b/clang/test/Driver/sanitizer-ld.c index 48e4ea1f7dcb5..c83066a334001 100644 --- a/clang/test/Driver/sanitizer-ld.c +++ b/clang/test/Driver/sanitizer-ld.c @@ -753,8 +753,8 @@ // CHECK-SAFESTACK-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}" // CHECK-SAFESTACK-LINUX-NOT: "-lc" // CHECK-SAFESTACK-LINUX-NOT: whole-archive -// CHECK-SAFESTACK-LINUX: libclang_rt.safestack.a" // CHECK-SAFESTACK-LINUX: "-u" "__safestack_init" +// CHECK-SAFESTACK-LINUX: libclang_rt.safestack.a" // CHECK-SAFESTACK-LINUX: "-lpthread" // CHECK-SAFESTACK-LINUX: "-ldl" // CHECK-SAFESTACK-LINUX: "-lresolv" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://li
[clang] [clang][Driver] Fix safestack -u ordering (PR #98468)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Rainer Orth (rorth) Changes When re-enabling safestack testing on Solaris after the unexplained b0260c5b1052f8e3ff1ec77dc42a11f42da762cc, all tests `FAIL`ed to link: ``` Undefined first referenced symbol in file __safestack_unsafe_stack_ptrbuffer-copy-vla.o __safestack_init(command line) ld: fatal: symbol referencing errors ``` The problem is that `-u __safestack_init` was passed to the linker after the corresponding version of `libclang_rt.safestack-*.a`. Since the Solaris linker (like Unix linkers for decades) respects the command line argument order (unlike e.g. GNU ld which uses GNU getopt), this cannot work. Fixed by moving the `-u` arg further to the front. Two affected testcases were fixed accordingly. Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, `x86_64-pc-linux-gnu`, and `sparc64-unknown-linux-gnu`. --- Full diff: https://github.com/llvm/llvm-project/pull/98468.diff 3 Files Affected: - (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+6-4) - (modified) clang/test/Driver/ohos.c (+1-1) - (modified) clang/test/Driver/sanitizer-ld.c (+1-1) ``diff diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 80a2b2bf31183..019df16a909f4 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -1534,6 +1534,12 @@ bool tools::addSanitizerRuntimes(const ToolChain &TC, const ArgList &Args, RequiredSymbols); } + // -u options must be added before the runtime libs that resolve them. + for (auto S : RequiredSymbols) { +CmdArgs.push_back("-u"); +CmdArgs.push_back(Args.MakeArgString(S)); + } + // Inject libfuzzer dependencies. if (SanArgs.needsFuzzer() && SanArgs.linkRuntimes() && !Args.hasArg(options::OPT_shared)) { @@ -1566,10 +1572,6 @@ bool tools::addSanitizerRuntimes(const ToolChain &TC, const ArgList &Args, addSanitizerRuntime(TC, Args, CmdArgs, RT, false, false); AddExportDynamic |= !addSanitizerDynamicList(TC, Args, CmdArgs, RT); } - for (auto S : RequiredSymbols) { -CmdArgs.push_back("-u"); -CmdArgs.push_back(Args.MakeArgString(S)); - } // If there is a static runtime with no dynamic list, force all the symbols // to be dynamic to be sure we export sanitizer interface functions. if (AddExportDynamic) diff --git a/clang/test/Driver/ohos.c b/clang/test/Driver/ohos.c index b1ce61e7227b6..8de4e6de57f7f 100644 --- a/clang/test/Driver/ohos.c +++ b/clang/test/Driver/ohos.c @@ -95,8 +95,8 @@ // RUN: | FileCheck %s -check-prefix=CHECK-SAFESTACK // CHECK-SAFESTACK: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]" // CHECK-SAFESTACK: "-fsanitize=safe-stack" -// CHECK-SAFESTACK: "[[RESOURCE_DIR]]{{/|}}lib{{/|}}arm-liteos-ohos{{/|}}libclang_rt.safestack.a" // CHECK-SAFESTACK: "__safestack_init" +// CHECK-SAFESTACK: "[[RESOURCE_DIR]]{{/|}}lib{{/|}}arm-liteos-ohos{{/|}}libclang_rt.safestack.a" // RUN: %clang %s -### --target=arm-liteos \ // RUN: -fsanitize=address 2>&1 \ diff --git a/clang/test/Driver/sanitizer-ld.c b/clang/test/Driver/sanitizer-ld.c index 48e4ea1f7dcb5..c83066a334001 100644 --- a/clang/test/Driver/sanitizer-ld.c +++ b/clang/test/Driver/sanitizer-ld.c @@ -753,8 +753,8 @@ // CHECK-SAFESTACK-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}" // CHECK-SAFESTACK-LINUX-NOT: "-lc" // CHECK-SAFESTACK-LINUX-NOT: whole-archive -// CHECK-SAFESTACK-LINUX: libclang_rt.safestack.a" // CHECK-SAFESTACK-LINUX: "-u" "__safestack_init" +// CHECK-SAFESTACK-LINUX: libclang_rt.safestack.a" // CHECK-SAFESTACK-LINUX: "-lpthread" // CHECK-SAFESTACK-LINUX: "-ldl" // CHECK-SAFESTACK-LINUX: "-lresolv" `` https://github.com/llvm/llvm-project/pull/98468 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] fix bug that undefined internal is a warning only for -pedantic-errors (PR #98016)
ccrownhill wrote: Oh that makes sense so ``` static void f(); void *k = _Generic(&f, void (*)(void) : 0, default : f); ``` should be ok since it is not in the result expression? https://github.com/llvm/llvm-project/pull/98016 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Fix safestack -u ordering (PR #98468)
rorth wrote: This patch was already approved in [ [safestack] Various Solaris fixes #98001 ](https://github.com/llvm/llvm-project/pull/98001), therefore I'll commit it shortly. https://github.com/llvm/llvm-project/pull/98468 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][X86] Add __cpuidex function to cpuid.h (PR #97785)
https://github.com/mstorsjo approved this pull request. LGTM, let’s reland this https://github.com/llvm/llvm-project/pull/97785 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 0248b59 - [clang][Driver] Fix safestack -u ordering (#98468)
Author: Rainer Orth Date: 2024-07-11T14:04:45+02:00 New Revision: 0248b597b1442ba803b61ba1d099ec8ef3872b2d URL: https://github.com/llvm/llvm-project/commit/0248b597b1442ba803b61ba1d099ec8ef3872b2d DIFF: https://github.com/llvm/llvm-project/commit/0248b597b1442ba803b61ba1d099ec8ef3872b2d.diff LOG: [clang][Driver] Fix safestack -u ordering (#98468) When re-enabling safestack testing on Solaris after the unexplained b0260c5b1052f8e3ff1ec77dc42a11f42da762cc, all tests `FAIL`ed to link: ``` Undefined first referenced symbol in file __safestack_unsafe_stack_ptrbuffer-copy-vla.o __safestack_init(command line) ld: fatal: symbol referencing errors ``` The problem is that `-u __safestack_init` was passed to the linker after the corresponding version of `libclang_rt.safestack-*.a`. Since the Solaris linker (like Unix linkers for decades) respects the command line argument order (unlike e.g. GNU ld which uses GNU getopt), this cannot work. Fixed by moving the `-u` arg further to the front. Two affected testcases were fixed accordingly. Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, `x86_64-pc-linux-gnu`, and `sparc64-unknown-linux-gnu`. Added: Modified: clang/lib/Driver/ToolChains/CommonArgs.cpp clang/test/Driver/ohos.c clang/test/Driver/sanitizer-ld.c Removed: diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 80a2b2bf31183..019df16a909f4 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -1534,6 +1534,12 @@ bool tools::addSanitizerRuntimes(const ToolChain &TC, const ArgList &Args, RequiredSymbols); } + // -u options must be added before the runtime libs that resolve them. + for (auto S : RequiredSymbols) { +CmdArgs.push_back("-u"); +CmdArgs.push_back(Args.MakeArgString(S)); + } + // Inject libfuzzer dependencies. if (SanArgs.needsFuzzer() && SanArgs.linkRuntimes() && !Args.hasArg(options::OPT_shared)) { @@ -1566,10 +1572,6 @@ bool tools::addSanitizerRuntimes(const ToolChain &TC, const ArgList &Args, addSanitizerRuntime(TC, Args, CmdArgs, RT, false, false); AddExportDynamic |= !addSanitizerDynamicList(TC, Args, CmdArgs, RT); } - for (auto S : RequiredSymbols) { -CmdArgs.push_back("-u"); -CmdArgs.push_back(Args.MakeArgString(S)); - } // If there is a static runtime with no dynamic list, force all the symbols // to be dynamic to be sure we export sanitizer interface functions. if (AddExportDynamic) diff --git a/clang/test/Driver/ohos.c b/clang/test/Driver/ohos.c index b1ce61e7227b6..8de4e6de57f7f 100644 --- a/clang/test/Driver/ohos.c +++ b/clang/test/Driver/ohos.c @@ -95,8 +95,8 @@ // RUN: | FileCheck %s -check-prefix=CHECK-SAFESTACK // CHECK-SAFESTACK: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]" // CHECK-SAFESTACK: "-fsanitize=safe-stack" -// CHECK-SAFESTACK: "[[RESOURCE_DIR]]{{/|}}lib{{/|}}arm-liteos-ohos{{/|}}libclang_rt.safestack.a" // CHECK-SAFESTACK: "__safestack_init" +// CHECK-SAFESTACK: "[[RESOURCE_DIR]]{{/|}}lib{{/|}}arm-liteos-ohos{{/|}}libclang_rt.safestack.a" // RUN: %clang %s -### --target=arm-liteos \ // RUN: -fsanitize=address 2>&1 \ diff --git a/clang/test/Driver/sanitizer-ld.c b/clang/test/Driver/sanitizer-ld.c index 48e4ea1f7dcb5..c83066a334001 100644 --- a/clang/test/Driver/sanitizer-ld.c +++ b/clang/test/Driver/sanitizer-ld.c @@ -753,8 +753,8 @@ // CHECK-SAFESTACK-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}" // CHECK-SAFESTACK-LINUX-NOT: "-lc" // CHECK-SAFESTACK-LINUX-NOT: whole-archive -// CHECK-SAFESTACK-LINUX: libclang_rt.safestack.a" // CHECK-SAFESTACK-LINUX: "-u" "__safestack_init" +// CHECK-SAFESTACK-LINUX: libclang_rt.safestack.a" // CHECK-SAFESTACK-LINUX: "-lpthread" // CHECK-SAFESTACK-LINUX: "-ldl" // CHECK-SAFESTACK-LINUX: "-lresolv" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Fix safestack -u ordering (PR #98468)
https://github.com/rorth closed https://github.com/llvm/llvm-project/pull/98468 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Emit bad shift warnings (PR #70307)
budimirarandjelovicsyrmia wrote: > @budimirarandjelovicsyrmia -- do you need someone to land these changes on > your behalf? I don't understand question. I think that I answered correctly to previous comments. https://github.com/llvm/llvm-project/pull/70307 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] fix bug that undefined internal is a warning only for -pedantic-errors (PR #98016)
ccrownhill wrote: Sorry, my mistake. This doesn't work for `default` but the problem is that in this example ``` static void *f(void); void *k = _Generic(&f, void *(*)(void) : 0, int (*)(void) : f()); ``` the `undefined-internal` error is still raised even though it is not in the result expression anymore. https://github.com/llvm/llvm-project/pull/98016 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] fix bug that undefined internal is a warning only for -pedantic-errors (PR #98016)
https://github.com/AaronBallman commented: I think the test cases should all be combined into a single file -- we don't stop issuing diagnostics after the first one, so it should be fine to put them all together into one file. https://github.com/llvm/llvm-project/pull/98016 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits