[clang] [Clang] Link libgcc_s.1.dylib when building for macOS 10.5 and older (PR #141401)
https://github.com/Un1q32 updated https://github.com/llvm/llvm-project/pull/141401 >From 3cf20444591e70a8a6d8782048ca4f6c0e22 Mon Sep 17 00:00:00 2001 From: Un1q32 Date: Mon, 27 Jan 2025 18:00:34 -0500 Subject: [PATCH 1/4] [Clang] Link libgcc_s.1.dylib when building for macOS 10.5 and older (intel) --- clang/lib/Driver/ToolChains/Darwin.cpp | 17 + clang/test/Driver/darwin-ld.c | 11 ++- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp index 452820159435f..ddc066d3d18a3 100644 --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -1645,14 +1645,15 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, CmdArgs.push_back("-lSystem"); // Select the dynamic runtime library and the target specific static library. - if (isTargetIOSBased()) { -// If we are compiling as iOS / simulator, don't attempt to link libgcc_s.1, -// it never went into the SDK. -// Linking against libgcc_s.1 isn't needed for iOS 5.0+ -if (isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator() && -getTriple().getArch() != llvm::Triple::aarch64) - CmdArgs.push_back("-lgcc_s.1"); - } + // If we are compiling as iOS / simulator, don't attempt to link libgcc_s.1, + // it never went into the SDK. + // Linking against libgcc_s.1 isn't needed for iOS 5.0+ or macOS 10.6+ + if (isTargetIOSBased() && isIPhoneOSVersionLT(5, 0) && + !isTargetIOSSimulator() && getTriple().getArch() != llvm::Triple::aarch64) +CmdArgs.push_back("-lgcc_s.1"); + else if (isTargetMacOSBased() && isMacosxVersionLT(10, 6) && + getTriple().getArch() != llvm::Triple::aarch64) +CmdArgs.push_back("-lgcc_s.1"); AddLinkRuntimeLib(Args, CmdArgs, "builtins"); } diff --git a/clang/test/Driver/darwin-ld.c b/clang/test/Driver/darwin-ld.c index f0ca411430cc7..9a8d98cdb9c2c 100644 --- a/clang/test/Driver/darwin-ld.c +++ b/clang/test/Driver/darwin-ld.c @@ -240,6 +240,15 @@ // RUN: FileCheck -check-prefix=LINK_NO_IOS_ARM64_LIBGCC_S %s < %t.log // LINK_NO_IOS_ARM64_LIBGCC_S-NOT: lgcc_s.1 +// Check that clang links with libgcc_s.1 for Mac OS X 10.5 and earlier, but not arm64 +// RUN: %clang -target x86_64-apple-macosx10.5 -mmacosx-version-min=10.5 -### %t.o 2> %t.log +// RUN: FileCheck -check-prefix=LINK_OSX_LIBGCC_S %s < %t.log +// LINK_OSX_LIBGCC_S: lgcc_s.1 + +// RUN: %clang -target arm64-apple-macosx10.5 -mmacosx-version-min=10.5 -### %t.o 2> %t.log +// RUN: FileCheck -check-prefix=LINK_NO_OSX_ARM64_LIBGCC_S %s < %t.log +// LINK_NO_OSX_ARM64_LIBGCC_S-NOT: lgcc_s.1 + // RUN: %clang -target x86_64-apple-darwin12 -rdynamic -### %t.o \ // RUN: -fuse-ld= -mlinker-version=100 2> %t.log // RUN: FileCheck -check-prefix=LINK_NO_EXPORT_DYNAMIC %s < %t.log @@ -385,4 +394,4 @@ // RUN: %clang -target armv7em-apple-darwin -mno-outline -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=ARMV7EM-MNO_OUTLINE %s < %t.log // ARMV7EM-MNO_OUTLINE: {{ld(.exe)?"}} -// ARMV7EM-MNO_OUTLINE-SAME: "-mllvm" "-enable-machine-outliner=never" "-mllvm" "-enable-linkonceodr-outlining" \ No newline at end of file +// ARMV7EM-MNO_OUTLINE-SAME: "-mllvm" "-enable-machine-outliner=never" "-mllvm" "-enable-linkonceodr-outlining" >From c82c7704c306f3d86b5226b137521bf7bf98a3cd Mon Sep 17 00:00:00 2001 From: Un1q32 Date: Wed, 4 Jun 2025 00:05:56 -0400 Subject: [PATCH 2/4] change the order of the if statmenets to check aarch64 first --- clang/lib/Driver/ToolChains/Darwin.cpp | 13 +++-- 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp index ddc066d3d18a3..516082192a0c9 100644 --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -1648,12 +1648,13 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, // If we are compiling as iOS / simulator, don't attempt to link libgcc_s.1, // it never went into the SDK. // Linking against libgcc_s.1 isn't needed for iOS 5.0+ or macOS 10.6+ - if (isTargetIOSBased() && isIPhoneOSVersionLT(5, 0) && - !isTargetIOSSimulator() && getTriple().getArch() != llvm::Triple::aarch64) -CmdArgs.push_back("-lgcc_s.1"); - else if (isTargetMacOSBased() && isMacosxVersionLT(10, 6) && - getTriple().getArch() != llvm::Triple::aarch64) -CmdArgs.push_back("-lgcc_s.1"); + if (getTriple().getArch() != llvm::Triple::aarch64) { +if (isTargetIOSBased() && isIPhoneOSVersionLT(5, 0) && +!isTargetIOSSimulator()) + CmdArgs.push_back("-lgcc_s.1"); +else if (isTargetMacOSBased() && isMacosxVersionLT(10, 6)) + CmdArgs.push_back("-lgcc_s.1"); + } AddLinkRuntimeLib(Args, CmdArgs, "builtins"); } >From 40a919ffb3bbf5bbc349d3af871d1d6b869b9e3a Mon Sep 17 00:00:00 2001 From: Un1q32 Date: Wed, 4 Jun 2025 00:12:12 -0400 Subject: [PATCH 3/
[clang] [llvm] [MemProf] Split MemProfiler into Instrumentation and Use. (PR #142811)
@@ -90,4 +66,4 @@ computeUndriftMap(Module &M, IndexedInstrProfReader *MemProfReader, } // namespace memprof } // namespace llvm -#endif +#endif kazutakahirata wrote: nit: could we end with a newline here? A diff involving an unterminated line looks ugly. https://github.com/llvm/llvm-project/pull/142811 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [MemProf] Split MemProfiler into Instrumentation and Use. (PR #142811)
https://github.com/kazutakahirata edited https://github.com/llvm/llvm-project/pull/142811 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [MemProf] Split MemProfiler into Instrumentation and Use. (PR #142811)
https://github.com/kazutakahirata approved this pull request. LGTM. Thanks for doing this! https://github.com/llvm/llvm-project/pull/142811 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 478bdd8 - [clang][bytecode] Save Constexpr bit in Function (#142793)
Author: Timm Baeder Date: 2025-06-05T06:38:48+02:00 New Revision: 478bdd8b9023612a4ef25d50973064e699a95d5b URL: https://github.com/llvm/llvm-project/commit/478bdd8b9023612a4ef25d50973064e699a95d5b DIFF: https://github.com/llvm/llvm-project/commit/478bdd8b9023612a4ef25d50973064e699a95d5b.diff LOG: [clang][bytecode] Save Constexpr bit in Function (#142793) Rename isConstexpr to isValid, the former was always a bad name. Save a constexpr bit in Function so we don't have to access the decl in CheckCallable. Added: Modified: clang/lib/AST/ByteCode/Context.cpp clang/lib/AST/ByteCode/Function.cpp clang/lib/AST/ByteCode/Function.h clang/lib/AST/ByteCode/Interp.cpp Removed: diff --git a/clang/lib/AST/ByteCode/Context.cpp b/clang/lib/AST/ByteCode/Context.cpp index d73705b6126fe..971eb7fd58876 100644 --- a/clang/lib/AST/ByteCode/Context.cpp +++ b/clang/lib/AST/ByteCode/Context.cpp @@ -49,7 +49,7 @@ bool Context::isPotentialConstantExpr(State &Parent, const FunctionDecl *FD) { if (!Run(Parent, Func)) return false; - return Func->isConstexpr(); + return Func->isValid(); } bool Context::evaluateAsRValue(State &Parent, const Expr *E, APValue &Result) { diff --git a/clang/lib/AST/ByteCode/Function.cpp b/clang/lib/AST/ByteCode/Function.cpp index e421dad062817..9eb6744ea47ad 100644 --- a/clang/lib/AST/ByteCode/Function.cpp +++ b/clang/lib/AST/ByteCode/Function.cpp @@ -27,6 +27,7 @@ Function::Function(Program &P, FunctionDeclTy Source, unsigned ArgSize, if (const auto *F = dyn_cast(Source)) { Variadic = F->isVariadic(); Immediate = F->isImmediateFunction(); +Constexpr = F->isConstexpr() || F->hasAttr(); if (const auto *CD = dyn_cast(F)) { Virtual = CD->isVirtual(); Kind = FunctionKind::Ctor; @@ -48,6 +49,7 @@ Function::Function(Program &P, FunctionDeclTy Source, unsigned ArgSize, Variadic = false; Virtual = false; Immediate = false; +Constexpr = false; } } diff --git a/clang/lib/AST/ByteCode/Function.h b/clang/lib/AST/ByteCode/Function.h index 8b577858474af..de88f3ded34dc 100644 --- a/clang/lib/AST/ByteCode/Function.h +++ b/clang/lib/AST/ByteCode/Function.h @@ -150,12 +150,13 @@ class Function final { /// Returns the source information at a given PC. SourceInfo getSource(CodePtr PC) const; - /// Checks if the function is valid to call in constexpr. - bool isConstexpr() const { return IsValid || isLambdaStaticInvoker(); } + /// Checks if the function is valid to call. + bool isValid() const { return IsValid || isLambdaStaticInvoker(); } /// Checks if the function is virtual. bool isVirtual() const { return Virtual; }; bool isImmediate() const { return Immediate; } + bool isConstexpr() const { return Constexpr; } /// Checks if the function is a constructor. bool isConstructor() const { return Kind == FunctionKind::Ctor; } @@ -303,6 +304,8 @@ class Function final { unsigned Virtual : 1; LLVM_PREFERRED_TYPE(bool) unsigned Immediate : 1; + LLVM_PREFERRED_TYPE(bool) + unsigned Constexpr : 1; public: /// Dumps the disassembled bytecode to \c llvm::errs(). diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index db91e5e328485..5c8abffb3a99d 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -857,23 +857,22 @@ bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) { return false; } - // Bail out if the function declaration itself is invalid. We will - // have produced a relevant diagnostic while parsing it, so just - // note the problematic sub-expression. - if (F->getDecl()->isInvalidDecl()) -return Invalid(S, OpPC); - if (S.checkingPotentialConstantExpression() && S.Current->getDepth() != 0) return false; - if (F->isConstexpr() && F->hasBody() && - (F->getDecl()->isConstexpr() || F->getDecl()->hasAttr())) + if (F->isValid() && F->hasBody() && F->isConstexpr()) return true; // Implicitly constexpr. if (F->isLambdaStaticInvoker()) return true; + // Bail out if the function declaration itself is invalid. We will + // have produced a relevant diagnostic while parsing it, so just + // note the problematic sub-expression. + if (F->getDecl()->isInvalidDecl()) +return Invalid(S, OpPC); + // Diagnose failed assertions specially. if (S.Current->getLocation(OpPC).isMacroID() && F->getDecl()->getIdentifier()) { @@ -923,7 +922,8 @@ bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) { // for a constant expression. It might be defined at the point we're // actually calling it. bool IsExtern = DiagDecl->getStorageClass() == SC_Extern; - if (!DiagDecl->isDefined() && !IsExtern && DiagDecl->isConstexpr() && + bool IsDefined = F->isDefined(); + if (!IsDefined && !IsExtern && DiagD
[clang] [clang][bytecode] Save Constexpr bit in Function (PR #142793)
https://github.com/tbaederr closed https://github.com/llvm/llvm-project/pull/142793 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [llvm][RISCV] Make zvknhb imply zvknha (PR #142896)
llvmbot wrote: @llvm/pr-subscribers-backend-risc-v Author: Brandon Wu (4vtomat) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/142896.diff 5 Files Affected: - (modified) clang/include/clang/Basic/riscv_vector.td (+3-3) - (modified) clang/test/Driver/print-enabled-extensions/riscv-sifive-p870.c (+2-1) - (modified) llvm/lib/Target/RISCV/RISCVFeatures.td (+1-1) - (modified) llvm/test/CodeGen/RISCV/attributes.ll (+8-8) - (modified) llvm/test/MC/RISCV/attribute-arch.s (+4-4) ``diff diff --git a/clang/include/clang/Basic/riscv_vector.td b/clang/include/clang/Basic/riscv_vector.td index bff8699463c43..336fa638b7d82 100644 --- a/clang/include/clang/Basic/riscv_vector.td +++ b/clang/include/clang/Basic/riscv_vector.td @@ -2848,9 +2848,9 @@ let UnMaskedPolicyScheme = HasPolicyOperand, HasMasked = false in { // zvknhb let RequiredFeatures = ["Zvknhb"] in { -defm vsha2ch : RVVOutOp2BuiltinSetVVZvk<"il">; -defm vsha2cl : RVVOutOp2BuiltinSetVVZvk<"il">; -defm vsha2ms : RVVOutOp2BuiltinSetVVZvk<"il">; +defm vsha2ch : RVVOutOp2BuiltinSetVVZvk<"l">; +defm vsha2cl : RVVOutOp2BuiltinSetVVZvk<"l">; +defm vsha2ms : RVVOutOp2BuiltinSetVVZvk<"l">; } // zvksed diff --git a/clang/test/Driver/print-enabled-extensions/riscv-sifive-p870.c b/clang/test/Driver/print-enabled-extensions/riscv-sifive-p870.c index f76e5daec672b..c1e08bd8cac23 100644 --- a/clang/test/Driver/print-enabled-extensions/riscv-sifive-p870.c +++ b/clang/test/Driver/print-enabled-extensions/riscv-sifive-p870.c @@ -64,6 +64,7 @@ // CHECK-NEXT: zvknc1.0 'Zvknc' (shorthand for 'Zvknc' and 'Zvbc') // CHECK-NEXT: zvkned 1.0 'Zvkned' (Vector AES Encryption & Decryption (Single Round)) // CHECK-NEXT: zvkng1.0 'Zvkng' (shorthand for 'Zvkn' and 'Zvkg') +// CHECK-NEXT: zvknha 1.0 'Zvknha' (Vector SHA-2 (SHA-256 only)) // CHECK-NEXT: zvknhb 1.0 'Zvknhb' (Vector SHA-2 (SHA-256 and SHA-512)) // CHECK-NEXT: zvks 1.0 'Zvks' (shorthand for 'Zvksed', 'Zvksh', 'Zvkb', and 'Zvkt') // CHECK-NEXT: zvksc1.0 'Zvksc' (shorthand for 'Zvks' and 'Zvbc') @@ -78,4 +79,4 @@ // CHECK-EMPTY: // CHECK-NEXT: Experimental extensions // CHECK-EMPTY: -// CHECK-NEXT: ISA String: rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_b1p0_v1p0_zic64b1p0_zicbom1p0_zicbop1p0_zicboz1p0_ziccamoa1p0_ziccif1p0_zicclsm1p0_ziccrse1p0_zicntr2p0_zicond1p0_zicsr2p0_zifencei2p0_zihintntl1p0_zihintpause2p0_zihpm2p0_zimop1p0_zmmul1p0_za64rs1p0_zaamo1p0_zalrsc1p0_zama16b1p0_zawrs1p0_zfa1p0_zfbfmin1p0_zfh1p0_zfhmin1p0_zca1p0_zcb1p0_zcd1p0_zcmop1p0_zba1p0_zbb1p0_zbs1p0_zkr1p0_zkt1p0_zvbb1p0_zvbc1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvfbfmin1p0_zvfbfwma1p0_zvfh1p0_zvfhmin1p0_zvkb1p0_zvkg1p0_zvkn1p0_zvknc1p0_zvkned1p0_zvkng1p0_zvknhb1p0_zvks1p0_zvksc1p0_zvksed1p0_zvksg1p0_zvksh1p0_zvkt1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0_supm1p0 +// CHECK-NEXT: ISA String: rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_b1p0_v1p0_zic64b1p0_zicbom1p0_zicbop1p0_zicboz1p0_ziccamoa1p0_ziccif1p0_zicclsm1p0_ziccrse1p0_zicntr2p0_zicond1p0_zicsr2p0_zifencei2p0_zihintntl1p0_zihintpause2p0_zihpm2p0_zimop1p0_zmmul1p0_za64rs1p0_zaamo1p0_zalrsc1p0_zama16b1p0_zawrs1p0_zfa1p0_zfbfmin1p0_zfh1p0_zfhmin1p0_zca1p0_zcb1p0_zcd1p0_zcmop1p0_zba1p0_zbb1p0_zbs1p0_zkr1p0_zkt1p0_zvbb1p0_zvbc1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvfbfmin1p0_zvfbfwma1p0_zvfh1p0_zvfhmin1p0_zvkb1p0_zvkg1p0_zvkn1p0_zvknc1p0_zvkned1p0_zvkng1p0_zvknha1p0_zvknhb1p0_zvks1p0_zvksc1p0_zvksed1p0_zvksg1p0_zvksh1p0_zvkt1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0_supm1p0 diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td b/llvm/lib/Target/RISCV/RISCVFeatures.td index 690068d05aaab..32535c0126fd9 100644 --- a/llvm/lib/Target/RISCV/RISCVFeatures.td +++ b/llvm/lib/Target/RISCV/RISCVFeatures.td @@ -787,7 +787,7 @@ def HasStdExtZvknha : Predicate<"Subtarget->hasStdExtZvknha()">, def FeatureStdExtZvknhb : RISCVExtension<1, 0, "Vector SHA-2 (SHA-256 and SHA-512)", - [FeatureStdExtZve64x]>, + [FeatureStdExtZve64x, FeatureStdExtZvknha]>, RISCVExtensionBitmask<0, 56>; def HasStdExtZvknhb : Predicate<"Subtarget->hasStdExtZvknhb()">, AssemblerPredicate<(all_of FeatureStdExtZvknhb), diff --git a/llvm/test/CodeGen/RISCV/attributes.ll b/llvm/test/CodeGen/RISCV/attributes.ll index ba8969b5a5382..a409126b53755 100644 --- a/llvm/test/CodeGen/RISCV/attributes.ll +++ b/llvm/test/CodeGen/RISCV/attributes.ll @@ -476,12 +476,12 @@ ; RV32ZVBC: .attribute 5, "rv32i2p1_zicsr2p0_zvbc1p0_zve32x1p0_zve64x1p0_zvl32b1p0_zvl64b1p0" ; RV32ZVKB: .attribute 5, "rv32i2p1_zicsr2p0_zve32x1p0_zvkb1p0_zvl32b1p0" ; RV32ZVKG: .attribute 5, "rv32i2p1_zicsr2p0_zve32x1p0_zvkg1p0_zvl32b1p0" -; RV32ZVKN: .attribute 5, "rv32i2p1_zicsr2p0_zve32x1p0_zve64x1p0_zvkb1p0_zvkn1p0_zvkned1p0_zvknhb1p
[clang] [clang][CFG] Fix assertion failure in checkIncorrectLogicOperator (PR #142897)
llvmbot wrote: @llvm/pr-subscribers-clang-analysis Author: Ziqing Luo (ziqingluo-90) Changes `checkIncorrectLogicOperator` checks if an expression, for example `x != 0 || x != 1.0`, is always true or false by comparing the two literals `0` and `1.0`. But in case `x` is a 16-bit float, the two literals have distinct types---16-bit float and double, respectively. Directly comparing `APValue`s extracted from the two literals results in an assertion failure because of their distinct types. This commit fixes the issue by doing a conversion from the "smaller" one to the "bigger" one. The two literals must be compatible because both of them are comparing with `x`. rdar://152456316 --- Full diff: https://github.com/llvm/llvm-project/pull/142897.diff 2 Files Affected: - (modified) clang/lib/Analysis/CFG.cpp (+22) - (added) clang/test/Sema/warn-unreachable_crash.cpp (+8) ``diff diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp index 7f37a8b18d46e..c9610cc2888ad 100644 --- a/clang/lib/Analysis/CFG.cpp +++ b/clang/lib/Analysis/CFG.cpp @@ -1261,6 +1261,28 @@ class CFGBuilder { L2Result.Val.getKind() == APValue::Float) { llvm::APFloat L1 = L1Result.Val.getFloat(); llvm::APFloat L2 = L2Result.Val.getFloat(); + // Note that L1 and L2 do not necessarily have the same type. For example + // `x != 0 || x != 1.0`, if `x` is a float16, the two literals `0` and + // `1.0` are float16 and double respectively. In this case, we should do + // a conversion before comparing L1 and L2. Their types must be + // compatible since they are comparing with the same DRE. + int8_t Order = Context->getFloatingTypeOrder(NumExpr1->getType(), + NumExpr2->getType()); + bool convertLoseInfo = false; + + if (Order > 0) { +// type rank L1 > L2: +if (L2.convert(L1.getSemantics(), llvm::APFloat::rmNearestTiesToEven, + &convertLoseInfo)) + return {}; + } else if (Order < 0) +// type rank L1 < L2: +if (L1.convert(L2.getSemantics(), llvm::APFloat::rmNearestTiesToEven, + &convertLoseInfo)) + return {}; + if (convertLoseInfo) +return {}; // If the conversion loses info, bail + llvm::APFloat MidValue = L1; MidValue.add(L2, llvm::APFloat::rmNearestTiesToEven); MidValue.divide(llvm::APFloat(MidValue.getSemantics(), "2.0"), diff --git a/clang/test/Sema/warn-unreachable_crash.cpp b/clang/test/Sema/warn-unreachable_crash.cpp new file mode 100644 index 0..7b23f30c6a214 --- /dev/null +++ b/clang/test/Sema/warn-unreachable_crash.cpp @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -verify -Wunreachable-code %s + +static void test(__fp16& x) { + if (x != 0 || x != 1.0) { // expected-note{{}} + x = 0.9; +} else + x = 0.8; // expected-warning{{code will never be executed}} +} `` https://github.com/llvm/llvm-project/pull/142897 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CFG] Fix assertion failure in checkIncorrectLogicOperator (PR #142897)
https://github.com/ziqingluo-90 created https://github.com/llvm/llvm-project/pull/142897 `checkIncorrectLogicOperator` checks if an expression, for example `x != 0 || x != 1.0`, is always true or false by comparing the two literals `0` and `1.0`. But in case `x` is a 16-bit float, the two literals have distinct types---16-bit float and double, respectively. Directly comparing `APValue`s extracted from the two literals results in an assertion failure because of their distinct types. This commit fixes the issue by doing a conversion from the "smaller" one to the "bigger" one. The two literals must be compatible because both of them are comparing with `x`. rdar://152456316 >From 99931f58846f361e409445d06fdfca4f5e7d3bb3 Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Thu, 5 Jun 2025 12:28:12 +0800 Subject: [PATCH] [clang][CFG] Fix assertion failure in checkIncorrectLogicOperator `checkIncorrectLogicOperator` checks if an expression, for example `x != 0 || x != 1.0`, is always true or false by comparing the two literals `0` and `1.0`. But in case `x` is a 16-bit float, the two literals have distinct types---16-bit float and double, respectively. Directly comparing `APValue`s extracted from the two literals results in an assertion failure because of their distinct types. This commit fixes the issue by doing a conversion from the "smaller" one to the "bigger" one. The two literals must be compatible because both of them are comparing with `x`. rdar://152456316 --- clang/lib/Analysis/CFG.cpp | 22 ++ clang/test/Sema/warn-unreachable_crash.cpp | 8 2 files changed, 30 insertions(+) create mode 100644 clang/test/Sema/warn-unreachable_crash.cpp diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp index 7f37a8b18d46e..c9610cc2888ad 100644 --- a/clang/lib/Analysis/CFG.cpp +++ b/clang/lib/Analysis/CFG.cpp @@ -1261,6 +1261,28 @@ class CFGBuilder { L2Result.Val.getKind() == APValue::Float) { llvm::APFloat L1 = L1Result.Val.getFloat(); llvm::APFloat L2 = L2Result.Val.getFloat(); + // Note that L1 and L2 do not necessarily have the same type. For example + // `x != 0 || x != 1.0`, if `x` is a float16, the two literals `0` and + // `1.0` are float16 and double respectively. In this case, we should do + // a conversion before comparing L1 and L2. Their types must be + // compatible since they are comparing with the same DRE. + int8_t Order = Context->getFloatingTypeOrder(NumExpr1->getType(), + NumExpr2->getType()); + bool convertLoseInfo = false; + + if (Order > 0) { +// type rank L1 > L2: +if (L2.convert(L1.getSemantics(), llvm::APFloat::rmNearestTiesToEven, + &convertLoseInfo)) + return {}; + } else if (Order < 0) +// type rank L1 < L2: +if (L1.convert(L2.getSemantics(), llvm::APFloat::rmNearestTiesToEven, + &convertLoseInfo)) + return {}; + if (convertLoseInfo) +return {}; // If the conversion loses info, bail + llvm::APFloat MidValue = L1; MidValue.add(L2, llvm::APFloat::rmNearestTiesToEven); MidValue.divide(llvm::APFloat(MidValue.getSemantics(), "2.0"), diff --git a/clang/test/Sema/warn-unreachable_crash.cpp b/clang/test/Sema/warn-unreachable_crash.cpp new file mode 100644 index 0..7b23f30c6a214 --- /dev/null +++ b/clang/test/Sema/warn-unreachable_crash.cpp @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -verify -Wunreachable-code %s + +static void test(__fp16& x) { + if (x != 0 || x != 1.0) { // expected-note{{}} + x = 0.9; +} else + x = 0.8; // expected-warning{{code will never be executed}} +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CFG] Fix assertion failure in checkIncorrectLogicOperator (PR #142897)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Ziqing Luo (ziqingluo-90) Changes `checkIncorrectLogicOperator` checks if an expression, for example `x != 0 || x != 1.0`, is always true or false by comparing the two literals `0` and `1.0`. But in case `x` is a 16-bit float, the two literals have distinct types---16-bit float and double, respectively. Directly comparing `APValue`s extracted from the two literals results in an assertion failure because of their distinct types. This commit fixes the issue by doing a conversion from the "smaller" one to the "bigger" one. The two literals must be compatible because both of them are comparing with `x`. rdar://152456316 --- Full diff: https://github.com/llvm/llvm-project/pull/142897.diff 2 Files Affected: - (modified) clang/lib/Analysis/CFG.cpp (+22) - (added) clang/test/Sema/warn-unreachable_crash.cpp (+8) ``diff diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp index 7f37a8b18d46e..c9610cc2888ad 100644 --- a/clang/lib/Analysis/CFG.cpp +++ b/clang/lib/Analysis/CFG.cpp @@ -1261,6 +1261,28 @@ class CFGBuilder { L2Result.Val.getKind() == APValue::Float) { llvm::APFloat L1 = L1Result.Val.getFloat(); llvm::APFloat L2 = L2Result.Val.getFloat(); + // Note that L1 and L2 do not necessarily have the same type. For example + // `x != 0 || x != 1.0`, if `x` is a float16, the two literals `0` and + // `1.0` are float16 and double respectively. In this case, we should do + // a conversion before comparing L1 and L2. Their types must be + // compatible since they are comparing with the same DRE. + int8_t Order = Context->getFloatingTypeOrder(NumExpr1->getType(), + NumExpr2->getType()); + bool convertLoseInfo = false; + + if (Order > 0) { +// type rank L1 > L2: +if (L2.convert(L1.getSemantics(), llvm::APFloat::rmNearestTiesToEven, + &convertLoseInfo)) + return {}; + } else if (Order < 0) +// type rank L1 < L2: +if (L1.convert(L2.getSemantics(), llvm::APFloat::rmNearestTiesToEven, + &convertLoseInfo)) + return {}; + if (convertLoseInfo) +return {}; // If the conversion loses info, bail + llvm::APFloat MidValue = L1; MidValue.add(L2, llvm::APFloat::rmNearestTiesToEven); MidValue.divide(llvm::APFloat(MidValue.getSemantics(), "2.0"), diff --git a/clang/test/Sema/warn-unreachable_crash.cpp b/clang/test/Sema/warn-unreachable_crash.cpp new file mode 100644 index 0..7b23f30c6a214 --- /dev/null +++ b/clang/test/Sema/warn-unreachable_crash.cpp @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -verify -Wunreachable-code %s + +static void test(__fp16& x) { + if (x != 0 || x != 1.0) { // expected-note{{}} + x = 0.9; +} else + x = 0.8; // expected-warning{{code will never be executed}} +} `` https://github.com/llvm/llvm-project/pull/142897 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CFG] Fix assertion failure in checkIncorrectLogicOperator (PR #142897)
ziqingluo-90 wrote: Godbolt example: https://godbolt.org/z/6dv3Kearx CC @YutongZhuu as this issue was first introduced in https://github.com/YutongZhuu/llvm-project/commit/9ae3368b3b912ae425b2fbe9a59949979286744f https://github.com/llvm/llvm-project/pull/142897 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [llvm][RISCV] Make zvknhb imply zvknha (PR #142896)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Brandon Wu (4vtomat) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/142896.diff 5 Files Affected: - (modified) clang/include/clang/Basic/riscv_vector.td (+3-3) - (modified) clang/test/Driver/print-enabled-extensions/riscv-sifive-p870.c (+2-1) - (modified) llvm/lib/Target/RISCV/RISCVFeatures.td (+1-1) - (modified) llvm/test/CodeGen/RISCV/attributes.ll (+8-8) - (modified) llvm/test/MC/RISCV/attribute-arch.s (+4-4) ``diff diff --git a/clang/include/clang/Basic/riscv_vector.td b/clang/include/clang/Basic/riscv_vector.td index bff8699463c43..336fa638b7d82 100644 --- a/clang/include/clang/Basic/riscv_vector.td +++ b/clang/include/clang/Basic/riscv_vector.td @@ -2848,9 +2848,9 @@ let UnMaskedPolicyScheme = HasPolicyOperand, HasMasked = false in { // zvknhb let RequiredFeatures = ["Zvknhb"] in { -defm vsha2ch : RVVOutOp2BuiltinSetVVZvk<"il">; -defm vsha2cl : RVVOutOp2BuiltinSetVVZvk<"il">; -defm vsha2ms : RVVOutOp2BuiltinSetVVZvk<"il">; +defm vsha2ch : RVVOutOp2BuiltinSetVVZvk<"l">; +defm vsha2cl : RVVOutOp2BuiltinSetVVZvk<"l">; +defm vsha2ms : RVVOutOp2BuiltinSetVVZvk<"l">; } // zvksed diff --git a/clang/test/Driver/print-enabled-extensions/riscv-sifive-p870.c b/clang/test/Driver/print-enabled-extensions/riscv-sifive-p870.c index f76e5daec672b..c1e08bd8cac23 100644 --- a/clang/test/Driver/print-enabled-extensions/riscv-sifive-p870.c +++ b/clang/test/Driver/print-enabled-extensions/riscv-sifive-p870.c @@ -64,6 +64,7 @@ // CHECK-NEXT: zvknc1.0 'Zvknc' (shorthand for 'Zvknc' and 'Zvbc') // CHECK-NEXT: zvkned 1.0 'Zvkned' (Vector AES Encryption & Decryption (Single Round)) // CHECK-NEXT: zvkng1.0 'Zvkng' (shorthand for 'Zvkn' and 'Zvkg') +// CHECK-NEXT: zvknha 1.0 'Zvknha' (Vector SHA-2 (SHA-256 only)) // CHECK-NEXT: zvknhb 1.0 'Zvknhb' (Vector SHA-2 (SHA-256 and SHA-512)) // CHECK-NEXT: zvks 1.0 'Zvks' (shorthand for 'Zvksed', 'Zvksh', 'Zvkb', and 'Zvkt') // CHECK-NEXT: zvksc1.0 'Zvksc' (shorthand for 'Zvks' and 'Zvbc') @@ -78,4 +79,4 @@ // CHECK-EMPTY: // CHECK-NEXT: Experimental extensions // CHECK-EMPTY: -// CHECK-NEXT: ISA String: rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_b1p0_v1p0_zic64b1p0_zicbom1p0_zicbop1p0_zicboz1p0_ziccamoa1p0_ziccif1p0_zicclsm1p0_ziccrse1p0_zicntr2p0_zicond1p0_zicsr2p0_zifencei2p0_zihintntl1p0_zihintpause2p0_zihpm2p0_zimop1p0_zmmul1p0_za64rs1p0_zaamo1p0_zalrsc1p0_zama16b1p0_zawrs1p0_zfa1p0_zfbfmin1p0_zfh1p0_zfhmin1p0_zca1p0_zcb1p0_zcd1p0_zcmop1p0_zba1p0_zbb1p0_zbs1p0_zkr1p0_zkt1p0_zvbb1p0_zvbc1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvfbfmin1p0_zvfbfwma1p0_zvfh1p0_zvfhmin1p0_zvkb1p0_zvkg1p0_zvkn1p0_zvknc1p0_zvkned1p0_zvkng1p0_zvknhb1p0_zvks1p0_zvksc1p0_zvksed1p0_zvksg1p0_zvksh1p0_zvkt1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0_supm1p0 +// CHECK-NEXT: ISA String: rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_b1p0_v1p0_zic64b1p0_zicbom1p0_zicbop1p0_zicboz1p0_ziccamoa1p0_ziccif1p0_zicclsm1p0_ziccrse1p0_zicntr2p0_zicond1p0_zicsr2p0_zifencei2p0_zihintntl1p0_zihintpause2p0_zihpm2p0_zimop1p0_zmmul1p0_za64rs1p0_zaamo1p0_zalrsc1p0_zama16b1p0_zawrs1p0_zfa1p0_zfbfmin1p0_zfh1p0_zfhmin1p0_zca1p0_zcb1p0_zcd1p0_zcmop1p0_zba1p0_zbb1p0_zbs1p0_zkr1p0_zkt1p0_zvbb1p0_zvbc1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvfbfmin1p0_zvfbfwma1p0_zvfh1p0_zvfhmin1p0_zvkb1p0_zvkg1p0_zvkn1p0_zvknc1p0_zvkned1p0_zvkng1p0_zvknha1p0_zvknhb1p0_zvks1p0_zvksc1p0_zvksed1p0_zvksg1p0_zvksh1p0_zvkt1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0_supm1p0 diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td b/llvm/lib/Target/RISCV/RISCVFeatures.td index 690068d05aaab..32535c0126fd9 100644 --- a/llvm/lib/Target/RISCV/RISCVFeatures.td +++ b/llvm/lib/Target/RISCV/RISCVFeatures.td @@ -787,7 +787,7 @@ def HasStdExtZvknha : Predicate<"Subtarget->hasStdExtZvknha()">, def FeatureStdExtZvknhb : RISCVExtension<1, 0, "Vector SHA-2 (SHA-256 and SHA-512)", - [FeatureStdExtZve64x]>, + [FeatureStdExtZve64x, FeatureStdExtZvknha]>, RISCVExtensionBitmask<0, 56>; def HasStdExtZvknhb : Predicate<"Subtarget->hasStdExtZvknhb()">, AssemblerPredicate<(all_of FeatureStdExtZvknhb), diff --git a/llvm/test/CodeGen/RISCV/attributes.ll b/llvm/test/CodeGen/RISCV/attributes.ll index ba8969b5a5382..a409126b53755 100644 --- a/llvm/test/CodeGen/RISCV/attributes.ll +++ b/llvm/test/CodeGen/RISCV/attributes.ll @@ -476,12 +476,12 @@ ; RV32ZVBC: .attribute 5, "rv32i2p1_zicsr2p0_zvbc1p0_zve32x1p0_zve64x1p0_zvl32b1p0_zvl64b1p0" ; RV32ZVKB: .attribute 5, "rv32i2p1_zicsr2p0_zve32x1p0_zvkb1p0_zvl32b1p0" ; RV32ZVKG: .attribute 5, "rv32i2p1_zicsr2p0_zve32x1p0_zvkg1p0_zvl32b1p0" -; RV32ZVKN: .attribute 5, "rv32i2p1_zicsr2p0_zve32x1p0_zve64x1p0_zvkb1p0_zvkn1p0_zvkned1p0_zvknhb1p0_zvkt1p0
[clang] [llvm] [llvm][RISCV] Make zvknhb imply zvknha (PR #142896)
https://github.com/4vtomat created https://github.com/llvm/llvm-project/pull/142896 None >From f8279f47ea299ba45496c7146ace152fd3715d48 Mon Sep 17 00:00:00 2001 From: Brandon Wu Date: Wed, 4 Jun 2025 21:41:46 -0700 Subject: [PATCH] [llvm][RISCV] Make zvknhb imply zvknha --- clang/include/clang/Basic/riscv_vector.td| 6 +++--- .../print-enabled-extensions/riscv-sifive-p870.c | 3 ++- llvm/lib/Target/RISCV/RISCVFeatures.td | 2 +- llvm/test/CodeGen/RISCV/attributes.ll| 16 llvm/test/MC/RISCV/attribute-arch.s | 8 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/clang/include/clang/Basic/riscv_vector.td b/clang/include/clang/Basic/riscv_vector.td index bff8699463c43..336fa638b7d82 100644 --- a/clang/include/clang/Basic/riscv_vector.td +++ b/clang/include/clang/Basic/riscv_vector.td @@ -2848,9 +2848,9 @@ let UnMaskedPolicyScheme = HasPolicyOperand, HasMasked = false in { // zvknhb let RequiredFeatures = ["Zvknhb"] in { -defm vsha2ch : RVVOutOp2BuiltinSetVVZvk<"il">; -defm vsha2cl : RVVOutOp2BuiltinSetVVZvk<"il">; -defm vsha2ms : RVVOutOp2BuiltinSetVVZvk<"il">; +defm vsha2ch : RVVOutOp2BuiltinSetVVZvk<"l">; +defm vsha2cl : RVVOutOp2BuiltinSetVVZvk<"l">; +defm vsha2ms : RVVOutOp2BuiltinSetVVZvk<"l">; } // zvksed diff --git a/clang/test/Driver/print-enabled-extensions/riscv-sifive-p870.c b/clang/test/Driver/print-enabled-extensions/riscv-sifive-p870.c index f76e5daec672b..c1e08bd8cac23 100644 --- a/clang/test/Driver/print-enabled-extensions/riscv-sifive-p870.c +++ b/clang/test/Driver/print-enabled-extensions/riscv-sifive-p870.c @@ -64,6 +64,7 @@ // CHECK-NEXT: zvknc1.0 'Zvknc' (shorthand for 'Zvknc' and 'Zvbc') // CHECK-NEXT: zvkned 1.0 'Zvkned' (Vector AES Encryption & Decryption (Single Round)) // CHECK-NEXT: zvkng1.0 'Zvkng' (shorthand for 'Zvkn' and 'Zvkg') +// CHECK-NEXT: zvknha 1.0 'Zvknha' (Vector SHA-2 (SHA-256 only)) // CHECK-NEXT: zvknhb 1.0 'Zvknhb' (Vector SHA-2 (SHA-256 and SHA-512)) // CHECK-NEXT: zvks 1.0 'Zvks' (shorthand for 'Zvksed', 'Zvksh', 'Zvkb', and 'Zvkt') // CHECK-NEXT: zvksc1.0 'Zvksc' (shorthand for 'Zvks' and 'Zvbc') @@ -78,4 +79,4 @@ // CHECK-EMPTY: // CHECK-NEXT: Experimental extensions // CHECK-EMPTY: -// CHECK-NEXT: ISA String: rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_b1p0_v1p0_zic64b1p0_zicbom1p0_zicbop1p0_zicboz1p0_ziccamoa1p0_ziccif1p0_zicclsm1p0_ziccrse1p0_zicntr2p0_zicond1p0_zicsr2p0_zifencei2p0_zihintntl1p0_zihintpause2p0_zihpm2p0_zimop1p0_zmmul1p0_za64rs1p0_zaamo1p0_zalrsc1p0_zama16b1p0_zawrs1p0_zfa1p0_zfbfmin1p0_zfh1p0_zfhmin1p0_zca1p0_zcb1p0_zcd1p0_zcmop1p0_zba1p0_zbb1p0_zbs1p0_zkr1p0_zkt1p0_zvbb1p0_zvbc1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvfbfmin1p0_zvfbfwma1p0_zvfh1p0_zvfhmin1p0_zvkb1p0_zvkg1p0_zvkn1p0_zvknc1p0_zvkned1p0_zvkng1p0_zvknhb1p0_zvks1p0_zvksc1p0_zvksed1p0_zvksg1p0_zvksh1p0_zvkt1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0_supm1p0 +// CHECK-NEXT: ISA String: rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_b1p0_v1p0_zic64b1p0_zicbom1p0_zicbop1p0_zicboz1p0_ziccamoa1p0_ziccif1p0_zicclsm1p0_ziccrse1p0_zicntr2p0_zicond1p0_zicsr2p0_zifencei2p0_zihintntl1p0_zihintpause2p0_zihpm2p0_zimop1p0_zmmul1p0_za64rs1p0_zaamo1p0_zalrsc1p0_zama16b1p0_zawrs1p0_zfa1p0_zfbfmin1p0_zfh1p0_zfhmin1p0_zca1p0_zcb1p0_zcd1p0_zcmop1p0_zba1p0_zbb1p0_zbs1p0_zkr1p0_zkt1p0_zvbb1p0_zvbc1p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvfbfmin1p0_zvfbfwma1p0_zvfh1p0_zvfhmin1p0_zvkb1p0_zvkg1p0_zvkn1p0_zvknc1p0_zvkned1p0_zvkng1p0_zvknha1p0_zvknhb1p0_zvks1p0_zvksc1p0_zvksed1p0_zvksg1p0_zvksh1p0_zvkt1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0_supm1p0 diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td b/llvm/lib/Target/RISCV/RISCVFeatures.td index 690068d05aaab..32535c0126fd9 100644 --- a/llvm/lib/Target/RISCV/RISCVFeatures.td +++ b/llvm/lib/Target/RISCV/RISCVFeatures.td @@ -787,7 +787,7 @@ def HasStdExtZvknha : Predicate<"Subtarget->hasStdExtZvknha()">, def FeatureStdExtZvknhb : RISCVExtension<1, 0, "Vector SHA-2 (SHA-256 and SHA-512)", - [FeatureStdExtZve64x]>, + [FeatureStdExtZve64x, FeatureStdExtZvknha]>, RISCVExtensionBitmask<0, 56>; def HasStdExtZvknhb : Predicate<"Subtarget->hasStdExtZvknhb()">, AssemblerPredicate<(all_of FeatureStdExtZvknhb), diff --git a/llvm/test/CodeGen/RISCV/attributes.ll b/llvm/test/CodeGen/RISCV/attributes.ll index ba8969b5a5382..a409126b53755 100644 --- a/llvm/test/CodeGen/RISCV/attributes.ll +++ b/llvm/test/CodeGen/RISCV/attributes.ll @@ -476,12 +476,12 @@ ; RV32ZVBC: .attribute 5, "rv32i2p1_zicsr2p0_zvbc1p0_zve32x1p0_zve64x1p0_zvl32b1p0_zvl64b1p0" ; RV32ZVKB: .attribute 5, "rv32i2p1_zicsr2p0_zve32x1p0_zvkb1p0_zvl32b1p0" ; RV32ZVKG: .attribute 5, "rv32i2p1_zicsr2p0_zve32x1p0_z
[clang-tools-extra] [clang-tidy] Add check for assignment or comparision operators' operand in `readability-math-missing-parentheses` (PR #141345)
vbvictor wrote: @flovent, please change email from private to public in github settings If you wish to have actual email written in commit. https://github.com/llvm/llvm-project/pull/141345 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Modules] Don't fail when an unused textual header is missing. (PR #138227)
vsapsai wrote: I'll be busy during WWDC week too, so no real changes are expected in the next 2 weeks. https://github.com/llvm/llvm-project/pull/138227 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [StaticAnalyzer] Fix tryExpandAsInteger's failures on PCH macros (PR #142722)
ziqingluo-90 wrote: CC @dtarditi https://github.com/llvm/llvm-project/pull/142722 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [llvm][RISCV] Make zvknhb imply zvknha (PR #142896)
https://github.com/tclin914 approved this pull request. Refer to https://github.com/riscv/riscv-crypto/blob/main/doc/vector/riscv-crypto-vector-zvknh.adoc. LGTM https://github.com/llvm/llvm-project/pull/142896 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [StaticAnalyzer] Fix tryExpandAsInteger's failures on PCH macros (PR #142722)
https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/142722 >From 3bd12ac6bb3c47b5e977cffec019df15a15426fc Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Wed, 4 Jun 2025 12:29:53 +0800 Subject: [PATCH 1/2] [StaticAnalyzer] Fix tryExpandAsInteger's failures on macros from PCHs The function `tryExpandAsInteger` attempts to extract an integer from a macro definition. Previously, the attempt would fail when the macro is from a PCH, because the function tried to access the text buffer of the source file, which does not exist in case of PCHs. The fix uses `Preprocessor::getSpelling`, which works in either cases. rdar://151403070 --- .../StaticAnalyzer/Core/CheckerHelpers.cpp| 16 ++-- clang/test/Analysis/pch_crash.cpp | 28 - clang/test/Analysis/pch_macro.cpp | 39 +++ 3 files changed, 51 insertions(+), 32 deletions(-) delete mode 100644 clang/test/Analysis/pch_crash.cpp create mode 100644 clang/test/Analysis/pch_macro.cpp diff --git a/clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp b/clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp index 4ed4113919c1d..111af35806dda 100644 --- a/clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp +++ b/clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp @@ -129,11 +129,19 @@ std::optional tryExpandAsInteger(StringRef Macro, const Preprocessor &PP) { // Parse an integer at the end of the macro definition. const Token &T = FilteredTokens.back(); - // FIXME: EOF macro token coming from a PCH file on macOS while marked as - //literal, doesn't contain any literal data - if (!T.isLiteral() || !T.getLiteralData()) + + if (!T.isLiteral()) return std::nullopt; - StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength()); + + bool InvalidSpelling = false; + // `Preprocessor::getSpelling` can get the spelling of the token regardless of + // whether the macro is defined in a PCH or not: + std::string Spelling = PP.getSpelling(T, &InvalidSpelling); + + if (InvalidSpelling) +return std::nullopt; + + StringRef ValueStr(Spelling); llvm::APInt IntValue; constexpr unsigned AutoSenseRadix = 0; if (ValueStr.getAsInteger(AutoSenseRadix, IntValue)) diff --git a/clang/test/Analysis/pch_crash.cpp b/clang/test/Analysis/pch_crash.cpp deleted file mode 100644 index 7ad2cb2d2ab57..0 --- a/clang/test/Analysis/pch_crash.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// RUN: %clang_cc1 -triple x86_64-apple-macosx10.15.0 -emit-pch -o %t %s -// RUN: %clang_analyze_cc1 -triple x86_64-apple-macosx10.15.0 -include-pch %t \ -// RUN: -analyzer-checker=core,apiModeling -verify %s -// -// RUN: %clang_cc1 -emit-pch -o %t %s -// RUN: %clang_analyze_cc1 -include-pch %t \ -// RUN: -analyzer-checker=core,apiModeling -verify %s - -// expected-no-diagnostics - -#ifndef HEADER -#define HEADER -// Pre-compiled header - -int foo(); - -// Literal data for this macro value will be null -#define EOF -1 - -#else -// Source file - -int test() { - // we need a function call here to initiate erroneous routine - return foo(); // no-crash -} - -#endif diff --git a/clang/test/Analysis/pch_macro.cpp b/clang/test/Analysis/pch_macro.cpp new file mode 100644 index 0..0cc00cfe0cc17 --- /dev/null +++ b/clang/test/Analysis/pch_macro.cpp @@ -0,0 +1,39 @@ +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.15.0 -emit-pch -o %t %s +// RUN: %clang_analyze_cc1 -triple x86_64-apple-macosx10.15.0 -include-pch %t \ +// RUN: -analyzer-checker=core,apiModeling,unix.StdCLibraryFunctions -verify %s +// +// RUN: %clang_cc1 -emit-pch -o %t %s +// RUN: %clang_analyze_cc1 -include-pch %t \ +// RUN: -analyzer-checker=core,apiModeling,unix.StdCLibraryFunctions -verify %s + +// expected-no-diagnostics + +#ifndef HEADER +#define HEADER +// Pre-compiled header + +int foo(); + +// Literal data for macro values will be null as they are defined in a PCH +#define EOF -1 +#define AT_FDCWD -2 + +#else +// Source file + +int test() { + // we need a function call here to initiate erroneous routine + return foo(); // no-crash +} + +// Test that StdLibraryFunctionsChecker can obtain the definition of +// AT_FDCWD even if it is from a PCH: +int faccessat(int, const char *, int, int); + +void test_faccessat() { + char fileSystemPath[10] = { 0 }; + + if (0 != faccessat(AT_FDCWD, fileSystemPath, 2, 0x0030)) {} +} + +#endif >From 8893dd5ae0784821c4c82f1c0ed65e25c832eff0 Mon Sep 17 00:00:00 2001 From: Ziqing Luo Date: Thu, 5 Jun 2025 13:14:03 +0800 Subject: [PATCH 2/2] address comments --- .../StaticAnalyzer/Core/CheckerHelpers.cpp| 4 +-- clang/test/Analysis/pch_macro.cpp | 30 +++ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp b/clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp index 111af35806dda..8b404377186e9 100644 --- a/clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp +++ b/clang/lib/StaticAn
[clang-tools-extra] [clangd] Implement LSP 3.17 positionEncoding (PR #142903)
https://github.com/someoneinjd created https://github.com/llvm/llvm-project/pull/142903 This PR adds support for the `positionEncoding` client capability introduced in LSP 3.17. Clangd can now negotiate the position encoding with the client during initialization. >From 5717ca8166a019e4c007099ce243d4f4bd88b599 Mon Sep 17 00:00:00 2001 From: someoneinjd Date: Thu, 5 Jun 2025 13:51:40 +0800 Subject: [PATCH] [clangd] Implement LSP 3.17 positionEncoding --- clang-tools-extra/clangd/ClangdLSPServer.cpp | 3 ++ clang-tools-extra/clangd/Protocol.cpp | 6 .../clangd/test/positionencoding.test | 32 +++ 3 files changed, 41 insertions(+) create mode 100644 clang-tools-extra/clangd/test/positionencoding.test diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp index 29321f7cd3fa2..e7b8cb5f6c79d 100644 --- a/clang-tools-extra/clangd/ClangdLSPServer.cpp +++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp @@ -686,6 +686,9 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params, ServerCaps["executeCommandProvider"] = llvm::json::Object{{"commands", Commands}}; + if (Opts.Encoding) +ServerCaps["positionEncoding"] = *Opts.Encoding; + llvm::json::Object Result{ {{"serverInfo", llvm::json::Object{ diff --git a/clang-tools-extra/clangd/Protocol.cpp b/clang-tools-extra/clangd/Protocol.cpp index c9e8a175b5d76..bf733af18ad3a 100644 --- a/clang-tools-extra/clangd/Protocol.cpp +++ b/clang-tools-extra/clangd/Protocol.cpp @@ -497,6 +497,12 @@ bool fromJSON(const llvm::json::Value &Params, ClientCapabilities &R, if (auto Cancel = StaleRequestSupport->getBoolean("cancel")) R.CancelsStaleRequests = *Cancel; } +if (auto *OffsetEncoding = General->get("positionEncodings")) { + R.offsetEncoding.emplace(); + if (!fromJSON(*OffsetEncoding, *R.offsetEncoding, +P.field("general").field("positionEncodings"))) +return false; +} } if (auto *OffsetEncoding = O->get("offsetEncoding")) { R.offsetEncoding.emplace(); diff --git a/clang-tools-extra/clangd/test/positionencoding.test b/clang-tools-extra/clangd/test/positionencoding.test new file mode 100644 index 0..eea7a1a596e9a --- /dev/null +++ b/clang-tools-extra/clangd/test/positionencoding.test @@ -0,0 +1,32 @@ +# RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s +# This test verifies that we can negotiate UTF-8 offsets via the positionEncodings capability introduced in LSP 3.17. +{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{"general":{"positionEncodings":["utf-8","utf-16"]}},"trace":"off"}} +# CHECK: "positionEncoding": "utf-8" +--- +{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///main.cpp","languageId":"cpp","version":1,"text":"/*ö*/int x;\nint y=x;"}}} +--- +{"jsonrpc":"2.0","id":1,"method":"textDocument/definition","params":{"textDocument":{"uri":"test:///main.cpp"},"position":{"line":1,"character":6}}} +# /*ö*/int x; +# 01234567890 +# x is character (and utf-16) range [9,10) but byte range [10,11). +# CHECK: "id": 1, +# CHECK-NEXT: "jsonrpc": "2.0", +# CHECK-NEXT: "result": [ +# CHECK-NEXT:{ +# CHECK-NEXT: "range": { +# CHECK-NEXT:"end": { +# CHECK-NEXT: "character": 11, +# CHECK-NEXT: "line": 0 +# CHECK-NEXT:}, +# CHECK-NEXT:"start": { +# CHECK-NEXT: "character": 10, +# CHECK-NEXT: "line": 0 +# CHECK-NEXT:} +# CHECK-NEXT: }, +# CHECK-NEXT: "uri": "file://{{.*}}/main.cpp" +# CHECK-NEXT:} +# CHECK-NEXT: ] +--- +{"jsonrpc":"2.0","id":1,"method":"shutdown"} +--- +{"jsonrpc":"2.0","method":"exit"} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Implement LSP 3.17 positionEncoding (PR #142903)
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/142903 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Implement LSP 3.17 positionEncoding (PR #142903)
llvmbot wrote: @llvm/pr-subscribers-clang-tools-extra Author: someoneinjd (someoneinjd) Changes This PR adds support for the `positionEncoding` client capability introduced in LSP 3.17. Clangd can now negotiate the position encoding with the client during initialization. --- Full diff: https://github.com/llvm/llvm-project/pull/142903.diff 3 Files Affected: - (modified) clang-tools-extra/clangd/ClangdLSPServer.cpp (+3) - (modified) clang-tools-extra/clangd/Protocol.cpp (+6) - (added) clang-tools-extra/clangd/test/positionencoding.test (+32) ``diff diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp index 29321f7cd3fa2..e7b8cb5f6c79d 100644 --- a/clang-tools-extra/clangd/ClangdLSPServer.cpp +++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp @@ -686,6 +686,9 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params, ServerCaps["executeCommandProvider"] = llvm::json::Object{{"commands", Commands}}; + if (Opts.Encoding) +ServerCaps["positionEncoding"] = *Opts.Encoding; + llvm::json::Object Result{ {{"serverInfo", llvm::json::Object{ diff --git a/clang-tools-extra/clangd/Protocol.cpp b/clang-tools-extra/clangd/Protocol.cpp index c9e8a175b5d76..bf733af18ad3a 100644 --- a/clang-tools-extra/clangd/Protocol.cpp +++ b/clang-tools-extra/clangd/Protocol.cpp @@ -497,6 +497,12 @@ bool fromJSON(const llvm::json::Value &Params, ClientCapabilities &R, if (auto Cancel = StaleRequestSupport->getBoolean("cancel")) R.CancelsStaleRequests = *Cancel; } +if (auto *OffsetEncoding = General->get("positionEncodings")) { + R.offsetEncoding.emplace(); + if (!fromJSON(*OffsetEncoding, *R.offsetEncoding, +P.field("general").field("positionEncodings"))) +return false; +} } if (auto *OffsetEncoding = O->get("offsetEncoding")) { R.offsetEncoding.emplace(); diff --git a/clang-tools-extra/clangd/test/positionencoding.test b/clang-tools-extra/clangd/test/positionencoding.test new file mode 100644 index 0..eea7a1a596e9a --- /dev/null +++ b/clang-tools-extra/clangd/test/positionencoding.test @@ -0,0 +1,32 @@ +# RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s +# This test verifies that we can negotiate UTF-8 offsets via the positionEncodings capability introduced in LSP 3.17. +{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{"general":{"positionEncodings":["utf-8","utf-16"]}},"trace":"off"}} +# CHECK: "positionEncoding": "utf-8" +--- +{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///main.cpp","languageId":"cpp","version":1,"text":"/*ö*/int x;\nint y=x;"}}} +--- +{"jsonrpc":"2.0","id":1,"method":"textDocument/definition","params":{"textDocument":{"uri":"test:///main.cpp"},"position":{"line":1,"character":6}}} +# /*ö*/int x; +# 01234567890 +# x is character (and utf-16) range [9,10) but byte range [10,11). +# CHECK: "id": 1, +# CHECK-NEXT: "jsonrpc": "2.0", +# CHECK-NEXT: "result": [ +# CHECK-NEXT:{ +# CHECK-NEXT: "range": { +# CHECK-NEXT:"end": { +# CHECK-NEXT: "character": 11, +# CHECK-NEXT: "line": 0 +# CHECK-NEXT:}, +# CHECK-NEXT:"start": { +# CHECK-NEXT: "character": 10, +# CHECK-NEXT: "line": 0 +# CHECK-NEXT:} +# CHECK-NEXT: }, +# CHECK-NEXT: "uri": "file://{{.*}}/main.cpp" +# CHECK-NEXT:} +# CHECK-NEXT: ] +--- +{"jsonrpc":"2.0","id":1,"method":"shutdown"} +--- +{"jsonrpc":"2.0","method":"exit"} `` https://github.com/llvm/llvm-project/pull/142903 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Ensure clang-repl accepts all C keywords supported in all language models (PR #142749)
https://github.com/anutosh491 closed https://github.com/llvm/llvm-project/pull/142749 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] added option `google-readability-namespace-comments.AllowNoNamespaceComments` (PR #124265)
https://github.com/thorsten-klein updated https://github.com/llvm/llvm-project/pull/124265 >From b1bfe0682f9889ae792ada546d3e4f1cd86acf69 Mon Sep 17 00:00:00 2001 From: "Klein, Thorsten (GDE-EDSI1)" Date: Fri, 24 Jan 2025 13:46:24 +0100 Subject: [PATCH] added option AllowNoNamespaceComments for google-readability-namespace-comments new option AllowOmittingNamespaceComments for google-readability-namespace-comments is added. When true, the check will accept if no namespace comment is present. The check will only fail if a namespace comment is specified which is different than expeced. Defaults to `false`. --- .../readability/NamespaceCommentCheck.cpp | 12 ++- .../readability/NamespaceCommentCheck.h | 1 + .../checks/llvm/namespace-comment.rst | 8 ++ ...ility-namespace-comments-missing-c++17.cpp | 59 ...readability-namespace-comments-missing.cpp | 91 +++ 5 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-missing-c++17.cpp create mode 100644 clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-missing.cpp diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp index 64dc941569a96..12e52d6afad56 100644 --- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp @@ -27,11 +27,13 @@ NamespaceCommentCheck::NamespaceCommentCheck(StringRef Name, "namespace( +(((inline )|([a-zA-Z0-9_:]))+))?\\.? *(\\*/)?$", llvm::Regex::IgnoreCase), ShortNamespaceLines(Options.get("ShortNamespaceLines", 1U)), - SpacesBeforeComments(Options.get("SpacesBeforeComments", 1U)) {} + SpacesBeforeComments(Options.get("SpacesBeforeComments", 1U)), + AllowOmittingNamespaceComments(Options.get("AllowOmittingNamespaceComments", false)) {} void NamespaceCommentCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "ShortNamespaceLines", ShortNamespaceLines); Options.store(Opts, "SpacesBeforeComments", SpacesBeforeComments); + Options.store(Opts, "AllowOmittingNamespaceComments", AllowOmittingNamespaceComments); } void NamespaceCommentCheck::registerMatchers(MatchFinder *Finder) { @@ -140,6 +142,7 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { SourceRange OldCommentRange(AfterRBrace, AfterRBrace); std::string Message = "%0 not terminated with a closing comment"; + bool hasComment = false; // Try to find existing namespace closing comment on the same line. if (Tok.is(tok::comment) && NextTokenIsOnSameLine) { @@ -158,6 +161,8 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { return; } + hasComment = true; + // Otherwise we need to fix the comment. NeedLineBreak = Comment.starts_with("/*"); OldCommentRange = @@ -183,6 +188,11 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { ND->isAnonymousNamespace() ? "anonymous namespace" : ("namespace '" + *NamespaceNameAsWritten + "'"); + // If no namespace comment is allowed + if(!hasComment && AllowOmittingNamespaceComments) { +return; + } + std::string Fix(SpacesBeforeComments, ' '); Fix.append("// namespace"); if (!ND->isAnonymousNamespace()) diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h index 7607d37b1b2fd..8edd77213f779 100644 --- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h +++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h @@ -34,6 +34,7 @@ class NamespaceCommentCheck : public ClangTidyCheck { llvm::Regex NamespaceCommentPattern; const unsigned ShortNamespaceLines; const unsigned SpacesBeforeComments; + const bool AllowOmittingNamespaceComments; llvm::SmallVector Ends; }; diff --git a/clang-tools-extra/docs/clang-tidy/checks/llvm/namespace-comment.rst b/clang-tools-extra/docs/clang-tidy/checks/llvm/namespace-comment.rst index be90260be73af..3c2c20fb9731b 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/llvm/namespace-comment.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/llvm/namespace-comment.rst @@ -39,3 +39,11 @@ Options An unsigned integer specifying the number of spaces before the comment closing a namespace definition. Default is `1U`. + + +.. option:: AllowOmittingNamespaceComments + + When true, the check will accept if no namespace comment is present. + The check will only fail if a namespace comment is specified which is + different than expeced. Defaults to `false`. + diff --git a/clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-c
[clang] [llvm] Add -funique-source-file-identifier flag. (PR #142901)
MaskRay wrote: Should call this "option". Within LLVM, we use flag for options without a value. https://github.com/llvm/llvm-project/pull/142901 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 627e49e - [AST] Fix an unused-function warning (NFC)
Author: Jie Fu Date: 2025-06-05T14:11:30+08:00 New Revision: 627e49e2491ab7750501d84a5804632074c6af54 URL: https://github.com/llvm/llvm-project/commit/627e49e2491ab7750501d84a5804632074c6af54 DIFF: https://github.com/llvm/llvm-project/commit/627e49e2491ab7750501d84a5804632074c6af54.diff LOG: [AST] Fix an unused-function warning (NFC) /llvm-project/clang/lib/AST/ByteCode/InterpBuiltin.cpp:26:13: error: unused function 'isNoopBuiltin' [-Werror,-Wunused-function] static bool isNoopBuiltin(unsigned ID) { ^ 1 error generated. Added: Modified: clang/lib/AST/ByteCode/InterpBuiltin.cpp Removed: diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp index a7c368394bb6e..b678f229d50bb 100644 --- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp +++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp @@ -23,7 +23,7 @@ namespace clang { namespace interp { -static bool isNoopBuiltin(unsigned ID) { +LLVM_ATTRIBUTE_UNUSED static bool isNoopBuiltin(unsigned ID) { switch (ID) { case Builtin::BIas_const: case Builtin::BIforward: ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Add -funique-source-file-identifier flag. (PR #142901)
https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/142901 >From 74acb06bb339909bc2950cecb95eb61df49c0379 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Wed, 4 Jun 2025 22:37:09 -0700 Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?= =?UTF-8?q?itial=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.6-beta.1 --- clang/docs/UsersManual.rst | 17 - clang/include/clang/Basic/CodeGenOptions.def| 2 -- clang/include/clang/Basic/CodeGenOptions.h | 4 clang/include/clang/Driver/Options.td | 16 +--- clang/lib/CodeGen/CodeGenModule.cpp | 9 +++-- clang/lib/Driver/ToolChains/Clang.cpp | 10 -- clang/test/CodeGen/unique-source-file-names.c | 5 +++-- clang/test/Driver/unique-source-file-names.c| 12 +--- llvm/lib/Transforms/Utils/ModuleUtils.cpp | 10 ++ .../unique-source-file-names.ll | 3 ++- 10 files changed, 60 insertions(+), 28 deletions(-) diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst index 8c72f95b94095..62844f7e6a2fa 100644 --- a/clang/docs/UsersManual.rst +++ b/clang/docs/UsersManual.rst @@ -2300,12 +2300,14 @@ are listed below. .. option:: -f[no-]unique-source-file-names When enabled, allows the compiler to assume that each object file - passed to the linker has been compiled using a unique source file - path. This is useful for reducing link times when doing ThinLTO - in combination with whole-program devirtualization or CFI. + passed to the linker has a unique identifier. The identifier for + an object file is either the source file path or the value of the + argument `-funique-source-file-identifier` if specified. This is + useful for reducing link times when doing ThinLTO in combination with + whole-program devirtualization or CFI. - The full source path passed to the compiler must be unique. This - means that, for example, the following is a usage error: + The full source path or identifier passed to the compiler must be + unique. This means that, for example, the following is a usage error: .. code-block:: console @@ -2327,6 +2329,11 @@ are listed below. A misuse of this flag may result in a duplicate symbol error at link time. +.. option:: -funique-source-file-identifier=IDENTIFIER + + Used with `-funique-source-file-names` to specify a source file + identifier. + .. option:: -fforce-emit-vtables In order to improve devirtualization, forces emitting of vtables even in diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def index aad4e107cbeb3..fa9474d63ae42 100644 --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -278,8 +278,6 @@ CODEGENOPT(SanitizeCfiICallNormalizeIntegers, 1, 0) ///< Normalize integer types ///< CFI icall function signatures CODEGENOPT(SanitizeCfiCanonicalJumpTables, 1, 0) ///< Make jump table symbols canonical ///< instead of creating a local jump table. -CODEGENOPT(UniqueSourceFileNames, 1, 0) ///< Allow the compiler to assume that TUs -///< have unique source file names at link time CODEGENOPT(SanitizeKcfiArity, 1, 0) ///< Embed arity in KCFI patchable function prefix CODEGENOPT(SanitizeCoverageType, 2, 0) ///< Type of sanitizer coverage ///< instrumentation. diff --git a/clang/include/clang/Basic/CodeGenOptions.h b/clang/include/clang/Basic/CodeGenOptions.h index 278803f7bb960..f6a6a7fcfa6d7 100644 --- a/clang/include/clang/Basic/CodeGenOptions.h +++ b/clang/include/clang/Basic/CodeGenOptions.h @@ -338,6 +338,10 @@ class CodeGenOptions : public CodeGenOptionsBase { /// -fsymbol-partition (see https://lld.llvm.org/Partitions.html). std::string SymbolPartition; + /// If non-empty, allow the compiler to assume that the given source file + /// identifier is unique at link time. + std::string UniqueSourceFileIdentifier; + enum RemarkKind { RK_Missing,// Remark argument not present on the command line. RK_Enabled,// Remark enabled via '-Rgroup'. diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 5ca31c253ed8f..f04e214066ccb 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -4204,13 +4204,15 @@ def ftrigraphs : Flag<["-"], "ftrigraphs">, Group, def fno_trigraphs : Flag<["-"], "fno-trigraphs">, Group, HelpText<"Do not process trigraph sequences">, Visibility<[ClangOption, CC1Option]>; -defm unique_source_file_names: BoolOption<"f", "unique-source-file-names", - CodeGen
[clang] [CIR] Upstream splat op for VectorType (PR #139827)
xlauko wrote: Since https://github.com/llvm/llvm-project/pull/14/ was merged, please mirror additional changes from https://github.com/llvm/clangir/pull/1626 before merging. https://github.com/llvm/llvm-project/pull/139827 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Upstream TernaryOp for VectorType (PR #142393)
https://github.com/xlauko edited https://github.com/llvm/llvm-project/pull/142393 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Upstream TernaryOp for VectorType (PR #142393)
https://github.com/xlauko approved this pull request. lgtm https://github.com/llvm/llvm-project/pull/142393 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 7ca7bcb - [clang-repl] Ensure clang-repl accepts all C keywords supported in all language models (#142749)
Author: Anutosh Bhat Date: 2025-06-05T11:23:50+05:30 New Revision: 7ca7bcb7d8dcf26fc0281697fe47aa6cdb3884c0 URL: https://github.com/llvm/llvm-project/commit/7ca7bcb7d8dcf26fc0281697fe47aa6cdb3884c0 DIFF: https://github.com/llvm/llvm-project/commit/7ca7bcb7d8dcf26fc0281697fe47aa6cdb3884c0.diff LOG: [clang-repl] Ensure clang-repl accepts all C keywords supported in all language models (#142749) As can be seen through the docs (https://github.com/llvm/llvm-project/blob/7e1fa09ce2a228c949ce4490c98f2c73ed8ada00/clang/docs/LanguageExtensions.rst#c-keywords-supported-in-all-language-modes), Clang supports certain C keywords in all language modes — this patch ensures clang-repl handles them consistently. Here's an example testing all the above keywords. We have everything in place except `_Imaginary` (_Complex works but _Imaginary doesn't which was weird) and `_Noreturn` Added: Modified: clang/lib/Parse/ParseTentative.cpp clang/test/Interpreter/disambiguate-decl-stmt.cpp Removed: diff --git a/clang/lib/Parse/ParseTentative.cpp b/clang/lib/Parse/ParseTentative.cpp index 95cee824c40b7..f50bcd8ea90bb 100644 --- a/clang/lib/Parse/ParseTentative.cpp +++ b/clang/lib/Parse/ParseTentative.cpp @@ -1171,6 +1171,7 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext AllowImplicitTypename, case tok::kw_inline: case tok::kw_virtual: case tok::kw_explicit: + case tok::kw__Noreturn: // Modules case tok::kw___module_private__: @@ -1225,6 +1226,7 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext AllowImplicitTypename, // GNU case tok::kw_restrict: case tok::kw__Complex: + case tok::kw__Imaginary: case tok::kw___attribute: case tok::kw___auto_type: return TPResult::True; diff --git a/clang/test/Interpreter/disambiguate-decl-stmt.cpp b/clang/test/Interpreter/disambiguate-decl-stmt.cpp index 1f4d5e267288b..f2a59c510f9a2 100644 --- a/clang/test/Interpreter/disambiguate-decl-stmt.cpp +++ b/clang/test/Interpreter/disambiguate-decl-stmt.cpp @@ -102,3 +102,16 @@ __attribute((noreturn)) Attrs2::Attrs2() = default; // Extra semicolon namespace N {}; + +// Test C keywords supported in all language modes. +// https://clang.llvm.org/docs/LanguageExtensions.html#c-keywords-supported-in-all-language-modes + +_Alignas(16) int aligned_var; +int align = _Alignof(double); +_Atomic int atomic_var = 0; +_Complex double complex_val = 1.0 + 2.0i; +_Float16 f = 1.5; +_Thread_local int counter = 0; +_Static_assert(sizeof(int) == 4, "int must be 4 bytes"); +_Imaginary float i = 2.0f; // expected-error {{imaginary types are not supported}} +_Noreturn void noreturn_func() { while (true) {} } \ No newline at end of file ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Added TypeKind.FLOAT16 for 32 in cindex.py (PR #142634)
https://github.com/DeinAlptraum approved this pull request. Thanks for the PR, LGTM I'll merge this once you've checked the private email setting as described in the bot comment. CC @Endilll : Seems like we're missing a bunch of `TypeKind`s, currently missing 33 - 39 and 179 - 181 enum variants. 180 and 181 were only added the other day, we might want to look into some way to test these automatically to ensure that any additions are also added on Python side in the future. https://github.com/llvm/llvm-project/pull/142634 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [PowerPC] Support for Packed BCD conversion builtins (PR #142723)
Himadhith wrote: @lei137 @amy-kwan @tonykuttai https://github.com/llvm/llvm-project/pull/142723 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Fix crash on template-specialization (PR #142338)
@@ -160,7 +160,7 @@ template struct X; // Make sure that the instantiated constructor initializes start and // end properly. -// CHECK-LABEL: define linkonce_odr void @_ZN1XIiEC2ERKS0_(ptr {{[^,]*}} %this, ptr noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) %other) unnamed_addr +// CHECK-LABEL: define linkonce_odr void @_ZN1XIiEC2ERKS0_(ptr {{[^,]*}} %this, ptr noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) %0) unnamed_addr mark-de-wever-sonarsource wrote: It changes to the name used in the declaration. In this case the declaration in the class is `X(const X &);` and the argument has no name. In this case it uses `%0`. Would the declaration be `X(const X & x);` the name would change to `%x`. I noticed only one test fails due to the change and it does not look that the name of the argument is specifically part of the test. There seem to be no other tests that are affected. So I'm not sure whether this specific change in behaviour is wanted or important. I'd be happy to look into not changing it in this case. https://github.com/llvm/llvm-project/pull/142338 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PAuth] Use different discriminators for __int128_t / __uint128_t / _BitInt(n) (PR #140276)
@@ -4451,6 +4451,8 @@ defm ptrauth_init_fini_address_discrimination : OptInCC1FFlag<"ptrauth-init-fini "Enable address discrimination of function pointers in init/fini arrays">; defm ptrauth_elf_got : OptInCC1FFlag<"ptrauth-elf-got", "Enable authentication of pointers from GOT (ELF only)">; defm aarch64_jump_table_hardening: OptInCC1FFlag<"aarch64-jump-table-hardening", "Use hardened lowering for jump-table dispatch">; +defm ptrauth_disable_128bit_type_discrimination : OptInCC1FFlag<"ptrauth-disable-128bit-type-discrimination", + "Do not use different discriminators for __int128_t / __uint128_t / _BitInt(n) compared to other integer types when computing function pointer type discriminator">; ojhunt wrote: it remains irksome that we need to duplicate the description for an option in the table def and the macro (not an issue with your PR, just an old man shaking fists at clouds :D ) https://github.com/llvm/llvm-project/pull/140276 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PAuth] Use different discriminators for __int128_t / __uint128_t / _BitInt(n) (PR #140276)
https://github.com/ojhunt commented: This basically looks good to me, sans the "can this just be on by default for elf/linux/etc" question https://github.com/llvm/llvm-project/pull/140276 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PAuth] Use different discriminators for __int128_t / __uint128_t / _BitInt(n) (PR #140276)
@@ -1883,6 +1883,9 @@ void Clang::AddAArch64TargetArgs(const ArgList &Args, Args.addOptInFlag( CmdArgs, options::OPT_fptrauth_function_pointer_type_discrimination, options::OPT_fno_ptrauth_function_pointer_type_discrimination); + Args.addOptInFlag( ojhunt wrote: there's apple kernel flags in this function, but it looks like darwin args are actually set up in `Toolchains/Darwin.cpp` - can the apple invocation paths hit this? if not I think it's worth just having this as an opt out rather than an opt in. We might be constrained by ABI, but I don't think you have any reason to restrict this. My request for a cli/langopt was so that we can stick with our existing ABI if need be, not because I thought you couldn't do this :D https://github.com/llvm/llvm-project/pull/140276 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][PAC] Add __builtin_get_vtable_pointer (PR #139790)
https://github.com/ojhunt closed https://github.com/llvm/llvm-project/pull/139790 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CodeGen] Add TBAA struct path info for array members (PR #137719)
brunodf-snps wrote: Could someone with commit access please merge this? Thanks! https://github.com/llvm/llvm-project/pull/137719 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-reorder-fields] Use expanded location for macros (PR #142147)
https://github.com/legrosbuffle approved this pull request. https://github.com/llvm/llvm-project/pull/142147 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PAuth] Use different discriminators for __int128_t / __uint128_t / _BitInt(n) (PR #140276)
https://github.com/ojhunt edited https://github.com/llvm/llvm-project/pull/140276 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Added TypeKind.FLOAT16 for 32 in cindex.py (PR #142634)
Endilll wrote: > Seems like we're missing a bunch of `TypeKind`s, currently missing 33 - 39 > and 179 - 181 enum variants. 180 and 181 were only added the other day, we > might want to look into some way to test these automatically to ensure that > any additions are also added on Python side in the future. Time to put libclang to use, and parse `cindex.h`? https://github.com/llvm/llvm-project/pull/142634 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Add check 'cppcoreguidelines-use-enum-class' (PR #138282)
https://github.com/vbvictor edited https://github.com/llvm/llvm-project/pull/138282 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Add check 'cppcoreguidelines-use-enum-class' (PR #138282)
@@ -0,0 +1,40 @@ +//===--- UseEnumClassCheck.h - clang-tidy ---*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_USEENUMCLASSCHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_USEENUMCLASSCHECK_H + +#include "../ClangTidyCheck.h" + +namespace clang::tidy::cppcoreguidelines { + +/// Check for unscoped enums and suggest to use scoped enums (enum class). +/// Optionally, ignore unscoped enums in classes via IgnoreUnscopedEnumsInClasses vbvictor wrote: This is not needed, only the sentence in ReleaseNotes should be placed here https://github.com/llvm/llvm-project/pull/138282 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Add check 'cppcoreguidelines-use-enum-class' (PR #138282)
https://github.com/vbvictor approved this pull request. LGTM, few nits with docs. Ping, @HerrCai0907, @carlosgalvezp, @PiotrZSL if you wish to leave a review. I suppose in 1-2 weeks I'll land the PR. https://github.com/llvm/llvm-project/pull/138282 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Added TypeKind.FLOAT16 for 32 in cindex.py (PR #142634)
DeinAlptraum wrote: > Time to put libclang to use, and parse cindex.h? Probably, though I'll check if there are any more direct options first. I don't quite like the idea of hardcoding source file paths in the tests of a binding. https://github.com/llvm/llvm-project/pull/142634 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] b36e161 - [clang][bytecode][NFC] Cache more integer type sizes (#142720)
Author: Timm Baeder Date: 2025-06-04T10:07:48+02:00 New Revision: b36e161a09bdebbabe159598778abb011303a9eb URL: https://github.com/llvm/llvm-project/commit/b36e161a09bdebbabe159598778abb011303a9eb DIFF: https://github.com/llvm/llvm-project/commit/b36e161a09bdebbabe159598778abb011303a9eb.diff LOG: [clang][bytecode][NFC] Cache more integer type sizes (#142720) Added: Modified: clang/lib/AST/ByteCode/Context.cpp clang/lib/AST/ByteCode/Context.h Removed: diff --git a/clang/lib/AST/ByteCode/Context.cpp b/clang/lib/AST/ByteCode/Context.cpp index 6b8f4e31e4ff9..d73705b6126fe 100644 --- a/clang/lib/AST/ByteCode/Context.cpp +++ b/clang/lib/AST/ByteCode/Context.cpp @@ -22,8 +22,10 @@ using namespace clang; using namespace clang::interp; Context::Context(ASTContext &Ctx) : Ctx(Ctx), P(new Program(*this)) { + this->ShortWidth = Ctx.getTargetInfo().getShortWidth(); this->IntWidth = Ctx.getTargetInfo().getIntWidth(); this->LongWidth = Ctx.getTargetInfo().getLongWidth(); + this->LongLongWidth = Ctx.getTargetInfo().getLongLongWidth(); assert(Ctx.getTargetInfo().getCharWidth() == 8 && "We're assuming 8 bit chars"); } @@ -265,6 +267,11 @@ std::optional Context::classify(QualType T) const { return PT_MemberPtr; // Just trying to avoid the ASTContext::getIntWidth call below. +if (Kind == BuiltinType::Short) + return integralTypeToPrimTypeS(this->ShortWidth); +if (Kind == BuiltinType::UShort) + return integralTypeToPrimTypeU(this->ShortWidth); + if (Kind == BuiltinType::Int) return integralTypeToPrimTypeS(this->IntWidth); if (Kind == BuiltinType::UInt) @@ -273,6 +280,11 @@ std::optional Context::classify(QualType T) const { return integralTypeToPrimTypeS(this->LongWidth); if (Kind == BuiltinType::ULong) return integralTypeToPrimTypeU(this->LongWidth); +if (Kind == BuiltinType::LongLong) + return integralTypeToPrimTypeS(this->LongLongWidth); +if (Kind == BuiltinType::ULongLong) + return integralTypeToPrimTypeU(this->LongLongWidth); + if (Kind == BuiltinType::SChar || Kind == BuiltinType::Char_S) return integralTypeToPrimTypeS(8); if (Kind == BuiltinType::UChar || Kind == BuiltinType::Char_U || diff --git a/clang/lib/AST/ByteCode/Context.h b/clang/lib/AST/ByteCode/Context.h index 9a604ce8ebbe9..5898ab5e54599 100644 --- a/clang/lib/AST/ByteCode/Context.h +++ b/clang/lib/AST/ByteCode/Context.h @@ -138,8 +138,10 @@ class Context final { /// ID identifying an evaluation. unsigned EvalID = 0; /// Cached widths (in bits) of common types, for a faster classify(). + unsigned ShortWidth; unsigned IntWidth; unsigned LongWidth; + unsigned LongLongWidth; }; } // namespace interp ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libclang/python] Derive library function types from annotations (PR #142120)
https://github.com/DeinAlptraum updated https://github.com/llvm/llvm-project/pull/142120 >From 4669be22f731faf9ce0985aa634166c30c7025c6 Mon Sep 17 00:00:00 2001 From: Jannick Kremer Date: Fri, 30 May 2025 19:54:15 +0900 Subject: [PATCH] [libclang/python] Derive library function types from annotations THis is a PoC for now --- clang/bindings/python/clang/cindex.py | 833 ++ 1 file changed, 583 insertions(+), 250 deletions(-) diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py index 6f7243cdf80ac..889df2e2f0a87 100644 --- a/clang/bindings/python/clang/cindex.py +++ b/clang/bindings/python/clang/cindex.py @@ -78,6 +78,7 @@ c_void_p, cast, cdll, +_Pointer, py_object, ) @@ -93,6 +94,7 @@ Iterator, Literal, Optional, +Protocol, Sequence, Type as TType, TypeVar, @@ -101,8 +103,7 @@ ) if TYPE_CHECKING: -from ctypes import _Pointer -from typing_extensions import Protocol, TypeAlias +from typing_extensions import TypeAlias StrPath: TypeAlias = TUnion[str, os.PathLike[str]] LibFunc: TypeAlias = TUnion[ @@ -3986,256 +3987,588 @@ def set_property(self, property, value): # Now comes the plumbing to hook up the C library. # Register callback types -translation_unit_includes_callback = CFUNCTYPE( +translation_unit_includes_callback: TypeAlias = CFUNCTYPE( # type: ignore [valid-type] None, c_object_p, POINTER(SourceLocation), c_uint, py_object ) -cursor_visit_callback = CFUNCTYPE(c_int, Cursor, Cursor, py_object) -fields_visit_callback = CFUNCTYPE(c_int, Cursor, py_object) +cursor_visit_callback: TypeAlias = CFUNCTYPE(c_int, Cursor, Cursor, py_object) # type: ignore [valid-type] +fields_visit_callback: TypeAlias = CFUNCTYPE(c_int, Cursor, py_object) # type: ignore [valid-type] + + +def _get_annotations() -> list[LibFunc]: +def str_to_type(typename: str) -> type: +# The _Pointer types are instantiated dynamically at runtime +# so convert manually accordingly +if typename.startswith("_Pointer[") and typename.endswith("]"): +inner_type = typename[9:-1] +inner_mapped_type = str_to_type(inner_type) +return POINTER(inner_mapped_type) +return globals_flat[typename] + +# Get all globally available names and flatten the builtins onto the +# top level of the dict. In the case of duplicates the builtin is +# overwritten with the non-builtin +gl = globals() +builtins = gl.pop("__builtins__") +globals_flat: dict[str, type] = {**builtins, **gl} + +func_names = {attr for attr in vars(ClangLib) if attr.startswith("clang_")} +annotation_types: list[LibFunc] = [] +for func_name in func_names: +annotation = getattr(ClangLib, func_name).__annotations__ +ret_type = str_to_type(annotation.pop("return")) +arg_types = [str_to_type(annotation[key]) for key in annotation.keys()] +annotation_types.append((func_name, arg_types, ret_type)) +return annotation_types + # Functions strictly alphabetical order. -FUNCTION_LIST: list[LibFunc] = [ -( -"clang_annotateTokens", -[TranslationUnit, POINTER(Token), c_uint, POINTER(Cursor)], -), -("clang_CompilationDatabase_dispose", [c_object_p]), -( -"clang_CompilationDatabase_fromDirectory", -[c_interop_string, POINTER(c_uint)], -c_object_p, -), -("clang_CompilationDatabase_getAllCompileCommands", [c_object_p], c_object_p), -( -"clang_CompilationDatabase_getCompileCommands", -[c_object_p, c_interop_string], -c_object_p, -), -("clang_CompileCommands_dispose", [c_object_p]), -("clang_CompileCommands_getCommand", [c_object_p, c_uint], c_object_p), -("clang_CompileCommands_getSize", [c_object_p], c_uint), -("clang_CompileCommand_getArg", [c_object_p, c_uint], _CXString), -("clang_CompileCommand_getDirectory", [c_object_p], _CXString), -("clang_CompileCommand_getFilename", [c_object_p], _CXString), -("clang_CompileCommand_getNumArgs", [c_object_p], c_uint), -( -"clang_codeCompleteAt", -[TranslationUnit, c_interop_string, c_int, c_int, c_void_p, c_int, c_int], -POINTER(CCRStructure), -), -("clang_codeCompleteGetDiagnostic", [CodeCompletionResults, c_int], Diagnostic), -("clang_codeCompleteGetNumDiagnostics", [CodeCompletionResults], c_int), -("clang_createIndex", [c_int, c_int], c_object_p), -("clang_createTranslationUnit", [Index, c_interop_string], c_object_p), -("clang_CXRewriter_create", [TranslationUnit], c_object_p), -("clang_CXRewriter_dispose", [Rewriter]), -("clang_CXRewriter_insertTextBefore", [Rewriter, SourceLocation, c_interop_string]), -("clang_CXRewriter_overwriteChangedFiles", [Rewriter], c_int), -("clang_CXRewriter_removeText", [Rewriter, SourceRange]), -("clang_CXRewriter_replaceText", [
[clang-tools-extra] Add check 'cppcoreguidelines-use-enum-class' (PR #138282)
@@ -0,0 +1,40 @@ +//===--- UseEnumClassCheck.h - clang-tidy ---*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_USEENUMCLASSCHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_USEENUMCLASSCHECK_H + +#include "../ClangTidyCheck.h" + +namespace clang::tidy::cppcoreguidelines { + +/// Check for unscoped enums and suggest to use scoped enums (enum class). vbvictor wrote: Please sync this with sentences in docs and ReleaseNotes https://github.com/llvm/llvm-project/pull/138282 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 93314bd - [clang][PAC] Add __builtin_get_vtable_pointer (#139790)
Author: Oliver Hunt Date: 2025-06-04T00:21:20-07:00 New Revision: 93314bd9462d5c41a23fb402be7ae0c7d099e274 URL: https://github.com/llvm/llvm-project/commit/93314bd9462d5c41a23fb402be7ae0c7d099e274 DIFF: https://github.com/llvm/llvm-project/commit/93314bd9462d5c41a23fb402be7ae0c7d099e274.diff LOG: [clang][PAC] Add __builtin_get_vtable_pointer (#139790) With pointer authentication it becomes non-trivial to correctly load the vtable pointer of a polymorphic object. __builtin_get_vtable_pointer is a function that performs the load and performs the appropriate authentication operations if necessary. Added: clang/test/CodeGenCXX/builtin-get-vtable-pointer.cpp clang/test/SemaCXX/builtin-get-vtable-pointer.cpp Modified: clang/docs/LanguageExtensions.rst clang/docs/ReleaseNotes.rst clang/include/clang/Basic/Builtins.td clang/include/clang/Basic/DiagnosticSemaKinds.td clang/lib/CodeGen/CGBuiltin.cpp clang/lib/Sema/SemaChecking.cpp Removed: diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index e1929740356e7..73544826809c3 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -3074,6 +3074,41 @@ following way: Query for this feature with ``__has_builtin(__builtin_offsetof)``. +``__builtin_get_vtable_pointer`` + + +``__builtin_get_vtable_pointer`` loads and authenticates the primary vtable +pointer from an instance of a polymorphic C++ class. This builtin is needed +for directly loading the vtable pointer when on platforms using +:doc:`PointerAuthentication`. + +**Syntax**: + +.. code-block:: c++ + + __builtin_get_vtable_pointer(PolymorphicClass*) + +**Example of Use**: + +.. code-block:: c++ + + struct PolymorphicClass { +virtual ~PolymorphicClass(); + }; + + PolymorphicClass anInstance; + const void* vtablePointer = __builtin_get_vtable_pointer(&anInstance); + +**Description**: + +The ``__builtin_get_vtable_pointer`` builtin loads the primary vtable +pointer from a polymorphic C++ type. If the target platform authenticates +vtable pointers, this builtin will perform the authentication and produce +the underlying raw pointer. The object being queried must be polymorphic, +and so must also be a complete type. + +Query for this feature with ``__has_builtin(__builtin_get_vtable_pointer)``. + ``__builtin_call_with_static_chain`` diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index d6b994d36df8a..512071427b65c 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -317,6 +317,8 @@ Non-comprehensive list of changes in this release ``sizeof`` or ``typeof`` expression. (#GH138444) - Deprecation warning is emitted for the deprecated ``__reference_binds_to_temporary`` intrinsic. ``__reference_constructs_from_temporary`` should be used instead. (#GH44056) +- Added `__builtin_get_vtable_pointer` to directly load the primary vtable pointer from a + polymorphic object. New Compiler Flags -- diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index e43b87fb3c131..b15cde05410ab 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -970,6 +970,12 @@ def IsWithinLifetime : LangBuiltin<"CXX_LANG"> { let Prototype = "bool(void*)"; } +def GetVtablePointer : LangBuiltin<"CXX_LANG"> { + let Spellings = ["__builtin_get_vtable_pointer"]; + let Attributes = [CustomTypeChecking, NoThrow, Const]; + let Prototype = "void*(void*)"; +} + // GCC exception builtins def EHReturn : Builtin { let Spellings = ["__builtin_eh_return"]; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 6f1e8d9fc74e6..c8c45438f969e 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -12803,6 +12803,14 @@ def err_bit_cast_non_trivially_copyable : Error< def err_bit_cast_type_size_mismatch : Error< "size of '__builtin_bit_cast' source type %0 does not match destination type %1 (%2 vs %3 bytes)">; +def err_get_vtable_pointer_incorrect_type +: Error<"__builtin_get_vtable_pointer requires an argument of%select{| " +"polymorphic}0 class pointer type" +", but %1 %select{was provided|has no virtual methods}0">; +def err_get_vtable_pointer_requires_complete_type +: Error<"__builtin_get_vtable_pointer requires an argument with a complete " +"type, but %0 is incomplete">; + // SYCL-specific diagnostics def warn_sycl_kernel_num_of_template_params : Warning< "'sycl_kernel' attribute only applies to a function template with at least" diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 369cff35b1bbf
[clang] [clang][bytecode][NFC] Cache more integer type sizes (PR #142720)
https://github.com/tbaederr closed https://github.com/llvm/llvm-project/pull/142720 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Ensure clang-repl accepts all C keywords supported in all language models (PR #142749)
https://github.com/anutosh491 created https://github.com/llvm/llvm-project/pull/142749 As can be seen through the docs (https://github.com/llvm/llvm-project/blob/7e1fa09ce2a228c949ce4490c98f2c73ed8ada00/clang/docs/LanguageExtensions.rst#c-keywords-supported-in-all-language-modes), Clang supports certain C keywords in all language modes — this patch ensures clang-repl handles them consistently. Here's an example testing all the above keywords. We have everything in place except `_Imaginary` (_Complex works but _Imaginary doesn't which was weird) and `_Noreturn` >From be0d72e8dab1ef90771e5929dcd5064e5980f877 Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Wed, 4 Jun 2025 14:34:05 +0530 Subject: [PATCH] Ensure clang-repl accepts all C keywords supported in all Clang language modes --- clang/lib/Parse/ParseTentative.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clang/lib/Parse/ParseTentative.cpp b/clang/lib/Parse/ParseTentative.cpp index 95cee824c40b7..f50bcd8ea90bb 100644 --- a/clang/lib/Parse/ParseTentative.cpp +++ b/clang/lib/Parse/ParseTentative.cpp @@ -1171,6 +1171,7 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext AllowImplicitTypename, case tok::kw_inline: case tok::kw_virtual: case tok::kw_explicit: + case tok::kw__Noreturn: // Modules case tok::kw___module_private__: @@ -1225,6 +1226,7 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext AllowImplicitTypename, // GNU case tok::kw_restrict: case tok::kw__Complex: + case tok::kw__Imaginary: case tok::kw___attribute: case tok::kw___auto_type: return TPResult::True; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][performance-unnecessary-value-param] Avoid in coroutines (PR #140912)
vbvictor wrote: I have a mixed feeling about whether we should always exclude all coroutines by default or not. When a coroutine has only one `co-operator` and nothing else should be safe to use a reference parameter? Am I wrong? So I think to be "on a safe side" I'd suggest a new option "IngoreCoroutines" that will be `true` by default. If A user 100% knows that all references will outlive the coroutine he could set it to `false` and check performance issues:). In the option description, we could describe why it is not good to disable it. Generally speaking, maybe It's not _very_ good to implement _recommendations_ of cppcore-guidlines as a must in non-cppcore checks. I'd be happy to land your changes with this option, without - I'd want a second opinion from a maintainer. https://github.com/llvm/llvm-project/pull/140912 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add new check `readability-use-numeric-limits` (PR #127430)
vbvictor wrote: @stellar-aria, 21th LLVM release will be soon and the PR is 95% ready to land even if some corner-cases are not matched. Do you wish to rebase on fresh main and after a quick re-review the check should be ready to land. https://github.com/llvm/llvm-project/pull/127430 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Ensure clang-repl accepts all C keywords supported in all language models (PR #142749)
anutosh491 wrote: On **Main** ``` anutosh491@vv-nuc:/build/anutosh491/llvm-project/build/bin$ ./clang-repl clang-repl> _Alignas(16) int x; clang-repl> int align = _Alignof(double); clang-repl> _Atomic int atomic_var = 0; clang-repl> _Complex double complex_val = 1.0 + 2.0i; clang-repl> _Float16 f = 1.5; clang-repl> _Thread_local int counter = 0; clang-repl> _Static_assert(sizeof(int) == 4, "int must be 4 bytes"); clang-repl> _Imaginary float i = 2.0f; In file included from <<< inputs >>>:1: input_line_8:1:1: error: expected expression 1 | _Imaginary float i = 2.0f; | ^ error: Parsing failed. clang-repl> _Noreturn void die() {while (true) {}} input_line_9:1:1: error: expected expression 1 | _Noreturn void die() {while (true) {}} | ^ error: Parsing failed. ``` On **Branch** after the change ``` anutosh491@vv-nuc:/build/anutosh491/llvm-project/build/bin$ ./clang-repl clang-repl> _Alignas(16) int x; clang-repl> int align = _Alignof(double); clang-repl> _Atomic int atomic_var = 0; clang-repl> _Complex double complex_val = 1.0 + 2.0i; clang-repl> _Float16 f = 1.5; clang-repl> _Thread_local int counter = 0; clang-repl> _Static_assert(sizeof(int) == 4, "int must be 4 bytes"); clang-repl> _Imaginary float i = 2.0f; In file included from <<< inputs >>>:1: input_line_8:1:1: error: imaginary types are not supported 1 | _Imaginary float i = 2.0f; | ^ error: Parsing failed. clang-repl> _Noreturn void die() {while (true) {}} ``` This now works how clang would expect it to. For eg ``` (xeus-cpp) anutosh491@Anutoshs-MacBook-Air xeus-cpp % cat test-file.cpp _Imaginary float i = 2.0f;% (xeus-cpp) anutosh491@Anutoshs-MacBook-Air xeus-cpp % clang++ -std=c++20 test-file.cpp -o test_program test-file.cpp:1:1: error: imaginary types are not supported _Imaginary float i = 2.0f; ^ 1 error generated. ``` And anything with _Noreturn would just compile fine. https://github.com/llvm/llvm-project/pull/142749 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Ensure clang-repl accepts all C keywords supported in all language models (PR #142749)
anutosh491 wrote: The error comes from here to be precise https://github.com/llvm/llvm-project/blob/41841e625db8d14d6701e7cb211b2fcab6a32a50/clang/lib/Parse/Parser.cpp#L1026-L1028 `IsDeclarationStatement` should be true but return false enabling a faulty call to `ParseTopLevelStmtDecl` https://github.com/llvm/llvm-project/pull/142749 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL][SPIR-V] Implement vk::ext_builtin_input attribute (PR #138530)
https://github.com/Keenuts updated https://github.com/llvm/llvm-project/pull/138530 From 8c405fefdb31200930b9a690df635aff7775f602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nathan=20Gau=C3=ABr?= Date: Wed, 30 Apr 2025 11:06:55 +0200 Subject: [PATCH 1/8] [HLSL] Implement vk::ext_builtin_input attribute This variable attribute is used in HLSL to add Vulkan specific builtins in a shader. The attribute is documented here: https://github.com/microsoft/hlsl-specs/blob/17727e88fd1cb09013cb3a144110826af05f4dd5/proposals/0011-inline-spirv.md Those variable, even if marked as `static` are externally initialized by the pipeline/driver/GPU. This is handled by moving them to a specific address space `hlsl_input`, also added by this commit. The design for input variables in Clang can be found here: https://github.com/llvm/wg-hlsl/blob/355771361ef69259fef39a65caef8bff9cb4046d/proposals/0019-spirv-input-builtin.md Related to #136920 --- clang/include/clang/Basic/AddressSpaces.h | 1 + clang/include/clang/Basic/Attr.td | 13 +++ clang/include/clang/Basic/AttrDocs.td | 22 +++ .../include/clang/Basic/AttributeCommonInfo.h | 2 +- clang/include/clang/Sema/SemaHLSL.h | 2 ++ clang/lib/AST/Type.cpp| 1 + clang/lib/AST/TypePrinter.cpp | 2 ++ clang/lib/Basic/Attributes.cpp| 1 + clang/lib/Basic/TargetInfo.cpp| 2 ++ clang/lib/Basic/Targets/AArch64.h | 1 + clang/lib/Basic/Targets/AMDGPU.cpp| 2 ++ clang/lib/Basic/Targets/DirectX.h | 1 + clang/lib/Basic/Targets/NVPTX.h | 1 + clang/lib/Basic/Targets/SPIR.h| 2 ++ clang/lib/Basic/Targets/SystemZ.h | 1 + clang/lib/Basic/Targets/TCE.h | 1 + clang/lib/Basic/Targets/WebAssembly.h | 1 + clang/lib/Basic/Targets/X86.h | 1 + clang/lib/CodeGen/CGHLSLRuntime.cpp | 11 ++ clang/lib/CodeGen/CGHLSLRuntime.h | 1 + clang/lib/CodeGen/CodeGenModule.cpp | 17 ++ clang/lib/Sema/SemaDecl.cpp | 6 + clang/lib/Sema/SemaDeclAttr.cpp | 3 +++ clang/lib/Sema/SemaHLSL.cpp | 14 clang/test/CodeGenHLSL/vk-input-builtin.hlsl | 14 .../SemaTemplate/address_space-dependent.cpp | 4 ++-- 26 files changed, 124 insertions(+), 3 deletions(-) create mode 100644 clang/test/CodeGenHLSL/vk-input-builtin.hlsl diff --git a/clang/include/clang/Basic/AddressSpaces.h b/clang/include/clang/Basic/AddressSpaces.h index 519d959bb636c..48e4a1c61fe02 100644 --- a/clang/include/clang/Basic/AddressSpaces.h +++ b/clang/include/clang/Basic/AddressSpaces.h @@ -61,6 +61,7 @@ enum class LangAS : unsigned { hlsl_constant, hlsl_private, hlsl_device, + hlsl_input, // Wasm specific address spaces. wasm_funcref, diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 216084344c00d..917e6eec08e0f 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -140,6 +140,11 @@ def SharedVar : SubsetSubjecthasGlobalStorage() && !S->getTLSKind()}], "global variables">; +def HLSLInputBuiltin : SubsetSubjecthasGlobalStorage() && +S->getStorageClass()==StorageClass::SC_Static && +S->getType().isConstQualified()}], + "input builtin">; + def GlobalVar : SubsetSubjecthasGlobalStorage()}], "global variables">; @@ -4951,6 +4956,14 @@ def HLSLWaveSize: InheritableAttr { let Documentation = [WaveSizeDocs]; } +def HLSLVkExtBuiltinInput : InheritableAttr { + let Spellings = [CXX11<"vk", "ext_builtin_input">]; + let Args = [IntArgument<"BuiltIn">]; + let Subjects = SubjectList<[HLSLInputBuiltin], ErrorDiag>; + let LangOpts = [HLSL]; + let Documentation = [HLSLVkExtBuiltinInputDocs]; +} + def RandomizeLayout : InheritableAttr { let Spellings = [GCC<"randomize_layout">]; let Subjects = SubjectList<[Record]>; diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index 65d66dd398ad1..1f8d8755e245c 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -8508,6 +8508,28 @@ and copied back to the argument after the callee returns. }]; } +def HLSLVkExtBuiltinInputDocs : Documentation { + let Category = DocCatVariable; + let Content = [{ +Vulkan shaders have `Input` builtins. Those variables are externally +initialized by the driver/pipeline, but each copy is private to the current +lane. + +Those builtins can be declared using the `[[vk::ext_builtin_input]]` attribute +like follows: + +.. code-block:: c++ + [[vk::ext_builtin_input(/* WorkgroupId */ 26)]] + static const uint3 groupid; + +This variable will be lowered into a module-level variable, with the `Input
[clang] [llvm] [HLSL][SPIR-V] Implement vk::ext_builtin_input attribute (PR #138530)
@@ -140,6 +140,11 @@ def SharedVar : SubsetSubjecthasGlobalStorage() && !S->getTLSKind()}], "global variables">; +def HLSLInputBuiltin : SubsetSubjecthasGlobalStorage() && +S->getStorageClass()==StorageClass::SC_Static && +S->getType().isConstQualified()}], + "static const globals">; Keenuts wrote: Ah didn't checked, I always run `git-clang-format` and call it a day! Thanks, applied the suggestion https://github.com/llvm/llvm-project/pull/138530 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-repl] Ensure clang-repl accepts all C keywords supported in all language models (PR #142749)
anutosh491 wrote: Should help us in the long run and fix the errors we see while including input/output based header on xeus-cpp-lite (happens cause these internally reference `_Noreturn` that clang-repl currently fails to understand)  https://github.com/llvm/llvm-project/pull/142749 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add ClangQueryChecks config option (PR #123734)
vbvictor wrote: @DeNiCoN, do you mind if this PR would be closed (or converted to draft at least)? I'm in the process of reviewing old PR to lower the number of open ones for ease of tracking. This PR could be reopened if needed. https://github.com/llvm/llvm-project/pull/123734 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] added option `google-readability-namespace-comments.AllowNoNamespaceComments` (PR #124265)
vbvictor wrote: @thorsten-klein, gentle ping, do you still wish to work on this check? 21th LLVM release will be soon, If you wish to have your changes in the upcoming release please rebase on main and fix issues suggested by HerrCai0907. https://github.com/llvm/llvm-project/pull/124265 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 4d6e44d - [CIR] Fix missing return value warning in maybePromoteBoolResult (#142673)
Author: Morris Hafner Date: 2025-06-04T11:52:47+02:00 New Revision: 4d6e44db8726d32e0edd47f41baf157986412858 URL: https://github.com/llvm/llvm-project/commit/4d6e44db8726d32e0edd47f41baf157986412858 DIFF: https://github.com/llvm/llvm-project/commit/4d6e44db8726d32e0edd47f41baf157986412858.diff LOG: [CIR] Fix missing return value warning in maybePromoteBoolResult (#142673) This is NFC and simply adds an llvm_unreachable Added: Modified: clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp Removed: diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp index 77287ec45972d..0d9252a55d280 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp @@ -104,6 +104,7 @@ class ScalarExprEmitter : public StmtVisitor { return builder.createBoolToInt(value, dstTy); if (mlir::isa(dstTy)) return value; +llvm_unreachable("Can only promote integer or boolean types"); } //======// ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Fix missing return value warning in maybePromoteBoolResult (PR #142673)
https://github.com/mmha closed https://github.com/llvm/llvm-project/pull/142673 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AArch64][Clang] Update new Neon vector element types. (PR #142760)
https://github.com/davemgreen created https://github.com/llvm/llvm-project/pull/142760 This updates the element types used in the new __Int8x8_t types added in #126945, mostly to allow C++ name mangling in ItaniumMangling mangleAArch64VectorBase to work correctly. Char is replaced by SignedCharTy or UnsignedCharTy as required and Float16Ty is better using HalfTy to match the vector types. Same for Long types. >From e4e2a99d69c9aee2413cbaac59138dacf4660d84 Mon Sep 17 00:00:00 2001 From: David Green Date: Wed, 4 Jun 2025 10:39:12 +0100 Subject: [PATCH] [AArch64][Clang] Update new Neon vector element types. This updates the element types used in the new __Int8x8_t types added in #126945, mostly to allow C++ name mangling in ItaniumMangling mangleAArch64VectorBase to work correctly. Char is replaced by SignedCharTy or UnsignedCharTy as required and Float16Ty is better using HalfTy to match the vector types. Same for Long types. --- .../include/clang/Basic/AArch64ACLETypes.def | 22 +- clang/test/AST/ast-dump-aarch64-neon-types.c | 22 +- clang/test/CodeGen/AArch64/mixed-neon-types.c | 559 -- 3 files changed, 538 insertions(+), 65 deletions(-) diff --git a/clang/include/clang/Basic/AArch64ACLETypes.def b/clang/include/clang/Basic/AArch64ACLETypes.def index 9acfd693288cf..bbe0c85f9ffbe 100644 --- a/clang/include/clang/Basic/AArch64ACLETypes.def +++ b/clang/include/clang/Basic/AArch64ACLETypes.def @@ -123,31 +123,31 @@ //===- Neon Vector point types ===// -NEON_VECTOR_TYPE(__Int8x8_t, CharTy, 8, 8, VectorKind::Neon) +NEON_VECTOR_TYPE(__Int8x8_t, SignedCharTy, 8, 8, VectorKind::Neon) NEON_VECTOR_TYPE(__Int16x4_t, ShortTy, 16, 4, VectorKind::Neon) NEON_VECTOR_TYPE(__Int32x2_t, IntTy, 32, 2, VectorKind::Neon) -NEON_VECTOR_TYPE(__Uint8x8_t, CharTy, 8, 8, VectorKind::Neon) +NEON_VECTOR_TYPE(__Uint8x8_t, UnsignedCharTy, 8, 8, VectorKind::Neon) NEON_VECTOR_TYPE(__Uint16x4_t, UnsignedShortTy, 16, 4, VectorKind::Neon) NEON_VECTOR_TYPE(__Uint32x2_t, UnsignedIntTy, 32, 2, VectorKind::Neon) -NEON_VECTOR_TYPE(__Float16x4_t, Float16Ty, 16, 4, VectorKind::Neon) +NEON_VECTOR_TYPE(__Float16x4_t, HalfTy, 16, 4, VectorKind::Neon) NEON_VECTOR_TYPE(__Float32x2_t, FloatTy, 32, 2, VectorKind::Neon) -NEON_VECTOR_TYPE(__Poly8x8_t, CharTy, 8, 8, VectorKind::NeonPoly) +NEON_VECTOR_TYPE(__Poly8x8_t, UnsignedCharTy, 8, 8, VectorKind::NeonPoly) NEON_VECTOR_TYPE(__Poly16x4_t, UnsignedShortTy, 16, 4, VectorKind::NeonPoly) NEON_VECTOR_TYPE(__Bfloat16x4_t, BFloat16Ty, 16, 4, VectorKind::Neon) -NEON_VECTOR_TYPE(__Int8x16_t, CharTy, 8, 16, VectorKind::Neon) +NEON_VECTOR_TYPE(__Int8x16_t, SignedCharTy, 8, 16, VectorKind::Neon) NEON_VECTOR_TYPE(__Int16x8_t, ShortTy, 16, 8, VectorKind::Neon) NEON_VECTOR_TYPE(__Int32x4_t, IntTy, 32, 4, VectorKind::Neon) -NEON_VECTOR_TYPE(__Int64x2_t, LongLongTy, 64, 2, VectorKind::Neon) -NEON_VECTOR_TYPE(__Uint8x16_t, CharTy, 8, 16, VectorKind::Neon) +NEON_VECTOR_TYPE(__Int64x2_t, LongTy, 64, 2, VectorKind::Neon) +NEON_VECTOR_TYPE(__Uint8x16_t, UnsignedCharTy, 8, 16, VectorKind::Neon) NEON_VECTOR_TYPE(__Uint16x8_t, UnsignedShortTy, 16, 8, VectorKind::Neon) NEON_VECTOR_TYPE(__Uint32x4_t, UnsignedIntTy, 32, 4, VectorKind::Neon) -NEON_VECTOR_TYPE(__Uint64x2_t, UnsignedLongLongTy, 64, 2, VectorKind::Neon) -NEON_VECTOR_TYPE(__Float16x8_t, Float16Ty, 16, 8, VectorKind::Neon) +NEON_VECTOR_TYPE(__Uint64x2_t, UnsignedLongTy, 64, 2, VectorKind::Neon) +NEON_VECTOR_TYPE(__Float16x8_t, HalfTy, 16, 8, VectorKind::Neon) NEON_VECTOR_TYPE(__Float32x4_t, FloatTy, 32, 4, VectorKind::Neon) NEON_VECTOR_TYPE(__Float64x2_t, DoubleTy, 64, 2, VectorKind::Neon) -NEON_VECTOR_TYPE(__Poly8x16_t, CharTy, 8, 16, VectorKind::NeonPoly) +NEON_VECTOR_TYPE(__Poly8x16_t, UnsignedCharTy, 8, 16, VectorKind::NeonPoly) NEON_VECTOR_TYPE(__Poly16x8_t, UnsignedShortTy, 16, 8, VectorKind::NeonPoly) -NEON_VECTOR_TYPE(__Poly64x2_t, UnsignedLongLongTy, 64, 2, VectorKind::NeonPoly) +NEON_VECTOR_TYPE(__Poly64x2_t, UnsignedLongTy, 64, 2, VectorKind::NeonPoly) NEON_VECTOR_TYPE(__Bfloat16x8_t, BFloat16Ty, 16, 8, VectorKind::Neon) NEON_VECTOR_TYPE(__Mfloat8x8_t, MFloat8Ty, 8, 8, VectorKind::Neon) NEON_VECTOR_TYPE(__Mfloat8x16_t, MFloat8Ty, 8, 16, VectorKind::Neon) diff --git a/clang/test/AST/ast-dump-aarch64-neon-types.c b/clang/test/AST/ast-dump-aarch64-neon-types.c index 16255cd51c9d8..f509bd880c14b 100644 --- a/clang/test/AST/ast-dump-aarch64-neon-types.c +++ b/clang/test/AST/ast-dump-aarch64-neon-types.c @@ -9,7 +9,7 @@ // RUN: %clang_cc1 -verify -verify-ignore-unexpected=note -triple arm-linux-gnu %s -x c++ __Int8x8_t Int8x8; -// CHECK: Int8x8 '__Int8x8_t':'__attribute__((neon_vector_type(8))) char' +// CHECK: Int8x8 '__Int8x8_t':'__attribute__((neon_vector_type(8))) signed char' // expected-error@-2{{unknown type name '__Int8x8_t'}} __Int16x4_t Int16x4; @@ -21,7 +21,7 @@ __Int32x2_t Int32x2; // expected-error@-2{{unknown type name '__Int32x2_t'}} __Uin
[clang] [AArch64][Clang] Update new Neon vector element types. (PR #142760)
llvmbot wrote: @llvm/pr-subscribers-clang Author: David Green (davemgreen) Changes This updates the element types used in the new __Int8x8_t types added in #126945, mostly to allow C++ name mangling in ItaniumMangling mangleAArch64VectorBase to work correctly. Char is replaced by SignedCharTy or UnsignedCharTy as required and Float16Ty is better using HalfTy to match the vector types. Same for Long types. --- Patch is 39.44 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/142760.diff 3 Files Affected: - (modified) clang/include/clang/Basic/AArch64ACLETypes.def (+11-11) - (modified) clang/test/AST/ast-dump-aarch64-neon-types.c (+11-11) - (modified) clang/test/CodeGen/AArch64/mixed-neon-types.c (+516-43) ``diff diff --git a/clang/include/clang/Basic/AArch64ACLETypes.def b/clang/include/clang/Basic/AArch64ACLETypes.def index 9acfd693288cf..bbe0c85f9ffbe 100644 --- a/clang/include/clang/Basic/AArch64ACLETypes.def +++ b/clang/include/clang/Basic/AArch64ACLETypes.def @@ -123,31 +123,31 @@ //===- Neon Vector point types ===// -NEON_VECTOR_TYPE(__Int8x8_t, CharTy, 8, 8, VectorKind::Neon) +NEON_VECTOR_TYPE(__Int8x8_t, SignedCharTy, 8, 8, VectorKind::Neon) NEON_VECTOR_TYPE(__Int16x4_t, ShortTy, 16, 4, VectorKind::Neon) NEON_VECTOR_TYPE(__Int32x2_t, IntTy, 32, 2, VectorKind::Neon) -NEON_VECTOR_TYPE(__Uint8x8_t, CharTy, 8, 8, VectorKind::Neon) +NEON_VECTOR_TYPE(__Uint8x8_t, UnsignedCharTy, 8, 8, VectorKind::Neon) NEON_VECTOR_TYPE(__Uint16x4_t, UnsignedShortTy, 16, 4, VectorKind::Neon) NEON_VECTOR_TYPE(__Uint32x2_t, UnsignedIntTy, 32, 2, VectorKind::Neon) -NEON_VECTOR_TYPE(__Float16x4_t, Float16Ty, 16, 4, VectorKind::Neon) +NEON_VECTOR_TYPE(__Float16x4_t, HalfTy, 16, 4, VectorKind::Neon) NEON_VECTOR_TYPE(__Float32x2_t, FloatTy, 32, 2, VectorKind::Neon) -NEON_VECTOR_TYPE(__Poly8x8_t, CharTy, 8, 8, VectorKind::NeonPoly) +NEON_VECTOR_TYPE(__Poly8x8_t, UnsignedCharTy, 8, 8, VectorKind::NeonPoly) NEON_VECTOR_TYPE(__Poly16x4_t, UnsignedShortTy, 16, 4, VectorKind::NeonPoly) NEON_VECTOR_TYPE(__Bfloat16x4_t, BFloat16Ty, 16, 4, VectorKind::Neon) -NEON_VECTOR_TYPE(__Int8x16_t, CharTy, 8, 16, VectorKind::Neon) +NEON_VECTOR_TYPE(__Int8x16_t, SignedCharTy, 8, 16, VectorKind::Neon) NEON_VECTOR_TYPE(__Int16x8_t, ShortTy, 16, 8, VectorKind::Neon) NEON_VECTOR_TYPE(__Int32x4_t, IntTy, 32, 4, VectorKind::Neon) -NEON_VECTOR_TYPE(__Int64x2_t, LongLongTy, 64, 2, VectorKind::Neon) -NEON_VECTOR_TYPE(__Uint8x16_t, CharTy, 8, 16, VectorKind::Neon) +NEON_VECTOR_TYPE(__Int64x2_t, LongTy, 64, 2, VectorKind::Neon) +NEON_VECTOR_TYPE(__Uint8x16_t, UnsignedCharTy, 8, 16, VectorKind::Neon) NEON_VECTOR_TYPE(__Uint16x8_t, UnsignedShortTy, 16, 8, VectorKind::Neon) NEON_VECTOR_TYPE(__Uint32x4_t, UnsignedIntTy, 32, 4, VectorKind::Neon) -NEON_VECTOR_TYPE(__Uint64x2_t, UnsignedLongLongTy, 64, 2, VectorKind::Neon) -NEON_VECTOR_TYPE(__Float16x8_t, Float16Ty, 16, 8, VectorKind::Neon) +NEON_VECTOR_TYPE(__Uint64x2_t, UnsignedLongTy, 64, 2, VectorKind::Neon) +NEON_VECTOR_TYPE(__Float16x8_t, HalfTy, 16, 8, VectorKind::Neon) NEON_VECTOR_TYPE(__Float32x4_t, FloatTy, 32, 4, VectorKind::Neon) NEON_VECTOR_TYPE(__Float64x2_t, DoubleTy, 64, 2, VectorKind::Neon) -NEON_VECTOR_TYPE(__Poly8x16_t, CharTy, 8, 16, VectorKind::NeonPoly) +NEON_VECTOR_TYPE(__Poly8x16_t, UnsignedCharTy, 8, 16, VectorKind::NeonPoly) NEON_VECTOR_TYPE(__Poly16x8_t, UnsignedShortTy, 16, 8, VectorKind::NeonPoly) -NEON_VECTOR_TYPE(__Poly64x2_t, UnsignedLongLongTy, 64, 2, VectorKind::NeonPoly) +NEON_VECTOR_TYPE(__Poly64x2_t, UnsignedLongTy, 64, 2, VectorKind::NeonPoly) NEON_VECTOR_TYPE(__Bfloat16x8_t, BFloat16Ty, 16, 8, VectorKind::Neon) NEON_VECTOR_TYPE(__Mfloat8x8_t, MFloat8Ty, 8, 8, VectorKind::Neon) NEON_VECTOR_TYPE(__Mfloat8x16_t, MFloat8Ty, 8, 16, VectorKind::Neon) diff --git a/clang/test/AST/ast-dump-aarch64-neon-types.c b/clang/test/AST/ast-dump-aarch64-neon-types.c index 16255cd51c9d8..f509bd880c14b 100644 --- a/clang/test/AST/ast-dump-aarch64-neon-types.c +++ b/clang/test/AST/ast-dump-aarch64-neon-types.c @@ -9,7 +9,7 @@ // RUN: %clang_cc1 -verify -verify-ignore-unexpected=note -triple arm-linux-gnu %s -x c++ __Int8x8_t Int8x8; -// CHECK: Int8x8 '__Int8x8_t':'__attribute__((neon_vector_type(8))) char' +// CHECK: Int8x8 '__Int8x8_t':'__attribute__((neon_vector_type(8))) signed char' // expected-error@-2{{unknown type name '__Int8x8_t'}} __Int16x4_t Int16x4; @@ -21,7 +21,7 @@ __Int32x2_t Int32x2; // expected-error@-2{{unknown type name '__Int32x2_t'}} __Uint8x8_t Uint8x8; -// CHECK: Uint8x8 '__Uint8x8_t':'__attribute__((neon_vector_type(8))) char' +// CHECK: Uint8x8 '__Uint8x8_t':'__attribute__((neon_vector_type(8))) unsigned char' // expected-error@-2{{unknown type name '__Uint8x8_t'}} __Uint16x4_t Uint16x4; @@ -33,7 +33,7 @@ __Uint32x2_t Uint32x2; // expected-error@-2{{unknown type name '__Uint32x2_t'}} __Float16x4_t Float16x4; -// CHEC
[clang] ac42923 - Reapply "[KeyInstr][Clang] For range stmt atoms" (#142630)
Author: Orlando Cazalet-Hyams Date: 2025-06-04T10:53:29+01:00 New Revision: ac42923c2defe51fcc9220f68d50b33b5e872933 URL: https://github.com/llvm/llvm-project/commit/ac42923c2defe51fcc9220f68d50b33b5e872933 DIFF: https://github.com/llvm/llvm-project/commit/ac42923c2defe51fcc9220f68d50b33b5e872933.diff LOG: Reapply "[KeyInstr][Clang] For range stmt atoms" (#142630) This reverts commit e6529dcedb3955706a8af5710591f1ac1bac26a3 with crash fixed. Original PR https://github.com/llvm/llvm-project/pull/134647 This patch is part of a stack that teaches Clang to generate Key Instructions metadata for C and C++. RFC: https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668 The feature is only functional in LLVM if LLVM is built with CMake flag LLVM_EXPERIMENTAL_KEY_INSTRUCTIONs. Eventually that flag will be removed. Added: clang/test/DebugInfo/KeyInstructions/for-range.cpp Modified: clang/lib/CodeGen/CGStmt.cpp Removed: diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp index 205a57cbab31a..dc92493ac70fa 100644 --- a/clang/lib/CodeGen/CGStmt.cpp +++ b/clang/lib/CodeGen/CGStmt.cpp @@ -1483,7 +1483,14 @@ CodeGenFunction::EmitCXXForRangeStmt(const CXXForRangeStmt &S, if (!Weights && CGM.getCodeGenOpts().OptimizationLevel) BoolCondVal = emitCondLikelihoodViaExpectIntrinsic( BoolCondVal, Stmt::getLikelihood(S.getBody())); - Builder.CreateCondBr(BoolCondVal, ForBody, ExitBlock, Weights); + auto *I = Builder.CreateCondBr(BoolCondVal, ForBody, ExitBlock, Weights); + // Key Instructions: Emit the condition and branch as separate atoms to + // match existing loop stepping behaviour. FIXME: We could have the branch as + // the backup location for the condition, which would probably be a better + // experience. + if (auto *CondI = dyn_cast(BoolCondVal)) +addInstToNewSourceAtom(CondI, nullptr); + addInstToNewSourceAtom(I, nullptr); if (ExitBlock != LoopExit.getBlock()) { EmitBlock(ExitBlock); @@ -1508,6 +1515,9 @@ CodeGenFunction::EmitCXXForRangeStmt(const CXXForRangeStmt &S, EmitStmt(S.getLoopVarStmt()); EmitStmt(S.getBody()); } + // The last block in the loop's body (which unconditionally branches to the + // `inc` block if there is one). + auto *FinalBodyBB = Builder.GetInsertBlock(); EmitStopPoint(&S); // If there is an increment, emit it next. @@ -1532,6 +1542,12 @@ CodeGenFunction::EmitCXXForRangeStmt(const CXXForRangeStmt &S, if (CGM.shouldEmitConvergenceTokens()) ConvergenceTokenStack.pop_back(); + + if (FinalBodyBB) { +// We want the for closing brace to be step-able on to match existing +// behaviour. +addInstToNewSourceAtom(FinalBodyBB->getTerminator(), nullptr); + } } void CodeGenFunction::EmitReturnOfRValue(RValue RV, QualType Ty) { diff --git a/clang/test/DebugInfo/KeyInstructions/for-range.cpp b/clang/test/DebugInfo/KeyInstructions/for-range.cpp new file mode 100644 index 0..433f900219f12 --- /dev/null +++ b/clang/test/DebugInfo/KeyInstructions/for-range.cpp @@ -0,0 +1,99 @@ +// RUN: %clang_cc1 -triple x86_64-linux-gnu -gkey-instructions %s -debug-info-kind=line-tables-only -emit-llvm -o - \ +// RUN: | FileCheck %s + +// Perennial question: should the inc be its own source atom or not +// (currently it is). + +// FIXME: See do.c and while.c regarding cmp and cond br groups. + +// The stores in the setup (stores to __RANGE1, __BEGIN1, __END1) are all +// marked as Key. Unclear whether that's desirable. Keep for now as that's +// least risky (at worst it introduces an unnecessary step while debugging, +// as opposed to potentially losing one we want). + +// Check the conditional branch (and the condition) in FOR_COND and +// unconditional branch in FOR_BODY are Key Instructions. + +struct Range { +int *begin(); +int *end(); +} r; + +// CHECK-LABEL: define dso_local void @_Z1av( +// CHECK-SAME: ) #[[ATTR0:[0-9]+]] !dbg [[DBG10:![0-9]+]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT:[[__RANGE1:%.*]] = alloca ptr, align 8 +// CHECK-NEXT:[[__BEGIN1:%.*]] = alloca ptr, align 8 +// CHECK-NEXT:[[__END1:%.*]] = alloca ptr, align 8 +// CHECK-NEXT:[[I:%.*]] = alloca i32, align 4 +// CHECK-NEXT:store ptr @r, ptr [[__RANGE1]], align 8, !dbg [[DBG14:![0-9]+]] +// CHECK-NEXT:[[CALL:%.*]] = call noundef ptr @_ZN5Range5beginEv(ptr noundef nonnull align 1 dereferenceable(1) @r), !dbg [[DBG15:![0-9]+]] +// CHECK-NEXT:store ptr [[CALL]], ptr [[__BEGIN1]], align 8, !dbg [[DBG16:![0-9]+]] +// CHECK-NEXT:[[CALL1:%.*]] = call noundef ptr @_ZN5Range3endEv(ptr noundef nonnull align 1 dereferenceable(1) @r), !dbg [[DBG17:![0-9]+]] +// CHECK-NEXT:store ptr [[CALL1]], ptr [[__END1]], align 8, !dbg [[DBG18:![0-9]+]] +// CHECK-NEXT:br label %[[FOR_COND:.*]], !dbg [[DBG19:![0-9]+]] +// CHECK: [[FOR_COND]
[clang] [clang-repl] Ensure clang-repl accepts all C keywords supported in all language models (PR #142749)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Anutosh Bhat (anutosh491) Changes As can be seen through the docs (https://github.com/llvm/llvm-project/blob/7e1fa09ce2a228c949ce4490c98f2c73ed8ada00/clang/docs/LanguageExtensions.rst#c-keywords-supported-in-all-language-modes), Clang supports certain C keywords in all language modes — this patch ensures clang-repl handles them consistently. Here's an example testing all the above keywords. We have everything in place except `_Imaginary` (_Complex works but _Imaginary doesn't which was weird) and `_Noreturn` --- Full diff: https://github.com/llvm/llvm-project/pull/142749.diff 1 Files Affected: - (modified) clang/lib/Parse/ParseTentative.cpp (+2) ``diff diff --git a/clang/lib/Parse/ParseTentative.cpp b/clang/lib/Parse/ParseTentative.cpp index 95cee824c40b7..f50bcd8ea90bb 100644 --- a/clang/lib/Parse/ParseTentative.cpp +++ b/clang/lib/Parse/ParseTentative.cpp @@ -1171,6 +1171,7 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext AllowImplicitTypename, case tok::kw_inline: case tok::kw_virtual: case tok::kw_explicit: + case tok::kw__Noreturn: // Modules case tok::kw___module_private__: @@ -1225,6 +1226,7 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext AllowImplicitTypename, // GNU case tok::kw_restrict: case tok::kw__Complex: + case tok::kw__Imaginary: case tok::kw___attribute: case tok::kw___auto_type: return TPResult::True; `` https://github.com/llvm/llvm-project/pull/142749 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] add new check: modernize-use-scoped-lock (PR #126434)
vbvictor wrote: Gentle ping @PiotrZSL https://github.com/llvm/llvm-project/pull/126434 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [ubsan] Add more -fsanitize-annotate-debug-info checks (PR #141997)
Michael137 wrote: > While logically correct I think we might have to teach LLDB how to handle > this. LLDB has a special "frame recognizer" where it looks for frames using > this fake debug info mechanism (e.g. __builtin_verbose_trap) and it assumes > the frame below it is the real source code and automatically selects this > frame when trapping so that the user sees the correct source location when > the trap is hit. If the frame below the fake frame isn't the user's code and > is instead another fake frame this won't work properly. Yea everything that @delcypher said here is accurate from the LLDB-side. Here's the logic that LLDB uses to pick which frame to display: https://github.com/llvm/llvm-project/blob/9ba332f9963561bb5ac6933266afe38eb8fde8cd/lldb/source/Target/VerboseTrapFrameRecognizer.cpp#L22-L50 Currently we just pick the frame just above the fake inlined frame (and skip over any `std::` frames). We can definitely adjust the heuristic to accommodate the case where we have another fake frame above the UBSan trap one. > It's probably possible to make LLDB work with which ever top frame we decide > but we'd probably want the fake frame names be easily recognizable and stable > so that LLDB's feature continues to work reliably. Agreed, for the `__builtin_verbose_trap` we picked `__clang_trap_msg` as the prefix for the fake frame. And that's how LLDB knows to activate the frame recognizer: https://github.com/llvm/llvm-project/blob/9ba332f9963561bb5ac6933266afe38eb8fde8cd/lldb/source/Target/VerboseTrapFrameRecognizer.cpp#L145-L146 We'll want a similar prefix for any other fake frames that LLDB is supposed to recognize > Given that -fsanitize-annotate-debug-info is off by default my suggestion is > that @anthonyhatran land the simplest version of his patch possible by not > concerning himself with -fsanitize-annotate-debug-info at this stage. And > after it's landed we can then decide how to make the two features interact in > a way that the LLDB folks are happy with. Agreed https://github.com/llvm/llvm-project/pull/141997 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add ClangQueryChecks config option (PR #123734)
vbvictor wrote: Closed as further review happens in https://github.com/llvm/llvm-project/pull/131804 https://github.com/llvm/llvm-project/pull/123734 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add ClangQueryChecks config option (PR #123734)
https://github.com/DeNiCoN closed https://github.com/llvm/llvm-project/pull/123734 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Added TypeKind.FLOAT16 for 32 in cindex.py (PR #142634)
Endilll wrote: > > Time to put libclang to use, and parse cindex.h? > > Probably, though I'll check if there are any more direct options first. I > don't quite like the idea of hardcoding source file paths in bindings tests. If that helps, it should be available using a relatively stable path, because it's a public header. https://github.com/llvm/llvm-project/pull/142634 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Introduce intra-procedural lifetime analysis in Clang (PR #142313)
https://github.com/usx95 edited https://github.com/llvm/llvm-project/pull/142313 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add AllowFalseEvaluated flag to clang-tidy noexcept-move-constructor check (PR #126897)
@@ -0,0 +1,63 @@ +// RUN: %check_clang_tidy %s performance-noexcept-move-constructor %t -- -- -fexceptions + +// RUN: %check_clang_tidy -check-suffix=CONFIG %s performance-noexcept-move-constructor,performance-noexcept-destructor %t -- \ +// RUN: -config="{CheckOptions: {performance-noexcept-move-constructor.AllowFalseEvaluated: true}}" \ +// RUN: -- -fexceptions + +namespace std +{ + template + struct is_nothrow_move_constructible + { +static constexpr bool value = __is_nothrow_constructible(T, __add_rvalue_reference(T)); + }; +} // namespace std + +struct ThrowOnAnything { + ThrowOnAnything() noexcept(false); + ThrowOnAnything(ThrowOnAnything&&) noexcept(false); + // CHECK-MESSAGES-NOT: :[[@LINE-1]]:3: warning: move constructors should be marked noexcept + // CHECK-MESSAGES-CONFIG-NOT: :[[@LINE-2]]:3: warning: move constructors should be marked noexcept vbvictor wrote: CHECK-MESSAGES-NOT considered deprecated because by default FileCheck triggers if there was output that was expected by CHECK-MESSAGES. So this could be removed in whole file https://github.com/llvm/llvm-project/pull/126897 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add AllowFalseEvaluated flag to clang-tidy noexcept-move-constructor check (PR #126897)
@@ -0,0 +1,63 @@ +// RUN: %check_clang_tidy %s performance-noexcept-move-constructor %t -- -- -fexceptions vbvictor wrote: Generally with options-test-file we do not need to check basic functionality since it should be covered in main test file https://github.com/llvm/llvm-project/pull/126897 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add AllowFalseEvaluated flag to clang-tidy noexcept-move-constructor check (PR #126897)
https://github.com/vbvictor commented: @Nechda, gentle ping, do you still wish to work on this PR? 21th LLVM release will be soon, If you wish to have your changes in the upcoming release please rebase on main and fix suggestions. https://github.com/llvm/llvm-project/pull/126897 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] `modernize-use-trailing-return-type`: add an option to apply to `void`-returning functions as well (PR #129406)
vbvictor wrote: @khuldraeseth, gentle ping, do you still wish to work on this check? 21th LLVM release will be soon, If you wish to have your changes in the upcoming release please rebase on main and fix suggested issues https://github.com/llvm/llvm-project/pull/129406 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add AllowFalseEvaluated flag to clang-tidy noexcept-move-constructor check (PR #126897)
https://github.com/vbvictor edited https://github.com/llvm/llvm-project/pull/126897 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL][SPIR-V] Implement vk::ext_builtin_input attribute (PR #138530)
Keenuts wrote: There is one failure on the CI, in lldb, an unrelated timeout https://github.com/llvm/llvm-project/pull/138530 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL][SPIR-V] Implement vk::ext_builtin_input attribute (PR #138530)
https://github.com/Keenuts closed https://github.com/llvm/llvm-project/pull/138530 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL][SPIR-V] Handle SV_Postion builtin in PS (PR #141759)
https://github.com/Keenuts updated https://github.com/llvm/llvm-project/pull/141759 From 4653aca0444c9ce14893e877eeb88241c9b01934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nathan=20Gau=C3=ABr?= Date: Mon, 5 May 2025 18:01:17 +0200 Subject: [PATCH] [HLSL][SPIR-V] Handle SV_Postion builtin in PS This commit is using the same mechanism as vk::ext_builtin_input to implement the SV_Position semantic input. The HLSL signature is not yet ready for DXIL, hence this commit only implements the SPIR-V side. This is incomplete as it doesn't allow the semantic on hull/domain and other shaders, but it's a first step to validate the overall input/output semantic logic. --- clang/include/clang/Basic/Attr.td | 7 clang/include/clang/Basic/AttrDocs.td | 14 +++ clang/include/clang/Sema/SemaHLSL.h | 2 + clang/lib/CodeGen/CGHLSLRuntime.cpp | 41 ++- clang/lib/Parse/ParseHLSL.cpp | 1 + clang/lib/Sema/SemaDeclAttr.cpp | 3 ++ clang/lib/Sema/SemaHLSL.cpp | 27 .../CodeGenHLSL/semantics/SV_Position.ps.hlsl | 10 + .../test/SemaHLSL/Semantics/position.ps.hlsl | 7 .../test/SemaHLSL/Semantics/position.vs.hlsl | 6 +++ 10 files changed, 108 insertions(+), 10 deletions(-) create mode 100644 clang/test/CodeGenHLSL/semantics/SV_Position.ps.hlsl create mode 100644 clang/test/SemaHLSL/Semantics/position.ps.hlsl create mode 100644 clang/test/SemaHLSL/Semantics/position.vs.hlsl diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 7c63279f156a9..ae363a780a674 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -4851,6 +4851,13 @@ def HLSLResourceBinding: InheritableAttr { }]; } +def HLSLSV_Position : HLSLAnnotationAttr { + let Spellings = [HLSLAnnotation<"sv_position">]; + let Subjects = SubjectList<[ParmVar, Field]>; + let LangOpts = [HLSL]; + let Documentation = [HLSLSV_PositionDocs]; +} + def HLSLPackOffset: HLSLAnnotationAttr { let Spellings = [HLSLAnnotation<"packoffset">]; let LangOpts = [HLSL]; diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index 5b58bbb510c54..a09de9220608d 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -8472,6 +8472,20 @@ The full documentation is available here: https://docs.microsoft.com/en-us/windo }]; } +def HLSLSV_PositionDocs : Documentation { + let Category = DocCatFunction; + let Content = [{ +The ``SV_Position`` semantic, when applied to an input parameter in a pixel +shader, contains the location of the pixel center (x, y) in screen space. +This semantic can be applied to the parameter, or a field in a struct used +as input parameter. +This attribute is supported as input in pixel, hull, domain and mesh shaders. +This attribute is supported as output in vertex, geometry and domain shaders. + +The full documentation is available here: https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-semantics + }]; +} + def HLSLGroupSharedAddressSpaceDocs : Documentation { let Category = DocCatVariable; let Content = [{ diff --git a/clang/include/clang/Sema/SemaHLSL.h b/clang/include/clang/Sema/SemaHLSL.h index 66d09f49680be..ba5f06f93dc30 100644 --- a/clang/include/clang/Sema/SemaHLSL.h +++ b/clang/include/clang/Sema/SemaHLSL.h @@ -125,6 +125,7 @@ class SemaHLSL : public SemaBase { void handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL); void handleSV_GroupThreadIDAttr(Decl *D, const ParsedAttr &AL); void handleSV_GroupIDAttr(Decl *D, const ParsedAttr &AL); + void handleSV_PositionAttr(Decl *D, const ParsedAttr &AL); void handlePackOffsetAttr(Decl *D, const ParsedAttr &AL); void handleShaderAttr(Decl *D, const ParsedAttr &AL); void handleResourceBindingAttr(Decl *D, const ParsedAttr &AL); @@ -146,6 +147,7 @@ class SemaHLSL : public SemaBase { // Diagnose whether the input ID is uint/unit2/uint3 type. bool diagnoseInputIDType(QualType T, const ParsedAttr &AL); + bool diagnosePositionType(QualType T, const ParsedAttr &AL); bool CanPerformScalarCast(QualType SrcTy, QualType DestTy); bool ContainsBitField(QualType BaseTy); diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp index 6d267e6164845..9115492d1b1dd 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -384,6 +384,28 @@ static Value *buildVectorInput(IRBuilder<> &B, Function *F, llvm::Type *Ty) { return B.CreateCall(F, {B.getInt32(0)}); } +static void addBuiltinDecoration(llvm::GlobalVariable *GV, unsigned BuiltIn) { + LLVMContext &Ctx = GV->getContext(); + IRBuilder<> B(GV->getContext()); + MDNode *Operands = + MDNode::get(Ctx, {ConstantAsMetadata::get(B.getInt32(11)), +ConstantAsMetadata::get(B.getInt32(BuiltIn))}); + MDNod
[clang] [HLSL][SPIR-V] Handle SV_Postion builtin in PS (PR #141759)
https://github.com/Keenuts edited https://github.com/llvm/llvm-project/pull/141759 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Introduce cir::RecordKind::Class (PR #142690)
https://github.com/xlauko edited https://github.com/llvm/llvm-project/pull/142690 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Introduce cir::RecordKind::Class (PR #142690)
https://github.com/xlauko approved this pull request. lgtm https://github.com/llvm/llvm-project/pull/142690 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix bad error recovery when classes are defined inside template (PR #142278)
https://github.com/ArtyomZabroda updated https://github.com/llvm/llvm-project/pull/142278 >From 6fc280bb5583ee4f1713cb1447b8b86993b7abb7 Mon Sep 17 00:00:00 2001 From: Artyom Zabroda Date: Sat, 31 May 2025 18:44:21 +0300 Subject: [PATCH 1/2] [clang] Fix bad error recovery when classes are defined inside template aliases --- clang/lib/Sema/SemaConcept.cpp | 8 clang/lib/Sema/SemaDeclCXX.cpp | 9 - clang/test/SemaCXX/concept-crash-on-diagnostic.cpp | 13 + 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp index c6a54dc141ded..1c654f46e23b3 100644 --- a/clang/lib/Sema/SemaConcept.cpp +++ b/clang/lib/Sema/SemaConcept.cpp @@ -220,6 +220,14 @@ static ExprResult EvaluateAtomicConstraint( if (Inst.isInvalid()) return ExprError(); +if (const TemplateTypeParmType *TTPT = + dyn_cast(AtomicExpr->getType().getDesugaredType(S.Context))) { + TemplateTypeParmDecl *TTPD = TTPT->getDecl(); + if (TTPD->isInvalidDecl()) { +return ExprError(); + } +} + llvm::FoldingSetNodeID ID; if (Template && DiagRecursiveConstraintEval(S, ID, Template, AtomicExpr, MLTAL)) { diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 55e078f3180a2..3efd18c0dcd96 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -13717,8 +13717,15 @@ Decl *Sema::ActOnAliasDeclaration(Scope *S, AccessSpecifier AS, const ParsedAttributesView &AttrList, TypeResult Type, Decl *DeclFromDeclSpec) { - if (Type.isInvalid()) + if (Type.isInvalid()) { +for (TemplateParameterList *TPL : TemplateParamLists) { + for (NamedDecl *D : *TPL) { +D->setInvalidDecl(true); + } +} return nullptr; + } + bool Invalid = false; DeclarationNameInfo NameInfo = GetNameFromUnqualifiedId(Name); diff --git a/clang/test/SemaCXX/concept-crash-on-diagnostic.cpp b/clang/test/SemaCXX/concept-crash-on-diagnostic.cpp index 1efed72522fef..af254828b0fe7 100644 --- a/clang/test/SemaCXX/concept-crash-on-diagnostic.cpp +++ b/clang/test/SemaCXX/concept-crash-on-diagnostic.cpp @@ -60,3 +60,16 @@ concept atomicish = requires() { }; atomicish f(); // expected-error {{expected 'auto' or 'decltype(auto)' after concept name}} } // namespace GH138820 + +namespace GH91564 { +template using A = struct B { // expected-error {{'GH91564::B' cannot be defined in a type alias template}} + template void f() requires (T()); // expected-note {{candidate template ignored: failed template argument deduction}} +}; +template void B::f(); // expected-error {{explicit instantiation of 'f' does not refer to a function template, variable template, member function, member class, or static data member}} + +template using C = struct D { // expected-error {{'GH91564::D' cannot be defined in a type alias template}} + using E = T; +}; +template void g() requires (D::E()); // expected-note {{candidate template ignored: failed template argument deduction}} +template void g(); // expected-error {{explicit instantiation of 'g' does not refer to a function template, variable template, member function, member class, or static data member}} +} \ No newline at end of file >From c52af95007c2efaac1d44f3ff36e6a8021d6b70f Mon Sep 17 00:00:00 2001 From: Artyom Zabroda Date: Wed, 4 Jun 2025 14:16:26 +0300 Subject: [PATCH 2/2] very inaccurate fix --- clang/include/clang/Parse/Parser.h | 2 ++ clang/lib/Parse/ParseDeclCXX.cpp| 17 + clang/lib/Sema/SemaConcept.cpp | 8 clang/lib/Sema/SemaDecl.cpp | 4 ++-- clang/lib/Sema/SemaDeclCXX.cpp | 9 + .../SemaCXX/concept-crash-on-diagnostic.cpp | 8 6 files changed, 26 insertions(+), 22 deletions(-) diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index c4bef4729fd36..90f17465bce7d 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -8909,6 +8909,8 @@ class Parser : public CodeCompletionHandler { bool OuterMightBeMessageSend = false); ///@} + + TemplateParameterLists *TemplateParamsFromAlias = nullptr; }; } // end namespace clang diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index 2cf33a856c4f4..4069d257b0150 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -886,11 +886,17 @@ Decl *Parser::ParseAliasDeclarationAfterDeclarator( << FixItHint::CreateRemoval(SourceRange(D.EllipsisLoc)); Decl *DeclFromDeclSpec = nullptr; + + this->TemplateParamsFromAlias = TemplateInfo.TemplateParams; + TypeResult TypeAlias = ParseTypeName(nullptr,
[clang] [clang] Fix bad error recovery when classes are defined inside template (PR #142278)
@@ -220,6 +220,14 @@ static ExprResult EvaluateAtomicConstraint( if (Inst.isInvalid()) return ExprError(); +if (const TemplateTypeParmType *TTPT = + dyn_cast(AtomicExpr->getType().getDesugaredType(S.Context))) { + TemplateTypeParmDecl *TTPD = TTPT->getDecl(); + if (TTPD->isInvalidDecl()) { +return ExprError(); + } +} + ArtyomZabroda wrote: You are right, I didn't change the type early enough, and after I did everything worked as expected. However, I've encountered a problem while implementing this fix. ParseAliasDeclarationAfterDeclarator initially parses an invalid struct and only then it checks whether the struct definition should be here in the first place. The problem is that I don't know of any nice way to obtain the template parameters of an alias while building a struct definition. In a new commit, I've used an improper way of passing template parameters to check if it fixes the issue. Maybe it would be better not to change the type as soon as getting into the struct definition, but instead to let it build itself improperly, and then when we figure out that struct definition shouldn't be there use TreeTransform to change this struct? https://github.com/llvm/llvm-project/pull/142278 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix bad error recovery when classes are defined inside template (PR #142278)
https://github.com/ArtyomZabroda edited https://github.com/llvm/llvm-project/pull/142278 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix bad error recovery when classes are defined inside template (PR #142278)
https://github.com/ArtyomZabroda edited https://github.com/llvm/llvm-project/pull/142278 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [WIP] ABI Lowering Library (PR #140112)
https://github.com/vortex73 updated https://github.com/llvm/llvm-project/pull/140112 >From 322c1cfb925f3073f3d3b30abe1b2e35ae7745f3 Mon Sep 17 00:00:00 2001 From: Narayan Sreekumar Date: Thu, 15 May 2025 23:13:50 +0530 Subject: [PATCH 1/6] [LLVM ABI] The Typesystem --- llvm/include/llvm/ABI/Types.h | 121 ++ 1 file changed, 121 insertions(+) create mode 100644 llvm/include/llvm/ABI/Types.h diff --git a/llvm/include/llvm/ABI/Types.h b/llvm/include/llvm/ABI/Types.h new file mode 100644 index 0..443a6c1eab4e7 --- /dev/null +++ b/llvm/include/llvm/ABI/Types.h @@ -0,0 +1,121 @@ +#ifndef LLVM_ABI_TYPES_H +#define LLVM_ABI_TYPES_H + +#include +#include +#include + +namespace llvm { +namespace abi { + +enum class TypeKind { + Void, + Integer, + Float, + Pointer, + Array, + Vector, + Struct, + Union, + Function +}; +class Type { +protected: + TypeKind Kind; + uint64_t SizeInBits; + uint64_t AlignInBits; + bool IsExplicitlyAligned; + + Type(TypeKind K, uint64_t Size, uint64_t Align, bool ExplicitAlign = false) + : Kind(K), SizeInBits(Size), AlignInBits(Align), +IsExplicitlyAligned(ExplicitAlign) {} + +public: + virtual ~Type() = default; + + TypeKind getKind() const { return Kind; } + uint64_t getSizeInBits() const { return SizeInBits; } + uint64_t getAlignInBits() const { return AlignInBits; } + bool hasExplicitAlignment() const { return IsExplicitlyAligned; } + + void setExplicitAlignment(uint64_t Align) { +AlignInBits = Align; +IsExplicitlyAligned = true; + } + + bool isVoid() const { return Kind == TypeKind::Void; } + bool isInteger() const { return Kind == TypeKind::Integer; } + bool isFloat() const { return Kind == TypeKind::Float; } + bool isPointer() const { return Kind == TypeKind::Pointer; } + bool isArray() const { return Kind == TypeKind::Array; } + bool isVector() const { return Kind == TypeKind::Vector; } + bool isStruct() const { return Kind == TypeKind::Struct; } + bool isUnion() const { return Kind == TypeKind::Union; } + bool isFunction() const { return Kind == TypeKind::Function; } + + static bool classof(const Type *) { return true; } +}; +class VoidType : public Type { +public: + VoidType() : Type(TypeKind::Void, 0, 0) {} + + static bool classof(const Type *T) { return T->getKind() == TypeKind::Void; } +}; + +class IntegerType : public Type { +private: + bool IsSigned; + bool IsAltRepresentation; + std::string TypeName; + +public: + IntegerType(uint64_t BitWidth, uint64_t Align, bool Signed, + bool AltRep = false, const std::string &Name = "") + : Type(TypeKind::Integer, BitWidth, Align), IsSigned(Signed), +IsAltRepresentation(AltRep), TypeName(Name) {} + + bool isSigned() const { return IsSigned; } + bool isAltRepresentation() const { return IsAltRepresentation; } + const std::string &getTypeName() const { return TypeName; } + + static bool classof(const Type *T) { +return T->getKind() == TypeKind::Integer; + } +}; +class FloatType : public Type { +private: + std::string TypeName; + +public: + FloatType(uint64_t BitWidth, uint64_t Align, const std::string &Name) + : Type(TypeKind::Float, BitWidth, Align), TypeName(Name) {} + + const std::string &getTypeName() const { return TypeName; } + + static bool classof(const Type *T) { return T->getKind() == TypeKind::Float; } +}; +class PointerType : public Type { +private: + std::unique_ptr PointeeType; + bool IsConst; + bool IsVolatile; + +public: + PointerType(std::unique_ptr Pointee, uint64_t Size, uint64_t Align, + bool Const = false, bool Volatile = false) + : Type(TypeKind::Pointer, Size, Align), PointeeType(std::move(Pointee)), +IsConst(Const), IsVolatile(Volatile) {} + + const Type *getPointeeType() const { return PointeeType.get(); } + bool isConst() const { return IsConst; } + bool isVolatile() const { return IsVolatile; } + + static bool classof(const Type *T) { +return T->getKind() == TypeKind::Pointer; + } +}; + +} // namespace abi +} // namespace llvm + +#endif >From 0858b1f327c7a49c2e2825124a8d5cabbd8654fd Mon Sep 17 00:00:00 2001 From: Narayan Sreekumar Date: Fri, 23 May 2025 17:53:53 +0530 Subject: [PATCH 2/6] [LLVMABI] API for Creating types --- llvm/include/llvm/ABI/Types.h | 244 +- 1 file changed, 213 insertions(+), 31 deletions(-) diff --git a/llvm/include/llvm/ABI/Types.h b/llvm/include/llvm/ABI/Types.h index 443a6c1eab4e7..84cb586832dbd 100644 --- a/llvm/include/llvm/ABI/Types.h +++ b/llvm/include/llvm/ABI/Types.h @@ -1,9 +1,9 @@ #ifndef LLVM_ABI_TYPES_H #define LLVM_ABI_TYPES_H +#include "llvm/ADT/ArrayRef.h" +#include "llvm/Support/Allocator.h" #include -#include -#include namespace llvm { namespace abi { @@ -19,6 +19,7 @@ enum class TypeKind { Union, Function }; + class Type { protected: TypeKind Kind; @@ -31,8 +32,6 @@ class Type { IsExplicitlyAligned(ExplicitAli
[clang] [clang][python][test] Check if libclang.so is loadable (PR #142353)
rorth wrote: > and couldn't find much on it either, but that sounds like > > > Alternatively, as I suggested, one could wrap the actual python -m unittest > > discover invocation with a check if libclang.so is loadable at all, only > > then running the actual test. Indeed: one should move the test directory to (say) `clang/test/bindings/python` and add a script using the proper `lit` syntax. See e.g. `llvm/utils/lit/tests/*.py`. This way one can use the full set of `XFAIL:` etc. directives and automatically gets the expected output. This way one wouldn't even have to write the necessary `lit.*` scripts: it's all handled by the preexisting `clang` test framework. > is pretty much the way to go here: wrap the `unittest` call in an additional > script that adapts the exit code and output format to what is used by the > other tests, and then also add additional platform checks into that script. > > You mentioned the problem of checking loadability at cmake time, but is this > really necessary? Such a wrapper script could still parse the failure > exceptions and emit an `XFAIL` at run time if `wrong ELF class: ELFCLASS32` > is encountered. But also, wouldn't you be able to check this at cmake time > just by probing if we are on a 64bit system that's building 32bit? Not at all: I just mentioned that attempt to describe why something along the lines of `RUN_PYTHON_TESTS` cannot be used here. It would even be easier (as I described) to just run a minimal script as described above first and only if that works run the actual tests. I'm pretty certain that it's way more reliable to just try loading `libclang.so` and react to failures, rather than trying to deduce the situation indirectly. This is quite similar to software that tries to reason if some filesystem access is possible rather than just trying it and let the kernel do its work (accept or reject the request). As in that case, there are so many factors that could affect this (like using a 32-bit `python` even on a 64-bit system) that would render all guesswork moot. https://github.com/llvm/llvm-project/pull/142353 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][python][test] Check if libclang.so is loadable (PR #142353)
rorth wrote: > @rorth Now that #142371 is merged, can you re-evaluate this PR and update the > description? This PR changed the output from completely silent to excessively verbose: I now get ``` FAILED: tools/clang/bindings/python/tests/CMakeFiles/check-clang-python /var/llvm/local-i386-release-stage2-A-openmp/tools/clang/stage2-bins/tools/clang/bindings/python/tests/CMakeFiles/check-clang-python cd /vol/llvm/src/llvm-project/local/clang/bindings/python && /usr/bin/cmake -E env CLANG_NO_DEFAULT_CONFIG=1 CLANG_LIBRARY_PATH=/var/llvm/local-i386-release-stage2-A-openmp/tools/clang/stage2-bins/lib /usr/bin/python3.11 -m unittest discover EEE.E.E..EE.EE... == ERROR: test_access_specifiers (tests.cindex.test_access_specifiers.TestAccessSpecifiers.test_access_specifiers) Ensure that C++ access specifiers are available on cursors -- Traceback (most recent call last): File "/vol/llvm/src/llvm-project/local/clang/bindings/python/clang/cindex.py", line 4371, in get_cindex_library library = cdll.LoadLibrary(self.get_filename()) ^ File "/usr/lib/python3.11/ctypes/__init__.py", line 454, in LoadLibrary return self._dlltype(name) ^^^ File "/usr/lib/python3.11/ctypes/__init__.py", line 376, in __init__ self._handle = _dlopen(self._name, mode) ^ OSError: ld.so.1: python3.11: /var/llvm/local-i386-release-stage2-A-openmp/tools/clang/stage2-bins/lib/libclang.so: wrong ELF class: ELFCLASS32 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/vol/llvm/src/llvm-project/local/clang/bindings/python/tests/cindex/test_access_specifiers.py", line 17, in test_access_specifiers tu = get_tu( ^^^ File "/vol/llvm/src/llvm-project/local/clang/bindings/python/tests/cindex/util.py", line 30, in get_tu return TranslationUnit.from_source(name, args, unsaved_files=[(name, source)]) ^^^ File "/vol/llvm/src/llvm-project/local/clang/bindings/python/clang/cindex.py", line 3317, in from_source index = Index.create() ^^ File "/vol/llvm/src/llvm-project/local/clang/bindings/python/clang/cindex.py", line 3189, in create return Index(conf.lib.clang_createIndex(excludeDecls, 0)) File "/vol/llvm/src/llvm-project/local/clang/bindings/python/clang/cindex.py", line 250, in __get__ value = self.wrapped(instance) ^^ File "/vol/llvm/src/llvm-project/local/clang/bindings/python/clang/cindex.py", line 4343, in lib lib = self.get_cindex_library() ^ File "/vol/llvm/src/llvm-project/local/clang/bindings/python/clang/cindex.py", line 4378, in get_cindex_library raise LibclangError(msg) clang.cindex.LibclangError: ld.so.1: python3.11: /var/llvm/local-i386-release-stage2-A-openmp/tools/clang/stage2-bins/lib/libclang.so: wrong ELF class: ELFCLASS32. To provide a path to libclang use Config.set_library_path() or Config.set_library_file(). ``` 158 times total. While one can see what's going on, there's no way to avoid the issue. https://github.com/llvm/llvm-project/pull/142353 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [WIP] ABI Lowering Library (PR #140112)
@@ -136,9 +136,69 @@ const llvm::abi::Type *QualTypeMapper::convertRecordType(const RecordType *RT) { if (RD->isUnion()) return convertUnionType(RD); + + // Handle C++ classes with base classes + auto *const CXXRd = dyn_cast(RD); + if (CXXRd && (CXXRd->getNumBases() > 0 || CXXRd->getNumVBases() > 0)) { +return convertCXXRecordType(CXXRd); + } return convertStructType(RD); } +const llvm::abi::StructType * +QualTypeMapper::convertCXXRecordType(const CXXRecordDecl *RD) { + const ASTRecordLayout &Layout = ASTCtx.getASTRecordLayout(RD); + SmallVector Fields; + + if (RD->isPolymorphic()) { +const llvm::abi::Type *VtablePointer = +createPointerTypeForPointee(ASTCtx.VoidPtrTy); +Fields.emplace_back(VtablePointer, 0); + } + + for (const auto &Base : RD->bases()) { +if (Base.isVirtual()) nikic wrote: I think bases() is always non-virtual? vbases() would be virtual. https://github.com/llvm/llvm-project/pull/140112 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [WIP] ABI Lowering Library (PR #140112)
@@ -136,9 +136,69 @@ const llvm::abi::Type *QualTypeMapper::convertRecordType(const RecordType *RT) { if (RD->isUnion()) return convertUnionType(RD); + + // Handle C++ classes with base classes + auto *const CXXRd = dyn_cast(RD); + if (CXXRd && (CXXRd->getNumBases() > 0 || CXXRd->getNumVBases() > 0)) { +return convertCXXRecordType(CXXRd); + } return convertStructType(RD); } +const llvm::abi::StructType * +QualTypeMapper::convertCXXRecordType(const CXXRecordDecl *RD) { + const ASTRecordLayout &Layout = ASTCtx.getASTRecordLayout(RD); + SmallVector Fields; + + if (RD->isPolymorphic()) { +const llvm::abi::Type *VtablePointer = +createPointerTypeForPointee(ASTCtx.VoidPtrTy); +Fields.emplace_back(VtablePointer, 0); + } + + for (const auto &Base : RD->bases()) { +if (Base.isVirtual()) + continue; + +const RecordType *BaseRT = Base.getType()->getAs(); +if (!BaseRT) nikic wrote: I don't think this can fail. Assert instead? https://github.com/llvm/llvm-project/pull/140112 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C2y] Handle FP-suffixes on prefixed octals (#141230) (PR #141695)
naveen-seth wrote: Ping https://github.com/llvm/llvm-project/pull/141695 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [WIP] ABI Lowering Library (PR #140112)
@@ -136,9 +136,69 @@ const llvm::abi::Type *QualTypeMapper::convertRecordType(const RecordType *RT) { if (RD->isUnion()) return convertUnionType(RD); + + // Handle C++ classes with base classes + auto *const CXXRd = dyn_cast(RD); + if (CXXRd && (CXXRd->getNumBases() > 0 || CXXRd->getNumVBases() > 0)) { +return convertCXXRecordType(CXXRd); + } return convertStructType(RD); } +const llvm::abi::StructType * +QualTypeMapper::convertCXXRecordType(const CXXRecordDecl *RD) { + const ASTRecordLayout &Layout = ASTCtx.getASTRecordLayout(RD); + SmallVector Fields; + + if (RD->isPolymorphic()) { +const llvm::abi::Type *VtablePointer = +createPointerTypeForPointee(ASTCtx.VoidPtrTy); +Fields.emplace_back(VtablePointer, 0); + } + + for (const auto &Base : RD->bases()) { +if (Base.isVirtual()) vortex73 wrote: I saw that [here](https://github.com/llvm/llvm-project/blob/8ed3cb0e6497944ac7284e88379051b768a426cd/clang/lib/CodeGen/CodeGenTypes.cpp#L812) and emulated that just to be safe. https://github.com/llvm/llvm-project/pull/140112 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [SimplifyCFG] Extend jump-threading to allow live local defs (PR #135079)
LU-JOHN wrote: @dtcxzyw can you please review? Thanks. https://github.com/llvm/llvm-project/pull/135079 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][performance-unnecessary-value-param] Avoid in coroutines (PR #140912)
dmpolukhin wrote: @HerrCai0907 @carlosgalvezp @PiotrZSL one more friendly ping. Please take a look, the change is benign and trivial one liner + test. I think it will really improve this check and avoid long hours for developers to figure out dangling references. https://github.com/llvm/llvm-project/pull/140912 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Ast importer visitors (PR #138838)
https://github.com/ganenkokb-yandex updated https://github.com/llvm/llvm-project/pull/138838 >From 0a5beb71cb46ad5ef2df753098a6742ffeef3a71 Mon Sep 17 00:00:00 2001 From: Evianaive <153540...@qq.com> Date: Tue, 25 Mar 2025 01:54:06 +0800 Subject: [PATCH 1/5] Implement missing visit function --- clang/lib/AST/ASTImporter.cpp | 285 +- 1 file changed, 284 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index 003bad225e30c..775e9b83d1fb1 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -68,6 +68,7 @@ #include #include #include +#include "ExprConcepts.h" namespace clang { @@ -564,6 +565,9 @@ namespace clang { ExpectedDecl VisitVarTemplateDecl(VarTemplateDecl *D); ExpectedDecl VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); ExpectedDecl VisitFunctionTemplateDecl(FunctionTemplateDecl *D); +ExpectedDecl VisitConceptDecl(ConceptDecl* D); +ExpectedDecl VisitRequiresExprBodyDecl(RequiresExprBodyDecl* E); +ExpectedDecl VisitImplicitConceptSpecializationDecl(ImplicitConceptSpecializationDecl* D); // Importing statements ExpectedStmt VisitStmt(Stmt *S); @@ -680,6 +684,8 @@ namespace clang { ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E); ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E); ExpectedStmt VisitCXXFoldExpr(CXXFoldExpr *E); +ExpectedStmt VisitRequiresExpr(RequiresExpr* E); +ExpectedStmt VisitConceptSpecializationExpr(ConceptSpecializationExpr* E); // Helper for chaining together multiple imports. If an error is detected, // subsequent imports will return default constructed nodes, so that failure @@ -1063,6 +1069,168 @@ Expected ASTNodeImporter::import(const LambdaCapture &From) { EllipsisLoc); } +template<> +Expected ASTNodeImporter::import(concepts::Requirement* FromRequire) { + auto ImportStringRef = [this](const StringRef& FromString) { + char* ToDiagMessage = new (Importer.getToContext()) char[FromString.size()]; + std::copy(FromString.begin(),FromString.end(),ToDiagMessage); + return StringRef(ToDiagMessage,FromString.size()); +}; + + auto ImportSubstitutionDiagnos = [this, &ImportStringRef] + (concepts::Requirement::SubstitutionDiagnostic* FromDiagnos, Error& Err)->concepts::Requirement::SubstitutionDiagnostic* { +const auto& ToEntity = ImportStringRef(FromDiagnos->SubstitutedEntity); +Expected ToLoc = import(FromDiagnos->DiagLoc); +if(!ToLoc) { + Err = ToLoc.takeError(); + return nullptr; +} +const auto& ToDiagMessage = ImportStringRef(FromDiagnos->DiagMessage); +return new (Importer.getToContext()) concepts::Requirement::SubstitutionDiagnostic{ + ToEntity, + ToLoc.get(), + ToDiagMessage}; + }; + switch (FromRequire->getKind()) { + case concepts::Requirement::RequirementKind::RK_Type: { +auto *From = cast(FromRequire); +if(From->isSubstitutionFailure()) +{ + // Should we return Error directly if TypeRequirement isSubstitutionFailure? + Error Err = Error::success(); + auto Diagnos = ImportSubstitutionDiagnos(From->getSubstitutionDiagnostic(),Err); + if (Err) +return std::move(Err); + return new (Importer.getToContext()) concepts::TypeRequirement(Diagnos); +} +else { + Expected ToType = import(From->getType()); + if(!ToType) +return ToType.takeError(); + return new (Importer.getToContext()) concepts::TypeRequirement(ToType.get()); +} +break; + } + case concepts::Requirement::RequirementKind::RK_Compound: + case concepts::Requirement::RequirementKind::RK_Simple: { +const auto *From = cast(FromRequire); + +auto Status = From->getSatisfactionStatus(); +llvm::PointerUnion E; +if (Status == concepts::ExprRequirement::SS_ExprSubstitutionFailure) { + Error Err = Error::success(); + E = ImportSubstitutionDiagnos(From->getExprSubstitutionDiagnostic(),Err); + if (Err) +return std::move(Err); +} else { + auto ExpectE = import(From->getExpr()); + if (!ExpectE) +return ExpectE.takeError(); + E = ExpectE.get(); +} + +std::optional Req; +ConceptSpecializationExpr *SubstitutedConstraintExpr = nullptr; +SourceLocation NoexceptLoc; +bool IsRKSimple = FromRequire->getKind() == concepts::Requirement::RK_Simple; +if (IsRKSimple) { + Req.emplace(); +} else { + auto NoexceptLoc = import(From->getNoexceptLoc()); + if(!NoexceptLoc) +return NoexceptLoc.takeError(); + auto& FromTypeRequirement = From->getReturnTypeRequirement(); + + if(FromTypeRequirement.isTypeConstraint()) { +auto ParamsOrErr = import(FromTypeRequirement.getTypeConstraintTemplateParameterList()); +if (!ParamsOrErr) + return ParamsOrErr.takeError(); +if (Status >= + concept
[clang] [llvm] [WIP] ABI Lowering Library (PR #140112)
@@ -136,9 +136,69 @@ const llvm::abi::Type *QualTypeMapper::convertRecordType(const RecordType *RT) { if (RD->isUnion()) return convertUnionType(RD); + + // Handle C++ classes with base classes + auto *const CXXRd = dyn_cast(RD); + if (CXXRd && (CXXRd->getNumBases() > 0 || CXXRd->getNumVBases() > 0)) { +return convertCXXRecordType(CXXRd); + } return convertStructType(RD); } +const llvm::abi::StructType * +QualTypeMapper::convertCXXRecordType(const CXXRecordDecl *RD) { + const ASTRecordLayout &Layout = ASTCtx.getASTRecordLayout(RD); + SmallVector Fields; + + if (RD->isPolymorphic()) { +const llvm::abi::Type *VtablePointer = +createPointerTypeForPointee(ASTCtx.VoidPtrTy); +Fields.emplace_back(VtablePointer, 0); + } + + for (const auto &Base : RD->bases()) { +if (Base.isVirtual()) nikic wrote: Yeah, you are right. It looks like bases() also includes virtual bases. https://github.com/llvm/llvm-project/pull/140112 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Introduce cir::RecordKind::Class (PR #142690)
https://github.com/erichkeane approved this pull request. https://github.com/llvm/llvm-project/pull/142690 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Add check 'cppcoreguidelines-use-enum-class' (PR #138282)
@@ -0,0 +1,35 @@ +.. title:: clang-tidy - cppcoreguidelines-use-enum-class + +cppcoreguidelines-use-enum-class + + +Finds unscoped (non-class) ``enum`` declarations and suggests using +``enum class`` instead. + +This check implements `Enum.3 vbvictor wrote: Should it? I've seen that most of cppcoreguidelines checks have this in the beginning. I suppose it's encouraging user to read actual guidline before reading check documentation. Some random examples I clicked right now: https://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/avoid-capturing-lambda-coroutines.html https://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/avoid-do-while.html https://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/interfaces-global-init.html https://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/pro-bounds-constant-array-index.html https://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.html https://github.com/llvm/llvm-project/pull/138282 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits