[clang-tools-extra] [clang-tidy] Avoid diagnosing std::array initializations for modernize-use-designated-initializers (PR #134774)
https://github.com/carlosgalvezp approved this pull request. LGTM! https://github.com/llvm/llvm-project/pull/134774 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Avoid diagnosing std::array initializations for modernize-use-designated-initializers (PR #134774)
carlosgalvezp wrote: > It can also happen in user defined class. Yes. But it's unclear what the behavior of the check should be. For `std::array`, it's clear, because one must not touch the internal element. For a user-defined type, "it depends" on how the user wants to design their struct. If the need comes, I envision we will need some sort of option so people can add other types on top `std::array` to be excluded from the check. But let's cross that bridge when we get there :) https://github.com/llvm/llvm-project/pull/134774 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Reland [clang] Handle instantiated members to determine visibility (#136128) (PR #136689)
https://github.com/asavonic closed https://github.com/llvm/llvm-project/pull/136689 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Avoid diagnosing std::array initializations for modernize-use-designated-initializers (PR #134774)
carlosgalvezp wrote: @RiverDave Do you have permissions to land the PR, or shall I do it for you? https://github.com/llvm/llvm-project/pull/134774 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 60b3a5b - [clang][bytecode] Fix two small builtin_constant_p cases (#137587)
Author: Timm Baeder Date: 2025-04-28T09:21:49+02:00 New Revision: 60b3a5b7e7db40ec74d3c4839a3fae8b73d98851 URL: https://github.com/llvm/llvm-project/commit/60b3a5b7e7db40ec74d3c4839a3fae8b73d98851 DIFF: https://github.com/llvm/llvm-project/commit/60b3a5b7e7db40ec74d3c4839a3fae8b73d98851.diff LOG: [clang][bytecode] Fix two small builtin_constant_p cases (#137587) Only accept string literals if we're pointing to the first index and do accept complex literals. Added: Modified: clang/lib/AST/ByteCode/Interp.cpp clang/test/AST/ByteCode/builtin-constant-p.cpp Removed: diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index 080f694e27da2..4f94bb5a85192 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -321,8 +321,11 @@ bool CheckBCPResult(InterpState &S, const Pointer &Ptr) { if (Ptr.isTypeidPointer()) return true; + if (Ptr.getType()->isAnyComplexType()) +return true; + if (const Expr *Base = Ptr.getDeclDesc()->asExpr()) -return isa(Base); +return isa(Base) && Ptr.getIndex() == 0; return false; } diff --git a/clang/test/AST/ByteCode/builtin-constant-p.cpp b/clang/test/AST/ByteCode/builtin-constant-p.cpp index f5b16761bfdc9..9f5521590833d 100644 --- a/clang/test/AST/ByteCode/builtin-constant-p.cpp +++ b/clang/test/AST/ByteCode/builtin-constant-p.cpp @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -std=c++20 -fexperimental-new-constant-interpreter -verify=expected,both %s -// RUN: %clang_cc1 -std=c++20 -verify=ref,both %s +// RUN: %clang_cc1 -std=c++20 -verify=expected,both %s -fexperimental-new-constant-interpreter +// RUN: %clang_cc1 -std=c++20 -verify=ref,both %s using intptr_t = __INTPTR_TYPE__; @@ -129,3 +129,14 @@ void g() { const float f = __builtin_is_constant_evaluated(); static_assert(fold(f == 0.0f)); } + +void test17(void) { +#define ASSERT(...) { enum { folded = (__VA_ARGS__) }; int arr[folded ? 1 : -1]; } +#define T(...) ASSERT(__builtin_constant_p(__VA_ARGS__)) +#define F(...) ASSERT(!__builtin_constant_p(__VA_ARGS__)) + + T(3i + 5); + T("string literal"); + F("string literal" + 1); // both-warning {{adding}} \ + // both-note {{use array indexing}} +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][bytecode] Fix two small builtin_constant_p cases (PR #137587)
https://github.com/tbaederr closed https://github.com/llvm/llvm-project/pull/137587 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][bytecode] Fix two small builtin_constant_p cases (PR #137587)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `openmp-offload-amdgpu-runtime-2` running on `rocm-worker-hw-02` while building `clang` at step 6 "test-openmp". Full details are available at: https://lab.llvm.org/buildbot/#/builders/10/builds/4271 Here is the relevant piece of the build log for the reference ``` Step 6 (test-openmp) failure: test (failure) TEST 'libarcher :: races/task-taskwait-nested.c' FAILED Exit Code: 1 Command Output (stdout): -- # RUN: at line 13 /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/./bin/clang -fopenmp -gdwarf-4 -O1 -fsanitize=thread -I /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests -I /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -L /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -Wl,-rpath,/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/runtime/src /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/races/task-taskwait-nested.c -o /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/tools/archer/tests/races/Output/task-taskwait-nested.c.tmp -latomic && env TSAN_OPTIONS='ignore_noninstrumented_modules=0:ignore_noninstrumented_modules=1' /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/deflake.bash /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/tools/archer/tests/races/Output/task-taskwait-nested.c.tmp 2>&1 | tee /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/tools/archer/tests/races/Output/task-taskwait-nested.c.tmp.log | /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/./bin/FileCheck /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/races/task-taskwait-nested.c # executed command: /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/./bin/clang -fopenmp -gdwarf-4 -O1 -fsanitize=thread -I /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests -I /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -L /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -Wl,-rpath,/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/runtime/src /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/races/task-taskwait-nested.c -o /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/tools/archer/tests/races/Output/task-taskwait-nested.c.tmp -latomic # note: command had no output on stdout or stderr # executed command: env TSAN_OPTIONS=ignore_noninstrumented_modules=0:ignore_noninstrumented_modules=1 /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/deflake.bash /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/tools/archer/tests/races/Output/task-taskwait-nested.c.tmp # note: command had no output on stdout or stderr # executed command: tee /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/tools/archer/tests/races/Output/task-taskwait-nested.c.tmp.log # note: command had no output on stdout or stderr # executed command: /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/./bin/FileCheck /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/races/task-taskwait-nested.c # note: command had no output on stdout or stderr # RUN: at line 14 /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/./bin/clang -fopenmp -gdwarf-4 -O1 -fsanitize=thread -I /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests -I /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -L /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -Wl,-rpath,/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/runtime/src /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/races/task-taskwait-nested.c -o /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/tools/archer/tests/races/Output/task-taskwait-nested.c.tmp -latomic && env ARCHER_OPTIONS="ignore_serial=1 report_data_leak=1" env TSAN_OPTIONS='ignore_noninstrumented_modules=0:ignore_noninstrumented_modules=1'
[clang] [clang-format] Fix a bug in annotating TT_PointerOrReference (PR #136073)
kadircet wrote: this didn't seem to restore the desired formatting, re-openning #135972 with additional context https://github.com/llvm/llvm-project/pull/136073 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][driver] Suppress gnu-line-marker when saving temps (PR #134621)
macurtis-amd wrote: @MaskRay ping https://github.com/llvm/llvm-project/pull/134621 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] Add IR Profile-Guided Optimization (IR PGO) support to the Flang compiler (PR #136098)
@@ -130,6 +133,20 @@ static bool saveMLIRTempFile(const CompilerInvocation &ci, // Custom BeginSourceFileAction //===--===// + +static llvm::cl::opt ClPGOColdFuncAttr( fanju110 wrote: > Adding a proper frontend driver option to both frontends is the best way > forward. Do you mean to let flang and clang reuse this definition? But this code of yours is defined in clang, and I need to let Flang link Clang's `BackendUtil.cpp`, which may cause some problems. So I put this definition in llvm namespace : `llvm/Frontend/Driver/CodeGenOptions.h`.This way I don't need to copy the code all over again in flang. What do you think about this? https://github.com/llvm/llvm-project/pull/136098 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [lld] [llvm] [mlir] [NFC] Use more isa and isa_and_nonnull instead dyn_cast for predicates (PR #137393)
https://github.com/AaronBallman approved this pull request. LGTM! https://github.com/llvm/llvm-project/pull/137393 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C23] Implement WG14 N3037 (PR #132939)
AaronBallman wrote: > > So the changes needed to move this patch forward are to only perform the > > attribute check when we're checking for a valid redefinition, not type > > compatibility in general. A follow-up to improve upon this can do the > > layout check when looking for compatibility. Alternatively (or as another > > follow-up), we can implement the case-by-case basis logic. > > Does that match your understanding @jyknight? > > Ping on this @jyknight Another ping (if no response by mid-week, I'll probably land the changes as-is and address concerns post-commit). https://github.com/llvm/llvm-project/pull/132939 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][AArch64] Don't #define __ARM_FEATURE_CRC32 when -crc is specified in -target-feature (PR #132167)
https://github.com/XiaShark updated https://github.com/llvm/llvm-project/pull/132167 >From 3be462100386014b3f78c1db5369487235a2bcf0 Mon Sep 17 00:00:00 2001 From: XiaShark Date: Thu, 20 Mar 2025 14:32:30 +0800 Subject: [PATCH] [clang][AArch64] Don't define features macros when explicitly disabled Currently, clang has a general issue where it may incorrectly define feature-specific macros(e.g., __ARM_FEATURE_CRC32) even when the corresponding features are explicitly disabled via -target-feature. This can lead to unexpected behavior in code that relies on these macros. This commit fixed the issue by adding a secondary check to confirm if the features are explicitly disabled in `-target-feature`. --- clang/lib/Basic/Targets/AArch64.cpp | 171 +++--- .../Preprocessor/aarch64-target-features.c| 36 2 files changed, 144 insertions(+), 63 deletions(-) diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp index 3633bab6e0df9..98b91ebe77aab 100644 --- a/clang/lib/Basic/Targets/AArch64.cpp +++ b/clang/lib/Basic/Targets/AArch64.cpp @@ -914,6 +914,66 @@ void AArch64TargetInfo::setFeatureEnabled(llvm::StringMap &Features, bool AArch64TargetInfo::handleTargetFeatures(std::vector &Features, DiagnosticsEngine &Diags) { + // The first round, address the ARM version initially. + for (const auto &Feature : Features) { +// All predecessor archs are added but select the latest one for ArchKind. +if (Feature == "+v8a" && ArchInfo->Version < llvm::AArch64::ARMV8A.Version) + ArchInfo = &llvm::AArch64::ARMV8A; +if (Feature == "+v8.1a" && +ArchInfo->Version < llvm::AArch64::ARMV8_1A.Version) + ArchInfo = &llvm::AArch64::ARMV8_1A; +if (Feature == "+v8.2a" && +ArchInfo->Version < llvm::AArch64::ARMV8_2A.Version) + ArchInfo = &llvm::AArch64::ARMV8_2A; +if (Feature == "+v8.3a" && +ArchInfo->Version < llvm::AArch64::ARMV8_3A.Version) + ArchInfo = &llvm::AArch64::ARMV8_3A; +if (Feature == "+v8.4a" && +ArchInfo->Version < llvm::AArch64::ARMV8_4A.Version) + ArchInfo = &llvm::AArch64::ARMV8_4A; +if (Feature == "+v8.5a" && +ArchInfo->Version < llvm::AArch64::ARMV8_5A.Version) + ArchInfo = &llvm::AArch64::ARMV8_5A; +if (Feature == "+v8.6a" && +ArchInfo->Version < llvm::AArch64::ARMV8_6A.Version) + ArchInfo = &llvm::AArch64::ARMV8_6A; +if (Feature == "+v8.7a" && +ArchInfo->Version < llvm::AArch64::ARMV8_7A.Version) + ArchInfo = &llvm::AArch64::ARMV8_7A; +if (Feature == "+v8.8a" && +ArchInfo->Version < llvm::AArch64::ARMV8_8A.Version) + ArchInfo = &llvm::AArch64::ARMV8_8A; +if (Feature == "+v8.9a" && +ArchInfo->Version < llvm::AArch64::ARMV8_9A.Version) + ArchInfo = &llvm::AArch64::ARMV8_9A; +if (Feature == "+v9a" && ArchInfo->Version < llvm::AArch64::ARMV9A.Version) + ArchInfo = &llvm::AArch64::ARMV9A; +if (Feature == "+v9.1a" && +ArchInfo->Version < llvm::AArch64::ARMV9_1A.Version) + ArchInfo = &llvm::AArch64::ARMV9_1A; +if (Feature == "+v9.2a" && +ArchInfo->Version < llvm::AArch64::ARMV9_2A.Version) + ArchInfo = &llvm::AArch64::ARMV9_2A; +if (Feature == "+v9.3a" && +ArchInfo->Version < llvm::AArch64::ARMV9_3A.Version) + ArchInfo = &llvm::AArch64::ARMV9_3A; +if (Feature == "+v9.4a" && +ArchInfo->Version < llvm::AArch64::ARMV9_4A.Version) + ArchInfo = &llvm::AArch64::ARMV9_4A; +if (Feature == "+v9.5a" && +ArchInfo->Version < llvm::AArch64::ARMV9_5A.Version) + ArchInfo = &llvm::AArch64::ARMV9_5A; +if (Feature == "+v9.6a" && +ArchInfo->Version < llvm::AArch64::ARMV9_6A.Version) + ArchInfo = &llvm::AArch64::ARMV9_6A; +if (Feature == "+v8r") + ArchInfo = &llvm::AArch64::ARMV8R; + } + + setDataLayout(); + setArchFeatures(); + + // The second round, address each feature. for (const auto &Feature : Features) { if (Feature == "-fp-armv8") HasNoFP = true; @@ -944,6 +1004,8 @@ bool AArch64TargetInfo::handleTargetFeatures(std::vector &Features, HasFullFP16 = true; HasSVE2 = true; } +if (Feature == "-sve2") + HasSVE2 = false; if (Feature == "+sve2p1") { FPU |= NeonMode; FPU |= SveMode; @@ -951,6 +1013,8 @@ bool AArch64TargetInfo::handleTargetFeatures(std::vector &Features, HasSVE2 = true; HasSVE2p1 = true; } +if (Feature == "-sve2p1") + HasSVE2p1 = false; if (Feature == "+sve-aes") { FPU |= NeonMode; HasFullFP16 = true; @@ -994,12 +1058,16 @@ bool AArch64TargetInfo::handleTargetFeatures(std::vector &Features, HasBFloat16 = true; HasFullFP16 = true; } +if (Feature == "-sme") + HasSME = false; if (Feature == "+sme2") { HasSME = true; HasSME2 = true; HasBFloat16 = true; HasFullF
[clang] [clang][AArch64] Don't define features macros when explicitly disabled (PR #132167)
https://github.com/XiaShark edited https://github.com/llvm/llvm-project/pull/132167 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][AArch64] Don't define features macros when explicitly disabled (PR #132167)
https://github.com/XiaShark edited https://github.com/llvm/llvm-project/pull/132167 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] Add IR Profile-Guided Optimization (IR PGO) support to the Flang compiler (PR #136098)
@@ -28,6 +28,7 @@ #include "flang/Semantics/unparse-with-symbols.h" #include "flang/Support/default-kinds.h" #include "flang/Tools/CrossToolHelpers.h" +#include "clang/CodeGen/BackendUtil.h" tarunprabhu wrote: We should not include clang headers unless necessary. If this was to obtain the declaration of `ClPGOColdFuncAttr`, it may be better to expose it in `llvm/Frontend/CodeGenOptions.h` and include that header here instead https://github.com/llvm/llvm-project/pull/136098 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] Add IR Profile-Guided Optimization (IR PGO) support to the Flang compiler (PR #136098)
@@ -19,6 +21,7 @@ template class Expected; template class IntrusiveRefCntPtr; class Module; class MemoryBufferRef; +extern cl::opt ClPGOColdFuncAttr; tarunprabhu wrote: Since this is an experimental option that will likely be removed and is only to be used in BackendUtil.cpp, it is better to move it there. Essentially, what was originally the `static` definition of `ClPGOColdFuncAttr` in `BackendUtil.cpp` would become `extern ClPGOColdFuncAttr`. https://github.com/llvm/llvm-project/pull/136098 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] Add IR Profile-Guided Optimization (IR PGO) support to the Flang compiler (PR #136098)
@@ -13,9 +13,14 @@ #ifndef LLVM_FRONTEND_DRIVER_CODEGENOPTIONS_H #define LLVM_FRONTEND_DRIVER_CODEGENOPTIONS_H +#include "llvm/ProfileData/InstrProfCorrelator.h" +#include namespace llvm { class Triple; class TargetLibraryInfoImpl; +extern llvm::cl::opt DebugInfoCorrelate; tarunprabhu wrote: Is it necessary to have this in a header? Is it used anywhere outside CodeGenOptions.cpp? Please see the [visibility](https://llvm.org/docs/CodingStandards.html#restrict-visibility) section in the LLVM coding standards document for a discussion of this. https://github.com/llvm/llvm-project/pull/136098 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Remove FEM_Indeterminable (PR #137247)
AaronBallman wrote: Why did this get merged before there were any reviews or responses? https://github.com/llvm/llvm-project/pull/137247 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] Add IR Profile-Guided Optimization (IR PGO) support to the Flang compiler (PR #136098)
https://github.com/tarunprabhu requested changes to this pull request. Thanks for the updating the PR. There seems to be a [buildkite failure](https://buildkite.com/llvm-project/github-pull-requests/builds/173137#01967cab-3f69-4ec6-8175-49795d1a2819). These failures are often worth checking because it might indicate that your changes might be incompatible with a different build configuration from yours. https://github.com/llvm/llvm-project/pull/136098 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] Add IR Profile-Guided Optimization (IR PGO) support to the Flang compiler (PR #136098)
@@ -20,8 +20,13 @@ #include "mlir/IR/OwningOpRef.h" #include "llvm/ADT/StringRef.h" #include "llvm/IR/Module.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/PGOOptions.h" #include +namespace llvm { +extern cl::opt ClPGOColdFuncAttr; tarunprabhu wrote: We probably don't want to expose this here. It is an experimental option that may be promoted to a proper frontend option at some point. It is better to leave this as a declaration in the .cpp file where this is actually used. https://github.com/llvm/llvm-project/pull/136098 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] Add IR Profile-Guided Optimization (IR PGO) support to the Flang compiler (PR #136098)
https://github.com/tblah edited https://github.com/llvm/llvm-project/pull/136098 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] Add IR Profile-Guided Optimization (IR PGO) support to the Flang compiler (PR #136098)
@@ -8,6 +8,8 @@ #ifndef LLVM_CLANG_CODEGEN_BACKENDUTIL_H #define LLVM_CLANG_CODEGEN_BACKENDUTIL_H +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/PGOOptions.h" #include "clang/Basic/LLVM.h" #include "llvm/IR/ModuleSummaryIndex.h" tblah wrote: nit: include ordering https://llvm.org/docs/CodingStandards.html#include-style https://github.com/llvm/llvm-project/pull/136098 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] Add IR Profile-Guided Optimization (IR PGO) support to the Flang compiler (PR #136098)
@@ -19,6 +21,7 @@ template class Expected; template class IntrusiveRefCntPtr; class Module; class MemoryBufferRef; +extern cl::opt ClPGOColdFuncAttr; tblah wrote: nit: I would put this `extern` in `BackendUtil.cpp` because it is not part of BackendUtils's public interface to other translation units. https://github.com/llvm/llvm-project/pull/136098 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] Add IR Profile-Guided Optimization (IR PGO) support to the Flang compiler (PR #136098)
https://github.com/tarunprabhu edited https://github.com/llvm/llvm-project/pull/136098 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Remove FEM_Indeterminable (PR #137247)
https://github.com/ojhunt closed https://github.com/llvm/llvm-project/pull/137247 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C] Diagnose use of C++ keywords in C (PR #137234)
https://github.com/erichkeane commented: sorry! I made these comments a while ago, but apparently never submitted them. https://github.com/llvm/llvm-project/pull/137234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C] Diagnose use of C++ keywords in C (PR #137234)
@@ -10416,6 +10447,15 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, // Finally, we know we have the right number of parameters, install them. NewFD->setParams(Params); + // If this declarator is a declaration and not a definition, its parameters + // will not be pushed onto a scope chain. That means we will not issue any + // reserved identifier warnings for the declaration, but we will for the + // definition. Handle those here. + if (!Params.empty() && !D.isFunctionDefinition()) { erichkeane wrote: I suspect THIS is where your slowdown is going to come from, and I see no tests for this (that is, function parameters). ALSO, `!Params.empty()` isnt' really necessary, the `for` loop will do that for you. https://github.com/llvm/llvm-project/pull/137234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C] Diagnose use of C++ keywords in C (PR #137234)
@@ -6107,6 +6109,29 @@ static bool isFromSystemHeader(SourceManager &SM, const Decl *D) { SM.isInSystemMacro(D->getLocation()); } +static bool isKeywordInCPlusPlus(const Sema &S, const IdentifierInfo *II) { + if (!II) +return false; + + // Build a static map of identifiers for all of the keywords in C++ that are + // not keywords in C. This allows us to do pointer comparisons instead of + // string comparisons when deciding whether the given identifier is a keyword + // or not. Note, this treats all keywords as being enabled, regardless of the + // setting of other language options. It intentionally disables the modules + // keywords because those are conditional keywords, so may be safe to use. + static llvm::SmallPtrSet Keywords; erichkeane wrote: note llvm::SmallPtrSet vs SmallSet is irrelevant here, the specialization for SmallSet on pointers is SmallPtrSet, but don't mind this being here, just interesting note :) https://github.com/llvm/llvm-project/pull/137234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C] Diagnose use of C++ keywords in C (PR #137234)
https://github.com/erichkeane edited https://github.com/llvm/llvm-project/pull/137234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C] Diagnose use of C++ keywords in C (PR #137234)
@@ -6107,6 +6109,29 @@ static bool isFromSystemHeader(SourceManager &SM, const Decl *D) { SM.isInSystemMacro(D->getLocation()); } +static bool isKeywordInCPlusPlus(const Sema &S, const IdentifierInfo *II) { + if (!II) +return false; + + // Build a static map of identifiers for all of the keywords in C++ that are + // not keywords in C. This allows us to do pointer comparisons instead of + // string comparisons when deciding whether the given identifier is a keyword + // or not. Note, this treats all keywords as being enabled, regardless of the + // setting of other language options. It intentionally disables the modules + // keywords because those are conditional keywords, so may be safe to use. + static llvm::SmallPtrSet Keywords; + if (Keywords.empty()) { +#define MODULES_KEYWORD(NAME) +#define KEYWORD(NAME, FLAGS) \ + Keywords.insert(&S.getPreprocessor().getIdentifierTable().get(#NAME)); +#define CXX_KEYWORD_OPERATOR(NAME, TOK) \ + Keywords.insert(&S.getPreprocessor().getIdentifierTable().get(#NAME)); +#include "clang/Basic/TokenKinds.def" + } + + return Keywords.contains(II); erichkeane wrote: This function is interesting. I like the approach. The `insert` here is obviously pretty slow, but all of those are only happening 1x per TU and a 'small' number (which, btw, how accurate is the 32 here? we NEED to make sure, perhaps via assert, that we always fall in the 'small' here). An alternative implementation idea here... In IdentifierTable, 'start' the TU by creating all the CXXKeywords in 1 place, via 1 allocation. Then add them to the IdentifierTable. That then makes this lookup: `return II >= IdentTable.FirstCXXKeyword && II <= IdentTable.LastCXXKeyword` The result is this is effectively 'free' to check, at a slight startup time/memory cost(basically, time to do the ABOVE getIdentifierTable.get calls). That said, the 'cost' of this warning, now that you have `isIgnored` checked, is pretty minor I presume? So perhaps not worth the effort. WDYT? https://github.com/llvm/llvm-project/pull/137234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Remove FEM_Indeterminable (PR #137247)
ojhunt wrote: @zahiraam it's currently causing a warning (@Endilll asking for an update is why I ended up looking at this on my phone) https://github.com/llvm/llvm-project/pull/137247 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Remove FEM_Indeterminable (PR #137247)
zahiraam wrote: > @zahiraam it's currently causing a warning (@Endilll asking for an update is > why I ended up looking at this on my phone) What is the warning? https://github.com/llvm/llvm-project/pull/137247 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Handle invalid variable template specialization whose type depends on itself (PR #134522)
https://github.com/zyn0217 commented: thanks, it looks much better https://github.com/llvm/llvm-project/pull/134522 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Handle invalid variable template specialization whose type depends on itself (PR #134522)
@@ -4348,6 +4348,23 @@ struct PartialSpecMatchResult { VarTemplatePartialSpecializationDecl *Partial; TemplateArgumentList *Args; }; + +struct TemplateArgEqualityComparator { + const ASTContext &Context; + + bool operator()(const TemplateArgument &Canonical, + const TemplateArgument &Unknown) const { +llvm::FoldingSetNodeID ID1, ID2; +Canonical.Profile(ID1, Context); +Context.getCanonicalTemplateArgument(Unknown).Profile(ID2, Context); +#ifndef NDEBUG +llvm::FoldingSetNodeID ID3; +Context.getCanonicalTemplateArgument(Canonical).Profile(ID3, Context); +assert(ID1 == ID3); +#endif +return ID1 == ID2; + } +}; zyn0217 wrote: Can we use `TemplateArgument::structurallyEquals`? If not, we also have `isSameTemplateArg(Context, X, Y)` localized in SemaTemplateDeduction, can we reuse that? https://github.com/llvm/llvm-project/pull/134522 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][Sema] Handle invalid variable template specialization whose type depends on itself (PR #134522)
https://github.com/zyn0217 edited https://github.com/llvm/llvm-project/pull/134522 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Implement lowering for LinkageSpecDecl (PR #137634)
https://github.com/andykaylor approved this pull request. lgtm https://github.com/llvm/llvm-project/pull/137634 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Preprocessor] Do not expand macros if the input is already preprocessed (PR #137665)
Juan Manuel Martinez =?utf-8?q?Caamaño?= Message-ID: In-Reply-To: llvmbot wrote: @llvm/pr-subscribers-clang Author: Juan Manuel Martinez Caamaño (jmmartinez) Changes This is a draft while I'm trying to figure out what's left to do. This has issues with the test `Modules/initializers.cpp`. The function `CompilerInstance::createModuleFromSource` creates a `FrontendInput` that "is preprocessed" from the preprocessed source string that is passed as argument (the module contents). However, this does not seem preprocessed (at least for this test). https://github.com/llvm/llvm-project/blob/ca21508080031c3eda1c6085f1de9cc26be4c336/clang/lib/Frontend/CompilerInstance.cpp#L2243 I'm not familiar with modules and I'm not sure if it's this patch, or the test that has issues. Other failures are fixed with https://github.com/llvm/llvm-project/pull/137623 --- Full diff: https://github.com/llvm/llvm-project/pull/137665.diff 3 Files Affected: - (modified) clang/include/clang/Lex/Preprocessor.h (+5) - (modified) clang/lib/Frontend/InitPreprocessor.cpp (+7) - (added) clang/test/Preprocessor/preprocess-cpp-output.c (+10) ``diff diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index f2dfd3a349b8b..63774e48a468b 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -1831,6 +1831,11 @@ class Preprocessor { MacroExpansionInDirectivesOverride = true; } + void SetDisableMacroExpansion() { +DisableMacroExpansion = true; +MacroExpansionInDirectivesOverride = false; + } + /// Peeks ahead N tokens and returns that token without consuming any /// tokens. /// diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index 1f297f228fc1b..6693cfb469f82 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -1556,6 +1556,13 @@ void clang::InitializePreprocessor(Preprocessor &PP, const PCHContainerReader &PCHContainerRdr, const FrontendOptions &FEOpts, const CodeGenOptions &CodeGenOpts) { + + if (all_of(FEOpts.Inputs, + [](const FrontendInputFile &FI) { return FI.isPreprocessed(); })) { +PP.SetDisableMacroExpansion(); +return; + } + const LangOptions &LangOpts = PP.getLangOpts(); std::string PredefineBuffer; PredefineBuffer.reserve(4080); diff --git a/clang/test/Preprocessor/preprocess-cpp-output.c b/clang/test/Preprocessor/preprocess-cpp-output.c new file mode 100644 index 0..2c180601e30ac --- /dev/null +++ b/clang/test/Preprocessor/preprocess-cpp-output.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -E -x c %s | FileCheck %s --check-prefixes=EXPANDED +// RUN: %clang_cc1 -E -x cpp-output %s | FileCheck %s --check-prefixes=NOT-EXPANDED + +// EXPANDED: void __attribute__((__attribute__((always_inline foo() +// NOT-EXPANDED: void __attribute__((always_inline)) foo() + +#define always_inline __attribute__((always_inline)) +void __attribute__((always_inline)) foo() { +return 4; +} `` https://github.com/llvm/llvm-project/pull/137665 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AMDGPU] Support the OpenCL generic addrspace feature by default (PR #137636)
@@ -155,3 +155,11 @@ #endif #pragma OPENCL EXTENSION cl_amd_media_ops2: enable +#if (__OPENCL_C_VERSION__ >= 300) frasercrmck wrote: My reading of the specification is that OpenCL 2.0 has the "generic address space" capability available by default, but not the `__opencl_c_generic_address_space` _feature_ (it's just automatically on). OpenCL 3.0 has the optional `__opencl_c_generic_address_space` feature which is not on by default. See https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_C.html#the-generic-address-space. All of the wording surrounding the generic address space is, e.g., `If the generic address space is supported i.e. for OpenCL C 2.0 or OpenCL C 3.0 with __opencl_c_generic_address_space feature [...]`. Looking at `opencl-c-base.h`, my guess is that we are defining the `__opencl_c_generic_address_space` feature on by default for OpenCL 2.0. That's non-standard, but it means there's a simpler internal way of checking for the feature's availability. Regardless, that header isn't available to this particular test - this is just using internal compiler defines, and there's no `__opencl_c_generic_address_space` defined by clang for OpenCL 2.0. I think that's the correct behaviour. https://github.com/llvm/llvm-project/pull/137636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Preprocessor] Do not expand macros if the input is already preprocessed (PR #137665)
https://github.com/jmmartinez created https://github.com/llvm/llvm-project/pull/137665 This is a draft while I'm trying to figure out what's left to do. This has issues with the test `Modules/initializers.cpp`. The function `CompilerInstance::createModuleFromSource` creates a `FrontendInput` that "is preprocessed" from the preprocessed source string that is passed as argument (the module contents). However, this does not seem preprocessed (at least for this test). https://github.com/llvm/llvm-project/blob/ca21508080031c3eda1c6085f1de9cc26be4c336/clang/lib/Frontend/CompilerInstance.cpp#L2243 I'm not familiar with modules and I'm not sure if it's this patch, or the test that has issues. Other failures are fixed with https://github.com/llvm/llvm-project/pull/137623 From 2a227b877994f41c9cbdc8eaf444571dfb5f333b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Martinez=20Caama=C3=B1o?= Date: Mon, 28 Apr 2025 17:05:46 +0200 Subject: [PATCH 1/2] Pre-commit test: [Preprocessor] Do not expand macros if the input is already preprocessed --- clang/test/Preprocessor/preprocess-cpp-output.c | 9 + 1 file changed, 9 insertions(+) create mode 100644 clang/test/Preprocessor/preprocess-cpp-output.c diff --git a/clang/test/Preprocessor/preprocess-cpp-output.c b/clang/test/Preprocessor/preprocess-cpp-output.c new file mode 100644 index 0..59ff057e9b871 --- /dev/null +++ b/clang/test/Preprocessor/preprocess-cpp-output.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -E -x c %s | FileCheck %s --check-prefixes=EXPANDED +// RUN: %clang_cc1 -E -x cpp-output %s | FileCheck %s --check-prefixes=EXPANDED + +// EXPANDED: void __attribute__((__attribute__((always_inline foo() + +#define always_inline __attribute__((always_inline)) +void __attribute__((always_inline)) foo() { +return 4; +} From 4ed49c6c842221be8b3ce21e522934329cb4ef0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Martinez=20Caama=C3=B1o?= Date: Tue, 22 Apr 2025 18:40:37 +0200 Subject: [PATCH 2/2] [Preprocessor] Do not expand macros if the input is already preprocessed --- clang/include/clang/Lex/Preprocessor.h | 5 + clang/lib/Frontend/InitPreprocessor.cpp | 7 +++ clang/test/Preprocessor/preprocess-cpp-output.c | 3 ++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index f2dfd3a349b8b..63774e48a468b 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -1831,6 +1831,11 @@ class Preprocessor { MacroExpansionInDirectivesOverride = true; } + void SetDisableMacroExpansion() { +DisableMacroExpansion = true; +MacroExpansionInDirectivesOverride = false; + } + /// Peeks ahead N tokens and returns that token without consuming any /// tokens. /// diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index 1f297f228fc1b..6693cfb469f82 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -1556,6 +1556,13 @@ void clang::InitializePreprocessor(Preprocessor &PP, const PCHContainerReader &PCHContainerRdr, const FrontendOptions &FEOpts, const CodeGenOptions &CodeGenOpts) { + + if (all_of(FEOpts.Inputs, + [](const FrontendInputFile &FI) { return FI.isPreprocessed(); })) { +PP.SetDisableMacroExpansion(); +return; + } + const LangOptions &LangOpts = PP.getLangOpts(); std::string PredefineBuffer; PredefineBuffer.reserve(4080); diff --git a/clang/test/Preprocessor/preprocess-cpp-output.c b/clang/test/Preprocessor/preprocess-cpp-output.c index 59ff057e9b871..2c180601e30ac 100644 --- a/clang/test/Preprocessor/preprocess-cpp-output.c +++ b/clang/test/Preprocessor/preprocess-cpp-output.c @@ -1,7 +1,8 @@ // RUN: %clang_cc1 -E -x c %s | FileCheck %s --check-prefixes=EXPANDED -// RUN: %clang_cc1 -E -x cpp-output %s | FileCheck %s --check-prefixes=EXPANDED +// RUN: %clang_cc1 -E -x cpp-output %s | FileCheck %s --check-prefixes=NOT-EXPANDED // EXPANDED: void __attribute__((__attribute__((always_inline foo() +// NOT-EXPANDED: void __attribute__((always_inline)) foo() #define always_inline __attribute__((always_inline)) void __attribute__((always_inline)) foo() { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Avoid diagnosing std::array initializations for modernize-use-designated-initializers (PR #134774)
RiverDave wrote: > @RiverDave Do you have permissions to land the PR, or shall I do it for you? Don't have permissions [yet](https://github.com/issues/created?issue=llvm%7Cllvm-project%7C131971)... You can merge it for me! https://github.com/llvm/llvm-project/pull/134774 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AMDGPU] Support the OpenCL generic addrspace feature by default (PR #137636)
@@ -155,3 +155,11 @@ #endif #pragma OPENCL EXTENSION cl_amd_media_ops2: enable +#if (__OPENCL_C_VERSION__ >= 300) jmmartinez wrote: Thanks ! You're right. It's available by default on OpenCL C 2 but not 3. https://github.com/llvm/llvm-project/pull/137636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Add CodePatterns config option under Completion (PR #137613)
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 HEAD~1 HEAD --extensions h,cpp -- clang-tools-extra/clangd/ClangdServer.cpp clang-tools-extra/clangd/CodeComplete.cpp clang-tools-extra/clangd/CodeComplete.h clang-tools-extra/clangd/Config.h clang-tools-extra/clangd/ConfigCompile.cpp clang-tools-extra/clangd/ConfigFragment.h clang-tools-extra/clangd/ConfigYAML.cpp clang-tools-extra/clangd/tool/ClangdMain.cpp clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp `` View the diff from clang-format here. ``diff diff --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp index 9077d5fa1..8387a847f 100644 --- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp +++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp @@ -3337,7 +3337,8 @@ TEST(CompletionTest, NoCodePatternsIfDisabled) { /// {statements}~" code pattern for^ } - )cpp", {}, Opts); + )cpp", + {}, Opts); EXPECT_THAT(Results.Completions, Not(Contains(kind(CompletionItemKind::Snippet; `` https://github.com/llvm/llvm-project/pull/137613 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C] Add new -Wimplicit-int-enum-cast to -Wc++-compat (PR #137658)
https://github.com/AaronBallman updated https://github.com/llvm/llvm-project/pull/137658 >From 0922c27f28eadd657086fd9eb0a68ab14ce37307 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Mon, 28 Apr 2025 11:56:40 -0400 Subject: [PATCH 1/2] Add new -Wimplicit-int-enum-cast to -Wc++-compat This introduces a new diagnostic group to diagnose implicit casts from int to an enumeration type. In C, this is valid, but it is not compatible with C++. Additionally, this moves the "implicit conversion from enum type to different enum type" diagnostic from `-Wenum-conversion` to a new group `-Wimplicit-enum-enum-cast`, which is a more accurate home for it. `-Wimplicit-enum-enum-cast` is also under `-Wimplicit-int-enum-cast`, as it is the same incompatibility (the enumeration on the right-hand is promoted to `int`, so it's an int -> enum conversion). Fixes #37027 --- clang/docs/ReleaseNotes.rst | 9 clang/include/clang/Basic/DiagnosticGroups.td | 7 ++- .../clang/Basic/DiagnosticSemaKinds.td| 5 +- clang/lib/Sema/SemaChecking.cpp | 8 ++- clang/test/Misc/warning-flags-enabled.c | 8 +-- .../test/Sema/implicit-int-enum-conversion.c | 52 +++ 6 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 clang/test/Sema/implicit-int-enum-conversion.c diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 3105d8b481560..1bcf358974437 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -150,6 +150,15 @@ C Language Changes - Added ``-Wimplicit-void-ptr-cast``, grouped under ``-Wc++-compat``, which diagnoses implicit conversion from ``void *`` to another pointer type as being incompatible with C++. (#GH17792) +- Added ``-Wimplicit-int-enum-cast``, grouped under ``-Wc++-compat``, which + diagnoses implicit conversion from integer types to an enumeration type in C, + which is not compatible with C++. #GH37027 +- Split "implicit conversion from enum type to different enum type" diagnostic + from ``-Wenum-conversion`` into its own diagnostic group, + ``-Wimplicit-enum-enum-cast``, which is grouped under both + ``-Wenum-conversion`` and ``-Wimplicit-int-enum-cast``. This conversion is an + int-to-enum conversion because the enumeration on the right-hand side is + promoted to ``int`` before the assignment. C2y Feature Support ^^^ diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 31e2cfa7ab485..97ed38d71ed51 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -103,10 +103,12 @@ def AnonEnumEnumConversion : DiagGroup<"anon-enum-enum-conversion", [DeprecatedAnonEnumEnumConversion]>; def EnumEnumConversion : DiagGroup<"enum-enum-conversion", [DeprecatedEnumEnumConversion]>; +def ImplicitEnumEnumCast : DiagGroup<"implicit-enum-enum-cast">; def EnumFloatConversion : DiagGroup<"enum-float-conversion", [DeprecatedEnumFloatConversion]>; def EnumConversion : DiagGroup<"enum-conversion", [EnumEnumConversion, +ImplicitEnumEnumCast, EnumFloatConversion, EnumCompareConditional]>; def DeprecatedOFast : DiagGroup<"deprecated-ofast">; @@ -157,7 +159,10 @@ def : DiagGroup<"c2x-compat", [C23Compat]>; def DefaultConstInitUnsafe : DiagGroup<"default-const-init-unsafe">; def DefaultConstInit : DiagGroup<"default-const-init", [DefaultConstInitUnsafe]>; def ImplicitVoidPtrCast : DiagGroup<"implicit-void-ptr-cast">; -def CXXCompat: DiagGroup<"c++-compat", [ImplicitVoidPtrCast, DefaultConstInit]>; +def ImplicitIntToEnumCast : DiagGroup<"implicit-int-enum-cast", + [ImplicitEnumEnumCast]>; +def CXXCompat: DiagGroup<"c++-compat", [ImplicitVoidPtrCast, DefaultConstInit, +ImplicitIntToEnumCast]>; def ExternCCompat : DiagGroup<"extern-c-compat">; def KeywordCompat : DiagGroup<"keyword-compat">; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 4c96142e28134..2e148e01d6e5e 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -4310,7 +4310,10 @@ def warn_impcast_string_literal_to_bool : Warning< InGroup, DefaultIgnore; def warn_impcast_different_enum_types : Warning< "implicit conversion from enumeration type %0 to different enumeration type " - "%1">, InGroup; + "%1">, InGroup; +def warn_impcast_int_to_enum : Warning< + "implicit conversion from %0 to enumeration type %1 is invalid in C++">, + InGroup, DefaultIgnore; def warn_impcast_bool_to_null_pointer : Warning< "initialization of pointer of type
[clang] [clang] Merge gtest binaries into AllClangUnitTests (PR #134196)
https://github.com/petrhosek approved this pull request. https://github.com/llvm/llvm-project/pull/134196 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Hide the `LangOptions` pointer from `CompilerInvocation` (PR #137675)
https://github.com/jansvoboda11 created https://github.com/llvm/llvm-project/pull/137675 This PR makes `CompilerInvocation` the sole owner of the `LangOptions` instance. >From 14469a8726fc1d038f41c7e3e29a84ec8f52d013 Mon Sep 17 00:00:00 2001 From: Jan Svoboda Date: Thu, 22 Aug 2024 08:45:08 -0700 Subject: [PATCH] [clang] Hide the `LangOptions` pointer from `CompilerInvocation` --- clang/include/clang/Frontend/ASTUnit.h| 4 ++-- clang/include/clang/Frontend/CompilerInstance.h | 3 --- clang/include/clang/Frontend/CompilerInvocation.h | 6 -- clang/lib/Frontend/ASTUnit.cpp| 10 ++ clang/lib/Frontend/FrontendAction.cpp | 2 +- 5 files changed, 9 insertions(+), 16 deletions(-) diff --git a/clang/include/clang/Frontend/ASTUnit.h b/clang/include/clang/Frontend/ASTUnit.h index 2baa2d1cc540d..73686b0eacbe2 100644 --- a/clang/include/clang/Frontend/ASTUnit.h +++ b/clang/include/clang/Frontend/ASTUnit.h @@ -106,7 +106,7 @@ class ASTUnit { }; private: - std::shared_ptrLangOpts; + std::unique_ptr LangOpts; IntrusiveRefCntPtr Diagnostics; IntrusiveRefCntPtr FileMgr; IntrusiveRefCntPtr SourceMgr; @@ -704,7 +704,7 @@ class ASTUnit { IntrusiveRefCntPtr Diags, const FileSystemOptions &FileSystemOpts, const HeaderSearchOptions &HSOpts, - std::shared_ptr LangOpts = nullptr, + const LangOptions *LangOpts = nullptr, bool OnlyLocalDecls = false, CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None, bool AllowASTWithCompilerErrors = false, diff --git a/clang/include/clang/Frontend/CompilerInstance.h b/clang/include/clang/Frontend/CompilerInstance.h index 7de4fb531d0e7..78ac1079354de 100644 --- a/clang/include/clang/Frontend/CompilerInstance.h +++ b/clang/include/clang/Frontend/CompilerInstance.h @@ -327,9 +327,6 @@ class CompilerInstance : public ModuleLoader { LangOptions &getLangOpts() { return Invocation->getLangOpts(); } const LangOptions &getLangOpts() const { return Invocation->getLangOpts(); } - std::shared_ptr getLangOptsPtr() const { -return Invocation->getLangOptsPtr(); - } PreprocessorOptions &getPreprocessorOpts() { return Invocation->getPreprocessorOpts(); diff --git a/clang/include/clang/Frontend/CompilerInvocation.h b/clang/include/clang/Frontend/CompilerInvocation.h index 1827ff0f6816d..31bf7e94efab8 100644 --- a/clang/include/clang/Frontend/CompilerInvocation.h +++ b/clang/include/clang/Frontend/CompilerInvocation.h @@ -265,12 +265,6 @@ class CompilerInvocation : public CompilerInvocationBase { } /// @} - /// Base class internals. - /// @{ - using CompilerInvocationBase::LangOpts; - std::shared_ptr getLangOptsPtr() { return LangOpts; } - /// @} - /// Create a compiler invocation from a list of input options. /// \returns true on success. /// diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index 3e4da76916585..e05385d119870 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -805,7 +805,7 @@ std::unique_ptr ASTUnit::LoadFromASTFile( StringRef Filename, const PCHContainerReader &PCHContainerRdr, WhatToLoad ToLoad, IntrusiveRefCntPtr Diags, const FileSystemOptions &FileSystemOpts, const HeaderSearchOptions &HSOpts, -std::shared_ptr LangOpts, bool OnlyLocalDecls, +const LangOptions *LangOpts, bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics, bool AllowASTWithCompilerErrors, bool UserFilesAreVolatile, IntrusiveRefCntPtr VFS) { std::unique_ptr AST(new ASTUnit(true)); @@ -819,7 +819,8 @@ std::unique_ptr ASTUnit::LoadFromASTFile( ConfigureDiags(Diags, *AST, CaptureDiagnostics); - AST->LangOpts = LangOpts ? LangOpts : std::make_shared(); + AST->LangOpts = LangOpts ? std::make_unique(*LangOpts) + : std::make_unique(); AST->OnlyLocalDecls = OnlyLocalDecls; AST->CaptureDiagnostics = CaptureDiagnostics; AST->Diagnostics = Diags; @@ -1211,7 +1212,8 @@ bool ASTUnit::Parse(std::shared_ptr PCHContainerOps, "IR inputs not support here!"); // Configure the various subsystems. - LangOpts = Clang->getInvocation().LangOpts; + LangOpts = + std::make_unique(Clang->getInvocation().getLangOpts()); FileSystemOpts = Clang->getFileSystemOpts(); ResetForParse(); @@ -1486,7 +1488,7 @@ void ASTUnit::transferASTDataFromCompilerInstance(CompilerInstance &CI) { // Steal the created target, context, and preprocessor if they have been // created. assert(CI.hasInvocation() && "missing invocation"); - LangOpts = CI.getInvocation().LangOpts; + LangOpts = std::make_unique(CI.getInvocation().getLangOpts()); TheSema = CI.takeSema(); Consumer = CI.takeASTConsumer(); if (CI.hasASTContext()) diff --git a/clang/lib/Frontend/FrontendAction.cpp b/
[clang] [llvm] [DXIL] Remove incompatible metadata types when preparing DXIL. (PR #136386)
https://github.com/bogner approved this pull request. Looks good https://github.com/llvm/llvm-project/pull/136386 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [DXIL] Remove incompatible metadata types when preparing DXIL. (PR #136386)
https://github.com/bogner edited https://github.com/llvm/llvm-project/pull/136386 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [DXIL] Remove incompatible metadata types when preparing DXIL. (PR #136386)
@@ -0,0 +1,29 @@ +; RUN: opt -S --dxil-prepare %s | FileCheck %s + +; Test that only metadata nodes that are valid in DXIL are allowed through + +target triple = "dxilv1.0-unknown-shadermodel6.0-compute" + +; Function Attrs: noinline nounwind memory(readwrite, inaccessiblemem: none) +define void @main(i32* %ptr) { +entry: + ; metadata ID changes to 0 once the current !0 and !1 are removed + ; since they aren't in the whitelist. range needs a payload. + ; CHECK: %val = load i32, ptr %ptr, align 4, !range [[RANGEMD:![0-9]+]] + %val = load i32, ptr %ptr, align 4, !range !2 + + %cmp.i = icmp ult i32 1, 2 + br i1 %cmp.i, label %_Z4mainDv3_j.exit, label %_Z4mainDv3_j.exit, !llvm.loop !0 + +_Z4mainDv3_j.exit:; preds = %for.body.i, %entry + ret void bogner wrote: You can check that the loop metadata is stripped here by using a regex for the end of the line: ```suggestion %cmp.i = icmp ult i32 1, 2 ; CHECK: br i1 %cmp.i, label %exit, label %exit{{$}} br i1 %cmp.i, label %exit, label %exit, !llvm.loop !0 exit: ret void ``` https://github.com/llvm/llvm-project/pull/136386 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [DXIL] Remove incompatible metadata types when preparing DXIL. (PR #136386)
@@ -0,0 +1,29 @@ +; RUN: opt -S --dxil-prepare %s | FileCheck %s + +; Test that only metadata nodes that are valid in DXIL are allowed through + +target triple = "dxilv1.0-unknown-shadermodel6.0-compute" + +; Function Attrs: noinline nounwind memory(readwrite, inaccessiblemem: none) +define void @main(i32* %ptr) { +entry: + ; metadata ID changes to 0 once the current !0 and !1 are removed + ; since they aren't in the whitelist. range needs a payload. + ; CHECK: %val = load i32, ptr %ptr, align 4, !range [[RANGEMD:![0-9]+]] + %val = load i32, ptr %ptr, align 4, !range !2 + + %cmp.i = icmp ult i32 1, 2 + br i1 %cmp.i, label %_Z4mainDv3_j.exit, label %_Z4mainDv3_j.exit, !llvm.loop !0 + +_Z4mainDv3_j.exit:; preds = %for.body.i, %entry + ret void +} + +; CHECK: [[RANGEMD]] = !{i32 1, i32 5} +; this next check line checks that nothing comes after the above check line. +; No more metadata should be necessary, the rest (the current 0 and 1) +; should be removed. +; CHECK-NOT: !{!"llvm.loop.mustprogress"} bogner wrote: `CHECK-NOT` is finicky - if `!{!"llvm.loop.mustprogress"}` prints *before* the range MD this won't fire. We need to use two check-nots, like so ```suggestion ; CHECK-NOT: !{!"llvm.loop.mustprogress"} ; CHECK: [[RANGEMD]] = !{i32 1, i32 5} ; CHECK-NOT: !{!"llvm.loop.mustprogress"} ``` https://github.com/llvm/llvm-project/pull/136386 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Hide the `LangOptions` pointer from `CompilerInvocation` (PR #137675)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Jan Svoboda (jansvoboda11) Changes This PR makes `CompilerInvocation` the sole owner of the `LangOptions` instance. --- Full diff: https://github.com/llvm/llvm-project/pull/137675.diff 5 Files Affected: - (modified) clang/include/clang/Frontend/ASTUnit.h (+2-2) - (modified) clang/include/clang/Frontend/CompilerInstance.h (-3) - (modified) clang/include/clang/Frontend/CompilerInvocation.h (-6) - (modified) clang/lib/Frontend/ASTUnit.cpp (+6-4) - (modified) clang/lib/Frontend/FrontendAction.cpp (+1-1) ``diff diff --git a/clang/include/clang/Frontend/ASTUnit.h b/clang/include/clang/Frontend/ASTUnit.h index 2baa2d1cc540d..73686b0eacbe2 100644 --- a/clang/include/clang/Frontend/ASTUnit.h +++ b/clang/include/clang/Frontend/ASTUnit.h @@ -106,7 +106,7 @@ class ASTUnit { }; private: - std::shared_ptrLangOpts; + std::unique_ptr LangOpts; IntrusiveRefCntPtr Diagnostics; IntrusiveRefCntPtr FileMgr; IntrusiveRefCntPtr SourceMgr; @@ -704,7 +704,7 @@ class ASTUnit { IntrusiveRefCntPtr Diags, const FileSystemOptions &FileSystemOpts, const HeaderSearchOptions &HSOpts, - std::shared_ptr LangOpts = nullptr, + const LangOptions *LangOpts = nullptr, bool OnlyLocalDecls = false, CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None, bool AllowASTWithCompilerErrors = false, diff --git a/clang/include/clang/Frontend/CompilerInstance.h b/clang/include/clang/Frontend/CompilerInstance.h index 7de4fb531d0e7..78ac1079354de 100644 --- a/clang/include/clang/Frontend/CompilerInstance.h +++ b/clang/include/clang/Frontend/CompilerInstance.h @@ -327,9 +327,6 @@ class CompilerInstance : public ModuleLoader { LangOptions &getLangOpts() { return Invocation->getLangOpts(); } const LangOptions &getLangOpts() const { return Invocation->getLangOpts(); } - std::shared_ptr getLangOptsPtr() const { -return Invocation->getLangOptsPtr(); - } PreprocessorOptions &getPreprocessorOpts() { return Invocation->getPreprocessorOpts(); diff --git a/clang/include/clang/Frontend/CompilerInvocation.h b/clang/include/clang/Frontend/CompilerInvocation.h index 1827ff0f6816d..31bf7e94efab8 100644 --- a/clang/include/clang/Frontend/CompilerInvocation.h +++ b/clang/include/clang/Frontend/CompilerInvocation.h @@ -265,12 +265,6 @@ class CompilerInvocation : public CompilerInvocationBase { } /// @} - /// Base class internals. - /// @{ - using CompilerInvocationBase::LangOpts; - std::shared_ptr getLangOptsPtr() { return LangOpts; } - /// @} - /// Create a compiler invocation from a list of input options. /// \returns true on success. /// diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index 3e4da76916585..e05385d119870 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -805,7 +805,7 @@ std::unique_ptr ASTUnit::LoadFromASTFile( StringRef Filename, const PCHContainerReader &PCHContainerRdr, WhatToLoad ToLoad, IntrusiveRefCntPtr Diags, const FileSystemOptions &FileSystemOpts, const HeaderSearchOptions &HSOpts, -std::shared_ptr LangOpts, bool OnlyLocalDecls, +const LangOptions *LangOpts, bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics, bool AllowASTWithCompilerErrors, bool UserFilesAreVolatile, IntrusiveRefCntPtr VFS) { std::unique_ptr AST(new ASTUnit(true)); @@ -819,7 +819,8 @@ std::unique_ptr ASTUnit::LoadFromASTFile( ConfigureDiags(Diags, *AST, CaptureDiagnostics); - AST->LangOpts = LangOpts ? LangOpts : std::make_shared(); + AST->LangOpts = LangOpts ? std::make_unique(*LangOpts) + : std::make_unique(); AST->OnlyLocalDecls = OnlyLocalDecls; AST->CaptureDiagnostics = CaptureDiagnostics; AST->Diagnostics = Diags; @@ -1211,7 +1212,8 @@ bool ASTUnit::Parse(std::shared_ptr PCHContainerOps, "IR inputs not support here!"); // Configure the various subsystems. - LangOpts = Clang->getInvocation().LangOpts; + LangOpts = + std::make_unique(Clang->getInvocation().getLangOpts()); FileSystemOpts = Clang->getFileSystemOpts(); ResetForParse(); @@ -1486,7 +1488,7 @@ void ASTUnit::transferASTDataFromCompilerInstance(CompilerInstance &CI) { // Steal the created target, context, and preprocessor if they have been // created. assert(CI.hasInvocation() && "missing invocation"); - LangOpts = CI.getInvocation().LangOpts; + LangOpts = std::make_unique(CI.getInvocation().getLangOpts()); TheSema = CI.takeSema(); Consumer = CI.takeASTConsumer(); if (CI.hasASTContext()) diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp index 783d1a64132b6..9b2aa253c90ee 100644 --- a/clang/lib/Frontend/FrontendAction.cpp +++ b/clang/lib/Frontend/FrontendAction
[clang] [sanitizer] Allow use-after-scope front-end argument to take effect with -fsanitize=kernel-address (PR #137015)
vitalybuka wrote: > > However, please be aware that default for Asan is ON. Should Kasan default > > be OFF in the beginning? > > @vitalybuka I'm not sure how many users test a kernel exclusively in `-O0`, > but to those who do, I suppose defaulting this to ON could allow the > sanitizer to capture never-before-seen use-after-scope issues. > > With that said, I'm inclined to keep this defaulted to ON like normal ASAN. > Does this sound reasonable, or am I missing some negative side-effects that > you had in mind when posting this comment? Would it be worth mentioning this > change as a release note regardless? > > EDIT: I realize one detail I missed when I wrote the description of the PR. > The 'workaround' to get `use-after-scope` functioning with > `-fsanitize=kernel-address` for `-O1` and up before this PR involves adding > `-mllvm -asan-use-after-scope=1`. So by defaulting > `-fsanitize-address-use-after-scope` to ON for `-fsanitize=kernel-address` in > this PR, we'd actually be enabling UAS detection for all optimization levels > which may be new to those who haven't employed the workaround. I suppose from > that PoV, effects are a bit more far reaching than I initially though. I'm > still inclined to keep it ON by default if not to increase coverage, but > maybe I'm being optimistic that it wouldn't have negative effects elsewhere... LGTM, I guess it's easy to add -fno-sanitize-address-use-after-scope into kernel build files if needed. https://github.com/llvm/llvm-project/pull/137015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [DXIL] Remove incompatible metadata types when preparing DXIL. (PR #136386)
@@ -0,0 +1,29 @@ +; RUN: opt -S --dxil-prepare %s | FileCheck %s + +; Test that only metadata nodes that are valid in DXIL are allowed through + +target triple = "dxilv1.0-unknown-shadermodel6.0-compute" + +; Function Attrs: noinline nounwind memory(readwrite, inaccessiblemem: none) +define void @main(i32* %ptr) { +entry: + ; metadata ID changes to 0 once the current !0 and !1 are removed + ; since they aren't in the whitelist. range needs a payload. bogner wrote: ```suggestion ; since they aren't in the allowlist. range needs a payload. ``` https://github.com/llvm/llvm-project/pull/136386 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [DXIL] Remove incompatible metadata types when preparing DXIL. (PR #136386)
@@ -176,6 +185,9 @@ class DXILPrepareModule : public ModulePass { VersionTuple ValVer = MetadataInfo.ValidatorVersion; bool SkipValidation = ValVer.getMajor() == 0 && ValVer.getMinor() == 0; +// construct whitelist of valid metadata node kinds bogner wrote: ```suggestion // construct allowlist of valid metadata node kinds ``` https://github.com/llvm/llvm-project/pull/136386 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Hide the `LangOptions` pointer from `CompilerInvocation` (PR #137675)
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 HEAD~1 HEAD --extensions h,cpp -- clang/include/clang/Frontend/ASTUnit.h clang/include/clang/Frontend/CompilerInstance.h clang/include/clang/Frontend/CompilerInvocation.h clang/lib/Frontend/ASTUnit.cpp clang/lib/Frontend/FrontendAction.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/include/clang/Frontend/ASTUnit.h b/clang/include/clang/Frontend/ASTUnit.h index 73686b0ea..ac99f0fb2 100644 --- a/clang/include/clang/Frontend/ASTUnit.h +++ b/clang/include/clang/Frontend/ASTUnit.h @@ -698,19 +698,17 @@ public: /// lifetime is expected to extend past that of the returned ASTUnit. /// /// \returns - The initialized ASTUnit or null if the AST failed to load. - static std::unique_ptr - LoadFromASTFile(StringRef Filename, const PCHContainerReader &PCHContainerRdr, - WhatToLoad ToLoad, - IntrusiveRefCntPtr Diags, - const FileSystemOptions &FileSystemOpts, - const HeaderSearchOptions &HSOpts, - const LangOptions *LangOpts = nullptr, - bool OnlyLocalDecls = false, - CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None, - bool AllowASTWithCompilerErrors = false, - bool UserFilesAreVolatile = false, - IntrusiveRefCntPtr VFS = - llvm::vfs::getRealFileSystem()); + static std::unique_ptr LoadFromASTFile( + StringRef Filename, const PCHContainerReader &PCHContainerRdr, + WhatToLoad ToLoad, IntrusiveRefCntPtr Diags, + const FileSystemOptions &FileSystemOpts, + const HeaderSearchOptions &HSOpts, const LangOptions *LangOpts = nullptr, + bool OnlyLocalDecls = false, + CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None, + bool AllowASTWithCompilerErrors = false, + bool UserFilesAreVolatile = false, + IntrusiveRefCntPtr VFS = + llvm::vfs::getRealFileSystem()); private: /// Helper function for \c LoadFromCompilerInvocation() and `` https://github.com/llvm/llvm-project/pull/137675 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [sanitizer] Allow use-after-scope front-end argument to take effect with -fsanitize=kernel-address (PR #137015)
https://github.com/vitalybuka approved this pull request. https://github.com/llvm/llvm-project/pull/137015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C] Diagnose declarations hidden in C++ (PR #137368)
https://github.com/erichkeane approved this pull request. 1 nit, that function could be cleaned up a bit, else LGTM. https://github.com/llvm/llvm-project/pull/137368 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C] Diagnose declarations hidden in C++ (PR #137368)
https://github.com/erichkeane edited https://github.com/llvm/llvm-project/pull/137368 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C] Diagnose declarations hidden in C++ (PR #137368)
@@ -1428,6 +1428,17 @@ bool DeclContext::Encloses(const DeclContext *DC) const { return false; } +bool DeclContext::LexicallyEncloses(const DeclContext *DC) const { + if (getPrimaryContext() != this) +return getPrimaryContext()->LexicallyEncloses(DC); + + for (; DC; DC = DC->getLexicalParent()) +if (!isa(DC) && !isa(DC) && erichkeane wrote: ```suggestion if (!isa(DC) && ``` That said... Perhaps we should just do a ``` if (isa(*this)) return false; ``` ?? Since thats the only way the equivilence would work? https://github.com/llvm/llvm-project/pull/137368 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Put tests for compatibility overloads for 'clamp', 'isinf', 'min', and 'max' in own files (PR #137004)
https://github.com/V-FEXrt approved this pull request. https://github.com/llvm/llvm-project/pull/137004 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Put tests for compatibility overloads for 'clamp', 'isinf', 'min', and 'max' in own files (PR #137004)
https://github.com/bogner approved this pull request. https://github.com/llvm/llvm-project/pull/137004 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] Add IR Profile-Guided Optimization (IR PGO) support to the Flang compiler (PR #136098)
https://github.com/tblah commented: Thanks for the updates https://github.com/llvm/llvm-project/pull/136098 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [llvm] Add IR Profile-Guided Optimization (IR PGO) support to the Flang compiler (PR #136098)
@@ -20,8 +20,13 @@ #include "mlir/IR/OwningOpRef.h" #include "llvm/ADT/StringRef.h" #include "llvm/IR/Module.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/PGOOptions.h" #include +namespace llvm { +extern cl::opt ClPGOColdFuncAttr; +} // namespace llvm tblah wrote: nit: I would put this `extern` in `flang/lib/Frontend/FrontendActions.cpp` because there is no need for this implementation detail to be part of the public interface. https://github.com/llvm/llvm-project/pull/136098 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc][NFC] Remove unary_builtin.inc (PR #137656)
https://github.com/frasercrmck created https://github.com/llvm/llvm-project/pull/137656 We had two ways of achieving the same thing. This commit removes unary_builtin.inc in favour of the approach combining gentype.inc with unary_def.inc. There is no change to the codegen for any target. >From 2ab6a2860341935fa6b6a7b6a2819c82d2c5eaa1 Mon Sep 17 00:00:00 2001 From: Fraser Cormack Date: Mon, 28 Apr 2025 16:50:51 +0100 Subject: [PATCH] [libclc][NFC] Remove unary_builtin.inc We had two ways of achieving the same thing. This commit removes unary_builtin.inc in favour of the approach combining gentype.inc with unary_def.inc. There is no change to the codegen for any target. --- libclc/clc/include/clc/math/unary_builtin.inc | 32 --- libclc/clc/lib/generic/math/clc_ceil.cl | 9 +++--- libclc/clc/lib/generic/math/clc_fabs.cl | 9 +++--- libclc/clc/lib/generic/math/clc_floor.cl | 9 +++--- libclc/clc/lib/generic/math/clc_rint.cl | 9 +++--- libclc/clc/lib/generic/math/clc_round.cl | 9 +++--- libclc/clc/lib/generic/math/clc_trunc.cl | 9 +++--- libclc/generic/lib/math/acos.cl | 8 ++--- libclc/generic/lib/math/acosh.cl | 7 ++-- libclc/generic/lib/math/acospi.cl | 6 ++-- libclc/generic/lib/math/asin.cl | 8 ++--- libclc/generic/lib/math/asinh.cl | 7 ++-- libclc/generic/lib/math/asinpi.cl | 7 ++-- libclc/generic/lib/math/atan.cl | 8 ++--- libclc/generic/lib/math/atanh.cl | 7 ++-- libclc/generic/lib/math/atanpi.cl | 7 ++-- libclc/generic/lib/math/ceil.cl | 8 ++--- libclc/generic/lib/math/fabs.cl | 8 ++--- libclc/generic/lib/math/floor.cl | 8 ++--- libclc/generic/lib/math/log1p.cl | 7 ++-- libclc/generic/lib/math/rint.cl | 7 ++-- libclc/generic/lib/math/round.cl | 8 ++--- libclc/generic/lib/math/trunc.cl | 7 ++-- 23 files changed, 93 insertions(+), 111 deletions(-) delete mode 100644 libclc/clc/include/clc/math/unary_builtin.inc diff --git a/libclc/clc/include/clc/math/unary_builtin.inc b/libclc/clc/include/clc/math/unary_builtin.inc deleted file mode 100644 index 790eaec5341d5..0 --- a/libclc/clc/include/clc/math/unary_builtin.inc +++ /dev/null @@ -1,32 +0,0 @@ -//===--===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===--===// - -#include -#include - -#ifndef __CLC_BUILTIN -#define __CLC_BUILTIN __CLC_XCONCAT(__clc_, __CLC_FUNCTION) -#endif - -_CLC_DEFINE_UNARY_BUILTIN(float, __CLC_FUNCTION, __CLC_BUILTIN, float) - -#ifdef cl_khr_fp64 - -#pragma OPENCL EXTENSION cl_khr_fp64 : enable - -_CLC_DEFINE_UNARY_BUILTIN(double, __CLC_FUNCTION, __CLC_BUILTIN, double) - -#endif - -#ifdef cl_khr_fp16 - -#pragma OPENCL EXTENSION cl_khr_fp16 : enable - -_CLC_DEFINE_UNARY_BUILTIN(half, __CLC_FUNCTION, __CLC_BUILTIN, half) - -#endif diff --git a/libclc/clc/lib/generic/math/clc_ceil.cl b/libclc/clc/lib/generic/math/clc_ceil.cl index 975b51185d58c..c4df638d5ce26 100644 --- a/libclc/clc/lib/generic/math/clc_ceil.cl +++ b/libclc/clc/lib/generic/math/clc_ceil.cl @@ -8,7 +8,8 @@ #include -#undef __CLC_FUNCTION -#define __CLC_FUNCTION __clc_ceil -#define __CLC_BUILTIN __builtin_elementwise_ceil -#include +#define FUNCTION __clc_ceil +#define __CLC_FUNCTION(x) __builtin_elementwise_ceil +#define __CLC_BODY + +#include diff --git a/libclc/clc/lib/generic/math/clc_fabs.cl b/libclc/clc/lib/generic/math/clc_fabs.cl index 90841afefdfb9..f684c1e76bbbd 100644 --- a/libclc/clc/lib/generic/math/clc_fabs.cl +++ b/libclc/clc/lib/generic/math/clc_fabs.cl @@ -8,7 +8,8 @@ #include -#undef __CLC_FUNCTION -#define __CLC_FUNCTION __clc_fabs -#define __CLC_BUILTIN __builtin_elementwise_abs -#include +#define FUNCTION __clc_fabs +#define __CLC_FUNCTION(x) __builtin_elementwise_abs +#define __CLC_BODY + +#include diff --git a/libclc/clc/lib/generic/math/clc_floor.cl b/libclc/clc/lib/generic/math/clc_floor.cl index 2b80e5b3a178e..0626ba36f3ea8 100644 --- a/libclc/clc/lib/generic/math/clc_floor.cl +++ b/libclc/clc/lib/generic/math/clc_floor.cl @@ -8,7 +8,8 @@ #include -#undef __CLC_FUNCTION -#define __CLC_FUNCTION __clc_floor -#define __CLC_BUILTIN __builtin_elementwise_floor -#include +#define FUNCTION __clc_floor +#define __CLC_FUNCTION(x) __builtin_elementwise_floor +#define __CLC_BODY + +#include diff --git a/libclc/clc/lib/generic/math/clc_rint.cl b/libclc/clc/lib/generic/math/clc_rint.cl index d0852bcf77163..2188a7d901f01 100644 --- a/libclc/clc/lib/generic/math/clc_rint.cl +++ b/libclc/clc/lib/generic/ma
[clang] [C] Diagnose use of C++ keywords in C (PR #137234)
@@ -6107,6 +6109,29 @@ static bool isFromSystemHeader(SourceManager &SM, const Decl *D) { SM.isInSystemMacro(D->getLocation()); } +static bool isKeywordInCPlusPlus(const Sema &S, const IdentifierInfo *II) { + if (!II) +return false; + + // Build a static map of identifiers for all of the keywords in C++ that are + // not keywords in C. This allows us to do pointer comparisons instead of + // string comparisons when deciding whether the given identifier is a keyword + // or not. Note, this treats all keywords as being enabled, regardless of the + // setting of other language options. It intentionally disables the modules + // keywords because those are conditional keywords, so may be safe to use. + static llvm::SmallPtrSet Keywords; + if (Keywords.empty()) { +#define MODULES_KEYWORD(NAME) +#define KEYWORD(NAME, FLAGS) \ + Keywords.insert(&S.getPreprocessor().getIdentifierTable().get(#NAME)); +#define CXX_KEYWORD_OPERATOR(NAME, TOK) \ + Keywords.insert(&S.getPreprocessor().getIdentifierTable().get(#NAME)); +#include "clang/Basic/TokenKinds.def" + } + + return Keywords.contains(II); erichkeane wrote: Oof! 48 would be fine. Else, I'd love a static-assert (or, if you're doing the work for that, just making this the 'right' number so it never actually allocates and we don't have 'extra'), but can live with '48 should be big enough for anybody!' https://github.com/llvm/llvm-project/pull/137234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64] Add pessimistic vscale_range when sve is in target-f… (PR #137624)
@@ -794,14 +795,22 @@ AArch64TargetInfo::getTargetBuiltins() const { std::optional> AArch64TargetInfo::getVScaleRange(const LangOptions &LangOpts, - bool IsArmStreamingFunction) const { + bool IsArmStreamingFunction, + llvm::Function *F) const { if (LangOpts.VScaleMin || LangOpts.VScaleMax) return std::pair( LangOpts.VScaleMin ? LangOpts.VScaleMin : 1, LangOpts.VScaleMax); if (hasFeature("sve") || (IsArmStreamingFunction && hasFeature("sme"))) return std::pair(1, 16); + if (F && F->hasFnAttribute("target-features")) { +StringRef Str = F->getFnAttribute("target-features").getValueAsString(); +for (const auto &s : llvm::split(Str, ",")) { + if (s == "+sve") david-arm wrote: Fair enough! https://github.com/llvm/llvm-project/pull/137624 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Remove FEM_Indeterminable (PR #137247)
zahiraam wrote: > > I've reverted, not sure why I thought it had been reviewed? > > Thanks! And I'm happy enough blaming GitHub's poor Ux for all confusion. :-) > > @zahiraam -- any chance you can look into this? Yes I can in a couple of days. @ojhunt I hope this is OK? https://github.com/llvm/llvm-project/pull/137247 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add new -Wimplicit-int-enum-cast to -Wc++-compat (PR #137658)
https://github.com/AaronBallman created https://github.com/llvm/llvm-project/pull/137658 This introduces a new diagnostic group to diagnose implicit casts from int to an enumeration type. In C, this is valid, but it is not compatible with C++. Additionally, this moves the "implicit conversion from enum type to different enum type" diagnostic from `-Wenum-conversion` to a new group `-Wimplicit-enum-enum-cast`, which is a more accurate home for it. `-Wimplicit-enum-enum-cast` is also under `-Wimplicit-int-enum-cast`, as it is the same incompatibility (the enumeration on the right-hand is promoted to `int`, so it's an int -> enum conversion). Fixes #37027 >From 0922c27f28eadd657086fd9eb0a68ab14ce37307 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Mon, 28 Apr 2025 11:56:40 -0400 Subject: [PATCH] Add new -Wimplicit-int-enum-cast to -Wc++-compat This introduces a new diagnostic group to diagnose implicit casts from int to an enumeration type. In C, this is valid, but it is not compatible with C++. Additionally, this moves the "implicit conversion from enum type to different enum type" diagnostic from `-Wenum-conversion` to a new group `-Wimplicit-enum-enum-cast`, which is a more accurate home for it. `-Wimplicit-enum-enum-cast` is also under `-Wimplicit-int-enum-cast`, as it is the same incompatibility (the enumeration on the right-hand is promoted to `int`, so it's an int -> enum conversion). Fixes #37027 --- clang/docs/ReleaseNotes.rst | 9 clang/include/clang/Basic/DiagnosticGroups.td | 7 ++- .../clang/Basic/DiagnosticSemaKinds.td| 5 +- clang/lib/Sema/SemaChecking.cpp | 8 ++- clang/test/Misc/warning-flags-enabled.c | 8 +-- .../test/Sema/implicit-int-enum-conversion.c | 52 +++ 6 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 clang/test/Sema/implicit-int-enum-conversion.c diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 3105d8b481560..1bcf358974437 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -150,6 +150,15 @@ C Language Changes - Added ``-Wimplicit-void-ptr-cast``, grouped under ``-Wc++-compat``, which diagnoses implicit conversion from ``void *`` to another pointer type as being incompatible with C++. (#GH17792) +- Added ``-Wimplicit-int-enum-cast``, grouped under ``-Wc++-compat``, which + diagnoses implicit conversion from integer types to an enumeration type in C, + which is not compatible with C++. #GH37027 +- Split "implicit conversion from enum type to different enum type" diagnostic + from ``-Wenum-conversion`` into its own diagnostic group, + ``-Wimplicit-enum-enum-cast``, which is grouped under both + ``-Wenum-conversion`` and ``-Wimplicit-int-enum-cast``. This conversion is an + int-to-enum conversion because the enumeration on the right-hand side is + promoted to ``int`` before the assignment. C2y Feature Support ^^^ diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 31e2cfa7ab485..97ed38d71ed51 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -103,10 +103,12 @@ def AnonEnumEnumConversion : DiagGroup<"anon-enum-enum-conversion", [DeprecatedAnonEnumEnumConversion]>; def EnumEnumConversion : DiagGroup<"enum-enum-conversion", [DeprecatedEnumEnumConversion]>; +def ImplicitEnumEnumCast : DiagGroup<"implicit-enum-enum-cast">; def EnumFloatConversion : DiagGroup<"enum-float-conversion", [DeprecatedEnumFloatConversion]>; def EnumConversion : DiagGroup<"enum-conversion", [EnumEnumConversion, +ImplicitEnumEnumCast, EnumFloatConversion, EnumCompareConditional]>; def DeprecatedOFast : DiagGroup<"deprecated-ofast">; @@ -157,7 +159,10 @@ def : DiagGroup<"c2x-compat", [C23Compat]>; def DefaultConstInitUnsafe : DiagGroup<"default-const-init-unsafe">; def DefaultConstInit : DiagGroup<"default-const-init", [DefaultConstInitUnsafe]>; def ImplicitVoidPtrCast : DiagGroup<"implicit-void-ptr-cast">; -def CXXCompat: DiagGroup<"c++-compat", [ImplicitVoidPtrCast, DefaultConstInit]>; +def ImplicitIntToEnumCast : DiagGroup<"implicit-int-enum-cast", + [ImplicitEnumEnumCast]>; +def CXXCompat: DiagGroup<"c++-compat", [ImplicitVoidPtrCast, DefaultConstInit, +ImplicitIntToEnumCast]>; def ExternCCompat : DiagGroup<"extern-c-compat">; def KeywordCompat : DiagGroup<"keyword-compat">; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 4c96142e28134..2e148e01d6e5e 100644 --- a/clang/include/clang/Basic/Diag
[clang] [C] Add new -Wimplicit-int-enum-cast to -Wc++-compat (PR #137658)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Aaron Ballman (AaronBallman) Changes This introduces a new diagnostic group to diagnose implicit casts from int to an enumeration type. In C, this is valid, but it is not compatible with C++. Additionally, this moves the "implicit conversion from enum type to different enum type" diagnostic from `-Wenum-conversion` to a new group `-Wimplicit-enum-enum-cast`, which is a more accurate home for it. `-Wimplicit-enum-enum-cast` is also under `-Wimplicit-int-enum-cast`, as it is the same incompatibility (the enumeration on the right-hand is promoted to `int`, so it's an int -> enum conversion). Fixes #37027 --- Full diff: https://github.com/llvm/llvm-project/pull/137658.diff 6 Files Affected: - (modified) clang/docs/ReleaseNotes.rst (+9) - (modified) clang/include/clang/Basic/DiagnosticGroups.td (+6-1) - (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+4-1) - (modified) clang/lib/Sema/SemaChecking.cpp (+7-1) - (modified) clang/test/Misc/warning-flags-enabled.c (+5-3) - (added) clang/test/Sema/implicit-int-enum-conversion.c (+52) ``diff diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 3105d8b481560..1bcf358974437 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -150,6 +150,15 @@ C Language Changes - Added ``-Wimplicit-void-ptr-cast``, grouped under ``-Wc++-compat``, which diagnoses implicit conversion from ``void *`` to another pointer type as being incompatible with C++. (#GH17792) +- Added ``-Wimplicit-int-enum-cast``, grouped under ``-Wc++-compat``, which + diagnoses implicit conversion from integer types to an enumeration type in C, + which is not compatible with C++. #GH37027 +- Split "implicit conversion from enum type to different enum type" diagnostic + from ``-Wenum-conversion`` into its own diagnostic group, + ``-Wimplicit-enum-enum-cast``, which is grouped under both + ``-Wenum-conversion`` and ``-Wimplicit-int-enum-cast``. This conversion is an + int-to-enum conversion because the enumeration on the right-hand side is + promoted to ``int`` before the assignment. C2y Feature Support ^^^ diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 31e2cfa7ab485..97ed38d71ed51 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -103,10 +103,12 @@ def AnonEnumEnumConversion : DiagGroup<"anon-enum-enum-conversion", [DeprecatedAnonEnumEnumConversion]>; def EnumEnumConversion : DiagGroup<"enum-enum-conversion", [DeprecatedEnumEnumConversion]>; +def ImplicitEnumEnumCast : DiagGroup<"implicit-enum-enum-cast">; def EnumFloatConversion : DiagGroup<"enum-float-conversion", [DeprecatedEnumFloatConversion]>; def EnumConversion : DiagGroup<"enum-conversion", [EnumEnumConversion, +ImplicitEnumEnumCast, EnumFloatConversion, EnumCompareConditional]>; def DeprecatedOFast : DiagGroup<"deprecated-ofast">; @@ -157,7 +159,10 @@ def : DiagGroup<"c2x-compat", [C23Compat]>; def DefaultConstInitUnsafe : DiagGroup<"default-const-init-unsafe">; def DefaultConstInit : DiagGroup<"default-const-init", [DefaultConstInitUnsafe]>; def ImplicitVoidPtrCast : DiagGroup<"implicit-void-ptr-cast">; -def CXXCompat: DiagGroup<"c++-compat", [ImplicitVoidPtrCast, DefaultConstInit]>; +def ImplicitIntToEnumCast : DiagGroup<"implicit-int-enum-cast", + [ImplicitEnumEnumCast]>; +def CXXCompat: DiagGroup<"c++-compat", [ImplicitVoidPtrCast, DefaultConstInit, +ImplicitIntToEnumCast]>; def ExternCCompat : DiagGroup<"extern-c-compat">; def KeywordCompat : DiagGroup<"keyword-compat">; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 4c96142e28134..2e148e01d6e5e 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -4310,7 +4310,10 @@ def warn_impcast_string_literal_to_bool : Warning< InGroup, DefaultIgnore; def warn_impcast_different_enum_types : Warning< "implicit conversion from enumeration type %0 to different enumeration type " - "%1">, InGroup; + "%1">, InGroup; +def warn_impcast_int_to_enum : Warning< + "implicit conversion from %0 to enumeration type %1 is invalid in C++">, + InGroup, DefaultIgnore; def warn_impcast_bool_to_null_pointer : Warning< "initialization of pointer of type %0 to null from a constant boolean " "expression">, InGroup; diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 2811fd3a04377..332504405eccb 100644 --- a/cla
[clang] [C] Add new -Wimplicit-int-enum-cast to -Wc++-compat (PR #137658)
https://github.com/AaronBallman edited https://github.com/llvm/llvm-project/pull/137658 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AMDGPU] Support the OpenCL generic addrspace feature by default (PR #137636)
@@ -155,3 +155,11 @@ #endif #pragma OPENCL EXTENSION cl_amd_media_ops2: enable +#if (__OPENCL_C_VERSION__ >= 300) jmmartinez wrote: I don't understand, isn't `__opencl_c_generic_address_space` available by default with `OPENCL_C_VERSION >= 200` (from reading `opencl-c-base.h`) ? https://github.com/llvm/llvm-project/pull/137636 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [sanitizer] Allow use-after-scope front-end argument to take effect with -fsanitize=kernel-address (PR #137015)
dgg5503 wrote: Ping for @vitalybuka , I'll merge this in by EOD if there are no objections based on my latest comment (for real this time 😀). https://github.com/llvm/llvm-project/pull/137015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C] Diagnose use of C++ keywords in C (PR #137234)
https://github.com/AaronBallman updated https://github.com/llvm/llvm-project/pull/137234 >From 56a3f3cd282e9bd5ef9014e4125380e0d9685121 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Thu, 24 Apr 2025 14:17:42 -0400 Subject: [PATCH 01/12] [C] Diagnose use of C++ keywords in C This adds a new diagnostic group, -Widentifier-is-c++-keyword, which is off by default and grouped under -Wc++-compat. The diagnostic catches use of C++ keywords in C code. This change additionally fixes an issue with -Wreserved-identifier not diagnosing use of reserved identifiers in function parameter lists. Partially fixes #21898 --- clang/docs/ReleaseNotes.rst | 3 + clang/include/clang/Basic/DiagnosticGroups.td | 3 +- .../clang/Basic/DiagnosticSemaKinds.td| 3 + clang/include/clang/Basic/IdentifierTable.h | 11 +- clang/lib/Basic/IdentifierTable.cpp | 27 +++ clang/lib/Sema/SemaDecl.cpp | 23 ++ clang/test/Sema/c++-keyword-in-c.c| 213 ++ 7 files changed, 279 insertions(+), 4 deletions(-) create mode 100644 clang/test/Sema/c++-keyword-in-c.c diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index d1f24fb23d44d..57b604335fcdd 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -143,6 +143,9 @@ C Language Changes - Added ``-Wimplicit-void-ptr-cast``, grouped under ``-Wc++-compat``, which diagnoses implicit conversion from ``void *`` to another pointer type as being incompatible with C++. (#GH17792) +- Added ``-Widentifier-is-c++-keyword``, grouped under ``-Wc++-compat``, which + diagnoses when a C++ keyword is used as an identifier in C. Partially + addresses #GH21898. C2y Feature Support ^^^ diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 6441b8049ed8d..84e590a857398 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -155,8 +155,9 @@ def C99Compat : DiagGroup<"c99-compat">; def C23Compat : DiagGroup<"c23-compat">; def : DiagGroup<"c2x-compat", [C23Compat]>; +def CppKeywordInC : DiagGroup<"identifier-is-c++-keyword">; def ImplicitVoidPtrCast : DiagGroup<"implicit-void-ptr-cast">; -def CXXCompat: DiagGroup<"c++-compat", [ImplicitVoidPtrCast]>; +def CXXCompat: DiagGroup<"c++-compat", [ImplicitVoidPtrCast, CppKeywordInC]>; def ExternCCompat : DiagGroup<"extern-c-compat">; def KeywordCompat : DiagGroup<"keyword-compat">; def GNUCaseRange : DiagGroup<"gnu-case-range">; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 8ff170520aafe..50a960313349a 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -496,6 +496,9 @@ def warn_unused_lambda_capture: Warning<"lambda capture %0 is not " "%select{used|required to be captured for this use}1">, InGroup, DefaultIgnore; +def warn_identifier_is_cpp_keyword : Warning< + "identifier %0 conflicts with a C++ keyword">, + InGroup, DefaultIgnore; def warn_reserved_extern_symbol: Warning< "identifier %0 is reserved because %select{" "|" // ReservedIdentifierStatus::NotReserved diff --git a/clang/include/clang/Basic/IdentifierTable.h b/clang/include/clang/Basic/IdentifierTable.h index 1275b056227b5..05c989c1b07d9 100644 --- a/clang/include/clang/Basic/IdentifierTable.h +++ b/clang/include/clang/Basic/IdentifierTable.h @@ -444,13 +444,18 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo { } bool isCPlusPlusOperatorKeyword() const { return IsCPPOperatorKeyword; } - /// Return true if this token is a keyword in the specified language. + /// Return true if this identifier uses a keyword token and is a keyword in + /// the specified language. bool isKeyword(const LangOptions &LangOpts) const; - /// Return true if this token is a C++ keyword in the specified - /// language. + /// Return true if this identifier uses a keyword token and is a C++ keyword + /// in the specified language. bool isCPlusPlusKeyword(const LangOptions &LangOpts) const; + /// Returns true if the name of this identifier matches a keyword given the + /// specified language options. + bool isNameKeyword(const LangOptions &LangOpts) const; + /// Get and set FETokenInfo. The language front-end is allowed to associate /// arbitrary metadata with this token. void *getFETokenInfo() const { return FETokenInfo; } diff --git a/clang/lib/Basic/IdentifierTable.cpp b/clang/lib/Basic/IdentifierTable.cpp index 16151c94464f9..412f0af40861a 100644 --- a/clang/lib/Basic/IdentifierTable.cpp +++ b/clang/lib/Basic/IdentifierTable.cpp @@ -343,6 +343,14 @@ static KeywordStatus getTokenKwStatus(const LangOptions &LangOpts, } } +static KeywordStatus getNameKwStatus(const LangOptions &LangOpts, + StringRef Name)
[clang] [C] Diagnose use of C++ keywords in C (PR #137234)
AaronBallman wrote: After talking with Erich offline, I've updated the implementation to use a binary_search. The pointers are being cast to `uintptr_t` so that the `llvm::sort()` isn't operating on unrelated pointers. https://github.com/llvm/llvm-project/pull/137234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Implement lowering for LinkageSpecDecl (PR #137634)
https://github.com/AmrDeveloper approved this pull request. https://github.com/llvm/llvm-project/pull/137634 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Upstream global initialization for VectorType (PR #137511)
@@ -373,8 +373,27 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const APValue &value, elements, typedFiller); } case APValue::Vector: { -cgm.errorNYI("ConstExprEmitter::tryEmitPrivate vector"); -return {}; +const QualType elementType = +destType->castAs()->getElementType(); +const unsigned numElements = value.getVectorLength(); + +SmallVector elements; +elements.reserve(numElements); + +for (unsigned i = 0; i < numElements; ++i) { + const mlir::Attribute element = + tryEmitPrivateForMemory(value.getVectorElt(i), elementType); + if (!element) +return {}; AmrDeveloper wrote: As far as I understood, yes the destructor will be called when we early return and will clean the vector https://github.com/llvm/llvm-project/pull/137511 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [CIR] Upstream global initialization for VectorType (PR #137511)
https://github.com/AmrDeveloper updated https://github.com/llvm/llvm-project/pull/137511 >From 153f0c0daa33b1c71ced4a0f050d49656e72f505 Mon Sep 17 00:00:00 2001 From: AmrDeveloper Date: Sat, 26 Apr 2025 18:43:00 +0200 Subject: [PATCH 1/2] [CIR] Upstream global initialization for VectorType --- .../include/clang/CIR/Dialect/IR/CIRAttrs.td | 33 ++- clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp | 23 - clang/lib/CIR/Dialect/IR/CIRAttrs.cpp | 88 +++ clang/lib/CIR/Dialect/IR/CIRDialect.cpp | 2 +- .../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 40 +++-- clang/test/CIR/CodeGen/vector-ext.cpp | 11 ++- clang/test/CIR/CodeGen/vector.cpp | 9 ++ 7 files changed, 196 insertions(+), 10 deletions(-) diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td index fb3f7b1632436..624a82762ab18 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td +++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td @@ -204,7 +204,7 @@ def ConstArrayAttr : CIR_Attr<"ConstArray", "const_array", [TypedAttrInterface]> }]> ]; - // Printing and parsing available in CIRDialect.cpp + // Printing and parsing available in CIRAttrs.cpp let hasCustomAssemblyFormat = 1; // Enable verifier. @@ -215,6 +215,37 @@ def ConstArrayAttr : CIR_Attr<"ConstArray", "const_array", [TypedAttrInterface]> }]; } +//===--===// +// ConstVectorAttr +//===--===// + +def ConstVectorAttr : CIR_Attr<"ConstVector", "const_vector", + [TypedAttrInterface]> { + let summary = "A constant vector from ArrayAttr"; + let description = [{ +A CIR vector attribute is an array of literals of the specified attribute +types. + }]; + + let parameters = (ins AttributeSelfTypeParameter<"">:$type, + "mlir::ArrayAttr":$elts); + + // Define a custom builder for the type; that removes the need to pass in an + // MLIRContext instance, as it can be inferred from the `type`. + let builders = [ +AttrBuilderWithInferredContext<(ins "cir::VectorType":$type, + "mlir::ArrayAttr":$elts), [{ + return $_get(type.getContext(), type, elts); +}]> + ]; + + // Printing and parsing available in CIRAttrs.cpp + let hasCustomAssemblyFormat = 1; + + // Enable verifier. + let genVerifyDecl = 1; +} + //===--===// // ConstPtrAttr //===--===// diff --git a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp index b9a74e90a5960..6e5c7b8fb51f8 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp @@ -373,8 +373,27 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const APValue &value, elements, typedFiller); } case APValue::Vector: { -cgm.errorNYI("ConstExprEmitter::tryEmitPrivate vector"); -return {}; +const QualType elementType = +destType->castAs()->getElementType(); +const unsigned numElements = value.getVectorLength(); + +SmallVector elements; +elements.reserve(numElements); + +for (unsigned i = 0; i < numElements; ++i) { + const mlir::Attribute element = + tryEmitPrivateForMemory(value.getVectorElt(i), elementType); + if (!element) +return {}; + elements.push_back(element); +} + +const auto desiredVecTy = +mlir::cast(cgm.convertType(destType)); + +return cir::ConstVectorAttr::get( +desiredVecTy, +mlir::ArrayAttr::get(cgm.getBuilder().getContext(), elements)); } case APValue::MemberPointer: { cgm.errorNYI("ConstExprEmitter::tryEmitPrivate member pointer"); diff --git a/clang/lib/CIR/Dialect/IR/CIRAttrs.cpp b/clang/lib/CIR/Dialect/IR/CIRAttrs.cpp index a8d9f6a0e6e9b..b9b27f33207b8 100644 --- a/clang/lib/CIR/Dialect/IR/CIRAttrs.cpp +++ b/clang/lib/CIR/Dialect/IR/CIRAttrs.cpp @@ -299,6 +299,94 @@ void ConstArrayAttr::print(AsmPrinter &printer) const { printer << ">"; } +//===--===// +// CIR ConstVectorAttr +//===--===// + +LogicalResult cir::ConstVectorAttr::verify( +function_ref<::mlir::InFlightDiagnostic()> emitError, Type type, +ArrayAttr elts) { + + if (!mlir::isa(type)) { +return emitError() << "type of cir::ConstVectorAttr is not a " + "cir::VectorType: " + << type; + } + + const auto vecType = mlir::cast(type); + + if (vecType.getSize() != elts.size()) { +return emitError() + << "number of constant elem
[clang] [CIR][NFC] Fix an unused variable warning (PR #137466)
https://github.com/AmrDeveloper closed https://github.com/llvm/llvm-project/pull/137466 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] e44f776 - [CIR][NFC] Fix an unused variable warning (#137466)
Author: Amr Hesham Date: 2025-04-28T19:06:20+02:00 New Revision: e44f7760fa6f9f2d70831a6e9bf9f8472d285f4d URL: https://github.com/llvm/llvm-project/commit/e44f7760fa6f9f2d70831a6e9bf9f8472d285f4d DIFF: https://github.com/llvm/llvm-project/commit/e44f7760fa6f9f2d70831a6e9bf9f8472d285f4d.diff LOG: [CIR][NFC] Fix an unused variable warning (#137466) This fixes a warning where a variable assigned in 'if' statement wasn't referenced again. Added: Modified: clang/lib/CIR/CodeGen/CIRGenExpr.cpp clang/lib/CIR/CodeGen/CIRGenModule.cpp Removed: diff --git a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp index 0a518c0fd935d..ff14798b9d34c 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp @@ -311,7 +311,7 @@ LValue CIRGenFunction::emitLValueForField(LValue base, const FieldDecl *field) { assert(!cir::MissingFeatures::opTBAA()); Address addr = base.getAddress(); - if (auto *classDef = dyn_cast(rec)) { + if (isa(rec)) { cgm.errorNYI(field->getSourceRange(), "emitLValueForField: C++ class"); return LValue(); } @@ -701,7 +701,7 @@ CIRGenFunction::emitArraySubscriptExpr(const clang::ArraySubscriptExpr *e) { } LValue CIRGenFunction::emitMemberExpr(const MemberExpr *e) { - if (auto *vd = dyn_cast(e->getMemberDecl())) { + if (isa(e->getMemberDecl())) { cgm.errorNYI(e->getSourceRange(), "emitMemberExpr: VarDecl"); return LValue(); } @@ -734,7 +734,7 @@ LValue CIRGenFunction::emitMemberExpr(const MemberExpr *e) { return lv; } - if (const auto *fd = dyn_cast(nd)) { + if (isa(nd)) { cgm.errorNYI(e->getSourceRange(), "emitMemberExpr: FunctionDecl"); return LValue(); } diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp index 8aa57d1dbf9b3..b9cc2da583009 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp @@ -366,7 +366,7 @@ void CIRGenModule::emitGlobalVarDefinition(const clang::VarDecl *vd, bool isTentative) { const QualType astTy = vd->getType(); const mlir::Type type = convertType(vd->getType()); - if (clang::IdentifierInfo *identifier = vd->getIdentifier()) { + if (vd->getIdentifier()) { StringRef name = getMangledName(GlobalDecl(vd)); auto varOp = builder.create(getLoc(vd->getSourceRange()), name, type); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [PowerPC] frontend get target feature from backend with cpu name (PR #137670)
https://github.com/diggerlin created https://github.com/llvm/llvm-project/pull/137670 1. The PR proceeds with a backend target hook to allow front-ends to determine what features are available in a compilation based on the CPU name. 2. Fix a backend target feature bug that supports HTM for Power8/9/10/11. However, HTM is only supported on Power8/9 according to the ISA. 3. All target features that are hardcoded in PPC.cpp can be retrieved from the backend target feature. I have double-checked that the hardcoded logic for inferring target features from the CPU in the frontend(PPC.cpp) is the same as in PPC.td. >From 97f10e6a0fb4c158359e79e24650f8fdf4d23ef2 Mon Sep 17 00:00:00 2001 From: zhijian Date: Fri, 25 Apr 2025 13:09:47 + Subject: [PATCH] implement getting target features from backend for clang frontend --- clang/lib/Basic/Targets/PPC.cpp | 150 +- .../cxx11-thread-local-reference.cpp | 2 +- .../Driver/aix-shared-lib-tls-model-opt.c | 7 +- .../Driver/aix-small-local-exec-dynamic-tls.c | 15 +- clang/test/Driver/ppc-crbits.cpp | 4 - clang/test/Driver/ppc-isa-features.cpp| 22 +-- llvm/include/llvm/MC/MCSubtargetInfo.h| 32 +++- .../llvm/TargetParser/PPCTargetParser.h | 5 + llvm/lib/MC/MCSubtargetInfo.cpp | 32 +++- llvm/lib/Target/PowerPC/PPC.td| 4 +- llvm/lib/TargetParser/CMakeLists.txt | 8 + llvm/lib/TargetParser/PPCTargetParser.cpp | 26 +++ llvm/utils/TableGen/SubtargetEmitter.cpp | 52 -- 13 files changed, 159 insertions(+), 200 deletions(-) diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp index 425ad68bb9098..2a1024be1d537 100644 --- a/clang/lib/Basic/Targets/PPC.cpp +++ b/clang/lib/Basic/Targets/PPC.cpp @@ -15,6 +15,7 @@ #include "clang/Basic/MacroBuilder.h" #include "clang/Basic/TargetBuiltins.h" #include "llvm/TargetParser/PPCTargetParser.h" +#include using namespace clang; using namespace clang::targets; @@ -516,130 +517,15 @@ static bool ppcUserFeaturesCheck(DiagnosticsEngine &Diags, bool PPCTargetInfo::initFeatureMap( llvm::StringMap &Features, DiagnosticsEngine &Diags, StringRef CPU, const std::vector &FeaturesVec) const { - Features["altivec"] = llvm::StringSwitch(CPU) -.Case("7400", true) -.Case("g4", true) -.Case("7450", true) -.Case("g4+", true) -.Case("970", true) -.Case("g5", true) -.Case("pwr6", true) -.Case("pwr7", true) -.Case("pwr8", true) -.Case("pwr9", true) -.Case("ppc64", true) -.Case("ppc64le", true) -.Default(false); - - Features["power9-vector"] = (CPU == "pwr9"); - Features["crypto"] = llvm::StringSwitch(CPU) - .Case("ppc64le", true) - .Case("pwr9", true) - .Case("pwr8", true) - .Default(false); - Features["power8-vector"] = llvm::StringSwitch(CPU) - .Case("ppc64le", true) - .Case("pwr9", true) - .Case("pwr8", true) - .Default(false); - Features["bpermd"] = llvm::StringSwitch(CPU) - .Case("ppc64le", true) - .Case("pwr9", true) - .Case("pwr8", true) - .Case("pwr7", true) - .Default(false); - Features["extdiv"] = llvm::StringSwitch(CPU) - .Case("ppc64le", true) - .Case("pwr9", true) - .Case("pwr8", true) - .Case("pwr7", true) - .Default(false); - Features["direct-move"] = llvm::StringSwitch(CPU) -.Case("ppc64le", true) -.Case("pwr9", true) -.Case("pwr8", true) -.Default(false); - Features["crbits"] = llvm::StringSwitch(CPU) -.Case("ppc64le", true) -.Case("pwr9", true) -.Case("pwr8", true) -.Default(false); - Features["vsx"] = llvm::StringSwitch(CPU) -.Case("ppc64le", true) -.Case("pwr9", true) -.Case("pwr8", true) -.Case("pwr7", true) -.Default(false); - Features["htm"] = llvm::StringSwitch(CPU) -.Case("ppc64le"
[clang] [llvm] [PowerPC] frontend get target feature from backend with cpu name (PR #137670)
llvmbot wrote: @llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-driver Author: zhijian lin (diggerlin) Changes 1. The PR proceeds with a backend target hook to allow front-ends to determine what features are available in a compilation based on the CPU name. 2. Fix a backend target feature bug that supports HTM for Power8/9/10/11. However, HTM is only supported on Power8/9 according to the ISA. 3. All target features that are hardcoded in PPC.cpp can be retrieved from the backend target feature. I have double-checked that the hardcoded logic for inferring target features from the CPU in the frontend(PPC.cpp) is the same as in PPC.td. --- Patch is 28.84 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/137670.diff 13 Files Affected: - (modified) clang/lib/Basic/Targets/PPC.cpp (+8-142) - (modified) clang/test/CodeGenCXX/cxx11-thread-local-reference.cpp (+1-1) - (modified) clang/test/Driver/aix-shared-lib-tls-model-opt.c (+3-4) - (modified) clang/test/Driver/aix-small-local-exec-dynamic-tls.c (+7-8) - (modified) clang/test/Driver/ppc-crbits.cpp (-4) - (modified) clang/test/Driver/ppc-isa-features.cpp (+11-11) - (modified) llvm/include/llvm/MC/MCSubtargetInfo.h (+25-7) - (modified) llvm/include/llvm/TargetParser/PPCTargetParser.h (+5) - (modified) llvm/lib/MC/MCSubtargetInfo.cpp (+28-4) - (modified) llvm/lib/Target/PowerPC/PPC.td (+2-2) - (modified) llvm/lib/TargetParser/CMakeLists.txt (+8) - (modified) llvm/lib/TargetParser/PPCTargetParser.cpp (+26) - (modified) llvm/utils/TableGen/SubtargetEmitter.cpp (+35-17) ``diff diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp index 425ad68bb9098..2a1024be1d537 100644 --- a/clang/lib/Basic/Targets/PPC.cpp +++ b/clang/lib/Basic/Targets/PPC.cpp @@ -15,6 +15,7 @@ #include "clang/Basic/MacroBuilder.h" #include "clang/Basic/TargetBuiltins.h" #include "llvm/TargetParser/PPCTargetParser.h" +#include using namespace clang; using namespace clang::targets; @@ -516,130 +517,15 @@ static bool ppcUserFeaturesCheck(DiagnosticsEngine &Diags, bool PPCTargetInfo::initFeatureMap( llvm::StringMap &Features, DiagnosticsEngine &Diags, StringRef CPU, const std::vector &FeaturesVec) const { - Features["altivec"] = llvm::StringSwitch(CPU) -.Case("7400", true) -.Case("g4", true) -.Case("7450", true) -.Case("g4+", true) -.Case("970", true) -.Case("g5", true) -.Case("pwr6", true) -.Case("pwr7", true) -.Case("pwr8", true) -.Case("pwr9", true) -.Case("ppc64", true) -.Case("ppc64le", true) -.Default(false); - - Features["power9-vector"] = (CPU == "pwr9"); - Features["crypto"] = llvm::StringSwitch(CPU) - .Case("ppc64le", true) - .Case("pwr9", true) - .Case("pwr8", true) - .Default(false); - Features["power8-vector"] = llvm::StringSwitch(CPU) - .Case("ppc64le", true) - .Case("pwr9", true) - .Case("pwr8", true) - .Default(false); - Features["bpermd"] = llvm::StringSwitch(CPU) - .Case("ppc64le", true) - .Case("pwr9", true) - .Case("pwr8", true) - .Case("pwr7", true) - .Default(false); - Features["extdiv"] = llvm::StringSwitch(CPU) - .Case("ppc64le", true) - .Case("pwr9", true) - .Case("pwr8", true) - .Case("pwr7", true) - .Default(false); - Features["direct-move"] = llvm::StringSwitch(CPU) -.Case("ppc64le", true) -.Case("pwr9", true) -.Case("pwr8", true) -.Default(false); - Features["crbits"] = llvm::StringSwitch(CPU) -.Case("ppc64le", true) -.Case("pwr9", true) -.Case("pwr8", true) -.Default(false); - Features["vsx"] = llvm::StringSwitch(CPU) -.Case("ppc64le", true) -.Case("pwr9", true) -.Case("pwr8", true) -.Case("pwr7", true) -.Default(false); - Features["htm"] = llvm::StringSwitch(CPU) -.Case("ppc64le", true) -
[clang] [llvm] [PowerPC] frontend get target feature from backend with cpu name (PR #137670)
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 HEAD~1 HEAD --extensions c,h,cpp -- clang/lib/Basic/Targets/PPC.cpp clang/test/CodeGenCXX/cxx11-thread-local-reference.cpp clang/test/Driver/aix-shared-lib-tls-model-opt.c clang/test/Driver/aix-small-local-exec-dynamic-tls.c clang/test/Driver/ppc-crbits.cpp clang/test/Driver/ppc-isa-features.cpp llvm/include/llvm/MC/MCSubtargetInfo.h llvm/include/llvm/TargetParser/PPCTargetParser.h llvm/lib/MC/MCSubtargetInfo.cpp llvm/lib/TargetParser/PPCTargetParser.cpp llvm/utils/TableGen/SubtargetEmitter.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp index 2a1024be1..b6ff8e11c 100644 --- a/clang/lib/Basic/Targets/PPC.cpp +++ b/clang/lib/Basic/Targets/PPC.cpp @@ -524,8 +524,8 @@ bool PPCTargetInfo::initFeatureMap( llvm::PPC::getPPCDefaultTargetFeatures(TheTriple, llvm::PPC::normalizeCPUName(CPU)); if (FeaturesOpt.has_value()) - Features = FeaturesOpt.value(); - +Features = FeaturesOpt.value(); + if (!ppcUserFeaturesCheck(Diags, FeaturesVec)) return false; diff --git a/llvm/include/llvm/MC/MCSubtargetInfo.h b/llvm/include/llvm/MC/MCSubtargetInfo.h index 287aaf591..87028271e 100644 --- a/llvm/include/llvm/MC/MCSubtargetInfo.h +++ b/llvm/include/llvm/MC/MCSubtargetInfo.h @@ -48,12 +48,12 @@ struct BasicSubtargetFeatureKV { return StringRef(Key) < StringRef(Other.Key); } BasicSubtargetFeatureKV(const char *Key, unsigned Value, - FeatureBitArray Implies) + FeatureBitArray Implies) : Key(Key), Value(Value), Implies(Implies) {} }; struct SubtargetFeatureKV : BasicSubtargetFeatureKV { - const char *Desc;///< Help descriptor + const char *Desc; ///< Help descriptor SubtargetFeatureKV(const char *Key, const char *Desc, unsigned Value, FeatureBitArray Implies) : BasicSubtargetFeatureKV(Key, Value, Implies), Desc(Desc) {} @@ -78,7 +78,7 @@ struct BasicSubtargetSubTypeKV { }; struct SubtargetSubTypeKV : BasicSubtargetSubTypeKV { - FeatureBitArray TuneImplies;///< K-V bit mask + FeatureBitArray TuneImplies; ///< K-V bit mask const MCSchedModel *SchedModel; }; diff --git a/llvm/utils/TableGen/SubtargetEmitter.cpp b/llvm/utils/TableGen/SubtargetEmitter.cpp index be1409f65..4498a75d9 100644 --- a/llvm/utils/TableGen/SubtargetEmitter.cpp +++ b/llvm/utils/TableGen/SubtargetEmitter.cpp @@ -274,8 +274,9 @@ unsigned SubtargetEmitter::featureKeyValues(raw_ostream &OS, // Begin feature table. OS << "// Sorted (by key) array of values for CPU features.\n" - << "extern const llvm::" << (IsEmitBasic ? "Basic" : "") << "SubtargetFeatureKV " - << (IsEmitBasic ? "Basic" : "") << Target << "FeatureKV[] = {\n"; + << "extern const llvm::" << (IsEmitBasic ? "Basic" : "") + << "SubtargetFeatureKV " << (IsEmitBasic ? "Basic" : "") << Target + << "FeatureKV[] = {\n"; for (const Record *Feature : FeatureList) { // Next feature @@ -357,8 +358,9 @@ unsigned SubtargetEmitter::cpuKeyValues(raw_ostream &OS, // Begin processor table. OS << "// Sorted (by key) array of values for CPU subtype.\n" - << "extern const llvm::" << (IsEmitBasic ? "Basic" : "") << "SubtargetSubTypeKV " - << (IsEmitBasic ? "Basic" : "") << Target << "SubTypeKV[] = {\n"; + << "extern const llvm::" << (IsEmitBasic ? "Basic" : "") + << "SubtargetSubTypeKV " << (IsEmitBasic ? "Basic" : "") << Target + << "SubTypeKV[] = {\n"; for (const Record *Processor : ProcessorList) { StringRef Name = Processor->getValueAsString("Name"); `` https://github.com/llvm/llvm-project/pull/137670 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Merge gtest binaries into AllClangUnitTests (PR #134196)
https://github.com/rnk updated https://github.com/llvm/llvm-project/pull/134196 >From 528be44ebae8ea5cd7f23c51ad11c314a73f152b Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Fri, 28 Mar 2025 22:11:05 -0700 Subject: [PATCH 1/8] [clang] Merge gtest binaries into AllClangUnitTests This reduces the size of the clang/unittests build directory by 64% and my overall build dir size by 5%. Static linking is the real driving factor here, but even if the default build configuration used shared libraries, I don't see why we should be building so many unit test binaries. To make the project more approachable for new contributors, I'm attempting to make the build a bit less resource-intensive. Build directory size is a common complaint, and this is low-hanging fruit. --- clang/unittests/CMakeLists.txt| 53 ++- clang/unittests/Driver/ModuleCacheTest.cpp| 2 +- clang/unittests/Interpreter/CMakeLists.txt| 2 +- .../Interpreter/ExceptionTests/CMakeLists.txt | 2 +- 4 files changed, 54 insertions(+), 5 deletions(-) diff --git a/clang/unittests/CMakeLists.txt b/clang/unittests/CMakeLists.txt index f3823ba309420..8d4476761e03e 100644 --- a/clang/unittests/CMakeLists.txt +++ b/clang/unittests/CMakeLists.txt @@ -15,11 +15,11 @@ if(CLANG_BUILT_STANDALONE) endif() endif() -# add_clang_unittest(test_name file1.cpp file2.cpp) +# add_distinct_clang_unittest(test_name file1.cpp file2.cpp) # # Will compile the list of files together and link against the clang # Produces a binary named 'basename(test_name)'. -function(add_clang_unittest test_name) +function(add_distinct_clang_unittest test_name) cmake_parse_arguments(ARG "" "" @@ -47,6 +47,33 @@ function(add_clang_unittest test_name) target_link_libraries(${test_name} PRIVATE ${ARG_LINK_LIBS}) endfunction() +define_property(GLOBAL PROPERTY CLANG_UNITTEST_SRCS) +define_property(GLOBAL PROPERTY CLANG_UNITTEST_LLVM_COMPONENTS) +define_property(GLOBAL PROPERTY CLANG_UNITTEST_CLANG_LIBS) +define_property(GLOBAL PROPERTY CLANG_UNITTEST_LINK_LIBS) + +# add_clang_unittest(test_name file1.cpp file2.cpp) +# +# Adds unittests to the combined AllClangUnitTests binary. The unittest binary +# is defined after adding all unittest subdirectories. +function(add_clang_unittest test_name) + cmake_parse_arguments(ARG +"" +"" +"CLANG_LIBS;LINK_LIBS;LLVM_COMPONENTS" +${ARGN}) + + file(RELATIVE_PATH src_prefix "${CMAKE_CURRENT_FUNCTION_LIST_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}") + set(srcs_prefixed) + foreach(src ${ARG_UNPARSED_ARGUMENTS}) +set(srcs_prefixed ${srcs_prefixed} "${src_prefix}/${src}") + endforeach() + set_property(GLOBAL APPEND PROPERTY CLANG_UNITTEST_SRCS ${srcs_prefixed}) + set_property(GLOBAL APPEND PROPERTY CLANG_UNITTEST_CLANG_LIBS ${ARG_CLANG_LIBS}) + set_property(GLOBAL APPEND PROPERTY CLANG_UNITTEST_LINK_LIBS ${ARG_LINK_LIBS}) + set_property(GLOBAL APPEND PROPERTY CLANG_UNITTEST_LLVM_COMPONENTS ${ARG_LLVM_COMPONENTS}) +endfunction() + add_subdirectory(Basic) add_subdirectory(Lex) add_subdirectory(Parse) @@ -77,3 +104,25 @@ add_subdirectory(Index) add_subdirectory(InstallAPI) add_subdirectory(Serialization) add_subdirectory(Support) + + +# If we're doing a single merged clang unit test binary, add that target after +# all the previous subdirectories have been processed. +get_property(SRCS GLOBAL PROPERTY CLANG_UNITTEST_SRCS) +get_property(CLANG_LIBS GLOBAL PROPERTY CLANG_UNITTEST_CLANG_LIBS) +get_property(LINK_LIBS GLOBAL PROPERTY CLANG_UNITTEST_LINK_LIBS) +get_property(LLVM_COMPONENTS GLOBAL PROPERTY CLANG_UNITTEST_LLVM_COMPONENTS) +add_distinct_clang_unittest(AllClangUnitTests + ${SRCS} + CLANG_LIBS + ${CLANG_LIBS} + LINK_LIBS + ${LINK_LIBS} + LLVM_COMPONENTS + ${LLVM_COMPONENTS} +) + +# The Tooling library has some internal headers. Make those work. If we like +# the merged clang unit test binary, we can udpate the include paths and make +# this the default. +include_directories(Tooling) diff --git a/clang/unittests/Driver/ModuleCacheTest.cpp b/clang/unittests/Driver/ModuleCacheTest.cpp index 48744415647e6..7aa5047c59bd3 100644 --- a/clang/unittests/Driver/ModuleCacheTest.cpp +++ b/clang/unittests/Driver/ModuleCacheTest.cpp @@ -17,7 +17,7 @@ using namespace clang::driver; namespace { -TEST(ModuleCacheTest, GetTargetAndMode) { +TEST(DriverModuleCacheTest, GetTargetAndMode) { SmallString<128> Buf; Driver::getDefaultModuleCachePath(Buf); StringRef Path = Buf; diff --git a/clang/unittests/Interpreter/CMakeLists.txt b/clang/unittests/Interpreter/CMakeLists.txt index 9df1a4b03da47..1dda9024075a1 100644 --- a/clang/unittests/Interpreter/CMakeLists.txt +++ b/clang/unittests/Interpreter/CMakeLists.txt @@ -1,4 +1,4 @@ -add_clang_unittest(ClangReplInterpreterTests +add_distinct_clang_unittest(ClangReplInterpreterTests IncrementalCompilerBuilderTest.cpp IncrementalProcessingTest.cpp InterpreterTest.cpp diff --git a/clang/unittests/Interpreter/Except
[clang] [llvm] [ARM] Adding diagnostics for mcmodel=tiny when used in invalid targets (PR #125643)
@@ -1755,6 +1755,18 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) { << TC.getTriple().str(); } + // Throw diagnosis if mcmodel=tiny option is passed for targets other than ARM + // or AArch64. + if (Arg *A = UArgs->getLastArg(options::OPT_mcmodel_EQ)) { ShashwathiNavada wrote: @MaskRay Thank you for your response! I noticed that in the function you mentioned, there’s a check like this: ``` else if (Triple.getArch() == llvm::Triple::x86_64) { Ok = llvm::is_contained({"small", "kernel", "medium", "large", "tiny"}, CM); } ``` I found that removing the tiny option here gives the desired result. Would you mind confirming if this approach looks good before I push the changes? https://github.com/llvm/llvm-project/pull/125643 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [mlir] [AMDGPU] Add a new amdgcn.load.to.lds intrinsic (PR #137425)
krzysz00 wrote: @jayfoad I still think we need an intrinsic here because a load + an addtid store can be scheduled much different from the asynchronous "gather to LDS" - and because we don't want this load/store to not be optimized https://github.com/llvm/llvm-project/pull/137425 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] c52fdbe - [clang][bytecode] Fix ia32_addcarry/subborrow (#137642)
Author: Timm Baeder Date: 2025-04-28T17:44:19+02:00 New Revision: c52fdbe697eb0eee2484c5bf1aeb17d678430830 URL: https://github.com/llvm/llvm-project/commit/c52fdbe697eb0eee2484c5bf1aeb17d678430830 DIFF: https://github.com/llvm/llvm-project/commit/c52fdbe697eb0eee2484c5bf1aeb17d678430830.diff LOG: [clang][bytecode] Fix ia32_addcarry/subborrow (#137642) RHS is followed by another Pointer. Added: Modified: clang/lib/AST/ByteCode/InterpBuiltin.cpp Removed: diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp index 34baae1986c35..e3d76326db44b 100644 --- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp +++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp @@ -1413,6 +1413,7 @@ static bool interp__builtin_ia32_pext(InterpState &S, CodePtr OpPC, return true; } +/// (CarryIn, LHS, RHS, Result) static bool interp__builtin_ia32_addcarry_subborrow(InterpState &S, CodePtr OpPC, const InterpFrame *Frame, @@ -1423,16 +1424,17 @@ static bool interp__builtin_ia32_addcarry_subborrow(InterpState &S, !Call->getArg(2)->getType()->isIntegerType()) return false; - APSInt CarryIn = peekToAPSInt( - S.Stk, *S.getContext().classify(Call->getArg(0)), - align(primSize(*S.getContext().classify(Call->getArg(2 + - align(primSize(*S.getContext().classify(Call->getArg(1 + - align(primSize(*S.getContext().classify(Call->getArg(0); + PrimType CarryInT = *S.getContext().classify(Call->getArg(0)); + PrimType LHST = *S.getContext().classify(Call->getArg(1)); + PrimType RHST = *S.getContext().classify(Call->getArg(2)); + unsigned PtrSize = align(primSize(PT_Ptr)); + APSInt CarryIn = + peekToAPSInt(S.Stk, CarryInT, + PtrSize + align(primSize(RHST)) + align(primSize(LHST)) + + align(primSize(CarryInT))); APSInt LHS = peekToAPSInt( - S.Stk, *S.getContext().classify(Call->getArg(1)), - align(primSize(*S.getContext().classify(Call->getArg(2 + - align(primSize(*S.getContext().classify(Call->getArg(1); - APSInt RHS = peekToAPSInt(S.Stk, *S.getContext().classify(Call->getArg(2))); + S.Stk, LHST, PtrSize + align(primSize(RHST)) + align(primSize(LHST))); + APSInt RHS = peekToAPSInt(S.Stk, RHST, PtrSize + align(primSize(RHST))); bool IsAdd = BuiltinOp == clang::X86::BI__builtin_ia32_addcarryx_u32 || BuiltinOp == clang::X86::BI__builtin_ia32_addcarryx_u64; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][bytecode] Fix ia32_addcarry/subborrow (PR #137642)
https://github.com/tbaederr closed https://github.com/llvm/llvm-project/pull/137642 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C] Diagnose use of C++ keywords in C (PR #137234)
@@ -10416,6 +10447,15 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, // Finally, we know we have the right number of parameters, install them. NewFD->setParams(Params); + // If this declarator is a declaration and not a definition, its parameters + // will not be pushed onto a scope chain. That means we will not issue any + // reserved identifier warnings for the declaration, but we will for the + // definition. Handle those here. + if (!Params.empty() && !D.isFunctionDefinition()) { AaronBallman wrote: They're tested: ``` // Smoke test that we catch keyword use in function parameters too. void func(int private); // expected-warning {{identifier 'private' conflicts with a C++ keyword}} \ cxx-error {{invalid parameter name: 'private' is a keyword}} ``` around line 192 https://github.com/llvm/llvm-project/pull/137234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C] Add new -Wimplicit-int-enum-cast to -Wc++-compat (PR #137658)
https://github.com/erichkeane approved this pull request. https://github.com/llvm/llvm-project/pull/137658 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Remove FEM_Indeterminable (PR #137661)
https://github.com/ojhunt created https://github.com/llvm/llvm-project/pull/137661 Remove FEM_Indeterminable as it is unused and cannot be stored safely in an unsigned bitfield >From a33b76cb769b8669922101c9cb7b9fbb28cbb1fe Mon Sep 17 00:00:00 2001 From: Oliver Hunt Date: Thu, 24 Apr 2025 13:30:40 -0700 Subject: [PATCH] [clang] Remove FEM_Indeterminable Remove FEM_Indeterminable as it is unused and cannot be stored safely in an unsigned bitfield --- clang/include/clang/Basic/FPOptions.def | 2 +- clang/include/clang/Basic/LangOptions.def | 2 +- clang/include/clang/Basic/LangOptions.h | 5 + 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/clang/include/clang/Basic/FPOptions.def b/clang/include/clang/Basic/FPOptions.def index 85986b4ff0b9c..90428c3c73c8b 100644 --- a/clang/include/clang/Basic/FPOptions.def +++ b/clang/include/clang/Basic/FPOptions.def @@ -24,7 +24,7 @@ OPTION(NoHonorInfs, bool, 1, NoHonorNaNs) OPTION(NoSignedZero, bool, 1, NoHonorInfs) OPTION(AllowReciprocal, bool, 1, NoSignedZero) OPTION(AllowApproxFunc, bool, 1, AllowReciprocal) -OPTION(FPEvalMethod, LangOptions::FPEvalMethodKind, 3, AllowApproxFunc) +OPTION(FPEvalMethod, LangOptions::FPEvalMethodKind, 2, AllowApproxFunc) OPTION(Float16ExcessPrecision, LangOptions::ExcessPrecisionKind, 2, FPEvalMethod) OPTION(BFloat16ExcessPrecision, LangOptions::ExcessPrecisionKind, 2, Float16ExcessPrecision) OPTION(MathErrno, bool, 1, BFloat16ExcessPrecision) diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index 85ca523c44157..930c1c06d1a76 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -347,7 +347,7 @@ BENIGN_ENUM_LANGOPT(DefaultFPContractMode, FPModeKind, 2, FPM_Off, "FP contracti COMPATIBLE_LANGOPT(ExpStrictFP, 1, false, "Enable experimental strict floating point") BENIGN_LANGOPT(RoundingMath, 1, false, "Do not assume default floating-point rounding behavior") BENIGN_ENUM_LANGOPT(FPExceptionMode, FPExceptionModeKind, 2, FPE_Default, "FP Exception Behavior Mode type") -BENIGN_ENUM_LANGOPT(FPEvalMethod, FPEvalMethodKind, 3, FEM_UnsetOnCommandLine, "FP type used for floating point arithmetic") +BENIGN_ENUM_LANGOPT(FPEvalMethod, FPEvalMethodKind, 2, FEM_UnsetOnCommandLine, "FP type used for floating point arithmetic") ENUM_LANGOPT(Float16ExcessPrecision, ExcessPrecisionKind, 2, FPP_Standard, "Intermediate truncation behavior for Float16 arithmetic") ENUM_LANGOPT(BFloat16ExcessPrecision, ExcessPrecisionKind, 2, FPP_Standard, "Intermediate truncation behavior for BFloat16 arithmetic") LANGOPT(NoBitFieldTypeAlign , 1, 0, "bit-field type alignment") diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h index bbebf7af9ede3..1bfc0d8e88556 100644 --- a/clang/include/clang/Basic/LangOptions.h +++ b/clang/include/clang/Basic/LangOptions.h @@ -304,10 +304,7 @@ class LangOptionsBase { }; /// Possible float expression evaluation method choices. - enum FPEvalMethodKind { -/// The evaluation method cannot be determined or is inconsistent for this -/// target. -FEM_Indeterminable = -1, + enum FPEvalMethodKind : unsigned { /// Use the declared type for fp arithmetic. FEM_Source = 0, /// Use the type double for fp arithmetic. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Remove FEM_Indeterminable (PR #137661)
ojhunt wrote: @Endilll this is the fix for the warning you're seeing https://github.com/llvm/llvm-project/pull/137661 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Remove FEM_Indeterminable (PR #137661)
ojhunt wrote: (Recreating after mismerge) https://github.com/llvm/llvm-project/pull/137661 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Remove FEM_Indeterminable (PR #137661)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Oliver Hunt (ojhunt) Changes Remove FEM_Indeterminable as it is unused and cannot be stored safely in an unsigned bitfield --- Full diff: https://github.com/llvm/llvm-project/pull/137661.diff 3 Files Affected: - (modified) clang/include/clang/Basic/FPOptions.def (+1-1) - (modified) clang/include/clang/Basic/LangOptions.def (+1-1) - (modified) clang/include/clang/Basic/LangOptions.h (+1-4) ``diff diff --git a/clang/include/clang/Basic/FPOptions.def b/clang/include/clang/Basic/FPOptions.def index 85986b4ff0b9c..90428c3c73c8b 100644 --- a/clang/include/clang/Basic/FPOptions.def +++ b/clang/include/clang/Basic/FPOptions.def @@ -24,7 +24,7 @@ OPTION(NoHonorInfs, bool, 1, NoHonorNaNs) OPTION(NoSignedZero, bool, 1, NoHonorInfs) OPTION(AllowReciprocal, bool, 1, NoSignedZero) OPTION(AllowApproxFunc, bool, 1, AllowReciprocal) -OPTION(FPEvalMethod, LangOptions::FPEvalMethodKind, 3, AllowApproxFunc) +OPTION(FPEvalMethod, LangOptions::FPEvalMethodKind, 2, AllowApproxFunc) OPTION(Float16ExcessPrecision, LangOptions::ExcessPrecisionKind, 2, FPEvalMethod) OPTION(BFloat16ExcessPrecision, LangOptions::ExcessPrecisionKind, 2, Float16ExcessPrecision) OPTION(MathErrno, bool, 1, BFloat16ExcessPrecision) diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index 85ca523c44157..930c1c06d1a76 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -347,7 +347,7 @@ BENIGN_ENUM_LANGOPT(DefaultFPContractMode, FPModeKind, 2, FPM_Off, "FP contracti COMPATIBLE_LANGOPT(ExpStrictFP, 1, false, "Enable experimental strict floating point") BENIGN_LANGOPT(RoundingMath, 1, false, "Do not assume default floating-point rounding behavior") BENIGN_ENUM_LANGOPT(FPExceptionMode, FPExceptionModeKind, 2, FPE_Default, "FP Exception Behavior Mode type") -BENIGN_ENUM_LANGOPT(FPEvalMethod, FPEvalMethodKind, 3, FEM_UnsetOnCommandLine, "FP type used for floating point arithmetic") +BENIGN_ENUM_LANGOPT(FPEvalMethod, FPEvalMethodKind, 2, FEM_UnsetOnCommandLine, "FP type used for floating point arithmetic") ENUM_LANGOPT(Float16ExcessPrecision, ExcessPrecisionKind, 2, FPP_Standard, "Intermediate truncation behavior for Float16 arithmetic") ENUM_LANGOPT(BFloat16ExcessPrecision, ExcessPrecisionKind, 2, FPP_Standard, "Intermediate truncation behavior for BFloat16 arithmetic") LANGOPT(NoBitFieldTypeAlign , 1, 0, "bit-field type alignment") diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h index bbebf7af9ede3..1bfc0d8e88556 100644 --- a/clang/include/clang/Basic/LangOptions.h +++ b/clang/include/clang/Basic/LangOptions.h @@ -304,10 +304,7 @@ class LangOptionsBase { }; /// Possible float expression evaluation method choices. - enum FPEvalMethodKind { -/// The evaluation method cannot be determined or is inconsistent for this -/// target. -FEM_Indeterminable = -1, + enum FPEvalMethodKind : unsigned { /// Use the declared type for fp arithmetic. FEM_Source = 0, /// Use the type double for fp arithmetic. `` https://github.com/llvm/llvm-project/pull/137661 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CompundLiteralExpr] Don't defer evaluation for CLEs (PR #137163)
https://github.com/kadircet updated https://github.com/llvm/llvm-project/pull/137163 From 99fa9a1f5fb74401c790871e6eb1ce473d048d74 Mon Sep 17 00:00:00 2001 From: Kadir Cetinkaya Date: Thu, 24 Apr 2025 11:12:00 +0200 Subject: [PATCH 1/3] [clang][CompundLiteralExpr] Don't defer evaluation for CLEs Previously we would defer evaluation of CLEs until LValue to RValue conversions, which would result in creating values within wrong scope and triggering use-after-frees. This patch instead eagerly evaluates CLEs, within the scope requiring them. This requires storing an extra pointer for CLE expressions with static storage. --- clang/include/clang/AST/Expr.h | 12 clang/lib/AST/Expr.cpp | 9 ++ clang/lib/AST/ExprConstant.cpp | 33 - clang/test/AST/static-compound-literals.cpp | 12 4 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 clang/test/AST/static-compound-literals.cpp diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h index a83320a7ddec2..ed56522d107dd 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -3489,6 +3489,11 @@ class CompoundLiteralExpr : public Expr { /// The int part of the pair stores whether this expr is file scope. llvm::PointerIntPair TInfoAndScope; Stmt *Init; + + /// Value of constant literals with static storage duration. Used only for + /// constant folding as CompoundLiteralExpr is not an ICE. + mutable APValue *StaticValue = nullptr; + public: CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo, QualType T, ExprValueKind VK, Expr *init, bool fileScope) @@ -3518,6 +3523,13 @@ class CompoundLiteralExpr : public Expr { TInfoAndScope.setPointer(tinfo); } + bool hasStaticStorage() const { return isFileScope() && isGLValue(); } + APValue *getOrCreateStaticValue(ASTContext &Ctx) const; + APValue &getStaticValue() const { +assert(StaticValue); +return *StaticValue; + } + SourceLocation getBeginLoc() const LLVM_READONLY { // FIXME: Init should never be null. if (!Init) diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 59c0e47c7c195..442e85b892a51 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -5467,3 +5467,12 @@ ConvertVectorExpr *ConvertVectorExpr::Create( return new (Mem) ConvertVectorExpr(SrcExpr, TI, DstType, VK, OK, BuiltinLoc, RParenLoc, FPFeatures); } + +APValue *CompoundLiteralExpr::getOrCreateStaticValue(ASTContext &Ctx) const { + assert(hasStaticStorage()); + if (!StaticValue) { +StaticValue = new (Ctx) APValue; +Ctx.addDestruction(StaticValue); + } + return StaticValue; +} diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 7c933f47bf7f0..2379e78c1631a 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -4596,10 +4596,6 @@ handleLValueToRValueConversion(EvalInfo &Info, const Expr *Conv, QualType Type, return false; } - APValue Lit; - if (!Evaluate(Lit, Info, CLE->getInitializer())) -return false; - // According to GCC info page: // // 6.28 Compound Literals @@ -4622,7 +4618,12 @@ handleLValueToRValueConversion(EvalInfo &Info, const Expr *Conv, QualType Type, } } - CompleteObject LitObj(LVal.Base, &Lit, Base->getType()); + APValue *Lit = + CLE->hasStaticStorage() + ? &CLE->getStaticValue() + : Info.CurrentCall->getTemporary(Base, LVal.Base.getVersion()); + + CompleteObject LitObj(LVal.Base, Lit, Base->getType()); return extractSubobject(Info, Conv, LitObj, LVal.Designator, RVal, AK); } else if (isa(Base) || isa(Base)) { // Special-case character extraction so we don't have to construct an @@ -9125,9 +9126,25 @@ bool LValueExprEvaluator::VisitCompoundLiteralExpr(const CompoundLiteralExpr *E) { assert((!Info.getLangOpts().CPlusPlus || E->isFileScope()) && "lvalue compound literal in c++?"); - // Defer visiting the literal until the lvalue-to-rvalue conversion. We can - // only see this when folding in C, so there's no standard to follow here. - return Success(E); + APValue *Lit; + // If CompountLiteral has static storage, its value can be used outside + // this expression. So evaluate it once and store it in ASTContext. + if (E->hasStaticStorage()) { +Lit = E->getOrCreateStaticValue(Info.Ctx); +Result.set(E); +// Reset any previously evaluated state, otherwise evaluation below might +// fail. +// FIXME: Should we just re-use the previously evaluated value instead? +*Lit = APValue(); + } else { +Lit = &Info.CurrentCall->createTemporary(E, E->getInitializer()->getType(), + ScopeKind::FullExpression, Result); + } + if (!EvaluateInPlace(*
[clang] [C] Diagnose use of C++ keywords in C (PR #137234)
@@ -6107,6 +6109,29 @@ static bool isFromSystemHeader(SourceManager &SM, const Decl *D) { SM.isInSystemMacro(D->getLocation()); } +static bool isKeywordInCPlusPlus(const Sema &S, const IdentifierInfo *II) { + if (!II) +return false; + + // Build a static map of identifiers for all of the keywords in C++ that are + // not keywords in C. This allows us to do pointer comparisons instead of + // string comparisons when deciding whether the given identifier is a keyword + // or not. Note, this treats all keywords as being enabled, regardless of the + // setting of other language options. It intentionally disables the modules + // keywords because those are conditional keywords, so may be safe to use. + static llvm::SmallPtrSet Keywords; + if (Keywords.empty()) { +#define MODULES_KEYWORD(NAME) +#define KEYWORD(NAME, FLAGS) \ + Keywords.insert(&S.getPreprocessor().getIdentifierTable().get(#NAME)); +#define CXX_KEYWORD_OPERATOR(NAME, TOK) \ + Keywords.insert(&S.getPreprocessor().getIdentifierTable().get(#NAME)); +#include "clang/Basic/TokenKinds.def" + } + + return Keywords.contains(II); AaronBallman wrote: I'd really rather not try to muck about with the layout of things in the identifier table, that's actually some pretty complicated logic because of "interesting identifiers" and Objective-C. I think the current perf is reasonable given that the checking only happens if the (off by default) diagnostic is enabled. WDYT? https://github.com/llvm/llvm-project/pull/137234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [lld] [llvm] [X86] Add pass to suppress EPGR/NDD instructions for relocations (PR #136660)
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 HEAD~1 HEAD --extensions cpp,h -- llvm/lib/Target/X86/X86SuppressAPXForReloc.cpp llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h llvm/lib/Target/X86/X86.h llvm/lib/Target/X86/X86InstrInfo.cpp llvm/lib/Target/X86/X86TargetMachine.cpp `` View the diff from clang-format here. ``diff diff --git a/llvm/lib/Target/X86/X86SuppressAPXForReloc.cpp b/llvm/lib/Target/X86/X86SuppressAPXForReloc.cpp index 903c6441b..28319beec 100644 --- a/llvm/lib/Target/X86/X86SuppressAPXForReloc.cpp +++ b/llvm/lib/Target/X86/X86SuppressAPXForReloc.cpp @@ -85,7 +85,7 @@ static bool handleInstructionWithEGPR(MachineFunction &MF, return false; auto suppressEGPRInInstrWithReloc = [&](MachineInstr &MI, -ArrayRef OpNoArray) { + ArrayRef OpNoArray) { int MemOpNo = X86II::getMemoryOperandNo(MI.getDesc().TSFlags) + X86II::getOperandBias(MI.getDesc()); auto &MO = MI.getOperand(X86::AddrDisp + MemOpNo); @@ -165,10 +165,9 @@ static bool handleNDDOrNFInstructions(MachineFunction &MF, LLVM_DEBUG(dbgs() << "Transform instruction with relocation type:\n " << MI); Register Reg = MRI->createVirtualRegister(&X86::GR64_NOREX2RegClass); - auto &CopyMI = - BuildMI(MBB, MI, MI.getDebugLoc(), TII->get(TargetOpcode::COPY), - Reg) - .addReg(MI.getOperand(1).getReg()); + auto &CopyMI = BuildMI(MBB, MI, MI.getDebugLoc(), + TII->get(TargetOpcode::COPY), Reg) + .addReg(MI.getOperand(1).getReg()); MI.getOperand(1).setReg(Reg); const MCInstrDesc &NewDesc = TII->get(X86::ADD64rm); MI.setDesc(NewDesc); @@ -187,10 +186,9 @@ static bool handleNDDOrNFInstructions(MachineFunction &MF, << MI); suppressEGPRRegClass(MF, MI, 0); Register Reg = MRI->createVirtualRegister(&X86::GR64_NOREX2RegClass); - auto &CopyMI = - BuildMI(MBB, MI, MI.getDebugLoc(), TII->get(TargetOpcode::COPY), - Reg) - .addReg(MI.getOperand(6).getReg()); + auto &CopyMI = BuildMI(MBB, MI, MI.getDebugLoc(), + TII->get(TargetOpcode::COPY), Reg) + .addReg(MI.getOperand(6).getReg()); auto &NewMI = BuildMI(MBB, MI, MI.getDebugLoc(), TII->get(X86::ADD64rm), MI.getOperand(0).getReg()) `` https://github.com/llvm/llvm-project/pull/136660 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C] Diagnose use of C++ keywords in C (PR #137234)
https://github.com/erichkeane approved this pull request. You can remove the `Params.empty` if you'd like, but this LGTM anyway. https://github.com/llvm/llvm-project/pull/137234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C] Diagnose use of C++ keywords in C (PR #137234)
@@ -6107,6 +6109,29 @@ static bool isFromSystemHeader(SourceManager &SM, const Decl *D) { SM.isInSystemMacro(D->getLocation()); } +static bool isKeywordInCPlusPlus(const Sema &S, const IdentifierInfo *II) { + if (!II) +return false; + + // Build a static map of identifiers for all of the keywords in C++ that are + // not keywords in C. This allows us to do pointer comparisons instead of + // string comparisons when deciding whether the given identifier is a keyword + // or not. Note, this treats all keywords as being enabled, regardless of the + // setting of other language options. It intentionally disables the modules + // keywords because those are conditional keywords, so may be safe to use. + static llvm::SmallPtrSet Keywords; + if (Keywords.empty()) { +#define MODULES_KEYWORD(NAME) +#define KEYWORD(NAME, FLAGS) \ + Keywords.insert(&S.getPreprocessor().getIdentifierTable().get(#NAME)); +#define CXX_KEYWORD_OPERATOR(NAME, TOK) \ + Keywords.insert(&S.getPreprocessor().getIdentifierTable().get(#NAME)); +#include "clang/Basic/TokenKinds.def" + } + + return Keywords.contains(II); AaronBallman wrote: 32 is wrong though, we have 34 keywords. Good catch on that. I'll bump to 48 to give wiggle room and pick something power-of-two-ish. WDYT? https://github.com/llvm/llvm-project/pull/137234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] f8724bd - [clang][bytecode] Check live-ness when calling dtors (#137645)
Author: Timm Baeder Date: 2025-04-28T17:47:30+02:00 New Revision: f8724bd873878df81720bdec8b7a9a24f2a40a03 URL: https://github.com/llvm/llvm-project/commit/f8724bd873878df81720bdec8b7a9a24f2a40a03 DIFF: https://github.com/llvm/llvm-project/commit/f8724bd873878df81720bdec8b7a9a24f2a40a03.diff LOG: [clang][bytecode] Check live-ness when calling dtors (#137645) We can't call a destructor on a dead pointer. Added: Modified: clang/lib/AST/ByteCode/Interp.cpp clang/test/AST/ByteCode/records.cpp Removed: diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index 4d89f23401db5..62b449597bca8 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -1375,6 +1375,9 @@ static bool checkConstructor(InterpState &S, CodePtr OpPC, const Function *Func, } bool CheckDestructor(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { + if (!CheckLive(S, OpPC, Ptr, AK_Destroy)) +return false; + // Can't call a dtor on a global variable. if (Ptr.block()->isStatic()) { const SourceInfo &E = S.Current->getSource(OpPC); diff --git a/clang/test/AST/ByteCode/records.cpp b/clang/test/AST/ByteCode/records.cpp index 9abfe6b8a15e7..c2fe3d9007480 100644 --- a/clang/test/AST/ByteCode/records.cpp +++ b/clang/test/AST/ByteCode/records.cpp @@ -1819,3 +1819,14 @@ namespace GlobalDtor { a.~A(); // both-note {{cannot modify an object that is visible outside}} } } + +namespace NullDtor { + struct S {}; + constexpr int foo() { // both-error {{never produces a constant expression}} + S *s = nullptr; + s->~S(); // both-note 2{{destruction of dereferenced null pointer is not allowed in a constant expression}} + return 10; + } + static_assert(foo() == 10, ""); // both-error {{not an integral constant expression}} \ + // both-note {{in call to}} +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C] Diagnose use of C++ keywords in C (PR #137234)
@@ -6107,6 +6109,29 @@ static bool isFromSystemHeader(SourceManager &SM, const Decl *D) { SM.isInSystemMacro(D->getLocation()); } +static bool isKeywordInCPlusPlus(const Sema &S, const IdentifierInfo *II) { + if (!II) +return false; + + // Build a static map of identifiers for all of the keywords in C++ that are + // not keywords in C. This allows us to do pointer comparisons instead of + // string comparisons when deciding whether the given identifier is a keyword + // or not. Note, this treats all keywords as being enabled, regardless of the + // setting of other language options. It intentionally disables the modules + // keywords because those are conditional keywords, so may be safe to use. + static llvm::SmallPtrSet Keywords; + if (Keywords.empty()) { +#define MODULES_KEYWORD(NAME) +#define KEYWORD(NAME, FLAGS) \ + Keywords.insert(&S.getPreprocessor().getIdentifierTable().get(#NAME)); +#define CXX_KEYWORD_OPERATOR(NAME, TOK) \ + Keywords.insert(&S.getPreprocessor().getIdentifierTable().get(#NAME)); +#include "clang/Basic/TokenKinds.def" + } + + return Keywords.contains(II); erichkeane wrote: Thats sensible. Perhaps an idea to hold onto in the future, but since this is only 'when diag enabled', its something we can think further about when/if this ever becomes a concern https://github.com/llvm/llvm-project/pull/137234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits