[clang] [clang][test] Avoid writing to a potentially write-protected dir (PR #96457)
https://github.com/karka228 created https://github.com/llvm/llvm-project/pull/96457 The test clang/test/Preprocessor/embed_weird.cpp create a file directly in the Inputs dir in the llvm-project repo instead of the temporary directory. The llvm-project repo may be write protected e.g. in a sandboxed environment. This patch create a separate temporary directory where the the null_byte.bin file is created along with the rest of copies of the other embed-files needed for the testcase. >From abf92edafdaae4b8e39cd11f21c366b8c5afc0d0 Mon Sep 17 00:00:00 2001 From: Karl-Johan Karlsson Date: Mon, 24 Jun 2024 08:49:12 +0200 Subject: [PATCH] [clang][test] Avoid writing to a potentially write-protected dir The test clang/test/Preprocessor/embed_weird.cpp create a file directly in the Inputs dir in the llvm-project repo instead of the temporary directory. The llvm-project repo may be write protected e.g. in a sandboxed environment. This patch create a separate temporary directory where the the null_byte.bin file is created along with the rest of copies of the other embed-files needed for the testcase. --- clang/test/Preprocessor/embed_weird.cpp | 10 ++ 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/clang/test/Preprocessor/embed_weird.cpp b/clang/test/Preprocessor/embed_weird.cpp index a90d3bc330538..31b622c848d6a 100644 --- a/clang/test/Preprocessor/embed_weird.cpp +++ b/clang/test/Preprocessor/embed_weird.cpp @@ -1,7 +1,9 @@ -// RUN: printf "\0" > %S/Inputs/null_byte.bin -// RUN: %clang_cc1 %s -fsyntax-only --embed-dir=%S/Inputs -verify=expected,cxx -Wno-c23-extensions -// RUN: %clang_cc1 -x c -std=c23 %s -fsyntax-only --embed-dir=%S/Inputs -verify=expected,c -// RUN: rm %S/Inputs/null_byte.bin +// RUN: rm -rf %t && mkdir -p %t/media +// RUN: cp %S/Inputs/single_byte.txt %S/Inputs/jk.txt %S/Inputs/numbers.txt %t/ +// RUN: cp %S/Inputs/media/empty %t/media/ +// RUN: printf "\0" > %t/null_byte.bin +// RUN: %clang_cc1 %s -fsyntax-only --embed-dir=%t -verify=expected,cxx -Wno-c23-extensions +// RUN: %clang_cc1 -x c -std=c23 %s -fsyntax-only --embed-dir=%t -verify=expected,c #embed ; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] c43d5f5 - [clang][analyzer] Add notes to PointerSubChecker (#95899)
Author: Balázs Kéri Date: 2024-06-24T09:03:40+02:00 New Revision: c43d5f540fd43409e7997c9fec97a1d415855b7c URL: https://github.com/llvm/llvm-project/commit/c43d5f540fd43409e7997c9fec97a1d415855b7c DIFF: https://github.com/llvm/llvm-project/commit/c43d5f540fd43409e7997c9fec97a1d415855b7c.diff LOG: [clang][analyzer] Add notes to PointerSubChecker (#95899) Notes are added to indicate the array declarations of the arrays in a found invalid pointer subtraction. Added: clang/test/Analysis/pointer-sub-notes.c Modified: clang/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp clang/test/Analysis/casts.c clang/test/Analysis/pointer-sub.c Removed: diff --git a/clang/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp index b73534136fdf0..eea93a41f1384 100644 --- a/clang/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp @@ -43,8 +43,6 @@ class PointerSubChecker bool checkArrayBounds(CheckerContext &C, const Expr *E, const ElementRegion *ElemReg, const MemRegion *Reg) const; - void reportBug(CheckerContext &C, const Expr *E, - const llvm::StringLiteral &Msg) const; public: void checkPreStmt(const BinaryOperator *B, CheckerContext &C) const; @@ -57,6 +55,14 @@ bool PointerSubChecker::checkArrayBounds(CheckerContext &C, const Expr *E, if (!ElemReg) return true; + auto ReportBug = [&](const llvm::StringLiteral &Msg) { +if (ExplodedNode *N = C.generateNonFatalErrorNode()) { + auto R = std::make_unique(BT, Msg, N); + R->addRange(E->getSourceRange()); + C.emitReport(std::move(R)); +} + }; + ProgramStateRef State = C.getState(); const MemRegion *SuperReg = ElemReg->getSuperRegion(); SValBuilder &SVB = C.getSValBuilder(); @@ -64,7 +70,7 @@ bool PointerSubChecker::checkArrayBounds(CheckerContext &C, const Expr *E, if (SuperReg == Reg) { if (const llvm::APSInt *I = SVB.getKnownValue(State, ElemReg->getIndex()); I && (!I->isOne() && !I->isZero())) - reportBug(C, E, Msg_BadVarIndex); + ReportBug(Msg_BadVarIndex); return false; } @@ -77,7 +83,7 @@ bool PointerSubChecker::checkArrayBounds(CheckerContext &C, const Expr *E, ProgramStateRef S1, S2; std::tie(S1, S2) = C.getState()->assume(*IndexTooLarge); if (S1 && !S2) { - reportBug(C, E, Msg_LargeArrayIndex); + ReportBug(Msg_LargeArrayIndex); return false; } } @@ -89,22 +95,13 @@ bool PointerSubChecker::checkArrayBounds(CheckerContext &C, const Expr *E, ProgramStateRef S1, S2; std::tie(S1, S2) = State->assume(*IndexTooSmall); if (S1 && !S2) { - reportBug(C, E, Msg_NegativeArrayIndex); + ReportBug(Msg_NegativeArrayIndex); return false; } } return true; } -void PointerSubChecker::reportBug(CheckerContext &C, const Expr *E, - const llvm::StringLiteral &Msg) const { - if (ExplodedNode *N = C.generateNonFatalErrorNode()) { -auto R = std::make_unique(BT, Msg, N); -R->addRange(E->getSourceRange()); -C.emitReport(std::move(R)); - } -} - void PointerSubChecker::checkPreStmt(const BinaryOperator *B, CheckerContext &C) const { // When doing pointer subtraction, if the two pointers do not point to the @@ -136,6 +133,9 @@ void PointerSubChecker::checkPreStmt(const BinaryOperator *B, if (!checkArrayBounds(C, B->getRHS(), ElemRR, LR)) return; + const ValueDecl *DiffDeclL = nullptr; + const ValueDecl *DiffDeclR = nullptr; + if (ElemLR && ElemRR) { const MemRegion *SuperLR = ElemLR->getSuperRegion(); const MemRegion *SuperRR = ElemRR->getSuperRegion(); @@ -144,9 +144,30 @@ void PointerSubChecker::checkPreStmt(const BinaryOperator *B, // Allow arithmetic on diff erent symbolic regions. if (isa(SuperLR) || isa(SuperRR)) return; +if (const auto *SuperDLR = dyn_cast(SuperLR)) + DiffDeclL = SuperDLR->getDecl(); +if (const auto *SuperDRR = dyn_cast(SuperRR)) + DiffDeclR = SuperDRR->getDecl(); } - reportBug(C, B, Msg_MemRegionDifferent); + if (ExplodedNode *N = C.generateNonFatalErrorNode()) { +auto R = +std::make_unique(BT, Msg_MemRegionDifferent, N); +R->addRange(B->getSourceRange()); +// The declarations may be identical even if the regions are diff erent: +// struct { int array[10]; } a, b; +// do_something(&a.array[5] - &b.array[5]); +// In this case don't emit notes. +if (DiffDeclL != DiffDeclR) { + if (DiffDeclL) +R->addNote("Array at the left-hand side of subtraction", + {DiffDeclL, C.getSourceManager()}); + if (DiffDeclR) +R->addNote("Array at the right-hand side of subtraction", +
[clang] [clang][analyzer] Add notes to PointerSubChecker (PR #95899)
https://github.com/balazske closed https://github.com/llvm/llvm-project/pull/95899 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][test] Avoid writing to a potentially write-protected dir (PR #96457)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Karl-Johan Karlsson (karka228) Changes The test clang/test/Preprocessor/embed_weird.cpp create a file directly in the Inputs dir in the llvm-project repo instead of the temporary directory. The llvm-project repo may be write protected e.g. in a sandboxed environment. This patch create a separate temporary directory where the the null_byte.bin file is created along with the rest of copies of the other embed-files needed for the testcase. --- Full diff: https://github.com/llvm/llvm-project/pull/96457.diff 1 Files Affected: - (modified) clang/test/Preprocessor/embed_weird.cpp (+6-4) ``diff diff --git a/clang/test/Preprocessor/embed_weird.cpp b/clang/test/Preprocessor/embed_weird.cpp index a90d3bc330538..31b622c848d6a 100644 --- a/clang/test/Preprocessor/embed_weird.cpp +++ b/clang/test/Preprocessor/embed_weird.cpp @@ -1,7 +1,9 @@ -// RUN: printf "\0" > %S/Inputs/null_byte.bin -// RUN: %clang_cc1 %s -fsyntax-only --embed-dir=%S/Inputs -verify=expected,cxx -Wno-c23-extensions -// RUN: %clang_cc1 -x c -std=c23 %s -fsyntax-only --embed-dir=%S/Inputs -verify=expected,c -// RUN: rm %S/Inputs/null_byte.bin +// RUN: rm -rf %t && mkdir -p %t/media +// RUN: cp %S/Inputs/single_byte.txt %S/Inputs/jk.txt %S/Inputs/numbers.txt %t/ +// RUN: cp %S/Inputs/media/empty %t/media/ +// RUN: printf "\0" > %t/null_byte.bin +// RUN: %clang_cc1 %s -fsyntax-only --embed-dir=%t -verify=expected,cxx -Wno-c23-extensions +// RUN: %clang_cc1 -x c -std=c23 %s -fsyntax-only --embed-dir=%t -verify=expected,c #embed ; `` https://github.com/llvm/llvm-project/pull/96457 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 45a7af7 - [X86][Driver] Enable feature cf for -mapxf
Author: Shengchen Kan Date: 2024-06-24T15:11:07+08:00 New Revision: 45a7af7c993f66044a8492dce1d073380feafffc URL: https://github.com/llvm/llvm-project/commit/45a7af7c993f66044a8492dce1d073380feafffc DIFF: https://github.com/llvm/llvm-project/commit/45a7af7c993f66044a8492dce1d073380feafffc.diff LOG: [X86][Driver] Enable feature cf for -mapxf This is follow-up for #78901 after validation. Added: Modified: clang/include/clang/Driver/Options.td clang/lib/Basic/Targets/X86.cpp clang/test/Driver/x86-target-features.c clang/test/Preprocessor/x86_target_features.c Removed: diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index bbf860aa491e1..8f915eacdaf6b 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -6318,8 +6318,8 @@ def mapx_features_EQ : CommaJoined<["-"], "mapx-features=">, Group, Values<"egpr,push2pop2,ppx,ndd,ccmp,nf,cf">; // For stability, we only add a feature to -mapxf after it passes the validation of llvm-test-suite && cpu2017 on Intel SDE. -def mapxf : Flag<["-"], "mapxf">, Alias, AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","nf"]>; -def mno_apxf : Flag<["-"], "mno-apxf">, Alias, AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","nf"]>; +def mapxf : Flag<["-"], "mapxf">, Alias, AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","nf","cf"]>; +def mno_apxf : Flag<["-"], "mno-apxf">, Alias, AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","nf","cf"]>; def mapx_inline_asm_use_gpr32 : Flag<["-"], "mapx-inline-asm-use-gpr32">, Group, HelpText<"Enable use of GPR32 in inline assembly for APX">; } // let Flags = [TargetSpecific] diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp index 036a655a4d073..deb19f5f60c00 100644 --- a/clang/lib/Basic/Targets/X86.cpp +++ b/clang/lib/Basic/Targets/X86.cpp @@ -963,7 +963,7 @@ void X86TargetInfo::getTargetDefines(const LangOptions &Opts, if (HasCF) Builder.defineMacro("__CF__"); // Condition here is aligned with the feature set of mapxf in Options.td - if (HasEGPR && HasPush2Pop2 && HasPPX && HasNDD && HasCCMP && HasNF) + if (HasEGPR && HasPush2Pop2 && HasPPX && HasNDD && HasCCMP && HasNF && HasCF) Builder.defineMacro("__APX_F__"); if (HasEGPR && HasInlineAsmUseGPR32) Builder.defineMacro("__APX_INLINE_ASM_USE_GPR32__"); diff --git a/clang/test/Driver/x86-target-features.c b/clang/test/Driver/x86-target-features.c index 3022ed1250d59..c75ebd0e4b630 100644 --- a/clang/test/Driver/x86-target-features.c +++ b/clang/test/Driver/x86-target-features.c @@ -423,8 +423,8 @@ // RUN: %clang -target x86_64-unknown-linux-gnu -mno-apxf -mapxf %s -### -o %t.o 2>&1 | FileCheck -check-prefix=APXF %s // RUN: %clang -target x86_64-unknown-linux-gnu -mapxf -mno-apxf %s -### -o %t.o 2>&1 | FileCheck -check-prefix=NO-APXF %s // -// APXF: "-target-feature" "+egpr" "-target-feature" "+push2pop2" "-target-feature" "+ppx" "-target-feature" "+ndd" "-target-feature" "+ccmp" "-target-feature" "+nf" -// NO-APXF: "-target-feature" "-egpr" "-target-feature" "-push2pop2" "-target-feature" "-ppx" "-target-feature" "-ndd" "-target-feature" "-ccmp" "-target-feature" "-nf" +// APXF: "-target-feature" "+egpr" "-target-feature" "+push2pop2" "-target-feature" "+ppx" "-target-feature" "+ndd" "-target-feature" "+ccmp" "-target-feature" "+nf" "-target-feature" "+cf" +// NO-APXF: "-target-feature" "-egpr" "-target-feature" "-push2pop2" "-target-feature" "-ppx" "-target-feature" "-ndd" "-target-feature" "-ccmp" "-target-feature" "-nf" "-target-feature" "-cf" // RUN: %clang -target x86_64-unknown-linux-gnu -mapx-features=egpr %s -### -o %t.o 2>&1 | FileCheck -check-prefix=EGPR %s // RUN: %clang -target x86_64-unknown-linux-gnu -mapx-features=push2pop2 %s -### -o %t.o 2>&1 | FileCheck -check-prefix=PUSH2POP2 %s diff --git a/clang/test/Preprocessor/x86_target_features.c b/clang/test/Preprocessor/x86_target_features.c index 3e63e2c77fddf..a476f68527a24 100644 --- a/clang/test/Preprocessor/x86_target_features.c +++ b/clang/test/Preprocessor/x86_target_features.c @@ -754,7 +754,7 @@ // RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapx-features=ccmp -x c -E -dM -o - %s | FileCheck --check-prefix=CCMP %s // RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapx-features=nf -x c -E -dM -o - %s | FileCheck --check-prefix=NF %s // RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapx-features=cf -x c -E -dM -o - %s | FileCheck --check-prefix=CF %s -// RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapxf -x c -E -dM -o - %s | FileCheck --check-prefixes=EGPR,PUSH2POP2,PPX,NDD,CCMP,NF,APXF %s +// RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapxf -x c -E -dM -o - %s | FileCheck --check-prefixes=EGPR,PUSH2POP2,PPX,NDD,CCMP,NF,CF,APXF
[clang] [clang][test] Avoid writing to a potentially write-protected dir (PR #96457)
https://github.com/karka228 edited https://github.com/llvm/llvm-project/pull/96457 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [SourceManager] Expose max usage of source location space as a Statistic (PR #96292)
https://github.com/usx95 approved this pull request. LGTM. Please wait a couple of days before landing to give a chance to other folks for reviewing. https://github.com/llvm/llvm-project/pull/96292 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [SourceManager] Expose max usage of source location space as a Statistic (PR #96292)
https://github.com/usx95 edited https://github.com/llvm/llvm-project/pull/96292 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [SourceManager] Expose max usage of source location space as a Statistic (PR #96292)
@@ -46,6 +47,12 @@ using namespace clang; using namespace SrcMgr; using llvm::MemoryBuffer; +#define DEBUG_TYPE "source-manager" + +STATISTIC( +MaxUsedSLocBytes, +"Maximum number of bytes used by source locations (both loaded and local)"); usx95 wrote: nit: It may also be helpful to add some background on why this is important to track. https://github.com/llvm/llvm-project/pull/96292 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Add support for getHostCPUFeatures using hwprobe (PR #94352)
https://github.com/dtcxzyw updated https://github.com/llvm/llvm-project/pull/94352 >From ff839bef048a65760f4cd0e9abafe11cfebd9362 Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Tue, 4 Jun 2024 21:08:27 +0800 Subject: [PATCH 1/8] [RISCV] Add support for getHostCPUFeatures using hwprobe Co-authored-by: Yangyu Chen --- llvm/lib/TargetParser/Host.cpp | 68 ++ 1 file changed, 68 insertions(+) diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp index 68155acd9e5bc..b4a13b38eb380 100644 --- a/llvm/lib/TargetParser/Host.cpp +++ b/llvm/lib/TargetParser/Host.cpp @@ -1998,6 +1998,74 @@ bool sys::getHostCPUFeatures(StringMap &Features) { return true; } +#elif defined(__linux__) && defined(__riscv) +#ifdef __has_include +#if __has_include() +#include +#endif +#endif +bool sys::getHostCPUFeatures(StringMap &Features) { +#ifdef RISCV_HWPROBE_KEY_MVENDORID + riscv_hwprobe Query[2]{ + {RISCV_HWPROBE_KEY_IMA_EXT_0, 0}, + {RISCV_HWPROBE_KEY_CPUPERF_0, 0}, + }; + int Ret = syscall(/*__NR_riscv_hwprobe=*/258, /*pairs=*/&Query, +/*pair_count=*/1, /*cpu_count=*/0, /*cpus=*/0, /*flags=*/0); + if (Ret != 0) +return false; + + uint64_t ExtMask = Query[0].value; + Features["f"] = ExtMask & RISCV_HWPROBE_IMA_FD; + Features["d"] = ExtMask & RISCV_HWPROBE_IMA_FD; + Features["c"] = ExtMask & RISCV_HWPROBE_IMA_C; + Features["v"] = ExtMask & RISCV_HWPROBE_IMA_V; + Features["zba"] = ExtMask & RISCV_HWPROBE_IMA_ZBA; + Features["zbb"] = ExtMask & RISCV_HWPROBE_IMA_ZBB; + Features["zbs"] = ExtMask & RISCV_HWPROBE_IMA_ZBS; + Features["zicboz"] = ExtMask & RISCV_HWPROBE_IMA_ZICBOZ; + Features["zbc"] = ExtMask & RISCV_HWPROBE_IMA_ZBC; + Features["zbkb"] = ExtMask & RISCV_HWPROBE_IMA_ZBKB; + Features["zbkc"] = ExtMask & RISCV_HWPROBE_IMA_ZBKC; + Features["zbkx"] = ExtMask & RISCV_HWPROBE_IMA_ZBKX; + Features["zknd"] = ExtMask & RISCV_HWPROBE_IMA_ZKND; + Features["zkne"] = ExtMask & RISCV_HWPROBE_IMA_ZKNE; + Features["zknh"] = ExtMask & RISCV_HWPROBE_IMA_ZKNH; + Features["zksed"] = ExtMask & RISCV_HWPROBE_IMA_ZKSED; + Features["zksh"] = ExtMask & RISCV_HWPROBE_IMA_ZKSH; + Features["zkt"] = ExtMask & RISCV_HWPROBE_IMA_ZKT; + Features["zvbb"] = ExtMask & RISCV_HWPROBE_IMA_ZVBB; + Features["zvbc"] = ExtMask & RISCV_HWPROBE_IMA_ZVBC; + Features["zvkb"] = ExtMask & RISCV_HWPROBE_IMA_ZVKB; + Features["zvkg"] = ExtMask & RISCV_HWPROBE_IMA_ZVKG; + Features["zvkned"] = ExtMask & RISCV_HWPROBE_IMA_ZVKNED; + Features["zvknha"] = ExtMask & RISCV_HWPROBE_IMA_ZVKNHA; + Features["zvknhb"] = ExtMask & RISCV_HWPROBE_IMA_ZVKNHB; + Features["zvksed"] = ExtMask & RISCV_HWPROBE_IMA_ZVKSED; + Features["zvksh"] = ExtMask & RISCV_HWPROBE_IMA_ZVKSH; + Features["zvkt"] = ExtMask & RISCV_HWPROBE_IMA_ZVKT; + Features["zfh"] = ExtMask & RISCV_HWPROBE_IMA_ZFH; + Features["zfhmin"] = ExtMask & RISCV_HWPROBE_IMA_ZFHMIN; + Features["zihintntl"] = ExtMask & RISCV_HWPROBE_IMA_ZIHINTNTL; + Features["zvfh"] = ExtMask & RISCV_HWPROBE_IMA_ZVFH; + Features["zvfhmin"] = ExtMask & RISCV_HWPROBE_IMA_ZVFHMIN; + Features["zfa"] = ExtMask & RISCV_HWPROBE_IMA_ZFA; + Features["ztso"] = ExtMask & RISCV_HWPROBE_IMA_ZTSO; + Features["zacas"] = ExtMask & RISCV_HWPROBE_IMA_ZACAS; + Features["zicond"] = ExtMask & RISCV_HWPROBE_IMA_ZICOND; + Features["zihintpause"] = ExtMask & RISCV_HWPROBE_IMA_ZIHINTPAUSE; + + uint64_t MisalignedMask = Query[1].value; + if (MisalignedMask == RISCV_HWPROBE_MISALIGNED_FAST) { +Features["unaligned-scalar-mem"] = true; +Features["unaligned-vector-mem"] = true; + } + + return true; +#else + return false; +#endif +} #else bool sys::getHostCPUFeatures(StringMap &Features) { return false; } #endif >From a2fa6e3d64d3a1e2a8e3a7af91068bdb1fda28b1 Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Tue, 4 Jun 2024 22:10:55 +0800 Subject: [PATCH 2/8] [RISCV] Address review comments. --- llvm/lib/TargetParser/Host.cpp | 112 +++-- 1 file changed, 52 insertions(+), 60 deletions(-) diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp index b4a13b38eb380..ec275c0a7fded 100644 --- a/llvm/lib/TargetParser/Host.cpp +++ b/llvm/lib/TargetParser/Host.cpp @@ -1999,72 +1999,64 @@ bool sys::getHostCPUFeatures(StringMap &Features) { return true; } #elif defined(__linux__) && defined(__riscv) -#ifdef __has_include -#if __has_include() -#include -#endif -#endif +// struct riscv_hwprobe +struct RISCVHwProbe { + int64_t Key; + uint64_t Value; +}; bool sys::getHostCPUFeatures(StringMap &Features) { -#ifdef RISCV_HWPROBE_KEY_MVENDORID - riscv_hwprobe Query[2]{ - {RISCV_HWPROBE_KEY_IMA_EXT_0, 0}, - {RISCV_HWPROBE_KEY_CPUPERF_0, 0}, - }; - int Ret = syscall(/*__NR_riscv_hwprobe=*/258, /*pairs=*/&Query, -/*pair_count=*/1, /*cpu_count=*/0, /*cpus=*/0, /*flags=*/0); + RISCVHwProbe Query[]{{/*RISCV_HWPROBE_KEY_IMA_EXT_0=*/4, 0}}; + int Re
[clang] [llvm] [RISCV] Add support for getHostCPUFeatures using hwprobe (PR #94352)
https://github.com/dtcxzyw updated https://github.com/llvm/llvm-project/pull/94352 >From ff839bef048a65760f4cd0e9abafe11cfebd9362 Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Tue, 4 Jun 2024 21:08:27 +0800 Subject: [PATCH 1/9] [RISCV] Add support for getHostCPUFeatures using hwprobe Co-authored-by: Yangyu Chen --- llvm/lib/TargetParser/Host.cpp | 68 ++ 1 file changed, 68 insertions(+) diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp index 68155acd9e5bc..b4a13b38eb380 100644 --- a/llvm/lib/TargetParser/Host.cpp +++ b/llvm/lib/TargetParser/Host.cpp @@ -1998,6 +1998,74 @@ bool sys::getHostCPUFeatures(StringMap &Features) { return true; } +#elif defined(__linux__) && defined(__riscv) +#ifdef __has_include +#if __has_include() +#include +#endif +#endif +bool sys::getHostCPUFeatures(StringMap &Features) { +#ifdef RISCV_HWPROBE_KEY_MVENDORID + riscv_hwprobe Query[2]{ + {RISCV_HWPROBE_KEY_IMA_EXT_0, 0}, + {RISCV_HWPROBE_KEY_CPUPERF_0, 0}, + }; + int Ret = syscall(/*__NR_riscv_hwprobe=*/258, /*pairs=*/&Query, +/*pair_count=*/1, /*cpu_count=*/0, /*cpus=*/0, /*flags=*/0); + if (Ret != 0) +return false; + + uint64_t ExtMask = Query[0].value; + Features["f"] = ExtMask & RISCV_HWPROBE_IMA_FD; + Features["d"] = ExtMask & RISCV_HWPROBE_IMA_FD; + Features["c"] = ExtMask & RISCV_HWPROBE_IMA_C; + Features["v"] = ExtMask & RISCV_HWPROBE_IMA_V; + Features["zba"] = ExtMask & RISCV_HWPROBE_IMA_ZBA; + Features["zbb"] = ExtMask & RISCV_HWPROBE_IMA_ZBB; + Features["zbs"] = ExtMask & RISCV_HWPROBE_IMA_ZBS; + Features["zicboz"] = ExtMask & RISCV_HWPROBE_IMA_ZICBOZ; + Features["zbc"] = ExtMask & RISCV_HWPROBE_IMA_ZBC; + Features["zbkb"] = ExtMask & RISCV_HWPROBE_IMA_ZBKB; + Features["zbkc"] = ExtMask & RISCV_HWPROBE_IMA_ZBKC; + Features["zbkx"] = ExtMask & RISCV_HWPROBE_IMA_ZBKX; + Features["zknd"] = ExtMask & RISCV_HWPROBE_IMA_ZKND; + Features["zkne"] = ExtMask & RISCV_HWPROBE_IMA_ZKNE; + Features["zknh"] = ExtMask & RISCV_HWPROBE_IMA_ZKNH; + Features["zksed"] = ExtMask & RISCV_HWPROBE_IMA_ZKSED; + Features["zksh"] = ExtMask & RISCV_HWPROBE_IMA_ZKSH; + Features["zkt"] = ExtMask & RISCV_HWPROBE_IMA_ZKT; + Features["zvbb"] = ExtMask & RISCV_HWPROBE_IMA_ZVBB; + Features["zvbc"] = ExtMask & RISCV_HWPROBE_IMA_ZVBC; + Features["zvkb"] = ExtMask & RISCV_HWPROBE_IMA_ZVKB; + Features["zvkg"] = ExtMask & RISCV_HWPROBE_IMA_ZVKG; + Features["zvkned"] = ExtMask & RISCV_HWPROBE_IMA_ZVKNED; + Features["zvknha"] = ExtMask & RISCV_HWPROBE_IMA_ZVKNHA; + Features["zvknhb"] = ExtMask & RISCV_HWPROBE_IMA_ZVKNHB; + Features["zvksed"] = ExtMask & RISCV_HWPROBE_IMA_ZVKSED; + Features["zvksh"] = ExtMask & RISCV_HWPROBE_IMA_ZVKSH; + Features["zvkt"] = ExtMask & RISCV_HWPROBE_IMA_ZVKT; + Features["zfh"] = ExtMask & RISCV_HWPROBE_IMA_ZFH; + Features["zfhmin"] = ExtMask & RISCV_HWPROBE_IMA_ZFHMIN; + Features["zihintntl"] = ExtMask & RISCV_HWPROBE_IMA_ZIHINTNTL; + Features["zvfh"] = ExtMask & RISCV_HWPROBE_IMA_ZVFH; + Features["zvfhmin"] = ExtMask & RISCV_HWPROBE_IMA_ZVFHMIN; + Features["zfa"] = ExtMask & RISCV_HWPROBE_IMA_ZFA; + Features["ztso"] = ExtMask & RISCV_HWPROBE_IMA_ZTSO; + Features["zacas"] = ExtMask & RISCV_HWPROBE_IMA_ZACAS; + Features["zicond"] = ExtMask & RISCV_HWPROBE_IMA_ZICOND; + Features["zihintpause"] = ExtMask & RISCV_HWPROBE_IMA_ZIHINTPAUSE; + + uint64_t MisalignedMask = Query[1].value; + if (MisalignedMask == RISCV_HWPROBE_MISALIGNED_FAST) { +Features["unaligned-scalar-mem"] = true; +Features["unaligned-vector-mem"] = true; + } + + return true; +#else + return false; +#endif +} #else bool sys::getHostCPUFeatures(StringMap &Features) { return false; } #endif >From a2fa6e3d64d3a1e2a8e3a7af91068bdb1fda28b1 Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Tue, 4 Jun 2024 22:10:55 +0800 Subject: [PATCH 2/9] [RISCV] Address review comments. --- llvm/lib/TargetParser/Host.cpp | 112 +++-- 1 file changed, 52 insertions(+), 60 deletions(-) diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp index b4a13b38eb380..ec275c0a7fded 100644 --- a/llvm/lib/TargetParser/Host.cpp +++ b/llvm/lib/TargetParser/Host.cpp @@ -1999,72 +1999,64 @@ bool sys::getHostCPUFeatures(StringMap &Features) { return true; } #elif defined(__linux__) && defined(__riscv) -#ifdef __has_include -#if __has_include() -#include -#endif -#endif +// struct riscv_hwprobe +struct RISCVHwProbe { + int64_t Key; + uint64_t Value; +}; bool sys::getHostCPUFeatures(StringMap &Features) { -#ifdef RISCV_HWPROBE_KEY_MVENDORID - riscv_hwprobe Query[2]{ - {RISCV_HWPROBE_KEY_IMA_EXT_0, 0}, - {RISCV_HWPROBE_KEY_CPUPERF_0, 0}, - }; - int Ret = syscall(/*__NR_riscv_hwprobe=*/258, /*pairs=*/&Query, -/*pair_count=*/1, /*cpu_count=*/0, /*cpus=*/0, /*flags=*/0); + RISCVHwProbe Query[]{{/*RISCV_HWPROBE_KEY_IMA_EXT_0=*/4, 0}}; + int Re
[clang] [llvm] [RISCV] Add support for getHostCPUFeatures using hwprobe (PR #94352)
dtcxzyw wrote: > > I have no idea about why it corrupts StringMap. Sad :( > >  > > Is this fixed after fixing the return statement? This may be caused by the > corruption of `getHostCPUNameForRISCV`.  It works well now :) I will post a patch removing experimental from `ztso`. https://github.com/llvm/llvm-project/pull/94352 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 790f931 - [NFC] [Modules] Extract the logic to decide whether the module units belongs to the same module
Author: Chuanqi Xu Date: 2024-06-24T15:58:46+08:00 New Revision: 790f931886a03324714f31a626eef7e9c609ae97 URL: https://github.com/llvm/llvm-project/commit/790f931886a03324714f31a626eef7e9c609ae97 DIFF: https://github.com/llvm/llvm-project/commit/790f931886a03324714f31a626eef7e9c609ae97.diff LOG: [NFC] [Modules] Extract the logic to decide whether the module units belongs to the same module This patch extracts the logci to decide how we decide the module units belongs to the same module into a member function of ASTContext. This is helpful to refactor the implementation in the future. Added: Modified: clang/include/clang/AST/ASTContext.h clang/lib/AST/ASTContext.cpp clang/lib/Sema/SemaDecl.cpp clang/lib/Sema/SemaLookup.cpp clang/lib/Sema/SemaModule.cpp Removed: diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index de86cb5e9d7fc..46fe2d23e9334 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -1073,6 +1073,12 @@ class ASTContext : public RefCountedBase { /// Get module under construction, nullptr if this is not a C++20 module. Module *getCurrentNamedModule() const { return CurrentCXXNamedModule; } + /// If the two module \p M1 and \p M2 are in the same module. + /// + /// FIXME: The signature may be confusing since `clang::Module` means to + /// a module fragment or a module unit but not a C++20 module. + bool isInSameModule(const Module *M1, const Module *M2); + TranslationUnitDecl *getTranslationUnitDecl() const { return TUDecl->getMostRecentDecl(); } diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index fca200988fea1..6aed55a92364b 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -1110,6 +1110,15 @@ void ASTContext::setCurrentNamedModule(Module *M) { CurrentCXXNamedModule = M; } +bool ASTContext::isInSameModule(const Module *M1, const Module *M2) { + if (!M1 != !M2) +return false; + + assert(M1 && "Shouldn't call `isInSameModule` if both M1 and M2 are none."); + return M1->getPrimaryModuleInterfaceName() == + M2->getPrimaryModuleInterfaceName(); +} + ExternCContextDecl *ASTContext::getExternCContextDecl() const { if (!ExternCContext) ExternCContext = ExternCContextDecl::Create(*this, getTranslationUnitDecl()); diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index e28e5c56c11a7..efd546a6a3817 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -1663,8 +1663,7 @@ bool Sema::CheckRedeclarationModuleOwnership(NamedDecl *New, NamedDecl *Old) { // Partitions are part of the module, but a partition could import another // module, so verify that the PMIs agree. if ((NewM->isModulePartition() || OldM->isModulePartition()) && -NewM->getPrimaryModuleInterfaceName() == -OldM->getPrimaryModuleInterfaceName()) +getASTContext().isInSameModule(NewM, OldM)) return false; } diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index be6ea20a956a3..12b13eb8683ac 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -1606,22 +1606,32 @@ bool Sema::isUsableModule(const Module *M) { // [module.global.frag]p1: // The global module fragment can be used to provide declarations that are // attached to the global module and usable within the module unit. - if (M == TheGlobalModuleFragment || M == TheImplicitGlobalModuleFragment || - // If M is the module we're parsing, it should be usable. This covers the - // private module fragment. The private module fragment is usable only if - // it is within the current module unit. And it must be the current - // parsing module unit if it is within the current module unit according - // to the grammar of the private module fragment. NOTE: This is covered by - // the following condition. The intention of the check is to avoid string - // comparison as much as possible. - M == getCurrentModule() || - // The module unit which is in the same module with the current module - // unit is usable. - // - // FIXME: Here we judge if they are in the same module by comparing the - // string. Is there any better solution? - M->getPrimaryModuleInterfaceName() == - llvm::StringRef(getLangOpts().CurrentModule).split(':').first) { + if (M == TheGlobalModuleFragment || M == TheImplicitGlobalModuleFragment) { +UsableModuleUnitsCache.insert(M); +return true; + } + + // Otherwise, the global module fragment from other translation unit is not + // directly usable. + if (M->isGlobalModule()) +return false; + + Module *Current = getCurrentModule(); + + // If we're not parsing a module, we can't use all the declarations from + /
[clang] [SourceManager] Expose max usage of source location space as a Statistic (PR #96292)
https://github.com/ilya-biryukov updated https://github.com/llvm/llvm-project/pull/96292 >From ded4cdee02b56b0284b5e44fd24de6e07c57e6bf Mon Sep 17 00:00:00 2001 From: Ilya Biryukov Date: Tue, 11 Jun 2024 19:07:07 +0200 Subject: [PATCH 1/2] [SourceManager] Expose max usage of source location space as a Statistic We have been running into source location exhaustion recently and want to use the statistics to monitor the usage in various files to be able to anticipate where the next problem will happen. I picked `Statistic` because it can be written into a structured JSON file and is easier to consume by further automation. This commit does not change any existing per-source-manager metrics exposed via `SourceManager::PrintStats()`. This does create some redundancy, but I also expect to be non-controversial because it aligns with the intended use of `Statistic`. --- clang/include/clang/Basic/SourceManager.h | 1 + clang/lib/Basic/SourceManager.cpp | 16 2 files changed, 17 insertions(+) diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h index d2e2e914327f2..d3ccc7ef81c07 100644 --- a/clang/include/clang/Basic/SourceManager.h +++ b/clang/include/clang/Basic/SourceManager.h @@ -1981,6 +1981,7 @@ class SourceManager : public RefCountedBase { SourceLocation SpellLoc, SourceLocation ExpansionLoc, unsigned ExpansionLength) const; + void updateSlocUsageStats() const; }; /// Comparison function object. diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index f0af1a3e3a38b..e430e8974ff5c 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -20,6 +20,7 @@ #include "llvm/ADT/MapVector.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/Statistic.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Support/Allocator.h" @@ -46,6 +47,12 @@ using namespace clang; using namespace SrcMgr; using llvm::MemoryBuffer; +#define DEBUG_TYPE "source-manager" + +STATISTIC( +MaxUsedSLocBytes, +"Maximum number of bytes used by source locations (both loaded and local)"); + //===--===// // SourceManager Helper Classes //===--===// @@ -466,6 +473,7 @@ SourceManager::AllocateLoadedSLocEntries(unsigned NumSLocEntries, SLocEntryLoaded.resize(LoadedSLocEntryTable.size()); SLocEntryOffsetLoaded.resize(LoadedSLocEntryTable.size()); CurrentLoadedOffset -= TotalSize; + updateSlocUsageStats(); int BaseID = -int(LoadedSLocEntryTable.size()) - 1; LoadedSLocEntryAllocBegin.push_back(FileID::get(BaseID)); return std::make_pair(BaseID, CurrentLoadedOffset); @@ -619,6 +627,7 @@ FileID SourceManager::createFileIDImpl(ContentCache &File, StringRef Filename, // We do a +1 here because we want a SourceLocation that means "the end of the // file", e.g. for the "no newline at the end of the file" diagnostic. NextLocalOffset += FileSize + 1; + updateSlocUsageStats(); // Set LastFileIDLookup to the newly created file. The next getFileID call is // almost guaranteed to be from that file. @@ -679,6 +688,7 @@ SourceManager::createExpansionLocImpl(const ExpansionInfo &Info, } // See createFileID for that +1. NextLocalOffset += Length + 1; + updateSlocUsageStats(); return SourceLocation::getMacroLoc(NextLocalOffset - (Length + 1)); } @@ -1843,6 +1853,12 @@ void SourceManager::associateFileChunkWithMacroArgExp( MacroArgsCache[EndOffs] = EndOffsMappedLoc; } +void SourceManager::updateSlocUsageStats() const { + SourceLocation::UIntTy UsedBytes = + NextLocalOffset + (MaxLoadedOffset - CurrentLoadedOffset); + MaxUsedSLocBytes.updateMax(UsedBytes); +} + /// If \arg Loc points inside a function macro argument, the returned /// location will be the macro location in which the argument was expanded. /// If a macro argument is used multiple times, the expanded location will >From eae8eb6f9019c41ec6d414d30de2e4156602c243 Mon Sep 17 00:00:00 2001 From: Ilya Biryukov Date: Mon, 24 Jun 2024 10:04:42 +0200 Subject: [PATCH 2/2] fixup! [SourceManager] Expose max usage of source location space as a Statistic Add a comment about the metric --- clang/lib/Basic/SourceManager.cpp | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index e430e8974ff5c..533a9fe88a215 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -49,9 +49,10 @@ using llvm::MemoryBuffer; #define DEBUG_TYPE "source-manager" -STATISTIC( -MaxUsedSLocBytes, -"Maximum number of bytes used by source
[clang] [clang][AArch64][FMV] Stop emitting alias to ifunc. (PR #96221)
https://github.com/labrinea updated https://github.com/llvm/llvm-project/pull/96221 >From 4b884669236cae2d5ac42a95517d9ce57060a494 Mon Sep 17 00:00:00 2001 From: Alexandros Lamprineas Date: Thu, 20 Jun 2024 17:40:44 +0100 Subject: [PATCH 1/2] [clang][AArch64][FMV] Stop emitting alias to ifunc. Long story short the interaction of two optimizations happening in GlobalOpt results in a crash. For more details look at the issue https://github.com/llvm/llvm-project/issues/96197. I will be fixing this in GlobalOpt but it is a conservative solution since it won't allow us to optimize resolvers which return a pointer to a function whose definition is in another TU when compiling without LTO: __attribute__((target_version("simd"))) void bar(void); __attribute__((target_version("default"))) void bar(void); int foo() { bar(); } --- clang/lib/CodeGen/CodeGenModule.cpp | 4 ++-- .../CodeGen/aarch64-mixed-target-attributes.c| 3 --- clang/test/CodeGen/attr-target-clones-aarch64.c | 16 clang/test/CodeGen/attr-target-version.c | 13 - .../CodeGenCXX/attr-target-clones-aarch64.cpp| 4 clang/test/CodeGenCXX/attr-target-version.cpp| 6 -- clang/test/CodeGenCXX/fmv-namespace.cpp | 2 -- 7 files changed, 2 insertions(+), 46 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index dd4a665ebc78b..76534475e88f7 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -4259,8 +4259,8 @@ void CodeGenModule::emitMultiVersionFunctions() { llvm::Constant *ResolverConstant = GetOrCreateMultiVersionResolver(GD); if (auto *IFunc = dyn_cast(ResolverConstant)) { ResolverConstant = IFunc->getResolver(); - if (FD->isTargetClonesMultiVersion() || - FD->isTargetVersionMultiVersion()) { + if (FD->isTargetClonesMultiVersion() && + !getTarget().getTriple().isAArch64()) { std::string MangledName = getMangledNameImpl( *this, GD, FD, /*OmitMultiVersionMangling=*/true); if (!GetGlobalValue(MangledName + ".ifunc")) { diff --git a/clang/test/CodeGen/aarch64-mixed-target-attributes.c b/clang/test/CodeGen/aarch64-mixed-target-attributes.c index 6aa747d4cb461..3c047fec6ceed 100644 --- a/clang/test/CodeGen/aarch64-mixed-target-attributes.c +++ b/clang/test/CodeGen/aarch64-mixed-target-attributes.c @@ -30,9 +30,6 @@ __attribute__((target_version("jscvt"))) int default_def_with_version_decls(void //. // CHECK: @__aarch64_cpu_features = external dso_local global { i64 } -// CHECK: @explicit_default.ifunc = weak_odr alias i32 (), ptr @explicit_default -// CHECK: @implicit_default.ifunc = weak_odr alias i32 (), ptr @implicit_default -// CHECK: @default_def_with_version_decls.ifunc = weak_odr alias i32 (), ptr @default_def_with_version_decls // CHECK: @explicit_default = weak_odr ifunc i32 (), ptr @explicit_default.resolver // CHECK: @implicit_default = weak_odr ifunc i32 (), ptr @implicit_default.resolver // CHECK: @default_def_with_version_decls = weak_odr ifunc i32 (), ptr @default_def_with_version_decls.resolver diff --git a/clang/test/CodeGen/attr-target-clones-aarch64.c b/clang/test/CodeGen/attr-target-clones-aarch64.c index ad6079a91fcd5..60f9c7f1fc24e 100644 --- a/clang/test/CodeGen/attr-target-clones-aarch64.c +++ b/clang/test/CodeGen/attr-target-clones-aarch64.c @@ -27,14 +27,6 @@ inline int __attribute__((target_clones("fp16", "sve2-bitperm+fcma", "default")) //. // CHECK: @__aarch64_cpu_features = external dso_local global { i64 } -// CHECK: @ftc.ifunc = weak_odr alias i32 (), ptr @ftc -// CHECK: @ftc_def.ifunc = weak_odr alias i32 (), ptr @ftc_def -// CHECK: @ftc_dup1.ifunc = weak_odr alias i32 (), ptr @ftc_dup1 -// CHECK: @ftc_dup2.ifunc = weak_odr alias i32 (), ptr @ftc_dup2 -// CHECK: @ftc_dup3.ifunc = weak_odr alias i32 (), ptr @ftc_dup3 -// CHECK: @ftc_inline2.ifunc = weak_odr alias i32 (), ptr @ftc_inline2 -// CHECK: @ftc_inline1.ifunc = weak_odr alias i32 (), ptr @ftc_inline1 -// CHECK: @ftc_inline3.ifunc = weak_odr alias i32 (), ptr @ftc_inline3 // CHECK: @ftc = weak_odr ifunc i32 (), ptr @ftc.resolver // CHECK: @ftc_def = weak_odr ifunc i32 (), ptr @ftc_def.resolver // CHECK: @ftc_dup1 = weak_odr ifunc i32 (), ptr @ftc_dup1.resolver @@ -45,14 +37,6 @@ inline int __attribute__((target_clones("fp16", "sve2-bitperm+fcma", "default")) // CHECK: @ftc_inline3 = weak_odr ifunc i32 (), ptr @ftc_inline3.resolver //. // CHECK-MTE-BTI: @__aarch64_cpu_features = external dso_local global { i64 } -// CHECK-MTE-BTI: @ftc.ifunc = weak_odr alias i32 (), ptr @ftc -// CHECK-MTE-BTI: @ftc_def.ifunc = weak_odr alias i32 (), ptr @ftc_def -// CHECK-MTE-BTI: @ftc_dup1.ifunc = weak_odr alias i32 (), ptr @ftc_dup1 -// CHECK-MTE-BTI: @ftc_dup2.ifunc = weak_odr alias i32 (), ptr @ftc_dup2 -// CHECK-MTE-BTI: @ftc_dup3.ifunc = weak_odr alias i32 (), ptr @ftc_dup3 -// CHECK-MTE-BTI: @ftc_in
[clang] 33676ba - [clang][Interp] Fix variable initialization in inactive regions
Author: Timm Bäder Date: 2024-06-24T10:18:05+02:00 New Revision: 33676ba543737f8e286e28a9cae81a848bdd3f09 URL: https://github.com/llvm/llvm-project/commit/33676ba543737f8e286e28a9cae81a848bdd3f09 DIFF: https://github.com/llvm/llvm-project/commit/33676ba543737f8e286e28a9cae81a848bdd3f09.diff LOG: [clang][Interp] Fix variable initialization in inactive regions When the EvalEmitter is inactive, it will simply not evaluate any of the operations we emit via emit*. However, it will still allocate variables. So the variables will be allocated, but we won't evaluate their initializer, so later when we see the variable again, it is uninitialized. Stop creating variables in that case. Added: Modified: clang/lib/AST/Interp/ByteCodeEmitter.h clang/lib/AST/Interp/ByteCodeExprGen.cpp clang/lib/AST/Interp/ByteCodeExprGen.h clang/lib/AST/Interp/EvalEmitter.h clang/test/AST/Interp/c.c Removed: diff --git a/clang/lib/AST/Interp/ByteCodeEmitter.h b/clang/lib/AST/Interp/ByteCodeEmitter.h index d797a0ab4a1c9..9a329e969f339 100644 --- a/clang/lib/AST/Interp/ByteCodeEmitter.h +++ b/clang/lib/AST/Interp/ByteCodeEmitter.h @@ -54,6 +54,9 @@ class ByteCodeEmitter { bool jump(const LabelTy &Label); bool fallthrough(const LabelTy &Label); + /// We're always emitting bytecode. + bool isActive() const { return true; } + /// Callback for local registration. Local createLocal(Descriptor *D); diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 72c569f56a788..cb5962466f35f 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -3404,11 +3404,16 @@ bool ByteCodeExprGen::visitDecl(const VarDecl *VD, } template -bool ByteCodeExprGen::visitVarDecl(const VarDecl *VD) { +VarCreationState ByteCodeExprGen::visitVarDecl(const VarDecl *VD) { // We don't know what to do with these, so just return false. if (VD->getType().isNull()) return false; + // This case is EvalEmitter-only. If we won't create any instructions for the + // initializer anyway, don't bother creating the variable in the first place. + if (!this->isActive()) +return VarCreationState::NotCreated(); + const Expr *Init = VD->getInit(); std::optional VarT = classify(VD->getType()); @@ -4237,7 +4242,10 @@ bool ByteCodeExprGen::visitDeclRef(const ValueDecl *D, const Expr *E) { if ((VD->hasGlobalStorage() || VD->isLocalVarDecl() || VD->isStaticDataMember()) && typeShouldBeVisited(VD->getType())) { - if (!this->visitVarDecl(VD)) + auto VarState = this->visitVarDecl(VD); + if (VarState.notCreated()) +return true; + if (!VarState) return false; // Retry. return this->visitDeclRef(VD, E); @@ -4247,7 +4255,10 @@ bool ByteCodeExprGen::visitDeclRef(const ValueDecl *D, const Expr *E) { if (const auto *VD = dyn_cast(D); VD && VD->getAnyInitializer() && VD->getType().isConstant(Ctx.getASTContext()) && !VD->isWeak()) { -if (!this->visitVarDecl(VD)) +auto VarState = this->visitVarDecl(VD); +if (VarState.notCreated()) + return true; +if (!VarState) return false; // Retry. return this->visitDeclRef(VD, E); diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.h b/clang/lib/AST/Interp/ByteCodeExprGen.h index eef8cae6e38cd..2921ffe49c45f 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.h +++ b/clang/lib/AST/Interp/ByteCodeExprGen.h @@ -70,6 +70,18 @@ struct InitLink { }; }; +/// State encapsulating if a the variable creation has been successful, +/// unsuccessful, or no variable has been created at all. +struct VarCreationState { + std::optional S = std::nullopt; + VarCreationState() = default; + VarCreationState(bool b) : S(b) {} + static VarCreationState NotCreated() { return VarCreationState(); } + + operator bool() const { return S && *S; } + bool notCreated() const { return !S; } +}; + /// Compilation context for expressions. template class ByteCodeExprGen : public ConstStmtVisitor, bool>, @@ -220,9 +232,8 @@ class ByteCodeExprGen : public ConstStmtVisitor, bool>, /// Just pass evaluation on to \p E. This leaves all the parsing flags /// intact. bool delegate(const Expr *E); - /// Creates and initializes a variable from the given decl. - bool visitVarDecl(const VarDecl *VD); + VarCreationState visitVarDecl(const VarDecl *VD); /// Visit an APValue. bool visitAPValue(const APValue &Val, PrimType ValType, const Expr *E); bool visitAPValueInitializer(const APValue &Val, const Expr *E); diff --git a/clang/lib/AST/Interp/EvalEmitter.h b/clang/lib/AST/Interp/EvalEmitter.h index 68accbc5214c2..e85f37d757b69 100644 --- a/clang/lib/AST/Interp/EvalEmitter.h +++ b/clang/lib/AS
[clang] [clang][utils] Remove ClangDataFormat.py for now (PR #96385)
Endilll wrote: LGTM > We should eventually develop proper formatters for Clang data-types, but > these are currently not ready. Yes, I'm still working on that in background. LLDB has to have a way to understand custom RTTI we use in AST nodes for statements and types, because adding a vtable pointer will increase memory pressure. I'm working on such mechanism, and that's why it's taking so long. https://github.com/llvm/llvm-project/pull/96385 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][utils] Remove ClangDataFormat.py for now (PR #96385)
Michael137 wrote: > LGTM > > > We should eventually develop proper formatters for Clang data-types, but > > these are currently not ready. > > Yes, I'm still working on that in background. LLDB has to have a way to > understand custom RTTI we use in AST nodes for statements and types, because > adding a vtable pointer will increase memory pressure. I'm working on such > mechanism, and that's why it's taking so long. Thanks, greatly appreciated! https://github.com/llvm/llvm-project/pull/96385 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [SourceManager] Expose max usage of source location space as a Statistic (PR #96292)
@@ -46,6 +47,12 @@ using namespace clang; using namespace SrcMgr; using llvm::MemoryBuffer; +#define DEBUG_TYPE "source-manager" + +STATISTIC( +MaxUsedSLocBytes, +"Maximum number of bytes used by source locations (both loaded and local)"); ilya-biryukov wrote: Done. I added a comment because the description string is something that tends to rather look like a one-liner. https://github.com/llvm/llvm-project/pull/96292 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [SourceManager] Expose max usage of source location space as a Statistic (PR #96292)
ilya-biryukov wrote: > LGTM. Please wait a couple of days before landing to give a chance to other > folks for reviewing. What would be a rationale to hold it off? It's perfectly within the [policy](https://llvm.org/docs/CodeReview.html#must-code-be-reviewed-prior-to-being-committed) to submit patches like this without too many reviewers and instead resolve any questions post-commit. I would be happy to revert or update if people raise questions, it just seems like too much wait time for a patch that does not change much. https://github.com/llvm/llvm-project/pull/96292 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Catch missing format attributes (PR #70024)
https://github.com/budimirarandjelovicsyrmia updated https://github.com/llvm/llvm-project/pull/70024 From 97cc6f1e97bb27422df8fa0ecce2f4ad1dfcacff Mon Sep 17 00:00:00 2001 From: budimirarandjelovicsyrmia Date: Fri, 5 Apr 2024 15:20:37 +0200 Subject: [PATCH] [clang] Catch missing format attributes --- clang/docs/ReleaseNotes.rst | 3 + clang/include/clang/Basic/DiagnosticGroups.td | 1 - .../clang/Basic/DiagnosticSemaKinds.td| 3 + clang/include/clang/Sema/Attr.h | 7 + clang/include/clang/Sema/Sema.h | 4 + clang/lib/Sema/SemaChecking.cpp | 4 +- clang/lib/Sema/SemaDeclAttr.cpp | 112 ++- clang/test/Sema/attr-format-missing.c | 304 ++ clang/test/Sema/attr-format-missing.cpp | 178 ++ 9 files changed, 612 insertions(+), 4 deletions(-) create mode 100644 clang/test/Sema/attr-format-missing.c create mode 100644 clang/test/Sema/attr-format-missing.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 9c8f8c4a4fbaf..31e31ab4ac262 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -612,6 +612,9 @@ Improvements to Clang's diagnostics used rather than when they are needed for constant evaluation or when code is generated for them. The check is now stricter to prevent crashes for some unsupported declarations (Fixes #GH95495). +- Clang now diagnoses missing format attributes for non-template functions and + class/struct/union members. Fixes #GH60718 + Improvements to Clang's time-trace -- diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 9b37d4bd3205b..4e075eb7c062a 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -505,7 +505,6 @@ def MainReturnType : DiagGroup<"main-return-type">; def MaxUnsignedZero : DiagGroup<"max-unsigned-zero">; def MissingBraces : DiagGroup<"missing-braces">; def MissingDeclarations: DiagGroup<"missing-declarations">; -def : DiagGroup<"missing-format-attribute">; def MissingIncludeDirs : DiagGroup<"missing-include-dirs">; def MissingNoreturn : DiagGroup<"missing-noreturn">; def MultiChar : DiagGroup<"multichar">; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 25a87078a5709..f92aa7be8effb 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -1021,6 +1021,9 @@ def err_opencl_invalid_param : Error< def err_opencl_invalid_return : Error< "declaring function return value of type %0 is not allowed %select{; did you forget * ?|}1">; def warn_enum_value_overflow : Warning<"overflow in enumeration value">; +def warn_missing_format_attribute : Warning< + "diagnostic behavior may be improved by adding the %0 format attribute to the declaration of %1">, + InGroup>, DefaultIgnore; def warn_pragma_options_align_reset_failed : Warning< "#pragma options align=reset failed: %0">, InGroup; diff --git a/clang/include/clang/Sema/Attr.h b/clang/include/clang/Sema/Attr.h index 3f0b10212789a..37c124ca7b454 100644 --- a/clang/include/clang/Sema/Attr.h +++ b/clang/include/clang/Sema/Attr.h @@ -123,6 +123,13 @@ inline bool isInstanceMethod(const Decl *D) { return false; } +inline bool checkIfMethodHasImplicitObjectParameter(const Decl *D) { + if (const auto *MethodDecl = dyn_cast(D)) +return MethodDecl->isInstance() && + !MethodDecl->hasCXXExplicitFunctionObjectParameter(); + return false; +} + /// Diagnose mutually exclusive attributes when present on a given /// declaration. Returns true if diagnosed. template diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index e43e5f465361d..93906437c6626 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -3775,6 +3775,10 @@ class Sema final : public SemaBase { enum class RetainOwnershipKind { NS, CF, OS }; + void DiagnoseMissingFormatAttributes(const FunctionDecl *FDecl, + ArrayRef Args, + SourceLocation Loc); + UuidAttr *mergeUuidAttr(Decl *D, const AttributeCommonInfo &CI, StringRef UuidAsWritten, MSGuidDecl *GuidDecl); diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 87988519e7691..63697fab64ee1 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -4119,8 +4119,10 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } - if (FD) + if (FD) { diagnoseArgDependentDiagnoseIfAttrs(FD, ThisArg, Args, Loc); +DiagnoseMissingFormatAttributes(FD, Args, Range.getBegin()); + } } void Sema::CheckConstrainedAuto(const AutoType *AutoT, Source
[clang] [Clang] Prevent null pointer dereferences in SVE tuple functions (PR #94267)
@@ -10226,7 +10229,7 @@ Value *CodeGenFunction::EmitSVETupleCreate(const SVETypeFlags &TypeFlags, ArrayRef Ops) { assert(TypeFlags.isTupleCreate() && "Expects TypleFlag isTupleCreate"); - auto *SrcTy = dyn_cast(Ops[0]->getType()); + auto *SrcTy = cast(Ops[0]->getType()); CarolineConcatto wrote: I believe we should have some consistency in here between EmitSVETupleSetOrGet and EmitSVETupleCreate. Or both we do : auto *SrcTy/SingleVecTy) = cast or auto *SrcTy/SingleVecTy) = dyn_cast( if (!ScrTy/SingleVecTy)) return Maybe is fine to cast directly to ScalableVectorType. I can see this being done is the other EmitSVE. https://github.com/llvm/llvm-project/pull/94267 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Try to fix https://github.com/llvm/llvm-project/issues/41441 (PR #96464)
https://github.com/awson created https://github.com/llvm/llvm-project/pull/96464 The [last attempt](https://github.com/llvm/llvm-project/pull/89036) to fix https://github.com/llvm/llvm-project/issues/41441 has been reverted immediately. Here I'm trying the simplest idea I've been able to come with: skip handling dependent case in `BuildCXXNew`. The original test (borrowed form https://github.com/llvm/llvm-project/pull/89036) passes. Also I've created and added to the tests a minimal repro of the code https://github.com/llvm/llvm-project/pull/89036 fails on. This (obviously) also passes. >From ad15dc4983e4d153b4eb19aa72b35c0a5ad919c0 Mon Sep 17 00:00:00 2001 From: awson Date: Mon, 24 Jun 2024 10:34:51 +0300 Subject: [PATCH 1/2] Don't handle ArraySize/AllocType early. --- clang/lib/Sema/SemaExprCXX.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index f3af8dee6b090..2f79540faea00 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -2174,7 +2174,8 @@ ExprResult Sema::BuildCXXNew(SourceRange Range, bool UseGlobal, // Per C++0x [expr.new]p5, the type being constructed may be a // typedef of an array type. - if (!ArraySize) { + // Dependent case will be handled separately. + if (!ArraySize && !AllocType->isDependentType()) { if (const ConstantArrayType *Array = Context.getAsConstantArrayType(AllocType)) { ArraySize = IntegerLiteral::Create(Context, Array->getSize(), >From a6fd197eab12a579c68ab1190f1bf6d144114ba9 Mon Sep 17 00:00:00 2001 From: awson Date: Mon, 24 Jun 2024 11:07:58 +0300 Subject: [PATCH 2/2] Tests for GH41441 I've borrowed size-calculation test from PR89036 and added another test, which PR89036 fails on. --- clang/test/SemaCXX/GH41441.cpp | 46 ++ 1 file changed, 46 insertions(+) create mode 100644 clang/test/SemaCXX/GH41441.cpp diff --git a/clang/test/SemaCXX/GH41441.cpp b/clang/test/SemaCXX/GH41441.cpp new file mode 100644 index 0..7a6260fef91b5 --- /dev/null +++ b/clang/test/SemaCXX/GH41441.cpp @@ -0,0 +1,46 @@ +// RUN: %clang --target=x86_64-pc-linux -S -fno-discard-value-names -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 %s -fsyntax-only -verify + +namespace std { + using size_t = decltype(sizeof(int)); +}; +void* operator new[](std::size_t, void*) noexcept; + +// CHECK: call void @llvm.memset.p0.i64(ptr align 1 %x, i8 0, i64 8, i1 false) +// CHECK: call void @llvm.memset.p0.i64(ptr align 16 %x, i8 0, i64 32, i1 false) +template +void f() +{ +typedef TYPE TArray[8]; + +TArray x; +new(&x) TArray(); +} + +template +void f1() { + int (*x)[1] = new int[1][1]; +} +template void f1(); +void f2() { + int (*x)[1] = new int[1][1]; +} + +int main() +{ +f(); +f(); +} + +// expected-no-diagnostics +template struct unique_ptr {unique_ptr(T* p){}}; + +template +unique_ptr make_unique(unsigned long long n) { + return unique_ptr(new T[n]()); +} + +auto boro(int n){ + typedef double HistoryBuffer[4]; + return make_unique(n); +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Try to fix https://github.com/llvm/llvm-project/issues/41441 (PR #96464)
github-actions[bot] wrote: Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using `@` followed by their GitHub username. If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html). You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/). https://github.com/llvm/llvm-project/pull/96464 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Try to fix https://github.com/llvm/llvm-project/issues/41441 (PR #96464)
llvmbot wrote: @llvm/pr-subscribers-clang Author: None (awson) Changes The [last attempt](https://github.com/llvm/llvm-project/pull/89036) to fix https://github.com/llvm/llvm-project/issues/41441 has been reverted immediately. Here I'm trying the simplest idea I've been able to come with: skip handling dependent case in `BuildCXXNew`. The original test (borrowed form https://github.com/llvm/llvm-project/pull/89036) passes. Also I've created and added to the tests a minimal repro of the code https://github.com/llvm/llvm-project/pull/89036 fails on. This (obviously) also passes. --- Full diff: https://github.com/llvm/llvm-project/pull/96464.diff 2 Files Affected: - (modified) clang/lib/Sema/SemaExprCXX.cpp (+2-1) - (added) clang/test/SemaCXX/GH41441.cpp (+46) ``diff diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index f3af8dee6b090..2f79540faea00 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -2174,7 +2174,8 @@ ExprResult Sema::BuildCXXNew(SourceRange Range, bool UseGlobal, // Per C++0x [expr.new]p5, the type being constructed may be a // typedef of an array type. - if (!ArraySize) { + // Dependent case will be handled separately. + if (!ArraySize && !AllocType->isDependentType()) { if (const ConstantArrayType *Array = Context.getAsConstantArrayType(AllocType)) { ArraySize = IntegerLiteral::Create(Context, Array->getSize(), diff --git a/clang/test/SemaCXX/GH41441.cpp b/clang/test/SemaCXX/GH41441.cpp new file mode 100644 index 0..7a6260fef91b5 --- /dev/null +++ b/clang/test/SemaCXX/GH41441.cpp @@ -0,0 +1,46 @@ +// RUN: %clang --target=x86_64-pc-linux -S -fno-discard-value-names -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 %s -fsyntax-only -verify + +namespace std { + using size_t = decltype(sizeof(int)); +}; +void* operator new[](std::size_t, void*) noexcept; + +// CHECK: call void @llvm.memset.p0.i64(ptr align 1 %x, i8 0, i64 8, i1 false) +// CHECK: call void @llvm.memset.p0.i64(ptr align 16 %x, i8 0, i64 32, i1 false) +template +void f() +{ +typedef TYPE TArray[8]; + +TArray x; +new(&x) TArray(); +} + +template +void f1() { + int (*x)[1] = new int[1][1]; +} +template void f1(); +void f2() { + int (*x)[1] = new int[1][1]; +} + +int main() +{ +f(); +f(); +} + +// expected-no-diagnostics +template struct unique_ptr {unique_ptr(T* p){}}; + +template +unique_ptr make_unique(unsigned long long n) { + return unique_ptr(new T[n]()); +} + +auto boro(int n){ + typedef double HistoryBuffer[4]; + return make_unique(n); +} `` https://github.com/llvm/llvm-project/pull/96464 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Try to fix llvm/llvm-project#41441 (PR #96464)
https://github.com/awson edited https://github.com/llvm/llvm-project/pull/96464 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Remove experimental from Ztso. (PR #96465)
https://github.com/dtcxzyw created https://github.com/llvm/llvm-project/pull/96465 Ztso 1.0 was ratified in January 2023. Documentation: https://github.com/riscv/riscv-isa-manual/blob/main/src/ztso-st-ext.adoc >From 34670ab55ccecb1a2c7d92f809c9cae0df4150c6 Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Mon, 24 Jun 2024 16:43:04 +0800 Subject: [PATCH] [RISCV] Remove experimental from Ztso. --- clang/test/Driver/riscv-arch.c| 24 ++ .../test/Preprocessor/riscv-target-features.c | 10 ++-- llvm/docs/RISCVUsage.rst | 4 +- llvm/docs/ReleaseNotes.rst| 1 + llvm/lib/Target/RISCV/RISCVFeatures.td| 4 +- .../CodeGen/RISCV/GlobalISel/atomic-fence.ll | 4 +- llvm/test/CodeGen/RISCV/atomic-cmpxchg.ll | 10 ++-- llvm/test/CodeGen/RISCV/atomic-fence.ll | 4 +- llvm/test/CodeGen/RISCV/atomic-load-store.ll | 8 ++-- llvm/test/CodeGen/RISCV/atomic-rmw.ll | 12 ++--- .../CodeGen/RISCV/atomicrmw-uinc-udec-wrap.ll | 4 +- llvm/test/CodeGen/RISCV/attributes.ll | 4 +- llvm/test/CodeGen/RISCV/module-elf-flags.ll | 2 +- llvm/test/MC/RISCV/Ztso.s | 4 +- llvm/test/MC/RISCV/attribute-arch.s | 4 +- llvm/test/MC/RISCV/elf-flags.s| 4 +- .../TargetParser/RISCVISAInfoTest.cpp | 46 +-- 17 files changed, 77 insertions(+), 72 deletions(-) diff --git a/clang/test/Driver/riscv-arch.c b/clang/test/Driver/riscv-arch.c index ffd92e1f398c4..c3c471c4bc396 100644 --- a/clang/test/Driver/riscv-arch.c +++ b/clang/test/Driver/riscv-arch.c @@ -365,24 +365,30 @@ // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-ZFHMIN %s // RV32-ZFHMIN: "-target-feature" "+zfhmin" -// RUN: not %clang --target=riscv32-unknown-elf -march=rv32iztso -### %s \ +// RUN: not %clang --target=riscv32-unknown-elf -march=rv32izalasr -### %s \ // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-NOFLAG %s -// RV32-EXPERIMENTAL-NOFLAG: error: invalid arch name 'rv32iztso' +// RV32-EXPERIMENTAL-NOFLAG: error: invalid arch name 'rv32izalasr' // RV32-EXPERIMENTAL-NOFLAG: requires '-menable-experimental-extensions' -// RUN: not %clang --target=riscv32-unknown-elf -march=rv32iztso -menable-experimental-extensions -### %s \ +// RUN: not %clang --target=riscv32-unknown-elf -march=rv32izalasr -menable-experimental-extensions -### %s \ // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-NOVERS %s -// RV32-EXPERIMENTAL-NOVERS: error: invalid arch name 'rv32iztso' +// RV32-EXPERIMENTAL-NOVERS: error: invalid arch name 'rv32izalasr' // RV32-EXPERIMENTAL-NOVERS: experimental extension requires explicit version number -// RUN: not %clang --target=riscv32-unknown-elf -march=rv32iztso0p7 -menable-experimental-extensions -### %s \ +// RUN: not %clang --target=riscv32-unknown-elf -march=rv32izalasr0p7 -menable-experimental-extensions -### %s \ // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-BADVERS %s -// RV32-EXPERIMENTAL-BADVERS: error: invalid arch name 'rv32iztso0p7' -// RV32-EXPERIMENTAL-BADVERS: unsupported version number 0.7 for experimental extension 'ztso' (this compiler supports 0.1) +// RV32-EXPERIMENTAL-BADVERS: error: invalid arch name 'rv32izalasr0p7' +// RV32-EXPERIMENTAL-BADVERS: unsupported version number 0.7 for experimental extension 'zalasr' (this compiler supports 0.1) -// RUN: %clang --target=riscv32-unknown-elf -march=rv32iztso0p1 -menable-experimental-extensions -### %s \ +// RUN: %clang --target=riscv32-unknown-elf -march=rv32izalasr0p1 -menable-experimental-extensions -### %s \ // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-GOODVERS %s -// RV32-EXPERIMENTAL-GOODVERS: "-target-feature" "+experimental-ztso" +// RV32-EXPERIMENTAL-GOODVERS: "-target-feature" "+experimental-zalasr" + +// RUN: %clang --target=riscv32-unknown-elf -march=rv32iztso1p0 -### %s \ +// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-ZTSO %s +// RUN: %clang --target=riscv32-unknown-elf -march=rv32iztso -### %s \ +// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-ZTSO %s +// RV32-ZTSO: "-target-feature" "+ztso" // RUN: %clang --target=riscv32-unknown-elf -march=rv32izbb1p0 -### %s \ // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-ZBB %s diff --git a/clang/test/Preprocessor/riscv-target-features.c b/clang/test/Preprocessor/riscv-target-features.c index d7935af532dfa..46a61e3c0afc7 100644 --- a/clang/test/Preprocessor/riscv-target-features.c +++ b/clang/test/Preprocessor/riscv-target-features.c @@ -1650,13 +1650,13 @@ // RUN: -o - | FileCheck --check-prefix=CHECK-ZICFILP-EXT %s // CHECK-ZICFILP-EXT: __riscv_zicfilp 4000{{$}} -// RUN: %clang --target=riscv32-unknown-linux-gnu -menable-experimental-extensions \ -// RUN: -march=rv32iztso0p1 -E -dM %s \ +// RUN: %clang --target=riscv32-unknown-linux-gnu \ +// RUN: -march=rv32iztso1p0 -E -dM %s \ // R
[clang] [llvm] [RISCV] Remove experimental from Ztso. (PR #96465)
llvmbot wrote: @llvm/pr-subscribers-clang-driver Author: Yingwei Zheng (dtcxzyw) Changes Ztso 1.0 was ratified in January 2023. Documentation: https://github.com/riscv/riscv-isa-manual/blob/main/src/ztso-st-ext.adoc --- Patch is 27.35 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/96465.diff 17 Files Affected: - (modified) clang/test/Driver/riscv-arch.c (+15-9) - (modified) clang/test/Preprocessor/riscv-target-features.c (+5-5) - (modified) llvm/docs/RISCVUsage.rst (+1-3) - (modified) llvm/docs/ReleaseNotes.rst (+1) - (modified) llvm/lib/Target/RISCV/RISCVFeatures.td (+2-2) - (modified) llvm/test/CodeGen/RISCV/GlobalISel/atomic-fence.ll (+2-2) - (modified) llvm/test/CodeGen/RISCV/atomic-cmpxchg.ll (+5-5) - (modified) llvm/test/CodeGen/RISCV/atomic-fence.ll (+2-2) - (modified) llvm/test/CodeGen/RISCV/atomic-load-store.ll (+4-4) - (modified) llvm/test/CodeGen/RISCV/atomic-rmw.ll (+6-6) - (modified) llvm/test/CodeGen/RISCV/atomicrmw-uinc-udec-wrap.ll (+2-2) - (modified) llvm/test/CodeGen/RISCV/attributes.ll (+2-2) - (modified) llvm/test/CodeGen/RISCV/module-elf-flags.ll (+1-1) - (modified) llvm/test/MC/RISCV/Ztso.s (+2-2) - (modified) llvm/test/MC/RISCV/attribute-arch.s (+2-2) - (modified) llvm/test/MC/RISCV/elf-flags.s (+2-2) - (modified) llvm/unittests/TargetParser/RISCVISAInfoTest.cpp (+23-23) ``diff diff --git a/clang/test/Driver/riscv-arch.c b/clang/test/Driver/riscv-arch.c index ffd92e1f398c4..c3c471c4bc396 100644 --- a/clang/test/Driver/riscv-arch.c +++ b/clang/test/Driver/riscv-arch.c @@ -365,24 +365,30 @@ // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-ZFHMIN %s // RV32-ZFHMIN: "-target-feature" "+zfhmin" -// RUN: not %clang --target=riscv32-unknown-elf -march=rv32iztso -### %s \ +// RUN: not %clang --target=riscv32-unknown-elf -march=rv32izalasr -### %s \ // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-NOFLAG %s -// RV32-EXPERIMENTAL-NOFLAG: error: invalid arch name 'rv32iztso' +// RV32-EXPERIMENTAL-NOFLAG: error: invalid arch name 'rv32izalasr' // RV32-EXPERIMENTAL-NOFLAG: requires '-menable-experimental-extensions' -// RUN: not %clang --target=riscv32-unknown-elf -march=rv32iztso -menable-experimental-extensions -### %s \ +// RUN: not %clang --target=riscv32-unknown-elf -march=rv32izalasr -menable-experimental-extensions -### %s \ // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-NOVERS %s -// RV32-EXPERIMENTAL-NOVERS: error: invalid arch name 'rv32iztso' +// RV32-EXPERIMENTAL-NOVERS: error: invalid arch name 'rv32izalasr' // RV32-EXPERIMENTAL-NOVERS: experimental extension requires explicit version number -// RUN: not %clang --target=riscv32-unknown-elf -march=rv32iztso0p7 -menable-experimental-extensions -### %s \ +// RUN: not %clang --target=riscv32-unknown-elf -march=rv32izalasr0p7 -menable-experimental-extensions -### %s \ // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-BADVERS %s -// RV32-EXPERIMENTAL-BADVERS: error: invalid arch name 'rv32iztso0p7' -// RV32-EXPERIMENTAL-BADVERS: unsupported version number 0.7 for experimental extension 'ztso' (this compiler supports 0.1) +// RV32-EXPERIMENTAL-BADVERS: error: invalid arch name 'rv32izalasr0p7' +// RV32-EXPERIMENTAL-BADVERS: unsupported version number 0.7 for experimental extension 'zalasr' (this compiler supports 0.1) -// RUN: %clang --target=riscv32-unknown-elf -march=rv32iztso0p1 -menable-experimental-extensions -### %s \ +// RUN: %clang --target=riscv32-unknown-elf -march=rv32izalasr0p1 -menable-experimental-extensions -### %s \ // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-GOODVERS %s -// RV32-EXPERIMENTAL-GOODVERS: "-target-feature" "+experimental-ztso" +// RV32-EXPERIMENTAL-GOODVERS: "-target-feature" "+experimental-zalasr" + +// RUN: %clang --target=riscv32-unknown-elf -march=rv32iztso1p0 -### %s \ +// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-ZTSO %s +// RUN: %clang --target=riscv32-unknown-elf -march=rv32iztso -### %s \ +// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-ZTSO %s +// RV32-ZTSO: "-target-feature" "+ztso" // RUN: %clang --target=riscv32-unknown-elf -march=rv32izbb1p0 -### %s \ // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-ZBB %s diff --git a/clang/test/Preprocessor/riscv-target-features.c b/clang/test/Preprocessor/riscv-target-features.c index d7935af532dfa..46a61e3c0afc7 100644 --- a/clang/test/Preprocessor/riscv-target-features.c +++ b/clang/test/Preprocessor/riscv-target-features.c @@ -1650,13 +1650,13 @@ // RUN: -o - | FileCheck --check-prefix=CHECK-ZICFILP-EXT %s // CHECK-ZICFILP-EXT: __riscv_zicfilp 4000{{$}} -// RUN: %clang --target=riscv32-unknown-linux-gnu -menable-experimental-extensions \ -// RUN: -march=rv32iztso0p1 -E -dM %s \ +// RUN: %clang --target=riscv32-unknown-linux-gnu \ +// RUN: -march=rv32iztso1p0 -E -dM %s \ // RUN: -o - | FileChe
[clang] [llvm] [RISCV] Add support for getHostCPUFeatures using hwprobe (PR #94352)
dtcxzyw wrote: See https://github.com/llvm/llvm-project/pull/96465 https://github.com/llvm/llvm-project/pull/94352 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] 6479604 - [CMake][libclc] Improve dependencies to avoid build errors (#95018)
Author: Tim Creech Date: 2024-06-24T09:51:34+01:00 New Revision: 64796044f4152c49e4b3c797390a83dcfd33bd46 URL: https://github.com/llvm/llvm-project/commit/64796044f4152c49e4b3c797390a83dcfd33bd46 DIFF: https://github.com/llvm/llvm-project/commit/64796044f4152c49e4b3c797390a83dcfd33bd46.diff LOG: [CMake][libclc] Improve dependencies to avoid build errors (#95018) With the Makefile generator and particularly high build parallelism some intermediate dependencies may be generated redundantly and concurrently, leading to build failures. To fix this, arrange for libclc's add_custom_commands to depend on targets in addition to files. This follows CMake documentation's[^1] guidance on add_custom_command: > Do not list the output in more than one independent target that may > build in parallel or the instances of the rule may conflict. Instead, > use the add_custom_target() command to drive the command and make the > other targets depend on that one. Eliminating the redundant commands also improves build times. [^1]: https://cmake.org/cmake/help/v3.29/command/add_custom_command.html Added: Modified: libclc/CMakeLists.txt libclc/cmake/modules/AddLibclc.cmake Removed: diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt index 9858ae905983f..ef8d21b167623 100644 --- a/libclc/CMakeLists.txt +++ b/libclc/CMakeLists.txt @@ -374,15 +374,21 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} ) OUTPUT ${output_file} EXTRA_OPTS "${mcpu}" -fno-builtin -nostdlib "${build_flags}" -I${PROJECT_SOURCE_DIR}/${file_dir} +DEPENDENCIES generate_convert.cl clspv-generate_convert.cl ) list( APPEND bytecode_files ${output_file} ) endforeach() -set( builtins_link_lib_tgt builtins.link.${arch_suffix} ) +set( builtins_comp_lib_tgt builtins.comp.${arch_suffix} ) +add_custom_target( ${builtins_comp_lib_tgt} + DEPENDS ${bytecode_files} +) +set( builtins_link_lib_tgt builtins.link.${arch_suffix} ) link_bc( TARGET ${builtins_link_lib_tgt} INPUTS ${bytecode_files} + DEPENDENCIES ${builtins_comp_lib_tgt} ) set( builtins_link_lib $ ) @@ -391,7 +397,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} ) set( spv_suffix ${arch_suffix}.spv ) add_custom_command( OUTPUT ${spv_suffix} COMMAND libclc::llvm-spirv ${spvflags} -o ${spv_suffix} ${builtins_link_lib} -DEPENDS ${builtins_link_lib} +DEPENDS ${builtins_link_lib} ${builtins_link_lib_tgt} ) add_custom_target( "prepare-${spv_suffix}" ALL DEPENDS "${spv_suffix}" ) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${spv_suffix} @@ -403,7 +409,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} ) add_custom_command( OUTPUT ${builtins_opt_lib_tgt}.bc COMMAND libclc::opt ${opt_flags} -o ${builtins_opt_lib_tgt}.bc ${builtins_link_lib} -DEPENDS libclc::opt ${builtins_link_lib} +DEPENDS libclc::opt ${builtins_link_lib} ${builtins_link_lib_tgt} ) add_custom_target( ${builtins_opt_lib_tgt} ALL DEPENDS ${builtins_opt_lib_tgt}.bc @@ -418,7 +424,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} ) set( obj_suffix ${arch_suffix}.bc ) add_custom_command( OUTPUT ${obj_suffix} COMMAND prepare_builtins -o ${obj_suffix} ${builtins_opt_lib} -DEPENDS ${builtins_opt_lib} prepare_builtins ) +DEPENDS ${builtins_opt_lib} ${builtins_opt_lib_tgt} prepare_builtins ) add_custom_target( prepare-${obj_suffix} ALL DEPENDS ${obj_suffix} ) # nvptx-- targets don't include workitem builtins diff --git a/libclc/cmake/modules/AddLibclc.cmake b/libclc/cmake/modules/AddLibclc.cmake index 7f4620fa6a21d..ea97e504364ba 100644 --- a/libclc/cmake/modules/AddLibclc.cmake +++ b/libclc/cmake/modules/AddLibclc.cmake @@ -80,11 +80,13 @@ endfunction() # Custom target to create # * INPUT ... # List of bytecode files to link together +# * DEPENDENCIES ... +# List of extra dependencies to inject function(link_bc) cmake_parse_arguments(ARG "" "TARGET" -"INPUTS" +"INPUTS;DEPENDENCIES" ${ARGN} ) @@ -106,7 +108,7 @@ function(link_bc) add_custom_command( OUTPUT ${ARG_TARGET}.bc COMMAND libclc::llvm-link -o ${ARG_TARGET}.bc ${LINK_INPUT_ARG} -DEPENDS libclc::llvm-link ${ARG_INPUTS} ${RSP_FILE} +DEPENDS libclc::llvm-link ${ARG_DEPENDENCIES} ${ARG_INPUTS} ${RSP_FILE} ) add_custom_target( ${ARG_TARGET} ALL DEPENDS ${ARG_TARGET}.bc ) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [CMake][libclc] Improve dependencies to avoid build errors (PR #95018)
https://github.com/frasercrmck closed https://github.com/llvm/llvm-project/pull/95018 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 2232881 - [C++20] [Modules] Avoid comparing primary module name to decide isInSameModule all the time
Author: Chuanqi Xu Date: 2024-06-24T16:55:17+08:00 New Revision: 2232881736f1a7e3e94ee1123dea1b6cd85a9c3a URL: https://github.com/llvm/llvm-project/commit/2232881736f1a7e3e94ee1123dea1b6cd85a9c3a DIFF: https://github.com/llvm/llvm-project/commit/2232881736f1a7e3e94ee1123dea1b6cd85a9c3a.diff LOG: [C++20] [Modules] Avoid comparing primary module name to decide isInSameModule all the time Previously, we decide if two module units are in the same module by comparing name of the primary module interface. But it looks not efficiency if we always compare the strings. It should be good to avoid the expensive string operations if possible. In this patch, we introduced a `llvm::StringMap` to map primary module name to a Module* and a `llvm::DenseMap` to map a Module* to a representative Module *. The representative Module* is one of the Module units belonging to a certain module. The module units have the same representative Module* should belong to the same module. We choose the representative Module* by the first module lookup for a certain primary module name. So the following module units have the same primary module name would get the same representative modules. So that for every modules, there will be only one hash process for the primary module name. Added: Modified: clang/include/clang/AST/ASTContext.h clang/lib/AST/ASTContext.cpp Removed: diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index 46fe2d23e9334..7aa1357b9aad0 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -467,6 +467,14 @@ class ASTContext : public RefCountedBase { /// This is the top-level (C++20) Named module we are building. Module *CurrentCXXNamedModule = nullptr; + /// Help structures to decide whether two `const Module *` belongs + /// to the same conceptual module to avoid the expensive to string comparison + /// if possible. + /// + /// Not serialized intentionally. + llvm::StringMap PrimaryModuleNameMap; + llvm::DenseMap SameModuleLookupSet; + static constexpr unsigned ConstantArrayTypesLog2InitSize = 8; static constexpr unsigned GeneralTypesLog2InitSize = 9; static constexpr unsigned FunctionProtoTypesLog2InitSize = 12; diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 6aed55a92364b..be24c161d6714 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -1114,9 +1114,25 @@ bool ASTContext::isInSameModule(const Module *M1, const Module *M2) { if (!M1 != !M2) return false; + /// Get the representative module for M. The representative module is the + /// first module unit for a specific primary module name. So that the module + /// units have the same representative module belongs to the same module. + /// + /// The process is helpful to reduce the expensive string operations. + auto GetRepresentativeModule = [this](const Module *M) { +auto Iter = SameModuleLookupSet.find(M); +if (Iter != SameModuleLookupSet.end()) + return Iter->second; + +const Module *RepresentativeModule = +PrimaryModuleNameMap.try_emplace(M->getPrimaryModuleInterfaceName(), M) +.first->second; +SameModuleLookupSet[M] = RepresentativeModule; +return RepresentativeModule; + }; + assert(M1 && "Shouldn't call `isInSameModule` if both M1 and M2 are none."); - return M1->getPrimaryModuleInterfaceName() == - M2->getPrimaryModuleInterfaceName(); + return GetRepresentativeModule(M1) == GetRepresentativeModule(M2); } ExternCContextDecl *ASTContext::getExternCContextDecl() const { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Remove experimental from Ztso. (PR #96465)
https://github.com/kito-cheng approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/96465 ___ 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: LGTM > There is also TokenKind: this one does not currently inherit from > BaseEnumeration and is defined somewhat differently, having all its variants > and their IDs as a dictionary in enumerations.py. This seems quite arbitrary > to me, is there any reason it is done this way? Otherwise I would also move > this to cindex.py as another subclass of BaseEnumeration I agree that this seems arbitrary. You think you can proceed with refactoring `TokenKind`. 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)
Endilll wrote: > @Endilll are you taking a look at this, and/or should I ask other reviewers? It's never a bad idea to add more reviewers, as long as they are relevant. 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] [clang][AArch64][FMV] Stop emitting alias to ifunc. (PR #96221)
https://github.com/labrinea updated https://github.com/llvm/llvm-project/pull/96221 >From 4b884669236cae2d5ac42a95517d9ce57060a494 Mon Sep 17 00:00:00 2001 From: Alexandros Lamprineas Date: Thu, 20 Jun 2024 17:40:44 +0100 Subject: [PATCH 1/2] [clang][AArch64][FMV] Stop emitting alias to ifunc. Long story short the interaction of two optimizations happening in GlobalOpt results in a crash. For more details look at the issue https://github.com/llvm/llvm-project/issues/96197. I will be fixing this in GlobalOpt but it is a conservative solution since it won't allow us to optimize resolvers which return a pointer to a function whose definition is in another TU when compiling without LTO: __attribute__((target_version("simd"))) void bar(void); __attribute__((target_version("default"))) void bar(void); int foo() { bar(); } --- clang/lib/CodeGen/CodeGenModule.cpp | 4 ++-- .../CodeGen/aarch64-mixed-target-attributes.c| 3 --- clang/test/CodeGen/attr-target-clones-aarch64.c | 16 clang/test/CodeGen/attr-target-version.c | 13 - .../CodeGenCXX/attr-target-clones-aarch64.cpp| 4 clang/test/CodeGenCXX/attr-target-version.cpp| 6 -- clang/test/CodeGenCXX/fmv-namespace.cpp | 2 -- 7 files changed, 2 insertions(+), 46 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index dd4a665ebc78b..76534475e88f7 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -4259,8 +4259,8 @@ void CodeGenModule::emitMultiVersionFunctions() { llvm::Constant *ResolverConstant = GetOrCreateMultiVersionResolver(GD); if (auto *IFunc = dyn_cast(ResolverConstant)) { ResolverConstant = IFunc->getResolver(); - if (FD->isTargetClonesMultiVersion() || - FD->isTargetVersionMultiVersion()) { + if (FD->isTargetClonesMultiVersion() && + !getTarget().getTriple().isAArch64()) { std::string MangledName = getMangledNameImpl( *this, GD, FD, /*OmitMultiVersionMangling=*/true); if (!GetGlobalValue(MangledName + ".ifunc")) { diff --git a/clang/test/CodeGen/aarch64-mixed-target-attributes.c b/clang/test/CodeGen/aarch64-mixed-target-attributes.c index 6aa747d4cb461..3c047fec6ceed 100644 --- a/clang/test/CodeGen/aarch64-mixed-target-attributes.c +++ b/clang/test/CodeGen/aarch64-mixed-target-attributes.c @@ -30,9 +30,6 @@ __attribute__((target_version("jscvt"))) int default_def_with_version_decls(void //. // CHECK: @__aarch64_cpu_features = external dso_local global { i64 } -// CHECK: @explicit_default.ifunc = weak_odr alias i32 (), ptr @explicit_default -// CHECK: @implicit_default.ifunc = weak_odr alias i32 (), ptr @implicit_default -// CHECK: @default_def_with_version_decls.ifunc = weak_odr alias i32 (), ptr @default_def_with_version_decls // CHECK: @explicit_default = weak_odr ifunc i32 (), ptr @explicit_default.resolver // CHECK: @implicit_default = weak_odr ifunc i32 (), ptr @implicit_default.resolver // CHECK: @default_def_with_version_decls = weak_odr ifunc i32 (), ptr @default_def_with_version_decls.resolver diff --git a/clang/test/CodeGen/attr-target-clones-aarch64.c b/clang/test/CodeGen/attr-target-clones-aarch64.c index ad6079a91fcd5..60f9c7f1fc24e 100644 --- a/clang/test/CodeGen/attr-target-clones-aarch64.c +++ b/clang/test/CodeGen/attr-target-clones-aarch64.c @@ -27,14 +27,6 @@ inline int __attribute__((target_clones("fp16", "sve2-bitperm+fcma", "default")) //. // CHECK: @__aarch64_cpu_features = external dso_local global { i64 } -// CHECK: @ftc.ifunc = weak_odr alias i32 (), ptr @ftc -// CHECK: @ftc_def.ifunc = weak_odr alias i32 (), ptr @ftc_def -// CHECK: @ftc_dup1.ifunc = weak_odr alias i32 (), ptr @ftc_dup1 -// CHECK: @ftc_dup2.ifunc = weak_odr alias i32 (), ptr @ftc_dup2 -// CHECK: @ftc_dup3.ifunc = weak_odr alias i32 (), ptr @ftc_dup3 -// CHECK: @ftc_inline2.ifunc = weak_odr alias i32 (), ptr @ftc_inline2 -// CHECK: @ftc_inline1.ifunc = weak_odr alias i32 (), ptr @ftc_inline1 -// CHECK: @ftc_inline3.ifunc = weak_odr alias i32 (), ptr @ftc_inline3 // CHECK: @ftc = weak_odr ifunc i32 (), ptr @ftc.resolver // CHECK: @ftc_def = weak_odr ifunc i32 (), ptr @ftc_def.resolver // CHECK: @ftc_dup1 = weak_odr ifunc i32 (), ptr @ftc_dup1.resolver @@ -45,14 +37,6 @@ inline int __attribute__((target_clones("fp16", "sve2-bitperm+fcma", "default")) // CHECK: @ftc_inline3 = weak_odr ifunc i32 (), ptr @ftc_inline3.resolver //. // CHECK-MTE-BTI: @__aarch64_cpu_features = external dso_local global { i64 } -// CHECK-MTE-BTI: @ftc.ifunc = weak_odr alias i32 (), ptr @ftc -// CHECK-MTE-BTI: @ftc_def.ifunc = weak_odr alias i32 (), ptr @ftc_def -// CHECK-MTE-BTI: @ftc_dup1.ifunc = weak_odr alias i32 (), ptr @ftc_dup1 -// CHECK-MTE-BTI: @ftc_dup2.ifunc = weak_odr alias i32 (), ptr @ftc_dup2 -// CHECK-MTE-BTI: @ftc_dup3.ifunc = weak_odr alias i32 (), ptr @ftc_dup3 -// CHECK-MTE-BTI: @ftc_in
[clang] 2151ba0 - [Docs][Clang] Missing DR status for C++23-era papers in cxx_status.html (#68846)
Author: A. Jiang Date: 2024-06-24T13:16:47+04:00 New Revision: 2151ba036213705346553e759fc4e095547989d1 URL: https://github.com/llvm/llvm-project/commit/2151ba036213705346553e759fc4e095547989d1 DIFF: https://github.com/llvm/llvm-project/commit/2151ba036213705346553e759fc4e095547989d1.diff LOG: [Docs][Clang] Missing DR status for C++23-era papers in cxx_status.html (#68846) List the following C++23-era WG21 papers as Defect Reports in cxx_status.html as per WG21 meeting minutes. - [P1949R7](https://wg21.link/p1949r7) (C++ Identifier Syntax using Unicode Standard Annex 31) - [P2156R1](https://wg21.link/p2156r1) (Allow Duplicate Attributes) - [P2036R3](https://wg21.link/p2036r3) (Change scope of lambda _trailing-return-type_) - [P2468R2](https://wg21.link/p2468r2) (The Equality Operator You Are Looking For) - [P2327R1](https://wg21.link/p2327r1) (De-deprecating `volatile` compound operations) - [P2493R0](https://wg21.link/p2493r0) (Missing feature test macros for C++20 core papers) - [P2513R3](https://wg21.link/p2513r3) (`char8_t` Compatibility and Portability Fix) - [P2460R2](https://wg21.link/p2460r2) (Relax requirements on `wchar_t` to match existing practices) - [P2579R0](https://wg21.link/p2579r0) (Mitigation strategies for [P2036](https://wg21.link/p2036) ”Changing scope for lambda _trailing-return-type_”) Added: Modified: clang/www/cxx_status.html Removed: diff --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html index 65dd31a0fb802..3ae9f5cb65ba8 100755 --- a/clang/www/cxx_status.html +++ b/clang/www/cxx_status.html @@ -247,7 +247,7 @@ C++23 implementation status Allow duplicate attributes - https://wg21.link/P2156R1";>P2156R1 + https://wg21.link/P2156R1";>P2156R1 (DR) Clang 13 @@ -267,7 +267,7 @@ C++23 implementation status C++ identifier syntax using UAX 31 - https://wg21.link/P1949R7";>P1949R7 + https://wg21.link/P1949R7";>P1949R7 (DR) Clang 14 @@ -287,11 +287,11 @@ C++23 implementation status Change scope of lambda trailing-return-type - https://wg21.link/P2036R3";>P2036R3 + https://wg21.link/P2036R3";>P2036R3 (DR) Clang 17 - https://wg21.link/P2579R0";>P2579R0 + https://wg21.link/P2579R0";>P2579R0 (DR) Multidimensional subscript operator @@ -352,12 +352,12 @@ C++23 implementation status The Equality Operator You Are Looking For - https://wg21.link/P2468R2";>P2468R2 + https://wg21.link/P2468R2";>P2468R2 (DR) Clang 16 De-deprecating volatile compound operations - https://wg21.link/P2327R1";>P2327R1 + https://wg21.link/P2327R1";>P2327R1 (DR) Clang 15 @@ -422,12 +422,12 @@ C++23 implementation status char8_t Compatibility and Portability Fix - https://wg21.link/P2513R3";>P2513R3 + https://wg21.link/P2513R3";>P2513R3 (DR) Clang 16 Relax requirements on wchar_t to match existing practices - https://wg21.link/P2460R2";>P2460R2 + https://wg21.link/P2460R2";>P2460R2 (DR) Yes @@ -563,7 +563,7 @@ C++20 implementation status https://wg21.link/p2103r0";>P2103R0 -https://wg21.link/p2493r0";>P2493R0 +https://wg21.link/p2493r0";>P2493R0 (DR) https://wg21.link/p2092r0";>P2092R0 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Docs][Clang] Missing DR status for C++23-era papers in cxx_status.html (PR #68846)
https://github.com/Endilll closed https://github.com/llvm/llvm-project/pull/68846 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [SourceManager] Expose max usage of source location space as a Statistic (PR #96292)
usx95 wrote: This is a simple enough patch, so I agree we can deal with concerns post-commit as well. Let's go ahead with landing this then. https://github.com/llvm/llvm-project/pull/96292 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Docs][Clang] Missing DR status for C++23-era papers in cxx_status.html (PR #68846)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `clang-cuda-l4` running on `cuda-l4-0` while building `clang` at step 3 "annotate". Full details are available at: https://lab.llvm.org/buildbot/#/builders/101/builds/581 Here is the relevant piece of the build log for the reference: ``` Step 3 (annotate) failure: '/buildbot/cuda-build --jobs=' (failure) ... + echo @@@STEP_SUMMARY_TEXT @@@BUILD_STEP Testing CUDA test-suite@@@ @@@STEP_SUMMARY_CLEAR@@@ @@@STEP_SUMMARY_TEXT + run ninja check-cuda-simple + echo '>>> ' ninja check-cuda-simple + ninja check-cuda-simple >>> ninja check-cuda-simple [0/40] cd /buildbot/cuda-l4-0/work/clang-cuda-l4/build/External/CUDA && /usr/local/bin/lit -vv -j 1 assert-cuda-11.8-c++11-libc++.test axpy-cuda-11.8-c++11-libc++.test algorithm-cuda-11.8-c++11-libc++.test cmath-cuda-11.8-c++11-libc++.test complex-cuda-11.8-c++11-libc++.test math_h-cuda-11.8-c++11-libc++.test new-cuda-11.8-c++11-libc++.test empty-cuda-11.8-c++11-libc++.test printf-cuda-11.8-c++11-libc++.test future-cuda-11.8-c++11-libc++.test builtin_var-cuda-11.8-c++11-libc++.test test_round-cuda-11.8-c++11-libc++.test -- Testing: 12 tests, 1 workers -- FAIL: test-suite :: External/CUDA/algorithm-cuda-11.8-c++11-libc++.test (1 of 12) TEST 'test-suite :: External/CUDA/algorithm-cuda-11.8-c++11-libc++.test' FAILED /buildbot/cuda-l4-0/work/clang-cuda-l4/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/cuda-l4-0/work/clang-cuda-l4/build/External/CUDA/Output/algorithm-cuda-11.8-c++11-libc++.test.out --redirect-input /dev/null --summary /buildbot/cuda-l4-0/work/clang-cuda-l4/build/External/CUDA/Output/algorithm-cuda-11.8-c++11-libc++.test.time /buildbot/cuda-l4-0/work/clang-cuda-l4/build/External/CUDA/algorithm-cuda-11.8-c++11-libc++ cd /buildbot/cuda-l4-0/work/clang-cuda-l4/build/External/CUDA ; /buildbot/cuda-l4-0/work/clang-cuda-l4/build/tools/fpcmp-target /buildbot/cuda-l4-0/work/clang-cuda-l4/build/External/CUDA/Output/algorithm-cuda-11.8-c++11-libc++.test.out algorithm.reference_output-cuda-11.8-c++11-libc++ + cd /buildbot/cuda-l4-0/work/clang-cuda-l4/build/External/CUDA + /buildbot/cuda-l4-0/work/clang-cuda-l4/build/tools/fpcmp-target /buildbot/cuda-l4-0/work/clang-cuda-l4/build/External/CUDA/Output/algorithm-cuda-11.8-c++11-libc++.test.out algorithm.reference_output-cuda-11.8-c++11-libc++ /buildbot/cuda-l4-0/work/clang-cuda-l4/build/tools/fpcmp-target: Comparison failed, textual difference between 'C' and 'S' FAIL: test-suite :: External/CUDA/assert-cuda-11.8-c++11-libc++.test (2 of 12) TEST 'test-suite :: External/CUDA/assert-cuda-11.8-c++11-libc++.test' FAILED /buildbot/cuda-l4-0/work/clang-cuda-l4/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/cuda-l4-0/work/clang-cuda-l4/build/External/CUDA/Output/assert-cuda-11.8-c++11-libc++.test.out --redirect-input /dev/null --summary /buildbot/cuda-l4-0/work/clang-cuda-l4/build/External/CUDA/Output/assert-cuda-11.8-c++11-libc++.test.time /buildbot/cuda-l4-0/work/clang-cuda-l4/build/External/CUDA/assert-cuda-11.8-c++11-libc++ cd /buildbot/cuda-l4-0/work/clang-cuda-l4/build/External/CUDA ; /buildbot/cuda-l4-0/work/clang-cuda-l4/build/tools/fpcmp-target /buildbot/cuda-l4-0/work/clang-cuda-l4/build/External/CUDA/Output/assert-cuda-11.8-c++11-libc++.test.out assert.reference_output-cuda-11.8-c++11-libc++ + cd /buildbot/cuda-l4-0/work/clang-cuda-l4/build/External/CUDA + /buildbot/cuda-l4-0/work/clang-cuda-l4/build/tools/fpcmp-target /buildbot/cuda-l4-0/work/clang-cuda-l4/build/External/CUDA/Output/assert-cuda-11.8-c++11-libc++.test.out assert.reference_output-cuda-11.8-c++11-libc++ /buildbot/cuda-l4-0/work/clang-cuda-l4/build/tools/fpcmp-target: Comparison failed, textual difference between 'e' and 'a' FAIL: test-suite :: External/CUDA/axpy-cuda-11.8-c++11-libc++.test (3 of 12) TEST 'test-suite :: External/CUDA/axpy-cuda-11.8-c++11-libc++.test' FAILED /buildbot/cuda-l4-0/work/clang-cuda-l4/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/cuda-l4-0/work/clang-cuda-l4/build/External/CUDA/Output/axpy-cuda-11.8-c++11-libc++.test.out --redirect-input /dev/null --summary /buildbot/cuda-l4-0/work/clang-cuda-l4/build/External/CUDA/Output/axpy-cuda-11.8-c++11-libc++.test.time /buildbot/cuda-l4-0/work/clang-cuda-l4/build/External/CUDA/axpy-cuda-11.8-c++11-libc++ cd /buildbot/cuda-l4-0/work/clang-cuda-l4/build/External/CUDA ; /buildbot/cuda-l4-0/work/clang-cuda-l4/build
[clang] [Docs][Clang] Missing DR status for C++23-era papers in cxx_status.html (PR #68846)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `clang-cuda-t4` running on `cuda-t4-0` while building `clang` at step 3 "annotate". Full details are available at: https://lab.llvm.org/buildbot/#/builders/69/builds/563 Here is the relevant piece of the build log for the reference: ``` Step 3 (annotate) failure: '/buildbot/cuda-build --jobs=' (failure) ... [ RUN ] LlvmLibcBlockStoreTest.Empty [ OK ] LlvmLibcBlockStoreTest.Empty (62 us) Ran 9 tests. PASS: 9 FAIL: 0 [559/1022] Linking CXX executable libc/test/src/math/smoke/libc.test.src.math.smoke.sqrt_test.__hermetic__.__build__ [560/1022] Linking CXX executable libc/test/src/math/smoke/libc.test.src.math.smoke.generic_sqrtf_test.__hermetic__.__build__ [561/1022] Linking CXX executable libc/test/src/math/smoke/libc.test.src.math.smoke.fmax_test.__hermetic__.__build__ [562/1022] Linking CXX executable libc/test/src/math/smoke/libc.test.src.math.smoke.sqrtf_test.__hermetic__.__build__ [563/1022] Linking CXX executable libc/test/src/math/smoke/libc.test.src.math.smoke.generic_sqrt_test.__hermetic__.__build__ [564/1022] Linking CXX executable libc/test/src/math/smoke/libc.test.src.math.smoke.fma_test.__hermetic__.__build__ [565/1022] Running hermetic test libc.test.src.__support.freelist_test.__hermetic__ FAILED: libc/test/src/__support/CMakeFiles/libc.test.src.__support.freelist_test.__hermetic__ /buildbot/cuda-t4-0/work/clang-cuda-t4/build-libc/libc/test/src/__support/CMakeFiles/libc.test.src.__support.freelist_test.__hermetic__ cd /buildbot/cuda-t4-0/work/clang-cuda-t4/build-libc/libc/test/src/__support && /buildbot/cuda-t4-0/work/clang-cuda-t4/clang/bin/nvptx-loader /buildbot/cuda-t4-0/work/clang-cuda-t4/build-libc/libc/test/src/__support/libc.test.src.__support.freelist_test.__hermetic__.__build__ [==] Running 9 tests from 1 test suite. [ RUN ] LlvmLibcFreeList.EmptyListHasNoMembers [ OK ] LlvmLibcFreeList.EmptyListHasNoMembers (7 us) [ RUN ] LlvmLibcFreeList.CanRetrieveAddedMember [ OK ] LlvmLibcFreeList.CanRetrieveAddedMember (14 us) [ RUN ] LlvmLibcFreeList.CanRetrieveAddedMemberForSmallerSize [ OK ] LlvmLibcFreeList.CanRetrieveAddedMemberForSmallerSize (13 us) [ RUN ] LlvmLibcFreeList.CanRemoveItem [ OK ] LlvmLibcFreeList.CanRemoveItem (11 us) [ RUN ] LlvmLibcFreeList.FindReturnsSmallestChunk [ OK ] LlvmLibcFreeList.FindReturnsSmallestChunk (31 us) [ RUN ] LlvmLibcFreeList.FindReturnsCorrectChunkInSameBucket [ OK ] LlvmLibcFreeList.FindReturnsCorrectChunkInSameBucket (15 us) [ RUN ] LlvmLibcFreeList.FindCanMoveUpThroughBuckets /ssd/cuda-builder/work/llvm-project/libc/utils/gpu/loader/nvptx/Loader.cpp:339:0: Error: misaligned address [566/1022] Linking CXX executable libc/test/src/math/smoke/libc.test.src.math.smoke.generic_sqrtl_test.__hermetic__.__build__ [567/1022] Linking CXX executable libc/test/src/math/smoke/libc.test.src.math.smoke.nearbyintf_test.__hermetic__.__build__ [568/1022] Linking CXX executable libc/test/src/math/smoke/libc.test.src.math.smoke.nearbyint_test.__hermetic__.__build__ [569/1022] Linking CXX executable libc/test/src/math/smoke/libc.test.src.math.smoke.asinhf_test.__hermetic__.__build__ [570/1022] Linking CXX executable libc/test/src/stdbit/libc.test.src.stdbit.stdc_leading_zeros_us_test.__hermetic__.__build__ [571/1022] Linking CXX executable libc/test/src/stdbit/libc.test.src.stdbit.stdc_leading_zeros_uc_test.__hermetic__.__build__ [572/1022] Linking CXX executable libc/test/src/stdbit/libc.test.src.stdbit.stdc_leading_zeros_ull_test.__hermetic__.__build__ [573/1022] Linking CXX executable libc/test/src/stdbit/libc.test.src.stdbit.stdc_leading_zeros_ui_test.__hermetic__.__build__ [574/1022] Linking CXX executable libc/test/src/stdbit/libc.test.src.stdbit.stdc_leading_zeros_ul_test.__hermetic__.__build__ ninja: build stopped: subcommand failed. ++ err=1 ++ echo PID 75441: subprocess exited with error 1 ++ exit 1 PID 75441: subprocess exited with error 1 + step_failure + echo @@@STEP_FAILURE@@@ @@@STEP_FAILURE@@@ Step 12 (Testing GPU libc) failure: (failure) ... [ RUN ] LlvmLibcBlockStoreTest.Empty [ OK ] LlvmLibcBlockStoreTest.Empty (62 us) Ran 9 tests. PASS: 9 FAIL: 0 [559/1022] Linking CXX executable libc/test/src/math/smoke/libc.test.src.math.smoke.sqrt_test.__hermetic__.__build__ [560/1022] Linking CXX executable libc/test/src/math/smoke/libc.test.src.math.smoke.generic_sqrtf_test.__hermetic__.__build__ [561/1022] Linking CXX executable libc/test/src/math/smoke/libc.test.src.math.smoke.fmax_test.__hermetic__.__build__ [562/1022] Linking CXX executable libc/test/src/math/smoke/libc.test.src.math.smoke.sqrtf_test.__hermetic__.__build__ [563/1022] Linking CXX executable libc/test/src/math/smoke/libc.test.src.math.smoke.generic_sqrt_test.__hermetic__.__build__ [564/1022] Linking CXX executable libc/test/src/math/smoke/libc.test.src.math.smoke.fma_test.__hermetic__.__b
[clang] [Docs][Clang] Missing DR status for C++23-era papers in cxx_status.html (PR #68846)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `clang-cuda-p4` running on `cuda-p4-0` while building `clang` at step 3 "annotate". Full details are available at: https://lab.llvm.org/buildbot/#/builders/15/builds/582 Here is the relevant piece of the build log for the reference: ``` Step 3 (annotate) failure: '/buildbot/cuda-build --jobs=' (failure) ... Ran 9 tests. PASS: 9 FAIL: 0 [638/1022] Linking CXX executable libc/test/src/stdlib/libc.test.src.stdlib.strtold_test.__hermetic__.__build__ [639/1022] Linking CXX executable libc/test/src/stdlib/libc.test.src.stdlib.strtof_test.__hermetic__.__build__ [640/1022] Linking CXX executable libc/test/src/stdlib/libc.test.src.stdlib.strtol_test.__hermetic__.__build__ [641/1022] Linking CXX executable libc/test/src/stdlib/libc.test.src.stdlib.strtoll_test.__hermetic__.__build__ [642/1022] Linking CXX executable libc/test/src/stdlib/libc.test.src.stdlib.strtoul_test.__hermetic__.__build__ [643/1022] Linking CXX executable libc/test/src/stdlib/libc.test.src.stdlib.strtoull_test.__hermetic__.__build__ [644/1022] Building CXX object libc/test/src/stdlib/CMakeFiles/libc.test.src.stdlib.labs_test.__hermetic__.__build__.dir/labs_test.cpp.o [645/1022] Linking CXX executable libc/test/src/stdlib/libc.test.src.stdlib.labs_test.__hermetic__.__build__ [646/1022] Running hermetic test libc.test.src.__support.freelist_test.__hermetic__ FAILED: libc/test/src/__support/CMakeFiles/libc.test.src.__support.freelist_test.__hermetic__ /buildbot/cuda-p4-0/work/clang-cuda-p4/build-libc/libc/test/src/__support/CMakeFiles/libc.test.src.__support.freelist_test.__hermetic__ cd /buildbot/cuda-p4-0/work/clang-cuda-p4/build-libc/libc/test/src/__support && /buildbot/cuda-p4-0/work/clang-cuda-p4/clang/bin/nvptx-loader /buildbot/cuda-p4-0/work/clang-cuda-p4/build-libc/libc/test/src/__support/libc.test.src.__support.freelist_test.__hermetic__.__build__ [==] Running 9 tests from 1 test suite. [ RUN ] LlvmLibcFreeList.EmptyListHasNoMembers [ OK ] LlvmLibcFreeList.EmptyListHasNoMembers (7 us) [ RUN ] LlvmLibcFreeList.CanRetrieveAddedMember [ OK ] LlvmLibcFreeList.CanRetrieveAddedMember (15 us) [ RUN ] LlvmLibcFreeList.CanRetrieveAddedMemberForSmallerSize [ OK ] LlvmLibcFreeList.CanRetrieveAddedMemberForSmallerSize (13 us) [ RUN ] LlvmLibcFreeList.CanRemoveItem [ OK ] LlvmLibcFreeList.CanRemoveItem (13 us) [ RUN ] LlvmLibcFreeList.FindReturnsSmallestChunk [ OK ] LlvmLibcFreeList.FindReturnsSmallestChunk (34 us) [ RUN ] LlvmLibcFreeList.FindReturnsCorrectChunkInSameBucket [ OK ] LlvmLibcFreeList.FindReturnsCorrectChunkInSameBucket (15 us) [ RUN ] LlvmLibcFreeList.FindCanMoveUpThroughBuckets /ssd/cuda-builder/work/llvm-project/libc/utils/gpu/loader/nvptx/Loader.cpp:339:0: Error: misaligned address [647/1022] Building CXX object libc/test/src/stdlib/CMakeFiles/libc.test.src.stdlib.abs_test.__hermetic__.__build__.dir/abs_test.cpp.o [648/1022] Building CXX object libc/test/src/stdlib/CMakeFiles/libc.test.src.stdlib.llabs_test.__hermetic__.__build__.dir/llabs_test.cpp.o [649/1022] Building CXX object libc/test/src/stdlib/CMakeFiles/libc.test.src.stdlib.lldiv_test.__hermetic__.__build__.dir/lldiv_test.cpp.o [650/1022] Building CXX object libc/test/src/stdlib/CMakeFiles/libc.test.src.stdlib.div_test.__hermetic__.__build__.dir/div_test.cpp.o [651/1022] Building CXX object libc/test/src/stdlib/CMakeFiles/libc.test.src.stdlib.ldiv_test.__hermetic__.__build__.dir/ldiv_test.cpp.o [652/1022] Building CXX object libc/test/src/stdlib/CMakeFiles/libc.test.src.stdlib.bsearch_test.__hermetic__.__build__.dir/bsearch_test.cpp.o [653/1022] Building CXX object libc/test/src/stdlib/CMakeFiles/libc.test.src.stdlib.rand_test.__hermetic__.__build__.dir/rand_test.cpp.o [654/1022] Building CXX object libc/test/src/stdlib/CMakeFiles/libc.test.src.stdlib.qsort_r_test.__hermetic__.__build__.dir/qsort_r_test.cpp.o [655/1022] Building CXX object libc/test/src/stdlib/CMakeFiles/libc.test.src.stdlib.qsort_test.__hermetic__.__build__.dir/qsort_test.cpp.o ninja: build stopped: subcommand failed. ++ err=1 ++ echo PID 383376: subprocess exited with error 1 ++ exit 1 PID 383376: subprocess exited with error 1 + step_failure + echo @@@STEP_FAILURE@@@ @@@STEP_FAILURE@@@ Step 12 (Testing GPU libc) failure: (failure) ... Ran 9 tests. PASS: 9 FAIL: 0 [638/1022] Linking CXX executable libc/test/src/stdlib/libc.test.src.stdlib.strtold_test.__hermetic__.__build__ [639/1022] Linking CXX executable libc/test/src/stdlib/libc.test.src.stdlib.strtof_test.__hermetic__.__build__ [640/1022] Linking CXX executable libc/test/src/stdlib/libc.test.src.stdlib.strtol_test.__hermetic__.__build__ [641/1022] Linking CXX executable libc/test/src/stdlib/libc.test.src.stdlib.strtoll_test.__hermetic__.__build__ [642/1022] Linking CXX executable libc/test/src/stdlib/libc.test.src.stdlib.strtoul_test.__hermetic__.__build__ [643/1022]
[clang] [Docs][Clang] Missing DR status for C++23-era papers in cxx_status.html (PR #68846)
Endilll wrote: All 3 buildbot failures are unrelated. https://github.com/llvm/llvm-project/pull/68846 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [x86][Codegen] security check cookie execute only when needed (PR #95904)
https://github.com/mahesh-attarde edited https://github.com/llvm/llvm-project/pull/95904 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [x86][CodeGen] security check cookie execute only when needed (PR #95904)
https://github.com/mahesh-attarde edited https://github.com/llvm/llvm-project/pull/95904 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [X86][CodeGen] security check cookie execute only when needed (PR #95904)
https://github.com/mahesh-attarde edited https://github.com/llvm/llvm-project/pull/95904 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] dfbfb6c - [SourceManager] Expose max usage of source location space as a Statistic (#96292)
Author: Ilya Biryukov Date: 2024-06-24T11:57:36+02:00 New Revision: dfbfb6c5c6dba8a25c7a9769e969d56ba19fc14d URL: https://github.com/llvm/llvm-project/commit/dfbfb6c5c6dba8a25c7a9769e969d56ba19fc14d DIFF: https://github.com/llvm/llvm-project/commit/dfbfb6c5c6dba8a25c7a9769e969d56ba19fc14d.diff LOG: [SourceManager] Expose max usage of source location space as a Statistic (#96292) We have been running into source location exhaustion recently and want to use the statistics to monitor the usage in various files to be able to anticipate where the next problem will happen. I picked `Statistic` because it can be written into a structured JSON file and is easier to consume by further automation. This commit does not change any existing per-source-manager metrics exposed via `SourceManager::PrintStats()`. This does create some redundancy, but I also expect to be non-controversial because it aligns with the intended use of `Statistic`. Added: Modified: clang/include/clang/Basic/SourceManager.h clang/lib/Basic/SourceManager.cpp Removed: diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h index d2e2e914327f2..d3ccc7ef81c07 100644 --- a/clang/include/clang/Basic/SourceManager.h +++ b/clang/include/clang/Basic/SourceManager.h @@ -1981,6 +1981,7 @@ class SourceManager : public RefCountedBase { SourceLocation SpellLoc, SourceLocation ExpansionLoc, unsigned ExpansionLength) const; + void updateSlocUsageStats() const; }; /// Comparison function object. diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index f0af1a3e3a38b..533a9fe88a215 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -20,6 +20,7 @@ #include "llvm/ADT/MapVector.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/Statistic.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Support/Allocator.h" @@ -46,6 +47,13 @@ using namespace clang; using namespace SrcMgr; using llvm::MemoryBuffer; +#define DEBUG_TYPE "source-manager" + +// Reaching a limit of 2^31 results in a hard error. This metric allows to track +// if particular invocation of the compiler is close to it. +STATISTIC(MaxUsedSLocBytes, "Maximum number of bytes used by source locations " +"(both loaded and local)."); + //===--===// // SourceManager Helper Classes //===--===// @@ -466,6 +474,7 @@ SourceManager::AllocateLoadedSLocEntries(unsigned NumSLocEntries, SLocEntryLoaded.resize(LoadedSLocEntryTable.size()); SLocEntryOffsetLoaded.resize(LoadedSLocEntryTable.size()); CurrentLoadedOffset -= TotalSize; + updateSlocUsageStats(); int BaseID = -int(LoadedSLocEntryTable.size()) - 1; LoadedSLocEntryAllocBegin.push_back(FileID::get(BaseID)); return std::make_pair(BaseID, CurrentLoadedOffset); @@ -619,6 +628,7 @@ FileID SourceManager::createFileIDImpl(ContentCache &File, StringRef Filename, // We do a +1 here because we want a SourceLocation that means "the end of the // file", e.g. for the "no newline at the end of the file" diagnostic. NextLocalOffset += FileSize + 1; + updateSlocUsageStats(); // Set LastFileIDLookup to the newly created file. The next getFileID call is // almost guaranteed to be from that file. @@ -679,6 +689,7 @@ SourceManager::createExpansionLocImpl(const ExpansionInfo &Info, } // See createFileID for that +1. NextLocalOffset += Length + 1; + updateSlocUsageStats(); return SourceLocation::getMacroLoc(NextLocalOffset - (Length + 1)); } @@ -1843,6 +1854,12 @@ void SourceManager::associateFileChunkWithMacroArgExp( MacroArgsCache[EndOffs] = EndOffsMappedLoc; } +void SourceManager::updateSlocUsageStats() const { + SourceLocation::UIntTy UsedBytes = + NextLocalOffset + (MaxLoadedOffset - CurrentLoadedOffset); + MaxUsedSLocBytes.updateMax(UsedBytes); +} + /// If \arg Loc points inside a function macro argument, the returned /// location will be the macro location in which the argument was expanded. /// If a macro argument is used multiple times, the expanded location will ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [SourceManager] Expose max usage of source location space as a Statistic (PR #96292)
https://github.com/ilya-biryukov closed https://github.com/llvm/llvm-project/pull/96292 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Diagnose variable template explicit specializations with storage-class-specifiers (PR #93873)
bgra8 wrote: @sdkrystian we need a way to disable the new check so we can do the code fixes for our large codebase while still using the old compiler. As the patch description suggests the correct code is rejected by the current `clang` so we have no path forward here. Can you please add a flag to allow switching to the old behavior? https://github.com/llvm/llvm-project/pull/93873 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AMDGPU] Enable atomic optimizer for 64 bit divergent values (PR #96473)
https://github.com/vikramRH edited https://github.com/llvm/llvm-project/pull/96473 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [TBAA] Emit int TBAA metadata on FP math libcalls (PR #96025)
@@ -707,7 +707,38 @@ static RValue emitLibraryCall(CodeGenFunction &CGF, const FunctionDecl *FD, const CallExpr *E, llvm::Constant *calleeValue) { CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E); CGCallee callee = CGCallee::forDirect(calleeValue, GlobalDecl(FD)); - return CGF.EmitCall(E->getCallee()->getType(), callee, E, ReturnValueSlot()); + RValue Call = + CGF.EmitCall(E->getCallee()->getType(), callee, E, ReturnValueSlot()); + + // Check the supported intrinsic. + if (unsigned BuiltinID = FD->getBuiltinID()) { +auto IntrinsicID = [&]() -> unsigned { + switch (BuiltinID) { + case Builtin::BIexpf: + case Builtin::BI__builtin_expf: + case Builtin::BI__builtin_expf128: +return true; + } + // TODO: support more FP math libcalls + return false; +}(); + +if (IntrinsicID) { + llvm::MDBuilder MDHelper(CGF.getLLVMContext()); + MDNode *RootMD; + if (CGF.getLangOpts().CPlusPlus) +RootMD = MDHelper.createTBAARoot("Simple C++ TBAA"); vfdff wrote: Fixed, thanks https://github.com/llvm/llvm-project/pull/96025 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [TBAA] Emit int TBAA metadata on FP math libcalls (PR #96025)
https://github.com/vfdff deleted https://github.com/llvm/llvm-project/pull/96025 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Clarify diagnostic notes for implicitly generated deduction guides (PR #96084)
@@ -12114,6 +12115,35 @@ static void NoteFunctionCandidate(Sema &S, OverloadCandidate *Cand, return; } + // If this is an implicit deduction guide against an implicitly defined + // constructor, add a note for it. Neither these deduction guides nor their + // corresponding constructors are explicitly spelled in the source code, Sirraide wrote: I personally would probably prefer not printing them if there already is enough context, but I don’t feel too strongly either way. https://github.com/llvm/llvm-project/pull/96084 ___ 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)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Haojian Wu (hokein) Changes The lifetime bound warning in Clang currently only considers initializations. This patch extends the warning to include assignments. - **NFC refactoring (first commit)**: this moves the existing lifetime checking code from `SemaInit.cpp` to a new location for better code isolation and reuse. - **Support for assignments of built-in pointer types (second commit)**: this is done is by reusing the existing statement-local implementation. Clang now warns if the pointer is assigned to a temporary object that being destoryed at the end of the full assignment expression. With this patch, we will detect more cases under the on-by-default diagnostic `-Wdangling`. I have added a new category for this specific diagnostic so that people can temporarily disable it if their codebase is not yet clean. This is the first step to address #63310, focusing only on pointer types. Support for C++ assignment operators will come in a follow-up patch. --- Patch is 109.79 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/96475.diff 10 Files Affected: - (modified) clang/include/clang/Basic/DiagnosticGroups.td (+3-1) - (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+5) - (modified) clang/lib/Sema/CMakeLists.txt (+1) - (added) clang/lib/Sema/CheckExprLifetime.cpp (+1285) - (added) clang/lib/Sema/CheckExprLifetime.h (+39) - (modified) clang/lib/Sema/SemaExpr.cpp (+4) - (modified) clang/lib/Sema/SemaInit.cpp (+3-1229) - (modified) clang/test/Parser/compound_literal.c (+3-2) - (modified) clang/test/SemaCXX/attr-lifetimebound.cpp (+6) - (modified) clang/test/SemaCXX/warn-dangling-local.cpp (+2) ``diff diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 9b37d4bd3205b..e828d0c459651 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -430,6 +430,7 @@ def LogicalOpParentheses: DiagGroup<"logical-op-parentheses">; def LogicalNotParentheses: DiagGroup<"logical-not-parentheses">; def ShiftOpParentheses: DiagGroup<"shift-op-parentheses">; def OverloadedShiftOpParentheses: DiagGroup<"overloaded-shift-op-parentheses">; +def DanglingAssignment: DiagGroup<"dangling-assignment">; def DanglingElse: DiagGroup<"dangling-else">; def DanglingField : DiagGroup<"dangling-field">; def DanglingInitializerList : DiagGroup<"dangling-initializer-list">; @@ -437,7 +438,8 @@ def DanglingGsl : DiagGroup<"dangling-gsl">; def ReturnStackAddress : DiagGroup<"return-stack-address">; // Name of this warning in GCC def : DiagGroup<"return-local-addr", [ReturnStackAddress]>; -def Dangling : DiagGroup<"dangling", [DanglingField, +def Dangling : DiagGroup<"dangling", [DanglingAssignment, + DanglingField, DanglingInitializerList, DanglingGsl, ReturnStackAddress]>; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 25a87078a5709..207529660b37b 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -10092,6 +10092,11 @@ def warn_new_dangling_initializer_list : Warning< "the allocated initializer list}0 " "will be destroyed at the end of the full-expression">, InGroup; +def warn_dangling_pointer_assignment : Warning< + "object backing the pointer %0 " + "will be destroyed at the end of the full-expression">, + InGroup; + def warn_unsupported_lifetime_extension : Warning< "lifetime extension of " "%select{temporary|backing array of initializer list}0 created " diff --git a/clang/lib/Sema/CMakeLists.txt b/clang/lib/Sema/CMakeLists.txt index f152d243d39a5..980a83d4431aa 100644 --- a/clang/lib/Sema/CMakeLists.txt +++ b/clang/lib/Sema/CMakeLists.txt @@ -15,6 +15,7 @@ clang_tablegen(OpenCLBuiltins.inc -gen-clang-opencl-builtins add_clang_library(clangSema AnalysisBasedWarnings.cpp + CheckExprLifetime.cpp CodeCompleteConsumer.cpp DeclSpec.cpp DelayedDiagnostic.cpp diff --git a/clang/lib/Sema/CheckExprLifetime.cpp b/clang/lib/Sema/CheckExprLifetime.cpp new file mode 100644 index 0..73b3fd2d3a138 --- /dev/null +++ b/clang/lib/Sema/CheckExprLifetime.cpp @@ -0,0 +1,1285 @@ +//===--- CheckExprLifetime.cpp ===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "CheckExprLifetime.h" +#include "clang/AST/Expr.h" +#include "clang/Basic/DiagnosticSema.h" +#in
[clang] [clang] Emit bad shift warnings (PR #70307)
https://github.com/budimirarandjelovicsyrmia updated https://github.com/llvm/llvm-project/pull/70307 From caea9286c405b8dc0e71383efed256beaa5134f0 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/lib/AST/ExprConstant.cpp | 7 +++ clang/lib/Sema/SemaExpr.cpp| 16 clang/test/C/drs/dr0xx.c | 3 ++- clang/test/C/drs/dr2xx.c | 4 +++- clang/test/Sema/builtins.c | 6 -- clang/test/Sema/constant-builtins-2.c | 10 ++ clang/test/Sema/shift-count-negative.c | 8 clang/test/Sema/shift-count-overflow.c | 6 ++ clang/test/Sema/shift-negative-value.c | 9 + clang/test/Sema/vla-2.c| 6 -- clang/test/SemaCXX/enum.cpp| 6 -- clang/test/SemaCXX/shift.cpp | 2 +- 12 files changed, 66 insertions(+), 17 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/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index af1f18aa8ef24..0926bcf258f58 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -2856,6 +2856,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().CPlusPlus) + return false; Result = LHS << SA; return true; } @@ -2879,6 +2882,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().CPlusPlus) + return false; Result = LHS >> SA; return true; } diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 44f886bf54e3a..fd1c8284b5ff0 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -11246,7 +11246,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; } @@ -11261,7 +11261,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; } @@ -11294,7 +11294,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; } @@ -17130,11 +17130,19 @@ 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.size()) { + Diagnoser.diagnoseFold(*this, DiagLoc) << E->getSourceRange(); + for (const PartialDiagnosticAt &Note : Notes) +Diag(Note.first, Note.second); +} + return E; } diff --git a/clang/test/C/drs/dr0xx.c b/clang/test/C/drs/dr0xx.c index 36de32a93da95..252dc9329c4ca 100644 --- a/clang/test/C/drs/dr0xx.c +++ b/clang/test/C/drs/dr0xx.c @@ -430,7 +430,8 @@ void dr081(void) { /* Demonstrate that we don't crash when left shifting a signed value; that's * implementation defined behavior. */ - _Static_assert(-1 << 1 == -2, "fail"); /* Didn't shift a zero into the "sign bit". */ + _Static_assert(-1 << 1 == -2, "fail"); /* expected-warning {{expression is not an integer constant expression; folding it to a constant is a GNU extension}} + expected-note {{left shift of negative value -1}} */ _Static_assert(
[clang] [llvm] [RISCV] Remove experimental from Ztso. (PR #96465)
https://github.com/wangpc-pp approved this pull request. LGTM. https://github.com/llvm/llvm-project/pull/96465 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Remove experimental from Ztso. (PR #96465)
https://github.com/wangpc-pp edited https://github.com/llvm/llvm-project/pull/96465 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Remove experimental from Ztso. (PR #96465)
@@ -365,24 +365,30 @@ // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-ZFHMIN %s // RV32-ZFHMIN: "-target-feature" "+zfhmin" -// RUN: not %clang --target=riscv32-unknown-elf -march=rv32iztso -### %s \ +// RUN: not %clang --target=riscv32-unknown-elf -march=rv32izalasr -### %s \ wangpc-pp wrote: Does this mean we should change this when `Zalasr` is no longer experimental? (Thought I think we don't have a way to avoid this, we will always need an experimental extension here) https://github.com/llvm/llvm-project/pull/96465 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Remove experimental from Ztso. (PR #96465)
https://github.com/wangpc-pp edited https://github.com/llvm/llvm-project/pull/96465 ___ 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)
Xazax-hun wrote: Wow, this is awesome! Thanks for tackling 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] f03cb00 - [Clang] Introduce `nonblocking`/`nonallocating` attributes (#84983)
Author: Doug Wyatt Date: 2024-06-24T12:51:31+02:00 New Revision: f03cb005eb4ba3c6fb645aca2228e907db8cd452 URL: https://github.com/llvm/llvm-project/commit/f03cb005eb4ba3c6fb645aca2228e907db8cd452 DIFF: https://github.com/llvm/llvm-project/commit/f03cb005eb4ba3c6fb645aca2228e907db8cd452.diff LOG: [Clang] Introduce `nonblocking`/`nonallocating` attributes (#84983) Introduce `nonblocking` and `nonallocating` attributes. RFC is here: https://discourse.llvm.org/t/rfc-nolock-and-noalloc-attributes/76837 This PR introduces the attributes, with some changes in Sema to deal with them as extensions to function (proto)types. There are some basic type checks, most importantly, a warning when trying to spoof the attribute (implicitly convert a function without the attribute to one that has it). A second, follow-on pull request will introduce new caller/callee verification. - Co-authored-by: Doug Wyatt Co-authored-by: Shafik Yaghmour Co-authored-by: Aaron Ballman Co-authored-by: Sirraide Added: clang/test/Sema/attr-nonblocking-sema.c clang/test/Sema/attr-nonblocking-sema.cpp clang/test/Sema/attr-nonblocking-syntax.cpp Modified: clang/docs/ReleaseNotes.rst clang/include/clang/AST/AbstractBasicReader.h clang/include/clang/AST/AbstractBasicWriter.h clang/include/clang/AST/Decl.h clang/include/clang/AST/PropertiesBase.td clang/include/clang/AST/Type.h clang/include/clang/AST/TypeProperties.td clang/include/clang/Basic/Attr.td clang/include/clang/Basic/AttrDocs.td clang/include/clang/Basic/DiagnosticGroups.td clang/include/clang/Basic/DiagnosticSemaKinds.td clang/include/clang/Sema/Sema.h clang/lib/AST/ASTContext.cpp clang/lib/AST/Type.cpp clang/lib/AST/TypePrinter.cpp clang/lib/Sema/Sema.cpp clang/lib/Sema/SemaDecl.cpp clang/lib/Sema/SemaDeclCXX.cpp clang/lib/Sema/SemaOverload.cpp clang/lib/Sema/SemaType.cpp clang/lib/Sema/TreeTransform.h Removed: diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 9c8f8c4a4fbaf..c6788d0deefae 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -511,6 +511,11 @@ Attribute Changes in Clang }; +- Introduced new function type attributes ``[[clang::nonblocking]]``, ``[[clang::nonallocating]]``, + ``[[clang::blocking]]``, and ``[[clang::allocating]]``, with GNU-style variants as well. + The attributes declare constraints about a function's behavior pertaining to blocking and + heap memory allocation. + Improvements to Clang's diagnostics --- - Clang now applies syntax highlighting to the code snippets it diff --git a/clang/include/clang/AST/AbstractBasicReader.h b/clang/include/clang/AST/AbstractBasicReader.h index ab036f1d445ac..4b627c65e276b 100644 --- a/clang/include/clang/AST/AbstractBasicReader.h +++ b/clang/include/clang/AST/AbstractBasicReader.h @@ -244,6 +244,15 @@ class DataStreamBasicReader : public BasicReaderBase { return FunctionProtoType::ExtParameterInfo::getFromOpaqueValue(value); } + FunctionEffect readFunctionEffect() { +uint32_t value = asImpl().readUInt32(); +return FunctionEffect::fromOpaqueInt32(value); + } + + EffectConditionExpr readEffectConditionExpr() { +return EffectConditionExpr{asImpl().readExprRef()}; + } + NestedNameSpecifier *readNestedNameSpecifier() { auto &ctx = getASTContext(); diff --git a/clang/include/clang/AST/AbstractBasicWriter.h b/clang/include/clang/AST/AbstractBasicWriter.h index 8e42fcaad1d38..b941add8bde88 100644 --- a/clang/include/clang/AST/AbstractBasicWriter.h +++ b/clang/include/clang/AST/AbstractBasicWriter.h @@ -222,6 +222,14 @@ class DataStreamBasicWriter : public BasicWriterBase { asImpl().writeUInt32(epi.getOpaqueValue()); } + void writeFunctionEffect(FunctionEffect E) { +asImpl().writeUInt32(E.toOpaqueInt32()); + } + + void writeEffectConditionExpr(EffectConditionExpr CE) { +asImpl().writeExprRef(CE.getCondition()); + } + void writeNestedNameSpecifier(NestedNameSpecifier *NNS) { // Nested name specifiers usually aren't too long. I think that 8 would // typically accommodate the vast majority. diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h index 7fd80b90d1033..5957f14098363 100644 --- a/clang/include/clang/AST/Decl.h +++ b/clang/include/clang/AST/Decl.h @@ -3042,6 +3042,16 @@ class FunctionDecl : public DeclaratorDecl, /// computed and stored. unsigned getODRHash() const; + FunctionEffectsRef getFunctionEffects() const { +// Effects may diff er between declarations, but they should be propagated +// from old to new on any redeclaration, so it suffices to look at +// getMostRecentDecl(). +if (const auto *FPT = +getMostRecentDecl()->getType()->getAs()) + return FPT->getFunctionEffe
[clang] Try to fix llvm/llvm-project#41441 (PR #96464)
https://github.com/awson updated https://github.com/llvm/llvm-project/pull/96464 >From 096b999120cc28844d780acbc16f8308b3a54160 Mon Sep 17 00:00:00 2001 From: awson Date: Mon, 24 Jun 2024 10:34:51 +0300 Subject: [PATCH 1/2] [Clang][Sema] don't handle ArraySize/AllocType early. --- clang/lib/Sema/SemaExprCXX.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index f3af8dee6b090..2f79540faea00 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -2174,7 +2174,8 @@ ExprResult Sema::BuildCXXNew(SourceRange Range, bool UseGlobal, // Per C++0x [expr.new]p5, the type being constructed may be a // typedef of an array type. - if (!ArraySize) { + // Dependent case will be handled separately. + if (!ArraySize && !AllocType->isDependentType()) { if (const ConstantArrayType *Array = Context.getAsConstantArrayType(AllocType)) { ArraySize = IntegerLiteral::Create(Context, Array->getSize(), >From 50dbd2c8dce3a70f19ea6f2f22f6f1f9bda84a1e Mon Sep 17 00:00:00 2001 From: awson Date: Mon, 24 Jun 2024 11:07:58 +0300 Subject: [PATCH 2/2] [clang][Sema] Tests for GH41441 I've borrowed size-calculation test from PR89036 and added another test, which PR89036 fails on. --- clang/test/SemaCXX/GH41441.cpp | 46 ++ 1 file changed, 46 insertions(+) create mode 100644 clang/test/SemaCXX/GH41441.cpp diff --git a/clang/test/SemaCXX/GH41441.cpp b/clang/test/SemaCXX/GH41441.cpp new file mode 100644 index 0..7a6260fef91b5 --- /dev/null +++ b/clang/test/SemaCXX/GH41441.cpp @@ -0,0 +1,46 @@ +// RUN: %clang --target=x86_64-pc-linux -S -fno-discard-value-names -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 %s -fsyntax-only -verify + +namespace std { + using size_t = decltype(sizeof(int)); +}; +void* operator new[](std::size_t, void*) noexcept; + +// CHECK: call void @llvm.memset.p0.i64(ptr align 1 %x, i8 0, i64 8, i1 false) +// CHECK: call void @llvm.memset.p0.i64(ptr align 16 %x, i8 0, i64 32, i1 false) +template +void f() +{ +typedef TYPE TArray[8]; + +TArray x; +new(&x) TArray(); +} + +template +void f1() { + int (*x)[1] = new int[1][1]; +} +template void f1(); +void f2() { + int (*x)[1] = new int[1][1]; +} + +int main() +{ +f(); +f(); +} + +// expected-no-diagnostics +template struct unique_ptr {unique_ptr(T* p){}}; + +template +unique_ptr make_unique(unsigned long long n) { + return unique_ptr(new T[n]()); +} + +auto boro(int n){ + typedef double HistoryBuffer[4]; + return make_unique(n); +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Clarify diagnostic notes for implicitly generated deduction guides (PR #96084)
@@ -12114,6 +12115,35 @@ static void NoteFunctionCandidate(Sema &S, OverloadCandidate *Cand, return; } + // If this is an implicit deduction guide against an implicitly defined + // constructor, add a note for it. Neither these deduction guides nor their + // corresponding constructors are explicitly spelled in the source code, hokein wrote: I have a different perspective: I'd prefer printing them as long as they are synthesized (not part of the written source code). While the example of combined template parameters might not be the best one (and I agree that understanding them from existing contexts is often sufficient), the conjunction of associated constraints for a class and the corresponding constructor is probably less obvious. I think printing them would make the situation clearer and help users avoid guessing. Moreover, this approach would be consistent with what GCC does. https://github.com/llvm/llvm-project/pull/96084 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [openmp] [PGO][Offload] Add GPU profiling flags to driver (PR #94268)
jhuber6 wrote: > @jhuber6 The clang format errors are mostly due to my local version of > `clang-format` disagreeing with the buildbot's version. Its a bit annoying, > but it shouldn't be too much of a problem given I plan on squashing and > merging once this gets approved. > > I added new flags for GPU PGO specifically because I didn't want to modify > the PGO flags' existing behavior. PGO has a significant runtime cost, so I > figured it would be best for the end user experience to only enable PGO on > the GPU when it was specifically requested. Is this something that specifically requires its own flag? Or could we just do `-Xarch_device -fprofile-generate`. https://github.com/llvm/llvm-project/pull/94268 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Add an ownership change visitor to StreamChecker (PR #94957)
Szelethus wrote: > > > I did not find a similar test for `MallocChecker` but there could be one > > > with similar test functions. > > > > > > I'm not sure what tests you are referring to. I did fix your other > > observations. > > I meant another test file where the `NoStateChangeFuncVisitor` is tested (if > there is any case for it). Oh, I see. The `MallocChecker` visitor is tested in `clang/test/Analysis/NewDeleteLeaks.cpp`. Evaluations are on the way. https://github.com/llvm/llvm-project/pull/94957 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 3d80792 - [clang][AArch64][FMV] Stop emitting alias to ifunc. (#96221)
Author: Alexandros Lamprineas Date: 2024-06-24T12:01:48+01:00 New Revision: 3d8079229e7571a5912e880bf7a960d809c8ee96 URL: https://github.com/llvm/llvm-project/commit/3d8079229e7571a5912e880bf7a960d809c8ee96 DIFF: https://github.com/llvm/llvm-project/commit/3d8079229e7571a5912e880bf7a960d809c8ee96.diff LOG: [clang][AArch64][FMV] Stop emitting alias to ifunc. (#96221) Long story short the interaction of two optimizations happening in GlobalOpt results in a crash. For more details look at the issue https://github.com/llvm/llvm-project/issues/96197. I will be fixing this in GlobalOpt but it is a conservative solution since it won't allow us to optimize resolvers which return a pointer to a function whose definition is in another TU when compiling without LTO: ``` __attribute__((target_version("simd"))) void bar(void); __attribute__((target_version("default"))) void bar(void); int foo() { bar(); } ``` fixes: #96197 Added: Modified: clang/docs/ReleaseNotes.rst clang/lib/CodeGen/CodeGenModule.cpp clang/test/CodeGen/aarch64-mixed-target-attributes.c clang/test/CodeGen/attr-target-clones-aarch64.c clang/test/CodeGen/attr-target-version.c clang/test/CodeGenCXX/attr-target-clones-aarch64.cpp clang/test/CodeGenCXX/attr-target-version.cpp clang/test/CodeGenCXX/fmv-namespace.cpp Removed: diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index c6788d0deefae..136c72cf682a9 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -95,13 +95,17 @@ ABI Changes in This Version - Fixed Microsoft calling convention when returning classes that have a deleted copy assignment operator. Such a class should be returned indirectly. +- Removed the global alias that was pointing to AArch64 Function Multiversioning + ifuncs. Its purpose was to preserve backwards compatibility when the ".ifunc" + suffix got removed from the name mangling. The alias interacts badly with + GlobalOpt (see the issue #96197). + - Fixed Microsoft name mangling for auto non-type template arguments of pointer type for MSVC 1920+. This change resolves incompatibilities with code compiled by MSVC 1920+ but will introduce incompatibilities with code compiled by earlier versions of Clang unless such code is built with the compiler option `-fms-compatibility-version=19.14` to imitate the MSVC 1914 mangling behavior. - AST Dumping Potentially Breaking Changes diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index dd4a665ebc78b..76534475e88f7 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -4259,8 +4259,8 @@ void CodeGenModule::emitMultiVersionFunctions() { llvm::Constant *ResolverConstant = GetOrCreateMultiVersionResolver(GD); if (auto *IFunc = dyn_cast(ResolverConstant)) { ResolverConstant = IFunc->getResolver(); - if (FD->isTargetClonesMultiVersion() || - FD->isTargetVersionMultiVersion()) { + if (FD->isTargetClonesMultiVersion() && + !getTarget().getTriple().isAArch64()) { std::string MangledName = getMangledNameImpl( *this, GD, FD, /*OmitMultiVersionMangling=*/true); if (!GetGlobalValue(MangledName + ".ifunc")) { diff --git a/clang/test/CodeGen/aarch64-mixed-target-attributes.c b/clang/test/CodeGen/aarch64-mixed-target-attributes.c index 6aa747d4cb461..3c047fec6ceed 100644 --- a/clang/test/CodeGen/aarch64-mixed-target-attributes.c +++ b/clang/test/CodeGen/aarch64-mixed-target-attributes.c @@ -30,9 +30,6 @@ __attribute__((target_version("jscvt"))) int default_def_with_version_decls(void //. // CHECK: @__aarch64_cpu_features = external dso_local global { i64 } -// CHECK: @explicit_default.ifunc = weak_odr alias i32 (), ptr @explicit_default -// CHECK: @implicit_default.ifunc = weak_odr alias i32 (), ptr @implicit_default -// CHECK: @default_def_with_version_decls.ifunc = weak_odr alias i32 (), ptr @default_def_with_version_decls // CHECK: @explicit_default = weak_odr ifunc i32 (), ptr @explicit_default.resolver // CHECK: @implicit_default = weak_odr ifunc i32 (), ptr @implicit_default.resolver // CHECK: @default_def_with_version_decls = weak_odr ifunc i32 (), ptr @default_def_with_version_decls.resolver diff --git a/clang/test/CodeGen/attr-target-clones-aarch64.c b/clang/test/CodeGen/attr-target-clones-aarch64.c index ad6079a91fcd5..60f9c7f1fc24e 100644 --- a/clang/test/CodeGen/attr-target-clones-aarch64.c +++ b/clang/test/CodeGen/attr-target-clones-aarch64.c @@ -27,14 +27,6 @@ inline int __attribute__((target_clones("fp16", "sve2-bitperm+fcma", "default")) //. // CHECK: @__aarch64_cpu_features = external dso_local global { i64 } -// CHECK: @ftc.ifunc = weak_odr alias i32 (), ptr @ftc -// CHECK: @ftc_def.ifunc = weak_odr alias i32
[clang] [clang][AArch64][FMV] Stop emitting alias to ifunc. (PR #96221)
https://github.com/labrinea closed https://github.com/llvm/llvm-project/pull/96221 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 4e6c8f1 - [clang] [MinGW] Set a predefined __GXX_TYPEINFO_EQUALITY_INLINE=0 for MinGW targets (#96062)
Author: Martin Storsjö Date: 2024-06-24T14:02:28+03:00 New Revision: 4e6c8f1d30b8516fc7205bbcc97a78a728215512 URL: https://github.com/llvm/llvm-project/commit/4e6c8f1d30b8516fc7205bbcc97a78a728215512 DIFF: https://github.com/llvm/llvm-project/commit/4e6c8f1d30b8516fc7205bbcc97a78a728215512.diff LOG: [clang] [MinGW] Set a predefined __GXX_TYPEINFO_EQUALITY_INLINE=0 for MinGW targets (#96062) libstdc++ requires this define to match what is predefined in GCC for the ABI of this platform; GCC hardcodes this define for all mingw configurations in gcc/config/i386/cygming.h. (It also defines __GXX_MERGED_TYPEINFO_NAMES=0, but that happens to match the defaults in libstdc++ headers, so there's no similar need to define it in Clang.) This fixes a Clang/libstdc++ interop issue discussed at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110572. Added: Modified: clang/lib/Frontend/InitPreprocessor.cpp clang/test/Preprocessor/predefined-win-macros.c Removed: diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index 2d5c94c760252..55ec460064830 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -934,6 +934,12 @@ static void InitializePredefinedMacros(const TargetInfo &TI, if (LangOpts.GNUCVersion && LangOpts.CPlusPlus11) Builder.defineMacro("__GXX_EXPERIMENTAL_CXX0X__"); + if (TI.getTriple().isWindowsGNUEnvironment()) { +// Set ABI defining macros for libstdc++ for MinGW, where the +// default in libstdc++ diff ers from the defaults for this target. +Builder.defineMacro("__GXX_TYPEINFO_EQUALITY_INLINE", "0"); + } + if (LangOpts.ObjC) { if (LangOpts.ObjCRuntime.isNonFragile()) { Builder.defineMacro("__OBJC2__"); diff --git a/clang/test/Preprocessor/predefined-win-macros.c b/clang/test/Preprocessor/predefined-win-macros.c index 14e2f584bd093..7d29e45c7d5ac 100644 --- a/clang/test/Preprocessor/predefined-win-macros.c +++ b/clang/test/Preprocessor/predefined-win-macros.c @@ -116,6 +116,7 @@ // CHECK-X86-MINGW: #define WINNT 1 // CHECK-X86-MINGW: #define _WIN32 1 // CHECK-X86-MINGW-NOT: #define _WIN64 1 +// CHECK-X86-MINGW: #define __GXX_TYPEINFO_EQUALITY_INLINE 0 // RUN: %clang_cc1 -triple thumbv7-windows-gnu %s -E -dM -o - \ // RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-ARM-MINGW @@ -125,6 +126,7 @@ // CHECK-ARM-MINGW: #define WINNT 1 // CHECK-ARM-MINGW: #define _WIN32 1 // CHECK-ARM-MINGW-NOT: #define _WIN64 1 +// CHECK-ARM-MINGW: #define __GXX_TYPEINFO_EQUALITY_INLINE 0 // RUN: %clang_cc1 -triple x86_64-windows-gnu %s -E -dM -o - \ // RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-AMD64-MINGW @@ -134,6 +136,7 @@ // CHECK-AMD64-MINGW: #define WINNT 1 // CHECK-AMD64-MINGW: #define _WIN32 1 // CHECK-AMD64-MINGW: #define _WIN64 1 +// CHECK-AMD64-MINGW: #define __GXX_TYPEINFO_EQUALITY_INLINE 0 // RUN: %clang_cc1 -triple aarch64-windows-gnu %s -E -dM -o - \ // RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-ARM64-MINGW @@ -145,6 +148,7 @@ // CHECK-ARM64-MINGW: #define _WIN32 1 // CHECK-ARM64-MINGW: #define _WIN64 1 // CHECK-ARM64-MINGW: #define __GCC_ASM_FLAG_OUTPUTS__ 1 +// CHECK-ARM64-MINGW: #define __GXX_TYPEINFO_EQUALITY_INLINE 0 // CHECK-ARM64-MINGW: #define __aarch64__ 1 // RUN: %clang_cc1 -triple arm64ec-windows-gnu %s -E -dM -o - \ @@ -157,6 +161,7 @@ // CHECK-ARM64EC-MINGW: #define _WIN32 1 // CHECK-ARM64EC-MINGW: #define _WIN64 1 // CHECK-ARM64EC-MINGW: #define __GCC_ASM_FLAG_OUTPUTS__ 1 +// CHECK-ARM64EC-MINGW: #define __GXX_TYPEINFO_EQUALITY_INLINE 0 // CHECK-ARM64EC-MINGW-NOT: #define __aarch64__ 1 // CHECK-ARM64EC-MINGW: #define __amd64 1 // CHECK-ARM64EC-MINGW: #define __amd64__ 1 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] [MinGW] Set a predefined __GXX_TYPEINFO_EQUALITY_INLINE=0 for… (PR #96062)
https://github.com/mstorsjo closed https://github.com/llvm/llvm-project/pull/96062 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 6b41de3 - [clang][Interp] Implement ptrauth builtins
Author: Timm Bäder Date: 2024-06-24T13:02:55+02:00 New Revision: 6b41de3605658069eb69b8684c2760e54bd1bea3 URL: https://github.com/llvm/llvm-project/commit/6b41de3605658069eb69b8684c2760e54bd1bea3 DIFF: https://github.com/llvm/llvm-project/commit/6b41de3605658069eb69b8684c2760e54bd1bea3.diff LOG: [clang][Interp] Implement ptrauth builtins Added: Modified: clang/lib/AST/Interp/ByteCodeExprGen.cpp clang/lib/AST/Interp/InterpBuiltin.cpp clang/test/CodeGen/ptrauth-intrinsics.c Removed: diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index cb5962466f35f..3c96059375360 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -3572,6 +3572,7 @@ bool ByteCodeExprGen::VisitBuiltinCallExpr(const CallExpr *E) { unsigned Builtin = E->getBuiltinCallee(); if (Builtin == Builtin::BI__builtin___CFStringMakeConstantString || Builtin == Builtin::BI__builtin___NSStringMakeConstantString || + Builtin == Builtin::BI__builtin_ptrauth_sign_constant || Builtin == Builtin::BI__builtin_function_start) { if (std::optional GlobalOffset = P.createGlobal(E)) return this->emitGetPtrGlobal(*GlobalOffset, E); diff --git a/clang/lib/AST/Interp/InterpBuiltin.cpp b/clang/lib/AST/Interp/InterpBuiltin.cpp index af8841c8b4ef8..aeb6ec42eb39e 100644 --- a/clang/lib/AST/Interp/InterpBuiltin.cpp +++ b/clang/lib/AST/Interp/InterpBuiltin.cpp @@ -13,6 +13,7 @@ #include "clang/AST/RecordLayout.h" #include "clang/Basic/Builtins.h" #include "clang/Basic/TargetInfo.h" +#include "llvm/Support/SipHash.h" namespace clang { namespace interp { @@ -1100,6 +1101,18 @@ static bool interp__builtin_os_log_format_buffer_size(InterpState &S, return true; } +static bool interp__builtin_ptrauth_string_discriminator( +InterpState &S, CodePtr OpPC, const InterpFrame *Frame, +const Function *Func, const CallExpr *Call) { + const auto &Ptr = S.Stk.peek(); + assert(Ptr.getFieldDesc()->isPrimitiveArray()); + + StringRef R(&Ptr.deref(), Ptr.getFieldDesc()->getNumElems() - 1); + uint64_t Result = getPointerAuthStableSipHash(R); + pushInteger(S, Result, Call->getType()); + return true; +} + bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F, const CallExpr *Call) { const InterpFrame *Frame = S.Current; @@ -1424,6 +1437,11 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F, return false; break; + case Builtin::BI__builtin_ptrauth_string_discriminator: +if (!interp__builtin_ptrauth_string_discriminator(S, OpPC, Frame, F, Call)) + return false; +break; + default: S.FFDiag(S.Current->getLocation(OpPC), diag::note_invalid_subexpr_in_const_expr) diff --git a/clang/test/CodeGen/ptrauth-intrinsics.c b/clang/test/CodeGen/ptrauth-intrinsics.c index db37d78553769..50bf1898e4b37 100644 --- a/clang/test/CodeGen/ptrauth-intrinsics.c +++ b/clang/test/CodeGen/ptrauth-intrinsics.c @@ -1,5 +1,8 @@ // RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-intrinsics -emit-llvm %s -o - | FileCheck %s // RUN: %clang_cc1 -triple aarch64-elf -fptrauth-intrinsics -emit-llvm %s -o - | FileCheck %s +// +// RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-intrinsics -emit-llvm %s -o - -fexperimental-new-constant-interpreter | FileCheck %s +// RUN: %clang_cc1 -triple aarch64-elf -fptrauth-intrinsics -emit-llvm %s -o - -fexperimental-new-constant-interpreter | FileCheck %s void (*fnptr)(void); long int_discriminator; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] cc4ec6d - [C++20] [Modules] Diagnose redeclarations from different modules
Author: Chuanqi Xu Date: 2024-06-24T19:03:31+08:00 New Revision: cc4ec6daf0d4f43110e8220d542c1155b8c1ef51 URL: https://github.com/llvm/llvm-project/commit/cc4ec6daf0d4f43110e8220d542c1155b8c1ef51 DIFF: https://github.com/llvm/llvm-project/commit/cc4ec6daf0d4f43110e8220d542c1155b8c1ef51.diff LOG: [C++20] [Modules] Diagnose redeclarations from different modules [basic.link]/p10: > If two declarations of an entity are attached to different modules, > the program is ill-formed But we only implemented the check for ODR. In this patch, we tried to diagnose the redeclarations from different modules. Added: clang/test/Modules/same-decl-in-different-modules.cppm Modified: clang/include/clang/Basic/DiagnosticSemaKinds.td clang/lib/Serialization/ASTReaderDecl.cpp clang/test/Modules/no-eager-load.cppm Removed: diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index f323d1c6eaf1b..134a4e4d547dd 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -6075,6 +6075,9 @@ def err_thread_thread_ diff erent_kind : Error< def err_mismatched_owning_module : Error< "declaration of %0 in %select{the global module|module %2}1 follows " "declaration in %select{the global module|module %4}3">; +def err_multiple_decl_in_ diff erent_modules : Error< + "declaration %0 attached to named module '%1' can't be attached to " + "other modules">; def err_redefinition_ diff erent_type : Error< "redefinition of %0 with a diff erent type% diff {: $ vs $|}1,2">; def err_redefinition_ diff erent_kind : Error< diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index 4b8b515c02c70..6afb18f932e72 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -3723,6 +3723,23 @@ void ASTDeclReader::attachPreviousDecl(ASTReader &Reader, Decl *D, #include "clang/AST/DeclNodes.inc" } + // [basic.link]/p10: + //If two declarations of an entity are attached to diff erent modules, + //the program is ill-formed; + // + // FIXME: Get rid of the enumeration of decl types once we have an appropriate + // abstract for decls of an entity. e.g., the namespace decl and using decl + // doesn't introduce an entity. + if (Module *M = Previous->getOwningModule(); + M && M->isNamedModule() && + isa(Previous) && + !Reader.getContext().isInSameModule(M, D->getOwningModule())) { +Reader.Diag(Previous->getLocation(), +diag::err_multiple_decl_in_ diff erent_modules) +<< cast(Previous) << M->Name; +Reader.Diag(D->getLocation(), diag::note_also_found); + } + // If the declaration was visible in one module, a redeclaration of it in // another module remains visible even if it wouldn't be visible by itself. // diff --git a/clang/test/Modules/no-eager-load.cppm b/clang/test/Modules/no-eager-load.cppm index 8a2c7656bca2b..c9eddaaed1555 100644 --- a/clang/test/Modules/no-eager-load.cppm +++ b/clang/test/Modules/no-eager-load.cppm @@ -44,6 +44,9 @@ void use() { // expected-note@* {{but in 'a' found a diff erent body}} } +// expected-er...@a.cppm:* {{declaration 'foo' attached to named module 'a' can't be attached to other modules}} +// expected-n...@b.cppm:* {{}} + //--- h.cppm export module h; export import a; @@ -55,3 +58,6 @@ void use() { foo(); // expected-error@* {{'foo' has diff erent definitions in diff erent modules;}} // expected-note@* {{but in 'a' found a diff erent body}} } + +// expected-er...@a.cppm:* {{declaration 'foo' attached to named module 'a' can't be attached to other modules}} +// expected-n...@b.cppm:* {{}} diff --git a/clang/test/Modules/same-decl-in- diff erent-modules.cppm b/clang/test/Modules/same-decl-in- diff erent-modules.cppm new file mode 100644 index 0..2e8e90f7cd8e9 --- /dev/null +++ b/clang/test/Modules/same-decl-in- diff erent-modules.cppm @@ -0,0 +1,42 @@ +// RUN: rm -rf %t +// RUN: mkdir %t +// RUN: split-file %s %t +// +// RUN: %clang_cc1 -std=c++20 %t/mod1.cppm -emit-module-interface -o %t/mod1.pcm +// RUN: %clang_cc1 -std=c++20 %t/mod2.cppm -emit-module-interface -o %t/mod2.pcm +// RUN: %clang_cc1 -std=c++20 %t/test.cc -fprebuilt-module-path=%t -fsyntax-only -verify + +//--- mod1.cppm +export module mod1; +export int v; +export void func(); +export class A {}; +export template +struct S {}; + +//--- mod2.cppm +export module mod2; +export int v; +export void func(); +export class A; +export template +struct S {}; + +//--- test.cc +import mod1; +import mod2; +void test() { +int value = v; +func(); +A a; +S s; +} + +// expected-er...@mod1.cppm:* {{declaration 'v' attached to named module 'mod1' can't be attached to other modules}} +/
[clang] [clang][PowerPC] Add flag to enable compatibility with GNU for complex arguments (PR #77732)
Long5hot wrote: Ping!! https://github.com/llvm/llvm-project/pull/77732 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Add winsysroot alias to the GNU driver (PR #95320)
zmodem wrote: I didn't realize this hadn't been merged already. I'll go ahead and push the button. https://github.com/llvm/llvm-project/pull/95320 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 17e51d5 - [Driver] Add winsysroot alias to the GNU driver (#95320)
Author: Andarwinux Date: 2024-06-24T13:09:39+02:00 New Revision: 17e51d5fc79fc1c9a2a33c13eb02cfbd70c9a221 URL: https://github.com/llvm/llvm-project/commit/17e51d5fc79fc1c9a2a33c13eb02cfbd70c9a221 DIFF: https://github.com/llvm/llvm-project/commit/17e51d5fc79fc1c9a2a33c13eb02cfbd70c9a221.diff LOG: [Driver] Add winsysroot alias to the GNU driver (#95320) fixes #91216 Added: Modified: clang/include/clang/Driver/Options.td Removed: diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 8f915eacdaf6b..c529cc9506667 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -8597,6 +8597,8 @@ def : Separate<["-"], "Xmicrosoft-windows-sdk-root">, Alias<_SLASH_winsdkdir>; def : Separate<["-"], "Xmicrosoft-windows-sdk-version">, Alias<_SLASH_winsdkversion>; +def : Separate<["-"], "Xmicrosoft-windows-sys-root">, +Alias<_SLASH_winsysroot>; // Ignored: ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Add winsysroot alias to the GNU driver (PR #95320)
https://github.com/zmodem closed https://github.com/llvm/llvm-project/pull/95320 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Add winsysroot alias to the GNU driver (PR #95320)
github-actions[bot] wrote: @Andarwinux Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail [here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr). If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of [LLVM development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy). You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! https://github.com/llvm/llvm-project/pull/95320 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Improve diagnostics for constraints of inline asm (NFC) (PR #96363)
@@ -2626,14 +2629,20 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) { SmallVector OutputConstraintInfos; SmallVector InputConstraintInfos; + const FunctionDecl *FD = dyn_cast_or_null(CurCodeDecl); Sirraide wrote: ```suggestion const auto *FD = dyn_cast_if_present(CurCodeDecl); ``` `dyn_cast_or_null` is deprecated (also, no need to spell out the type here since it’s already evident from the cast). https://github.com/llvm/llvm-project/pull/96363 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Improve diagnostics for constraints of inline asm (NFC) (PR #96363)
https://github.com/Sirraide edited https://github.com/llvm/llvm-project/pull/96363 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Improve diagnostics for constraints of inline asm (NFC) (PR #96363)
@@ -309,6 +309,39 @@ def err_asm_invalid_type : Error< def err_ms_asm_bitfield_unsupported : Error< "an inline asm block cannot have an operand which is a bit-field">; +def asm_invalid_constraint_generic : TextSubstitution< + "invalid %select{input|output}0 constraint '%1' in asm">; +def err_asm_invalid_constraint : Error< + "%sub{asm_invalid_constraint_generic}0,1">; +def err_asm_invalid_constraint_start : Error< + "%sub{asm_invalid_constraint_generic}0,1: output constraint must start with" + " '=' or '+'">; +def err_asm_invalid_constraint_rw_clobber : Error< + "%sub{asm_invalid_constraint_generic}0,1: early clobber with a read-write" + " constraint must be a register">; +def err_asm_invalid_constraint_mem_or_reg : Error< + "%sub{asm_invalid_constraint_generic}0,1: constraint must allow either" + " memory or register operands">; +def err_asm_invalid_constraint_missing_bracket : Error< + "%sub{asm_invalid_constraint_generic}0,1: missing ']'">; +def err_asm_invalid_constraint_wrong_symbol : Error< + "%sub{asm_invalid_constraint_generic}0,1: cannot find an output constraint" + " with the specified name">; Sirraide wrote: ```suggestion "%sub{asm_invalid_constraint_generic}0,1: no matching output constraint">; ``` There has to be a corresponding output constraint with the same name as I understand it? This confused me a bit just now while I was looking at the tests, so maybe something like this would make that a bit clearer? https://github.com/llvm/llvm-project/pull/96363 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Improve diagnostics for constraints of inline asm (NFC) (PR #96363)
@@ -309,6 +309,39 @@ def err_asm_invalid_type : Error< def err_ms_asm_bitfield_unsupported : Error< "an inline asm block cannot have an operand which is a bit-field">; +def asm_invalid_constraint_generic : TextSubstitution< + "invalid %select{input|output}0 constraint '%1' in asm">; +def err_asm_invalid_constraint : Error< + "%sub{asm_invalid_constraint_generic}0,1">; +def err_asm_invalid_constraint_start : Error< + "%sub{asm_invalid_constraint_generic}0,1: output constraint must start with" + " '=' or '+'">; +def err_asm_invalid_constraint_rw_clobber : Error< + "%sub{asm_invalid_constraint_generic}0,1: early clobber with a read-write" + " constraint must be a register">; +def err_asm_invalid_constraint_mem_or_reg : Error< + "%sub{asm_invalid_constraint_generic}0,1: constraint must allow either" + " memory or register operands">; +def err_asm_invalid_constraint_missing_bracket : Error< + "%sub{asm_invalid_constraint_generic}0,1: missing ']'">; +def err_asm_invalid_constraint_wrong_symbol : Error< + "%sub{asm_invalid_constraint_generic}0,1: cannot find an output constraint" + " with the specified name">; +def err_asm_invalid_constraint_empty : Error< + "%sub{asm_invalid_constraint_generic}0,1: empty constraint has been" + " provided">; +def err_asm_invalid_constraint_oob : Error< + "%sub{asm_invalid_constraint_generic}0,1: the index is out of bounds">; +def err_asm_invalid_constraint_missing : Error< + "%sub{asm_invalid_constraint_generic}0,1: references to a non-existing output" + " constraint">; Sirraide wrote: ```suggestion "%sub{asm_invalid_constraint_generic}0,1: references non-existent output" " constraint">; ``` nit https://github.com/llvm/llvm-project/pull/96363 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Improve diagnostics for constraints of inline asm (NFC) (PR #96363)
https://github.com/Sirraide commented: Frontend changes look sensible, but I can’t really comment on anything target-specific... https://github.com/llvm/llvm-project/pull/96363 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Improve diagnostics for constraints of inline asm (NFC) (PR #96363)
@@ -309,6 +309,39 @@ def err_asm_invalid_type : Error< def err_ms_asm_bitfield_unsupported : Error< "an inline asm block cannot have an operand which is a bit-field">; +def asm_invalid_constraint_generic : TextSubstitution< + "invalid %select{input|output}0 constraint '%1' in asm">; +def err_asm_invalid_constraint : Error< + "%sub{asm_invalid_constraint_generic}0,1">; +def err_asm_invalid_constraint_start : Error< + "%sub{asm_invalid_constraint_generic}0,1: output constraint must start with" + " '=' or '+'">; +def err_asm_invalid_constraint_rw_clobber : Error< + "%sub{asm_invalid_constraint_generic}0,1: early clobber with a read-write" + " constraint must be a register">; +def err_asm_invalid_constraint_mem_or_reg : Error< + "%sub{asm_invalid_constraint_generic}0,1: constraint must allow either" + " memory or register operands">; +def err_asm_invalid_constraint_missing_bracket : Error< + "%sub{asm_invalid_constraint_generic}0,1: missing ']'">; +def err_asm_invalid_constraint_wrong_symbol : Error< + "%sub{asm_invalid_constraint_generic}0,1: cannot find an output constraint" + " with the specified name">; +def err_asm_invalid_constraint_empty : Error< + "%sub{asm_invalid_constraint_generic}0,1: empty constraint has been" + " provided">; +def err_asm_invalid_constraint_oob : Error< + "%sub{asm_invalid_constraint_generic}0,1: the index is out of bounds">; +def err_asm_invalid_constraint_missing : Error< + "%sub{asm_invalid_constraint_generic}0,1: references to a non-existing output" + " constraint">; +def err_asm_invalid_constraint_wrongly_tied : Error< + "%sub{asm_invalid_constraint_generic}0,1: tied constraint must be tied to" + " the same operand referenced to by the number">; +def err_asm_invalid_constraint_output_only : Error< + "%sub{asm_invalid_constraint_generic}0,1: must refer to an output only" Sirraide wrote: ```suggestion "%sub{asm_invalid_constraint_generic}0,1: must refer to an output-only" ``` another nit here too https://github.com/llvm/llvm-project/pull/96363 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Improve diagnostics for constraints of inline asm (NFC) (PR #96363)
Sirraide wrote: > Initially I've implemented the target errors through std::string. Then > changed to diag::kind after reading InternalsManual. I'm not sure what is > better. Hmm, if they’re not changing very often (if at all), then I’d also use DiagIDs for this, yeah. https://github.com/llvm/llvm-project/pull/96363 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Allow raw string literals in C as an extension (PR #88265)
Sirraide wrote: > I think making it so that the test passes (actually handles raw string > literals) and updating the FIXME in DependencyDirectivesScanner.cpp should be > fine To clarify, that means setting the `RawStringLiterals` LangOpt in `DependencyDirectivesScanner.cpp`, right? I’m assuming yes, but I just want to make sure. https://github.com/llvm/llvm-project/pull/88265 ___ 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)
@@ -430,7 +430,8 @@ void dr081(void) { /* Demonstrate that we don't crash when left shifting a signed value; that's * implementation defined behavior. */ - _Static_assert(-1 << 1 == -2, "fail"); /* Didn't shift a zero into the "sign bit". */ + _Static_assert(-1 << 1 == -2, "fail"); /* c89only-error {{static assertion expression is not an integral constant expression}} budimirarandjelovicsyrmia wrote: This was error in all C language modes. At first, I added diagnosing this error in C mode (file SemaExpr.cpp, lines between 1732-1750, function diagnoseNotICE). After suggestion, I changed it to pedantically emit warning (substitute diagnoseNotICE with diagnoseFold, same part of code). 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][Sema] Fix crash on atomic builtins with incomplete type args (PR #96374)
Sirraide wrote: `RequireCompleteType` seems like the way to go here, yeah. https://github.com/llvm/llvm-project/pull/96374 ___ 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)
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/96422 >From f5938919b3a0060db6b373bead1c52f4bb65c841 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Fri, 21 Jun 2024 12:15:07 +0100 Subject: [PATCH 1/4] [clang][CGRecordLayout] Remove dependency on isZeroSize This is a follow-up from the conversation starting at https://github.com/llvm/llvm-project/pull/93809#issuecomment-2173729801 The root problem that motivated the change are external AST sources that compute `ASTRecordLayout`s themselves instead of letting Clang compute them from the AST. One such examples is LLDB using DWARF to get the definitive offsets and sizes of C++ structures. Such layouts should be considered correct (modulo buggy DWARF), but various assertions and lowering logic around the `CGRecordLayoutBuilder` relies on the AST having `[[no_unique_address]]` attached to them. This is a layout-altering attribute which is not encoded in DWARF. This causes us LLDB to trip over the various LLVM<->Clang layout consistency checks. There has been precedent for avoiding such layout-altering attributes to affect lowering with externally-provided layouts (e.g., packed structs). This patch proposes to replace the `isZeroSize` checks in `CGRecordLayoutBuilder` (which roughly means "empty field with [[no_unique_address]]") with checks for `CodeGen::isEmptyField`/`CodeGen::isEmptyRecord`. --- clang/lib/CodeGen/ABIInfoImpl.cpp | 6 ++--- clang/lib/CodeGen/ABIInfoImpl.h | 6 ++--- clang/lib/CodeGen/CGExpr.cpp | 3 ++- clang/lib/CodeGen/CGRecordLayoutBuilder.cpp | 14 ++-- clang/test/CodeGen/X86/x86_64-vaarg.c | 3 ++- clang/test/CodeGen/debug-info-packed-struct.c | 2 +- clang/test/CodeGen/paren-list-agg-init.cpp| 15 + .../CodeGenCXX/2011-12-19-init-list-ctor.cpp | 6 ++--- clang/test/CodeGenCXX/auto-var-init.cpp | 10 - .../test/CodeGenCXX/bitfield-access-empty.cpp | 16 +++--- clang/test/CodeGenCXX/class-layout.cpp| 2 +- clang/test/CodeGenCXX/compound-literals.cpp | 2 +- clang/test/CodeGenCXX/exceptions.cpp | 7 +++--- .../lambda-deterministic-captures.cpp | 4 +--- clang/test/CodeGenCXX/ms_struct.cpp | 4 +--- clang/test/CodeGenCXX/partial-destruction.cpp | 11 -- clang/test/CodeGenCXX/pr18962.cpp | 5 ++--- clang/test/CodeGenCXX/references.cpp | 4 +--- clang/test/CodeGenCXX/temporaries.cpp | 12 +- clang/test/CodeGenObjCXX/lambda-to-block.mm | 9 clang/test/OpenMP/irbuilder_for_iterator.cpp | 10 - clang/test/OpenMP/irbuilder_for_rangefor.cpp | 14 +--- .../test/OpenMP/task_member_call_codegen.cpp | 22 --- clang/test/Sema/ms_class_layout.cpp | 14 ++-- 24 files changed, 85 insertions(+), 116 deletions(-) diff --git a/clang/lib/CodeGen/ABIInfoImpl.cpp b/clang/lib/CodeGen/ABIInfoImpl.cpp index e9a26abb77837..92fcc3bc2c5f4 100644 --- a/clang/lib/CodeGen/ABIInfoImpl.cpp +++ b/clang/lib/CodeGen/ABIInfoImpl.cpp @@ -248,7 +248,7 @@ Address CodeGen::emitMergePHI(CodeGenFunction &CGF, Address Addr1, return Address(PHI, Addr1.getElementType(), Align); } -bool CodeGen::isEmptyField(ASTContext &Context, const FieldDecl *FD, +bool CodeGen::isEmptyField(const ASTContext &Context, const FieldDecl *FD, bool AllowArrays, bool AsIfNoUniqueAddr) { if (FD->isUnnamedBitField()) return true; @@ -289,8 +289,8 @@ bool CodeGen::isEmptyField(ASTContext &Context, const FieldDecl *FD, return isEmptyRecord(Context, FT, AllowArrays, AsIfNoUniqueAddr); } -bool CodeGen::isEmptyRecord(ASTContext &Context, QualType T, bool AllowArrays, -bool AsIfNoUniqueAddr) { +bool CodeGen::isEmptyRecord(const ASTContext &Context, QualType T, +bool AllowArrays, bool AsIfNoUniqueAddr) { const RecordType *RT = T->getAs(); if (!RT) return false; diff --git a/clang/lib/CodeGen/ABIInfoImpl.h b/clang/lib/CodeGen/ABIInfoImpl.h index 92986fb431646..e3f373e39c35a 100644 --- a/clang/lib/CodeGen/ABIInfoImpl.h +++ b/clang/lib/CodeGen/ABIInfoImpl.h @@ -126,15 +126,15 @@ Address emitMergePHI(CodeGenFunction &CGF, Address Addr1, /// is an unnamed bit-field or an (array of) empty record(s). If /// AsIfNoUniqueAddr is true, then C++ record fields are considered empty if /// the [[no_unique_address]] attribute would have made them empty. -bool isEmptyField(ASTContext &Context, const FieldDecl *FD, bool AllowArrays, - bool AsIfNoUniqueAddr = false); +bool isEmptyField(const ASTContext &Context, const FieldDecl *FD, + bool AllowArrays, bool AsIfNoUniqueAddr = false); /// isEmptyRecord - Return true iff a structure contains only empty /// fields. Note that a structure with a flexible array member is not /// considered empty. If AsIfNoUniqueAddr is true, then C++ r
[clang] [analyzer] Check the correct first and last elements in cstring.UninitializedRead (PR #95408)
@@ -393,6 +401,162 @@ ProgramStateRef CStringChecker::checkNonNull(CheckerContext &C, return stateNonNull; } +static std::optional getIndex(ProgramStateRef State, + const ElementRegion *ER, CharKind CK) { + SValBuilder &SVB = State->getStateManager().getSValBuilder(); + ASTContext &Ctx = SVB.getContext(); + + if (CK == CharKind::Regular) { +if (ER->getValueType() != Ctx.CharTy) + return {}; +return ER->getIndex(); + } + + if (ER->getValueType() != Ctx.WideCharTy) +return {}; + + QualType SizeTy = Ctx.getSizeType(); + NonLoc WideSize = + SVB.makeIntVal(Ctx.getTypeSizeInChars(Ctx.WideCharTy).getQuantity(), + SizeTy) + .castAs(); + SVal Offset = + SVB.evalBinOpNN(State, BO_Mul, ER->getIndex(), WideSize, SizeTy); + if (Offset.isUnknown()) +return {}; + return Offset.castAs(); +} + +// Try to get hold of the origin region (e.g. the actual array region from an +// element region). +static const TypedValueRegion *getOriginRegion(const ElementRegion *ER) { + const MemRegion *MR = ER->getSuperRegion(); + const MemRegion *Ret = MR; + assert(MR); + if (const auto *sym = MR->getAs()) { +SymbolRef sym2 = sym->getSymbol(); +if (!sym2) + return nullptr; +Ret = sym2->getOriginRegion(); + } + return dyn_cast_or_null(Ret); +} + +// Basically 1 -> 1st, 12 -> 12th, etc. +static void printIdxWithOrdinalSuffix(llvm::raw_ostream &Os, unsigned Idx) { + Os << Idx << llvm::getOrdinalSuffix(Idx); Szelethus wrote:  I'm not too hot about this one. I'd keep it as-is. https://github.com/llvm/llvm-project/pull/95408 ___ 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)
https://github.com/kovdan01 created https://github.com/llvm/llvm-project/pull/96478 Depends on #96477 If both `-fptrauth-init-fini` and `-fptrauth-calls` are passed, sign function pointers in `llvm.global_ctors` and `llvm.global_dtors` with constant discriminator 0xD9D4 (`ptrauth_string_discriminator("init_fini")`). Additionally, if `-fptrauth-init-fini-address-discrimination` is passed, address discrimination is used for signing (otherwise, just constant discriminator is used). >From aeece525a037c227018013267ecb30c83e420c57 Mon Sep 17 00:00:00 2001 From: Daniil Kovalev Date: Fri, 21 Jun 2024 12:32:51 +0300 Subject: [PATCH] [PAC][AArch64] Support init/fini array signing If both `-fptrauth-init-fini` and `-fptrauth-calls` are passed, sign function pointers in `llvm.global_ctors` and `llvm.global_dtors` with constant discriminator 0xD9D4 (`ptrauth_string_discriminator("init_fini")`). Additionally, if `-fptrauth-init-fini-address-discrimination` is passed, address discrimination is used for signing (otherwise, just constant discriminator is used). --- clang/include/clang/Basic/Features.def| 1 + clang/include/clang/Basic/LangOptions.def | 1 + .../include/clang/Basic/PointerAuthOptions.h | 7 +++ clang/include/clang/Driver/Options.td | 1 + clang/lib/CodeGen/CodeGenModule.cpp | 63 --- clang/lib/Driver/ToolChains/Clang.cpp | 3 + clang/lib/Frontend/CompilerInvocation.cpp | 9 +++ clang/lib/Headers/ptrauth.h | 8 +++ clang/test/CodeGen/aarch64-elf-pauthabi.c | 12 +++- clang/test/CodeGen/ptrauth-init-fini.c| 45 + clang/test/Driver/aarch64-ptrauth.c | 6 +- clang/test/Preprocessor/ptrauth_feature.c | 52 ++- compiler-rt/lib/builtins/crtbegin.c | 16 + llvm/include/llvm/BinaryFormat/ELF.h | 3 +- .../AArch64/note-gnu-property-elf-pauthabi.ll | 2 +- .../ELF/AArch64/aarch64-feature-pauth.s | 18 +++--- llvm/tools/llvm-readobj/ELFDumper.cpp | 4 +- 17 files changed, 197 insertions(+), 54 deletions(-) create mode 100644 clang/test/CodeGen/ptrauth-init-fini.c diff --git a/clang/include/clang/Basic/Features.def b/clang/include/clang/Basic/Features.def index 53f410d3cb4bd..5dca40b261655 100644 --- a/clang/include/clang/Basic/Features.def +++ b/clang/include/clang/Basic/Features.def @@ -110,6 +110,7 @@ FEATURE(ptrauth_vtable_pointer_address_discrimination, LangOpts.PointerAuthVTPtr FEATURE(ptrauth_vtable_pointer_type_discrimination, LangOpts.PointerAuthVTPtrTypeDiscrimination) FEATURE(ptrauth_member_function_pointer_type_discrimination, LangOpts.PointerAuthCalls) FEATURE(ptrauth_init_fini, LangOpts.PointerAuthInitFini) +FEATURE(ptrauth_init_fini_address_discrimination, LangOpts.PointerAuthInitFiniAddressDiscrimination) EXTENSION(swiftcc, PP.getTargetInfo().checkCallingConvention(CC_Swift) == clang::TargetInfo::CCCR_OK) diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index 6dd6b5614f44c..2de854731 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -168,6 +168,7 @@ LANGOPT(PointerAuthAuthTraps, 1, 0, "pointer authentication failure traps") LANGOPT(PointerAuthVTPtrAddressDiscrimination, 1, 0, "incorporate address discrimination in authenticated vtable pointers") LANGOPT(PointerAuthVTPtrTypeDiscrimination, 1, 0, "incorporate type discrimination in authenticated vtable pointers") LANGOPT(PointerAuthInitFini, 1, 0, "sign function pointers in init/fini arrays") +LANGOPT(PointerAuthInitFiniAddressDiscrimination, 1, 0, "incorporate address discrimination in authenticated function pointers in init/fini arrays") LANGOPT(DoubleSquareBracketAttributes, 1, 0, "'[[]]' attributes extension for all language standard modes") LANGOPT(ExperimentalLateParseAttributes, 1, 0, "experimental late parsing of attributes") diff --git a/clang/include/clang/Basic/PointerAuthOptions.h b/clang/include/clang/Basic/PointerAuthOptions.h index aaad4a2b2b5ae..9e2b64111e461 100644 --- a/clang/include/clang/Basic/PointerAuthOptions.h +++ b/clang/include/clang/Basic/PointerAuthOptions.h @@ -23,6 +23,10 @@ namespace clang { +/// Constant discriminator to be used with function pointers in .init_array and +/// .fini_array. The value is ptrauth_string_discriminator("init_fini") +constexpr uint16_t InitFiniPointerConstantDiscriminator = 0xD9D4; + constexpr unsigned PointerAuthKeyNone = -1; class PointerAuthSchema { @@ -150,6 +154,9 @@ class PointerAuthSchema { struct PointerAuthOptions { /// The ABI for C function pointers. PointerAuthSchema FunctionPointers; + + /// The ABI for function addresses in .init_array and .fini_array + PointerAuthSchema InitFiniPointers; }; } // end namespace clang diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index c529cc9506667..5b8d4139d975
[clang] [Clang][Sema] fix assertion failure about invalid conversion when calling lambda (PR #96431)
https://github.com/Sirraide approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/96431 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Clarify diagnostic notes for implicitly generated deduction guides (PR #96084)
@@ -12114,6 +12115,35 @@ static void NoteFunctionCandidate(Sema &S, OverloadCandidate *Cand, return; } + // If this is an implicit deduction guide against an implicitly defined + // constructor, add a note for it. Neither these deduction guides nor their + // corresponding constructors are explicitly spelled in the source code, Sirraide wrote: Hmm, yeah, if there are situations where that might help, then it might make sense to do that. https://github.com/llvm/llvm-project/pull/96084 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Check the correct first and last elements in cstring.UninitializedRead (PR #95408)
https://github.com/Szelethus updated https://github.com/llvm/llvm-project/pull/95408 From d717b412749f10b45a9387044e97da6981f3cad4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20Umann?= Date: Thu, 25 Apr 2024 17:31:24 +0200 Subject: [PATCH 1/5] [analyzer] Check the correct first and last elements in cstring.UninitializedRead I intend to fix this checker up so that we can move it out of alpha. I made a bunch of analyses, and found many similar false positives: ```c++ int t[] = {1,2,3}; memcpy(dst, t, sizeof(t) / sizeof(t[0])); // warn ``` The problem here is the way CStringChecker checks whether the destination and source buffers are initialized: heuristically, it only checks the first and last element. This is fine, however, it retrieves these elements as characters, even if the underlaying object is not a character array. Reading the last byte of an integer is undefined, so the checker emits a bug here. A quick search tells you the rationale: "Both objects are reinterpreted as arrays of unsigned char.". But the static analyzer right now can't check byte-by-byte if a memory region is _initialized_, it can only check if its a well-defined character or not. In this patch, I pry the original array out of the arguments to memcpy (and similar functions), and retrieve the actual first and last elements according to the array's actual element type. Currently, my improvements reduced the number of reports to 29 on these projects: memcached,tmux,curl,twin,vim,openssl,sqlite,ffmpeg,postgres https://codechecker-demo.eastus.cloudapp.azure.com/Default/reports?detection-status=New&detection-status=Reopened&detection-status=Unresolved&is-unique=on&run=%2acstring_uninit_upper_bound_patched&newcheck=%2acstring_uninit_upper_bounds_patched&diff-type=New&checker-name=alpha.unix.cstring.UninitializedRead&items-per-page=100 Before my patch, there were 87. https://codechecker-demo.eastus.cloudapp.azure.com/Default/reports?detection-status=New&detection-status=Reopened&detection-status=Unresolved&is-unique=on&run=%2acstring_uninit_baseline&newcheck=%2acstring_uninit_upper_bounds_patched&diff-type=New&checker-name=alpha.unix.cstring.UninitializedRead&items-per-page=100 Change-Id: I0ef16beed735201af857abb6ed02de764af2e78a --- .../Core/PathSensitive/MemRegion.h| 14 ++ .../Checkers/CStringChecker.cpp | 226 +++--- clang/test/Analysis/bstring_UninitRead.c | 66 - 3 files changed, 258 insertions(+), 48 deletions(-) diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h index 151d3e57c1cb8..05d679b659029 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h @@ -34,6 +34,7 @@ #include "llvm/ADT/iterator_range.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/Casting.h" +#include "llvm/Support/ErrorHandling.h" #include #include #include @@ -99,6 +100,8 @@ class MemRegion : public llvm::FoldingSetNode { #define REGION(Id, Parent) Id ## Kind, #define REGION_RANGE(Id, First, Last) BEGIN_##Id = First, END_##Id = Last, #include "clang/StaticAnalyzer/Core/PathSensitive/Regions.def" +#undef REGION +#undef REGION_RANGE }; private: @@ -171,6 +174,17 @@ class MemRegion : public llvm::FoldingSetNode { Kind getKind() const { return kind; } + StringRef getKindStr() const { +switch (getKind()) { +#define REGION(Id, Parent) \ + case Id##Kind: \ +return #Id; +#include "clang/StaticAnalyzer/Core/PathSensitive/Regions.def" +#undef REGION +} +llvm_unreachable("Unkown kind!"); + } + template const RegionTy* getAs() const; template LLVM_ATTRIBUTE_RETURNS_NONNULL const RegionTy *castAs() const; diff --git a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp index 238e87a712a43..fdea2e01215b4 100644 --- a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp @@ -12,6 +12,7 @@ //===--===// #include "InterCheckerAPI.h" +#include "clang/AST/OperationKinds.h" #include "clang/Basic/Builtins.h" #include "clang/Basic/CharInfo.h" #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h" @@ -22,10 +23,13 @@ #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h" #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h" #include "clang/StaticAnalyzer/Core/PathSensitive/DynamicExtent.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h" #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h" +#include "llvm/ADT/APSInt.h" #in
[clang] [llvm] [X86][CodeGen] security check cookie execute only when needed (PR #95904)
RKSimon wrote: @mahesh-attarde please can you rebase against trunk - I've cleaned up the test checks to help with the codegen diff https://github.com/llvm/llvm-project/pull/95904 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] efab4a3 - [Sema] Fix -Wunused-variable in SemaType.cpp (NFC)
Author: Jie Fu Date: 2024-06-24T19:40:35+08:00 New Revision: efab4a380f36dcd23561633f8bba484036c500f3 URL: https://github.com/llvm/llvm-project/commit/efab4a380f36dcd23561633f8bba484036c500f3 DIFF: https://github.com/llvm/llvm-project/commit/efab4a380f36dcd23561633f8bba484036c500f3.diff LOG: [Sema] Fix -Wunused-variable in SemaType.cpp (NFC) /llvm-project/clang/lib/Sema/SemaType.cpp:7625:8: error: unused variable 'Success' [-Werror,-Wunused-variable] bool Success = FX.insert(NewEC, Errs); ^ 1 error generated. Added: Modified: clang/lib/Sema/SemaType.cpp Removed: diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 426cd0aa91c01..53b9083c95c1b 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -7622,7 +7622,7 @@ handleNonBlockingNonAllocatingTypeAttr(TypeProcessingState &TPState, FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); FunctionEffectSet FX(EPI.FunctionEffects); FunctionEffectSet::Conflicts Errs; - bool Success = FX.insert(NewEC, Errs); + [[maybe_unused]] bool Success = FX.insert(NewEC, Errs); assert(Success && "effect conflicts should have been diagnosed above"); EPI.FunctionEffects = FunctionEffectsRef(FX); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Remove experimental from Ztso. (PR #96465)
@@ -365,24 +365,30 @@ // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-ZFHMIN %s // RV32-ZFHMIN: "-target-feature" "+zfhmin" -// RUN: not %clang --target=riscv32-unknown-elf -march=rv32iztso -### %s \ +// RUN: not %clang --target=riscv32-unknown-elf -march=rv32izalasr -### %s \ dtcxzyw wrote: Yeah. https://github.com/llvm/llvm-project/pull/96465 ___ 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)
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/96422 >From f5938919b3a0060db6b373bead1c52f4bb65c841 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Fri, 21 Jun 2024 12:15:07 +0100 Subject: [PATCH 1/4] [clang][CGRecordLayout] Remove dependency on isZeroSize This is a follow-up from the conversation starting at https://github.com/llvm/llvm-project/pull/93809#issuecomment-2173729801 The root problem that motivated the change are external AST sources that compute `ASTRecordLayout`s themselves instead of letting Clang compute them from the AST. One such examples is LLDB using DWARF to get the definitive offsets and sizes of C++ structures. Such layouts should be considered correct (modulo buggy DWARF), but various assertions and lowering logic around the `CGRecordLayoutBuilder` relies on the AST having `[[no_unique_address]]` attached to them. This is a layout-altering attribute which is not encoded in DWARF. This causes us LLDB to trip over the various LLVM<->Clang layout consistency checks. There has been precedent for avoiding such layout-altering attributes to affect lowering with externally-provided layouts (e.g., packed structs). This patch proposes to replace the `isZeroSize` checks in `CGRecordLayoutBuilder` (which roughly means "empty field with [[no_unique_address]]") with checks for `CodeGen::isEmptyField`/`CodeGen::isEmptyRecord`. --- clang/lib/CodeGen/ABIInfoImpl.cpp | 6 ++--- clang/lib/CodeGen/ABIInfoImpl.h | 6 ++--- clang/lib/CodeGen/CGExpr.cpp | 3 ++- clang/lib/CodeGen/CGRecordLayoutBuilder.cpp | 14 ++-- clang/test/CodeGen/X86/x86_64-vaarg.c | 3 ++- clang/test/CodeGen/debug-info-packed-struct.c | 2 +- clang/test/CodeGen/paren-list-agg-init.cpp| 15 + .../CodeGenCXX/2011-12-19-init-list-ctor.cpp | 6 ++--- clang/test/CodeGenCXX/auto-var-init.cpp | 10 - .../test/CodeGenCXX/bitfield-access-empty.cpp | 16 +++--- clang/test/CodeGenCXX/class-layout.cpp| 2 +- clang/test/CodeGenCXX/compound-literals.cpp | 2 +- clang/test/CodeGenCXX/exceptions.cpp | 7 +++--- .../lambda-deterministic-captures.cpp | 4 +--- clang/test/CodeGenCXX/ms_struct.cpp | 4 +--- clang/test/CodeGenCXX/partial-destruction.cpp | 11 -- clang/test/CodeGenCXX/pr18962.cpp | 5 ++--- clang/test/CodeGenCXX/references.cpp | 4 +--- clang/test/CodeGenCXX/temporaries.cpp | 12 +- clang/test/CodeGenObjCXX/lambda-to-block.mm | 9 clang/test/OpenMP/irbuilder_for_iterator.cpp | 10 - clang/test/OpenMP/irbuilder_for_rangefor.cpp | 14 +--- .../test/OpenMP/task_member_call_codegen.cpp | 22 --- clang/test/Sema/ms_class_layout.cpp | 14 ++-- 24 files changed, 85 insertions(+), 116 deletions(-) diff --git a/clang/lib/CodeGen/ABIInfoImpl.cpp b/clang/lib/CodeGen/ABIInfoImpl.cpp index e9a26abb77837..92fcc3bc2c5f4 100644 --- a/clang/lib/CodeGen/ABIInfoImpl.cpp +++ b/clang/lib/CodeGen/ABIInfoImpl.cpp @@ -248,7 +248,7 @@ Address CodeGen::emitMergePHI(CodeGenFunction &CGF, Address Addr1, return Address(PHI, Addr1.getElementType(), Align); } -bool CodeGen::isEmptyField(ASTContext &Context, const FieldDecl *FD, +bool CodeGen::isEmptyField(const ASTContext &Context, const FieldDecl *FD, bool AllowArrays, bool AsIfNoUniqueAddr) { if (FD->isUnnamedBitField()) return true; @@ -289,8 +289,8 @@ bool CodeGen::isEmptyField(ASTContext &Context, const FieldDecl *FD, return isEmptyRecord(Context, FT, AllowArrays, AsIfNoUniqueAddr); } -bool CodeGen::isEmptyRecord(ASTContext &Context, QualType T, bool AllowArrays, -bool AsIfNoUniqueAddr) { +bool CodeGen::isEmptyRecord(const ASTContext &Context, QualType T, +bool AllowArrays, bool AsIfNoUniqueAddr) { const RecordType *RT = T->getAs(); if (!RT) return false; diff --git a/clang/lib/CodeGen/ABIInfoImpl.h b/clang/lib/CodeGen/ABIInfoImpl.h index 92986fb431646..e3f373e39c35a 100644 --- a/clang/lib/CodeGen/ABIInfoImpl.h +++ b/clang/lib/CodeGen/ABIInfoImpl.h @@ -126,15 +126,15 @@ Address emitMergePHI(CodeGenFunction &CGF, Address Addr1, /// is an unnamed bit-field or an (array of) empty record(s). If /// AsIfNoUniqueAddr is true, then C++ record fields are considered empty if /// the [[no_unique_address]] attribute would have made them empty. -bool isEmptyField(ASTContext &Context, const FieldDecl *FD, bool AllowArrays, - bool AsIfNoUniqueAddr = false); +bool isEmptyField(const ASTContext &Context, const FieldDecl *FD, + bool AllowArrays, bool AsIfNoUniqueAddr = false); /// isEmptyRecord - Return true iff a structure contains only empty /// fields. Note that a structure with a flexible array member is not /// considered empty. If AsIfNoUniqueAddr is true, then C++ r
[clang] [llvm] [AMDGPU] Enable atomic optimizer for 64 bit divergent values (PR #96473)
arsenm wrote: > Kindly review only the top commit here If you're going to repost with a pre-commit, it would be better to have all the pieces squashed into one. Also you could look into using graphite or SPR for managing dependent pull requests https://github.com/llvm/llvm-project/pull/96473 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 9cd6ef4 - [RISCV] Remove experimental from Ztso. (#96465)
Author: Yingwei Zheng Date: 2024-06-24T20:10:42+08:00 New Revision: 9cd6ef4b8a5c843ef491437c765d4cb2ff2f8fe3 URL: https://github.com/llvm/llvm-project/commit/9cd6ef4b8a5c843ef491437c765d4cb2ff2f8fe3 DIFF: https://github.com/llvm/llvm-project/commit/9cd6ef4b8a5c843ef491437c765d4cb2ff2f8fe3.diff LOG: [RISCV] Remove experimental from Ztso. (#96465) Ztso 1.0 was ratified in January 2023. Documentation: https://github.com/riscv/riscv-isa-manual/blob/main/src/ztso-st-ext.adoc Added: Modified: clang/test/Driver/riscv-arch.c clang/test/Preprocessor/riscv-target-features.c llvm/docs/RISCVUsage.rst llvm/docs/ReleaseNotes.rst llvm/lib/Target/RISCV/RISCVFeatures.td llvm/test/CodeGen/RISCV/GlobalISel/atomic-fence.ll llvm/test/CodeGen/RISCV/atomic-cmpxchg.ll llvm/test/CodeGen/RISCV/atomic-fence.ll llvm/test/CodeGen/RISCV/atomic-load-store.ll llvm/test/CodeGen/RISCV/atomic-rmw.ll llvm/test/CodeGen/RISCV/atomicrmw-uinc-udec-wrap.ll llvm/test/CodeGen/RISCV/attributes.ll llvm/test/CodeGen/RISCV/module-elf-flags.ll llvm/test/MC/RISCV/Ztso.s llvm/test/MC/RISCV/attribute-arch.s llvm/test/MC/RISCV/elf-flags.s llvm/unittests/TargetParser/RISCVISAInfoTest.cpp Removed: diff --git a/clang/test/Driver/riscv-arch.c b/clang/test/Driver/riscv-arch.c index ffd92e1f398c4..c3c471c4bc396 100644 --- a/clang/test/Driver/riscv-arch.c +++ b/clang/test/Driver/riscv-arch.c @@ -365,24 +365,30 @@ // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-ZFHMIN %s // RV32-ZFHMIN: "-target-feature" "+zfhmin" -// RUN: not %clang --target=riscv32-unknown-elf -march=rv32iztso -### %s \ +// RUN: not %clang --target=riscv32-unknown-elf -march=rv32izalasr -### %s \ // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-NOFLAG %s -// RV32-EXPERIMENTAL-NOFLAG: error: invalid arch name 'rv32iztso' +// RV32-EXPERIMENTAL-NOFLAG: error: invalid arch name 'rv32izalasr' // RV32-EXPERIMENTAL-NOFLAG: requires '-menable-experimental-extensions' -// RUN: not %clang --target=riscv32-unknown-elf -march=rv32iztso -menable-experimental-extensions -### %s \ +// RUN: not %clang --target=riscv32-unknown-elf -march=rv32izalasr -menable-experimental-extensions -### %s \ // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-NOVERS %s -// RV32-EXPERIMENTAL-NOVERS: error: invalid arch name 'rv32iztso' +// RV32-EXPERIMENTAL-NOVERS: error: invalid arch name 'rv32izalasr' // RV32-EXPERIMENTAL-NOVERS: experimental extension requires explicit version number -// RUN: not %clang --target=riscv32-unknown-elf -march=rv32iztso0p7 -menable-experimental-extensions -### %s \ +// RUN: not %clang --target=riscv32-unknown-elf -march=rv32izalasr0p7 -menable-experimental-extensions -### %s \ // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-BADVERS %s -// RV32-EXPERIMENTAL-BADVERS: error: invalid arch name 'rv32iztso0p7' -// RV32-EXPERIMENTAL-BADVERS: unsupported version number 0.7 for experimental extension 'ztso' (this compiler supports 0.1) +// RV32-EXPERIMENTAL-BADVERS: error: invalid arch name 'rv32izalasr0p7' +// RV32-EXPERIMENTAL-BADVERS: unsupported version number 0.7 for experimental extension 'zalasr' (this compiler supports 0.1) -// RUN: %clang --target=riscv32-unknown-elf -march=rv32iztso0p1 -menable-experimental-extensions -### %s \ +// RUN: %clang --target=riscv32-unknown-elf -march=rv32izalasr0p1 -menable-experimental-extensions -### %s \ // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-GOODVERS %s -// RV32-EXPERIMENTAL-GOODVERS: "-target-feature" "+experimental-ztso" +// RV32-EXPERIMENTAL-GOODVERS: "-target-feature" "+experimental-zalasr" + +// RUN: %clang --target=riscv32-unknown-elf -march=rv32iztso1p0 -### %s \ +// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-ZTSO %s +// RUN: %clang --target=riscv32-unknown-elf -march=rv32iztso -### %s \ +// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-ZTSO %s +// RV32-ZTSO: "-target-feature" "+ztso" // RUN: %clang --target=riscv32-unknown-elf -march=rv32izbb1p0 -### %s \ // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-ZBB %s diff --git a/clang/test/Preprocessor/riscv-target-features.c b/clang/test/Preprocessor/riscv-target-features.c index d7935af532dfa..46a61e3c0afc7 100644 --- a/clang/test/Preprocessor/riscv-target-features.c +++ b/clang/test/Preprocessor/riscv-target-features.c @@ -1650,13 +1650,13 @@ // RUN: -o - | FileCheck --check-prefix=CHECK-ZICFILP-EXT %s // CHECK-ZICFILP-EXT: __riscv_zicfilp 4000{{$}} -// RUN: %clang --target=riscv32-unknown-linux-gnu -menable-experimental-extensions \ -// RUN: -march=rv32iztso0p1 -E -dM %s \ +// RUN: %clang --target=riscv32-unknown-linux-gnu \ +// RUN: -march=rv32iztso1p0 -E -dM %s \ // RUN: -o - | FileCheck --check-prefix=CHECK-ZTSO-EXT %s -// RUN: %clang --target=riscv64-un
[clang] [llvm] [RISCV] Remove experimental from Ztso. (PR #96465)
https://github.com/dtcxzyw closed https://github.com/llvm/llvm-project/pull/96465 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits