[clang] 646d352 - [OpenMP][ASan] Enable ASan Instrumentation for AMDGPUOpenMPToolChain. (#124754)
Author: Amit Kumar Pandey Date: 2025-02-05T13:37:31+05:30 New Revision: 646d352ab0d0a9cfafa3f2c9c415b5773834ad5b URL: https://github.com/llvm/llvm-project/commit/646d352ab0d0a9cfafa3f2c9c415b5773834ad5b DIFF: https://github.com/llvm/llvm-project/commit/646d352ab0d0a9cfafa3f2c9c415b5773834ad5b.diff LOG: [OpenMP][ASan] Enable ASan Instrumentation for AMDGPUOpenMPToolChain. (#124754) Enable device code ASan instrumentation for openmp offload applications using option '-fsanitize=address'. Added: clang/test/Driver/amdgpu-openmp-sanitize-options.c Modified: clang/lib/Driver/ToolChains/AMDGPU.h clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp clang/lib/Driver/ToolChains/HIPAMD.cpp Removed: diff --git a/clang/lib/Driver/ToolChains/AMDGPU.h b/clang/lib/Driver/ToolChains/AMDGPU.h index aad6bc75dffafc4..bc941a40445ad04 100644 --- a/clang/lib/Driver/ToolChains/AMDGPU.h +++ b/clang/lib/Driver/ToolChains/AMDGPU.h @@ -146,9 +146,24 @@ class LLVM_LIBRARY_VISIBILITY ROCMToolChain : public AMDGPUToolChain { getCommonDeviceLibNames(const llvm::opt::ArgList &DriverArgs, const std::string &GPUArch, bool isOpenMP = false) const; + SanitizerMask getSupportedSanitizers() const override { return SanitizerKind::Address; } + + void diagnoseUnsupportedSanitizers(const llvm::opt::ArgList &Args) const { +if (!Args.hasFlag(options::OPT_fgpu_sanitize, options::OPT_fno_gpu_sanitize, + true)) + return; +auto &Diags = getDriver().getDiags(); +for (auto *A : Args.filtered(options::OPT_fsanitize_EQ)) { + SanitizerMask K = + parseSanitizerValue(A->getValue(), /*Allow Groups*/ false); + if (K != SanitizerKind::Address) +Diags.Report(clang::diag::warn_drv_unsupported_option_for_target) +<< A->getAsString(Args) << getTriple().str(); +} + } }; } // end namespace toolchains diff --git a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp index 24d244ba6f0e18b..00bf9c7338edd11 100644 --- a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp +++ b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp @@ -37,6 +37,8 @@ AMDGPUOpenMPToolChain::AMDGPUOpenMPToolChain(const Driver &D, // Lookup binaries into the driver directory, this is used to // discover the 'amdgpu-arch' executable. getProgramPaths().push_back(getDriver().Dir); + // Diagnose unsupported sanitizer options only once. + diagnoseUnsupportedSanitizers(Args); } void AMDGPUOpenMPToolChain::addClangTargetOptions( @@ -71,10 +73,10 @@ llvm::opt::DerivedArgList *AMDGPUOpenMPToolChain::TranslateArgs( const OptTable &Opts = getDriver().getOpts(); - for (Arg *A : Args) { -if (!llvm::is_contained(*DAL, A)) + for (Arg *A : Args) +if (!shouldSkipSanitizeOption(*this, Args, BoundArch, A) && +!llvm::is_contained(*DAL, A)) DAL->append(A); - } if (!BoundArch.empty()) { DAL->eraseArg(options::OPT_march_EQ); diff --git a/clang/lib/Driver/ToolChains/HIPAMD.cpp b/clang/lib/Driver/ToolChains/HIPAMD.cpp index 158a2520759846a..0e50eddd6b3d293 100644 --- a/clang/lib/Driver/ToolChains/HIPAMD.cpp +++ b/clang/lib/Driver/ToolChains/HIPAMD.cpp @@ -216,17 +216,8 @@ HIPAMDToolChain::HIPAMDToolChain(const Driver &D, const llvm::Triple &Triple, // Lookup binaries into the driver directory, this is used to // discover the clang-offload-bundler executable. getProgramPaths().push_back(getDriver().Dir); - // Diagnose unsupported sanitizer options only once. - if (!Args.hasFlag(options::OPT_fgpu_sanitize, options::OPT_fno_gpu_sanitize, -true)) -return; - for (auto *A : Args.filtered(options::OPT_fsanitize_EQ)) { -SanitizerMask K = parseSanitizerValue(A->getValue(), /*AllowGroups=*/false); -if (K != SanitizerKind::Address) - D.getDiags().Report(clang::diag::warn_drv_unsupported_option_for_target) - << A->getAsString(Args) << getTriple().str(); - } + diagnoseUnsupportedSanitizers(Args); } void HIPAMDToolChain::addClangTargetOptions( diff --git a/clang/test/Driver/amdgpu-openmp-sanitize-options.c b/clang/test/Driver/amdgpu-openmp-sanitize-options.c new file mode 100644 index 000..ac25d7fd802e1fb --- /dev/null +++ b/clang/test/Driver/amdgpu-openmp-sanitize-options.c @@ -0,0 +1,65 @@ +// REQUIRES: x86-registered-target, amdgpu-registered-target + +// Fail on invalid ROCm Path. +// RUN: not %clang -### --target=x86_64-unknown-linux-gnu -fopenmp --offload-arch=gfx908:xnack+ -fsanitize=address -fgpu-sanitize -nogpuinc --rocm-path=%S/Inputs/rocm-invalid %s 2>&1 \ +// RUN: | FileCheck --check-prefix=FAIL %s + +// Enable multiple sanitizer's apart from ASan with invalid rocm-path. +// RUN: not %clang -### --target=x86_64-unknown-linux-gnu -fopenmp --offload-arch=gfx908:xnack+ -fsanitize=addre
[clang] [compiler-rt] [profile] Add `%b` `LLVM_PROFILE_FILE` option for binary ID (PR #123963)
@@ -2917,7 +2918,7 @@ instrumentation: $ LLVM_PROFILE_FILE="code-%m.profraw" ./code See `this `_ section - about the ``%t``, and ``%c`` modifiers. + about the ``%b``, ``%t``, and ``%c`` modifiers. david-xl wrote: better add an %b use example here too. https://github.com/llvm/llvm-project/pull/123963 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenMP][ASan] Enable ASan Instrumentation for AMDGPUOpenMPToolChain. (PR #124754)
https://github.com/ampandey-1995 closed https://github.com/llvm/llvm-project/pull/124754 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add BreakBeforeTemplateClose option (PR #118046)
@@ -11224,6 +11224,254 @@ TEST_F(FormatTest, WrapsTemplateDeclarationsWithComments) { Style); } +TEST_F(FormatTest, BreakBeforeTemplateCloser) { + FormatStyle Style = getLLVMStyle(); + // Begin with tests covering the case where there is no constraint on the + // column limit. + Style.ColumnLimit = 0; + Style.BreakBeforeTemplateCloser = true; + // BreakBeforeTemplateCloser should NOT force template declarations onto + // multiple lines. + verifyFormat("template \n" + "void foo() {}", + Style); + verifyFormat("template \n" + "void foo() {}", + Style); + // It should add a line break before > if not already present: + verifyFormat("template <\n" + "typename Foo\n" + ">\n" + "void foo() {}", + "template <\n" + "typename Foo>\n" + "void foo() {}", + Style); + verifyFormat("template <\n" + "typename Foo,\n" + "typename Bar\n" + ">\n" + "void foo() {}", + "template <\n" + "typename Foo,\n" + "typename Bar>\n" + "void foo() {}", + Style); + // When within an indent scope, the > should be placed accordingly: + verifyFormat("struct Baz {\n" + " template <\n" + " typename Foo,\n" + " typename Bar\n" + " >\n" + " void foo() {}\n" + "};", + "struct Baz {\n" + " template <\n" + " typename Foo,\n" + " typename Bar>\n" + " void foo() {}\n" + "};", + Style); + + // Test from https://github.com/llvm/llvm-project/issues/80049: + verifyFormat( + "using type = std::remove_cv_t<\n" + "add_common_cv_reference<\n" + "std::common_type_t, std::decay_t>,\n" + "T0,\n" + "T1\n" + ">\n" + ">;", + "using type = std::remove_cv_t<\n" + "add_common_cv_reference<\n" + "std::common_type_t, std::decay_t>,\n" + "T0,\n" + "T1>>;", + Style); + + // Test lambda goes to next line: + verifyFormat("void foo() {\n" + " auto lambda = []<\n" + "typename T\n" + ">(T t) {\n" + " };\n" + "}", + "void foo() {\n" + " auto lambda = []<\n" + " typename T>(T t){\n" + " };\n" + "}", + Style); + // With no column limit, two parameters can go on the same line: + verifyFormat("void foo() {\n" + " auto lambda = []<\n" + "typename T, typename Foo\n" + ">(T t) {\n" + " };\n" + "}", + "void foo() {\n" + " auto lambda = []<\n" + " typename T, typename Foo>(T t){\n" + " };\n" + "}", + Style); + // Or on different lines: + verifyFormat("void foo() {\n" + " auto lambda = []<\n" + "typename T,\n" + "typename Foo\n" + ">(T t) {\n" + " };\n" + "}", + "void foo() {\n" + " auto lambda = []<\n" + " typename T,\n" + " typename Foo>(T t){\n" + " };\n" + "}", + Style); + + // Test template usage goes to next line too: + verifyFormat("void foo() {\n" + " myFunc<\n" + " T\n" + " >();\n" + "}", + "void foo() {\n" + " myFunc<\n" + " T>();\n" + "}", + Style); + + // Now test that it handles the cases when the column limit forces wrapping. + Style.ColumnLimit = 40; + // Breaks when the name is looong. Note that these names are exactly 1 + // character too long for the ColumnLimit. + verifyFormat("template <\n" + "typename Foo,\n" + "typename Barrr\n" + ">\n" + "void foo() {}", + Style); + // BlockIndent style is used when the ColumnLimit allows it: + verifyFormat("template \n" + "void foo() {}", + Style); + verifyFormat("template \n" + "void foo() {}", + Style); + // Additionally, long names should be split in one step: + verifyFormat("template <\n" + "typename Foo,\n" + "typename Barrr\n" + ">\n" + "void foo() {}", +
[clang] [clang-format] Add BreakBeforeTemplateClose option (PR #118046)
@@ -11224,6 +11224,254 @@ TEST_F(FormatTest, WrapsTemplateDeclarationsWithComments) { Style); } +TEST_F(FormatTest, BreakBeforeTemplateCloser) { + FormatStyle Style = getLLVMStyle(); + // Begin with tests covering the case where there is no constraint on the + // column limit. + Style.ColumnLimit = 0; + Style.BreakBeforeTemplateCloser = true; + // BreakBeforeTemplateCloser should NOT force template declarations onto + // multiple lines. + verifyFormat("template \n" + "void foo() {}", + Style); + verifyFormat("template \n" + "void foo() {}", + Style); + // It should add a line break before > if not already present: + verifyFormat("template <\n" + "typename Foo\n" + ">\n" + "void foo() {}", + "template <\n" + "typename Foo>\n" + "void foo() {}", + Style); + verifyFormat("template <\n" + "typename Foo,\n" + "typename Bar\n" + ">\n" + "void foo() {}", + "template <\n" + "typename Foo,\n" + "typename Bar>\n" + "void foo() {}", + Style); + // When within an indent scope, the > should be placed accordingly: + verifyFormat("struct Baz {\n" + " template <\n" + " typename Foo,\n" + " typename Bar\n" + " >\n" + " void foo() {}\n" + "};", + "struct Baz {\n" + " template <\n" + " typename Foo,\n" + " typename Bar>\n" + " void foo() {}\n" + "};", + Style); + + // Test from https://github.com/llvm/llvm-project/issues/80049: + verifyFormat( + "using type = std::remove_cv_t<\n" + "add_common_cv_reference<\n" + "std::common_type_t, std::decay_t>,\n" + "T0,\n" + "T1\n" + ">\n" + ">;", + "using type = std::remove_cv_t<\n" + "add_common_cv_reference<\n" + "std::common_type_t, std::decay_t>,\n" + "T0,\n" + "T1>>;", + Style); + + // Test lambda goes to next line: + verifyFormat("void foo() {\n" + " auto lambda = []<\n" + "typename T\n" + ">(T t) {\n" + " };\n" + "}", + "void foo() {\n" + " auto lambda = []<\n" + " typename T>(T t){\n" + " };\n" + "}", + Style); + // With no column limit, two parameters can go on the same line: + verifyFormat("void foo() {\n" + " auto lambda = []<\n" + "typename T, typename Foo\n" + ">(T t) {\n" + " };\n" + "}", + "void foo() {\n" + " auto lambda = []<\n" + " typename T, typename Foo>(T t){\n" + " };\n" + "}", + Style); + // Or on different lines: + verifyFormat("void foo() {\n" + " auto lambda = []<\n" + "typename T,\n" + "typename Foo\n" + ">(T t) {\n" + " };\n" + "}", + "void foo() {\n" + " auto lambda = []<\n" + " typename T,\n" + " typename Foo>(T t){\n" + " };\n" + "}", + Style); + + // Test template usage goes to next line too: + verifyFormat("void foo() {\n" + " myFunc<\n" + " T\n" + " >();\n" + "}", + "void foo() {\n" + " myFunc<\n" + " T>();\n" + "}", + Style); + + // Now test that it handles the cases when the column limit forces wrapping. + Style.ColumnLimit = 40; + // Breaks when the name is looong. Note that these names are exactly 1 + // character too long for the ColumnLimit. + verifyFormat("template <\n" + "typename Foo,\n" + "typename Barrr\n" + ">\n" + "void foo() {}", + Style); + // BlockIndent style is used when the ColumnLimit allows it: + verifyFormat("template \n" + "void foo() {}", + Style); + verifyFormat("template \n" + "void foo() {}", + Style); owenca wrote: IIRC we agreed that these 3 test cases are redundant? https://github.com/llvm/llvm-project/pull/118046 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https:
[clang] [clang-format] Add BreakBeforeTemplateClose option (PR #118046)
@@ -304,6 +304,10 @@ bool ContinuationIndenter::canBreak(const LineState &State) { Current.closesBlockOrBlockTypeList(Style))) { return false; } + if (Style.BreakBeforeTemplateCloser && Current.is(TT_TemplateCloser) && + !CurrentState.BreakBeforeClosingAngle) { +return false; + } owenca wrote: ```suggestion if (Style.BreakBeforeTemplateCloser && Current.is(TT_TemplateCloser)) return CurrentState.BreakBeforeClosingAngle; ``` And move this to line 362 below for ease of maintenance. https://github.com/llvm/llvm-project/pull/118046 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ARM] Emit an error when the hard-float ABI is enabled but can't be used. (PR #111334)
chrisnc wrote: I've been fairly busy over the past few months so haven't had time to pursue this further. One of the issues is that as far as I can tell, there doesn't seem to be a mechanism to issue a warning from within LLVM codegen, only to error. The behavior you are describing is already what `clang` does, but there isn't a way to just move that into LLVM so it can be easily used. There's also the matter of whether to treat an explicit choice of target that has eabihf as the ABI component in the same way. For this to be generally useful to Rust I think you have to treat the target choice as opting in to that ABI, but that is not the current behavior of the `clang` warning, and there are several test cases invoking the LLVM tools directly that expect the behavior of just not using the same ABI that the target says it should... My next step was going to experiment with the approach the RISC-V backend uses and see how it goes, especially to evaluate the blast radius in the tests and compare. https://github.com/llvm/llvm-project/pull/111334 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix ASTWriter crash after merging named enums (PR #114240)
@@ -2551,18 +2551,7 @@ void Sema::MergeTypedefNameDecl(Scope *S, TypedefNameDecl *New, // Make the old tag definition visible. makeMergedDefinitionVisible(Hidden); - // If this was an unscoped enumeration, yank all of its enumerators - // out of the scope. - if (isa(NewTag)) { -Scope *EnumScope = getNonFieldDeclScope(S); -for (auto *D : NewTag->decls()) { - auto *ED = cast(D); - assert(EnumScope->isDeclScope(ED)); - EnumScope->RemoveDecl(ED); - IdResolver.RemoveDecl(ED); - ED->getLexicalDeclContext()->removeDecl(ED); michael-jabbour-sonarsource wrote: Thank you all for looking into this :pray: > Can we solve this issue by reusing some level of modules-specific declaration > shadowing? I am new to modules, and I only learned how this part of the code works while debugging the crash I am sharing here. I am not entirely sure I understand what this means, could you provide some pointers that I can start from (e.g. function names, commits, ...etc)? I can try to dig into this at the end of this week or next week if needed... https://github.com/llvm/llvm-project/pull/114240 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix ASTWriter crash after merging named enums (PR #114240)
https://github.com/michael-jabbour-sonarsource edited https://github.com/llvm/llvm-project/pull/114240 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add support for the c2000 architecture (PR #125663)
@@ -0,0 +1,22 @@ +#include "clang/Driver/Driver.h" +#include "clang/Driver/DriverDiagnostic.h" +#include "clang/Driver/InputInfo.h" +#include "clang/Driver/Tool.h" +#include "clang/Driver/ToolChain.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Option/Option.h" + +#include +#include + +namespace clang { student433 wrote: Got it! Modifying this for better compatibility https://github.com/llvm/llvm-project/pull/125663 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] CTAD alias: Respect explicit deduction guides defined after the first use of the alias template. (PR #125478)
@@ -237,8 +237,17 @@ static_assert(__is_same(decltype(s.t), int)); // explicit deduction guide. Foo(int) -> Foo; AFoo s2{i}; -// FIXME: the type should be X because of the above explicit deduction guide. -static_assert(__is_same(decltype(s2.t), int)); +static_assert(__is_same(decltype(s2.t), X)); + + +template +using BFoo = AFoo; +static_assert(__is_same(decltype(BFoo(i).t), X)); + + +Foo(double) -> Foo; +static_assert(__is_same(decltype(AFoo(1.0).t), int)); +static_assert(__is_same(decltype(BFoo(1.0).t), int)); hokein wrote: > > Does it fix this case: https://godbolt.org/z/b84rzhjjK if not we need to > > open a bug. > > That test case doesn't look related to these changes to me, I think it's a > different issue. This is not related to this patch. Filed #125821 for tracking (thanks for spotting it!) https://github.com/llvm/llvm-project/pull/125478 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [PGO] Add a clang option -fprofile-continuous that enables PGO continuous mode (PR #124353)
petrhosek wrote: > I believe all comments have been addressed. friendly ping. @petrhosek any > feedback please? The high-level comment is that the continuous mode isn't PGO specific, it was actually originally developed primarily for coverage, although it can be used for PGO as well due to the fact that coverage and PGO share the instrumentation and runtime (with the limitation of value profiling not being supported). I don't think this flag should imply that it's PGO specific by explicitly referring to PGO, rather everywhere in your change where you currently say "PGO", you should say "profiling" (or "instrumentation profiling") to imply that it can be used for both coverage and PGO. TL;DR `s/PGO/instrumentation profiling/g` https://github.com/llvm/llvm-project/pull/124353 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver][HIP] Do not pass -dependency-file flag for HIP Device offloading (PR #125646)
https://github.com/lalaniket8 updated https://github.com/llvm/llvm-project/pull/125646 >From ae1f0e723ee8de2bc4f0032c884512ec79fae800 Mon Sep 17 00:00:00 2001 From: anikelal Date: Tue, 4 Feb 2025 12:13:20 +0530 Subject: [PATCH 1/2] [Driver][HIP] Do not pass -dependency-file flag for HIP Device offloading When we launch hipcc with multiple offload architectures along with -MF dep_file flag, the clang compilation invocations for host and device offloads write to the same dep_file, and can lead to collision during file IO operations. This can typically happen during large workloads. This commit provides a fix to generate dep_file only in host compilation. --- clang/lib/Driver/ToolChains/Clang.cpp | 30 ++- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 27de34634660c3..4066a588b5f48b 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -1013,21 +1013,23 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, ArgM = ArgMD; if (ArgM) { -// Determine the output location. -const char *DepFile; -if (Arg *MF = Args.getLastArg(options::OPT_MF)) { - DepFile = MF->getValue(); - C.addFailureResultFile(DepFile, &JA); -} else if (Output.getType() == types::TY_Dependencies) { - DepFile = Output.getFilename(); -} else if (!ArgMD) { - DepFile = "-"; -} else { - DepFile = getDependencyFileName(Args, Inputs); - C.addFailureResultFile(DepFile, &JA); +if (!JA.isDeviceOffloading(Action::OFK_HIP)) { + // Determine the output location. + const char *DepFile; + if (Arg *MF = Args.getLastArg(options::OPT_MF)) { +DepFile = MF->getValue(); +C.addFailureResultFile(DepFile, &JA); + } else if (Output.getType() == types::TY_Dependencies) { +DepFile = Output.getFilename(); + } else if (!ArgMD) { +DepFile = "-"; + } else { +DepFile = getDependencyFileName(Args, Inputs); +C.addFailureResultFile(DepFile, &JA); + } + CmdArgs.push_back("-dependency-file"); + CmdArgs.push_back(DepFile); } -CmdArgs.push_back("-dependency-file"); -CmdArgs.push_back(DepFile); bool HasTarget = false; for (const Arg *A : Args.filtered(options::OPT_MT, options::OPT_MQ)) { >From 62d313ab07199a90b0523e4be1bd4b0b555faf03 Mon Sep 17 00:00:00 2001 From: anikelal Date: Wed, 5 Feb 2025 14:49:50 +0530 Subject: [PATCH 2/2] Adding littest --- .../Driver/dep-file-flag-with-multiple-offload-archs.hip| 6 ++ 1 file changed, 6 insertions(+) create mode 100644 clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip diff --git a/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip b/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip new file mode 100644 index 00..a183647a733192 --- /dev/null +++ b/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip @@ -0,0 +1,6 @@ +// RUN: %clang -### --offload-arch=gfx1030 --offload-arch=gfx1100 --offload-arch=gfx1101 -MD -MF tmp.d -v %s 2>&1 | FileCheck %s + +// CHECK-NOT: {{.*}}clang{{.*}}"-target-cpu" "gfx1030"{{.*}}"-dependency-file" "tmp.d" +// CHECK-NOT: {{.*}}clang{{.*}}"-target-cpu" "gfx1100"{{.*}}"-dependency-file" "tmp.d" +// CHECK-NOT: {{.*}}clang{{.*}}"-target-cpu" "gfx1101"{{.*}}"-dependency-file" "tmp.d" +// CHECK: {{.*}}clang{{.*}}"-target-cpu" "x86-64"{{.*}}"-dependency-file" "tmp.d" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add support for the c2000 architecture (PR #125663)
https://github.com/student433 edited https://github.com/llvm/llvm-project/pull/125663 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][bytecode] Handle CXXPseudoDestructorExprs (PR #125835)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) Changes Make lifetime management more explicit. We're only using this for CXXPseudoDestructorExprs for now but we need this to handle std::construct_at/placement-new after destructor calls later anyway. --- Full diff: https://github.com/llvm/llvm-project/pull/125835.diff 7 Files Affected: - (modified) clang/lib/AST/ByteCode/Compiler.cpp (+8) - (modified) clang/lib/AST/ByteCode/Descriptor.h (+8-1) - (modified) clang/lib/AST/ByteCode/Interp.cpp (+18) - (modified) clang/lib/AST/ByteCode/Interp.h (+6) - (modified) clang/lib/AST/ByteCode/Opcodes.td (+5) - (modified) clang/lib/AST/ByteCode/Pointer.h (+16) - (modified) clang/test/AST/ByteCode/cxx20.cpp (+32-1) ``diff diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index c1408379b4c1b8..cf89cdc667acc2 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -4715,6 +4715,14 @@ bool Compiler::VisitCallExpr(const CallExpr *E) { } else if (!this->visit(MC->getImplicitObjectArgument())) { return false; } + } else if (const auto *PD = + dyn_cast(E->getCallee())) { +const Expr *Base = PD->getBase(); +if (!Base->isGLValue()) + return this->discard(Base); +if (!this->visit(Base)) + return false; +return this->emitKill(E); } else if (!FuncDecl) { const Expr *Callee = E->getCallee(); CalleeOffset = this->allocateLocalPrimitive(Callee, PT_FnPtr, true, false); diff --git a/clang/lib/AST/ByteCode/Descriptor.h b/clang/lib/AST/ByteCode/Descriptor.h index a73e28d2e600e8..96c82a18913e02 100644 --- a/clang/lib/AST/ByteCode/Descriptor.h +++ b/clang/lib/AST/ByteCode/Descriptor.h @@ -61,6 +61,11 @@ struct alignas(void *) GlobalInlineDescriptor { }; static_assert(sizeof(GlobalInlineDescriptor) == sizeof(void *), ""); +enum class Lifetime : uint8_t { + Started, + Ended, +}; + /// Inline descriptor embedded in structures and arrays. /// /// Such descriptors precede all composite array elements and structure fields. @@ -100,12 +105,14 @@ struct InlineDescriptor { LLVM_PREFERRED_TYPE(bool) unsigned IsArrayElement : 1; + Lifetime LifeState; + const Descriptor *Desc; InlineDescriptor(const Descriptor *D) : Offset(sizeof(InlineDescriptor)), IsConst(false), IsInitialized(false), IsBase(false), IsActive(false), IsFieldMutable(false), -IsArrayElement(false), Desc(D) {} +IsArrayElement(false), LifeState(Lifetime::Started), Desc(D) {} void dump() const { dump(llvm::errs()); } void dump(llvm::raw_ostream &OS) const; diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index 1123ced99eb069..bf48139f57c0f0 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -561,6 +561,18 @@ bool CheckInitialized(InterpState &S, CodePtr OpPC, const Pointer &Ptr, return false; } +static bool CheckLifetime(InterpState &S, CodePtr OpPC, const Pointer &Ptr, + AccessKinds AK) { + if (Ptr.getLifetime() == Lifetime::Started) +return true; + + if (!S.checkingPotentialConstantExpression()) { +S.FFDiag(S.Current->getSource(OpPC), diag::note_constexpr_access_uninit) +<< AK << /*uninitialized=*/false << S.Current->getRange(OpPC); + } + return false; +} + bool CheckGlobalInitialized(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { if (Ptr.isInitialized()) return true; @@ -605,6 +617,8 @@ bool CheckLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr, return false; if (!CheckActive(S, OpPC, Ptr, AK)) return false; + if (!CheckLifetime(S, OpPC, Ptr, AK)) +return false; if (!CheckInitialized(S, OpPC, Ptr, AK)) return false; if (!CheckTemporary(S, OpPC, Ptr, AK)) @@ -634,6 +648,8 @@ bool CheckFinalLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { return false; if (!CheckActive(S, OpPC, Ptr, AK_Read)) return false; + if (!CheckLifetime(S, OpPC, Ptr, AK_Read)) +return false; if (!CheckInitialized(S, OpPC, Ptr, AK_Read)) return false; if (!CheckTemporary(S, OpPC, Ptr, AK_Read)) @@ -650,6 +666,8 @@ bool CheckStore(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { return false; if (!CheckDummy(S, OpPC, Ptr, AK_Assign)) return false; + if (!CheckLifetime(S, OpPC, Ptr, AK_Assign)) +return false; if (!CheckExtern(S, OpPC, Ptr)) return false; if (!CheckRange(S, OpPC, Ptr, AK_Assign)) diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index 9f029adc708390..66fd31feb24f4e 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -1254,6 +1254,12 @@ bool GetLocal(InterpState &S, CodePtr OpPC, uint32_t I) { return true; } +static inline bool Kill(InterpState &S, CodePtr OpPC) { + const auto &Ptr = S.Stk.pop(); + Ptr.endLifetime(); + retu
[clang] [llvm] [clang] Add support for the c2000 architecture (PR #125663)
@@ -0,0 +1,356 @@ +#include "C2000.h" +#include "Targets.h" +#include "clang/Basic/Builtins.h" +#include "clang/Basic/Diagnostic.h" +#include "clang/Basic/MacroBuilder.h" +#include "clang/Basic/TargetBuiltins.h" + +using namespace clang; +using namespace clang::targets; + +const char *const C2000TargetInfo::GCCRegNames[] = { +"ACC", "XAR0", "XAR1", "XAR2", "XAR3", "XAR4", "XAR5", "XAR6", "XAR7"}; + +ArrayRef C2000TargetInfo::getGCCRegNames() const { + return llvm::ArrayRef(GCCRegNames); +} + +bool C2000TargetInfo::handleTargetFeatures(std::vector &Features, + DiagnosticsEngine &Diags) { + + for (const auto &Feature : Features) { +if (Feature == "+eabi") { + eabi = true; + continue; +} +if (Feature == "+strict_ansi") { + strict = true; + continue; +} +if (Feature == "+cla_support") { + cla_support = true; +} +if (Feature == "+cla0") { + cla0 = true; + continue; +} +if (Feature == "+cla1") { + cla1 = true; + continue; +} +if (Feature == "+cla2") { + cla2 = true; + continue; +} +if (Feature == "+relaxed") { + relaxed = true; + continue; +} +if (Feature == "+fpu64") { + fpu64 = true; + continue; +} +if (Feature == "+fpu32") { + fpu32 = true; + continue; +} +if (Feature == "+tmu_support") { + tmu_support = true; +} +if (Feature == "+tmu1") { + tmu1 = true; + continue; +} +if (Feature == "+idiv0") { + idiv0 = true; + continue; +} +if (Feature == "+vcu_support") { + vcu_support = true; +} +if (Feature == "+vcu2") { + vcu2 = true; + continue; +} +if (Feature == "+vcrc") { + vcrc = true; + continue; +} +if (Feature == "+opt_level") { + opt = true; + continue; +} + } + return true; +} + +bool C2000TargetInfo::hasFeature(StringRef Feature) const { + return llvm::StringSwitch(Feature) + .Case("eabi", eabi) + .Case("strict_ansi", strict) + .Case("cla-support", cla_support) + .Case("cla0", cla0) + .Case("cla1", cla1) + .Case("cla2", cla2) + .Case("relaxed", relaxed) + .Case("fpu64", fpu64) + .Case("fpu32", fpu32) + .Case("tmu-support", tmu_support) + .Case("tmu1", tmu1) + .Case("vcu-support", vcu_support) + .Case("vcu2", vcu2) + .Case("vcrc", vcrc) + .Case("opt-level", opt) + .Default(false); +} + +void C2000TargetInfo::getTargetDefines(const LangOptions &Opts, + MacroBuilder &Builder) const { + Builder.undefineMacro("__CHAR_BIT__"); // FIXME: Implement 16-bit char + Builder.defineMacro("__CHAR_BIT__", "16"); + Builder.defineMacro("__TMS320C2000__"); + Builder.defineMacro("_TMS320C2000"); + Builder.defineMacro("__TMS320C28XX__"); + Builder.defineMacro("_TMS320C28XX"); + Builder.defineMacro("__TMS320C28X__"); + Builder.defineMacro("_TMS320C28X"); + Builder.defineMacro("__TI_STRICT_FP_MODE__"); + Builder.defineMacro("__COMPILER_VERSION__"); + Builder.defineMacro("__TI_COMPILER_VERSION__"); + Builder.defineMacro("__TI_COMPILER_VERSION__QUAL_ID"); + Builder.defineMacro("__TI_COMPILER_VERSION__QUAL__", "QUAL_LETTER"); + Builder.defineMacro("__little_endian__"); + Builder.defineMacro("__PTRDIFF_T_TYPE__", "signed long"); + Builder.defineMacro("__SIZE_T_TYPE__", "unsigned long"); + Builder.defineMacro("__WCHAR_T_TYPE__", "long unsigned"); + Builder.defineMacro("__TI_WCHAR_T_BITS", "16"); + Builder.defineMacro("__TI_C99_COMPLEX_ENABLED"); + Builder.defineMacro("__TI_GNU_ATTRIBUTE_SUPPORT__"); + Builder.defineMacro("__LARGE_MODEL__"); + Builder.defineMacro("__signed_chars__"); + Builder.defineMacro("__OPTIMIZE_FOR_SPACE"); + + if (hasFeature("eabi")) +Builder.defineMacro("__TI_EABI__"); + if (hasFeature("strict_ansi")) +Builder.defineMacro("__TI_STRICT_ANSI_MODE__"); + if (hasFeature("cla-support")) +Builder.defineMacro("__TMS320C28XX_CLA__"); + + if (hasFeature("cla0")) +Builder.defineMacro("__TMS320C28XX_CLA0__"); + else if (hasFeature("cla1")) +Builder.defineMacro("__TMS320C28XX_CLA1__"); + else if (hasFeature("cla2")) +Builder.defineMacro("__TMS320C28XX_CLA2__"); + + if (hasFeature("fpu64")) { +Builder.defineMacro("__TMS320C28XX_FPU64__"); +Builder.defineMacro("__TMS320C28XX_FPU32__"); + } else if (hasFeature("fpu32")) +Builder.defineMacro("__TMS320C28XX_FPU32__"); + if (hasFeature("idiv0")) +Builder.defineMacro("__TMS320C28XX_IDIV__"); + if (hasFeature("tmu1")) +Builder.defineMacro("__TMS320C28XX_TMU1__"); + if (hasFeature("tmu-support")) { +Builder.defineMacro("__TMS320C28XX_TMU0__"); +Builder.defineMacro("__TMS320C28XX_TMU__"); + } + if (hasFeature("vcu-support")) +Builder.defineMacro("__TMS320C28XX_VCU0__"); + if (hasFeature("vcu2")) +Builder.defineMacro("__TMS320C28XX_VCU2_
[clang] [llvm] [clang] Add support for the c2000 architecture (PR #125663)
https://github.com/student433 edited https://github.com/llvm/llvm-project/pull/125663 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [mlir] [IR][ModRef] Introduce `errno` memory location (PR #120783)
@@ -82,7 +82,7 @@ define void @test_store(ptr %p) { @G = external global ptr define i8 @test_store_capture(ptr %p) { -; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: read, inaccessiblemem: none) +; FNATTRS: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: read, inaccessiblemem: none, errnomem: none) antoniofrighetto wrote: Hmm, the pointer is never accessed with an integer size, it should never alias errno, so should be correct to infer NoModRef for `test_store_capture`? Though now I think we might still miss something as follows while inferring attributes (and then let AA conclude if it aliases errno or not)? ```c++ if (Loc->Size == LocationSize::precise(sizeof(int))) ME |= MemoryEffects::errnoMemOnly(MR); ``` https://github.com/llvm/llvm-project/pull/120783 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Add time-trace scopes for high-level analyzer steps (PR #125508)
https://github.com/balazs-benics-sonarsource approved this pull request. I had a look at the PR, and it looks awesome. Could you please update the attached speedscope image? It looks like it's out of sync with the implementation, for example if you look at the "Loc PostStmt { ... stuff here ...}" , it appears to include the ProgramPoint dump, and according to your implementation it should only have "Loc ". Am I right? https://github.com/llvm/llvm-project/pull/125508 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][bytecode] Handle CXXPseudoDestructorExprs (PR #125835)
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/125835 Make lifetime management more explicit. We're only using this for CXXPseudoDestructorExprs for now but we need this to handle std::construct_at/placement-new after destructor calls later anyway. >From 59093b2044bf5188e2743a3cff6c4f2dd4ce3507 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Wed, 5 Feb 2025 11:29:24 +0100 Subject: [PATCH] [clang][bytecode] Handle CXXPseudoDestructorExprs Make lifetime management more explicit. We're only using this for CXXPseudoDestructorExprs for now but we need this to handle std::construct_at/placement-new after destructor calls later anyway. --- clang/lib/AST/ByteCode/Compiler.cpp | 8 +++ clang/lib/AST/ByteCode/Descriptor.h | 9 +++- clang/lib/AST/ByteCode/Interp.cpp | 18 clang/lib/AST/ByteCode/Interp.h | 6 ++ clang/lib/AST/ByteCode/Opcodes.td | 5 + clang/lib/AST/ByteCode/Pointer.h| 16 ++ clang/test/AST/ByteCode/cxx20.cpp | 33 - 7 files changed, 93 insertions(+), 2 deletions(-) diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index c1408379b4c1b8a..cf89cdc667acc29 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -4715,6 +4715,14 @@ bool Compiler::VisitCallExpr(const CallExpr *E) { } else if (!this->visit(MC->getImplicitObjectArgument())) { return false; } + } else if (const auto *PD = + dyn_cast(E->getCallee())) { +const Expr *Base = PD->getBase(); +if (!Base->isGLValue()) + return this->discard(Base); +if (!this->visit(Base)) + return false; +return this->emitKill(E); } else if (!FuncDecl) { const Expr *Callee = E->getCallee(); CalleeOffset = this->allocateLocalPrimitive(Callee, PT_FnPtr, true, false); diff --git a/clang/lib/AST/ByteCode/Descriptor.h b/clang/lib/AST/ByteCode/Descriptor.h index a73e28d2e600e8d..96c82a18913e02e 100644 --- a/clang/lib/AST/ByteCode/Descriptor.h +++ b/clang/lib/AST/ByteCode/Descriptor.h @@ -61,6 +61,11 @@ struct alignas(void *) GlobalInlineDescriptor { }; static_assert(sizeof(GlobalInlineDescriptor) == sizeof(void *), ""); +enum class Lifetime : uint8_t { + Started, + Ended, +}; + /// Inline descriptor embedded in structures and arrays. /// /// Such descriptors precede all composite array elements and structure fields. @@ -100,12 +105,14 @@ struct InlineDescriptor { LLVM_PREFERRED_TYPE(bool) unsigned IsArrayElement : 1; + Lifetime LifeState; + const Descriptor *Desc; InlineDescriptor(const Descriptor *D) : Offset(sizeof(InlineDescriptor)), IsConst(false), IsInitialized(false), IsBase(false), IsActive(false), IsFieldMutable(false), -IsArrayElement(false), Desc(D) {} +IsArrayElement(false), LifeState(Lifetime::Started), Desc(D) {} void dump() const { dump(llvm::errs()); } void dump(llvm::raw_ostream &OS) const; diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index 1123ced99eb0698..bf48139f57c0f09 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -561,6 +561,18 @@ bool CheckInitialized(InterpState &S, CodePtr OpPC, const Pointer &Ptr, return false; } +static bool CheckLifetime(InterpState &S, CodePtr OpPC, const Pointer &Ptr, + AccessKinds AK) { + if (Ptr.getLifetime() == Lifetime::Started) +return true; + + if (!S.checkingPotentialConstantExpression()) { +S.FFDiag(S.Current->getSource(OpPC), diag::note_constexpr_access_uninit) +<< AK << /*uninitialized=*/false << S.Current->getRange(OpPC); + } + return false; +} + bool CheckGlobalInitialized(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { if (Ptr.isInitialized()) return true; @@ -605,6 +617,8 @@ bool CheckLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr, return false; if (!CheckActive(S, OpPC, Ptr, AK)) return false; + if (!CheckLifetime(S, OpPC, Ptr, AK)) +return false; if (!CheckInitialized(S, OpPC, Ptr, AK)) return false; if (!CheckTemporary(S, OpPC, Ptr, AK)) @@ -634,6 +648,8 @@ bool CheckFinalLoad(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { return false; if (!CheckActive(S, OpPC, Ptr, AK_Read)) return false; + if (!CheckLifetime(S, OpPC, Ptr, AK_Read)) +return false; if (!CheckInitialized(S, OpPC, Ptr, AK_Read)) return false; if (!CheckTemporary(S, OpPC, Ptr, AK_Read)) @@ -650,6 +666,8 @@ bool CheckStore(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { return false; if (!CheckDummy(S, OpPC, Ptr, AK_Assign)) return false; + if (!CheckLifetime(S, OpPC, Ptr, AK_Assign)) +return false; if (!CheckExtern(S, OpPC, Ptr)) return false; if (!CheckRange(S, OpPC, Ptr, AK_Assign)) diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang
[clang] [analyzer] Add time-trace scopes for high-level analyzer steps (PR #125508)
necto wrote: > I had a look at the PR, and it looks awesome. Could you please update the > attached speedscope image? It looks like it's out of sync with the > implementation, for example if you look at the "Loc PostStmt { ... stuff here > ...}" , it appears to include the ProgramPoint dump, and according to your > implementation it should only have "Loc ". Am I right? speedscope puts the "details" onto the scope labels in addition to their name, unlike chrome-tracing that only displays the name, so that's the up-to-date display https://github.com/llvm/llvm-project/pull/125508 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [libcxx] [llvm] [libc++][ranges] P2542R8: Implement `views::concat` (PR #120920)
changkhothuychung wrote: @frederick-vs-ja just follow up on this https://github.com/llvm/llvm-project/pull/120920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix ASTWriter crash after merging named enums (PR #114240)
https://github.com/michael-jabbour-sonarsource edited https://github.com/llvm/llvm-project/pull/114240 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix ASTWriter crash after merging named enums (PR #114240)
@@ -2639,6 +2628,19 @@ void Sema::MergeTypedefNameDecl(Scope *S, TypedefNameDecl *New, notePreviousDefinition(Old, New->getLocation()); } +void Sema::CleanupMergedEnum(Scope *S, Decl *New) { michael-jabbour-sonarsource wrote: > Is MergeTypedefNameDecl not called for the motivating example? Unfortunately, it seems to me that `MergeTypedefNameDecl` is only called in the typedef to anonymous enum case (`MyEnum3` in the test case I am adding). For the rest of the enum cases, the closest I found was `Sema::ActOnDuplicateDefinition`, which is called when merging all tags (and this is where I am adding the new call to `CleanupMergedEnum`). > Can we find a common path when merging definitions to put that logic there? I could only see that merging enums for C and Obj-C crashes in this case (C++ works differently, see [here](https://github.com/llvm/llvm-project/pull/114240#issuecomment-2614544626)), and I found `Sema::ActOnDuplicateDefinition` during my investigation to be the function that handles merging tags. I am not aware of a central place for merging definitions in general. Could you provide some hints on what to look for? https://github.com/llvm/llvm-project/pull/114240 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Clang][AArch64] Add support for SHF_AARCH64_PURECODE ELF section flag (2/3) (PR #125688)
https://github.com/Il-Capitano converted_to_draft https://github.com/llvm/llvm-project/pull/125688 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add support for the c2000 architecture (PR #125663)
https://github.com/student433 edited https://github.com/llvm/llvm-project/pull/125663 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Driver] Add an option to control loop-interchange (PR #125830)
https://github.com/sjoerdmeijer created https://github.com/llvm/llvm-project/pull/125830 This introduces options `-floop-interchange` and `-fno-loop-interchange` to enable/disable the loop-interchange pass. This is part of the work that tries to get that pass enabled by default (#124911), where it was remarked that a user facing option to control this would be convenient to have. The option name is the same as GCC's. >From 24b8e28cfa016ad2b3f494dbf811a2c0da5d7742 Mon Sep 17 00:00:00 2001 From: Sjoerd Meijer Date: Tue, 4 Feb 2025 03:38:34 -0800 Subject: [PATCH] [Clang][Driver] Add an option to control loop-interchange This introduces options -floop-interchange and -fno-loop-interchange to enable/disable the loop-interchange pass. This is part of the work that tries to get that pass enabled by default (#124911), where it was remarked that a user facing option to control this would be convenient to have. The option (name) is the same as GCC's. --- clang/include/clang/Driver/Options.td | 3 +++ clang/lib/Driver/ToolChains/Clang.cpp | 10 ++ clang/test/Driver/clang_f_opts.c | 7 +++ 3 files changed, 20 insertions(+) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index df705104d9ea314..3132f8946c6d3be 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -4073,6 +4073,9 @@ defm assumptions : BoolFOption<"assumptions", "Disable codegen and compile-time checks for C++23's [[assume]] attribute">, PosFlag>; +def floop_interchange : Flag<["-"], "floop-interchange">, Group, + HelpText<"Enable the loop interchange pass">; +def fno_loop_interchange: Flag<["-"], "fno-loop-interchange">, Group; def fvectorize : Flag<["-"], "fvectorize">, Group, HelpText<"Enable the loop vectorization passes">; def fno_vectorize : Flag<["-"], "fno-vectorize">, Group; diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 33f08cf28feca18..757093c3d3a5cfa 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -7619,6 +7619,16 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, Args.addOptOutFlag(CmdArgs, options::OPT_fgnu_inline_asm, options::OPT_fno_gnu_inline_asm); + // Handle -floop-interchange + if (Arg *A = Args.getLastArg(options::OPT_floop_interchange, + options::OPT_fno_loop_interchange)) { +CmdArgs.push_back("-mllvm"); +if (A->getOption().matches(options::OPT_floop_interchange)) + CmdArgs.push_back("-enable-loopinterchange=true"); +else + CmdArgs.push_back("-enable-loopinterchange=false"); + } + // Enable vectorization per default according to the optimization level // selected. For optimization levels that want vectorization we use the alias // option to simplify the hasFlag logic. diff --git a/clang/test/Driver/clang_f_opts.c b/clang/test/Driver/clang_f_opts.c index 38f25898c955682..908d592928b01fc 100644 --- a/clang/test/Driver/clang_f_opts.c +++ b/clang/test/Driver/clang_f_opts.c @@ -156,6 +156,13 @@ // CHECK-VECTORIZE: "-vectorize-loops" // CHECK-NO-VECTORIZE-NOT: "-vectorize-loops" +// RUN: %clang -### -S -floop-interchange %s 2>&1 | FileCheck -check-prefix=CHECK-INTERCHANGE %s +// RUN: %clang -### -S -fno-loop-interchange -floop-interchange %s 2>&1 | FileCheck -check-prefix=CHECK-INTERCHANGE %s +// RUN: %clang -### -S -fno-loop-interchange %s 2>&1 | FileCheck -check-prefix=CHECK-NO-INTERCHANGE %s +// RUN: %clang -### -S -floop-interchange -fno-loop-interchange %s 2>&1 | FileCheck -check-prefix=CHECK-NO-INTERCHANGE %s +// CHECK-INTERCHANGE: "-mllvm" "-enable-loopinterchange=true" +// CHECK-NO-INTERCHANGE: "-mllvm" "-enable-loopinterchange=false" + // RUN: %clang -### -S -fslp-vectorize %s 2>&1 | FileCheck -check-prefix=CHECK-SLP-VECTORIZE %s // RUN: %clang -### -S -fno-slp-vectorize -fslp-vectorize %s 2>&1 | FileCheck -check-prefix=CHECK-SLP-VECTORIZE %s // RUN: %clang -### -S -fno-slp-vectorize %s 2>&1 | FileCheck -check-prefix=CHECK-NO-SLP-VECTORIZE %s ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Driver] Add an option to control loop-interchange (PR #125830)
llvmbot wrote: @llvm/pr-subscribers-clang-driver Author: Sjoerd Meijer (sjoerdmeijer) Changes This introduces options `-floop-interchange` and `-fno-loop-interchange` to enable/disable the loop-interchange pass. This is part of the work that tries to get that pass enabled by default (#124911), where it was remarked that a user facing option to control this would be convenient to have. The option name is the same as GCC's. --- Full diff: https://github.com/llvm/llvm-project/pull/125830.diff 3 Files Affected: - (modified) clang/include/clang/Driver/Options.td (+3) - (modified) clang/lib/Driver/ToolChains/Clang.cpp (+10) - (modified) clang/test/Driver/clang_f_opts.c (+7) ``diff diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index df705104d9ea31..3132f8946c6d3b 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -4073,6 +4073,9 @@ defm assumptions : BoolFOption<"assumptions", "Disable codegen and compile-time checks for C++23's [[assume]] attribute">, PosFlag>; +def floop_interchange : Flag<["-"], "floop-interchange">, Group, + HelpText<"Enable the loop interchange pass">; +def fno_loop_interchange: Flag<["-"], "fno-loop-interchange">, Group; def fvectorize : Flag<["-"], "fvectorize">, Group, HelpText<"Enable the loop vectorization passes">; def fno_vectorize : Flag<["-"], "fno-vectorize">, Group; diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 33f08cf28feca1..757093c3d3a5cf 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -7619,6 +7619,16 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, Args.addOptOutFlag(CmdArgs, options::OPT_fgnu_inline_asm, options::OPT_fno_gnu_inline_asm); + // Handle -floop-interchange + if (Arg *A = Args.getLastArg(options::OPT_floop_interchange, + options::OPT_fno_loop_interchange)) { +CmdArgs.push_back("-mllvm"); +if (A->getOption().matches(options::OPT_floop_interchange)) + CmdArgs.push_back("-enable-loopinterchange=true"); +else + CmdArgs.push_back("-enable-loopinterchange=false"); + } + // Enable vectorization per default according to the optimization level // selected. For optimization levels that want vectorization we use the alias // option to simplify the hasFlag logic. diff --git a/clang/test/Driver/clang_f_opts.c b/clang/test/Driver/clang_f_opts.c index 38f25898c95568..908d592928b01f 100644 --- a/clang/test/Driver/clang_f_opts.c +++ b/clang/test/Driver/clang_f_opts.c @@ -156,6 +156,13 @@ // CHECK-VECTORIZE: "-vectorize-loops" // CHECK-NO-VECTORIZE-NOT: "-vectorize-loops" +// RUN: %clang -### -S -floop-interchange %s 2>&1 | FileCheck -check-prefix=CHECK-INTERCHANGE %s +// RUN: %clang -### -S -fno-loop-interchange -floop-interchange %s 2>&1 | FileCheck -check-prefix=CHECK-INTERCHANGE %s +// RUN: %clang -### -S -fno-loop-interchange %s 2>&1 | FileCheck -check-prefix=CHECK-NO-INTERCHANGE %s +// RUN: %clang -### -S -floop-interchange -fno-loop-interchange %s 2>&1 | FileCheck -check-prefix=CHECK-NO-INTERCHANGE %s +// CHECK-INTERCHANGE: "-mllvm" "-enable-loopinterchange=true" +// CHECK-NO-INTERCHANGE: "-mllvm" "-enable-loopinterchange=false" + // RUN: %clang -### -S -fslp-vectorize %s 2>&1 | FileCheck -check-prefix=CHECK-SLP-VECTORIZE %s // RUN: %clang -### -S -fno-slp-vectorize -fslp-vectorize %s 2>&1 | FileCheck -check-prefix=CHECK-SLP-VECTORIZE %s // RUN: %clang -### -S -fno-slp-vectorize %s 2>&1 | FileCheck -check-prefix=CHECK-NO-SLP-VECTORIZE %s `` https://github.com/llvm/llvm-project/pull/125830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Driver] Add an option to control loop-interchange (PR #125830)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Sjoerd Meijer (sjoerdmeijer) Changes This introduces options `-floop-interchange` and `-fno-loop-interchange` to enable/disable the loop-interchange pass. This is part of the work that tries to get that pass enabled by default (#124911), where it was remarked that a user facing option to control this would be convenient to have. The option name is the same as GCC's. --- Full diff: https://github.com/llvm/llvm-project/pull/125830.diff 3 Files Affected: - (modified) clang/include/clang/Driver/Options.td (+3) - (modified) clang/lib/Driver/ToolChains/Clang.cpp (+10) - (modified) clang/test/Driver/clang_f_opts.c (+7) ``diff diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index df705104d9ea314..3132f8946c6d3be 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -4073,6 +4073,9 @@ defm assumptions : BoolFOption<"assumptions", "Disable codegen and compile-time checks for C++23's [[assume]] attribute">, PosFlag>; +def floop_interchange : Flag<["-"], "floop-interchange">, Group, + HelpText<"Enable the loop interchange pass">; +def fno_loop_interchange: Flag<["-"], "fno-loop-interchange">, Group; def fvectorize : Flag<["-"], "fvectorize">, Group, HelpText<"Enable the loop vectorization passes">; def fno_vectorize : Flag<["-"], "fno-vectorize">, Group; diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 33f08cf28feca18..757093c3d3a5cfa 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -7619,6 +7619,16 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, Args.addOptOutFlag(CmdArgs, options::OPT_fgnu_inline_asm, options::OPT_fno_gnu_inline_asm); + // Handle -floop-interchange + if (Arg *A = Args.getLastArg(options::OPT_floop_interchange, + options::OPT_fno_loop_interchange)) { +CmdArgs.push_back("-mllvm"); +if (A->getOption().matches(options::OPT_floop_interchange)) + CmdArgs.push_back("-enable-loopinterchange=true"); +else + CmdArgs.push_back("-enable-loopinterchange=false"); + } + // Enable vectorization per default according to the optimization level // selected. For optimization levels that want vectorization we use the alias // option to simplify the hasFlag logic. diff --git a/clang/test/Driver/clang_f_opts.c b/clang/test/Driver/clang_f_opts.c index 38f25898c955682..908d592928b01fc 100644 --- a/clang/test/Driver/clang_f_opts.c +++ b/clang/test/Driver/clang_f_opts.c @@ -156,6 +156,13 @@ // CHECK-VECTORIZE: "-vectorize-loops" // CHECK-NO-VECTORIZE-NOT: "-vectorize-loops" +// RUN: %clang -### -S -floop-interchange %s 2>&1 | FileCheck -check-prefix=CHECK-INTERCHANGE %s +// RUN: %clang -### -S -fno-loop-interchange -floop-interchange %s 2>&1 | FileCheck -check-prefix=CHECK-INTERCHANGE %s +// RUN: %clang -### -S -fno-loop-interchange %s 2>&1 | FileCheck -check-prefix=CHECK-NO-INTERCHANGE %s +// RUN: %clang -### -S -floop-interchange -fno-loop-interchange %s 2>&1 | FileCheck -check-prefix=CHECK-NO-INTERCHANGE %s +// CHECK-INTERCHANGE: "-mllvm" "-enable-loopinterchange=true" +// CHECK-NO-INTERCHANGE: "-mllvm" "-enable-loopinterchange=false" + // RUN: %clang -### -S -fslp-vectorize %s 2>&1 | FileCheck -check-prefix=CHECK-SLP-VECTORIZE %s // RUN: %clang -### -S -fno-slp-vectorize -fslp-vectorize %s 2>&1 | FileCheck -check-prefix=CHECK-SLP-VECTORIZE %s // RUN: %clang -### -S -fno-slp-vectorize %s 2>&1 | FileCheck -check-prefix=CHECK-NO-SLP-VECTORIZE %s `` https://github.com/llvm/llvm-project/pull/125830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [WIP][clang][DebugInfo] Add new DW_AT_APPLE_enum_kind to encode enum_extensibility (PR #124752)
Michael137 wrote: > Is my thing about the ctor understanding correct, and it's that the ctor > exists theoretically/abstractly, but not in the AST or in the generated > IR/DWARF? Could it be added/would that be sufficient? > > But, yeah, probably fine to just add the attribute, since that's the real > feature you want to know about. Hmmm this is what the AST looks like: ``` |-EnumDecl 0xc9accd6d0 line:3:6 Enum | `-EnumConstantDecl 0xc9accd790 col:5 e1 'Enum' |-VarDecl 0xc9accd848 col:3 e 'enum Enum':'Enum' |-EnumDecl 0xc9accd8e0 line:7:12 class EnumClass 'unsigned int' | `-EnumConstantDecl 0xc9accd9a0 col:5 ec1 'EnumClass' |-VarDecl 0xc9accda58 col:3 ec 'enum EnumClass':'EnumClass' |-EnumDecl 0xc9accdae8 line:11:48 OpenEnum | |-EnumExtensibilityAttr 0xc9accdbb0 Open | `-EnumConstantDecl 0xc9accdc08 col:3 oe1 'OpenEnum' |-VarDecl 0xc9accdcb8 col:3 oe 'enum OpenEnum':'OpenEnum' |-EnumDecl 0xc9accdd60 line:15:54 class OpenEnumClass 'unsigned int' | |-EnumExtensibilityAttr 0xc9accde20 Open | `-EnumConstantDecl 0xc9accde78 col:3 oec1 'OpenEnumClass' |-VarDecl 0xc9accdf28 col:3 oec 'enum OpenEnumClass':'OpenEnumClass' |-EnumDecl 0xc9accdfd0 col:27 ns_enum 'unsigned int' | `-EnumExtensibilityAttr 0xc9acce090 Open |-TypedefDecl 0xc9acce148 col:27 ns_enum 'enum ns_enum':'ns_enum' | `-ElaboratedType 0xc9acce0f0 'enum ns_enum' sugar | `-EnumType 0xc9acce070 'ns_enum' | `-Enum 0xc9acce210 'ns_enum' |-EnumDecl 0xc9acce210 prev 0xc9accdfd0 line:19:27 ns_enum 'unsigned int' | |-EnumExtensibilityAttr 0xc9acce2e0 Inherited Open | `-EnumConstantDecl 0xc9acce308 col:3 ns1 'ns_enum' `-VarDecl 0xc9acce3b8 col:3 ns 'enum ns_enum':'ns_enum' ``` So yea no sign of a constructor, in either AST, IR or DWARF. So it does sound more like a hypothetical construct than something that is modelled in Clang (looking at how the `EnumExtensibilityAttr` is used in Clang I don't see any mention of constructors). Seems non-trivial to generate one, particularly just for this purpose. Also if enum constructors ever become a thing then we'll need to disambiguate this case somehow. So a dedicated attribute seemed like the only way https://github.com/llvm/llvm-project/pull/124752 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [TBAA] Don't emit pointer-tbaa for void pointers. (PR #122116)
brunodf-snps wrote: > We're documenting a weaker guarantee than we implement, yes. OK, thanks. I guess the wording "in Clang 20, [...] Clang now distinguishes different pointers by their pointee type, except as limited by the relaxations around qualifiers and `void*` described above" led me to believe this was intended as a description of what was currently implemented. Anyway, and more importantly, does the choice to document a weaker guarantee mean that you expect that the TBAA implementation can be further refined in this respect? (Which does not seem hard.) Or is it too dangerous for Clang to have stricter aliasing rules than GCC? GCC does seem to consider `int*` and `void**` to alias, or so I conclude from the extra load of `*p1` in test1 here: https://godbolt.org/z/5jjh8MrP8 https://github.com/llvm/llvm-project/pull/122116 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] Move rotate to CLC library; optimize (PR #125713)
https://github.com/frasercrmck closed https://github.com/llvm/llvm-project/pull/125713 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] 76d1cb2 - [libclc] Move rotate to CLC library; optimize (#125713)
Author: Fraser Cormack Date: 2025-02-05T10:38:23Z New Revision: 76d1cb22c1b9460c0abfba943d7cc202dc30fca3 URL: https://github.com/llvm/llvm-project/commit/76d1cb22c1b9460c0abfba943d7cc202dc30fca3 DIFF: https://github.com/llvm/llvm-project/commit/76d1cb22c1b9460c0abfba943d7cc202dc30fca3.diff LOG: [libclc] Move rotate to CLC library; optimize (#125713) This commit moves the rotate builtin to the CLC library. It also optimizes rotate(x, n) to generate the @llvm.fshl(x, x, n) intrinsic, for both scalar and vector types. The previous implementation was too cautious in its handling of the shift amount; the OpenCL rules state that the shift amount is always treated as an unsigned value modulo the bitwidth. Added: libclc/clc/include/clc/integer/clc_rotate.h libclc/clc/lib/generic/integer/clc_rotate.cl libclc/clc/lib/generic/integer/clc_rotate.inc Modified: libclc/clc/lib/clspv/SOURCES libclc/clc/lib/generic/SOURCES libclc/clc/lib/spirv/SOURCES libclc/generic/lib/integer/rotate.cl Removed: libclc/generic/lib/integer/rotate.inc diff --git a/libclc/clc/include/clc/integer/clc_rotate.h b/libclc/clc/include/clc/integer/clc_rotate.h new file mode 100644 index 000..21c945a9ae1bdc1 --- /dev/null +++ b/libclc/clc/include/clc/integer/clc_rotate.h @@ -0,0 +1,12 @@ +#ifndef __CLC_INTEGER_CLC_ROTATE_H__ +#define __CLC_INTEGER_CLC_ROTATE_H__ + +#define __CLC_FUNCTION __clc_rotate +#define __CLC_BODY + +#include + +#undef __CLC_BODY +#undef __CLC_FUNCTION + +#endif // __CLC_INTEGER_CLC_ROTATE_H__ diff --git a/libclc/clc/lib/clspv/SOURCES b/libclc/clc/lib/clspv/SOURCES index c96a6fc15bf6778..2fe07f62a328ca0 100644 --- a/libclc/clc/lib/clspv/SOURCES +++ b/libclc/clc/lib/clspv/SOURCES @@ -7,6 +7,7 @@ ../generic/integer/clc_mul_hi.cl ../generic/integer/clc_popcount.cl ../generic/integer/clc_rhadd.cl +../generic/integer/clc_rotate.cl ../generic/integer/clc_sub_sat.cl ../generic/integer/clc_upsample.cl ../generic/math/clc_ceil.cl diff --git a/libclc/clc/lib/generic/SOURCES b/libclc/clc/lib/generic/SOURCES index 5fd882eb1bb256d..2d31f9ac23fec27 100644 --- a/libclc/clc/lib/generic/SOURCES +++ b/libclc/clc/lib/generic/SOURCES @@ -13,6 +13,7 @@ integer/clc_mul24.cl integer/clc_mul_hi.cl integer/clc_popcount.cl integer/clc_rhadd.cl +integer/clc_rotate.cl integer/clc_sub_sat.cl integer/clc_upsample.cl math/clc_ceil.cl diff --git a/libclc/clc/lib/generic/integer/clc_rotate.cl b/libclc/clc/lib/generic/integer/clc_rotate.cl new file mode 100644 index 000..7546862fe401e47 --- /dev/null +++ b/libclc/clc/lib/generic/integer/clc_rotate.cl @@ -0,0 +1,5 @@ +#include +#include + +#define __CLC_BODY +#include diff --git a/libclc/clc/lib/generic/integer/clc_rotate.inc b/libclc/clc/lib/generic/integer/clc_rotate.inc new file mode 100644 index 000..f144553eabd5252 --- /dev/null +++ b/libclc/clc/lib/generic/integer/clc_rotate.inc @@ -0,0 +1,22 @@ +#define __CLC_AS_GENTYPE(x) __CLC_XCONCAT(__clc_as_, __CLC_GENTYPE)(x) +#define __CLC_AS_U_GENTYPE(x) __CLC_XCONCAT(__clc_as_, __CLC_U_GENTYPE)(x) + +// The rotate(A, B) builtin left-shifts corresponding to the usual OpenCL shift +// modulo rules. These rules state that A is left-shifted by the log2(N) least +// significant bits in B when viewed as an unsigned integer value. Thus we don't +// have to worry about signed shift amounts, and can perform the computation in +// unsigned types. +_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_rotate(__CLC_GENTYPE x, + __CLC_GENTYPE n) { + __CLC_U_GENTYPE x_as_u = __CLC_AS_U_GENTYPE(x); + __CLC_U_GENTYPE mask = (__CLC_U_GENTYPE)(__CLC_GENSIZE - 1); + + __CLC_U_GENTYPE lshift_amt = __CLC_AS_U_GENTYPE(n) & mask; + + __CLC_U_GENTYPE rshift_amt = + (((__CLC_U_GENTYPE)__CLC_GENSIZE - lshift_amt) & mask); + + __CLC_U_GENTYPE result = (x_as_u << lshift_amt) | (x_as_u >> rshift_amt); + + return __CLC_AS_GENTYPE(result); +} diff --git a/libclc/clc/lib/spirv/SOURCES b/libclc/clc/lib/spirv/SOURCES index c3cc4068225d811..96040a3aebd8355 100644 --- a/libclc/clc/lib/spirv/SOURCES +++ b/libclc/clc/lib/spirv/SOURCES @@ -11,6 +11,7 @@ ../generic/integer/clc_mul_hi.cl ../generic/integer/clc_popcount.cl ../generic/integer/clc_rhadd.cl +../generic/integer/clc_rotate.cl ../generic/integer/clc_sub_sat.cl ../generic/integer/clc_upsample.cl ../generic/math/clc_ceil.cl diff --git a/libclc/generic/lib/integer/rotate.cl b/libclc/generic/lib/integer/rotate.cl index 27ce515c729331b..1e72af30f33f2bd 100644 --- a/libclc/generic/lib/integer/rotate.cl +++ b/libclc/generic/lib/integer/rotate.cl @@ -1,4 +1,7 @@ #include +#include + +#define FUNCTION rotate +#define __CLC_BODY -#define __CLC_BODY #include diff --git a/libclc/generic/lib/integer/rotate.inc b/libclc/generic/lib/integer/rotate.inc deleted file mode 100644 index 33bb0a85241d2
[clang] [clang] CTAD alias: Respect explicit deduction guides defined after the first use of the alias template. (PR #125478)
@@ -237,8 +237,17 @@ static_assert(__is_same(decltype(s.t), int)); // explicit deduction guide. Foo(int) -> Foo; AFoo s2{i}; -// FIXME: the type should be X because of the above explicit deduction guide. -static_assert(__is_same(decltype(s2.t), int)); +static_assert(__is_same(decltype(s2.t), X)); + + +template +using BFoo = AFoo; +static_assert(__is_same(decltype(BFoo(i).t), X)); + + +Foo(double) -> Foo; +static_assert(__is_same(decltype(AFoo(1.0).t), int)); +static_assert(__is_same(decltype(BFoo(1.0).t), int)); hokein wrote: > https://compiler-explorer.com/z/x8PhEqWeo A simpler example: https://compiler-explorer.com/z/Tdx1jd1bM I think Clang (and MSVC) are correct in rejecting this example. The candidate deduction guide `(AFoo(T t, U) -> Foo)` is not selected because the `is_deducible` type trait is not satisfied, as indicated in the diagnostic message. It looks like a bug in gcc. https://github.com/llvm/llvm-project/pull/125478 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver][HIP] Do not pass -dependency-file flag for HIP Device offloading (PR #125646)
lalaniket8 wrote: > need a lit test Added [dep-file-flag-with-multiple-offload-archs.hip](https://github.com/llvm/llvm-project/blob/62d313ab07199a90b0523e4be1bd4b0b555faf03/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip) https://github.com/llvm/llvm-project/pull/125646 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add support for the c2000 architecture (PR #125663)
https://github.com/student433 edited https://github.com/llvm/llvm-project/pull/125663 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [profile] Add `%b` `LLVM_PROFILE_FILE` option for binary ID (PR #123963)
https://github.com/ArtSin updated https://github.com/llvm/llvm-project/pull/123963 >From 1d1b66d11cddbb2d663879a9bd23bc4eadf6beba Mon Sep 17 00:00:00 2001 From: Artem Sinkevich Date: Wed, 5 Feb 2025 15:14:25 +0400 Subject: [PATCH] [profile] Add `%b` `LLVM_PROFILE_FILE` option for binary ID Add support for expanding `%b` in `LLVM_PROFILE_FILE` to the binary ID (build ID). It can be used with `%m` to avoid its signature collisions. This is supported on all platforms where writing binary IDs into profiles is implemented, as the `__llvm_write_binary_ids` function is used. Fixes #51560. --- clang/docs/SourceBasedCodeCoverage.rst| 5 ++ clang/docs/UsersManual.rst| 13 - compiler-rt/lib/profile/InstrProfilingFile.c | 58 +-- .../test/profile/Linux/binary-id-path.c | 40 + 4 files changed, 108 insertions(+), 8 deletions(-) create mode 100644 compiler-rt/test/profile/Linux/binary-id-path.c diff --git a/clang/docs/SourceBasedCodeCoverage.rst b/clang/docs/SourceBasedCodeCoverage.rst index 73910e134a58911..49bce3b72b45aa2 100644 --- a/clang/docs/SourceBasedCodeCoverage.rst +++ b/clang/docs/SourceBasedCodeCoverage.rst @@ -94,6 +94,11 @@ directory structure will be created. Additionally, the following special not specified (i.e the pattern is "%m"), it's assumed that ``N = 1``. The merge pool specifier can only occur once per filename pattern. +* "%b" expands out to the binary ID (build ID). It can be used with "%Nm" to + avoid binary signature collisions. To use it, the program should be compiled + with the build ID linker option (``--build-id`` for GNU ld or LLD). Linux, + Windows and AIX are supported. + * "%c" expands out to nothing, but enables a mode in which profile counter updates are continuously synced to a file. This means that if the instrumented program crashes, or is killed by a signal, perfect coverage diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst index 260e84910c6f783..f9bb31871acf2c9 100644 --- a/clang/docs/UsersManual.rst +++ b/clang/docs/UsersManual.rst @@ -2880,7 +2880,8 @@ instrumentation: environment variable to specify an alternate file. If non-default file name is specified by both the environment variable and the command line option, the environment variable takes precedence. The file name pattern specified - can include different modifiers: ``%p``, ``%h``, ``%m``, ``%t``, and ``%c``. + can include different modifiers: ``%p``, ``%h``, ``%m``, ``%b``, ``%t``, and + ``%c``. Any instance of ``%p`` in that file name will be replaced by the process ID, so that you can easily distinguish the profile output from multiple @@ -2902,11 +2903,11 @@ instrumentation: ``%p`` is that the storage requirement for raw profile data files is greatly increased. To avoid issues like this, the ``%m`` specifier can used in the profile name. When this specifier is used, the profiler runtime will substitute ``%m`` - with a unique integer identifier associated with the instrumented binary. Additionally, + with an integer identifier associated with the instrumented binary. Additionally, multiple raw profiles dumped from different processes that share a file system (can be on different hosts) will be automatically merged by the profiler runtime during the dumping. If the program links in multiple instrumented shared libraries, each library - will dump the profile data into its own profile data file (with its unique integer + will dump the profile data into its own profile data file (with its integer id embedded in the profile name). Note that the merging enabled by ``%m`` is for raw profile data generated by profiler runtime. The resulting merged "raw" profile data file still needs to be converted to a different format expected by the compiler ( @@ -2916,6 +2917,12 @@ instrumentation: $ LLVM_PROFILE_FILE="code-%m.profraw" ./code + Although rare, binary signatures used by the ``%m`` specifier can have + collisions. In this case, the ``%b`` specifier, which expands to the binary + ID (build ID), can be added. To use it, the program should be compiled with + the build ID linker option (``--build-id`` for GNU ld or LLD). Linux, Windows + and AIX are supported. + See `this `_ section about the ``%t``, and ``%c`` modifiers. diff --git a/compiler-rt/lib/profile/InstrProfilingFile.c b/compiler-rt/lib/profile/InstrProfilingFile.c index bad4cc71801ec40..343063fd6b754f1 100644 --- a/compiler-rt/lib/profile/InstrProfilingFile.c +++ b/compiler-rt/lib/profile/InstrProfilingFile.c @@ -77,6 +77,7 @@ typedef struct lprofFilename { char Hostname[COMPILER_RT_MAX_HOSTLEN]; unsigned NumPids; unsigned NumHosts; + unsigned NumBinaryIds; /* When in-process merging is enabled, this parameter specifies * the total number of profile data files shared by all the processes * spawned from the same
[clang] [compiler-rt] [profile] Add `%b` `LLVM_PROFILE_FILE` option for binary ID (PR #123963)
@@ -2917,7 +2918,7 @@ instrumentation: $ LLVM_PROFILE_FILE="code-%m.profraw" ./code See `this `_ section - about the ``%t``, and ``%c`` modifiers. + about the ``%b``, ``%t``, and ``%c`` modifiers. ArtSin wrote: Done https://github.com/llvm/llvm-project/pull/123963 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][bytecode] Handle CXXPseudoDestructorExprs (PR #125835)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `openmp-offload-amdgpu-runtime` running on `omp-vega20-0` while building `clang` at step 7 "Add check check-offload". Full details are available at: https://lab.llvm.org/buildbot/#/builders/30/builds/15280 Here is the relevant piece of the build log for the reference ``` Step 7 (Add check check-offload) failure: test (failure) TEST 'libomptarget :: amdgcn-amd-amdhsa :: api/omp_host_call.c' FAILED Exit Code: 2 Command Output (stdout): -- # RUN: at line 1 /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/clang -fopenmp-I /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test -I /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -nogpulib -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib -fopenmp-targets=amdgcn-amd-amdhsa /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/api/omp_host_call.c -o /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/api/Output/omp_host_call.c.tmp /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a && /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/api/Output/omp_host_call.c.tmp | /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/FileCheck /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/api/omp_host_call.c # executed command: /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/clang -fopenmp -I /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test -I /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -nogpulib -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib -fopenmp-targets=amdgcn-amd-amdhsa /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/api/omp_host_call.c -o /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/api/Output/omp_host_call.c.tmp /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a # note: command had no output on stdout or stderr # executed command: /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/api/Output/omp_host_call.c.tmp # note: command had no output on stdout or stderr # error: command failed with exit status: -11 # executed command: /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/FileCheck /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/api/omp_host_call.c # .---command stderr # | FileCheck error: '' is empty. # | FileCheck command line: /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/FileCheck /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/api/omp_host_call.c # `- # error: command failed with exit status: 2 -- ``` https://github.com/llvm/llvm-project/pull/125835 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add support for the c2000 architecture (PR #125663)
https://github.com/student433 edited https://github.com/llvm/llvm-project/pull/125663 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Do not destruct fields of unions (PR #122330)
https://github.com/Xazax-hun approved this pull request. LG, thanks! https://github.com/llvm/llvm-project/pull/122330 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [llvm][DebugInfo] Add new DW_AT_APPLE_enum_kind to encode enum_extensibility (PR #124752)
https://github.com/Michael137 edited https://github.com/llvm/llvm-project/pull/124752 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [llvm][DebugInfo] Add new DW_AT_APPLE_enum_kind to encode enum_extensibility (PR #124752)
Michael137 wrote: I've only included the LLVM changes here now (anything metadata and DWARF attribute related). Will do the plumbing from the frontend in a separate patch https://github.com/llvm/llvm-project/pull/124752 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add support for the c2000 architecture (PR #125663)
https://github.com/student433 edited https://github.com/llvm/llvm-project/pull/125663 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang-linker-wrapper] Add ELF packaging for spirv64-intel OpenMP images (PR #125737)
https://github.com/sarnex updated https://github.com/llvm/llvm-project/pull/125737 >From d4b3358e1ccbae6889aaef280431f06a115102e0 Mon Sep 17 00:00:00 2001 From: "Sarnie, Nick" Date: Wed, 22 Jan 2025 08:35:49 -0800 Subject: [PATCH 1/2] [clang-linker-wrapper] Add ELF packaging for spirv64-intel OpenMP images Signed-off-by: Sarnie, Nick --- .../Inputs/clang-linker-wrapper-spirv-elf.o | Bin 0 -> 1344 bytes .../clang-linker-wrapper-spirv-elf.cpp| 14 +++ clang/test/Tooling/lit.local.cfg | 6 ++ clang/test/lit.site.cfg.py.in | 1 + .../ClangLinkerWrapper.cpp| 15 .../llvm/Frontend/Offloading/Utility.h| 6 ++ llvm/lib/Frontend/Offloading/CMakeLists.txt | 1 + llvm/lib/Frontend/Offloading/Utility.cpp | 85 ++ 8 files changed, 128 insertions(+) create mode 100644 clang/test/Tooling/Inputs/clang-linker-wrapper-spirv-elf.o create mode 100644 clang/test/Tooling/clang-linker-wrapper-spirv-elf.cpp diff --git a/clang/test/Tooling/Inputs/clang-linker-wrapper-spirv-elf.o b/clang/test/Tooling/Inputs/clang-linker-wrapper-spirv-elf.o new file mode 100644 index ..3e5bddcedfff16395b215ef438b5c4ce7c4ada9b GIT binary patch literal 1344 zcmb_bPiqrV5T8wIs#a?%B0@a`yi_Ecq)D2Mh(t=YlwgZc(1Wy_-M7iw{m14Rs|b1$ zz4-+MzkuJN;K8rpu@^spcOlN~&ZgT(y*W$v_kO>bc{4lj<=saAVL{U%GY#&;3CmP~ zqr%C$mn?g55hHguKmGc#@rRVg(ev+6o|eB+{xKUld7 z!FpdGOB*n+nB-Az5uce^o*4`)6A_QyFsQ87b$o`dtgMWrjK+6sH6){#1KkS!n&(Z@ zS2c>m7s8S{MYgSGceT-K7;8Ns_x-F+OXg9@es(FnIYj2)_ zc39SyFU_C-jLqIeoql9j==ET+{GqUZxwM4=#Q$Ms)aT&$^elJ!#iu>jkzSomkZYk< z;V_y{Hs3_jr8ty8pYMx6f}>ke1itA8pa-E8`lH9Y)v+|K1JG$adgwS_XxeTtOoctu zwsE$|V&R#(80|T+=?lPPiKRI}eC-qdCwqqbkfa^?7p#w?n&N=(~s^^-g-=u zv&lJV{&~BDWT8I|5#HzZ9VW+l5!dS3;w4Y&*Oj linkDevice(ArrayRef InputFiles, } } +Error containerizeRawImage(std::unique_ptr &Img, OffloadKind Kind, + const ArgList &Args) { + llvm::Triple Triple(Args.getLastArgValue(OPT_triple_EQ)); + if (Kind != OFK_OpenMP || !Triple.isSPIRV() || + Triple.getVendor() != llvm::Triple::Intel) +return Error::success(); + if (Error E = offloading::intel::containerizeOpenMPSPIRVImage(Img)) +return E; + return Error::success(); +} + Expected writeOffloadFile(const OffloadFile &File) { const OffloadBinary &Binary = *File.getBinary(); @@ -960,6 +971,10 @@ Expected> linkAndWrapDeviceFiles( return createFileError(*OutputOrErr, EC); } + // Manually containerize offloading images not in ELF format. + if (Error E = containerizeRawImage(*FileOrErr, Kind, LinkerArgs)) +return E; + std::scoped_lock Guard(ImageMtx); OffloadingImage TheImage{}; TheImage.TheImageKind = diff --git a/llvm/include/llvm/Frontend/Offloading/Utility.h b/llvm/include/llvm/Frontend/Offloading/Utility.h index 7932fd5acbe1e2..9140371a8c2ed2 100644 --- a/llvm/include/llvm/Frontend/Offloading/Utility.h +++ b/llvm/include/llvm/Frontend/Offloading/Utility.h @@ -10,6 +10,7 @@ #define LLVM_FRONTEND_OFFLOADING_UTILITY_H #include +#include #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" @@ -152,6 +153,11 @@ Error getAMDGPUMetaDataFromImage(MemoryBufferRef MemBuffer, StringMap &KernelInfoMap, uint16_t &ELFABIVersion); } // namespace amdgpu +namespace intel { +/// Containerizes an offloading binary into the ELF binary format expected by +/// the Intel runtime offload plugin. +Error containerizeOpenMPSPIRVImage(std::unique_ptr &Binary); +} // namespace intel } // namespace offloading } // namespace llvm diff --git a/llvm/lib/Frontend/Offloading/CMakeLists.txt b/llvm/lib/Frontend/Offloading/CMakeLists.txt index ce445ad9cc4cb6..8e1ede9c72b391 100644 --- a/llvm/lib/Frontend/Offloading/CMakeLists.txt +++ b/llvm/lib/Frontend/Offloading/CMakeLists.txt @@ -12,6 +12,7 @@ add_llvm_component_library(LLVMFrontendOffloading Core BinaryFormat Object + ObjectYAML Support TransformUtils TargetParser diff --git a/llvm/lib/Frontend/Offloading/Utility.cpp b/llvm/lib/Frontend/Offloading/Utility.cpp index 8117a42b8a45cd..f9c74ab975d102 100644 --- a/llvm/lib/Frontend/Offloading/Utility.cpp +++ b/llvm/lib/Frontend/Offloading/Utility.cpp @@ -15,6 +15,8 @@ #include "llvm/IR/GlobalVariable.h" #include "llvm/IR/Value.h" #include "llvm/Object/ELFObjectFile.h" +#include "llvm/ObjectYAML/ELFYAML.h" +#include "llvm/ObjectYAML/yaml2obj.h" #include "llvm/Support/MemoryBufferRef.h" #include "llvm/Transforms/Utils/ModuleUtils.h" @@ -373,3 +375,86 @@ Error llvm::offloading::amdgpu::getAMDGPUMetaDataFromImage( } return Error::success(); } +Error offloading::intel::containerizeOpenMPSPIRVImage( +std::unique_ptr &Img) { + constexpr char INTEL_ONEOMP_OFFLOAD_VERSION[] = "1.0"; + constexpr int NT_INTEL_ONEOMP_OFFLOAD_VERSION = 1; + constexpr int NT_INTEL_ONEOMP_OFFLOAD_IMAG
[clang] [analyzer] Remove some false negatives in StackAddrEscapeChecker (PR #125638)
@@ -247,45 +240,134 @@ void StackAddrEscapeChecker::checkPreCall(const CallEvent &Call, } } -void StackAddrEscapeChecker::checkPreStmt(const ReturnStmt *RS, - CheckerContext &C) const { - if (!ChecksEnabled[CK_StackAddrEscapeChecker]) -return; +/// A visitor made for use with a ScanReachableSymbols scanner, used +/// for finding stack regions within an SVal that live on the current +/// stack frame of the given checker context. This visitor excludes +/// NonParamVarRegion that data is bound to in a BlockDataRegion's +/// bindings, since these are likely uninteresting, e.g., in case a +/// temporary is constructed on the stack, but it captures values +/// that would leak. +class FindStackRegionsSymbolVisitor final : public SymbolVisitor { + CheckerContext &Ctxt; + const StackFrameContext *StackFrameContext; + SmallVector &EscapingStackRegions; - const Expr *RetE = RS->getRetValue(); - if (!RetE) -return; - RetE = RetE->IgnoreParens(); +public: + explicit FindStackRegionsSymbolVisitor( + CheckerContext &Ctxt, + SmallVector &StorageForStackRegions) + : Ctxt(Ctxt), StackFrameContext(Ctxt.getStackFrame()), +EscapingStackRegions(StorageForStackRegions) {} - SVal V = C.getSVal(RetE); - const MemRegion *R = V.getAsRegion(); - if (!R) -return; + bool VisitSymbol(SymbolRef sym) override { return true; } - if (const BlockDataRegion *B = dyn_cast(R)) -checkReturnedBlockCaptures(*B, C); + bool VisitMemRegion(const MemRegion *MR) override { +SaveIfEscapes(MR); - if (!isa(R->getMemorySpace()) || isNotInCurrentFrame(R, C)) -return; +if (const BlockDataRegion *BDR = MR->getAs()) + return VisitBlockDataRegionCaptures(BDR); + +return true; + } + +private: + void SaveIfEscapes(const MemRegion *MR) { +const StackSpaceRegion *SSR = +MR->getMemorySpace()->getAs(); +if (SSR && SSR->getStackFrame() == StackFrameContext) + EscapingStackRegions.push_back(MR); + } + + bool VisitBlockDataRegionCaptures(const BlockDataRegion *BDR) { +for (auto Var : BDR->referenced_vars()) { + SVal Val = Ctxt.getState()->getSVal(Var.getCapturedRegion()); + const MemRegion *Region = Val.getAsRegion(); + if (Region) { +SaveIfEscapes(Region); +VisitMemRegion(Region); + } +} + +return false; + } +}; + +/// Given some memory regions that are flagged by FindStackRegionsSymbolVisitor, +/// this function filters out memory regions that are being returned that are +/// likely not true leaks: +/// 1. If returning a block data region that has stack memory space +/// 2. If returning a constructed object that has stack memory space +static SmallVector +FilterReturnExpressionLeaks(const SmallVector &MaybeEscaped, +CheckerContext &C, const Expr *RetE, SVal &RetVal) { + + SmallVector WillEscape; + + const MemRegion *RetRegion = RetVal.getAsRegion(); // Returning a record by value is fine. (In this case, the returned // expression will be a copy-constructor, possibly wrapped in an // ExprWithCleanups node.) if (const ExprWithCleanups *Cleanup = dyn_cast(RetE)) RetE = Cleanup->getSubExpr(); - if (isa(RetE) && RetE->getType()->isRecordType()) -return; + bool IsConstructExpr = + isa(RetE) && RetE->getType()->isRecordType(); // The CK_CopyAndAutoreleaseBlockObject cast causes the block to be copied // so the stack address is not escaping here. + bool IsCopyAndAutoreleaseBlockObj = false; if (const auto *ICE = dyn_cast(RetE)) { -if (isa(R) && -ICE->getCastKind() == CK_CopyAndAutoreleaseBlockObject) { - return; -} +IsCopyAndAutoreleaseBlockObj = +isa_and_nonnull(RetRegion) && +ICE->getCastKind() == CK_CopyAndAutoreleaseBlockObject; + } + + for (const MemRegion *MR : MaybeEscaped) { +if (RetRegion == MR && (IsCopyAndAutoreleaseBlockObj || IsConstructExpr)) + continue; + +// If this is a construct expr of an unelided return value copy, then don't +// warn about returning a region that currently lives on the stack. +if (IsConstructExpr && RetVal.getAs() && Flandini wrote: > We basically want to collect all the pointers from the returned value a > similar way and want to check if any of those point to stack memory. That is what I was hoping this PR was: add a `ScanReachableSymbols` & `SymbolVisitor` that takes all stack regions behind the return SVal and warns on those. Previously, this checker only did this for `BlockDataRegion` captures and it only checked if the return SVal is a stack space region. IIUC, you would like this instead to be reworked into `checkPointerEscape`? https://github.com/llvm/llvm-project/pull/125638 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Make `-Xarch_` handling generic for all toolchains (PR #125421)
DavidSpickett wrote: I've pushed a fix for one of the tests on 32 bit Arm, as it failed on our bot: https://lab.llvm.org/buildbot/#/builders/154/builds/11413/steps/5/logs/FAIL__Clang__offload-Xarch_c Maybe your intent was specifically to have a line that uses the host architecture, if that was the case, we can figure out a `requires:` to somehow make that work. I have access to a machine to reproduce it. The other way to fix it was to use `-Xarch_nvptx32` instead but of course that failed on a 64-bit host. Let me know if you want to follow up on this. https://github.com/llvm/llvm-project/pull/125421 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][test][OpenMP] Fix test assumptions of libomp and clang paths (PR #125891)
@@ -1,49 +1,49 @@ // REQUIRES: x86-registered-target, amdgpu-registered-target // Fail on invalid ROCm Path. -// RUN: not %clang -### --target=x86_64-unknown-linux-gnu -fopenmp --offload-arch=gfx908:xnack+ -fsanitize=address -fgpu-sanitize -nogpuinc --rocm-path=%S/Inputs/rocm-invalid %s 2>&1 \ +// RUN: not %clang -no-canonical-prefixes -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp --offload-arch=gfx908:xnack+ -fsanitize=address -fgpu-sanitize -nogpuinc --rocm-path=%S/Inputs/rocm-invalid %s 2>&1 \ rupprecht wrote: The error is: `clang: error: '-fopenmp-targets' must be used in conjunction with a '-fopenmp' option compatible with offloading; e.g., '-fopenmp=libomp' or '-fopenmp=libiomp5' ` The `-fopenmp-targets` flag is not explicitly set here, I assume it must be added somewhere with the driver based on another param. https://github.com/llvm/llvm-project/pull/125891 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libc] [Clang] Add width handling for shuffle helper (PR #125896)
llvmbot wrote: @llvm/pr-subscribers-backend-x86 Author: Joseph Huber (jhuber6) Changes Summary: The CUDA impelementation has long supported the `width` argument on its shuffle instrucitons, which makes it more difficult to replace those uses with this helper. This patch just correctly implements that for AMDGPU and NVPTX so it's equivalent to `__shfl_sync` in CUDA. This will ease porting. --- Full diff: https://github.com/llvm/llvm-project/pull/125896.diff 4 Files Affected: - (modified) clang/lib/Headers/amdgpuintrin.h (+9-5) - (modified) clang/lib/Headers/gpuintrin.h (+14-10) - (modified) clang/lib/Headers/nvptxintrin.h (+8-7) - (modified) libc/src/__support/GPU/utils.h (+3-2) ``diff diff --git a/clang/lib/Headers/amdgpuintrin.h b/clang/lib/Headers/amdgpuintrin.h index 038605605462f8..9dad99ffe9439a 100644 --- a/clang/lib/Headers/amdgpuintrin.h +++ b/clang/lib/Headers/amdgpuintrin.h @@ -145,17 +145,21 @@ _DEFAULT_FN_ATTRS static __inline__ void __gpu_sync_lane(uint64_t __lane_mask) { // Shuffles the the lanes inside the wavefront according to the given index. _DEFAULT_FN_ATTRS static __inline__ uint32_t -__gpu_shuffle_idx_u32(uint64_t __lane_mask, uint32_t __idx, uint32_t __x) { - return __builtin_amdgcn_ds_bpermute(__idx << 2, __x); +__gpu_shuffle_idx_u32(uint64_t __lane_mask, uint32_t __idx, uint32_t __x, + uint32_t __width) { + uint32_t __lane = __idx + (__gpu_lane_id() & ~(__width - 1)); + return __builtin_amdgcn_ds_bpermute(__lane << 2, __x); } // Shuffles the the lanes inside the wavefront according to the given index. _DEFAULT_FN_ATTRS static __inline__ uint64_t -__gpu_shuffle_idx_u64(uint64_t __lane_mask, uint32_t __idx, uint64_t __x) { +__gpu_shuffle_idx_u64(uint64_t __lane_mask, uint32_t __idx, uint64_t __x, + uint32_t __width) { uint32_t __hi = (uint32_t)(__x >> 32ull); uint32_t __lo = (uint32_t)(__x & 0x); - return ((uint64_t)__builtin_amdgcn_ds_bpermute(__idx << 2, __hi) << 32ull) | - ((uint64_t)__builtin_amdgcn_ds_bpermute(__idx << 2, __lo)); + return ((uint64_t)__gpu_shuffle_idx_u32(__lane_mask, __idx, __hi, __width) + << 32ull) | + ((uint64_t)__gpu_shuffle_idx_u32(__lane_mask, __idx, __lo, __width)); } // Returns true if the flat pointer points to AMDGPU 'shared' memory. diff --git a/clang/lib/Headers/gpuintrin.h b/clang/lib/Headers/gpuintrin.h index 4c463c08fc..11c87e85cd4975 100644 --- a/clang/lib/Headers/gpuintrin.h +++ b/clang/lib/Headers/gpuintrin.h @@ -133,18 +133,21 @@ __gpu_read_first_lane_f64(uint64_t __lane_mask, double __x) { // Shuffles the the lanes according to the given index. _DEFAULT_FN_ATTRS static __inline__ float -__gpu_shuffle_idx_f32(uint64_t __lane_mask, uint32_t __idx, float __x) { +__gpu_shuffle_idx_f32(uint64_t __lane_mask, uint32_t __idx, float __x, + uint32_t __width) { return __builtin_bit_cast( float, __gpu_shuffle_idx_u32(__lane_mask, __idx, - __builtin_bit_cast(uint32_t, __x))); + __builtin_bit_cast(uint32_t, __x), __width)); } // Shuffles the the lanes according to the given index. _DEFAULT_FN_ATTRS static __inline__ double -__gpu_shuffle_idx_f64(uint64_t __lane_mask, uint32_t __idx, double __x) { +__gpu_shuffle_idx_f64(uint64_t __lane_mask, uint32_t __idx, double __x, + uint32_t __width) { return __builtin_bit_cast( - double, __gpu_shuffle_idx_u64(__lane_mask, __idx, -__builtin_bit_cast(uint64_t, __x))); + double, + __gpu_shuffle_idx_u64(__lane_mask, __idx, +__builtin_bit_cast(uint64_t, __x), __width)); } // Gets the sum of all lanes inside the warp or wavefront. @@ -153,7 +156,8 @@ __gpu_shuffle_idx_f64(uint64_t __lane_mask, uint32_t __idx, double __x) { uint64_t __lane_mask, __type __x) { \ for (uint32_t __step = __gpu_num_lanes() / 2; __step > 0; __step /= 2) { \ uint32_t __index = __step + __gpu_lane_id(); \ - __x += __gpu_shuffle_idx_##__suffix(__lane_mask, __index, __x); \ + __x += __gpu_shuffle_idx_##__suffix(__lane_mask, __index, __x, \ + __gpu_num_lanes()); \ } \ return __gpu_read_first_lane_##__suffix(__lane_mask, __x); \ } @@ -171,10 +175,10 @@ __DO_LANE_SUM(double, f64); // double __gpu_lane_sum_f64(m, x) uint32_t __index = __gpu_lane_id() - __step; \ __bitmask_type bitmask = __gpu_lane_id() >= __step; \ __x += __builtin_bit_cast( \ - __type,
[clang] [libc] [Clang] Add width handling for shuffle helper (PR #125896)
https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/125896 Summary: The CUDA impelementation has long supported the `width` argument on its shuffle instrucitons, which makes it more difficult to replace those uses with this helper. This patch just correctly implements that for AMDGPU and NVPTX so it's equivalent to `__shfl_sync` in CUDA. This will ease porting. >From 1bb963028e1b52c61286a8723475acd5ad0cb9ba Mon Sep 17 00:00:00 2001 From: Joseph Huber Date: Wed, 5 Feb 2025 11:46:45 -0600 Subject: [PATCH] [Clang] Add width handling for shuffle helper Summary: The CUDA impelementation has long supported the `width` argument on its shuffle instrucitons, which makes it more difficult to replace those uses with this helper. This patch just correctly implements that for AMDGPU and NVPTX so it's equivalent to `__shfl_sync` in CUDA. This will ease porting. --- clang/lib/Headers/amdgpuintrin.h | 14 +- clang/lib/Headers/gpuintrin.h| 24 ++-- clang/lib/Headers/nvptxintrin.h | 15 --- libc/src/__support/GPU/utils.h | 5 +++-- 4 files changed, 34 insertions(+), 24 deletions(-) diff --git a/clang/lib/Headers/amdgpuintrin.h b/clang/lib/Headers/amdgpuintrin.h index 038605605462f80..9dad99ffe9439ab 100644 --- a/clang/lib/Headers/amdgpuintrin.h +++ b/clang/lib/Headers/amdgpuintrin.h @@ -145,17 +145,21 @@ _DEFAULT_FN_ATTRS static __inline__ void __gpu_sync_lane(uint64_t __lane_mask) { // Shuffles the the lanes inside the wavefront according to the given index. _DEFAULT_FN_ATTRS static __inline__ uint32_t -__gpu_shuffle_idx_u32(uint64_t __lane_mask, uint32_t __idx, uint32_t __x) { - return __builtin_amdgcn_ds_bpermute(__idx << 2, __x); +__gpu_shuffle_idx_u32(uint64_t __lane_mask, uint32_t __idx, uint32_t __x, + uint32_t __width) { + uint32_t __lane = __idx + (__gpu_lane_id() & ~(__width - 1)); + return __builtin_amdgcn_ds_bpermute(__lane << 2, __x); } // Shuffles the the lanes inside the wavefront according to the given index. _DEFAULT_FN_ATTRS static __inline__ uint64_t -__gpu_shuffle_idx_u64(uint64_t __lane_mask, uint32_t __idx, uint64_t __x) { +__gpu_shuffle_idx_u64(uint64_t __lane_mask, uint32_t __idx, uint64_t __x, + uint32_t __width) { uint32_t __hi = (uint32_t)(__x >> 32ull); uint32_t __lo = (uint32_t)(__x & 0x); - return ((uint64_t)__builtin_amdgcn_ds_bpermute(__idx << 2, __hi) << 32ull) | - ((uint64_t)__builtin_amdgcn_ds_bpermute(__idx << 2, __lo)); + return ((uint64_t)__gpu_shuffle_idx_u32(__lane_mask, __idx, __hi, __width) + << 32ull) | + ((uint64_t)__gpu_shuffle_idx_u32(__lane_mask, __idx, __lo, __width)); } // Returns true if the flat pointer points to AMDGPU 'shared' memory. diff --git a/clang/lib/Headers/gpuintrin.h b/clang/lib/Headers/gpuintrin.h index 4c463c08fce..11c87e85cd49754 100644 --- a/clang/lib/Headers/gpuintrin.h +++ b/clang/lib/Headers/gpuintrin.h @@ -133,18 +133,21 @@ __gpu_read_first_lane_f64(uint64_t __lane_mask, double __x) { // Shuffles the the lanes according to the given index. _DEFAULT_FN_ATTRS static __inline__ float -__gpu_shuffle_idx_f32(uint64_t __lane_mask, uint32_t __idx, float __x) { +__gpu_shuffle_idx_f32(uint64_t __lane_mask, uint32_t __idx, float __x, + uint32_t __width) { return __builtin_bit_cast( float, __gpu_shuffle_idx_u32(__lane_mask, __idx, - __builtin_bit_cast(uint32_t, __x))); + __builtin_bit_cast(uint32_t, __x), __width)); } // Shuffles the the lanes according to the given index. _DEFAULT_FN_ATTRS static __inline__ double -__gpu_shuffle_idx_f64(uint64_t __lane_mask, uint32_t __idx, double __x) { +__gpu_shuffle_idx_f64(uint64_t __lane_mask, uint32_t __idx, double __x, + uint32_t __width) { return __builtin_bit_cast( - double, __gpu_shuffle_idx_u64(__lane_mask, __idx, -__builtin_bit_cast(uint64_t, __x))); + double, + __gpu_shuffle_idx_u64(__lane_mask, __idx, +__builtin_bit_cast(uint64_t, __x), __width)); } // Gets the sum of all lanes inside the warp or wavefront. @@ -153,7 +156,8 @@ __gpu_shuffle_idx_f64(uint64_t __lane_mask, uint32_t __idx, double __x) { uint64_t __lane_mask, __type __x) { \ for (uint32_t __step = __gpu_num_lanes() / 2; __step > 0; __step /= 2) { \ uint32_t __index = __step + __gpu_lane_id(); \ - __x += __gpu_shuffle_idx_##__suffix(__lane_mask, __index, __x); \ + __x += __gpu_shuffle_idx_##__suffix(__lane_mask, __index, __x, \ + __gpu_num_lanes()); \ } \ return __gpu_read_first_lane_##__suffix(__
[clang] [libc] [Clang] Add width handling for shuffle helper (PR #125896)
llvmbot wrote: @llvm/pr-subscribers-libc Author: Joseph Huber (jhuber6) Changes Summary: The CUDA impelementation has long supported the `width` argument on its shuffle instrucitons, which makes it more difficult to replace those uses with this helper. This patch just correctly implements that for AMDGPU and NVPTX so it's equivalent to `__shfl_sync` in CUDA. This will ease porting. --- Full diff: https://github.com/llvm/llvm-project/pull/125896.diff 4 Files Affected: - (modified) clang/lib/Headers/amdgpuintrin.h (+9-5) - (modified) clang/lib/Headers/gpuintrin.h (+14-10) - (modified) clang/lib/Headers/nvptxintrin.h (+8-7) - (modified) libc/src/__support/GPU/utils.h (+3-2) ``diff diff --git a/clang/lib/Headers/amdgpuintrin.h b/clang/lib/Headers/amdgpuintrin.h index 038605605462f8..9dad99ffe9439a 100644 --- a/clang/lib/Headers/amdgpuintrin.h +++ b/clang/lib/Headers/amdgpuintrin.h @@ -145,17 +145,21 @@ _DEFAULT_FN_ATTRS static __inline__ void __gpu_sync_lane(uint64_t __lane_mask) { // Shuffles the the lanes inside the wavefront according to the given index. _DEFAULT_FN_ATTRS static __inline__ uint32_t -__gpu_shuffle_idx_u32(uint64_t __lane_mask, uint32_t __idx, uint32_t __x) { - return __builtin_amdgcn_ds_bpermute(__idx << 2, __x); +__gpu_shuffle_idx_u32(uint64_t __lane_mask, uint32_t __idx, uint32_t __x, + uint32_t __width) { + uint32_t __lane = __idx + (__gpu_lane_id() & ~(__width - 1)); + return __builtin_amdgcn_ds_bpermute(__lane << 2, __x); } // Shuffles the the lanes inside the wavefront according to the given index. _DEFAULT_FN_ATTRS static __inline__ uint64_t -__gpu_shuffle_idx_u64(uint64_t __lane_mask, uint32_t __idx, uint64_t __x) { +__gpu_shuffle_idx_u64(uint64_t __lane_mask, uint32_t __idx, uint64_t __x, + uint32_t __width) { uint32_t __hi = (uint32_t)(__x >> 32ull); uint32_t __lo = (uint32_t)(__x & 0x); - return ((uint64_t)__builtin_amdgcn_ds_bpermute(__idx << 2, __hi) << 32ull) | - ((uint64_t)__builtin_amdgcn_ds_bpermute(__idx << 2, __lo)); + return ((uint64_t)__gpu_shuffle_idx_u32(__lane_mask, __idx, __hi, __width) + << 32ull) | + ((uint64_t)__gpu_shuffle_idx_u32(__lane_mask, __idx, __lo, __width)); } // Returns true if the flat pointer points to AMDGPU 'shared' memory. diff --git a/clang/lib/Headers/gpuintrin.h b/clang/lib/Headers/gpuintrin.h index 4c463c08fc..11c87e85cd4975 100644 --- a/clang/lib/Headers/gpuintrin.h +++ b/clang/lib/Headers/gpuintrin.h @@ -133,18 +133,21 @@ __gpu_read_first_lane_f64(uint64_t __lane_mask, double __x) { // Shuffles the the lanes according to the given index. _DEFAULT_FN_ATTRS static __inline__ float -__gpu_shuffle_idx_f32(uint64_t __lane_mask, uint32_t __idx, float __x) { +__gpu_shuffle_idx_f32(uint64_t __lane_mask, uint32_t __idx, float __x, + uint32_t __width) { return __builtin_bit_cast( float, __gpu_shuffle_idx_u32(__lane_mask, __idx, - __builtin_bit_cast(uint32_t, __x))); + __builtin_bit_cast(uint32_t, __x), __width)); } // Shuffles the the lanes according to the given index. _DEFAULT_FN_ATTRS static __inline__ double -__gpu_shuffle_idx_f64(uint64_t __lane_mask, uint32_t __idx, double __x) { +__gpu_shuffle_idx_f64(uint64_t __lane_mask, uint32_t __idx, double __x, + uint32_t __width) { return __builtin_bit_cast( - double, __gpu_shuffle_idx_u64(__lane_mask, __idx, -__builtin_bit_cast(uint64_t, __x))); + double, + __gpu_shuffle_idx_u64(__lane_mask, __idx, +__builtin_bit_cast(uint64_t, __x), __width)); } // Gets the sum of all lanes inside the warp or wavefront. @@ -153,7 +156,8 @@ __gpu_shuffle_idx_f64(uint64_t __lane_mask, uint32_t __idx, double __x) { uint64_t __lane_mask, __type __x) { \ for (uint32_t __step = __gpu_num_lanes() / 2; __step > 0; __step /= 2) { \ uint32_t __index = __step + __gpu_lane_id(); \ - __x += __gpu_shuffle_idx_##__suffix(__lane_mask, __index, __x); \ + __x += __gpu_shuffle_idx_##__suffix(__lane_mask, __index, __x, \ + __gpu_num_lanes()); \ } \ return __gpu_read_first_lane_##__suffix(__lane_mask, __x); \ } @@ -171,10 +175,10 @@ __DO_LANE_SUM(double, f64); // double __gpu_lane_sum_f64(m, x) uint32_t __index = __gpu_lane_id() - __step; \ __bitmask_type bitmask = __gpu_lane_id() >= __step; \ __x += __builtin_bit_cast( \ - __type,
[clang] [libc] [Clang] Add width handling for shuffle helper (PR #125896)
https://github.com/jhuber6 edited https://github.com/llvm/llvm-project/pull/125896 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][OpenMP] OpenMP 6.0 updates to restrictions with order/concurrent (PR #125621)
ddpagan wrote: @alexey-bataev - question: I didn't see an approval from you but the PR says that I can merge. Did I miss something? https://github.com/llvm/llvm-project/pull/125621 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][bytecode] Mark IndirectFieldDecl chain links as initialized (PR #125869)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) Changes We only initialize the final field above, so make sure we're marking the links in the chain on the way there as initialized as well. --- Full diff: https://github.com/llvm/llvm-project/pull/125869.diff 2 Files Affected: - (modified) clang/lib/AST/ByteCode/Compiler.cpp (+16) - (modified) clang/test/AST/ByteCode/unions.cpp (+22) ``diff diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index cf89cdc667acc2..1e1e96a1c4782f 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -5604,6 +5604,22 @@ bool Compiler::compileConstructor(const CXXConstructorDecl *Ctor) { if (!emitFieldInitializer(NestedField, NestedFieldOffset, InitExpr)) return false; + + // Mark all chain links as initialized. + unsigned InitFieldOffset = 0; + for (const NamedDecl *ND : IFD->chain().drop_back()) { +const auto *FD = cast(ND); +const Record *FieldRecord = this->P.getOrCreateRecord(FD->getParent()); +assert(FieldRecord); +NestedField = FieldRecord->getField(FD); +InitFieldOffset += NestedField->Offset; +assert(NestedField); +if (!this->emitGetPtrThisField(InitFieldOffset, InitExpr)) + return false; +if (!this->emitFinishInitPop(InitExpr)) + return false; + } + } else { assert(Init->isDelegatingInitializer()); if (!this->emitThis(InitExpr)) diff --git a/clang/test/AST/ByteCode/unions.cpp b/clang/test/AST/ByteCode/unions.cpp index b1fbb0c4dfc06a..c6b5e34810f05d 100644 --- a/clang/test/AST/ByteCode/unions.cpp +++ b/clang/test/AST/ByteCode/unions.cpp @@ -463,4 +463,26 @@ namespace MoveAssign { } static_assert(f()== 12); } + +namespace IFD { + template + struct Optional { +struct { + union { +char null_state; +T val; + }; +}; +constexpr Optional() : null_state(){} + }; + + constexpr bool test() + { +Optional opt{}; +Optional opt2{}; +opt = opt2; +return true; + } + static_assert(test()); +} #endif `` https://github.com/llvm/llvm-project/pull/125869 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang-linker-wrapper] Add ELF packaging for spirv64-intel OpenMP images (PR #125737)
@@ -373,3 +375,86 @@ Error llvm::offloading::amdgpu::getAMDGPUMetaDataFromImage( } return Error::success(); } +Error offloading::intel::containerizeOpenMPSPIRVImage( +std::unique_ptr &Img) { + constexpr char INTEL_ONEOMP_OFFLOAD_VERSION[] = "1.0"; + constexpr int NT_INTEL_ONEOMP_OFFLOAD_VERSION = 1; + constexpr int NT_INTEL_ONEOMP_OFFLOAD_IMAGE_COUNT = 2; + constexpr int NT_INTEL_ONEOMP_OFFLOAD_IMAGE_AUX = 3; + + // Start creating notes for the ELF container. + std::vector Notes; + std::string Version = toHex(INTEL_ONEOMP_OFFLOAD_VERSION); + Notes.emplace_back(ELFYAML::NoteEntry{"INTELONEOMPOFFLOAD", +yaml::BinaryRef(Version), +NT_INTEL_ONEOMP_OFFLOAD_VERSION}); + + // The AuxInfo string will hold auxiliary information for the image. + // ELFYAML::NoteEntry structures will hold references to the + // string, so we have to make sure the string is valid. + std::string AuxInfo; + + // TODO: Pass compile/link opts + StringRef CompileOpts = ""; + StringRef LinkOpts = ""; + + unsigned ImageFmt = 1; // SPIR-V format + + AuxInfo = toHex((Twine(0) + Twine('\0') + Twine(ImageFmt) + Twine('\0') + + CompileOpts + Twine('\0') + LinkOpts) + .str()); + Notes.emplace_back(ELFYAML::NoteEntry{"INTELONEOMPOFFLOAD", +yaml::BinaryRef(AuxInfo), +NT_INTEL_ONEOMP_OFFLOAD_IMAGE_AUX}); + + std::string ImgCount = toHex(Twine(1).str()); // always one image per ELF + Notes.emplace_back(ELFYAML::NoteEntry{"INTELONEOMPOFFLOAD", +yaml::BinaryRef(ImgCount), +NT_INTEL_ONEOMP_OFFLOAD_IMAGE_COUNT}); + + std::string YamlFile; + llvm::raw_string_ostream YamlFileStream(YamlFile); + + // Write YAML template file. + { sarnex wrote: No, will remove, thanks https://github.com/llvm/llvm-project/pull/125737 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang-linker-wrapper] Add ELF packaging for spirv64-intel OpenMP images (PR #125737)
sarnex wrote: Sorry, I thought the feedback from the other PR was to check in a binary, will remove and generate it as part of the test. https://github.com/llvm/llvm-project/pull/125737 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang-linker-wrapper] Add ELF packaging for spirv64-intel OpenMP images (PR #125737)
https://github.com/sarnex edited https://github.com/llvm/llvm-project/pull/125737 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add clang atomic control options and attribute (PR #114841)
@@ -764,6 +764,73 @@ void Parser::ParseGNUAttributeArgs( ScopeLoc, Form); } +void Parser::ParseAtomicAttribute( yxsamliu wrote: I've simplified ParseAtomicAttribute by introducing a lambda that handles parsing a single option (including the optional '!' prefix) so we don't repeat the same code for every argument. This makes the function cleaner and easier to understand while still doing all the necessary work to support multiple atomic options. I've already tested that GCC (https://godbolt.org/z/7qE81dnsq) and MSVC (https://godbolt.org/z/fT5bvbrf5) correctly parse and ignore this attribute if they don’t support it, so the syntax isn’t a problem for other compilers. The current form gives us the flexibility to have fine-grained control over atomic operations, which alternative forms (like trying to fit it into existing attribute formats) wouldn’t allow as cleanly. Those could lead to ambiguity or limit our options later. Overall, while the logic here is a bit special, it’s necessary for handling the variable arguments and negations properly, and the refactoring should help keep it maintainable. https://github.com/llvm/llvm-project/pull/114841 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] disallow attributes on void parameters (PR #124920)
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/124920 >From bd731e4be65fc9c1746aa6a8f63d206eb54bb2be Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Wed, 29 Jan 2025 15:17:06 +0200 Subject: [PATCH 01/13] [Clang] disallow attributes on void parameters --- clang/docs/ReleaseNotes.rst| 2 ++ clang/lib/Parse/ParseDecl.cpp | 7 +++ clang/test/Parser/cxx0x-attributes.cpp | 9 + 3 files changed, 18 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 7fafe2807bd388..0c87e52007d546 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -100,6 +100,8 @@ Removed Compiler Flags Attribute Changes in Clang -- +- Clang now disallows the use of attributes on void parameters. (#GH108819) + Improvements to Clang's diagnostics --- diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index f136d5007e8a5f..0b88dd4449b1e2 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -7986,6 +7986,13 @@ void Parser::ParseParameterDeclarationClause( if (getLangOpts().HLSL) MaybeParseHLSLAnnotations(DS.getAttributes()); +if (ParmDeclarator.getIdentifier() == nullptr && +ParmDeclarator.getDeclarationAttributes().size() && +ParmDeclarator.getDeclSpec().getTypeSpecType() == DeclSpec::TST_void) { + SourceRange AttrRange = ParmDeclarator.getDeclarationAttributes().Range; + Diag(AttrRange.getBegin(), diag::err_attributes_not_allowed) << AttrRange; +} + if (Tok.is(tok::kw_requires)) { // User tried to define a requires clause in a parameter declaration, // which is surely not a function declaration. diff --git a/clang/test/Parser/cxx0x-attributes.cpp b/clang/test/Parser/cxx0x-attributes.cpp index fad3010c98b9c2..13fcdd142fa841 100644 --- a/clang/test/Parser/cxx0x-attributes.cpp +++ b/clang/test/Parser/cxx0x-attributes.cpp @@ -453,3 +453,12 @@ namespace P2361 { } alignas(int) struct AlignAsAttribute {}; // expected-error {{misplaced attributes; expected attributes here}} + +namespace GH108819 { +void a([[maybe_unused]] void) {} // expected-error {{an attribute list cannot appear here}} \ + // expected-warning {{use of the 'maybe_unused' attribute is a C++17 extension}} +void b([[deprecated]] void) {} // expected-error {{an attribute list cannot appear here}} \ + // expected-warning {{use of the 'deprecated' attribute is a C++14 extension}} +void c([[clang::lifetimebound]] void) {} // expected-error {{an attribute list cannot appear here}} +void d([[clang::annotate("a", "b", 1)]] void) {} // expected-error {{an attribute list cannot appear here}} +} >From 063f76730ebfd289f5340d0d8477a43a5ea965c2 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Wed, 29 Jan 2025 15:54:48 +0200 Subject: [PATCH 02/13] remove unnecessary name check --- clang/lib/Parse/ParseDecl.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 0b88dd4449b1e2..934c16c9591520 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -7986,8 +7986,7 @@ void Parser::ParseParameterDeclarationClause( if (getLangOpts().HLSL) MaybeParseHLSLAnnotations(DS.getAttributes()); -if (ParmDeclarator.getIdentifier() == nullptr && -ParmDeclarator.getDeclarationAttributes().size() && +if (ParmDeclarator.getDeclarationAttributes().size() && ParmDeclarator.getDeclSpec().getTypeSpecType() == DeclSpec::TST_void) { SourceRange AttrRange = ParmDeclarator.getDeclarationAttributes().Range; Diag(AttrRange.getBegin(), diag::err_attributes_not_allowed) << AttrRange; >From 3f3431513ad59111794953d27e64608b3ce2e6e1 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Wed, 29 Jan 2025 16:07:18 +0200 Subject: [PATCH 03/13] use empty instead of size --- clang/lib/Parse/ParseDecl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 934c16c9591520..963b59565953d4 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -7986,7 +7986,7 @@ void Parser::ParseParameterDeclarationClause( if (getLangOpts().HLSL) MaybeParseHLSLAnnotations(DS.getAttributes()); -if (ParmDeclarator.getDeclarationAttributes().size() && +if (!ParmDeclarator.getDeclarationAttributes().empty() && ParmDeclarator.getDeclSpec().getTypeSpecType() == DeclSpec::TST_void) { SourceRange AttrRange = ParmDeclarator.getDeclarationAttributes().Range; Diag(AttrRange.getBegin(), diag::err_attributes_not_allowed) << AttrRange; >From 9919006df9ec32023b2bf179b72f9ebaf977bd08 Mon Sep 1
[clang] [HLSL] Fix resource wrapper declaration (PR #125718)
https://github.com/s-perron edited https://github.com/llvm/llvm-project/pull/125718 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang-linker-wrapper] Add ELF packaging for spirv64-intel OpenMP images (PR #125737)
https://github.com/sarnex edited https://github.com/llvm/llvm-project/pull/125737 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [lldb] Reland: [clang] fix P3310 overload resolution flag propagation (PR #125791)
https://github.com/mizvekov closed https://github.com/llvm/llvm-project/pull/125791 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add clang atomic control options and attribute (PR #114841)
@@ -5958,6 +5968,58 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, RenderFloatingPointOptions(TC, D, OFastEnabled, Args, CmdArgs, JA); + if (Arg *AtomicArg = Args.getLastArg(options::OPT_fatomic_EQ)) { yxsamliu wrote: Refactored the code by moving the parsing and validation of the -fatomic= options into a separate helper function. About round-trip processing, the helper function simply reuses the original argument string (via Args.MakeArgString(AtomicArg->getAsString(Args))). This guarantees that the options round-trip correctly through the Render phase without alteration. The atomic lowering options require per-key parsing, duplicate detection, and value validation because we want to allow a single flag to control multiple aspects (namely, no_remote_memory, no_fine_grained_memory, and ignore_denormal_mode). While it might seem complicated at first glance, this design offers significant flexibility and consistency. Alternative approaches such as using separate flags for each option would fragment the interface and could complicate both user documentation and the round-trip (rendering) of these options through the driver. https://github.com/llvm/llvm-project/pull/114841 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang][OpenMP] New OpenMP 6.0 assumption clause, 'no_openmp_construc… (PR #125933)
https://github.com/ddpagan created https://github.com/llvm/llvm-project/pull/125933 …ts'. Add initial parsing/sema support for new assumption clause so clause can be specified. For now, it's ignored, just like the others. Added support for 'no_openmp_construct' to release notes. Testing - Updated appropriate LIT tests. - Testing: check-all >From 86069865d3ae356593c7a28f99cc1a4ec53f3120 Mon Sep 17 00:00:00 2001 From: Dave Pagan Date: Thu, 30 Jan 2025 10:53:30 -0600 Subject: [PATCH] [clang][OpenMP] New OpenMP 6.0 assumption clause, 'no_openmp_constructs'. Add initial parsing/sema support for new assumption clause so clause can be specified. For now, it's ignored, just like the others. Added support for 'no_openmp_construct' to release notes. Testing - Updated appropriate LIT tests. - Testing: check-all --- clang/docs/ReleaseNotes.rst | 1 + clang/include/clang/AST/OpenMPClause.h| 22 ++ clang/include/clang/AST/RecursiveASTVisitor.h | 6 +++ clang/include/clang/Basic/AttrDocs.td | 1 + clang/lib/AST/OpenMPClause.cpp| 5 +++ clang/lib/AST/StmtProfile.cpp | 3 ++ clang/lib/Parse/ParseOpenMP.cpp | 2 + clang/lib/Sema/SemaOpenMP.cpp | 2 + clang/lib/Sema/TreeTransform.h| 5 +++ clang/lib/Serialization/ASTReader.cpp | 6 +++ clang/lib/Serialization/ASTWriter.cpp | 3 ++ clang/test/OpenMP/assume_lambda.cpp | 8 +++- clang/test/OpenMP/assume_nesting_tmpl.cpp | 10 - clang/test/OpenMP/assume_template.cpp | 12 +++-- clang/test/OpenMP/assumes_codegen.cpp | 18 clang/test/OpenMP/assumes_messages.c | 44 +-- clang/test/OpenMP/assumes_messages_attr.c | 28 ++-- clang/test/OpenMP/assumes_print.cpp | 19 clang/test/OpenMP/attr-assume.cpp | 3 +- clang/tools/libclang/CIndex.cpp | 3 ++ llvm/include/llvm/Frontend/OpenMP/OMP.td | 4 ++ .../include/llvm/Frontend/OpenMP/OMPKinds.def | 1 + llvm/lib/IR/Assumptions.cpp | 13 +++--- llvm/lib/Transforms/IPO/OpenMPOpt.cpp | 3 +- llvm/test/Transforms/OpenMP/icv_tracking.ll | 2 + 25 files changed, 157 insertions(+), 67 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 21c1ff25d2862ba..d45e46cab3f923a 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -262,6 +262,7 @@ Python Binding Changes OpenMP Support -- +- Added support 'no_openmp_constructs' assumption clause. Improvements diff --git a/clang/include/clang/AST/OpenMPClause.h b/clang/include/clang/AST/OpenMPClause.h index abdf9333e7125c4..154ecfbaa441820 100644 --- a/clang/include/clang/AST/OpenMPClause.h +++ b/clang/include/clang/AST/OpenMPClause.h @@ -2423,6 +2423,28 @@ class OMPNoOpenMPRoutinesClause final OMPNoOpenMPRoutinesClause() : OMPNoChildClause() {} }; +/// This represents the 'no_openmp_constructs' clause in the + '#pragma omp assume' directive. +/// +/// \code +/// #pragma omp assume no_openmp_constructs +/// \endcode +/// In this example directive '#pragma omp assume' has a 'no_openmp_constructs' +/// clause. +class OMPNoOpenMPConstructsClause final +: public OMPNoChildClause { +public: + /// Build 'no_openmp_constructs' clause. + /// + /// \param StartLoc Starting location of the clause. + /// \param EndLoc Ending location of the clause. + OMPNoOpenMPConstructsClause(SourceLocation StartLoc, SourceLocation EndLoc) + : OMPNoChildClause(StartLoc, EndLoc) {} + + /// Build an empty clause. + OMPNoOpenMPConstructsClause() : OMPNoChildClause() {} +}; + /// This represents the 'no_parallelism' clause in the '#pragma omp assume' /// directive. /// diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h index 55505794e70542c..06c762c080de09d 100644 --- a/clang/include/clang/AST/RecursiveASTVisitor.h +++ b/clang/include/clang/AST/RecursiveASTVisitor.h @@ -3544,6 +3544,12 @@ bool RecursiveASTVisitor::VisitOMPNoOpenMPRoutinesClause( return true; } +template +bool RecursiveASTVisitor::VisitOMPNoOpenMPConstructsClause( +OMPNoOpenMPConstructsClause *) { + return true; +} + template bool RecursiveASTVisitor::VisitOMPNoParallelismClause( OMPNoParallelismClause *) { diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index a8b588169725a2c..0ad4c958d098303 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -5274,6 +5274,7 @@ optimization passes are aware of the following assumptions: "omp_no_openmp" "omp_no_openmp_routines" "omp_no_parallelism" +"omp_no_openmp_constructs" The OpenMP standard defines the meaning of OpenMP assumptions ("omp_XYZ" is spelled "XYZ" in the `OpenMP 5.1 Standard`_). diff --git a/c
[clang] [compiler-rt] [rtsan] Enable RealtimeSanitizer for FreeBSD (PR #125389)
allanjude wrote: We have seen interest in all of the different sanitizers from our embedded customers who use FreeBSD to build appliances. We have done work to extend support in FreeBSD for LLVM's KASAN and KMSAN, and have also seen commercial interest in KCSAN and RTSAN https://github.com/llvm/llvm-project/pull/125389 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang][OpenMP] New OpenMP 6.0 assumption clause, 'no_openmp_construc… (PR #125933)
llvmbot wrote: @llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-modules Author: David Pagan (ddpagan) Changes …ts'. Add initial parsing/sema support for new assumption clause so clause can be specified. For now, it's ignored, just like the others. Added support for 'no_openmp_construct' to release notes. Testing - Updated appropriate LIT tests. - Testing: check-all --- Patch is 51.39 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/125933.diff 25 Files Affected: - (modified) clang/docs/ReleaseNotes.rst (+1) - (modified) clang/include/clang/AST/OpenMPClause.h (+22) - (modified) clang/include/clang/AST/RecursiveASTVisitor.h (+6) - (modified) clang/include/clang/Basic/AttrDocs.td (+1) - (modified) clang/lib/AST/OpenMPClause.cpp (+5) - (modified) clang/lib/AST/StmtProfile.cpp (+3) - (modified) clang/lib/Parse/ParseOpenMP.cpp (+2) - (modified) clang/lib/Sema/SemaOpenMP.cpp (+2) - (modified) clang/lib/Sema/TreeTransform.h (+5) - (modified) clang/lib/Serialization/ASTReader.cpp (+6) - (modified) clang/lib/Serialization/ASTWriter.cpp (+3) - (modified) clang/test/OpenMP/assume_lambda.cpp (+7-1) - (modified) clang/test/OpenMP/assume_nesting_tmpl.cpp (+9-1) - (modified) clang/test/OpenMP/assume_template.cpp (+9-3) - (modified) clang/test/OpenMP/assumes_codegen.cpp (+9-9) - (modified) clang/test/OpenMP/assumes_messages.c (+22-22) - (modified) clang/test/OpenMP/assumes_messages_attr.c (+14-14) - (modified) clang/test/OpenMP/assumes_print.cpp (+10-9) - (modified) clang/test/OpenMP/attr-assume.cpp (+2-1) - (modified) clang/tools/libclang/CIndex.cpp (+3) - (modified) llvm/include/llvm/Frontend/OpenMP/OMP.td (+4) - (modified) llvm/include/llvm/Frontend/OpenMP/OMPKinds.def (+1) - (modified) llvm/lib/IR/Assumptions.cpp (+7-6) - (modified) llvm/lib/Transforms/IPO/OpenMPOpt.cpp (+2-1) - (modified) llvm/test/Transforms/OpenMP/icv_tracking.ll (+2) ``diff diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 21c1ff25d2862ba..d45e46cab3f923a 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -262,6 +262,7 @@ Python Binding Changes OpenMP Support -- +- Added support 'no_openmp_constructs' assumption clause. Improvements diff --git a/clang/include/clang/AST/OpenMPClause.h b/clang/include/clang/AST/OpenMPClause.h index abdf9333e7125c4..154ecfbaa441820 100644 --- a/clang/include/clang/AST/OpenMPClause.h +++ b/clang/include/clang/AST/OpenMPClause.h @@ -2423,6 +2423,28 @@ class OMPNoOpenMPRoutinesClause final OMPNoOpenMPRoutinesClause() : OMPNoChildClause() {} }; +/// This represents the 'no_openmp_constructs' clause in the + '#pragma omp assume' directive. +/// +/// \code +/// #pragma omp assume no_openmp_constructs +/// \endcode +/// In this example directive '#pragma omp assume' has a 'no_openmp_constructs' +/// clause. +class OMPNoOpenMPConstructsClause final +: public OMPNoChildClause { +public: + /// Build 'no_openmp_constructs' clause. + /// + /// \param StartLoc Starting location of the clause. + /// \param EndLoc Ending location of the clause. + OMPNoOpenMPConstructsClause(SourceLocation StartLoc, SourceLocation EndLoc) + : OMPNoChildClause(StartLoc, EndLoc) {} + + /// Build an empty clause. + OMPNoOpenMPConstructsClause() : OMPNoChildClause() {} +}; + /// This represents the 'no_parallelism' clause in the '#pragma omp assume' /// directive. /// diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h index 55505794e70542c..06c762c080de09d 100644 --- a/clang/include/clang/AST/RecursiveASTVisitor.h +++ b/clang/include/clang/AST/RecursiveASTVisitor.h @@ -3544,6 +3544,12 @@ bool RecursiveASTVisitor::VisitOMPNoOpenMPRoutinesClause( return true; } +template +bool RecursiveASTVisitor::VisitOMPNoOpenMPConstructsClause( +OMPNoOpenMPConstructsClause *) { + return true; +} + template bool RecursiveASTVisitor::VisitOMPNoParallelismClause( OMPNoParallelismClause *) { diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index a8b588169725a2c..0ad4c958d098303 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -5274,6 +5274,7 @@ optimization passes are aware of the following assumptions: "omp_no_openmp" "omp_no_openmp_routines" "omp_no_parallelism" +"omp_no_openmp_constructs" The OpenMP standard defines the meaning of OpenMP assumptions ("omp_XYZ" is spelled "XYZ" in the `OpenMP 5.1 Standard`_). diff --git a/clang/lib/AST/OpenMPClause.cpp b/clang/lib/AST/OpenMPClause.cpp index bbf7a4d95654837..424cab3a7de35cb 100644 --- a/clang/lib/AST/OpenMPClause.cpp +++ b/clang/lib/AST/OpenMPClause.cpp @@ -2073,6 +2073,11 @@ void OMPClausePrinter::VisitOMPNoOpenMPRoutinesClause( OS << "no_openmp_routines"; } +void OMPClausePrinter::VisitOMPNoOpenMPConstructsClau
[clang] [libc] [Clang] Add width handling for shuffle helper (PR #125896)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `llvm-clang-win-x-aarch64` running on `as-builder-2` while building `clang,libc` at step 10 "test-check-clang". Full details are available at: https://lab.llvm.org/buildbot/#/builders/193/builds/5476 Here is the relevant piece of the build log for the reference ``` Step 10 (test-check-clang) failure: Test just built components: check-clang completed (failure) TEST 'Clang :: Headers/gpuintrin.c' FAILED Exit Code: 2 Command Output (stdout): -- # RUN: at line 2 c:\buildbot\as-builder-2\x-aarch64\build\bin\clang.exe -cc1 -internal-isystem C:\buildbot\as-builder-2\x-aarch64\build\lib\clang\21\include -nostdsysteminc -internal-isystem C:\buildbot\as-builder-2\x-aarch64\llvm-project\clang\test\Headers/Inputs/include -internal-isystem C:\buildbot\as-builder-2\x-aarch64\llvm-project\clang\test\Headers/../../lib/Headers/ -triple amdgcn-amd-amdhsa -emit-llvm C:\buildbot\as-builder-2\x-aarch64\llvm-project\clang\test\Headers\gpuintrin.c -o - | c:\buildbot\as-builder-2\x-aarch64\build\bin\filecheck.exe C:\buildbot\as-builder-2\x-aarch64\llvm-project\clang\test\Headers\gpuintrin.c --check-prefix=AMDGPU # executed command: 'c:\buildbot\as-builder-2\x-aarch64\build\bin\clang.exe' -cc1 -internal-isystem 'C:\buildbot\as-builder-2\x-aarch64\build\lib\clang\21\include' -nostdsysteminc -internal-isystem 'C:\buildbot\as-builder-2\x-aarch64\llvm-project\clang\test\Headers/Inputs/include' -internal-isystem 'C:\buildbot\as-builder-2\x-aarch64\llvm-project\clang\test\Headers/../../lib/Headers/' -triple amdgcn-amd-amdhsa -emit-llvm 'C:\buildbot\as-builder-2\x-aarch64\llvm-project\clang\test\Headers\gpuintrin.c' -o - # .---command stderr # | C:\buildbot\as-builder-2\x-aarch64\llvm-project\clang\test\Headers\gpuintrin.c:103:35: error: too few arguments to function call, expected 4, have 3 # | 103 | __gpu_shuffle_idx_u32(-1, -1, -1); # | | ~ ^ # | C:\buildbot\as-builder-2\x-aarch64\build\lib\clang\21\include\amdgpuintrin.h:148:1: note: '__gpu_shuffle_idx_u32' declared here # | 148 | __gpu_shuffle_idx_u32(uint64_t __lane_mask, uint32_t __idx, uint32_t __x, # | | ^ ~~~ # | 149 | uint32_t __width) { # | | # | 1 error generated. # `- # error: command failed with exit status: 1 # executed command: 'c:\buildbot\as-builder-2\x-aarch64\build\bin\filecheck.exe' 'C:\buildbot\as-builder-2\x-aarch64\llvm-project\clang\test\Headers\gpuintrin.c' --check-prefix=AMDGPU # .---command stderr # | FileCheck error: '' is empty. # | FileCheck command line: c:\buildbot\as-builder-2\x-aarch64\build\bin\filecheck.exe C:\buildbot\as-builder-2\x-aarch64\llvm-project\clang\test\Headers\gpuintrin.c --check-prefix=AMDGPU # `- # error: command failed with exit status: 2 -- ``` https://github.com/llvm/llvm-project/pull/125896 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [rtsan] Enable RealtimeSanitizer for FreeBSD (PR #125389)
@@ -43,6 +44,21 @@ static __rtsan::Context &GetContextForThisThreadImpl() { return *current_thread_context; } +#else + +// On FreeBSD, pthread api cannot be used as calloc is called under the hood +// at library initialization time. devnexen wrote: I ll try to see what I can do later this week. basically even just compiling a binary doing nothing I get from lldb a recursive call on libpthread initialisation -> calloc, rinse and repeat ... then eventually crash. https://github.com/llvm/llvm-project/pull/125389 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libc] [Clang] Add width handling for shuffle helper (PR #125896)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `llvm-clang-x86_64-darwin` running on `doug-worker-3` while building `clang,libc` at step 6 "test-build-unified-tree-check-all". Full details are available at: https://lab.llvm.org/buildbot/#/builders/23/builds/7317 Here is the relevant piece of the build log for the reference ``` Step 6 (test-build-unified-tree-check-all) failure: test (failure) TEST 'Clang :: Headers/gpuintrin.c' FAILED Exit Code: 2 Command Output (stderr): -- RUN: at line 2: /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/clang -cc1 -internal-isystem /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/lib/clang/21/include -nostdsysteminc -internal-isystem /Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Headers/Inputs/include -internal-isystem /Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Headers/../../lib/Headers/ -triple amdgcn-amd-amdhsa -emit-llvm /Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Headers/gpuintrin.c -o - | /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/FileCheck /Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Headers/gpuintrin.c --check-prefix=AMDGPU + /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/clang -cc1 -internal-isystem /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/lib/clang/21/include -nostdsysteminc -internal-isystem /Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Headers/Inputs/include -internal-isystem /Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Headers/../../lib/Headers/ -triple amdgcn-amd-amdhsa -emit-llvm /Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Headers/gpuintrin.c -o - + /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/FileCheck /Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Headers/gpuintrin.c --check-prefix=AMDGPU /Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Headers/gpuintrin.c:103:35: error: too few arguments to function call, expected 4, have 3 103 | __gpu_shuffle_idx_u32(-1, -1, -1); | ~ ^ /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/lib/clang/21/include/amdgpuintrin.h:148:1: note: '__gpu_shuffle_idx_u32' declared here 148 | __gpu_shuffle_idx_u32(uint64_t __lane_mask, uint32_t __idx, uint32_t __x, | ^ ~~~ 149 | uint32_t __width) { | 1 error generated. FileCheck error: '' is empty. FileCheck command line: /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/FileCheck /Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Headers/gpuintrin.c --check-prefix=AMDGPU -- ``` https://github.com/llvm/llvm-project/pull/125896 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [rtsan] Enable RealtimeSanitizer for FreeBSD (PR #125389)
@@ -43,6 +44,21 @@ static __rtsan::Context &GetContextForThisThreadImpl() { return *current_thread_context; } +#else + +// On FreeBSD, pthread api cannot be used as calloc is called under the hood +// at library initialization time. +static __thread Context *ctx = nullptr; + +static __rtsan::Context &GetContextForThisThreadImpl() { + if (ctx == nullptr) { +ctx = static_cast(MmapOrDie(sizeof(Context), "RtsanContext")); +new (ctx) Context(); devnexen wrote: Yes I tried that originally but it freezes I ll try again or trying to make pthread api works. https://github.com/llvm/llvm-project/pull/125389 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Optimize -Wunsafe-buffer-usage. (PR #125492)
ziqingluo-90 wrote: > > I added @ziqingluo-90 @jkorous-apple as reviewers since you've approved > > recent changes to this warning. Please let us know if you're the right > > reviewers for this and feel free to loop in more people if necessary. > > Thank you @ivanaivanovska, the profiling and research you did is already > valuable. Looks like there are a lot of changes. I will review them but it > may take a while. I know it's annoying, but could you split the change into smaller ones? It gonna be easier to review and with lower risk to break our downstream usage of the warning. https://github.com/llvm/llvm-project/pull/125492 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][X86] Support __attribute__((model("small"/"large"))) (PR #124834)
https://github.com/aeubanks updated https://github.com/llvm/llvm-project/pull/124834 >From 7c40169ec7430ec64aaeb053e423eca1ceff7f0d Mon Sep 17 00:00:00 2001 From: Arthur Eubanks Date: Tue, 28 Jan 2025 20:36:58 + Subject: [PATCH 1/8] [clang][X86] Support __attribute__((model("small"/"large"))) Following up #72078, on x86-64 this allows a global to be considered small or large regardless of the code model. For example, x86-64's medium code model by default classifies globals as small or large depending on their size relative to -mlarge-data-threshold. --- clang/docs/ReleaseNotes.rst | 5 + clang/include/clang/Basic/Attr.td| 13 + clang/lib/Sema/SemaDeclAttr.cpp | 11 ++- clang/test/CodeGen/X86/codemodel.cpp | 27 +++ clang/test/Sema/attr-model.cpp | 22 ++ 5 files changed, 61 insertions(+), 17 deletions(-) create mode 100644 clang/test/CodeGen/X86/codemodel.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 7b5562a80a35a69..dba3ed593dae28e 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -657,6 +657,11 @@ Attribute Changes in Clang - Clang now disallows the use of attributes after the namespace name. (#GH121407) +- Clang now allows ``__attribute__((model("small")))`` and + ``__attribute__((model("large")))`` on non-TLS globals in x86-64 compilations. + This forces the global to be considered small or large in regards to the + x86-64 code model, regardless of the code model specified for the compilation. + Improvements to Clang's diagnostics --- diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index f4ba2bc3c6de31b..092dc751d79f227 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -462,6 +462,7 @@ def TargetMSP430 : TargetArch<["msp430"]>; def TargetM68k : TargetArch<["m68k"]>; def TargetRISCV : TargetArch<["riscv32", "riscv64"]>; def TargetX86 : TargetArch<["x86"]>; +def TargetX86_64 : TargetArch<["x86_64"]>; def TargetAnyX86 : TargetArch<["x86", "x86_64"]>; def TargetWebAssembly : TargetArch<["wasm32", "wasm64"]>; def TargetNVPTX : TargetArch<["nvptx", "nvptx64"]>; @@ -3117,11 +3118,15 @@ def PragmaClangTextSection : InheritableAttr { let Documentation = [InternalOnly]; } -def CodeModel : InheritableAttr, TargetSpecificAttr { +def CodeModel : InheritableAttr, +TargetSpecificAttr> { let Spellings = [GCC<"model">]; - let Args = [EnumArgument<"Model", "llvm::CodeModel::Model", /*is_string=*/1, - ["normal", "medium", "extreme"], ["Small", "Medium", "Large"], - /*opt=*/0, /*fake=*/0, /*isExternalType=*/1, /*isCovered=*/0>]; + let Args = [EnumArgument< + "Model", "llvm::CodeModel::Model", + /*is_string=*/1, ["small", "normal", "medium", "large", "extreme"], + ["Small", "Small", "Medium", "Large", "Large"], + /*opt=*/0, /*fake=*/0, /*isExternalType=*/1, /*isCovered=*/0>]; let Subjects = SubjectList<[NonTLSGlobalVar], ErrorDiag>; let Documentation = [CodeModelDocs]; } diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 9d7d22590bce4b4..e2c752df06c25a4 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -64,6 +64,7 @@ #include "llvm/IR/DerivedTypes.h" #include "llvm/MC/MCSectionMachO.h" #include "llvm/Support/Error.h" +#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" #include "llvm/TargetParser/Triple.h" @@ -2949,6 +2950,13 @@ static void handleSectionAttr(Sema &S, Decl *D, const ParsedAttr &AL) { } } +static bool isValidCodeModelAttr(Sema &S, StringRef Str) { + bool IsX8664Target = + S.Context.getTargetInfo().getTriple().getArch() == llvm::Triple::x86_64; + bool IsX8664Spelling = Str == "small" || Str == "large"; + return IsX8664Target == IsX8664Spelling; +} + static void handleCodeModelAttr(Sema &S, Decl *D, const ParsedAttr &AL) { StringRef Str; SourceLocation LiteralLoc; @@ -2957,7 +2965,8 @@ static void handleCodeModelAttr(Sema &S, Decl *D, const ParsedAttr &AL) { return; llvm::CodeModel::Model CM; - if (!CodeModelAttr::ConvertStrToModel(Str, CM)) { + if (!CodeModelAttr::ConvertStrToModel(Str, CM) || + !isValidCodeModelAttr(S, Str)) { S.Diag(LiteralLoc, diag::err_attr_codemodel_arg) << Str; return; } diff --git a/clang/test/CodeGen/X86/codemodel.cpp b/clang/test/CodeGen/X86/codemodel.cpp new file mode 100644 index 000..60a840665b49cd0 --- /dev/null +++ b/clang/test/CodeGen/X86/codemodel.cpp @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 -emit-llvm -triple x86_64-unknown-unknown %s -o - | FileCheck %s + +// CHECK: @_ZL2v1 ={{.*}} global i32 0, code_model "small" +static int v1 __attribute__((model("small"))); + +void use1() { + v1 = 1; +} + +// CHECK: @
[clang] [clang][X86] Support __attribute__((model("small"/"large"))) (PR #124834)
@@ -62,6 +62,10 @@ def CodeModelDocs : Documentation { let Content = [{ The ``model`` attribute allows overriding the translation unit's code model (specified by ``-mcmodel``) for a specific global variable. + +On LoongArch, allowed values are "normal", "medium", "extreme". aeubanks wrote: I've added some description at least on the x86-64 side of things https://github.com/llvm/llvm-project/pull/124834 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang][OpenMP] New OpenMP 6.0 assumption clause, 'no_openmp_construc… (PR #125933)
llvmbot wrote: @llvm/pr-subscribers-flang-openmp Author: David Pagan (ddpagan) Changes …ts'. Add initial parsing/sema support for new assumption clause so clause can be specified. For now, it's ignored, just like the others. Added support for 'no_openmp_construct' to release notes. Testing - Updated appropriate LIT tests. - Testing: check-all --- Patch is 51.39 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/125933.diff 25 Files Affected: - (modified) clang/docs/ReleaseNotes.rst (+1) - (modified) clang/include/clang/AST/OpenMPClause.h (+22) - (modified) clang/include/clang/AST/RecursiveASTVisitor.h (+6) - (modified) clang/include/clang/Basic/AttrDocs.td (+1) - (modified) clang/lib/AST/OpenMPClause.cpp (+5) - (modified) clang/lib/AST/StmtProfile.cpp (+3) - (modified) clang/lib/Parse/ParseOpenMP.cpp (+2) - (modified) clang/lib/Sema/SemaOpenMP.cpp (+2) - (modified) clang/lib/Sema/TreeTransform.h (+5) - (modified) clang/lib/Serialization/ASTReader.cpp (+6) - (modified) clang/lib/Serialization/ASTWriter.cpp (+3) - (modified) clang/test/OpenMP/assume_lambda.cpp (+7-1) - (modified) clang/test/OpenMP/assume_nesting_tmpl.cpp (+9-1) - (modified) clang/test/OpenMP/assume_template.cpp (+9-3) - (modified) clang/test/OpenMP/assumes_codegen.cpp (+9-9) - (modified) clang/test/OpenMP/assumes_messages.c (+22-22) - (modified) clang/test/OpenMP/assumes_messages_attr.c (+14-14) - (modified) clang/test/OpenMP/assumes_print.cpp (+10-9) - (modified) clang/test/OpenMP/attr-assume.cpp (+2-1) - (modified) clang/tools/libclang/CIndex.cpp (+3) - (modified) llvm/include/llvm/Frontend/OpenMP/OMP.td (+4) - (modified) llvm/include/llvm/Frontend/OpenMP/OMPKinds.def (+1) - (modified) llvm/lib/IR/Assumptions.cpp (+7-6) - (modified) llvm/lib/Transforms/IPO/OpenMPOpt.cpp (+2-1) - (modified) llvm/test/Transforms/OpenMP/icv_tracking.ll (+2) ``diff diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 21c1ff25d2862ba..d45e46cab3f923a 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -262,6 +262,7 @@ Python Binding Changes OpenMP Support -- +- Added support 'no_openmp_constructs' assumption clause. Improvements diff --git a/clang/include/clang/AST/OpenMPClause.h b/clang/include/clang/AST/OpenMPClause.h index abdf9333e7125c4..154ecfbaa441820 100644 --- a/clang/include/clang/AST/OpenMPClause.h +++ b/clang/include/clang/AST/OpenMPClause.h @@ -2423,6 +2423,28 @@ class OMPNoOpenMPRoutinesClause final OMPNoOpenMPRoutinesClause() : OMPNoChildClause() {} }; +/// This represents the 'no_openmp_constructs' clause in the + '#pragma omp assume' directive. +/// +/// \code +/// #pragma omp assume no_openmp_constructs +/// \endcode +/// In this example directive '#pragma omp assume' has a 'no_openmp_constructs' +/// clause. +class OMPNoOpenMPConstructsClause final +: public OMPNoChildClause { +public: + /// Build 'no_openmp_constructs' clause. + /// + /// \param StartLoc Starting location of the clause. + /// \param EndLoc Ending location of the clause. + OMPNoOpenMPConstructsClause(SourceLocation StartLoc, SourceLocation EndLoc) + : OMPNoChildClause(StartLoc, EndLoc) {} + + /// Build an empty clause. + OMPNoOpenMPConstructsClause() : OMPNoChildClause() {} +}; + /// This represents the 'no_parallelism' clause in the '#pragma omp assume' /// directive. /// diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h index 55505794e70542c..06c762c080de09d 100644 --- a/clang/include/clang/AST/RecursiveASTVisitor.h +++ b/clang/include/clang/AST/RecursiveASTVisitor.h @@ -3544,6 +3544,12 @@ bool RecursiveASTVisitor::VisitOMPNoOpenMPRoutinesClause( return true; } +template +bool RecursiveASTVisitor::VisitOMPNoOpenMPConstructsClause( +OMPNoOpenMPConstructsClause *) { + return true; +} + template bool RecursiveASTVisitor::VisitOMPNoParallelismClause( OMPNoParallelismClause *) { diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index a8b588169725a2c..0ad4c958d098303 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -5274,6 +5274,7 @@ optimization passes are aware of the following assumptions: "omp_no_openmp" "omp_no_openmp_routines" "omp_no_parallelism" +"omp_no_openmp_constructs" The OpenMP standard defines the meaning of OpenMP assumptions ("omp_XYZ" is spelled "XYZ" in the `OpenMP 5.1 Standard`_). diff --git a/clang/lib/AST/OpenMPClause.cpp b/clang/lib/AST/OpenMPClause.cpp index bbf7a4d95654837..424cab3a7de35cb 100644 --- a/clang/lib/AST/OpenMPClause.cpp +++ b/clang/lib/AST/OpenMPClause.cpp @@ -2073,6 +2073,11 @@ void OMPClausePrinter::VisitOMPNoOpenMPRoutinesClause( OS << "no_openmp_routines"; } +void OMPClausePrinter::VisitOMPNoOpenMPConstructsClause( +OMPNoOpenMPConstruc
[libunwind] Silence -Wunused-parameter warnings in Unwind-wasm.c (PR #125412)
georgthegreat wrote: I applied @ldionne suggestions, I am fine with his approach. https://github.com/llvm/llvm-project/pull/125412 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [libclang/python] Enable packaging libclang bindings (PR #125806)
@@ -0,0 +1,34 @@ +[build-system] +requires = ["setuptools>=42", "setuptools_scm"] +build-backend = "setuptools.build_meta" + +[project] +name = "clang" +description = "libclang python bindings" +readme = {file = "README.txt", content-type = "text/plain"} + +license = { text = "Apache-2.0 with LLVM exception" } +authors = [ +{ name = "LLVM" } +] +keywords = ["llvm", "clang", "libclang"] +classifiers = [ +"Intended Audience :: Developers", +"License :: OSI Approved :: Apache Software License", +"Development Status :: 5 - Production/Stable", +"Topic :: Software Development :: Compilers", +"Operating System :: OS Independent", +"Programming Language :: Python :: 3", +] +dynamic = ["version"] + +[project.urls] +Homepage = "http://clang.llvm.org/"; +Download = "http://llvm.org/releases/download.html"; LecrisUT wrote: I don't know about where the relevant documentation for that is, if any. Maybe wait for a developer to respond on this https://github.com/llvm/llvm-project/pull/125806 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Improve function pointer CastRParen detection. (PR #126019)
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 52fc6ffcda0895c0c7b976ad1f5cb5a282b571d2 7a9726372f24c7bc42c18b78e989dff3b48bc910 --extensions cpp -- clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/TokenAnnotatorTest.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index fc84f29dd0..fccf37bed2 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -2925,7 +2925,7 @@ private: Prev = Prev->Previous; if (!Prev || Prev->isNot(tok::r_paren)) return false; - const auto* PrevMatchingParen = Prev->MatchingParen; + const auto *PrevMatchingParen = Prev->MatchingParen; if (!PrevMatchingParen) return false; `` https://github.com/llvm/llvm-project/pull/126019 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add support for the c2000 architecture (PR #125663)
SonicStark wrote: Excited to see your nice work!!! AFAIK all *TI extension keywords* may confuse clang frontend, and treating them as macros would result in strange behaviors, e.g. ```c // DSP2833x_PieVect.h typedef interrupt void(*PINT)(void); ``` So special keywords handling would be necessary... See [SPRU514Z - TMS320C28x Optimizing C/C++ Compiler](https://www.ti.com/lit/ug/spru514z/spru514z.pdf): > 6.5 Keywords > The C28x C/C++ compiler supports all of the standard C89 keywords, including > const, volatile, and register. It supports all of the standard C99 keywords, > including inline and restrict. It supports all of the standard C11 keywords. > It also supports TI extension keywords `__interrupt`, `__cregister`, and > `__asm`. > ... > 6.5.2 The `__cregister` Keyword > ... > 6.5.3 The `__interrupt` Keyword > ... CMIIW :) @DragonDisciple https://github.com/llvm/llvm-project/pull/125663 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add support for the c2000 architecture (PR #125663)
@@ -929,7 +936,7 @@ def ObjCXX : Flag<["-"], "ObjC++">, Flags<[NoXarchOption]>, def ObjC : Flag<["-"], "ObjC">, Flags<[NoXarchOption]>, HelpText<"Treat source input files as Objective-C inputs">; def O : Joined<["-"], "O">, Group, - Visibility<[ClangOption, CC1Option, FC1Option, FlangOption]>; + Visibility<[ClangOption, CC1Option, FC1Option, FlangOption, CL2000Option]>; student433 wrote: Since I didn't define all the flags here, which I'm going for now, I think it should be enough to just parse the option https://github.com/llvm/llvm-project/pull/125663 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add support for the c2000 architecture (PR #125663)
@@ -1571,6 +1572,13 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) { } else { Diag(diag::err_drv_dxc_missing_target_profile); } + } else if (IsC2000Mode()) { +llvm::Triple T(TargetTriple); +T.setArch(llvm::Triple::c2000); student433 wrote: I also thought this would make sense and I think currently a 4 component(arch, vendor, OS, env) string is created for triple. Maybe c28-ti-unknown-eabi makes more sense then, if it also makes sense to upstream. https://github.com/llvm/llvm-project/pull/125663 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ARM] Emit an error when the hard-float ABI is enabled but can't be used. (PR #111334)
RalfJung wrote: > there doesn't seem to be a mechanism to issue a warning from within LLVM > codegen, only to error. RISC-V does `errs() << "Hard-float 'f' ABI can't be used for a target that " ...` and that acts as a warning. It just prints a message to stderr. It's not pretty but it's better than generating code that has the wrong ABI and spending an hour debugging that... Rust will always set `Options.FloatABIType` to a non-`Default` value for ARM-32. https://github.com/llvm/llvm-project/pull/111334 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add support for the c2000 architecture (PR #125663)
@@ -9111,3 +9118,50 @@ def wasm_opt : Flag<["--"], "wasm-opt">, Group, HelpText<"Enable the wasm-opt optimizer (default)">, MarshallingInfoNegativeFlag>; + + + +//===--===// +// cl2000 Options +//===--===// + + + + +def cl2000_include_path : Joined<["--"], "include_path=">, Group, student433 wrote: I understand, this merge could be pretty specific to a use-case. This was done when i diagnosed that clangd stopped returning errors and just lop outputs about ignored arguments for compilation for all flags after only the first few were defined here, but of course, that is an individual case, so it would be better to add all flags. I will go for it then! https://github.com/llvm/llvm-project/pull/125663 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix P3310 overload resolution flag propagation (PR #125372)
Michael137 wrote: > Might be as simple as a constant true or false, but I'm nearing the end of my > work day so I've reverted it for now. > > In the meantime, @Michael137 might know if this is something LLDB should > actually be tracking. Or in other words, is #125290 something that can happen > via LLDB too? Probably best to pass a constant `false`/`true` to preserve old behaviour. We can't even instantiate templates in the expression evaluator right now, so don't think we should be worrying about this at the moment https://github.com/llvm/llvm-project/pull/125372 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add support for the c2000 architecture (PR #125663)
student433 wrote: > General comments: > > * Please do not use tabs for spacing. This is what causes the unexpected > whitespace gaps in the diff. > > * There is a utility, clang-format-diff.py, which will assist in > appeasing the code formatting check. However, I noticed running it myself > that it changes some entire lists that should likely stay the way they are, > so be careful! > > * My usual command line is something like: git diff -U0 --no-color > --relative HEAD~1..HEAD | /path/to/clang-format-diff.py -p1 -i -binary > /path/to/clang-format(.exe) > > * Is there no desire to catch and support C2000 built-in functions? Those > will show up in clangd as undefined symbols and will be errors in c99 or > later, and in all C++ modes. > > * Options > > * The options parser for clang and for the TI compilers are obviously > very different. Some options interact with others for the purposes of > ease-of-use and error checking, which is something that the clang options > parser won't understand. I'll do my best to be diligent in case I have to > point this out > * There are many more options than the ones currently captured. Is it > important we get as many as we can? Otherwise this will be a PR that is > tailor-fit to a single use-case. > > * Is there a testing strategy you have in mind? At the very least, we > need to cover the selection of the new mode and options. See > clang/test/Driver/cl-options.c for an example Thank you very much for your inputs, I have yet to add the test cases for cl2000 driver in clang/tests/Driver and pair it with diagnostics as needed. I will be sure to check the clang-format for indentation and other things. Will respond to each comment individually :) > Excited to see your nice work!!! > > AFAIK all _TI extension keywords_ may confuse clang frontend, and treating > them as macros would result in strange behaviors, e.g. > > ```c > // DSP2833x_PieVect.h > typedef interrupt void(*PINT)(void); > ``` > > So special keywords handling would be necessary... > > See [SPRU514Z - TMS320C28x Optimizing C/C++ > Compiler](https://www.ti.com/lit/ug/spru514z/spru514z.pdf): > > > 6.5 Keywords > > The C28x C/C++ compiler supports all of the standard C89 keywords, > > including const, volatile, and register. It supports all of the standard > > C99 keywords, including inline and restrict. It supports all of the > > standard C11 keywords. It also supports TI extension keywords > > `__interrupt`, `__cregister`, and `__asm`. > > ... > > 6.5.2 The `__cregister` Keyword > > ... > > 6.5.3 The `__interrupt` Keyword > > ... > > CMIIW :) @DragonDisciple Thank you very much for your inputs, I understand that these are semantically incorrect and would require a meaningful definition to avoid it being misunderstood. I could look into this :) https://github.com/llvm/llvm-project/pull/125663 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add support for the c2000 architecture (PR #125663)
@@ -0,0 +1,356 @@ +#include "C2000.h" +#include "Targets.h" +#include "clang/Basic/Builtins.h" +#include "clang/Basic/Diagnostic.h" +#include "clang/Basic/MacroBuilder.h" +#include "clang/Basic/TargetBuiltins.h" + +using namespace clang; +using namespace clang::targets; + +const char *const C2000TargetInfo::GCCRegNames[] = { +"ACC", "XAR0", "XAR1", "XAR2", "XAR3", "XAR4", "XAR5", "XAR6", "XAR7"}; student433 wrote: You're right! This is somewhere extended to codegen and support for this syntax could be omitted if TI compilers do not support them :) P.S. it was just added for fulfillment with no strong reason behind it https://github.com/llvm/llvm-project/pull/125663 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add support for the c2000 architecture (PR #125663)
https://github.com/student433 edited https://github.com/llvm/llvm-project/pull/125663 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add support for the c2000 architecture (PR #125663)
@@ -0,0 +1,356 @@ +#include "C2000.h" +#include "Targets.h" +#include "clang/Basic/Builtins.h" +#include "clang/Basic/Diagnostic.h" +#include "clang/Basic/MacroBuilder.h" +#include "clang/Basic/TargetBuiltins.h" + +using namespace clang; +using namespace clang::targets; + +const char *const C2000TargetInfo::GCCRegNames[] = { +"ACC", "XAR0", "XAR1", "XAR2", "XAR3", "XAR4", "XAR5", "XAR6", "XAR7"}; + +ArrayRef C2000TargetInfo::getGCCRegNames() const { + return llvm::ArrayRef(GCCRegNames); +} + +bool C2000TargetInfo::handleTargetFeatures(std::vector &Features, + DiagnosticsEngine &Diags) { + + for (const auto &Feature : Features) { +if (Feature == "+eabi") { + eabi = true; + continue; +} +if (Feature == "+strict_ansi") { + strict = true; + continue; +} +if (Feature == "+cla_support") { + cla_support = true; +} +if (Feature == "+cla0") { + cla0 = true; + continue; +} +if (Feature == "+cla1") { + cla1 = true; + continue; +} +if (Feature == "+cla2") { + cla2 = true; + continue; +} +if (Feature == "+relaxed") { + relaxed = true; + continue; +} +if (Feature == "+fpu64") { + fpu64 = true; + continue; +} +if (Feature == "+fpu32") { + fpu32 = true; + continue; +} +if (Feature == "+tmu_support") { + tmu_support = true; +} +if (Feature == "+tmu1") { + tmu1 = true; + continue; +} +if (Feature == "+idiv0") { + idiv0 = true; + continue; +} +if (Feature == "+vcu_support") { + vcu_support = true; +} +if (Feature == "+vcu2") { + vcu2 = true; + continue; +} +if (Feature == "+vcrc") { + vcrc = true; + continue; +} +if (Feature == "+opt_level") { + opt = true; + continue; +} + } + return true; +} + +bool C2000TargetInfo::hasFeature(StringRef Feature) const { + return llvm::StringSwitch(Feature) + .Case("eabi", eabi) + .Case("strict_ansi", strict) + .Case("cla-support", cla_support) + .Case("cla0", cla0) + .Case("cla1", cla1) + .Case("cla2", cla2) + .Case("relaxed", relaxed) + .Case("fpu64", fpu64) + .Case("fpu32", fpu32) + .Case("tmu-support", tmu_support) + .Case("tmu1", tmu1) + .Case("vcu-support", vcu_support) + .Case("vcu2", vcu2) + .Case("vcrc", vcrc) + .Case("opt-level", opt) + .Default(false); +} + +void C2000TargetInfo::getTargetDefines(const LangOptions &Opts, + MacroBuilder &Builder) const { + Builder.undefineMacro("__CHAR_BIT__"); // FIXME: Implement 16-bit char + Builder.defineMacro("__CHAR_BIT__", "16"); + Builder.defineMacro("__TMS320C2000__"); student433 wrote: Actually, the defined macros without a feature condition are all dumped regardless of options. As you suggest that some of the macros are tied to options, It would be best to not declare them wrongly. But I would like to know what options affect macros like c99 complex enabled, large model, and others, since I could not find them documented in compiler manual. If there is uncertainty, those should be removed as you suggest https://github.com/llvm/llvm-project/pull/125663 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Comments] Allow HTML tags across multiple lines (PR #120843)
Nerixyz wrote: Ping - This is done from my end, the fuzzer and parsing for `` can be done in followup PRs. https://github.com/llvm/llvm-project/pull/120843 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Improve diagnostics for vector builtins (PR #125673)
@@ -2393,8 +2395,10 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { if (CheckVectorElementCallArgs(&SemaRef, TheCall)) return true; if (SemaRef.BuiltinElementwiseTernaryMath( -TheCall, /*CheckForFloatArgs*/ -TheCall->getArg(0)->getType()->hasFloatingRepresentation())) +TheCall, /*ArgTyRestr*/ +TheCall->getArg(0)->getType()->hasFloatingRepresentation() +? Sema::EltwiseBuiltinArgTyRestriction::FloatTy frasercrmck wrote: The default "mode" for `BuiltinElementwiseTernaryMath` was `CheckForFloatArgs = true`, and it's now `EltwiseBuiltinArgTyRestriction::FloatTy` so we only need to update the cases where HLSL was ever passing `CheckForFloatArgs = false`. https://github.com/llvm/llvm-project/pull/125673 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Driver] Add an option to control loop-interchange (PR #125830)
Meinersbur wrote: The other optimzation pass options (unrolll, vectorize, ...) are implemented in `PipelineTuningOptions` and `CodeGenOptions.def`. Do it the same way? https://github.com/llvm/llvm-project/pull/125830 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang] Add support for the c2000 architecture (PR #125663)
https://github.com/student433 edited https://github.com/llvm/llvm-project/pull/125663 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)
https://github.com/AidanGoldfarb edited https://github.com/llvm/llvm-project/pull/122754 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [Sanitizers] the access size (8 bytes) exceeds the max lock-free size (4 bytes) for 32-bit (PR #125388)
@@ -1120,3 +1120,23 @@ // RUN:-c \ // RUN: | FileCheck --check-prefixes=CHECK-K-UNUSED %s // CHECK-K-UNUSED: clang: warning: -K: 'linker' input unused [-Wunused-command-line-argument] + + +// This test verifies that the linker doesn't include '-latomic' when no sanitizers are enabled +// Running this test on non-AIX host will result in an unrelated error +// FIXME: Sanitizer interface functions must be exported by export files on AIX w2yehia wrote: ```suggestion // FIXME: Running this test on non-AIX host will result in the following error: // LLVM ERROR: Sanitizer interface functions must be exported by export files on AIX ``` https://github.com/llvm/llvm-project/pull/125388 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [Sanitizers] the access size (8 bytes) exceeds the max lock-free size (4 bytes) for 32-bit (PR #125388)
@@ -1120,3 +1120,23 @@ // RUN:-c \ // RUN: | FileCheck --check-prefixes=CHECK-K-UNUSED %s // CHECK-K-UNUSED: clang: warning: -K: 'linker' input unused [-Wunused-command-line-argument] + + +// This test verifies that the linker doesn't include '-latomic' when no sanitizers are enabled +// Running this test on non-AIX host will result in an unrelated error +// FIXME: Sanitizer interface functions must be exported by export files on AIX w2yehia wrote: The 1st test doesn't crash though. The error occurs when you have -m32 and -fsanitize=address, so technically you don't need to make the first test aix specific. https://github.com/llvm/llvm-project/pull/125388 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [Sanitizers] the access size (8 bytes) exceeds the max lock-free size (4 bytes) for 32-bit (PR #125388)
https://github.com/w2yehia requested changes to this pull request. https://github.com/llvm/llvm-project/pull/125388 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [Sanitizers] the access size (8 bytes) exceeds the max lock-free size (4 bytes) for 32-bit (PR #125388)
@@ -1120,3 +1120,23 @@ // RUN:-c \ // RUN: | FileCheck --check-prefixes=CHECK-K-UNUSED %s // CHECK-K-UNUSED: clang: warning: -K: 'linker' input unused [-Wunused-command-line-argument] + + +// This test verifies that the linker doesn't include '-latomic' when no sanitizers are enabled +// Running this test on non-AIX host will result in an unrelated error +// FIXME: Sanitizer interface functions must be exported by export files on AIX w2yehia wrote: I tried the 2nd test on powerpcle and I see the error message: `LLVM ERROR: Sanitizer interface functions must be exported by export files on AIX.` I suggest reformatting the comment to make it clear that the FIXME is related to the "unrelated error". See above suggestion. https://github.com/llvm/llvm-project/pull/125388 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang-linker-wrapper] Add ELF packaging for spirv64-intel OpenMP images (PR #125737)
https://github.com/sarnex edited https://github.com/llvm/llvm-project/pull/125737 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang-linker-wrapper] Add ELF packaging for spirv64-intel OpenMP images (PR #125737)
https://github.com/sarnex edited https://github.com/llvm/llvm-project/pull/125737 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang-linker-wrapper] Add ELF packaging for spirv64-intel OpenMP images (PR #125737)
@@ -373,3 +375,86 @@ Error llvm::offloading::amdgpu::getAMDGPUMetaDataFromImage( } return Error::success(); } +Error offloading::intel::containerizeOpenMPSPIRVImage( +std::unique_ptr &Img) { + constexpr char INTEL_ONEOMP_OFFLOAD_VERSION[] = "1.0"; + constexpr int NT_INTEL_ONEOMP_OFFLOAD_VERSION = 1; + constexpr int NT_INTEL_ONEOMP_OFFLOAD_IMAGE_COUNT = 2; + constexpr int NT_INTEL_ONEOMP_OFFLOAD_IMAGE_AUX = 3; + + // Start creating notes for the ELF container. + std::vector Notes; + std::string Version = toHex(INTEL_ONEOMP_OFFLOAD_VERSION); + Notes.emplace_back(ELFYAML::NoteEntry{"INTELONEOMPOFFLOAD", +yaml::BinaryRef(Version), +NT_INTEL_ONEOMP_OFFLOAD_VERSION}); + + // The AuxInfo string will hold auxiliary information for the image. + // ELFYAML::NoteEntry structures will hold references to the + // string, so we have to make sure the string is valid. + std::string AuxInfo; + + // TODO: Pass compile/link opts + StringRef CompileOpts = ""; + StringRef LinkOpts = ""; + + unsigned ImageFmt = 1; // SPIR-V format + + AuxInfo = toHex((Twine(0) + Twine('\0') + Twine(ImageFmt) + Twine('\0') + + CompileOpts + Twine('\0') + LinkOpts) + .str()); + Notes.emplace_back(ELFYAML::NoteEntry{"INTELONEOMPOFFLOAD", +yaml::BinaryRef(AuxInfo), +NT_INTEL_ONEOMP_OFFLOAD_IMAGE_AUX}); + + std::string ImgCount = toHex(Twine(1).str()); // always one image per ELF + Notes.emplace_back(ELFYAML::NoteEntry{"INTELONEOMPOFFLOAD", +yaml::BinaryRef(ImgCount), +NT_INTEL_ONEOMP_OFFLOAD_IMAGE_COUNT}); + + std::string YamlFile; + llvm::raw_string_ostream YamlFileStream(YamlFile); + + // Write YAML template file. + { jhuber6 wrote: Is this separate block necessary? https://github.com/llvm/llvm-project/pull/125737 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Remove some false negatives in StackAddrEscapeChecker (PR #125638)
@@ -247,45 +240,134 @@ void StackAddrEscapeChecker::checkPreCall(const CallEvent &Call, } } -void StackAddrEscapeChecker::checkPreStmt(const ReturnStmt *RS, - CheckerContext &C) const { - if (!ChecksEnabled[CK_StackAddrEscapeChecker]) -return; +/// A visitor made for use with a ScanReachableSymbols scanner, used +/// for finding stack regions within an SVal that live on the current +/// stack frame of the given checker context. This visitor excludes +/// NonParamVarRegion that data is bound to in a BlockDataRegion's +/// bindings, since these are likely uninteresting, e.g., in case a +/// temporary is constructed on the stack, but it captures values +/// that would leak. +class FindStackRegionsSymbolVisitor final : public SymbolVisitor { + CheckerContext &Ctxt; + const StackFrameContext *StackFrameContext; + SmallVector &EscapingStackRegions; - const Expr *RetE = RS->getRetValue(); - if (!RetE) -return; - RetE = RetE->IgnoreParens(); +public: + explicit FindStackRegionsSymbolVisitor( + CheckerContext &Ctxt, + SmallVector &StorageForStackRegions) + : Ctxt(Ctxt), StackFrameContext(Ctxt.getStackFrame()), +EscapingStackRegions(StorageForStackRegions) {} - SVal V = C.getSVal(RetE); - const MemRegion *R = V.getAsRegion(); - if (!R) -return; + bool VisitSymbol(SymbolRef sym) override { return true; } - if (const BlockDataRegion *B = dyn_cast(R)) -checkReturnedBlockCaptures(*B, C); + bool VisitMemRegion(const MemRegion *MR) override { +SaveIfEscapes(MR); - if (!isa(R->getMemorySpace()) || isNotInCurrentFrame(R, C)) -return; +if (const BlockDataRegion *BDR = MR->getAs()) + return VisitBlockDataRegionCaptures(BDR); + +return true; + } + +private: + void SaveIfEscapes(const MemRegion *MR) { +const StackSpaceRegion *SSR = +MR->getMemorySpace()->getAs(); +if (SSR && SSR->getStackFrame() == StackFrameContext) + EscapingStackRegions.push_back(MR); + } + + bool VisitBlockDataRegionCaptures(const BlockDataRegion *BDR) { +for (auto Var : BDR->referenced_vars()) { + SVal Val = Ctxt.getState()->getSVal(Var.getCapturedRegion()); + const MemRegion *Region = Val.getAsRegion(); + if (Region) { +SaveIfEscapes(Region); +VisitMemRegion(Region); + } +} + +return false; + } +}; + +/// Given some memory regions that are flagged by FindStackRegionsSymbolVisitor, +/// this function filters out memory regions that are being returned that are +/// likely not true leaks: +/// 1. If returning a block data region that has stack memory space +/// 2. If returning a constructed object that has stack memory space +static SmallVector +FilterReturnExpressionLeaks(const SmallVector &MaybeEscaped, +CheckerContext &C, const Expr *RetE, SVal &RetVal) { + + SmallVector WillEscape; + + const MemRegion *RetRegion = RetVal.getAsRegion(); // Returning a record by value is fine. (In this case, the returned // expression will be a copy-constructor, possibly wrapped in an // ExprWithCleanups node.) if (const ExprWithCleanups *Cleanup = dyn_cast(RetE)) RetE = Cleanup->getSubExpr(); - if (isa(RetE) && RetE->getType()->isRecordType()) -return; + bool IsConstructExpr = + isa(RetE) && RetE->getType()->isRecordType(); // The CK_CopyAndAutoreleaseBlockObject cast causes the block to be copied // so the stack address is not escaping here. + bool IsCopyAndAutoreleaseBlockObj = false; if (const auto *ICE = dyn_cast(RetE)) { -if (isa(R) && -ICE->getCastKind() == CK_CopyAndAutoreleaseBlockObject) { - return; -} +IsCopyAndAutoreleaseBlockObj = +isa_and_nonnull(RetRegion) && +ICE->getCastKind() == CK_CopyAndAutoreleaseBlockObject; + } + + for (const MemRegion *MR : MaybeEscaped) { +if (RetRegion == MR && (IsCopyAndAutoreleaseBlockObj || IsConstructExpr)) + continue; + +// If this is a construct expr of an unelided return value copy, then don't +// warn about returning a region that currently lives on the stack. +if (IsConstructExpr && RetVal.getAs() && Flandini wrote: > Could you elaborate why the analyzer thinks the temporary is referred to by v > here? The test case has `v` as an argument, the constructor of `ClassWithoutDestructor` does a `v.push(this)` and has `-analyzer-config elide-constructors=false -DNO_ELIDE_FLAG -std=c++11`. `StackAddrEscapeChecker::checkEndFunction` will warn on this since it checks all of `v`'s bindings. The way I am scanning stack memory regions behind the return value in `StackAddrEscapeChecker::checkPreStmt` will also warn on this, and to avoid this double warning in this case, I added this line here this review comment is on. Typing this out, I'm realizing I could cut this line, since this: ``` ClassWithoutDestructor make1(AddressVector &v) { return ClassWi