[clang] cc1: Report an error for multiple actions unless separated by -main-file-name (PR #91140)
@@ -2841,6 +2841,30 @@ static bool ParseFrontendArgs(FrontendOptions , ArgList , } Opts.ProgramAction = *ProgramAction; + +// Catch common mistakes when multiple actions are specified for cc1 (e.g. +// -S -emit-llvm means -emit-llvm while -emit-llvm -S means -S). However, to +// support driver `-c -Xclang ACTION` (-cc1 -emit-llvm file -main-file-name +// X ACTION), we suppress the error when the two actions are separated by +// -main-file-name. +// +// As an exception, accept composable -ast-dump*. +if (!A->getSpelling().starts_with("-ast-dump")) { jansvoboda11 wrote: Any reason why use string-based prefix instead of checking for the `OPT_` enums? https://github.com/llvm/llvm-project/pull/91140 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Teach .option arch to support experimental extensions. (PR #89727)
https://github.com/yetingk closed https://github.com/llvm/llvm-project/pull/89727 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] d70267f - [RISCV] Teach .option arch to support experimental extensions. (#89727)
Author: Yeting Kuo Date: 2024-05-06T13:55:37+08:00 New Revision: d70267fbae228990c47b5bdbce7aa659e8b5146e URL: https://github.com/llvm/llvm-project/commit/d70267fbae228990c47b5bdbce7aa659e8b5146e DIFF: https://github.com/llvm/llvm-project/commit/d70267fbae228990c47b5bdbce7aa659e8b5146e.diff LOG: [RISCV] Teach .option arch to support experimental extensions. (#89727) Previously `.option arch` denied extenions are not belongs to RISC-V features. But experimental features have experimental- prefix, so `.option arch` can not serve for experimental extension. This patch uses the features of extensions to identify extension existance. Added: clang/test/Driver/riscv-option-arch.c clang/test/Driver/riscv-option-arch.s Modified: llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp llvm/test/MC/RISCV/option-arch.s Removed: diff --git a/clang/test/Driver/riscv-option-arch.c b/clang/test/Driver/riscv-option-arch.c new file mode 100644 index 00..e583e9fd62b08c --- /dev/null +++ b/clang/test/Driver/riscv-option-arch.c @@ -0,0 +1,7 @@ +// RUN: %clang --target=riscv64 -menable-experimental-extensions -c -o /dev/null %s +// RUN: ! %clang --target=riscv64 -c -o /dev/null %s 2>&1 | FileCheck -check-prefixes=CHECK-ERR %s + +void foo() { + asm volatile (".option arch, +zicfiss"); + // CHECK-ERR: Unexpected experimental extensions. +} diff --git a/clang/test/Driver/riscv-option-arch.s b/clang/test/Driver/riscv-option-arch.s new file mode 100644 index 00..8ce84dd8ffe79d --- /dev/null +++ b/clang/test/Driver/riscv-option-arch.s @@ -0,0 +1,5 @@ +# RUN: %clang --target=riscv64 -menable-experimental-extensions -c -o /dev/null %s +# RUN: ! %clang --target=riscv64 -c -o /dev/null %s 2>&1 | FileCheck -check-prefixes=CHECK-ERR %s + +.option arch, +zicfiss +# CHECK-ERR: Unexpected experimental extensions. diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp index 8ac79ddce595e0..6af1d5010d3a47 100644 --- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp +++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp @@ -84,6 +84,9 @@ class RISCVAsmParser : public MCTargetAsmParser { SMLoc getLoc() const { return getParser().getTok().getLoc(); } bool isRV64() const { return getSTI().hasFeature(RISCV::Feature64Bit); } bool isRVE() const { return getSTI().hasFeature(RISCV::FeatureStdExtE); } + bool enableExperimentalExtension() const { +return getSTI().hasFeature(RISCV::Experimental); + } RISCVTargetStreamer () { assert(getParser().getStreamer().getTargetStreamer() && @@ -2824,17 +2827,19 @@ bool RISCVAsmParser::parseDirectiveOption() { break; } - auto Ext = llvm::lower_bound(RISCVFeatureKV, Arch); - if (Ext == std::end(RISCVFeatureKV) || StringRef(Ext->Key) != Arch || - !RISCVISAInfo::isSupportedExtension(Arch)) { -if (isDigit(Arch.back())) - return Error( - Loc, - "Extension version number parsing not currently implemented"); + if (isDigit(Arch.back())) +return Error( +Loc, "Extension version number parsing not currently implemented"); + + std::string Feature = RISCVISAInfo::getTargetFeatureForExtension(Arch); + if (!enableExperimentalExtension() && + StringRef(Feature).starts_with("experimental-")) +return Error(Loc, "Unexpected experimental extensions."); + auto Ext = llvm::lower_bound(RISCVFeatureKV, Feature); + if (Ext == std::end(RISCVFeatureKV) || StringRef(Ext->Key) != Feature) return Error(Loc, "unknown extension feature"); - } - Args.emplace_back(Type, Ext->Key); + Args.emplace_back(Type, Arch.str()); if (Type == RISCVOptionArchArgType::Plus) { FeatureBitset OldFeatureBits = STI->getFeatureBits(); diff --git a/llvm/test/MC/RISCV/option-arch.s b/llvm/test/MC/RISCV/option-arch.s index 6ee133c7159a27..7826252f66e6c8 100644 --- a/llvm/test/MC/RISCV/option-arch.s +++ b/llvm/test/MC/RISCV/option-arch.s @@ -1,7 +1,7 @@ -# RUN: llvm-mc -triple riscv32 -show-encoding < %s \ +# RUN: llvm-mc -triple riscv32 -mattr=+experimental -show-encoding < %s \ # RUN: | FileCheck -check-prefixes=CHECK %s -# RUN: llvm-mc -triple riscv32 -filetype=obj < %s \ -# RUN: | llvm-objdump --triple=riscv32 --mattr=+c,+m,+a,+f,+zba -d -M no-aliases - \ +# RUN: llvm-mc -triple riscv32 -mattr=+experimental -filetype=obj < %s \ +# RUN: | llvm-objdump --triple=riscv32 --mattr=+c,+m,+a,+f,+zba,+experimental-zicfiss -d -M no-aliases - \ # RUN: | FileCheck -check-prefixes=CHECK-INST %s # Test '.option arch, +' and '.option arch, -' directive @@ -78,6 +78,13 @@ lr.w t0, (t1) # CHECK: encoding: [0xb3,0x22,0x73,0x20] sh1add t0, t1, t2 +# Test experimental extension +# CHECK: .option arch, +zicfiss +.option arch, +zicfiss +#
[clang] [llvm] [AMDGPU][WIP] Extend readlane, writelane and readfirstlane intrinsic lowering for generic types (PR #89217)
https://github.com/vikramRH edited https://github.com/llvm/llvm-project/pull/89217 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AMDGPU][WIP] Add support for i64/f64 readlane, writelane and readfirstlane operations. (PR #89217)
vikramRH wrote: 1. Review comments 2. improve GIsel lowering 3. add tests for half, bfloat, float2, ptr, vector of ptr and int 4. removed gfx700 checks from writelane test since it caused issues with f16 legalization. is this required ? https://github.com/llvm/llvm-project/pull/89217 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Modules] No transitive source location change (PR #86912)
ChuanqiXu9 wrote: I've relanded this in https://github.com/llvm/llvm-project/commit/947b06282324db8fe2784c4054af9de493a876af. Let's see what happens. https://github.com/llvm/llvm-project/pull/86912 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 947b062 - Reland "[Modules] No transitive source location change (#86912)"
Author: Chuanqi Xu Date: 2024-05-06T13:35:16+08:00 New Revision: 947b06282324db8fe2784c4054af9de493a876af URL: https://github.com/llvm/llvm-project/commit/947b06282324db8fe2784c4054af9de493a876af DIFF: https://github.com/llvm/llvm-project/commit/947b06282324db8fe2784c4054af9de493a876af.diff LOG: Reland "[Modules] No transitive source location change (#86912)" This relands 6c31104. The patch was reverted due to incorrectly introduced alignment. And the patch was re-commited after fixing the alignment issue. Following off are the original message: This is part of "no transitive change" patch series, "no transitive source location change". I talked this with @Bigcheese in the tokyo's WG21 meeting. The idea comes from @jyknight posted on LLVM discourse. That for: ``` // A.cppm export module A; ... // B.cppm export module B; import A; ... //--- C.cppm export module C; import C; ``` Almost every time A.cppm changes, we need to recompile `B`. Due to we think the source location is significant to the semantics. But it may be good if we can avoid recompiling `C` if the change from `A` wouldn't change the BMI of B. This patch only cares source locations. So let's focus on source location's example. We can see the full example from the attached test. ``` //--- A.cppm export module A; export template struct C { T func() { return T(43); } }; export int funcA() { return 43; } //--- A.v1.cppm export module A; export template struct C { T func() { return T(43); } }; export int funcA() { return 43; } //--- B.cppm export module B; import A; export int funcB() { return funcA(); } //--- C.cppm export module C; import A; export void testD() { C c; c.func(); } ``` Here the only difference between `A.cppm` and `A.v1.cppm` is that `A.v1.cppm` has an additional blank line. Then the test shows that two BMI of `B.cppm`, one specified `-fmodule-file=A=A.pcm` and the other specified `-fmodule-file=A=A.v1.pcm`, should have the bit-wise same contents. However, it is a different story for C, since C instantiates templates from A, and the instantiation records the source information from module A, which is different from `A` and `A.v1`, so it is expected that the BMI `C.pcm` and `C.v1.pcm` can and should differ. To fully understand the patch, we need to understand how we encodes source locations and how we serialize and deserialize them. For source locations, we encoded them as: ``` | | | _ base offset of an imported module | | | |_ base offset of another imported module | | | | | ___ 0 ``` As the diagram shows, we encode the local (unloaded) source location from 0 to higher bits. And we allocate the space for source locations from the loaded modules from high bits to 0. Then the source locations from the loaded modules will be mapped to our source location space according to the allocated offset. For example, for, ``` // a.cppm export module a; ... // b.cppm export module b; import a; ... ``` Assuming the offset of a source location (let's name the location as `S`) in a.cppm is 45 and we will record the value `45` into the BMI `a.pcm`. Then in b.cppm, when we import a, the source manager will allocate a space for module 'a' (according to the recorded number of source locations) as the base offset of module 'a' in the current source location spaces. Let's assume the allocated base offset as 90 in this example. Then when we want to get the location in the current source location space for `S`, we can get it simply by adding `45` to `90` to `135`. Finally we can get the source location for `S` in module B as `135`. And when we want to write module `b`, we would also write the source location of `S` as `135` directly in the BMI. And to clarify the location `S` comes from module `a`, we also need to record the base offset of module `a`, 90 in the BMI of `b`. Then the problem comes. Since the base offset of module 'a' is computed by the number source locations in module 'a'. In module 'b', the recorded base offset of module 'a' will change every time the number of source locations in module 'a' increase or decrease. In other words, the contents of BMI of B will change every time the number of locations in module 'a' changes. This is pretty sensitive. Almost every change will change the number of locations. So this is the problem this patch want to solve. Let's continue with the existing design to understand what's going on. Another interesting case is: ``` // c.cppm export module c; import whatever; import a; import b; ... ``` In `c.cppm`, when we import `a`, we still need to allocate a base location offset for it, let's say the value becomes to `200` somehow. Then when we reach the location `S` recorded in module `b`, we need to translate it into the current source location space. The solution is quite simple, we can get it by `135 + (200 - 90) = 245`. In another word, the offset of a source location in current module can be computed as
[clang] [llvm] [AMDGPU] Add amdgpu-as MMRA for fences (PR #78572)
@@ -18365,6 +18366,28 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID, return nullptr; } +void CodeGenFunction::AddAMDGCNFenceAddressSpaceMMRA(llvm::Instruction *Inst, + const CallExpr *E) { + constexpr const char *Tag = "amdgpu-as"; ssahasra wrote: Just bikeshedding a bit, but do we really need the "amdgpu" prefix on the tag? Clang will only generate these for AMDGPU anyway. It's not a blocker, but feels like we are being cautious for no reason. https://github.com/llvm/llvm-project/pull/78572 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] cc1: Report an error for multiple actions unless separated by -main-file-name (PR #91140)
https://github.com/ChuanqiXu9 approved this pull request. LGTM. https://github.com/llvm/llvm-project/pull/91140 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][driver] Support `-x` for all languages in CL mode (PR #89772)
https://github.com/ChuanqiXu9 commented: It may be better to add a test with `-x c++-module` within CL mode. https://github.com/llvm/llvm-project/pull/89772 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Don't remove parentheses of fold expressions (PR #91045)
llvmbot wrote: /pull-request llvm/llvm-project#91165 https://github.com/llvm/llvm-project/pull/91045 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AMDGPU] Add amdgpu-as MMRA for fences (PR #78572)
@@ -678,6 +679,59 @@ class SIMemoryLegalizer final : public MachineFunctionPass { bool runOnMachineFunction(MachineFunction ) override; }; +static std::array, 3> ASNames = {{ +{"global", SIAtomicAddrSpace::GLOBAL}, +{"local", SIAtomicAddrSpace::LDS}, +{"image", SIAtomicAddrSpace::SCRATCH}, +}}; + +void diagnoseUnknownMMRAASName(const MachineInstr , StringRef AS) { + const MachineFunction *MF = MI.getMF(); + const Function = MF->getFunction(); + std::string Str; + raw_string_ostream OS(Str); + OS << "unknown address space '" << AS << "'; expected one of "; + bool IsFirst = true; ssahasra wrote: Use ListSeparator from StringExtras.h https://github.com/llvm/llvm-project/pull/78572 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AMDGPU] Add amdgpu-as MMRA for fences (PR #78572)
@@ -18365,6 +18366,28 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID, return nullptr; } +void CodeGenFunction::AddAMDGCNFenceAddressSpaceMMRA(llvm::Instruction *Inst, ssahasra wrote: The function immediately below this uses "AMDGPU" in its name. I think that's the newer practice. I don't have a strong opinion on this, because the same file also has functions which say "AMDGCN" instead. I am not sure which way the naming convention is leaning. https://github.com/llvm/llvm-project/pull/78572 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AMDGPU] Add amdgpu-as MMRA for fences (PR #78572)
https://github.com/ssahasra edited https://github.com/llvm/llvm-project/pull/78572 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AMDGPU] Add amdgpu-as MMRA for fences (PR #78572)
@@ -4408,6 +4409,42 @@ Target-Specific Extensions Clang supports some language features conditionally on some targets. +AMDGPU Language Extensions +-- + +__builtin_amdgcn_fence +^^ + +``__builtin_amdgcn_fence`` emits a fence. + +* ``unsigned`` atomic ordering, e.g. ``__ATOMIC_ACQUIRE`` +* ``const char *`` synchronization scope, e.g. ``workgroup`` +* Zero or more ``const char *`` address spaces names. + +The address spaces arguments must be string literals with known values, such as: + +* ``"local"`` +* ``"global"`` +* ``"image"`` + +If one or more address space name are provided, the code generator will attempt +to emit potentially faster instructions that only fence those address spaces. ssahasra wrote: This use of "fence" as a verb seems a bit too informal. Reword it to say "instructions that order access to at least those address spaces"? (Note the addition of "at least" to signify a lower bound) https://github.com/llvm/llvm-project/pull/78572 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AMDGPU] Add amdgpu-as MMRA for fences (PR #78572)
https://github.com/ssahasra approved this pull request. The frontend changes and the MMRA emitted in LLVM IR look good to me. The backend changes also look okay, but please see if anyone else has comments about that. https://github.com/llvm/llvm-project/pull/78572 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Don't remove parentheses of fold expressions (PR #91045)
owenca wrote: /cherry-pick db0ed5533368 https://github.com/llvm/llvm-project/pull/91045 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Don't remove parentheses of fold expressions (PR #91045)
https://github.com/owenca milestoned https://github.com/llvm/llvm-project/pull/91045 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Don't remove parentheses of fold expressions (PR #91045)
https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/91045 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] db0ed55 - [clang-format] Don't remove parentheses of fold expressions (#91045)
Author: Owen Pan Date: 2024-05-05T21:33:41-07:00 New Revision: db0ed5533368414b1c4e1c884eef651c66359da2 URL: https://github.com/llvm/llvm-project/commit/db0ed5533368414b1c4e1c884eef651c66359da2 DIFF: https://github.com/llvm/llvm-project/commit/db0ed5533368414b1c4e1c884eef651c66359da2.diff LOG: [clang-format] Don't remove parentheses of fold expressions (#91045) Fixes #90966. Added: Modified: clang/lib/Format/UnwrappedLineParser.cpp clang/unittests/Format/FormatTest.cpp Removed: diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index b5415fa9ecab55..f71661d837ec3d 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -2511,6 +2511,7 @@ bool UnwrappedLineParser::parseParens(TokenType AmpAmpTokenType) { assert(FormatTok->is(tok::l_paren) && "'(' expected."); auto *LeftParen = FormatTok; bool SeenEqual = false; + bool MightBeFoldExpr = false; const bool MightBeStmtExpr = Tokens->peekNextToken()->is(tok::l_brace); nextToken(); do { @@ -2522,7 +2523,7 @@ bool UnwrappedLineParser::parseParens(TokenType AmpAmpTokenType) { parseChildBlock(); break; case tok::r_paren: - if (!MightBeStmtExpr && !Line->InMacroBody && + if (!MightBeStmtExpr && !MightBeFoldExpr && !Line->InMacroBody && Style.RemoveParentheses > FormatStyle::RPS_Leave) { const auto *Prev = LeftParen->Previous; const auto *Next = Tokens->peekNextToken(); @@ -2565,6 +2566,10 @@ bool UnwrappedLineParser::parseParens(TokenType AmpAmpTokenType) { parseBracedList(); } break; +case tok::ellipsis: + MightBeFoldExpr = true; + nextToken(); + break; case tok::equal: SeenEqual = true; if (Style.isCSharp() && FormatTok->is(TT_FatArrow)) diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 32ba6b6853c799..e6f8e4a06515ea 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -27204,8 +27204,14 @@ TEST_F(FormatTest, RemoveParentheses) { "if ((({ a; })))\n" " b;", Style); + verifyFormat("static_assert((std::is_constructible_v && ...));", + "static_assert(((std::is_constructible_v && ...)));", + Style); verifyFormat("return (0);", "return (((0)));", Style); verifyFormat("return (({ 0; }));", "return ((({ 0; })));", Style); + verifyFormat("return ((... && std::is_convertible_v));", + "return (((... && std::is_convertible_v)));", + Style); Style.RemoveParentheses = FormatStyle::RPS_ReturnStatement; verifyFormat("#define Return0 return (0);", Style); @@ -27213,6 +27219,9 @@ TEST_F(FormatTest, RemoveParentheses) { verifyFormat("co_return 0;", "co_return ((0));", Style); verifyFormat("return 0;", "return (((0)));", Style); verifyFormat("return ({ 0; });", "return ((({ 0; })));", Style); + verifyFormat("return (... && std::is_convertible_v);", + "return (((... && std::is_convertible_v)));", + Style); verifyFormat("inline decltype(auto) f() {\n" " if (a) {\n" "return (a);\n" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang][hlsl] Add tan intrinsic part 1 (PR #90276)
efriedma-quic wrote: I'm worried if we add a whole new series of math intrinsics without adding the corresponding constrained intrinsics, it's going to be confusing for anyone trying to understand how math intrinsics work. Why does tan exist, but not constrained tan? `tan` is defined basically the same way as `sin` in Builtins.td; the only difference is that instead of `def SinF16F128 : Builtin, F16F128MathTemplate`, there's just `def TanF128 : Builtin {` (so no f16 support). https://github.com/llvm/llvm-project/pull/90276 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [llvm] Add triples for managarm (PR #87845)
brad0 wrote: @MaskRay https://github.com/llvm/llvm-project/pull/87845 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang backend] In AArch64's DataLayout, specify a minimum function alignment of 4. (PR #90702)
@@ -1480,11 +1480,11 @@ AArch64leTargetInfo::AArch64leTargetInfo(const llvm::Triple , void AArch64leTargetInfo::setDataLayout() { if (getTriple().isOSBinFormatMachO()) { if(getTriple().isArch32Bit()) - resetDataLayout("e-m:o-p:32:32-i64:64-i128:128-n32:64-S128", "_"); + resetDataLayout("e-m:o-p:32:32-i64:64-i128:128-n32:64-S128-Fn32", "_"); efriedma-quic wrote: Thumb2 function pointers aren't aligned... but from LLVM's perspective it's a completely different target, so it's not relevant. https://github.com/llvm/llvm-project/pull/90702 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Don't allow comma in front of structural enum (PR #91056)
https://github.com/rymiel closed https://github.com/llvm/llvm-project/pull/91056 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] c609043 - [clang-format] Don't allow comma in front of structural enum (#91056)
Author: Emilia Kond Date: 2024-05-06T06:44:13+03:00 New Revision: c609043dd00955bf177ff57b0bad2a87c1e61a36 URL: https://github.com/llvm/llvm-project/commit/c609043dd00955bf177ff57b0bad2a87c1e61a36 DIFF: https://github.com/llvm/llvm-project/commit/c609043dd00955bf177ff57b0bad2a87c1e61a36.diff LOG: [clang-format] Don't allow comma in front of structural enum (#91056) Assume that a comma in front of `enum` means it is actually a part of an elaborated type in a template parameter list. Fixes https://github.com/llvm/llvm-project/issues/47782 Added: Modified: clang/lib/Format/UnwrappedLineParser.cpp clang/unittests/Format/TokenAnnotatorTest.cpp Removed: diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index e8a8dd58d07eea..b5415fa9ecab55 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -1763,8 +1763,9 @@ void UnwrappedLineParser::parseStructuralElement( break; } case tok::kw_enum: - // Ignore if this is part of "template enum". - if (Previous && Previous->isOneOf(tok::less, tok::arrow)) { + // Ignore if this is part of "template enum" or + // "template <..., enum ...>". + if (Previous && Previous->isOneOf(tok::less, tok::arrow, tok::comma)) { nextToken(); break; } diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 01daf8dee505bc..b424424b85777b 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -489,6 +489,10 @@ TEST_F(TokenAnnotatorTest, UnderstandsStructs) { EXPECT_TOKEN(Tokens[24], tok::amp, TT_UnaryOperator); EXPECT_TOKEN(Tokens[27], tok::l_square, TT_ArraySubscriptLSquare); EXPECT_TOKEN(Tokens[32], tok::r_brace, TT_StructRBrace); + + Tokens = annotate("template struct S {};"); + ASSERT_EQ(Tokens.size(), 15u) << Tokens; + EXPECT_TOKEN(Tokens[11], tok::l_brace, TT_StructLBrace); } TEST_F(TokenAnnotatorTest, UnderstandsUnions) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [NFC][clang-tidy]increase stability for bugprone-return-const-ref-from-parameter (PR #91160)
llvmbot wrote: @llvm/pr-subscribers-clang-tools-extra @llvm/pr-subscribers-clang-tidy Author: Congcong Cai (HerrCai0907) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/91160.diff 1 Files Affected: - (modified) clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp (+6-3) ``diff diff --git a/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp index b3f7dd6d1c86f8..cacba38b4a5aa8 100644 --- a/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp @@ -29,10 +29,13 @@ void ReturnConstRefFromParameterCheck::registerMatchers(MatchFinder *Finder) { void ReturnConstRefFromParameterCheck::check( const MatchFinder::MatchResult ) { const auto *R = Result.Nodes.getNodeAs("ret"); - diag(R->getRetValue()->getBeginLoc(), - "returning a constant reference parameter may cause a use-after-free " + const SourceRange Range = R->getRetValue()->getSourceRange(); + if (Range.isInvalid()) +return; + diag(Range.getBegin(), + "returning a constant reference parameter may cause use-after-free " "when the parameter is constructed from a temporary") - << R->getRetValue()->getSourceRange(); + << Range; } } // namespace clang::tidy::bugprone `` https://github.com/llvm/llvm-project/pull/91160 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [NFC][clang-tidy]increase stability for bugprone-return-const-ref-from-parameter (PR #91160)
https://github.com/HerrCai0907 created https://github.com/llvm/llvm-project/pull/91160 None >From 8ba443f10a0fa65c319e5149a289d65f89a94d26 Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Mon, 6 May 2024 10:58:23 +0800 Subject: [PATCH] [NFC][clang-tidy]increase stability for bugprone-return-const-ref-from-parameter --- .../bugprone/ReturnConstRefFromParameterCheck.cpp| 9 ++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp index b3f7dd6d1c86f8..cacba38b4a5aa8 100644 --- a/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp @@ -29,10 +29,13 @@ void ReturnConstRefFromParameterCheck::registerMatchers(MatchFinder *Finder) { void ReturnConstRefFromParameterCheck::check( const MatchFinder::MatchResult ) { const auto *R = Result.Nodes.getNodeAs("ret"); - diag(R->getRetValue()->getBeginLoc(), - "returning a constant reference parameter may cause a use-after-free " + const SourceRange Range = R->getRetValue()->getSourceRange(); + if (Range.isInvalid()) +return; + diag(Range.getBegin(), + "returning a constant reference parameter may cause use-after-free " "when the parameter is constructed from a temporary") - << R->getRetValue()->getSourceRange(); + << Range; } } // namespace clang::tidy::bugprone ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Reland "[Win32][ELF] Make CodeView a DebugInfoFormat only for COFF format", second try (PR #88245)
https://github.com/phoebewang reopened https://github.com/llvm/llvm-project/pull/88245 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang backend] In AArch64's DataLayout, specify a minimum function alignment of 4. (PR #90702)
llvmbot wrote: >/cherry-pick ddecadabebdd4b301bd65534b58009e57ac1bbe5 Error: Command failed due to missing milestone. https://github.com/llvm/llvm-project/pull/90702 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang backend] In AArch64's DataLayout, specify a minimum function alignment of 4. (PR #90702)
llvmbot wrote: >/cherry-pick ddecadabebdd4b301bd65534b58009e57ac1bbe5 Error: Command failed due to missing milestone. https://github.com/llvm/llvm-project/pull/90702 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang backend] In AArch64's DataLayout, specify a minimum function alignment of 4. (PR #90702)
@@ -1480,11 +1480,11 @@ AArch64leTargetInfo::AArch64leTargetInfo(const llvm::Triple , void AArch64leTargetInfo::setDataLayout() { if (getTriple().isOSBinFormatMachO()) { if(getTriple().isArch32Bit()) - resetDataLayout("e-m:o-p:32:32-i64:64-i128:128-n32:64-S128", "_"); + resetDataLayout("e-m:o-p:32:32-i64:64-i128:128-n32:64-S128-Fn32", "_"); AtariDreams wrote: Is this true even if the cpu was executing thumb2 instructions in AArch32 mode? https://github.com/llvm/llvm-project/pull/90702 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Implement P2809: Trivial infinite loops are not Undefined Behavior (PR #90066)
@@ -908,6 +908,69 @@ void CodeGenFunction::EmitIfStmt(const IfStmt ) { incrementProfileCounter(); } +bool CodeGenFunction::checkIfLoopMustProgress(const Expr *ControllingExpression, + bool HasEmptyBody) { + if (CGM.getCodeGenOpts().getFiniteLoops() == + CodeGenOptions::FiniteLoopsKind::Never) +return false; + + // Now apply rules for plain C (see 6.8.5.6 in C11). + // Loops with constant conditions do not have to make progress in any C + // version. + // As an extension, we consisider loops whose constant expression + // can be constant-folded. + Expr::EvalResult Result; + bool CondIsConstInt = hubert-reinterpretcast wrote: > So... we treat it as a manifestly constant-evaluated for the purpose of > checking whether the loop is trivial, but then flips to not manifestly > constant-evaluated for the actual evaluation at runtime? Yes. > The wording could use some clarification... The absence of wording to change the condition itself (that is, what is used at runtime) to be manifestly constant-evaluated is intentional. This wording is not unique. It is also used for the _determination_ of constant initialization, which #89565 (that you referred to) points out is also broken in Clang (however, in contrast to the condition case, once determined to be constant initialization, the initializer itself is considered manifestly constant-evaluated). > Maybe we can run constant-evaluation before Sema::CheckForImmediateInvocation > runs, though. I think that makes sense. The _constant-expression_ that we are evaluating introduces an immediate function context that suppresses immediate invocations (https://eel.is/c++draft/expr.const#16). Example: ```cpp struct A { constexpr A(const int ) : p() {} const int *p; }; consteval A a() { return {42}; } enum { X = (a(), 0) }; // OK, no immediate invocations; Clang and GCC both accept ``` https://github.com/llvm/llvm-project/pull/90066 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang backend] In AArch64's DataLayout, specify a minimum function alignment of 4. (PR #90702)
AtariDreams wrote: /cherry-pick ddecadabebdd4b301bd65534b58009e57ac1bbe5 https://github.com/llvm/llvm-project/pull/90702 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang backend] In AArch64's DataLayout, specify a minimum function alignment of 4. (PR #90702)
AtariDreams wrote: /cherry-pick ddecadabebdd4b301bd65534b58009e57ac1bbe5 https://github.com/llvm/llvm-project/pull/90702 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang backend] In AArch64's DataLayout, specify a minimum function alignment of 4. (PR #90702)
github-actions[bot] wrote: @dougsonos Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail [here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr). If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of [LLVM development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy). You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! https://github.com/llvm/llvm-project/pull/90702 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang backend] In AArch64's DataLayout, specify a minimum function alignment of 4. (PR #90702)
https://github.com/efriedma-quic closed https://github.com/llvm/llvm-project/pull/90702 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] ddecada - [clang backend] In AArch64's DataLayout, specify a minimum function alignment of 4. (#90702)
Author: Doug Wyatt Date: 2024-05-05T19:05:15-07:00 New Revision: ddecadabebdd4b301bd65534b58009e57ac1bbe5 URL: https://github.com/llvm/llvm-project/commit/ddecadabebdd4b301bd65534b58009e57ac1bbe5 DIFF: https://github.com/llvm/llvm-project/commit/ddecadabebdd4b301bd65534b58009e57ac1bbe5.diff LOG: [clang backend] In AArch64's DataLayout, specify a minimum function alignment of 4. (#90702) This addresses an issue where the explicit alignment of 2 (for C++ ABI reasons) was being propagated to the back end and causing under-aligned functions (in special sections). This is an alternate approach suggested by @efriedma-quic in PR #90415. Fixes #90358 Added: Modified: clang/lib/Basic/Targets/AArch64.cpp clang/test/CodeGen/aarch64-type-sizes.c clang/test/CodeGen/coff-aarch64-type-sizes.c clang/test/CodeGen/target-data.c clang/test/CodeGenCXX/member-alignment.cpp clang/test/OpenMP/distribute_parallel_for_num_threads_codegen.cpp clang/test/OpenMP/distribute_parallel_for_simd_num_threads_codegen.cpp llvm/lib/IR/AutoUpgrade.cpp llvm/lib/Target/AArch64/AArch64TargetMachine.cpp llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp Removed: diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp index c8d243a8fb7aea..1a02520d7bd1f8 100644 --- a/clang/lib/Basic/Targets/AArch64.cpp +++ b/clang/lib/Basic/Targets/AArch64.cpp @@ -1480,11 +1480,11 @@ AArch64leTargetInfo::AArch64leTargetInfo(const llvm::Triple , void AArch64leTargetInfo::setDataLayout() { if (getTriple().isOSBinFormatMachO()) { if(getTriple().isArch32Bit()) - resetDataLayout("e-m:o-p:32:32-i64:64-i128:128-n32:64-S128", "_"); + resetDataLayout("e-m:o-p:32:32-i64:64-i128:128-n32:64-S128-Fn32", "_"); else - resetDataLayout("e-m:o-i64:64-i128:128-n32:64-S128", "_"); + resetDataLayout("e-m:o-i64:64-i128:128-n32:64-S128-Fn32", "_"); } else -resetDataLayout("e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"); + resetDataLayout("e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32"); } void AArch64leTargetInfo::getTargetDefines(const LangOptions , @@ -1507,7 +1507,7 @@ void AArch64beTargetInfo::getTargetDefines(const LangOptions , void AArch64beTargetInfo::setDataLayout() { assert(!getTriple().isOSBinFormatMachO()); - resetDataLayout("E-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"); + resetDataLayout("E-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32"); } WindowsARM64TargetInfo::WindowsARM64TargetInfo(const llvm::Triple , @@ -1530,8 +1530,8 @@ WindowsARM64TargetInfo::WindowsARM64TargetInfo(const llvm::Triple , void WindowsARM64TargetInfo::setDataLayout() { resetDataLayout(Triple.isOSBinFormatMachO() - ? "e-m:o-i64:64-i128:128-n32:64-S128" - : "e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128", + ? "e-m:o-i64:64-i128:128-n32:64-S128-Fn32" + : "e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128-Fn32", Triple.isOSBinFormatMachO() ? "_" : ""); } diff --git a/clang/test/CodeGen/aarch64-type-sizes.c b/clang/test/CodeGen/aarch64-type-sizes.c index 7a2508c6e15874..a40423c1f8deb2 100644 --- a/clang/test/CodeGen/aarch64-type-sizes.c +++ b/clang/test/CodeGen/aarch64-type-sizes.c @@ -1,7 +1,7 @@ // RUN: %clang_cc1 -triple aarch64_be-none-linux-gnu -emit-llvm -w -o - %s | FileCheck %s // char by definition has size 1 -// CHECK: target datalayout = "E-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128" +// CHECK: target datalayout = "E-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32" int check_short(void) { return sizeof(short); diff --git a/clang/test/CodeGen/coff-aarch64-type-sizes.c b/clang/test/CodeGen/coff-aarch64-type-sizes.c index f8286618fc8f72..9cb0ddbaef3f65 100644 --- a/clang/test/CodeGen/coff-aarch64-type-sizes.c +++ b/clang/test/CodeGen/coff-aarch64-type-sizes.c @@ -1,6 +1,6 @@ // RUN: %clang_cc1 -triple aarch64-windows -emit-llvm -w -o - %s | FileCheck %s -// CHECK: target datalayout = "e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128" +// CHECK: target datalayout = "e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128-Fn32" // CHECK: target triple = "aarch64-unknown-windows-msvc" int check_short(void) { diff --git a/clang/test/CodeGen/target-data.c b/clang/test/CodeGen/target-data.c index c184f314f68f80..9d86880d6513e0 100644 --- a/clang/test/CodeGen/target-data.c +++ b/clang/test/CodeGen/target-data.c @@ -185,15 +185,15 @@ // RUN: %clang_cc1 -triple arm64-unknown -o - -emit-llvm %s | \ // RUN: FileCheck %s -check-prefix=AARCH64 -// AARCH64: target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128" +// AARCH64: target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32" // RUN: %clang_cc1 -triple arm64_32-apple-ios7.0 -o -
[clang] [Clang][Comments] Support for parsing headers in Doxygen \par commands (PR #91100)
https://github.com/hdoc edited https://github.com/llvm/llvm-project/pull/91100 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] solve crash due to function overloading. (PR #90255)
@@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -emit-llvm < %s lolloz98 wrote: Yes. I gave another read now and found out the FileCheck guide to solve some of my doubts. I will need to double check also the llvm IR generation, if everything is ok, I should be able to modify the test quickly. As of now I am for a bit more than a week away from pc, but as soon as I am back I will finish this pr. thank you for your help, I'll be posting soon :) https://github.com/llvm/llvm-project/pull/90255 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Handle Java switch expressions (PR #91112)
mydeveloperday wrote: This looks good https://github.com/llvm/llvm-project/pull/91112 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Don't allow comma in front of structural enum (PR #91056)
https://github.com/mydeveloperday approved this pull request. https://github.com/llvm/llvm-project/pull/91056 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [openmp] [OpenMP] Depobj optimisation (PR #91145)
https://github.com/rpereira-dev edited https://github.com/llvm/llvm-project/pull/91145 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [openmp] [OpenMP] Depobj optimisation (PR #91145)
rpereira-dev wrote: My bad, forgot to test codegen... These also require adjustements ``` Failed Tests (8): Clang :: OpenMP/depobj_codegen.cpp Clang :: OpenMP/interop_irbuilder.cpp Clang :: OpenMP/target_enter_data_depend_codegen.cpp Clang :: OpenMP/target_exit_data_depend_codegen.cpp Clang :: OpenMP/target_update_depend_codegen.cpp Clang :: OpenMP/task_codegen.c Clang :: OpenMP/task_codegen.cpp Clang :: OpenMP/task_if_codegen.cpp ``` https://github.com/llvm/llvm-project/pull/91145 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Enable FPContract with optnone (PR #91061)
https://github.com/wjristow approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/91061 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Enable FPContract with optnone (PR #91061)
@@ -968,10 +968,7 @@ class FPOptionsOverride { setAllowFPContractAcrossStatement(); } - void setDisallowOptimizations() { -setFPPreciseEnabled(true); -setDisallowFPContract(); - } + void setDisallowOptimizations() { setFPPreciseEnabled(true); } wjristow wrote: Ahhh.. I didn't realize. Thanks! https://github.com/llvm/llvm-project/pull/91061 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang backend] In AArch64's DataLayout, specify a minimum function alignment of 4. (PR #90702)
dougsonos wrote: > Which email address do you want the commit associated with? The GitHub > "squash and merge" button wants to attribute it to your "sonosphere.com" > address, but it looks like the commits themselves are using an "apple.com" > address. Well neither will last forever, but hopefully sonosphere.com lasts a bit longer, so use that one please :) Thanks https://github.com/llvm/llvm-project/pull/90702 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [openmp] [OpenMP] Depobj optimisation (PR #91145)
llvmbot wrote: @llvm/pr-subscribers-clang-codegen Author: PEREIRA Romain (rpereira-dev) Changes # Description As per before, an `omp_depend_t` remains a `kmp_depend_info_t *` allocated on the heap. This patch extends the `kmp_depend_info_t *` data structure caching its associated `kmp_dephash_entry_t` after instanciating a `depobj` with `# pragma omp depobj(obj) depend(...)`, hence removing a call to `__kmp_dephash_find` on task constructs using it. # Notes Regarding tests, we should probably maintain a header file with all runtime data structure interfaces of interest to avoid code dupplication as currently. # Evaluation On 16x cores Intel(R) Xeon(R) Gold 5218 CPU @ 2.30GHz 10 runs on the same code, with/without the patch gives respectively `0.946 +/- 0.004 s.` and `1.046 +/- 0.007 s.` `clang -fopenmp -Wall -Werror -Wextra -O0 main.c` ```C # include assert.h # include omp.h # include stdio.h static omp_depend_t obj; # define N 16 static int x[N]; # define I (4096 * 64) int main(void) { double t0 = omp_get_wtime(); # pragma omp parallel { # pragma omp single nowait { # pragma omp depobj(obj) depend(iterator(i=0:N), out: x[i]) for (int i = 0 ; i I ; ++i) { # pragma omp depobj(obj) update(out) # pragma omp task depend(depobj: obj) shared(x) firstprivate(i) {} # pragma omp depobj(obj) update(in) # pragma omp task depend(depobj: obj) shared(x) firstprivate(i) {} } # pragma omp depobj(obj) destroy # pragma omp taskwait } } double tf = omp_get_wtime(); printf("Took %lf s.\n", tf - t0); return 0; } ``` --- Patch is 27.86 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/91145.diff 23 Files Affected: - (modified) clang/lib/CodeGen/CGOpenMPRuntime.cpp (+35-7) - (modified) clang/lib/CodeGen/CGOpenMPRuntime.h (+14-2) - (modified) llvm/include/llvm/Frontend/OpenMP/OMPConstants.h (+1-1) - (modified) llvm/include/llvm/Frontend/OpenMP/OMPKinds.def (+1) - (modified) openmp/runtime/src/dllexports (+1) - (modified) openmp/runtime/src/kmp.h (+3) - (modified) openmp/runtime/src/kmp_taskdeps.cpp (+18-4) - (modified) openmp/runtime/test/ompt/tasks/kmp_task_depend_all.c (+8) - (modified) openmp/runtime/test/ompt/tasks/omp_task_depend_all.c (+3) - (modified) openmp/runtime/test/tasking/hidden_helper_task/common.h (+1) - (modified) openmp/runtime/test/tasking/hidden_helper_task/depend.cpp (+4) - (modified) openmp/runtime/test/tasking/hidden_helper_task/gtid.cpp (+3) - (modified) openmp/runtime/test/tasking/kmp_detach_tasks_t3.c (+2) - (modified) openmp/runtime/test/tasking/kmp_task_depend_all.c (+8) - (modified) openmp/runtime/test/tasking/kmp_task_deps.h (+1) - (modified) openmp/runtime/test/tasking/kmp_task_deps_multiple_edges.c (+4) - (modified) openmp/runtime/test/tasking/kmp_task_deps_multiple_edges_inoutset.c (+2) - (modified) openmp/runtime/test/tasking/kmp_taskwait_depend_all.c (+8) - (modified) openmp/runtime/test/tasking/kmp_taskwait_depend_in.c (+3) - (modified) openmp/runtime/test/tasking/kmp_taskwait_nowait.c (+3) - (modified) openmp/runtime/test/tasking/omp50_task_depend_mtx.c (+3) - (modified) openmp/runtime/test/tasking/omp50_task_depend_mtx2.c (+3) - (modified) openmp/runtime/test/tasking/omp51_task_dep_inoutset.c (+3) ``diff diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index e39c7c58d2780e5..cf1fbe94c195dfd 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -4030,6 +4030,7 @@ static void getDependTypes(ASTContext , QualType , addFieldToRecordDecl(C, KmpDependInfoRD, C.getIntPtrType()); addFieldToRecordDecl(C, KmpDependInfoRD, C.getSizeType()); addFieldToRecordDecl(C, KmpDependInfoRD, FlagsTy); +addFieldToRecordDecl(C, KmpDependInfoRD, C.VoidPtrTy); KmpDependInfoRD->completeDefinition(); KmpDependInfoTy = C.getRecordType(KmpDependInfoRD); } @@ -4062,10 +4063,11 @@ CGOpenMPRuntime::getDepobjElements(CodeGenFunction , LValue DepobjLVal, return std::make_pair(NumDeps, Base); } -static void emitDependData(CodeGenFunction , QualType , - llvm::PointerUnion Pos, - const OMPTaskDataTy::DependData , - Address DependenciesArray) { +void CGOpenMPRuntime::emitDependData( +CodeGenFunction , QualType , +llvm::PointerUnion Pos, +const OMPTaskDataTy::DependData , Address DependenciesArray, +bool depobj, SourceLocation Loc) { CodeGenModule = CGF.CGM; ASTContext = CGM.getContext(); QualType FlagsTy; @@ -4121,6 +4123,30 @@ static void emitDependData(CodeGenFunction , QualType , CGF.EmitStoreOfScalar( llvm::ConstantInt::get(LLVMFlagsTy,
[clang] [llvm] [openmp] [OpenMP] Depobj optimisation (PR #91145)
llvmbot wrote: @llvm/pr-subscribers-clang Author: PEREIRA Romain (rpereira-dev) Changes # Description As per before, an `omp_depend_t` remains a `kmp_depend_info_t *` allocated on the heap. This patch extends the `kmp_depend_info_t *` data structure caching its associated `kmp_dephash_entry_t` after instanciating a depobj `obj` with `# pragma omp depobj(obj) depend(...)`, hence removing a call to `__kmp_dephash_find` on task constructs using `obj`. # Notes Regarding tests, we should probably maintain a header file with all runtime data structure interfaces of interest to avoid code dupplication as currently. # Evaluation On 16x cores Intel(R) Xeon(R) Gold 5218 CPU @ 2.30GHz 10 runs on the same code, with/without the patch gives respectively `0.946 +/- 0.004 s.` and `1.046 +/- 0.007 s.` `clang -fopenmp -Wall -Werror -Wextra -O0 main.c` ```C # include assert.h # include omp.h # include stdio.h static omp_depend_t obj; # define N 16 static int x[N]; # define I (4096 * 64) int main(void) { double t0 = omp_get_wtime(); # pragma omp parallel { # pragma omp single nowait { # pragma omp depobj(obj) depend(iterator(i=0:N), out: x[i]) for (int i = 0 ; i I ; ++i) { # pragma omp depobj(obj) update(out) # pragma omp task depend(depobj: obj) shared(x) firstprivate(i) {} # pragma omp depobj(obj) update(in) # pragma omp task depend(depobj: obj) shared(x) firstprivate(i) {} } # pragma omp depobj(obj) destroy # pragma omp taskwait } } double tf = omp_get_wtime(); printf("Took %lf s.\n", tf - t0); return 0; } ``` --- Patch is 27.86 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/91145.diff 23 Files Affected: - (modified) clang/lib/CodeGen/CGOpenMPRuntime.cpp (+35-7) - (modified) clang/lib/CodeGen/CGOpenMPRuntime.h (+14-2) - (modified) llvm/include/llvm/Frontend/OpenMP/OMPConstants.h (+1-1) - (modified) llvm/include/llvm/Frontend/OpenMP/OMPKinds.def (+1) - (modified) openmp/runtime/src/dllexports (+1) - (modified) openmp/runtime/src/kmp.h (+3) - (modified) openmp/runtime/src/kmp_taskdeps.cpp (+18-4) - (modified) openmp/runtime/test/ompt/tasks/kmp_task_depend_all.c (+8) - (modified) openmp/runtime/test/ompt/tasks/omp_task_depend_all.c (+3) - (modified) openmp/runtime/test/tasking/hidden_helper_task/common.h (+1) - (modified) openmp/runtime/test/tasking/hidden_helper_task/depend.cpp (+4) - (modified) openmp/runtime/test/tasking/hidden_helper_task/gtid.cpp (+3) - (modified) openmp/runtime/test/tasking/kmp_detach_tasks_t3.c (+2) - (modified) openmp/runtime/test/tasking/kmp_task_depend_all.c (+8) - (modified) openmp/runtime/test/tasking/kmp_task_deps.h (+1) - (modified) openmp/runtime/test/tasking/kmp_task_deps_multiple_edges.c (+4) - (modified) openmp/runtime/test/tasking/kmp_task_deps_multiple_edges_inoutset.c (+2) - (modified) openmp/runtime/test/tasking/kmp_taskwait_depend_all.c (+8) - (modified) openmp/runtime/test/tasking/kmp_taskwait_depend_in.c (+3) - (modified) openmp/runtime/test/tasking/kmp_taskwait_nowait.c (+3) - (modified) openmp/runtime/test/tasking/omp50_task_depend_mtx.c (+3) - (modified) openmp/runtime/test/tasking/omp50_task_depend_mtx2.c (+3) - (modified) openmp/runtime/test/tasking/omp51_task_dep_inoutset.c (+3) ``diff diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index e39c7c58d2780e5..cf1fbe94c195dfd 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -4030,6 +4030,7 @@ static void getDependTypes(ASTContext , QualType , addFieldToRecordDecl(C, KmpDependInfoRD, C.getIntPtrType()); addFieldToRecordDecl(C, KmpDependInfoRD, C.getSizeType()); addFieldToRecordDecl(C, KmpDependInfoRD, FlagsTy); +addFieldToRecordDecl(C, KmpDependInfoRD, C.VoidPtrTy); KmpDependInfoRD->completeDefinition(); KmpDependInfoTy = C.getRecordType(KmpDependInfoRD); } @@ -4062,10 +4063,11 @@ CGOpenMPRuntime::getDepobjElements(CodeGenFunction , LValue DepobjLVal, return std::make_pair(NumDeps, Base); } -static void emitDependData(CodeGenFunction , QualType , - llvm::PointerUnion Pos, - const OMPTaskDataTy::DependData , - Address DependenciesArray) { +void CGOpenMPRuntime::emitDependData( +CodeGenFunction , QualType , +llvm::PointerUnion Pos, +const OMPTaskDataTy::DependData , Address DependenciesArray, +bool depobj, SourceLocation Loc) { CodeGenModule = CGF.CGM; ASTContext = CGM.getContext(); QualType FlagsTy; @@ -4121,6 +4123,30 @@ static void emitDependData(CodeGenFunction , QualType , CGF.EmitStoreOfScalar( llvm::ConstantInt::get(LLVMFlagsTy,
[clang] [llvm] [openmp] [OpenMP] Depobj optimisation (PR #91145)
https://github.com/rpereira-dev edited https://github.com/llvm/llvm-project/pull/91145 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [openmp] [OpenMP] Depobj optimisation (PR #91145)
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/91145 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [openmp] [OpenMP] Depobj optimisation (PR #91145)
https://github.com/rpereira-dev edited https://github.com/llvm/llvm-project/pull/91145 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [openmp] [OpenMP] Depobj optimisation (PR #91145)
https://github.com/rpereira-dev created https://github.com/llvm/llvm-project/pull/91145 # Description As per before, an `omp_depend_t` remains a `kmp_depend_info_t *` allocated on the heap. This patch extends the `kmp_depend_info_t *` data structure caching its associated `kmp_dephash_entry_t` after instanciating a depobj `obj` with `# pragma omp depobj(obj) depend(...)`, hence removing a call to `__kmp_dephash_find` on task constructs using `obj`. This hashing operation can represent # Notes Regarding tests, we should probably maintain a header file with all runtime data structure interfaces of interest to avoid code dupplication as currently. # Evaluation On 16x cores Intel(R) Xeon(R) Gold 5218 CPU @ 2.30GHz 10 runs on the same code, with/without the patch gives respectively `0.946 +/- 0.004 s.` and `1.046 +/- 0.007 s.` `clang -fopenmp -Wall -Werror -Wextra -O0 main.c` ```C # include # include # include static omp_depend_t obj; # define N 16 static int x[N]; # define I (4096 * 64) int main(void) { double t0 = omp_get_wtime(); # pragma omp parallel { # pragma omp single nowait { # pragma omp depobj(obj) depend(iterator(i=0:N), out: x[i]) for (int i = 0 ; i < I ; ++i) { # pragma omp depobj(obj) update(out) # pragma omp task depend(depobj: obj) shared(x) firstprivate(i) {} # pragma omp depobj(obj) update(in) # pragma omp task depend(depobj: obj) shared(x) firstprivate(i) {} } # pragma omp depobj(obj) destroy # pragma omp taskwait } } double tf = omp_get_wtime(); printf("Took %lf s.\n", tf - t0); return 0; } ``` >From e72c62ae0c79d6970af21465285aa96f841353a2 Mon Sep 17 00:00:00 2001 From: Romain PEREIRA Date: Thu, 2 May 2024 14:27:02 +0200 Subject: [PATCH 1/4] [WIP] Optimized OpenMP depobj implementation to avoid rehashing --- clang/lib/CodeGen/CGOpenMPRuntime.cpp | 38 --- clang/lib/CodeGen/CGOpenMPRuntime.h | 17 - .../llvm/Frontend/OpenMP/OMPConstants.h | 2 +- .../include/llvm/Frontend/OpenMP/OMPKinds.def | 1 + openmp/runtime/src/dllexports | 1 + openmp/runtime/src/kmp.h | 21 ++ openmp/runtime/src/kmp_taskdeps.cpp | 19 -- 7 files changed, 87 insertions(+), 12 deletions(-) diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index e39c7c58d2780e..459585b1639301 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -4030,6 +4030,7 @@ static void getDependTypes(ASTContext , QualType , addFieldToRecordDecl(C, KmpDependInfoRD, C.getIntPtrType()); addFieldToRecordDecl(C, KmpDependInfoRD, C.getSizeType()); addFieldToRecordDecl(C, KmpDependInfoRD, FlagsTy); +addFieldToRecordDecl(C, KmpDependInfoRD, C.VoidPtrTy); KmpDependInfoRD->completeDefinition(); KmpDependInfoTy = C.getRecordType(KmpDependInfoRD); } @@ -4062,10 +4063,12 @@ CGOpenMPRuntime::getDepobjElements(CodeGenFunction , LValue DepobjLVal, return std::make_pair(NumDeps, Base); } -static void emitDependData(CodeGenFunction , QualType , +void CGOpenMPRuntime::emitDependData(CodeGenFunction , QualType , llvm::PointerUnion Pos, const OMPTaskDataTy::DependData , - Address DependenciesArray) { + Address DependenciesArray, + bool depobj, + SourceLocation Loc) { CodeGenModule = CGF.CGM; ASTContext = CGM.getContext(); QualType FlagsTy; @@ -4121,6 +4124,30 @@ static void emitDependData(CodeGenFunction , QualType , CGF.EmitStoreOfScalar( llvm::ConstantInt::get(LLVMFlagsTy, static_cast(DepKind)), FlagsLVal); +// deps[i].dephash = NULL || findhash if depobj +LValue DephashLVal = CGF.EmitLValueForField( +Base, *std::next(KmpDependInfoRD->field_begin(), + static_cast(RTLDependInfoFields::Dephash))); +llvm::Value * Dephash; +if (depobj) +{ +// Build kmp_dephash_entry * __kmpc_dephash_find(ident_t * loc, kmp_int32 gtid, kmp_intptr_t addr) +llvm::OpenMPIRBuilder = CGM.getOpenMPRuntime().getOMPBuilder(); +llvm::Value *UpLoc = emitUpdateLocation(CGF, Loc); +llvm::Value *ThreadID = getThreadID(CGF, Loc); +llvm::Value * DephashArgs[3] = { UpLoc, ThreadID, Addr } ; +Dephash = CGF.EmitRuntimeCall( +OMPBuilder.getOrCreateRuntimeFunction( +CGM.getModule(), OMPRTL___kmpc_dephash_find), +DephashArgs); +} +else +{ +Dephash = llvm::Constant::getNullValue(CGF.VoidPtrTy); +} +CGF.EmitStoreOfScalar(Dephash, DephashLVal); +
[clang] [analyzer] Support determining origins in a conditional operator in WebKit checkers. (PR #91143)
https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/91143 >From bbef8dedba3daf7ee35acf66b67418af80bc12c8 Mon Sep 17 00:00:00 2001 From: Ryosuke Niwa Date: Sun, 5 May 2024 13:40:10 -0700 Subject: [PATCH] [analyzer] Support determining origins in a conditional operator in WebKit checkers. This PR adds the support for determining the origin of a pointer in a conditional operator. Because such an expression can have two distinct origins each of which needs to be visited, this PR refactors tryToFindPtrOrigin to take a callback instead of returning a pair. The callback is called for the second operand and the third operand of the conditioanl operator (i.e. E2 and E3 in E1 ? E2 : E3). Also treat nullptr and integer literal as safe pointer origins in the local variable checker. --- .../Checkers/WebKit/ASTUtils.cpp | 23 -- .../StaticAnalyzer/Checkers/WebKit/ASTUtils.h | 11 ++- .../WebKit/UncountedCallArgsChecker.cpp | 36 + .../WebKit/UncountedLocalVarsChecker.cpp | 73 +++ .../Analysis/Checkers/WebKit/call-args.cpp| 14 .../Checkers/WebKit/uncounted-local-vars.cpp | 18 + 6 files changed, 113 insertions(+), 62 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp index b36fa95bc73f3e..3e4bb276bb49ae 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp @@ -16,8 +16,9 @@ namespace clang { -std::pair -tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj) { +bool tryToFindPtrOrigin( +const Expr *E, bool StopAtFirstRefCountedObj, +std::function callback) { while (E) { if (auto *tempExpr = dyn_cast(E)) { E = tempExpr->getSubExpr(); @@ -27,12 +28,18 @@ tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj) { E = tempExpr->getSubExpr(); continue; } +if (auto *Expr = dyn_cast(E)) { + return tryToFindPtrOrigin(Expr->getTrueExpr(), StopAtFirstRefCountedObj, +callback) && + tryToFindPtrOrigin(Expr->getFalseExpr(), StopAtFirstRefCountedObj, +callback); +} if (auto *cast = dyn_cast(E)) { if (StopAtFirstRefCountedObj) { if (auto *ConversionFunc = dyn_cast_or_null(cast->getConversionFunction())) { if (isCtorOfRefCounted(ConversionFunc)) -return {E, true}; +return callback(E, true); } } // FIXME: This can give false "origin" that would lead to false negatives @@ -47,7 +54,7 @@ tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj) { if (IsGetterOfRefCt && *IsGetterOfRefCt) { E = memberCall->getImplicitObjectArgument(); if (StopAtFirstRefCountedObj) { - return {E, true}; + return callback(E, true); } continue; } @@ -64,17 +71,17 @@ tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj) { if (auto *callee = call->getDirectCallee()) { if (isCtorOfRefCounted(callee)) { if (StopAtFirstRefCountedObj) -return {E, true}; +return callback(E, true); E = call->getArg(0); continue; } if (isReturnValueRefCounted(callee)) - return {E, true}; + return callback(E, true); if (isSingleton(callee)) - return {E, true}; + return callback(E, true); if (isPtrConversion(callee)) { E = call->getArg(0); @@ -91,7 +98,7 @@ tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj) { break; } // Some other expression. - return {E, false}; + return callback(E, false); } bool isASafeCallArg(const Expr *E) { diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h index e35ea4ef05dd17..e972924e0c523d 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h @@ -13,6 +13,7 @@ #include "llvm/ADT/APInt.h" #include "llvm/Support/Casting.h" +#include #include #include @@ -48,10 +49,12 @@ class Expr; /// represents ref-counted object during the traversal we return relevant /// sub-expression and true. /// -/// \returns subexpression that we traversed to and if \p -/// StopAtFirstRefCountedObj is true we also return whether we stopped early. -std::pair -tryToFindPtrOrigin(const clang::Expr *E, bool StopAtFirstRefCountedObj); +/// Calls \p callback with the subexpression that we traversed to and if \p +/// StopAtFirstRefCountedObj is true we also specify whether we stopped early. +/// Returns false if any of calls to callbacks returned false. Otherwise true. +bool tryToFindPtrOrigin( +const clang::Expr *E, bool
[clang] [analyzer] Support determining origins in a conditional operator in WebKit checkers. (PR #91143)
https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/91143 >From 477ef4bc201240044051410ac2d2f33b10049d49 Mon Sep 17 00:00:00 2001 From: Ryosuke Niwa Date: Sun, 5 May 2024 13:40:10 -0700 Subject: [PATCH] [analyzer] Support determining origins in a conditional operator in WebKit checkers. This PR adds the support for determining the origin of a pointer in a conditional operator. Because such an expression can have two distinct origins each of which needs to be visited, this PR refactors tryToFindPtrOrigin to take a callback instead of returning a pair. The callback is called for the second operand and the third operand of the conditioanl operator (i.e. E2 and E3 in E1 ? E2 : E3). Also treat nullptr and integer literal as safe pointer origins in the local variable checker. --- .../Checkers/WebKit/ASTUtils.cpp | 23 -- .../StaticAnalyzer/Checkers/WebKit/ASTUtils.h | 11 ++- .../WebKit/UncountedCallArgsChecker.cpp | 36 + .../WebKit/UncountedLocalVarsChecker.cpp | 73 +++ .../Analysis/Checkers/WebKit/call-args.cpp| 14 .../Checkers/WebKit/uncounted-local-vars.cpp | 18 + 6 files changed, 113 insertions(+), 62 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp index b36fa95bc73f3e..a80ba9ca7dfae1 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp @@ -16,8 +16,9 @@ namespace clang { -std::pair -tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj) { +bool tryToFindPtrOrigin( +const Expr *E, bool StopAtFirstRefCountedObj, +std::function callback) { while (E) { if (auto *tempExpr = dyn_cast(E)) { E = tempExpr->getSubExpr(); @@ -27,12 +28,18 @@ tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj) { E = tempExpr->getSubExpr(); continue; } +if (auto* Expr = dyn_cast(E)) { + return tryToFindPtrOrigin(Expr->getTrueExpr(), StopAtFirstRefCountedObj, +callback) && + tryToFindPtrOrigin(Expr->getFalseExpr(), StopAtFirstRefCountedObj, +callback); +} if (auto *cast = dyn_cast(E)) { if (StopAtFirstRefCountedObj) { if (auto *ConversionFunc = dyn_cast_or_null(cast->getConversionFunction())) { if (isCtorOfRefCounted(ConversionFunc)) -return {E, true}; +return callback(E, true); } } // FIXME: This can give false "origin" that would lead to false negatives @@ -47,7 +54,7 @@ tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj) { if (IsGetterOfRefCt && *IsGetterOfRefCt) { E = memberCall->getImplicitObjectArgument(); if (StopAtFirstRefCountedObj) { - return {E, true}; + return callback(E, true); } continue; } @@ -64,17 +71,17 @@ tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj) { if (auto *callee = call->getDirectCallee()) { if (isCtorOfRefCounted(callee)) { if (StopAtFirstRefCountedObj) -return {E, true}; +return callback(E, true); E = call->getArg(0); continue; } if (isReturnValueRefCounted(callee)) - return {E, true}; + return callback(E, true); if (isSingleton(callee)) - return {E, true}; + return callback(E, true); if (isPtrConversion(callee)) { E = call->getArg(0); @@ -91,7 +98,7 @@ tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj) { break; } // Some other expression. - return {E, false}; + return callback(E, false); } bool isASafeCallArg(const Expr *E) { diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h index e35ea4ef05dd17..e972924e0c523d 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h @@ -13,6 +13,7 @@ #include "llvm/ADT/APInt.h" #include "llvm/Support/Casting.h" +#include #include #include @@ -48,10 +49,12 @@ class Expr; /// represents ref-counted object during the traversal we return relevant /// sub-expression and true. /// -/// \returns subexpression that we traversed to and if \p -/// StopAtFirstRefCountedObj is true we also return whether we stopped early. -std::pair -tryToFindPtrOrigin(const clang::Expr *E, bool StopAtFirstRefCountedObj); +/// Calls \p callback with the subexpression that we traversed to and if \p +/// StopAtFirstRefCountedObj is true we also specify whether we stopped early. +/// Returns false if any of calls to callbacks returned false. Otherwise true. +bool tryToFindPtrOrigin( +const clang::Expr *E, bool
[clang] [analyzer] Support determining origins in a conditional operator in WebKit checkers. (PR #91143)
https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/91143 >From b7360fced7163fddc7f02305bb9cc234c1ae1fef Mon Sep 17 00:00:00 2001 From: Ryosuke Niwa Date: Sun, 5 May 2024 13:40:10 -0700 Subject: [PATCH] [analyzer] Support determining origns in a conditional operator in WebKit checkers. This PR adds the support for determining the origin of a pointer in a conditional operator. Because such an expression can have two distinct origins each of which needs to be visited, this PR refactors tryToFindPtrOrigin to take a callback instead of returning a pair. The callback is called for the second operand and the third operand of the conditioanl operator (i.e. E2 and E3 in E1 ? E2 : E3). Also treat nullptr and integer literal as safe pointer origins in the local variable checker. --- .../Checkers/WebKit/ASTUtils.cpp | 23 -- .../StaticAnalyzer/Checkers/WebKit/ASTUtils.h | 11 ++- .../WebKit/UncountedCallArgsChecker.cpp | 36 + .../WebKit/UncountedLocalVarsChecker.cpp | 73 +++ .../Analysis/Checkers/WebKit/call-args.cpp| 14 .../Checkers/WebKit/uncounted-local-vars.cpp | 18 + 6 files changed, 113 insertions(+), 62 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp index b36fa95bc73f3e..a80ba9ca7dfae1 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp @@ -16,8 +16,9 @@ namespace clang { -std::pair -tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj) { +bool tryToFindPtrOrigin( +const Expr *E, bool StopAtFirstRefCountedObj, +std::function callback) { while (E) { if (auto *tempExpr = dyn_cast(E)) { E = tempExpr->getSubExpr(); @@ -27,12 +28,18 @@ tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj) { E = tempExpr->getSubExpr(); continue; } +if (auto* Expr = dyn_cast(E)) { + return tryToFindPtrOrigin(Expr->getTrueExpr(), StopAtFirstRefCountedObj, +callback) && + tryToFindPtrOrigin(Expr->getFalseExpr(), StopAtFirstRefCountedObj, +callback); +} if (auto *cast = dyn_cast(E)) { if (StopAtFirstRefCountedObj) { if (auto *ConversionFunc = dyn_cast_or_null(cast->getConversionFunction())) { if (isCtorOfRefCounted(ConversionFunc)) -return {E, true}; +return callback(E, true); } } // FIXME: This can give false "origin" that would lead to false negatives @@ -47,7 +54,7 @@ tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj) { if (IsGetterOfRefCt && *IsGetterOfRefCt) { E = memberCall->getImplicitObjectArgument(); if (StopAtFirstRefCountedObj) { - return {E, true}; + return callback(E, true); } continue; } @@ -64,17 +71,17 @@ tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj) { if (auto *callee = call->getDirectCallee()) { if (isCtorOfRefCounted(callee)) { if (StopAtFirstRefCountedObj) -return {E, true}; +return callback(E, true); E = call->getArg(0); continue; } if (isReturnValueRefCounted(callee)) - return {E, true}; + return callback(E, true); if (isSingleton(callee)) - return {E, true}; + return callback(E, true); if (isPtrConversion(callee)) { E = call->getArg(0); @@ -91,7 +98,7 @@ tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj) { break; } // Some other expression. - return {E, false}; + return callback(E, false); } bool isASafeCallArg(const Expr *E) { diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h index e35ea4ef05dd17..e972924e0c523d 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h @@ -13,6 +13,7 @@ #include "llvm/ADT/APInt.h" #include "llvm/Support/Casting.h" +#include #include #include @@ -48,10 +49,12 @@ class Expr; /// represents ref-counted object during the traversal we return relevant /// sub-expression and true. /// -/// \returns subexpression that we traversed to and if \p -/// StopAtFirstRefCountedObj is true we also return whether we stopped early. -std::pair -tryToFindPtrOrigin(const clang::Expr *E, bool StopAtFirstRefCountedObj); +/// Calls \p callback with the subexpression that we traversed to and if \p +/// StopAtFirstRefCountedObj is true we also specify whether we stopped early. +/// Returns false if any of calls to callbacks returned false. Otherwise true. +bool tryToFindPtrOrigin( +const clang::Expr *E, bool
[clang] [analyzer] Support determining origins in a conditional operator in WebKit checkers. (PR #91143)
https://github.com/rniwa edited https://github.com/llvm/llvm-project/pull/91143 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Support determining origns in a conditional operator in WebKit checkers. (PR #91143)
https://github.com/rniwa edited https://github.com/llvm/llvm-project/pull/91143 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Support determining the orign in a conditional operator in WebKit checkers. (PR #91143)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff a312dd68c0ce368313164eb92cbdd95192afa3f8 ae2d8006c7f9237ed4e79cb3b729c4ce55a24b35 -- clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp clang/test/Analysis/Checkers/WebKit/call-args.cpp clang/test/Analysis/Checkers/WebKit/uncounted-local-vars.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp index f2e531837a..3e4bb276bb 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp @@ -16,8 +16,9 @@ namespace clang { -bool tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj, - std::function callback) { +bool tryToFindPtrOrigin( +const Expr *E, bool StopAtFirstRefCountedObj, +std::function callback) { while (E) { if (auto *tempExpr = dyn_cast(E)) { E = tempExpr->getSubExpr(); @@ -27,10 +28,11 @@ bool tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj, E = tempExpr->getSubExpr(); continue; } -if (auto* Expr = dyn_cast(E)) { +if (auto *Expr = dyn_cast(E)) { return tryToFindPtrOrigin(Expr->getTrueExpr(), StopAtFirstRefCountedObj, -callback) && tryToFindPtrOrigin(Expr->getFalseExpr(), -StopAtFirstRefCountedObj, callback); +callback) && + tryToFindPtrOrigin(Expr->getFalseExpr(), StopAtFirstRefCountedObj, +callback); } if (auto *cast = dyn_cast(E)) { if (StopAtFirstRefCountedObj) { diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h index cfcc046dc9..e972924e0c 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h @@ -52,8 +52,9 @@ class Expr; /// Calls \p callback with the subexpression that we traversed to and if \p /// StopAtFirstRefCountedObj is true we also specify whether we stopped early. /// Returns false if any of calls to callbacks returned false. Otherwise true. -bool tryToFindPtrOrigin(const clang::Expr *E, bool StopAtFirstRefCountedObj, - std::function callback); +bool tryToFindPtrOrigin( +const clang::Expr *E, bool StopAtFirstRefCountedObj, +std::function callback); /// For \p E referring to a ref-countable/-counted pointer/reference we return /// whether it's a safe call argument. Examples: function parameter or diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp index cf98e2d213..658a23e255 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp @@ -127,22 +127,22 @@ public: bool isPtrOriginSafe(const Expr *Arg) const { return tryToFindPtrOrigin(Arg, /*StopAtFirstRefCountedObj=*/true, -[](const clang::Expr* ArgOrigin, bool IsSafe) { - if (IsSafe) -return true; - if (isa(ArgOrigin)) { -// foo(nullptr) -return true; - } - if (isa(ArgOrigin)) { -// FIXME: Check the value. -// foo(NULL) -return true; - } - if (isASafeCallArg(ArgOrigin)) -return true; - return false; -}); + [](const clang::Expr *ArgOrigin, bool IsSafe) { +if (IsSafe) + return true; +if (isa(ArgOrigin)) { + // foo(nullptr) + return true; +} +if (isa(ArgOrigin)) { + // FIXME: Check the value. + // foo(NULL) + return true; +} +if (isASafeCallArg(ArgOrigin)) + return true; +return false; + }); } bool shouldSkipCall(const CallExpr *CE) const { diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp index 1d1dfa12e9..a1a070d6a6 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp +++
[clang] [analyzer] Support determining the orign in a conditional operator in WebKit checkers. (PR #91143)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Ryosuke Niwa (rniwa) Changes This PR adds the support for determining the origin of a pointer in a conditional operator. Because such an expression can have two distinct origins each of which needs to be visited, this PR refactors tryToFindPtrOrigin to take a callback instead of returning a pair. The callback is called for the second operand and the third operand of the conditioanl operator (i.e. E2 and E3 in E1 ? E2 : E3). Also treat nullptr and integer literal as safe pointer origins in the local variable checker. --- Full diff: https://github.com/llvm/llvm-project/pull/91143.diff 6 Files Affected: - (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp (+13-8) - (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h (+6-4) - (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp (+17-19) - (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLocalVarsChecker.cpp (+38-29) - (modified) clang/test/Analysis/Checkers/WebKit/call-args.cpp (+14) - (modified) clang/test/Analysis/Checkers/WebKit/uncounted-local-vars.cpp (+18) ``diff diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp index b36fa95bc73f3e..f2e531837ac848 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp @@ -16,8 +16,8 @@ namespace clang { -std::pair -tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj) { +bool tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj, + std::function callback) { while (E) { if (auto *tempExpr = dyn_cast(E)) { E = tempExpr->getSubExpr(); @@ -27,12 +27,17 @@ tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj) { E = tempExpr->getSubExpr(); continue; } +if (auto* Expr = dyn_cast(E)) { + return tryToFindPtrOrigin(Expr->getTrueExpr(), StopAtFirstRefCountedObj, +callback) && tryToFindPtrOrigin(Expr->getFalseExpr(), +StopAtFirstRefCountedObj, callback); +} if (auto *cast = dyn_cast(E)) { if (StopAtFirstRefCountedObj) { if (auto *ConversionFunc = dyn_cast_or_null(cast->getConversionFunction())) { if (isCtorOfRefCounted(ConversionFunc)) -return {E, true}; +return callback(E, true); } } // FIXME: This can give false "origin" that would lead to false negatives @@ -47,7 +52,7 @@ tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj) { if (IsGetterOfRefCt && *IsGetterOfRefCt) { E = memberCall->getImplicitObjectArgument(); if (StopAtFirstRefCountedObj) { - return {E, true}; + return callback(E, true); } continue; } @@ -64,17 +69,17 @@ tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj) { if (auto *callee = call->getDirectCallee()) { if (isCtorOfRefCounted(callee)) { if (StopAtFirstRefCountedObj) -return {E, true}; +return callback(E, true); E = call->getArg(0); continue; } if (isReturnValueRefCounted(callee)) - return {E, true}; + return callback(E, true); if (isSingleton(callee)) - return {E, true}; + return callback(E, true); if (isPtrConversion(callee)) { E = call->getArg(0); @@ -91,7 +96,7 @@ tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj) { break; } // Some other expression. - return {E, false}; + return callback(E, false); } bool isASafeCallArg(const Expr *E) { diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h index e35ea4ef05dd17..cfcc046dc9d36c 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h @@ -13,6 +13,7 @@ #include "llvm/ADT/APInt.h" #include "llvm/Support/Casting.h" +#include #include #include @@ -48,10 +49,11 @@ class Expr; /// represents ref-counted object during the traversal we return relevant /// sub-expression and true. /// -/// \returns subexpression that we traversed to and if \p -/// StopAtFirstRefCountedObj is true we also return whether we stopped early. -std::pair -tryToFindPtrOrigin(const clang::Expr *E, bool StopAtFirstRefCountedObj); +/// Calls \p callback with the subexpression that we traversed to and if \p +/// StopAtFirstRefCountedObj is true we also specify whether we stopped early. +/// Returns false if any of calls to callbacks returned false. Otherwise true. +bool tryToFindPtrOrigin(const clang::Expr *E, bool StopAtFirstRefCountedObj, + std::function callback); /// For \p E referring to a ref-countable/-counted pointer/reference we
[clang] [analyzer] Support determining the orign in a conditional operator in WebKit checkers. (PR #91143)
https://github.com/rniwa created https://github.com/llvm/llvm-project/pull/91143 This PR adds the support for determining the origin of a pointer in a conditional operator. Because such an expression can have two distinct origins each of which needs to be visited, this PR refactors tryToFindPtrOrigin to take a callback instead of returning a pair. The callback is called for the second operand and the third operand of the conditioanl operator (i.e. E2 and E3 in E1 ? E2 : E3). Also treat nullptr and integer literal as safe pointer origins in the local variable checker. >From ae2d8006c7f9237ed4e79cb3b729c4ce55a24b35 Mon Sep 17 00:00:00 2001 From: Ryosuke Niwa Date: Sun, 5 May 2024 13:40:10 -0700 Subject: [PATCH] [analyzer] Support determining the orign in a conditional operator in WebKit checkers. This PR adds the support for determining the origin of a pointer in a conditional operator. Because such an expression can have two distinct origins each of which needs to be visited, this PR refactors tryToFindPtrOrigin to take a callback instead of returning a pair. The callback is called for the second operand and the third operand of the conditioanl operator (i.e. E2 and E3 in E1 ? E2 : E3). Also treat nullptr and integer literal as safe pointer origins in the local variable checker. --- .../Checkers/WebKit/ASTUtils.cpp | 21 +++--- .../StaticAnalyzer/Checkers/WebKit/ASTUtils.h | 10 +-- .../WebKit/UncountedCallArgsChecker.cpp | 36 +- .../WebKit/UncountedLocalVarsChecker.cpp | 67 +++ .../Analysis/Checkers/WebKit/call-args.cpp| 14 .../Checkers/WebKit/uncounted-local-vars.cpp | 18 + 6 files changed, 106 insertions(+), 60 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp index b36fa95bc73f3e..f2e531837ac848 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp @@ -16,8 +16,8 @@ namespace clang { -std::pair -tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj) { +bool tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj, + std::function callback) { while (E) { if (auto *tempExpr = dyn_cast(E)) { E = tempExpr->getSubExpr(); @@ -27,12 +27,17 @@ tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj) { E = tempExpr->getSubExpr(); continue; } +if (auto* Expr = dyn_cast(E)) { + return tryToFindPtrOrigin(Expr->getTrueExpr(), StopAtFirstRefCountedObj, +callback) && tryToFindPtrOrigin(Expr->getFalseExpr(), +StopAtFirstRefCountedObj, callback); +} if (auto *cast = dyn_cast(E)) { if (StopAtFirstRefCountedObj) { if (auto *ConversionFunc = dyn_cast_or_null(cast->getConversionFunction())) { if (isCtorOfRefCounted(ConversionFunc)) -return {E, true}; +return callback(E, true); } } // FIXME: This can give false "origin" that would lead to false negatives @@ -47,7 +52,7 @@ tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj) { if (IsGetterOfRefCt && *IsGetterOfRefCt) { E = memberCall->getImplicitObjectArgument(); if (StopAtFirstRefCountedObj) { - return {E, true}; + return callback(E, true); } continue; } @@ -64,17 +69,17 @@ tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj) { if (auto *callee = call->getDirectCallee()) { if (isCtorOfRefCounted(callee)) { if (StopAtFirstRefCountedObj) -return {E, true}; +return callback(E, true); E = call->getArg(0); continue; } if (isReturnValueRefCounted(callee)) - return {E, true}; + return callback(E, true); if (isSingleton(callee)) - return {E, true}; + return callback(E, true); if (isPtrConversion(callee)) { E = call->getArg(0); @@ -91,7 +96,7 @@ tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj) { break; } // Some other expression. - return {E, false}; + return callback(E, false); } bool isASafeCallArg(const Expr *E) { diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h index e35ea4ef05dd17..cfcc046dc9d36c 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h @@ -13,6 +13,7 @@ #include "llvm/ADT/APInt.h" #include "llvm/Support/Casting.h" +#include #include #include @@ -48,10 +49,11 @@ class Expr; /// represents ref-counted object during the traversal we return relevant /// sub-expression and true. /// -/// \returns subexpression that we traversed to and if \p -///
[clang] [llvm] [AArch64][SME] Save VG for unwind info when changing streaming-mode (PR #83301)
@@ -221,6 +224,15 @@ def : Pat<(AArch64_smstop (i32 svcr_op:$pstate), (i64 /*AArch64SME::Always*/0)), (MSRpstatesvcrImm1 svcr_op:$pstate, 0b0)>; +// Pseudo to insert cfi_offset/cfi_restore instructions. Used to save or restore +// the streaming value of VG around streaming-mode changes in locally-streaming +// functions. +def VGUnwindInfoPseudo : + Pseudo<(outs), (ins timm0_1:$save_restore), []>, Sched<[]>; efriedma-quic wrote: Is there a reason to make this one pseudo, instead of two? The two operations have opposite semantics, and opcode space isn't that scarce. https://github.com/llvm/llvm-project/pull/83301 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AArch64][SME] Save VG for unwind info when changing streaming-mode (PR #83301)
@@ -3730,6 +3730,12 @@ def warn_gnu_inline_cplusplus_without_extern : Warning< "'gnu_inline' attribute without 'extern' in C++ treated as externally" " available, this changed in Clang 10">, InGroup>; +def warn_sme_streaming_mode_change_no_sve : Warning< + "function requires a streaming-mode change, unwinding is not possible without 'sve'">, + InGroup; efriedma-quic wrote: This should probably be an error if it's possible to unwind: it's effectively miscompile. Both here, and in the backend. Add a note suggesting marking the function `noexcept`/`__attribute((nothrow))`. If it isn't possible to unwind, you just end up with slightly inaccurate debug info, which is just annoying; probably not worth warning for that. https://github.com/llvm/llvm-project/pull/83301 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang backend] In AArch64's DataLayout, specify a minimum function alignment of 4. (PR #90702)
efriedma-quic wrote: Which email address do you want the commit associated with? The GitHub "squash and merge" button wants to attribute it to your "sonosphere.com" address, but it looks like the commits themselves are using an "apple.com" address. https://github.com/llvm/llvm-project/pull/90702 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang backend] In AArch64's DataLayout, specify a minimum function alignment of 4. (PR #90702)
https://github.com/efriedma-quic approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/90702 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Revert "Revert "[OpenMP][TR12] change property of map-type modifier."… (PR #91141)
llvmbot wrote: @llvm/pr-subscribers-clang Author: None (jyu2-git) Changes … (#90885)" This reverts commit eea81aa29848361eb5b24f24d2af643fdeb9adfd. Also change isMapType as @vitalybuka suggested. Hope this fix sanitizer build problem. --- Patch is 29.74 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/91141.diff 4 Files Affected: - (modified) clang/include/clang/Basic/DiagnosticParseKinds.td (+5) - (modified) clang/lib/Parse/ParseOpenMP.cpp (+43-8) - (modified) clang/test/OpenMP/target_ast_print.cpp (+58) - (modified) clang/test/OpenMP/target_map_messages.cpp (+59-46) ``diff diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index fdffb35ea0d955..44bc4e0e130de8 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -1438,6 +1438,9 @@ def err_omp_decl_in_declare_simd_variant : Error< def err_omp_sink_and_source_iteration_not_allowd: Error<" '%0 %select{sink:|source:}1' must be with '%select{omp_cur_iteration - 1|omp_cur_iteration}1'">; def err_omp_unknown_map_type : Error< "incorrect map type, expected one of 'to', 'from', 'tofrom', 'alloc', 'release', or 'delete'">; +def err_omp_more_one_map_type : Error<"map type is already specified">; +def note_previous_map_type_specified_here +: Note<"map type '%0' is previous specified here">; def err_omp_unknown_map_type_modifier : Error< "incorrect map type modifier, expected one of: 'always', 'close', 'mapper'" "%select{|, 'present'|, 'present', 'iterator'}0%select{|, 'ompx_hold'}1">; @@ -1445,6 +1448,8 @@ def err_omp_map_type_missing : Error< "missing map type">; def err_omp_map_type_modifier_missing : Error< "missing map type modifier">; +def err_omp_map_modifier_specification_list : Error< + "empty modifier-specification-list is not allowed">; def err_omp_declare_simd_inbranch_notinbranch : Error< "unexpected '%0' clause, '%1' is specified already">; def err_omp_expected_clause_argument diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp index 18ba1185ee8de7..5265d8f1922c31 100644 --- a/clang/lib/Parse/ParseOpenMP.cpp +++ b/clang/lib/Parse/ParseOpenMP.cpp @@ -4228,13 +4228,20 @@ bool Parser::parseMapperModifier(SemaOpenMP::OpenMPVarListDataTy ) { return T.consumeClose(); } +static OpenMPMapClauseKind isMapType(Parser ); + /// Parse map-type-modifiers in map clause. -/// map([ [map-type-modifier[,] [map-type-modifier[,] ...] map-type : ] list) +/// map([ [map-type-modifier[,] [map-type-modifier[,] ...] [map-type] : ] list) /// where, map-type-modifier ::= always | close | mapper(mapper-identifier) | /// present +/// where, map-type ::= alloc | delete | from | release | to | tofrom bool Parser::parseMapTypeModifiers(SemaOpenMP::OpenMPVarListDataTy ) { + bool HasMapType = false; + SourceLocation PreMapLoc = Tok.getLocation(); + StringRef PreMapName = ""; while (getCurToken().isNot(tok::colon)) { OpenMPMapModifierKind TypeModifier = isMapModifier(*this); +OpenMPMapClauseKind MapKind = isMapType(*this); if (TypeModifier == OMPC_MAP_MODIFIER_always || TypeModifier == OMPC_MAP_MODIFIER_close || TypeModifier == OMPC_MAP_MODIFIER_present || @@ -4257,6 +4264,19 @@ bool Parser::parseMapTypeModifiers(SemaOpenMP::OpenMPVarListDataTy ) { Diag(Data.MapTypeModifiersLoc.back(), diag::err_omp_missing_comma) << "map type modifier"; +} else if (getLangOpts().OpenMP >= 60 && MapKind != OMPC_MAP_unknown) { + if (!HasMapType) { +HasMapType = true; +Data.ExtraModifier = MapKind; +MapKind = OMPC_MAP_unknown; +PreMapLoc = Tok.getLocation(); +PreMapName = Tok.getIdentifierInfo()->getName(); + } else { +Diag(Tok, diag::err_omp_more_one_map_type); +Diag(PreMapLoc, diag::note_previous_map_type_specified_here) +<< PreMapName; + } + ConsumeToken(); } else { // For the case of unknown map-type-modifier or a map-type. // Map-type is followed by a colon; the function returns when it @@ -4267,8 +4287,14 @@ bool Parser::parseMapTypeModifiers(SemaOpenMP::OpenMPVarListDataTy ) { continue; } // Potential map-type token as it is followed by a colon. - if (PP.LookAhead(0).is(tok::colon)) -return false; + if (PP.LookAhead(0).is(tok::colon)) { +if (getLangOpts().OpenMP >= 60) { + break; +} else { + return false; +} + } + Diag(Tok, diag::err_omp_unknown_map_type_modifier) << (getLangOpts().OpenMP >= 51 ? (getLangOpts().OpenMP >= 52 ? 2 : 1) : 0) @@ -4278,6 +4304,14 @@ bool Parser::parseMapTypeModifiers(SemaOpenMP::OpenMPVarListDataTy ) { if (getCurToken().is(tok::comma)) ConsumeToken(); } + if
[clang] [clang-format] Don't allow comma in front of structural enum (PR #91056)
https://github.com/owenca approved this pull request. https://github.com/llvm/llvm-project/pull/91056 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Revert "Revert "[OpenMP][TR12] change property of map-type modifier."… (PR #91141)
https://github.com/jyu2-git created https://github.com/llvm/llvm-project/pull/91141 … (#90885)" This reverts commit eea81aa29848361eb5b24f24d2af643fdeb9adfd. Also change isMapType as @vitalybuka suggested. Hope this fix sanitizer build problem. >From 563c1254162d7b42fd7579514f45df326216f508 Mon Sep 17 00:00:00 2001 From: Jennifer Yu Date: Sun, 5 May 2024 10:44:40 -0700 Subject: [PATCH] Revert "Revert "[OpenMP][TR12] change property of map-type modifier." (#90885)" This reverts commit eea81aa29848361eb5b24f24d2af643fdeb9adfd. --- .../clang/Basic/DiagnosticParseKinds.td | 5 + clang/lib/Parse/ParseOpenMP.cpp | 51 +++-- clang/test/OpenMP/target_ast_print.cpp| 58 ++ clang/test/OpenMP/target_map_messages.cpp | 105 ++ 4 files changed, 165 insertions(+), 54 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index fdffb35ea0d955..44bc4e0e130de8 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -1438,6 +1438,9 @@ def err_omp_decl_in_declare_simd_variant : Error< def err_omp_sink_and_source_iteration_not_allowd: Error<" '%0 %select{sink:|source:}1' must be with '%select{omp_cur_iteration - 1|omp_cur_iteration}1'">; def err_omp_unknown_map_type : Error< "incorrect map type, expected one of 'to', 'from', 'tofrom', 'alloc', 'release', or 'delete'">; +def err_omp_more_one_map_type : Error<"map type is already specified">; +def note_previous_map_type_specified_here +: Note<"map type '%0' is previous specified here">; def err_omp_unknown_map_type_modifier : Error< "incorrect map type modifier, expected one of: 'always', 'close', 'mapper'" "%select{|, 'present'|, 'present', 'iterator'}0%select{|, 'ompx_hold'}1">; @@ -1445,6 +1448,8 @@ def err_omp_map_type_missing : Error< "missing map type">; def err_omp_map_type_modifier_missing : Error< "missing map type modifier">; +def err_omp_map_modifier_specification_list : Error< + "empty modifier-specification-list is not allowed">; def err_omp_declare_simd_inbranch_notinbranch : Error< "unexpected '%0' clause, '%1' is specified already">; def err_omp_expected_clause_argument diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp index 18ba1185ee8de7..5265d8f1922c31 100644 --- a/clang/lib/Parse/ParseOpenMP.cpp +++ b/clang/lib/Parse/ParseOpenMP.cpp @@ -4228,13 +4228,20 @@ bool Parser::parseMapperModifier(SemaOpenMP::OpenMPVarListDataTy ) { return T.consumeClose(); } +static OpenMPMapClauseKind isMapType(Parser ); + /// Parse map-type-modifiers in map clause. -/// map([ [map-type-modifier[,] [map-type-modifier[,] ...] map-type : ] list) +/// map([ [map-type-modifier[,] [map-type-modifier[,] ...] [map-type] : ] list) /// where, map-type-modifier ::= always | close | mapper(mapper-identifier) | /// present +/// where, map-type ::= alloc | delete | from | release | to | tofrom bool Parser::parseMapTypeModifiers(SemaOpenMP::OpenMPVarListDataTy ) { + bool HasMapType = false; + SourceLocation PreMapLoc = Tok.getLocation(); + StringRef PreMapName = ""; while (getCurToken().isNot(tok::colon)) { OpenMPMapModifierKind TypeModifier = isMapModifier(*this); +OpenMPMapClauseKind MapKind = isMapType(*this); if (TypeModifier == OMPC_MAP_MODIFIER_always || TypeModifier == OMPC_MAP_MODIFIER_close || TypeModifier == OMPC_MAP_MODIFIER_present || @@ -4257,6 +4264,19 @@ bool Parser::parseMapTypeModifiers(SemaOpenMP::OpenMPVarListDataTy ) { Diag(Data.MapTypeModifiersLoc.back(), diag::err_omp_missing_comma) << "map type modifier"; +} else if (getLangOpts().OpenMP >= 60 && MapKind != OMPC_MAP_unknown) { + if (!HasMapType) { +HasMapType = true; +Data.ExtraModifier = MapKind; +MapKind = OMPC_MAP_unknown; +PreMapLoc = Tok.getLocation(); +PreMapName = Tok.getIdentifierInfo()->getName(); + } else { +Diag(Tok, diag::err_omp_more_one_map_type); +Diag(PreMapLoc, diag::note_previous_map_type_specified_here) +<< PreMapName; + } + ConsumeToken(); } else { // For the case of unknown map-type-modifier or a map-type. // Map-type is followed by a colon; the function returns when it @@ -4267,8 +4287,14 @@ bool Parser::parseMapTypeModifiers(SemaOpenMP::OpenMPVarListDataTy ) { continue; } // Potential map-type token as it is followed by a colon. - if (PP.LookAhead(0).is(tok::colon)) -return false; + if (PP.LookAhead(0).is(tok::colon)) { +if (getLangOpts().OpenMP >= 60) { + break; +} else { + return false; +} + } + Diag(Tok, diag::err_omp_unknown_map_type_modifier) << (getLangOpts().OpenMP >= 51 ? (getLangOpts().OpenMP >= 52 ? 2 : 1)
[clang] [Clang][AArch64] Fixed incorrect _BitInt alignment (PR #90602)
@@ -1674,4 +1679,4 @@ void RenderScript64TargetInfo::getTargetDefines(const LangOptions , MacroBuilder ) const { Builder.defineMacro("__RENDERSCRIPT__"); AArch64leTargetInfo::getTargetDefines(Opts, Builder); -} +} efriedma-quic wrote: Missing newline? https://github.com/llvm/llvm-project/pull/90602 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Fixed incorrect _BitInt alignment (PR #90602)
@@ -518,6 +518,16 @@ class TargetInfo : public TransferrableTargetInfo, /// getInt128Align() - Returns the alignment of Int128. unsigned getInt128Align() const { return Int128Align; } + /// getBitIntAlign/Width - Return aligned size of '_BitInt' and + /// 'unsigned _BitInt' for this target, in bits. + unsigned getBitIntWidth(unsigned NumBits) const { +return llvm::alignTo(NumBits, getBitIntAlign(NumBits)); + } + virtual unsigned getBitIntAlign(unsigned NumBits) const { efriedma-quic wrote: Instead of making this virtual, maybe it makes sense to add a field `std::optional BitIntMaxAlign` to TargetInfo? I expect the logic here besides the max width to be consistent across all targets. https://github.com/llvm/llvm-project/pull/90602 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Fixed incorrect _BitInt alignment (PR #90602)
https://github.com/efriedma-quic commented: LG https://github.com/llvm/llvm-project/pull/90602 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Fixed incorrect _BitInt alignment (PR #90602)
https://github.com/efriedma-quic edited https://github.com/llvm/llvm-project/pull/90602 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Don't allow comma in front of structural enum (PR #91056)
llvmbot wrote: @llvm/pr-subscribers-clang-format Author: Emilia Kond (rymiel) Changes Assume that a comma in front of `enum` means it is actually a part of an elaborated type in a template parameter list. Fixes https://github.com/llvm/llvm-project/issues/47782 --- Full diff: https://github.com/llvm/llvm-project/pull/91056.diff 2 Files Affected: - (modified) clang/lib/Format/UnwrappedLineParser.cpp (+3-2) - (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+4) ``diff diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index e8a8dd58d07eea..b5415fa9ecab55 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -1763,8 +1763,9 @@ void UnwrappedLineParser::parseStructuralElement( break; } case tok::kw_enum: - // Ignore if this is part of "template enum". - if (Previous && Previous->isOneOf(tok::less, tok::arrow)) { + // Ignore if this is part of "template enum" or + // "template <..., enum ...>". + if (Previous && Previous->isOneOf(tok::less, tok::arrow, tok::comma)) { nextToken(); break; } diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 01daf8dee505bc..b424424b85777b 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -489,6 +489,10 @@ TEST_F(TokenAnnotatorTest, UnderstandsStructs) { EXPECT_TOKEN(Tokens[24], tok::amp, TT_UnaryOperator); EXPECT_TOKEN(Tokens[27], tok::l_square, TT_ArraySubscriptLSquare); EXPECT_TOKEN(Tokens[32], tok::r_brace, TT_StructRBrace); + + Tokens = annotate("template struct S {};"); + ASSERT_EQ(Tokens.size(), 15u) << Tokens; + EXPECT_TOKEN(Tokens[11], tok::l_brace, TT_StructLBrace); } TEST_F(TokenAnnotatorTest, UnderstandsUnions) { `` https://github.com/llvm/llvm-project/pull/91056 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][dataflow] Fix crash when `operator=` result type is not destination type. (PR #90898)
@@ -556,14 +556,23 @@ class TransferVisitor : public ConstStmtVisitor { copyRecord(*LocSrc, *LocDst, Env); - // If the expr is a glvalue, we can reasonably assume the operator is - // returning T& and thus we can assign it `LocDst`. - if (S->isGLValue()) { + // The assignment operator can have an arbitrary return type. We model the + // return value only if the return type is the same as or a base class of + // the destination type. + if (S->getType().getCanonicalType().getUnqualifiedType() != + LocDst->getType().getCanonicalType().getUnqualifiedType()) { +auto ReturnDecl = S->getType()->getAsCXXRecordDecl(); +auto DstDecl = LocDst->getType()->getAsCXXRecordDecl(); +if (ReturnDecl == nullptr || DstDecl == nullptr) + return; +if (!DstDecl->isDerivedFrom(ReturnDecl)) Xazax-hun wrote: Would we want to create a fresh storage location here? https://github.com/llvm/llvm-project/pull/90898 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][dataflow] Fix crash when `operator=` result type is not destination type. (PR #90898)
https://github.com/Xazax-hun approved this pull request. https://github.com/llvm/llvm-project/pull/90898 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] solve crash due to function overloading. (PR #90255)
@@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -emit-llvm < %s efriedma-quic wrote: Have you seen https://llvm.org/docs/TestingGuide.html#regression-test-structure ? If you have any ideas for improving the documentation, please let me know (or better, propose a patch; it's generated from llvm/docs/TestingGuide.rst). https://github.com/llvm/llvm-project/pull/90255 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] cc1: Report an error for multiple actions unless separated by -main-file-name (PR #91140)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Fangrui Song (MaskRay) Changes When multiple actions are specified, the last one is used and others are overridden. This might lead to confusion if the user is used to driver's `-S -emit-llvm` behavior. ``` %clang_cc1 -S -emit-llvm a.c # -S is overridden %clang_cc1 -emit-llvm -S a.c # -emit-llvm is overridden %clang_cc1 -fsyntax-only -S a.c # -fsyntax-only is overridden ``` However, we want to continue supporting overriding the driver action with -Xclang: * `clang -c -Xclang -ast-dump a.c` (`%clang -cc1 -emit-obj ... -main-file-name a.c ... -ast-dump`) * `clang -c -xc++ -Xclang -emit-module stl.modulemap` As an exception, we allow -ast-dump* options to be composed together (e.g. `-ast-dump -ast-dump-lookups` in AST/ast-dump-lookups.cpp). --- Full diff: https://github.com/llvm/llvm-project/pull/91140.diff 3 Files Affected: - (modified) clang/include/clang/Basic/DiagnosticFrontendKinds.td (+2) - (modified) clang/lib/Frontend/CompilerInvocation.cpp (+24) - (added) clang/test/Frontend/multiple-actions.c (+7) ``diff diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td index fcffadacc8e631..48c174cfa9e8a5 100644 --- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td +++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td @@ -134,6 +134,8 @@ def err_fe_no_pch_in_dir : Error< "no suitable precompiled header file found in directory '%0'">; def err_fe_action_not_available : Error< "action %0 not compiled in">; +def err_fe_invalid_multiple_actions : Error< +"action %0 is specified, another action is not allowed: %1">; def err_fe_invalid_alignment : Error< "invalid value '%1' in '%0'; alignment must be a power of 2">; def err_fe_invalid_exception_model diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 8312abc3603953..4a4c02b03ce938 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -2841,6 +2841,30 @@ static bool ParseFrontendArgs(FrontendOptions , ArgList , } Opts.ProgramAction = *ProgramAction; + +// Catch common mistakes when multiple actions are specified for cc1 (e.g. +// -S -emit-llvm means -emit-llvm while -emit-llvm -S means -S). However, to +// support driver `-c -Xclang ACTION` (-cc1 -emit-llvm file -main-file-name +// X ACTION), we suppress the error when the two actions are separated by +// -main-file-name. +// +// As an exception, accept composable -ast-dump*. +if (!A->getSpelling().starts_with("-ast-dump")) { + const Arg *SavedAction = nullptr; + for (const Arg *AA : + Args.filtered(OPT_Action_Group, OPT_main_file_name)) { +if (AA->getOption().matches(OPT_main_file_name)) { + SavedAction = nullptr; +} else if (!SavedAction) { + SavedAction = AA; +} else { + if (!A->getOption().matches(OPT_ast_dump_EQ)) +Diags.Report(diag::err_fe_invalid_multiple_actions) +<< A->getSpelling() << SavedAction->getSpelling(); + break; +} + } +} } if (const Arg* A = Args.getLastArg(OPT_plugin)) { diff --git a/clang/test/Frontend/multiple-actions.c b/clang/test/Frontend/multiple-actions.c new file mode 100644 index 00..5dd9ac3c8754f7 --- /dev/null +++ b/clang/test/Frontend/multiple-actions.c @@ -0,0 +1,7 @@ +// RUN: not %clang_cc1 -S -emit-llvm -main-file-name %s 2>&1 | FileCheck %s --check-prefix=ERR1 --implicit-check-not=error: +// ERR1: error: action -emit-llvm is specified, another action is not allowed: -S + +// RUN: not %clang_cc1 -main-file-name %s -emit-llvm-only -emit-llvm -S 2>&1 | FileCheck %s --check-prefix=ERR2 --implicit-check-not=error: +// ERR2: error: action -S is specified, another action is not allowed: -emit-llvm-only + +// RUN: %clang_cc1 -S -main-file-name %s -emit-llvm -o /dev/null `` https://github.com/llvm/llvm-project/pull/91140 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] cc1: Report an error for multiple actions unless separated by -main-file-name (PR #91140)
https://github.com/MaskRay created https://github.com/llvm/llvm-project/pull/91140 When multiple actions are specified, the last one is used and others are overridden. This might lead to confusion if the user is used to driver's `-S -emit-llvm` behavior. ``` %clang_cc1 -S -emit-llvm a.c # -S is overridden %clang_cc1 -emit-llvm -S a.c # -emit-llvm is overridden %clang_cc1 -fsyntax-only -S a.c # -fsyntax-only is overridden ``` However, we want to continue supporting overriding the driver action with -Xclang: * `clang -c -Xclang -ast-dump a.c` (`%clang -cc1 -emit-obj ... -main-file-name a.c ... -ast-dump`) * `clang -c -xc++ -Xclang -emit-module stl.modulemap` As an exception, we allow -ast-dump* options to be composed together (e.g. `-ast-dump -ast-dump-lookups` in AST/ast-dump-lookups.cpp). >From c8677337fbcc6a1456466e65dd847f9317f16a4f Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sun, 5 May 2024 13:06:36 -0700 Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?= =?UTF-8?q?l=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.5-bogner --- .../clang/Basic/DiagnosticFrontendKinds.td| 2 ++ clang/lib/Frontend/CompilerInvocation.cpp | 24 +++ clang/test/Frontend/multiple-actions.c| 7 ++ 3 files changed, 33 insertions(+) create mode 100644 clang/test/Frontend/multiple-actions.c diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td index fcffadacc8e631..48c174cfa9e8a5 100644 --- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td +++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td @@ -134,6 +134,8 @@ def err_fe_no_pch_in_dir : Error< "no suitable precompiled header file found in directory '%0'">; def err_fe_action_not_available : Error< "action %0 not compiled in">; +def err_fe_invalid_multiple_actions : Error< +"action %0 is specified, another action is not allowed: %1">; def err_fe_invalid_alignment : Error< "invalid value '%1' in '%0'; alignment must be a power of 2">; def err_fe_invalid_exception_model diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 8312abc3603953..4a4c02b03ce938 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -2841,6 +2841,30 @@ static bool ParseFrontendArgs(FrontendOptions , ArgList , } Opts.ProgramAction = *ProgramAction; + +// Catch common mistakes when multiple actions are specified for cc1 (e.g. +// -S -emit-llvm means -emit-llvm while -emit-llvm -S means -S). However, to +// support driver `-c -Xclang ACTION` (-cc1 -emit-llvm file -main-file-name +// X ACTION), we suppress the error when the two actions are separated by +// -main-file-name. +// +// As an exception, accept composable -ast-dump*. +if (!A->getSpelling().starts_with("-ast-dump")) { + const Arg *SavedAction = nullptr; + for (const Arg *AA : + Args.filtered(OPT_Action_Group, OPT_main_file_name)) { +if (AA->getOption().matches(OPT_main_file_name)) { + SavedAction = nullptr; +} else if (!SavedAction) { + SavedAction = AA; +} else { + if (!A->getOption().matches(OPT_ast_dump_EQ)) +Diags.Report(diag::err_fe_invalid_multiple_actions) +<< A->getSpelling() << SavedAction->getSpelling(); + break; +} + } +} } if (const Arg* A = Args.getLastArg(OPT_plugin)) { diff --git a/clang/test/Frontend/multiple-actions.c b/clang/test/Frontend/multiple-actions.c new file mode 100644 index 00..5dd9ac3c8754f7 --- /dev/null +++ b/clang/test/Frontend/multiple-actions.c @@ -0,0 +1,7 @@ +// RUN: not %clang_cc1 -S -emit-llvm -main-file-name %s 2>&1 | FileCheck %s --check-prefix=ERR1 --implicit-check-not=error: +// ERR1: error: action -emit-llvm is specified, another action is not allowed: -S + +// RUN: not %clang_cc1 -main-file-name %s -emit-llvm-only -emit-llvm -S 2>&1 | FileCheck %s --check-prefix=ERR2 --implicit-check-not=error: +// ERR2: error: action -S is specified, another action is not allowed: -emit-llvm-only + +// RUN: %clang_cc1 -S -main-file-name %s -emit-llvm -o /dev/null ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Implement P2809: Trivial infinite loops are not Undefined Behavior (PR #90066)
@@ -908,6 +908,69 @@ void CodeGenFunction::EmitIfStmt(const IfStmt ) { incrementProfileCounter(); } +bool CodeGenFunction::checkIfLoopMustProgress(const Expr *ControllingExpression, + bool HasEmptyBody) { + if (CGM.getCodeGenOpts().getFiniteLoops() == + CodeGenOptions::FiniteLoopsKind::Never) +return false; + + // Now apply rules for plain C (see 6.8.5.6 in C11). + // Loops with constant conditions do not have to make progress in any C + // version. + // As an extension, we consisider loops whose constant expression + // can be constant-folded. + Expr::EvalResult Result; + bool CondIsConstInt = efriedma-quic wrote: So... we treat it as a manifestly constant-evaluated for the purpose of checking whether the loop is trivial, but then flips to not manifestly constant-evaluated for the actual evaluation at runtime? The wording could use some clarification... Due to the way Sema::CheckForImmediateInvocation works, once we decide an expression is not manifestly constant-evaluated, we can't actually constant-evaluate it, I think; the AST is modified. Maybe we can run constant-evaluation before Sema::CheckForImmediateInvocation runs, though. https://github.com/llvm/llvm-project/pull/90066 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 57f13b5 - [HLSL] Remove overridden -S
Author: Fangrui Song Date: 2024-05-05T12:53:34-07:00 New Revision: 57f13b51bdb373534ba5e507868b353a015107de URL: https://github.com/llvm/llvm-project/commit/57f13b51bdb373534ba5e507868b353a015107de DIFF: https://github.com/llvm/llvm-project/commit/57f13b51bdb373534ba5e507868b353a015107de.diff LOG: [HLSL] Remove overridden -S The cc1 option -S (https://reviews.llvm.org/D124983) is overridden by the latter -emit-llvm. Added: Modified: clang/lib/Driver/ToolChains/HLSL.cpp clang/test/Driver/dxc_fcgl.hlsl Removed: diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp b/clang/lib/Driver/ToolChains/HLSL.cpp index 1169b5d8c92dd6..558e4db46f8182 100644 --- a/clang/lib/Driver/ToolChains/HLSL.cpp +++ b/clang/lib/Driver/ToolChains/HLSL.cpp @@ -218,8 +218,7 @@ HLSLToolChain::TranslateArgs(const DerivedArgList , StringRef BoundArch, } } if (A->getOption().getID() == options::OPT_emit_pristine_llvm) { - // Translate fcgl into -S -emit-llvm and -disable-llvm-passes. - DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_S)); + // Translate -fcgl into -emit-llvm and -disable-llvm-passes. DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_emit_llvm)); DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_disable_llvm_passes)); diff --git a/clang/test/Driver/dxc_fcgl.hlsl b/clang/test/Driver/dxc_fcgl.hlsl index 567bad1bc13b5a..cfbf2503ddaaeb 100644 --- a/clang/test/Driver/dxc_fcgl.hlsl +++ b/clang/test/Driver/dxc_fcgl.hlsl @@ -1,6 +1,6 @@ // RUN: not %clang_dxc -fcgl -T lib_6_7 foo.hlsl -### %s 2>&1 | FileCheck %s -// Make sure fcgl option flag which translated into "-S" "-emit-llvm" "-disable-llvm-passes". +// Make sure fcgl option flag which translated into "-emit-llvm" "-disable-llvm-passes". // CHECK:"-S" // CHECK-SAME:"-emit-llvm" "-disable-llvm-passes" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)
https://github.com/dougsonos edited https://github.com/llvm/llvm-project/pull/84983 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)
@@ -4639,6 +4644,312 @@ class FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode { } }; +// -- + +class Decl; +class CXXMethodDecl; +struct FunctionEffectDiff; +class FunctionEffectsRef; +class FunctionEffectSet; dougsonos wrote: Cleaned up https://github.com/llvm/llvm-project/pull/84983 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)
@@ -4639,6 +4644,312 @@ class FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode { } }; +// -- + +class Decl; +class CXXMethodDecl; +struct FunctionEffectDiff; +class FunctionEffectsRef; +class FunctionEffectSet; + +/// Represents an abstract function effect, using just an enumeration describing +/// its kind. +class FunctionEffect { +public: + /// Identifies the particular effect. + enum class Kind : uint8_t { +None = 0, +NonBlocking = 1, +NonAllocating = 2, +Blocking = 3, +Allocating = 4 + }; + + /// Flags describing some behaviors of the effect. + using Flags = unsigned; + enum FlagBit : Flags { +// Can verification inspect callees' implementations? (e.g. nonblocking: +// yes, tcb+types: no). This also implies the need for 2nd-pass +// verification. +FE_InferrableOnCallees = 0x1, + +// Language constructs which effects can diagnose as disallowed. +FE_ExcludeThrow = 0x2, +FE_ExcludeCatch = 0x4, +FE_ExcludeObjCMessageSend = 0x8, +FE_ExcludeStaticLocalVars = 0x10, +FE_ExcludeThreadLocalVars = 0x20 + }; + +private: + LLVM_PREFERRED_TYPE(Kind) + unsigned FKind : 3; + + // Expansion: for hypothetical TCB+types, there could be one Kind for TCB, + // then ~16(?) bits "SubKind" to map to a specific named TCB. SubKind would + // be considered for uniqueness. + +public: + FunctionEffect() : FKind(unsigned(Kind::None)) {} + + explicit FunctionEffect(Kind K) : FKind(unsigned(K)) {} + + /// The kind of the effect. + Kind kind() const { return Kind(FKind); } + + /// Return the opposite kind, for effects which have opposites. + Kind oppositeKind() const; + + /// For serialization. + uint32_t toOpaqueInt32() const { return FKind; } + static FunctionEffect fromOpaqueInt32(uint32_t Value) { +return FunctionEffect(Kind(Value)); + } + + /// Flags describing some behaviors of the effect. + Flags flags() const { +switch (kind()) { +case Kind::NonBlocking: + return FE_InferrableOnCallees | FE_ExcludeThrow | FE_ExcludeCatch | + FE_ExcludeObjCMessageSend | FE_ExcludeStaticLocalVars | + FE_ExcludeThreadLocalVars; +case Kind::NonAllocating: + // Same as NonBlocking, except without FE_ExcludeStaticLocalVars + return FE_InferrableOnCallees | FE_ExcludeThrow | FE_ExcludeCatch | + FE_ExcludeObjCMessageSend | FE_ExcludeThreadLocalVars; +case Kind::Blocking: +case Kind::Allocating: + return 0; +case Kind::None: + break; +} +llvm_unreachable("unknown effect kind"); + } + + /// The description printed in diagnostics, e.g. 'nonblocking'. + StringRef name() const; + + /// Return true if the effect is allowed to be inferred on the callee, + /// which is either a FunctionDecl or BlockDecl. + /// This is only used if the effect has FE_InferrableOnCallees flag set. + /// Example: This allows nonblocking(false) to prevent inference for the + /// function. + bool canInferOnFunction(const Decl ) const; + + // Return false for success. When true is returned for a direct call, then the + // FE_InferrableOnCallees flag may trigger inference rather than an immediate + // diagnostic. Caller should be assumed to have the effect (it may not have it + // explicitly when inferring). + bool shouldDiagnoseFunctionCall(bool Direct, + ArrayRef CalleeFX) const; + + friend bool operator==(const FunctionEffect , const FunctionEffect ) { +return LHS.FKind == RHS.FKind; + } + friend bool operator!=(const FunctionEffect , const FunctionEffect ) { +return !(LHS == RHS); + } + friend bool operator<(const FunctionEffect , const FunctionEffect ) { +return LHS.FKind < RHS.FKind; + } +}; + +/// Wrap a function effect's condition expression in another struct so +/// that FunctionProtoType's TrailingObjects can treat it separately. +class FunctionEffectCondition { + Expr *Cond = nullptr; // if null, unconditional + +public: + FunctionEffectCondition() = default; + FunctionEffectCondition(Expr *E) : Cond(E) {} // implicit OK + + Expr *expr() const { return Cond; } + + bool operator==(const FunctionEffectCondition ) const { +return Cond == RHS.Cond; + } +}; + +/// A FunctionEffect plus a potential boolean expression determining whether +/// the effect is declared (e.g. nonblocking(expr)). Generally the condition +/// expression when present, is dependent. +struct FunctionEffectWithCondition { + FunctionEffect Effect; + FunctionEffectCondition Cond; + + /// Return a textual description of the effect, and its condition, if any. + std::string description() const; +}; + +struct FunctionEffectDiff { dougsonos wrote: Moved to Sema https://github.com/llvm/llvm-project/pull/84983 ___ cfe-commits mailing list cfe-commits@lists.llvm.org
[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)
@@ -4639,6 +4644,312 @@ class FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode { } }; +// -- + +class Decl; +class CXXMethodDecl; +struct FunctionEffectDiff; +class FunctionEffectsRef; +class FunctionEffectSet; + +/// Represents an abstract function effect, using just an enumeration describing +/// its kind. +class FunctionEffect { +public: + /// Identifies the particular effect. + enum class Kind : uint8_t { +None = 0, +NonBlocking = 1, +NonAllocating = 2, +Blocking = 3, +Allocating = 4 + }; + + /// Flags describing some behaviors of the effect. + using Flags = unsigned; + enum FlagBit : Flags { +// Can verification inspect callees' implementations? (e.g. nonblocking: +// yes, tcb+types: no). This also implies the need for 2nd-pass +// verification. +FE_InferrableOnCallees = 0x1, + +// Language constructs which effects can diagnose as disallowed. +FE_ExcludeThrow = 0x2, +FE_ExcludeCatch = 0x4, +FE_ExcludeObjCMessageSend = 0x8, +FE_ExcludeStaticLocalVars = 0x10, +FE_ExcludeThreadLocalVars = 0x20 + }; + +private: + LLVM_PREFERRED_TYPE(Kind) + unsigned FKind : 3; + + // Expansion: for hypothetical TCB+types, there could be one Kind for TCB, + // then ~16(?) bits "SubKind" to map to a specific named TCB. SubKind would + // be considered for uniqueness. + +public: + FunctionEffect() : FKind(unsigned(Kind::None)) {} + + explicit FunctionEffect(Kind K) : FKind(unsigned(K)) {} + + /// The kind of the effect. + Kind kind() const { return Kind(FKind); } + + /// Return the opposite kind, for effects which have opposites. + Kind oppositeKind() const; + + /// For serialization. + uint32_t toOpaqueInt32() const { return FKind; } + static FunctionEffect fromOpaqueInt32(uint32_t Value) { +return FunctionEffect(Kind(Value)); + } + + /// Flags describing some behaviors of the effect. + Flags flags() const { +switch (kind()) { +case Kind::NonBlocking: + return FE_InferrableOnCallees | FE_ExcludeThrow | FE_ExcludeCatch | + FE_ExcludeObjCMessageSend | FE_ExcludeStaticLocalVars | + FE_ExcludeThreadLocalVars; +case Kind::NonAllocating: + // Same as NonBlocking, except without FE_ExcludeStaticLocalVars + return FE_InferrableOnCallees | FE_ExcludeThrow | FE_ExcludeCatch | + FE_ExcludeObjCMessageSend | FE_ExcludeThreadLocalVars; +case Kind::Blocking: +case Kind::Allocating: + return 0; +case Kind::None: + break; +} +llvm_unreachable("unknown effect kind"); + } + + /// The description printed in diagnostics, e.g. 'nonblocking'. + StringRef name() const; + + /// Return true if the effect is allowed to be inferred on the callee, + /// which is either a FunctionDecl or BlockDecl. + /// This is only used if the effect has FE_InferrableOnCallees flag set. + /// Example: This allows nonblocking(false) to prevent inference for the + /// function. + bool canInferOnFunction(const Decl ) const; + + // Return false for success. When true is returned for a direct call, then the + // FE_InferrableOnCallees flag may trigger inference rather than an immediate + // diagnostic. Caller should be assumed to have the effect (it may not have it + // explicitly when inferring). + bool shouldDiagnoseFunctionCall(bool Direct, + ArrayRef CalleeFX) const; + + friend bool operator==(const FunctionEffect , const FunctionEffect ) { +return LHS.FKind == RHS.FKind; + } + friend bool operator!=(const FunctionEffect , const FunctionEffect ) { +return !(LHS == RHS); + } + friend bool operator<(const FunctionEffect , const FunctionEffect ) { +return LHS.FKind < RHS.FKind; + } +}; + +/// Wrap a function effect's condition expression in another struct so +/// that FunctionProtoType's TrailingObjects can treat it separately. +class FunctionEffectCondition { + Expr *Cond = nullptr; // if null, unconditional + +public: + FunctionEffectCondition() = default; + FunctionEffectCondition(Expr *E) : Cond(E) {} // implicit OK + + Expr *expr() const { return Cond; } + + bool operator==(const FunctionEffectCondition ) const { +return Cond == RHS.Cond; + } +}; + +/// A FunctionEffect plus a potential boolean expression determining whether +/// the effect is declared (e.g. nonblocking(expr)). Generally the condition +/// expression when present, is dependent. +struct FunctionEffectWithCondition { + FunctionEffect Effect; + FunctionEffectCondition Cond; + + /// Return a textual description of the effect, and its condition, if any. + std::string description() const; +}; + +struct FunctionEffectDiff { + enum class Kind { Added, Removed, ConditionMismatch }; + + FunctionEffect::Kind EffectKind; + Kind DiffKind; + FunctionEffectWithCondition Old; // invalid when Added + FunctionEffectWithCondition
[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)
@@ -4639,6 +4644,312 @@ class FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode { } }; +// -- + +class Decl; +class CXXMethodDecl; +struct FunctionEffectDiff; +class FunctionEffectsRef; +class FunctionEffectSet; + +/// Represents an abstract function effect, using just an enumeration describing +/// its kind. +class FunctionEffect { +public: + /// Identifies the particular effect. + enum class Kind : uint8_t { +None = 0, +NonBlocking = 1, +NonAllocating = 2, +Blocking = 3, +Allocating = 4 + }; + + /// Flags describing some behaviors of the effect. + using Flags = unsigned; + enum FlagBit : Flags { +// Can verification inspect callees' implementations? (e.g. nonblocking: +// yes, tcb+types: no). This also implies the need for 2nd-pass +// verification. +FE_InferrableOnCallees = 0x1, + +// Language constructs which effects can diagnose as disallowed. +FE_ExcludeThrow = 0x2, +FE_ExcludeCatch = 0x4, +FE_ExcludeObjCMessageSend = 0x8, +FE_ExcludeStaticLocalVars = 0x10, +FE_ExcludeThreadLocalVars = 0x20 + }; + +private: + LLVM_PREFERRED_TYPE(Kind) + unsigned FKind : 3; + + // Expansion: for hypothetical TCB+types, there could be one Kind for TCB, + // then ~16(?) bits "SubKind" to map to a specific named TCB. SubKind would + // be considered for uniqueness. + +public: + FunctionEffect() : FKind(unsigned(Kind::None)) {} + + explicit FunctionEffect(Kind K) : FKind(unsigned(K)) {} + + /// The kind of the effect. + Kind kind() const { return Kind(FKind); } + + /// Return the opposite kind, for effects which have opposites. + Kind oppositeKind() const; + + /// For serialization. + uint32_t toOpaqueInt32() const { return FKind; } + static FunctionEffect fromOpaqueInt32(uint32_t Value) { +return FunctionEffect(Kind(Value)); + } + + /// Flags describing some behaviors of the effect. + Flags flags() const { +switch (kind()) { +case Kind::NonBlocking: + return FE_InferrableOnCallees | FE_ExcludeThrow | FE_ExcludeCatch | + FE_ExcludeObjCMessageSend | FE_ExcludeStaticLocalVars | + FE_ExcludeThreadLocalVars; +case Kind::NonAllocating: + // Same as NonBlocking, except without FE_ExcludeStaticLocalVars + return FE_InferrableOnCallees | FE_ExcludeThrow | FE_ExcludeCatch | + FE_ExcludeObjCMessageSend | FE_ExcludeThreadLocalVars; +case Kind::Blocking: +case Kind::Allocating: + return 0; +case Kind::None: + break; +} +llvm_unreachable("unknown effect kind"); + } + + /// The description printed in diagnostics, e.g. 'nonblocking'. + StringRef name() const; + + /// Return true if the effect is allowed to be inferred on the callee, + /// which is either a FunctionDecl or BlockDecl. + /// This is only used if the effect has FE_InferrableOnCallees flag set. + /// Example: This allows nonblocking(false) to prevent inference for the + /// function. + bool canInferOnFunction(const Decl ) const; + + // Return false for success. When true is returned for a direct call, then the + // FE_InferrableOnCallees flag may trigger inference rather than an immediate + // diagnostic. Caller should be assumed to have the effect (it may not have it + // explicitly when inferring). + bool shouldDiagnoseFunctionCall(bool Direct, + ArrayRef CalleeFX) const; + + friend bool operator==(const FunctionEffect , const FunctionEffect ) { +return LHS.FKind == RHS.FKind; + } + friend bool operator!=(const FunctionEffect , const FunctionEffect ) { +return !(LHS == RHS); + } + friend bool operator<(const FunctionEffect , const FunctionEffect ) { +return LHS.FKind < RHS.FKind; + } +}; + +/// Wrap a function effect's condition expression in another struct so +/// that FunctionProtoType's TrailingObjects can treat it separately. +class FunctionEffectCondition { + Expr *Cond = nullptr; // if null, unconditional + +public: + FunctionEffectCondition() = default; + FunctionEffectCondition(Expr *E) : Cond(E) {} // implicit OK + + Expr *expr() const { return Cond; } + + bool operator==(const FunctionEffectCondition ) const { +return Cond == RHS.Cond; + } +}; + +/// A FunctionEffect plus a potential boolean expression determining whether +/// the effect is declared (e.g. nonblocking(expr)). Generally the condition +/// expression when present, is dependent. +struct FunctionEffectWithCondition { + FunctionEffect Effect; + FunctionEffectCondition Cond; + + /// Return a textual description of the effect, and its condition, if any. + std::string description() const; +}; + +struct FunctionEffectDiff { + enum class Kind { Added, Removed, ConditionMismatch }; + + FunctionEffect::Kind EffectKind; + Kind DiffKind; + FunctionEffectWithCondition Old; // invalid when Added + FunctionEffectWithCondition
[clang] [alpha.webkit.UncountedCallArgsChecker] Allow trivial operator++ (PR #91102)
https://github.com/rniwa edited https://github.com/llvm/llvm-project/pull/91102 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [alpha.webkit.UncountedCallArgsChecker] Allow trivial operator++ (PR #91102)
https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/91102 >From b3ae3d7a2a8885777b691e7fde237f5745e764a1 Mon Sep 17 00:00:00 2001 From: Ryosuke Niwa Date: Sat, 4 May 2024 20:29:03 -0700 Subject: [PATCH 1/2] [alpha.webkit.UncountedCallArgsChecker] Allow trivial operator++ This PR adds the support for trivial operator++ implementations. T& operator++() and T operator++(int) are trivial if the calle is trivial. Also allow incrementing and decrementing of a POD member variable. --- .../Checkers/WebKit/PtrTypesSemantics.cpp | 17 ++- .../Checkers/WebKit/uncounted-obj-arg.cpp | 28 +++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp index 6901dbb415bf76..c219172477a621 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp @@ -316,10 +316,15 @@ class TrivialFunctionAnalysisVisitor if (UO->isIncrementOp() || UO->isDecrementOp()) { // Allow increment or decrement of a POD type. - if (auto *RefExpr = dyn_cast(UO->getSubExpr())) { + auto *SubExpr = UO->getSubExpr(); + if (auto *RefExpr = dyn_cast(SubExpr)) { if (auto *Decl = dyn_cast(RefExpr->getDecl())) return Decl->isLocalVarDeclOrParm() && Decl->getType().isPODType(Decl->getASTContext()); + } else if (auto *ME = dyn_cast(SubExpr)) { +if (auto *Decl = ME->getMemberDecl()) + return Visit(ME->getBase()) && + Decl->getType().isPODType(Decl->getASTContext()); } } // Other operators are non-trivial. @@ -405,6 +410,16 @@ class TrivialFunctionAnalysisVisitor return TrivialFunctionAnalysis::isTrivialImpl(Callee, Cache); } + bool VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *OCE) { +if (!checkArguments(OCE)) + return false; +auto *Callee = OCE->getCalleeDecl(); +if (!Callee) + return false; +// Recursively descend into the callee to confirm that it's trivial as well. +return TrivialFunctionAnalysis::isTrivialImpl(Callee, Cache); + } + bool VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E) { if (auto *Expr = E->getExpr()) { if (!Visit(Expr)) diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp index 63a68a994a5c64..2816a9cb823649 100644 --- a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp +++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp @@ -137,11 +137,26 @@ class Number { Number(int v) : v(v) { } Number(double); Number operator+(const Number&); + Number& operator++() { ++v; return *this; } + Number operator++(int) { Number returnValue(v); ++v; return returnValue; } const int& value() const { return v; } + void someMethod(); + private: int v; }; +class ComplexNumber { +public: + ComplexNumber() : real(0), complex(0) { } + ComplexNumber& operator++() { real.someMethod(); return *this; } + ComplexNumber operator++(int); + +private: + Number real; + Number complex; +}; + class RefCounted { public: void ref() const; @@ -208,6 +223,9 @@ class RefCounted { unsigned trivial32() { return sizeof(int); } unsigned trivial33() { return ~0xff; } template unsigned trivial34() { return v; } + void trivial35() { v++; } + void trivial36() { ++(*number); } + void trivial37() { (*number)++; } static RefCounted& singleton() { static RefCounted s_RefCounted; @@ -282,9 +300,12 @@ class RefCounted { int nonTrivial13() { return ~otherFunction(); } int nonTrivial14() { int r = 0xff; r |= otherFunction(); return r; } + void nonTrivial15() { ++complex; } + void nonTrivial16() { complex++; } unsigned v { 0 }; Number* number { nullptr }; + ComplexNumber complex; Enum enumValue { Enum::Value1 }; }; @@ -340,6 +361,9 @@ class UnrelatedClass { getFieldTrivial().trivial32(); // no-warning getFieldTrivial().trivial33(); // no-warning getFieldTrivial().trivial34<7>(); // no-warning +getFieldTrivial().trivial35(); // no-warning +getFieldTrivial().trivial36(); // no-warning +getFieldTrivial().trivial37(); // no-warning RefCounted::singleton().trivial18(); // no-warning RefCounted::singleton().someFunction(); // no-warning @@ -374,6 +398,10 @@ class UnrelatedClass { // expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} getFieldTrivial().nonTrivial14(); // expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} +getFieldTrivial().nonTrivial15(); +// expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}} +getFieldTrivial().nonTrivial16(); +// expected-warning@-1{{Call argument for 'this' parameter is
[clang-tools-extra] [clang-tidy] new check misc-use-internal-linkage (PR #90830)
https://github.com/5chmidti edited https://github.com/llvm/llvm-project/pull/90830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] new check misc-use-internal-linkage (PR #90830)
https://github.com/5chmidti edited https://github.com/llvm/llvm-project/pull/90830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] new check misc-use-internal-linkage (PR #90830)
@@ -0,0 +1,79 @@ +//===--- UseInternalLinkageCheck.cpp - clang-tidy--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "UseInternalLinkageCheck.h" +#include "clang/AST/Decl.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/ASTMatchers/ASTMatchers.h" +#include "clang/ASTMatchers/ASTMatchersMacros.h" +#include "clang/Basic/Specifiers.h" +#include "llvm/ADT/STLExtras.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::misc { + +namespace { + +AST_POLYMORPHIC_MATCHER(isFirstDecl, +AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl, +VarDecl)) { + return Node.isFirstDecl(); +} + +AST_MATCHER(Decl, isInMainFile) { + return llvm::all_of(Node.redecls(), [&](const Decl *D) { +return Finder->getASTContext().getSourceManager().isInMainFile( +D->getLocation()); + }); +} + +AST_POLYMORPHIC_MATCHER(isExternStorageClass, +AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl, +VarDecl)) { + return Node.getStorageClass() == SC_Extern; +} + +} // namespace + +void UseInternalLinkageCheck::registerMatchers(MatchFinder *Finder) { + auto Common = allOf(isFirstDecl(), isInMainFile(), + unless(anyOf( + // 1. internal linkage + isStaticStorageClass(), isInAnonymousNamespace(), + // 2. explicit external linkage + isExternStorageClass(), isExternC(), + // 3. template + isExplicitTemplateSpecialization(), + clang::ast_matchers::isTemplateInstantiation(), 5chmidti wrote: Template instantiations will already be ignored because of the traversal kind https://github.com/llvm/llvm-project/pull/90830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] new check misc-use-internal-linkage (PR #90830)
https://github.com/5chmidti commented: Regarding unit build: `google-global-names-in-headers` is one of the checks that check file extensions: https://github.com/llvm/llvm-project/blob/d33937b6236767137a1ec3393d0933f10eed4ffe/clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp#L42-L44 Nice that there is a check for this now, it looks like there are a few instances of this issue in LLVM as well. https://github.com/llvm/llvm-project/pull/90830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] new check misc-use-internal-linkage (PR #90830)
https://github.com/5chmidti edited https://github.com/llvm/llvm-project/pull/90830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] new check misc-use-internal-linkage (PR #90830)
@@ -0,0 +1,79 @@ +//===--- UseInternalLinkageCheck.cpp - clang-tidy--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "UseInternalLinkageCheck.h" +#include "clang/AST/Decl.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/ASTMatchers/ASTMatchers.h" +#include "clang/ASTMatchers/ASTMatchersMacros.h" +#include "clang/Basic/Specifiers.h" +#include "llvm/ADT/STLExtras.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::misc { + +namespace { + +AST_POLYMORPHIC_MATCHER(isFirstDecl, +AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl, +VarDecl)) { + return Node.isFirstDecl(); +} 5chmidti wrote: You don't need to make this a polymorphic matcher, `isFirstDecl` is part of `clang::Decl`. https://github.com/llvm/llvm-project/pull/90830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] new check misc-use-internal-linkage (PR #90830)
@@ -0,0 +1,79 @@ +//===--- UseInternalLinkageCheck.cpp - clang-tidy--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "UseInternalLinkageCheck.h" +#include "clang/AST/Decl.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/ASTMatchers/ASTMatchers.h" +#include "clang/ASTMatchers/ASTMatchersMacros.h" +#include "clang/Basic/Specifiers.h" +#include "llvm/ADT/STLExtras.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::misc { + +namespace { + +AST_POLYMORPHIC_MATCHER(isFirstDecl, +AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl, +VarDecl)) { + return Node.isFirstDecl(); +} + +AST_MATCHER(Decl, isInMainFile) { + return llvm::all_of(Node.redecls(), [&](const Decl *D) { +return Finder->getASTContext().getSourceManager().isInMainFile( +D->getLocation()); + }); +} + +AST_POLYMORPHIC_MATCHER(isExternStorageClass, +AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl, +VarDecl)) { + return Node.getStorageClass() == SC_Extern; +} + +} // namespace + +void UseInternalLinkageCheck::registerMatchers(MatchFinder *Finder) { + auto Common = allOf(isFirstDecl(), isInMainFile(), + unless(anyOf( + // 1. internal linkage + isStaticStorageClass(), isInAnonymousNamespace(), + // 2. explicit external linkage + isExternStorageClass(), isExternC(), + // 3. template + isExplicitTemplateSpecialization(), + clang::ast_matchers::isTemplateInstantiation(), + // 4. friend + hasAncestor(friendDecl(); + Finder->addMatcher( + functionDecl(Common, unless(cxxMethodDecl()), unless(isMain())) + .bind("fn"), + this); + Finder->addMatcher(varDecl(Common, hasGlobalStorage()).bind("var"), this); +} + +static constexpr StringRef Message = +"%0 %1 can be made static or moved into an anonymous namespace " +"to enforce internal linkage"; + +void UseInternalLinkageCheck::check(const MatchFinder::MatchResult ) { + if (const auto *FD = Result.Nodes.getNodeAs("fn")) { +diag(FD->getLocation(), Message) << "function" << FD; +return; + } + if (const auto *VD = Result.Nodes.getNodeAs("var")) { +diag(VD->getLocation(), Message) << "variable" << VD; +return; + } 5chmidti wrote: Please stream `SourceRange`s into the diagnostics. For the `FunctionDecl` you could use `SourceRange(FD->getBeginLoc(), FD->getTypeSpecEndLoc())`, which would not highlight the body (that would be quite noisy). https://github.com/llvm/llvm-project/pull/90830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] d33937b - [test] %clang_cc1: remove redundant actions
Author: Fangrui Song Date: 2024-05-05T11:42:04-07:00 New Revision: d33937b6236767137a1ec3393d0933f10eed4ffe URL: https://github.com/llvm/llvm-project/commit/d33937b6236767137a1ec3393d0933f10eed4ffe DIFF: https://github.com/llvm/llvm-project/commit/d33937b6236767137a1ec3393d0933f10eed4ffe.diff LOG: [test] %clang_cc1: remove redundant actions ParseFrontendArgs takes the last OPT_Action_Group option. The other actions are overridden. Added: Modified: clang/test/CodeGen/SystemZ/align-systemz-02.c clang/test/CodeGen/thinlto-distributed-cfi-devirt.ll clang/test/CodeGen/thinlto-distributed-cfi.ll clang/test/CodeGenCXX/module-intializer.cpp clang/test/Lexer/raw-string-dlim-invalid.cpp clang/test/Modules/prune-non-affecting-module-map-files-textual.c clang/test/PCH/empty-with-headers.c clang/test/PCH/ms-if-exists.cpp Removed: diff --git a/clang/test/CodeGen/SystemZ/align-systemz-02.c b/clang/test/CodeGen/SystemZ/align-systemz-02.c index 013faea61ada24..4b2d32649226e0 100644 --- a/clang/test/CodeGen/SystemZ/align-systemz-02.c +++ b/clang/test/CodeGen/SystemZ/align-systemz-02.c @@ -1,10 +1,10 @@ // RUN: %clang_cc1 -triple s390x-linux-gnu %s -o - -target-feature +vector -emit-llvm \ // RUN:| FileCheck %s -check-prefix=VECIR -// RUN: %clang_cc1 -triple s390x-linux-gnu %s -o - -target-feature +vector -emit-obj -S \ +// RUN: %clang_cc1 -triple s390x-linux-gnu %s -o - -target-feature +vector -S \ // RUN:| FileCheck %s -check-prefix=VECASM // RUN: %clang_cc1 -triple s390x-linux-gnu %s -o - -target-feature -vector -emit-llvm \ // RUN:| FileCheck %s -check-prefix=SCALIR -// RUN: %clang_cc1 -triple s390x-linux-gnu %s -o - -target-feature -vector -emit-obj -S \ +// RUN: %clang_cc1 -triple s390x-linux-gnu %s -o - -target-feature -vector -S \ // RUN:| FileCheck %s -check-prefix=SCALASM // REQUIRES: systemz-registered-target diff --git a/clang/test/CodeGen/thinlto-distributed-cfi-devirt.ll b/clang/test/CodeGen/thinlto-distributed-cfi-devirt.ll index 433fd1fe204304..acbcdcdb4fd024 100644 --- a/clang/test/CodeGen/thinlto-distributed-cfi-devirt.ll +++ b/clang/test/CodeGen/thinlto-distributed-cfi-devirt.ll @@ -38,12 +38,12 @@ ; CHECK-DIS: ^2 = typeid: (name: "_ZTS1A", summary: (typeTestRes: (kind: allOnes, sizeM1BitWidth: 7), wpdResolutions: ((offset: 0, wpdRes: (kind: branchFunnel)), (offset: 8, wpdRes: (kind: singleImpl, singleImplName: "_ZN1A1nEi") ; guid = 7004155349499253778 ; RUN: %clang_cc1 -triple x86_64-grtev4-linux-gnu \ -; RUN: -emit-obj -fthinlto-index=%t.o.thinlto.bc -O2 -Rpass=wholeprogramdevirt \ +; RUN: -fthinlto-index=%t.o.thinlto.bc -O2 -Rpass=wholeprogramdevirt \ ; RUN: -emit-llvm -o - -x ir %t.o 2>&1 | FileCheck %s --check-prefixes=CHECK-IR --check-prefixes=REMARKS ; Check that the devirtualization is suppressed via -wholeprogramdevirt-skip ; RUN: %clang_cc1 -triple x86_64-grtev4-linux-gnu -mllvm -wholeprogramdevirt-skip=_ZN1A1nEi \ -; RUN: -emit-obj -fthinlto-index=%t.o.thinlto.bc -O2 -Rpass=wholeprogramdevirt \ +; RUN: -fthinlto-index=%t.o.thinlto.bc -O2 -Rpass=wholeprogramdevirt \ ; RUN: -emit-llvm -o - -x ir %t.o 2>&1 | FileCheck %s --check-prefixes=SKIP-IR --check-prefixes=SKIP-REMARKS ; REMARKS: single-impl: devirtualized a call to _ZN1A1nEi diff --git a/clang/test/CodeGen/thinlto-distributed-cfi.ll b/clang/test/CodeGen/thinlto-distributed-cfi.ll index 47e56c091a6120..6023ba8f32df91 100644 --- a/clang/test/CodeGen/thinlto-distributed-cfi.ll +++ b/clang/test/CodeGen/thinlto-distributed-cfi.ll @@ -28,7 +28,7 @@ ; CHECK-DIS: ^2 = typeid: (name: "_ZTS1A", summary: (typeTestRes: (kind: single, sizeM1BitWidth: 0))) ; guid = 7004155349499253778 ; RUN: %clang_cc1 -triple x86_64-grtev4-linux-gnu \ -; RUN: -emit-obj -fthinlto-index=%t.o.thinlto.bc \ +; RUN: -fthinlto-index=%t.o.thinlto.bc \ ; RUN: -emit-llvm -o - -x ir %t.o | FileCheck %s --check-prefixes=CHECK-IR ; Ensure that backend does not fail generating native code. diff --git a/clang/test/CodeGenCXX/module-intializer.cpp b/clang/test/CodeGenCXX/module-intializer.cpp index 2be1d5a49843c9..318250a653a7c2 100644 --- a/clang/test/CodeGenCXX/module-intializer.cpp +++ b/clang/test/CodeGenCXX/module-intializer.cpp @@ -14,7 +14,7 @@ // RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 M-Part.cpp \ // RUN:-emit-module-interface -o M-Part.pcm -// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 M-Part.pcm -S \ +// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 M-Part.pcm \ // RUN:-emit-llvm -o - | FileCheck %s --check-prefix=CHECK-P // RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 M.cpp \ diff --git a/clang/test/Lexer/raw-string-dlim-invalid.cpp b/clang/test/Lexer/raw-string-dlim-invalid.cpp index da797f00a1d628..8928b398ceb76d 100644 --- a/clang/test/Lexer/raw-string-dlim-invalid.cpp +++
[clang-tools-extra] [clang-tidy] Add `modernize-use-uniform-initializer` check (PR #91124)
carlosgalvezp wrote: Consider also that this check should probably not apply to variables of type `auto`, see AUTOSAR rule A8-5-3. https://github.com/llvm/llvm-project/pull/91124 ___ 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 `modernize-use-uniform-initializer` check (PR #91124)
carlosgalvezp wrote: Regarding the problem of {} initialization and std::vector, I believe we could restrict this check to not warn on classes that have a constructor taking a `std:: initializer_list`. I believe AUTOSAR has an exception for that. https://github.com/llvm/llvm-project/pull/91124 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ARM] Armv8-R does not require fp64 or neon. (PR #88287)
chrisnc wrote: If there's no other feedback, could someone hit the merge button for me? https://github.com/llvm/llvm-project/pull/88287 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 7e59223 - [test] %clang_cc1: remove redundant actions
Author: Fangrui Song Date: 2024-05-05T10:46:06-07:00 New Revision: 7e59223ac4b045178c287a56154113d5989572f4 URL: https://github.com/llvm/llvm-project/commit/7e59223ac4b045178c287a56154113d5989572f4 DIFF: https://github.com/llvm/llvm-project/commit/7e59223ac4b045178c287a56154113d5989572f4.diff LOG: [test] %clang_cc1: remove redundant actions ParseFrontendArgs takes the last OPT_Action_Group option. The other actions are overridden. Added: Modified: clang/test/AST/arithmetic-fence-builtin.c clang/test/ASTMerge/codegen-exprs/test.c clang/test/CXX/module/module.private.frag/p1.cpp clang/test/CodeGen/PowerPC/builtins-ppc-fpconstrained.c clang/test/CodeGen/PowerPC/builtins-ppc-vec-ins-error.c clang/test/CodeGen/PowerPC/vector-bool-pixel-altivec-init-no-parentheses.c clang/test/CodeGen/PowerPC/vector-bool-pixel-altivec-init.c clang/test/CodeGen/PowerPC/vector-compat-pixel-bool-ternary.c clang/test/CodeGen/PowerPC/vector-compat-pixel-bool.c clang/test/CodeGen/PowerPC/vector-compat-ternary.c clang/test/CodeGen/PowerPC/vector-compat.c clang/test/CodeGen/aarch64-ABI-align-packed-assembly.c clang/test/CodeGen/aarch64-neon-intrinsics.c clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics-constrained.c clang/test/CodeGen/builtins-nvptx-native-half-type-err.c clang/test/CodeGen/builtins-nvptx-native-half-type.c clang/test/CodeGen/math-builtins-long.c clang/test/CodeGen/pch-dllexport.cpp clang/test/CodeGen/thinlto-loop-vectorize-pm.c clang/test/CodeGenCXX/module-intializer.cpp clang/test/CodeGenOpenCL/builtins-amdgcn-raytracing.cl clang/test/CodeGenSYCL/function-attrs.cpp clang/test/CoverageMapping/pr32679.cpp clang/test/Frontend/output-paths.c clang/test/Headers/ms-arm64-intrin.cpp clang/test/Modules/cxx20-10-5-ex1.cpp clang/test/Modules/cxx20-importing-function-bodies.cppm clang/test/Modules/cxx20-include-translation.cpp clang/test/Modules/eagerly-load-cxx-named-modules.cppm clang/test/Modules/load-module-with-errors.m clang/test/Modules/no-import-func-body.cppm clang/test/Modules/odr_using_dependent_name.cppm clang/test/Modules/pr59780.cppm clang/test/Modules/pr61067.cppm clang/test/SemaCUDA/call-kernel-from-kernel.cu clang/test/SemaCUDA/constexpr-variables.cu Removed: diff --git a/clang/test/AST/arithmetic-fence-builtin.c b/clang/test/AST/arithmetic-fence-builtin.c index acdefade0748a2..2450bb4d59d514 100644 --- a/clang/test/AST/arithmetic-fence-builtin.c +++ b/clang/test/AST/arithmetic-fence-builtin.c @@ -20,33 +20,31 @@ // RUN: | FileCheck %s --strict-whitespace --check-prefixes=CHECK,CHECK2 // // Tests with serialization: -// RUN: %clang_cc1 -ast-dump -triple i386-pc-linux-gnu -emit-pch -o %t %s +// RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-pch -o %t %s // RUN: %clang_cc1 -triple i386-pc-linux-gnu -include-pch %t -ast-dump-all /dev/null \ // RUN: | FileCheck %s --strict-whitespace // -// RUN: %clang_cc1 -ast-dump -triple aarch64-unknown-linux-gnu -emit-pch -o %t %s +// RUN: %clang_cc1 -triple aarch64-unknown-linux-gnu -emit-pch -o %t %s // RUN: %clang_cc1 -triple aarch64-unknown-linux-gnu -include-pch %t -ast-dump-all /dev/null \ // RUN: | FileCheck %s --strict-whitespace // -// RUN: %clang_cc1 -ast-dump -triple i386-pc-linux-gnu -DFAST -mreassociate %s \ +// RUN: %clang_cc1 -triple i386-pc-linux-gnu -DFAST -mreassociate %s \ // RUN: -emit-pch -o %t // RUN: %clang_cc1 -triple i386-pc-linux-gnu -include-pch %t -ast-dump-all /dev/null \ // RUN: | FileCheck %s --strict-whitespace --check-prefixes=CHECK,CHECK1 // -// RUN: %clang_cc1 -ast-dump -triple aarch64-unknown-linux-gnu -DFAST -mreassociate %s \ +// RUN: %clang_cc1 -triple aarch64-unknown-linux-gnu -DFAST -mreassociate %s \ // RUN: -emit-pch -o %t // RUN: %clang_cc1 -triple aarch64-unknown-linux-gnu -include-pch %t -ast-dump-all /dev/null \ // RUN: | FileCheck %s --strict-whitespace --check-prefixes=CHECK,CHECK1 // -// RUN: %clang_cc1 -ast-dump -triple i386-pc-linux-gnu -DFAST -mreassociate %s \ -// RUN: -fprotect-parens \ -// RUN: -emit-pch -o %t +// RUN: %clang_cc1 -triple i386-pc-linux-gnu -DFAST -mreassociate %s \ +// RUN: -fprotect-parens -emit-pch -o %t // RUN: %clang_cc1 -triple i386-pc-linux-gnu -include-pch %t -ast-dump-all /dev/null -fprotect-parens\ // RUN: | FileCheck %s --strict-whitespace --check-prefixes=CHECK,CHECK2 // -// RUN: %clang_cc1 -ast-dump -triple aarch64-unknown-linux-gnu -DFAST -mreassociate %s \ -// RUN: -fprotect-parens \ -// RUN: -emit-pch -o %t +// RUN: %clang_cc1 -triple aarch64-unknown-linux-gnu -DFAST -mreassociate %s \ +// RUN: -fprotect-parens -emit-pch -o %t // RUN: %clang_cc1 -triple aarch64-unknown-linux-gnu -include-pch %t -ast-dump-all /dev/null -fprotect-parens\ // RUN: | FileCheck %s --strict-whitespace --check-prefixes=CHECK,CHECK2
[clang] [clang] Distinguish unresolved templates in UnresolvedLookupExpr (PR #89019)
zyn0217 wrote: @aganea Oops, this is an oversight I think, because I don't build lldb locally nor run its tests... I'm proposing a PR https://github.com/llvm/llvm-project/pull/91132, can you help me confirm if that works? https://github.com/llvm/llvm-project/pull/89019 ___ 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 `modernize-use-uniform-initializer` check (PR #91124)
https://github.com/PiotrZSL requested changes to this pull request. Fix pointed out nits https://github.com/llvm/llvm-project/pull/91124 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits