[clang-tools-extra] [clang-tidy] Add readability-use-span-first-last check (PR #118074)
https://github.com/5chmidti edited https://github.com/llvm/llvm-project/pull/118074 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add recursion protection in ExceptionSpecAnalyzer (PR #66810)
https://github.com/5chmidti approved this pull request. LGTM, but please add a release note about fixing the infinite recursion https://github.com/llvm/llvm-project/pull/66810 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add recursion protection in ExceptionSpecAnalyzer (PR #66810)
5chmidti wrote: And maybe @carlosgalvezp wants to comment https://github.com/llvm/llvm-project/pull/66810 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][use-internal-linkage]fix false positives for global overloaded operator new and operator delete (PR #117945)
https://github.com/5chmidti approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/117945 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [SelectionDAG][PowerPC] Add an intrinsic for memcmp. (PR #118178)
llvmbot wrote: @llvm/pr-subscribers-llvm-selectiondag Author: Stefan Pintilie (stefanp-ibm) Changes In the backend we want to provide special handling for the function memcmp. This patch adds an intrinsic so that the backend will recognize it as more than just a regular function call. This patch also adds special handling for PowerPC on AIX. --- Full diff: https://github.com/llvm/llvm-project/pull/118178.diff 10 Files Affected: - (modified) clang/lib/CodeGen/CGBuiltin.cpp (+13) - (modified) clang/test/CodeGen/builtin-memfns.c (+35-18) - (modified) clang/test/CodeGen/debug-info-extern-call.c (+5-5) - (modified) llvm/include/llvm/CodeGen/SelectionDAG.h (+6) - (modified) llvm/include/llvm/IR/Intrinsics.td (+6) - (modified) llvm/include/llvm/IR/RuntimeLibcalls.def (+1) - (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (+51) - (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (+19-1) - (modified) llvm/lib/Target/PowerPC/PPCISelLowering.cpp (+1) - (added) llvm/test/CodeGen/PowerPC/memintr.ll (+151) ``diff diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index cb9c23b8e0a0d0..0688f4064d788b 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -4483,6 +4483,19 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, return RValue::get(nullptr); } + case Builtin::BImemcmp: { +Address Src = EmitPointerWithAlignment(E->getArg(0)); +Address Dst = EmitPointerWithAlignment(E->getArg(1)); +Value *SizeVal = EmitScalarExpr(E->getArg(2)); +llvm::Type *Tys[] = {Dst.getBasePointer()->getType(), + Src.getBasePointer()->getType(), SizeVal->getType()}; + +Function *F = CGM.getIntrinsic(Intrinsic::memcmp, Tys); +Value *Mem1Value = EmitScalarExpr(E->getArg(0)); +Value *Mem2Value = EmitScalarExpr(E->getArg(1)); +Value *Args[] = {Mem1Value, Mem2Value, SizeVal}; +return RValue::get(Builder.CreateCall(F, Args)); + } case Builtin::BImemcpy: case Builtin::BI__builtin_memcpy: case Builtin::BImempcpy: diff --git a/clang/test/CodeGen/builtin-memfns.c b/clang/test/CodeGen/builtin-memfns.c index 23c3c60b779b37..51c5ad43cc7ef2 100644 --- a/clang/test/CodeGen/builtin-memfns.c +++ b/clang/test/CodeGen/builtin-memfns.c @@ -1,16 +1,23 @@ -// RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm < %s| FileCheck %s +// RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm < %s| FileCheck %s --check-prefixes=CHECK,CHECK32 +// RUN: %clang_cc1 -triple ppc -emit-llvm < %s| FileCheck %s --check-prefixes=CHECK,CHECK32 +// RUN: %clang_cc1 -triple ppc64 -emit-llvm < %s| FileCheck %s --check-prefixes=CHECK,CHECK64 typedef __WCHAR_TYPE__ wchar_t; typedef __SIZE_TYPE__ size_t; void *memcpy(void *, void const *, size_t); void *memccpy(void *, void const *, int, size_t); - -// CHECK: @test1 -// CHECK: call void @llvm.memset.p0.i32 -// CHECK: call void @llvm.memset.p0.i32 -// CHECK: call void @llvm.memcpy.p0.p0.i32 -// CHECK: call void @llvm.memmove.p0.p0.i32 +int memcmp(const void *, const void *, size_t); + +// CHECK-LABEL: @test1 +// CHECK32: call void @llvm.memset.p0.i32 +// CHECK64: call void @llvm.memset.p0.i64 +// CHECK32: call void @llvm.memset.p0.i32 +// CHECK64: call void @llvm.memset.p0.i64 +// CHECK32: call void @llvm.memcpy.p0.p0.i32 +// CHECK64: call void @llvm.memcpy.p0.p0.i64 +// CHECK32: call void @llvm.memmove.p0.p0.i32 +// CHECK64: call void @llvm.memmove.p0.p0.i64 // CHECK-NOT: __builtin // CHECK: ret int test1(int argc, char **argv) { @@ -23,37 +30,38 @@ int test1(int argc, char **argv) { return 0; } -// CHECK: @test2 -// CHECK: call void @llvm.memcpy.p0.p0.i32 +// CHECK-LABEL: @test2 +// CHECK32: call void @llvm.memcpy.p0.p0.i32 +// CHECK64: call void @llvm.memcpy.p0.p0.i64 char* test2(char* a, char* b) { return __builtin_memcpy(a, b, 4); } -// CHECK: @test3 +// CHECK-LABEL: @test3 // CHECK: call void @llvm.memset void test3(char *P) { __builtin___memset_chk(P, 42, 128, 128); } -// CHECK: @test4 +// CHECK-LABEL: @test4 // CHECK: call void @llvm.memcpy void test4(char *P, char *Q) { __builtin___memcpy_chk(P, Q, 128, 128); } -// CHECK: @test5 +// CHECK-LABEL: @test5 // CHECK: call void @llvm.memmove void test5(char *P, char *Q) { __builtin___memmove_chk(P, Q, 128, 128); } -// CHECK: @test6 +// CHECK-LABEL: @test6 // CHECK: call void @llvm.memcpy int test6(char *X) { return __builtin___memcpy_chk(X, X, 42, 42) != 0; } -// CHECK: @test7 +// CHECK-LABEL: @test7 // PR12094 int test7(int *p) { struct snd_pcm_hw_params_t* hwparams; // incomplete type. @@ -75,14 +83,14 @@ struct PS { } __attribute__((packed)); struct PS ps; void test8(int *arg) { - // CHECK: @test8 + // CHECK-LABEL: @test8 // CHECK: call void @llvm.memcpy{{.*}} align 4 {{.*}} align 1 {{.*}} 16, i1 false) __builtin_memcpy(arg, ps.modes, sizeof(struct PS)); } __attribute((align
[clang] [llvm] [SelectionDAG][PowerPC] Add an intrinsic for memcmp. (PR #118178)
llvmbot wrote: @llvm/pr-subscribers-backend-powerpc Author: Stefan Pintilie (stefanp-ibm) Changes In the backend we want to provide special handling for the function memcmp. This patch adds an intrinsic so that the backend will recognize it as more than just a regular function call. This patch also adds special handling for PowerPC on AIX. --- Full diff: https://github.com/llvm/llvm-project/pull/118178.diff 10 Files Affected: - (modified) clang/lib/CodeGen/CGBuiltin.cpp (+13) - (modified) clang/test/CodeGen/builtin-memfns.c (+35-18) - (modified) clang/test/CodeGen/debug-info-extern-call.c (+5-5) - (modified) llvm/include/llvm/CodeGen/SelectionDAG.h (+6) - (modified) llvm/include/llvm/IR/Intrinsics.td (+6) - (modified) llvm/include/llvm/IR/RuntimeLibcalls.def (+1) - (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (+51) - (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (+19-1) - (modified) llvm/lib/Target/PowerPC/PPCISelLowering.cpp (+1) - (added) llvm/test/CodeGen/PowerPC/memintr.ll (+151) ``diff diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index cb9c23b8e0a0d0..0688f4064d788b 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -4483,6 +4483,19 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, return RValue::get(nullptr); } + case Builtin::BImemcmp: { +Address Src = EmitPointerWithAlignment(E->getArg(0)); +Address Dst = EmitPointerWithAlignment(E->getArg(1)); +Value *SizeVal = EmitScalarExpr(E->getArg(2)); +llvm::Type *Tys[] = {Dst.getBasePointer()->getType(), + Src.getBasePointer()->getType(), SizeVal->getType()}; + +Function *F = CGM.getIntrinsic(Intrinsic::memcmp, Tys); +Value *Mem1Value = EmitScalarExpr(E->getArg(0)); +Value *Mem2Value = EmitScalarExpr(E->getArg(1)); +Value *Args[] = {Mem1Value, Mem2Value, SizeVal}; +return RValue::get(Builder.CreateCall(F, Args)); + } case Builtin::BImemcpy: case Builtin::BI__builtin_memcpy: case Builtin::BImempcpy: diff --git a/clang/test/CodeGen/builtin-memfns.c b/clang/test/CodeGen/builtin-memfns.c index 23c3c60b779b37..51c5ad43cc7ef2 100644 --- a/clang/test/CodeGen/builtin-memfns.c +++ b/clang/test/CodeGen/builtin-memfns.c @@ -1,16 +1,23 @@ -// RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm < %s| FileCheck %s +// RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm < %s| FileCheck %s --check-prefixes=CHECK,CHECK32 +// RUN: %clang_cc1 -triple ppc -emit-llvm < %s| FileCheck %s --check-prefixes=CHECK,CHECK32 +// RUN: %clang_cc1 -triple ppc64 -emit-llvm < %s| FileCheck %s --check-prefixes=CHECK,CHECK64 typedef __WCHAR_TYPE__ wchar_t; typedef __SIZE_TYPE__ size_t; void *memcpy(void *, void const *, size_t); void *memccpy(void *, void const *, int, size_t); - -// CHECK: @test1 -// CHECK: call void @llvm.memset.p0.i32 -// CHECK: call void @llvm.memset.p0.i32 -// CHECK: call void @llvm.memcpy.p0.p0.i32 -// CHECK: call void @llvm.memmove.p0.p0.i32 +int memcmp(const void *, const void *, size_t); + +// CHECK-LABEL: @test1 +// CHECK32: call void @llvm.memset.p0.i32 +// CHECK64: call void @llvm.memset.p0.i64 +// CHECK32: call void @llvm.memset.p0.i32 +// CHECK64: call void @llvm.memset.p0.i64 +// CHECK32: call void @llvm.memcpy.p0.p0.i32 +// CHECK64: call void @llvm.memcpy.p0.p0.i64 +// CHECK32: call void @llvm.memmove.p0.p0.i32 +// CHECK64: call void @llvm.memmove.p0.p0.i64 // CHECK-NOT: __builtin // CHECK: ret int test1(int argc, char **argv) { @@ -23,37 +30,38 @@ int test1(int argc, char **argv) { return 0; } -// CHECK: @test2 -// CHECK: call void @llvm.memcpy.p0.p0.i32 +// CHECK-LABEL: @test2 +// CHECK32: call void @llvm.memcpy.p0.p0.i32 +// CHECK64: call void @llvm.memcpy.p0.p0.i64 char* test2(char* a, char* b) { return __builtin_memcpy(a, b, 4); } -// CHECK: @test3 +// CHECK-LABEL: @test3 // CHECK: call void @llvm.memset void test3(char *P) { __builtin___memset_chk(P, 42, 128, 128); } -// CHECK: @test4 +// CHECK-LABEL: @test4 // CHECK: call void @llvm.memcpy void test4(char *P, char *Q) { __builtin___memcpy_chk(P, Q, 128, 128); } -// CHECK: @test5 +// CHECK-LABEL: @test5 // CHECK: call void @llvm.memmove void test5(char *P, char *Q) { __builtin___memmove_chk(P, Q, 128, 128); } -// CHECK: @test6 +// CHECK-LABEL: @test6 // CHECK: call void @llvm.memcpy int test6(char *X) { return __builtin___memcpy_chk(X, X, 42, 42) != 0; } -// CHECK: @test7 +// CHECK-LABEL: @test7 // PR12094 int test7(int *p) { struct snd_pcm_hw_params_t* hwparams; // incomplete type. @@ -75,14 +83,14 @@ struct PS { } __attribute__((packed)); struct PS ps; void test8(int *arg) { - // CHECK: @test8 + // CHECK-LABEL: @test8 // CHECK: call void @llvm.memcpy{{.*}} align 4 {{.*}} align 1 {{.*}} 16, i1 false) __builtin_memcpy(arg, ps.modes, sizeof(struct PS)); } __attribute((aligned
[clang] Draft (PR #118177)
https://github.com/c8ef created https://github.com/llvm/llvm-project/pull/118177 None >From 69c3275b5119adc049821aacf2b9f01641d73aad Mon Sep 17 00:00:00 2001 From: c8ef Date: Sun, 1 Dec 2024 00:10:58 +0800 Subject: [PATCH] constexpr elementwise bitreverse --- clang/docs/LanguageExtensions.rst | 2 +- clang/docs/ReleaseNotes.rst | 1 + clang/include/clang/Basic/Builtins.td | 2 +- clang/lib/AST/ExprConstant.cpp| 22 ++- .../test/CodeGen/builtins-elementwise-math.c | 2 +- clang/test/Sema/constant_builtins_vector.cpp | 5 + 6 files changed, 26 insertions(+), 8 deletions(-) diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index c053a5ab3c528c..52032e935928f1 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -648,7 +648,7 @@ elementwise to the input. Unless specified otherwise operation(±0) = ±0 and operation(±infinity) = ±infinity The integer elementwise intrinsics, including ``__builtin_elementwise_popcount``, -can be called in a ``constexpr`` context. +``__builtin_elementwise_bitreverse``, can be called in a ``constexpr`` context. == == = Name Operation Supported element types diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index e44aefa90ab386..7a4d58f170d297 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -402,6 +402,7 @@ Non-comprehensive list of changes in this release - ``__builtin_reduce_and`` function can now be used in constant expressions. - ``__builtin_reduce_or`` and ``__builtin_reduce_xor`` functions can now be used in constant expressions. - ``__builtin_elementwise_popcount`` function can now be used in constant expressions. +- ``__builtin_elementwise_bitreverse`` function can now be used in constant expressions. New Compiler Flags -- diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index db5cd73fba8ad1..f953f869d726bb 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -1270,7 +1270,7 @@ def ElementwiseATan2 : Builtin { def ElementwiseBitreverse : Builtin { let Spellings = ["__builtin_elementwise_bitreverse"]; - let Attributes = [NoThrow, Const, CustomTypeChecking]; + let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr]; let Prototype = "void(...)"; } diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index bb5ab67328fbc6..a99e91ff7b786e 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -11310,7 +11310,8 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) { switch (E->getBuiltinCallee()) { default: return false; - case Builtin::BI__builtin_elementwise_popcount: { + case Builtin::BI__builtin_elementwise_popcount: + case Builtin::BI__builtin_elementwise_bitreverse: { APValue Source; if (!EvaluateAsRValue(Info, E->getArg(0), Source)) return false; @@ -11322,9 +11323,19 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) { for (unsigned EltNum = 0; EltNum < SourceLen; ++EltNum) { APSInt Elt = Source.getVectorElt(EltNum).getInt(); - ResultElements.push_back( - APValue(APSInt(APInt(Info.Ctx.getIntWidth(DestEltTy), Elt.popcount()), - DestEltTy->isUnsignedIntegerOrEnumerationType(; + switch (E->getBuiltinCallee()) { + case Builtin::BI__builtin_elementwise_popcount: +ResultElements.push_back(APValue( +APSInt(APInt(Info.Ctx.getIntWidth(DestEltTy), Elt.popcount()), + DestEltTy->isUnsignedIntegerOrEnumerationType(; +break; + case Builtin::BI__builtin_elementwise_bitreverse: +ResultElements.push_back( +APValue(APSInt(Elt.reverseBits(), + DestEltTy->isUnsignedIntegerOrEnumerationType()) +.extOrTrunc(Info.Ctx.getIntWidth(DestEltTy; +break; + } } return Success(APValue(ResultElements.data(), ResultElements.size()), E); @@ -12833,7 +12844,8 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E, case Builtin::BI__builtin_bitreverse8: case Builtin::BI__builtin_bitreverse16: case Builtin::BI__builtin_bitreverse32: - case Builtin::BI__builtin_bitreverse64: { + case Builtin::BI__builtin_bitreverse64: + case Builtin::BI__builtin_elementwise_bitreverse: { APSInt Val; if (!EvaluateInteger(E->getArg(0), Val, Info)) return false; diff --git a/clang/test/CodeGen/builtins-elementwise-math.c b/clang/test/CodeGen/builtins-elementwise-math.c i
[clang] [llvm] [SelectionDAG][PowerPC] Add an intrinsic for memcmp. (PR #118178)
https://github.com/stefanp-ibm created https://github.com/llvm/llvm-project/pull/118178 In the backend we want to provide special handling for the function memcmp. This patch adds an intrinsic so that the backend will recognize it as more than just a regular function call. This patch also adds special handling for PowerPC on AIX. >From 11868cec3a03be41dbf0201d95bfd2a5416a0ca5 Mon Sep 17 00:00:00 2001 From: Stefan Pintilie Date: Fri, 29 Nov 2024 15:46:46 -0500 Subject: [PATCH] [SelectionDAG][PowerPC] Add an intrinsic for memcmp. In the backend we want to provide special handling for the function memcmp. This patch adds an intrinsic so that the backend will recognize it as more than just a regular function call. This patch also adds special handling for PowerPC on AIX. --- clang/lib/CodeGen/CGBuiltin.cpp | 13 ++ clang/test/CodeGen/builtin-memfns.c | 53 +++--- clang/test/CodeGen/debug-info-extern-call.c | 10 +- llvm/include/llvm/CodeGen/SelectionDAG.h | 6 + llvm/include/llvm/IR/Intrinsics.td| 6 + llvm/include/llvm/IR/RuntimeLibcalls.def | 1 + .../lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 51 ++ .../SelectionDAG/SelectionDAGBuilder.cpp | 20 ++- llvm/lib/Target/PowerPC/PPCISelLowering.cpp | 1 + llvm/test/CodeGen/PowerPC/memintr.ll | 151 ++ 10 files changed, 288 insertions(+), 24 deletions(-) create mode 100644 llvm/test/CodeGen/PowerPC/memintr.ll diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index cb9c23b8e0a0d0..0688f4064d788b 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -4483,6 +4483,19 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, return RValue::get(nullptr); } + case Builtin::BImemcmp: { +Address Src = EmitPointerWithAlignment(E->getArg(0)); +Address Dst = EmitPointerWithAlignment(E->getArg(1)); +Value *SizeVal = EmitScalarExpr(E->getArg(2)); +llvm::Type *Tys[] = {Dst.getBasePointer()->getType(), + Src.getBasePointer()->getType(), SizeVal->getType()}; + +Function *F = CGM.getIntrinsic(Intrinsic::memcmp, Tys); +Value *Mem1Value = EmitScalarExpr(E->getArg(0)); +Value *Mem2Value = EmitScalarExpr(E->getArg(1)); +Value *Args[] = {Mem1Value, Mem2Value, SizeVal}; +return RValue::get(Builder.CreateCall(F, Args)); + } case Builtin::BImemcpy: case Builtin::BI__builtin_memcpy: case Builtin::BImempcpy: diff --git a/clang/test/CodeGen/builtin-memfns.c b/clang/test/CodeGen/builtin-memfns.c index 23c3c60b779b37..51c5ad43cc7ef2 100644 --- a/clang/test/CodeGen/builtin-memfns.c +++ b/clang/test/CodeGen/builtin-memfns.c @@ -1,16 +1,23 @@ -// RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm < %s| FileCheck %s +// RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm < %s| FileCheck %s --check-prefixes=CHECK,CHECK32 +// RUN: %clang_cc1 -triple ppc -emit-llvm < %s| FileCheck %s --check-prefixes=CHECK,CHECK32 +// RUN: %clang_cc1 -triple ppc64 -emit-llvm < %s| FileCheck %s --check-prefixes=CHECK,CHECK64 typedef __WCHAR_TYPE__ wchar_t; typedef __SIZE_TYPE__ size_t; void *memcpy(void *, void const *, size_t); void *memccpy(void *, void const *, int, size_t); - -// CHECK: @test1 -// CHECK: call void @llvm.memset.p0.i32 -// CHECK: call void @llvm.memset.p0.i32 -// CHECK: call void @llvm.memcpy.p0.p0.i32 -// CHECK: call void @llvm.memmove.p0.p0.i32 +int memcmp(const void *, const void *, size_t); + +// CHECK-LABEL: @test1 +// CHECK32: call void @llvm.memset.p0.i32 +// CHECK64: call void @llvm.memset.p0.i64 +// CHECK32: call void @llvm.memset.p0.i32 +// CHECK64: call void @llvm.memset.p0.i64 +// CHECK32: call void @llvm.memcpy.p0.p0.i32 +// CHECK64: call void @llvm.memcpy.p0.p0.i64 +// CHECK32: call void @llvm.memmove.p0.p0.i32 +// CHECK64: call void @llvm.memmove.p0.p0.i64 // CHECK-NOT: __builtin // CHECK: ret int test1(int argc, char **argv) { @@ -23,37 +30,38 @@ int test1(int argc, char **argv) { return 0; } -// CHECK: @test2 -// CHECK: call void @llvm.memcpy.p0.p0.i32 +// CHECK-LABEL: @test2 +// CHECK32: call void @llvm.memcpy.p0.p0.i32 +// CHECK64: call void @llvm.memcpy.p0.p0.i64 char* test2(char* a, char* b) { return __builtin_memcpy(a, b, 4); } -// CHECK: @test3 +// CHECK-LABEL: @test3 // CHECK: call void @llvm.memset void test3(char *P) { __builtin___memset_chk(P, 42, 128, 128); } -// CHECK: @test4 +// CHECK-LABEL: @test4 // CHECK: call void @llvm.memcpy void test4(char *P, char *Q) { __builtin___memcpy_chk(P, Q, 128, 128); } -// CHECK: @test5 +// CHECK-LABEL: @test5 // CHECK: call void @llvm.memmove void test5(char *P, char *Q) { __builtin___memmove_chk(P, Q, 128, 128); } -// CHECK: @test6 +// CHECK-LABEL: @test6 // CHECK: call void @llvm.memcpy int test6(char *X) { return __builtin___memcpy_chk(X, X, 42, 42) != 0; } -// CHECK: @test7 +// CHECK-LABEL: @tes
[clang] [llvm] [SelectionDAG][PowerPC] Add an intrinsic for memcmp. (PR #118178)
tschuett wrote: langref update for the new intrinsic? https://github.com/llvm/llvm-project/pull/118178 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Tooling/Inclusion] Update std symbol mapping (PR #118174)
https://github.com/vvd170501 ready_for_review https://github.com/llvm/llvm-project/pull/118174 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][use-internal-linkage]fix false positives for global overloaded operator new and operator delete (PR #117945)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `sanitizer-x86_64-linux-bootstrap-asan` running on `sanitizer-buildbot1` while building `clang-tools-extra` at step 2 "annotate". Full details are available at: https://lab.llvm.org/buildbot/#/builders/52/builds/4138 Here is the relevant piece of the build log for the reference ``` Step 2 (annotate) failure: 'python ../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py' (failure) ... llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using lld-link: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using ld64.lld: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using wasm-ld: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using ld.lld: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld.lld llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using lld-link: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using ld64.lld: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using wasm-ld: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/main.py:72: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 900 seconds was requested on the command line. Forcing timeout to be 900 seconds. -- Testing: 87510 of 87511 tests, 88 workers -- Testing: 0.. 10 FAIL: Clang :: Interpreter/inline-virtual.cpp (12629 of 87510) TEST 'Clang :: Interpreter/inline-virtual.cpp' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 6: cat /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp | /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/clang-repl -Xcc -fno-rtti -Xcc -fno-sized-deallocation | /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/FileCheck /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp + cat /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp + /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/clang-repl -Xcc -fno-rtti -Xcc -fno-sized-deallocation + /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/FileCheck /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp JIT session error: In graph incr_module_23-jitted-objectbuffer, section .text.startup: relocation target "_ZN1AD2Ev" at address 0x732e2582f040 is out of range of Delta32 fixup at 0x6f2e24f0f02d ( @ 0x6f2e24f0f010 + 0x1d) error: Failed to materialize symbols: { (main, { __orc_init_func.incr_module_23, a2, $.incr_module_23.__inits.0 }) } error: Failed to materialize symbols: { (main, { __orc_init_func.incr_module_23 }) } /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp:26:11: error: CHECK: expected string not found in input // CHECK: ~A(2) ^ :1:262: note: scanning from here clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl... clang-repl> clang-repl... clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> ~A(1) ^ Input file: Check file: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp -dump-input=help explains the following input dump. Input was: << 1: clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl... clang-repl> clang-r
[clang] Draft (PR #118177)
https://github.com/c8ef updated https://github.com/llvm/llvm-project/pull/118177 >From 69c3275b5119adc049821aacf2b9f01641d73aad Mon Sep 17 00:00:00 2001 From: c8ef Date: Sun, 1 Dec 2024 00:10:58 +0800 Subject: [PATCH 1/2] constexpr elementwise bitreverse --- clang/docs/LanguageExtensions.rst | 2 +- clang/docs/ReleaseNotes.rst | 1 + clang/include/clang/Basic/Builtins.td | 2 +- clang/lib/AST/ExprConstant.cpp| 22 ++- .../test/CodeGen/builtins-elementwise-math.c | 2 +- clang/test/Sema/constant_builtins_vector.cpp | 5 + 6 files changed, 26 insertions(+), 8 deletions(-) diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index c053a5ab3c528c..52032e935928f1 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -648,7 +648,7 @@ elementwise to the input. Unless specified otherwise operation(±0) = ±0 and operation(±infinity) = ±infinity The integer elementwise intrinsics, including ``__builtin_elementwise_popcount``, -can be called in a ``constexpr`` context. +``__builtin_elementwise_bitreverse``, can be called in a ``constexpr`` context. == == = Name Operation Supported element types diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index e44aefa90ab386..7a4d58f170d297 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -402,6 +402,7 @@ Non-comprehensive list of changes in this release - ``__builtin_reduce_and`` function can now be used in constant expressions. - ``__builtin_reduce_or`` and ``__builtin_reduce_xor`` functions can now be used in constant expressions. - ``__builtin_elementwise_popcount`` function can now be used in constant expressions. +- ``__builtin_elementwise_bitreverse`` function can now be used in constant expressions. New Compiler Flags -- diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index db5cd73fba8ad1..f953f869d726bb 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -1270,7 +1270,7 @@ def ElementwiseATan2 : Builtin { def ElementwiseBitreverse : Builtin { let Spellings = ["__builtin_elementwise_bitreverse"]; - let Attributes = [NoThrow, Const, CustomTypeChecking]; + let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr]; let Prototype = "void(...)"; } diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index bb5ab67328fbc6..a99e91ff7b786e 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -11310,7 +11310,8 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) { switch (E->getBuiltinCallee()) { default: return false; - case Builtin::BI__builtin_elementwise_popcount: { + case Builtin::BI__builtin_elementwise_popcount: + case Builtin::BI__builtin_elementwise_bitreverse: { APValue Source; if (!EvaluateAsRValue(Info, E->getArg(0), Source)) return false; @@ -11322,9 +11323,19 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) { for (unsigned EltNum = 0; EltNum < SourceLen; ++EltNum) { APSInt Elt = Source.getVectorElt(EltNum).getInt(); - ResultElements.push_back( - APValue(APSInt(APInt(Info.Ctx.getIntWidth(DestEltTy), Elt.popcount()), - DestEltTy->isUnsignedIntegerOrEnumerationType(; + switch (E->getBuiltinCallee()) { + case Builtin::BI__builtin_elementwise_popcount: +ResultElements.push_back(APValue( +APSInt(APInt(Info.Ctx.getIntWidth(DestEltTy), Elt.popcount()), + DestEltTy->isUnsignedIntegerOrEnumerationType(; +break; + case Builtin::BI__builtin_elementwise_bitreverse: +ResultElements.push_back( +APValue(APSInt(Elt.reverseBits(), + DestEltTy->isUnsignedIntegerOrEnumerationType()) +.extOrTrunc(Info.Ctx.getIntWidth(DestEltTy; +break; + } } return Success(APValue(ResultElements.data(), ResultElements.size()), E); @@ -12833,7 +12844,8 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E, case Builtin::BI__builtin_bitreverse8: case Builtin::BI__builtin_bitreverse16: case Builtin::BI__builtin_bitreverse32: - case Builtin::BI__builtin_bitreverse64: { + case Builtin::BI__builtin_bitreverse64: + case Builtin::BI__builtin_elementwise_bitreverse: { APSInt Val; if (!EvaluateInteger(E->getArg(0), Val, Info)) return false; diff --git a/clang/test/CodeGen/builtins-elementwise-math.c b/clang/test/CodeGen/builtins-elementwise-math.c ind
[clang] [Tooling/Inclusion] Update std symbol mapping (PR #118174)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Vadim D. (vvd170501) Changes https://github.com/PeterFeicht/cppreference-doc/releases/tag/v20241110 --- Full diff: https://github.com/llvm/llvm-project/pull/118174.diff 2 Files Affected: - (modified) clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc (+5-8) - (modified) clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc (+50-6) ``diff diff --git a/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc b/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc index 8f20ce98152f08..9179217dd6ca8b 100644 --- a/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc +++ b/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc @@ -261,6 +261,11 @@ SYMBOL(data, std::ranges::, ) SYMBOL(data, std::ranges::, ) SYMBOL(cdata, std::ranges::, ) SYMBOL(cdata, std::ranges::, ) +// https://eel.is/c++draft/tuple.general#2: +// In addition to being available via inclusion of the header, +// ignore ... is available when ... is included. +SYMBOL(ignore, std::, ) +SYMBOL(ignore, std::, ) // Ignore specializations SYMBOL(hash, std::, ) @@ -389,18 +394,10 @@ SYMBOL(make_error_condition, std::, /*no headers*/) SYMBOL(erase, std::, /*no headers*/) SYMBOL(erase_if, std::, /*no headers*/) -// cppreference symbol index page was missing these symbols. -// Remove them when the cppreference offline archive catches up. -SYMBOL(regular_invocable, std::, ) - // Symbols missing from the generated symbol map as reported by users. // Remove when the generator starts producing them. SYMBOL(div, std::, ) SYMBOL(abort, std::, ) -SYMBOL(atomic_wait, std::, ) -SYMBOL(atomic_wait_explicit, std::, ) -SYMBOL(move_backward, std::, ) -SYMBOL(month_weekday, std::chrono::, ) SYMBOL(binary_search, std::ranges::, ) SYMBOL(equal_range, std::ranges::, ) diff --git a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc index b4afd0228694ff..c1927180d33976 100644 --- a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc +++ b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc @@ -6,7 +6,7 @@ // This file was generated automatically by // clang/tools/include-mapping/gen_std.py, DO NOT EDIT! // -// Generated from cppreference offline HTML book (modified on 2024-06-10). +// Generated from cppreference offline HTML book (modified on 2024-11-10). //===--===// SYMBOL(ATOMIC_BOOL_LOCK_FREE, None, ) @@ -578,6 +578,7 @@ SYMBOL(add_pointer, std::, ) SYMBOL(add_pointer_t, std::, ) SYMBOL(add_rvalue_reference, std::, ) SYMBOL(add_rvalue_reference_t, std::, ) +SYMBOL(add_sat, std::, ) SYMBOL(add_volatile, std::, ) SYMBOL(add_volatile_t, std::, ) SYMBOL(addressof, std::, ) @@ -699,6 +700,10 @@ SYMBOL(atomic_fetch_add, std::, ) SYMBOL(atomic_fetch_add_explicit, std::, ) SYMBOL(atomic_fetch_and, std::, ) SYMBOL(atomic_fetch_and_explicit, std::, ) +SYMBOL(atomic_fetch_max, std::, ) +SYMBOL(atomic_fetch_max_explicit, std::, ) +SYMBOL(atomic_fetch_min, std::, ) +SYMBOL(atomic_fetch_min_explicit, std::, ) SYMBOL(atomic_fetch_or, std::, ) SYMBOL(atomic_fetch_or_explicit, std::, ) SYMBOL(atomic_fetch_sub, std::, ) @@ -727,6 +732,8 @@ SYMBOL(atomic_signal_fence, std::, ) SYMBOL(atomic_store, std::, ) SYMBOL(atomic_store_explicit, std::, ) SYMBOL(atomic_thread_fence, std::, ) +SYMBOL(atomic_wait, std::, ) +SYMBOL(atomic_wait_explicit, std::, ) SYMBOL(atto, std::, ) SYMBOL(auto_ptr, std::, ) SYMBOL(back_insert_iterator, std::, ) @@ -829,6 +836,8 @@ SYMBOL(boolalpha, std::, ) SYMBOL(boolalpha, std::, ) SYMBOL(boyer_moore_horspool_searcher, std::, ) SYMBOL(boyer_moore_searcher, std::, ) +SYMBOL(breakpoint, std::, ) +SYMBOL(breakpoint_if_debugging, std::, ) SYMBOL(bsearch, std::, ) SYMBOL(bsearch, None, ) SYMBOL(bsearch, None, ) @@ -951,6 +960,7 @@ SYMBOL(copy_constructible, std::, ) SYMBOL(copy_if, std::, ) SYMBOL(copy_n, std::, ) SYMBOL(copyable, std::, ) +SYMBOL(copyable_function, std::, ) SYMBOL(copysign, std::, ) SYMBOL(copysign, None, ) SYMBOL(copysign, None, ) @@ -1048,12 +1058,14 @@ SYMBOL(dextents, std::, ) SYMBOL(difftime, std::, ) SYMBOL(difftime, None, ) SYMBOL(difftime, None, ) +SYMBOL(dims, std::, ) SYMBOL(disable_sized_sentinel_for, std::, ) SYMBOL(discard_block_engine, std::, ) SYMBOL(discrete_distribution, std::, ) SYMBOL(disjunction, std::, ) SYMBOL(disjunction_v, std::, ) SYMBOL(distance, std::, ) +SYMBOL(div_sat, std::, ) SYMBOL(div_t, std::, ) SYMBOL(div_t, None, ) SYMBOL(div_t, None, ) @@ -1077,6 +1089,7 @@ SYMBOL(emit_on_flush, std::, ) SYMBOL(emit_on_flush, std::, ) SYMBOL(enable_if, std::, ) SYMBOL(enable_if_t, std::, ) +SYMBOL(enable_nonlocking_formatter_optimization, std::, ) SYMBOL(enable_shared_from_this, std::, ) SYMBOL(endian, std::, ) SYMBOL(endl, std::, ) @@ -1241,8 +1254,7 @@ SYMBOL(fgetwc, None, ) SYMBOL(fgetws, std::, ) SYMBOL(fgetws, None, ) SYM
[clang] [clang-format] Add BreakBeforeTemplateClose option (PR #118046)
https://github.com/leijurv edited https://github.com/llvm/llvm-project/pull/118046 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Fix compilation for the x32 ABI. (PR #116608)
https://github.com/alexrp updated https://github.com/llvm/llvm-project/pull/116608 From 87f34d96faea8288e351f4450afa0710b2567fd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Mon, 18 Nov 2024 13:12:30 +0100 Subject: [PATCH] [libunwind] Fix compilation for the x32 ABI. This would previously fail the static assertions in UnwindCursor.hpp due to UnwindCursor's size not matching unw_cursor_t's size. As is done for MIPS N32, this just declares the appropriate size in __libunwind_config.h. --- libunwind/include/__libunwind_config.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libunwind/include/__libunwind_config.h b/libunwind/include/__libunwind_config.h index 028b9e3baa8065..bb7fe4c83a3c17 100644 --- a/libunwind/include/__libunwind_config.h +++ b/libunwind/include/__libunwind_config.h @@ -53,6 +53,9 @@ #else # define _LIBUNWIND_CURSOR_SIZE 66 #endif +# elif defined(__ILP32__) +#define _LIBUNWIND_CONTEXT_SIZE 21 +#define _LIBUNWIND_CURSOR_SIZE 28 # else #define _LIBUNWIND_CONTEXT_SIZE 21 #define _LIBUNWIND_CURSOR_SIZE 33 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Recover GLTemplateParameterList for generic lambdas in RebuildLambdaScopeInfo (PR #118176)
https://github.com/zyn0217 created https://github.com/llvm/llvm-project/pull/118176 The NTTP argument appearing inside a trailing return type of a generic lambda would have to check for potential lambda captures, where the function needs GLTemplateParameterList of the current LSI to tell whether the lambda is generic. The lambda scope in this context is rebuilt by the LambdaScopeForCallOperatorInstantiationRAII when substituting the lambda operator during template argument deduction. Thus, I think the template parameter list should be preserved in the rebuilding process, as it seems otherwise innocuous to me. Fixes #115931 >From 6d55d79dc7a67a94be0f72b15f8da90813ebb9fd Mon Sep 17 00:00:00 2001 From: Younan Zhang Date: Sat, 30 Nov 2024 23:23:47 +0800 Subject: [PATCH] [Clang] Recover GLTemplateParameterList for generic lambdas in RebuildLambdaScopeInfo --- clang/docs/ReleaseNotes.rst | 2 ++ clang/lib/Sema/SemaDecl.cpp | 21 --- .../SemaCXX/lambda-capture-type-deduction.cpp | 16 ++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 8bd06fadfdc984..e8e8a8cff76e45 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -714,6 +714,8 @@ Bug Fixes to C++ Support assumption if they also occur inside of a dependent lambda. (#GH114787) - Clang now uses valid deduced type locations when diagnosing functions with trailing return type missing placeholder return type. (#GH78694) +- Fixed an incorrect lambda scope of generic lambdas that caused Clang to crash when computing potential lambda + captures at the end of a full expression. (#GH115931) Bug Fixes to AST Handling ^ diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 74b0e5ad23bd48..75389d6ba7bfd8 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -15504,10 +15504,25 @@ LambdaScopeInfo *Sema::RebuildLambdaScopeInfo(CXXMethodDecl *CallOperator) { LSI->CallOperator = CallOperator; LSI->Lambda = LambdaClass; LSI->ReturnType = CallOperator->getReturnType(); - // This function in calls in situation where the context of the call operator - // is not entered, so we set AfterParameterList to false, so that + // When this function is called in situation where the context of the call + // operator is not entered, we set AfterParameterList to false, so that // `tryCaptureVariable` finds explicit captures in the appropriate context. - LSI->AfterParameterList = false; + // + // There is also at least a situation as in FinishTemplateArgumentDeduction(), + // where we would set the CurContext to the lambda operator before + // substituting into it. In this case the flag needs to be true such that + // tryCaptureVariable can correctly handle potential captures thereof. + LSI->AfterParameterList = CurContext == CallOperator; + // GLTemplateParameterList is necessary for getCurGenericLambda() which is + // used at the point of dealing with potential captures. + // + // We don't use LambdaClass->isGenericLambda() because this value doesn't + // flip for instantiated generic lambdas, where no FunctionTemplateDecls are + // associated. (Technically, we could recover that list from their + // instantiation patterns, but for now, the GLTemplateParameterList seems + // unnecessary in these cases.) + if (FunctionTemplateDecl *FTD = CallOperator->getDescribedFunctionTemplate()) +LSI->GLTemplateParameterList = FTD->getTemplateParameters(); const LambdaCaptureDefault LCD = LambdaClass->getLambdaCaptureDefault(); if (LCD == LCD_None) diff --git a/clang/test/SemaCXX/lambda-capture-type-deduction.cpp b/clang/test/SemaCXX/lambda-capture-type-deduction.cpp index a86f3018989927..234cb6806f041a 100644 --- a/clang/test/SemaCXX/lambda-capture-type-deduction.cpp +++ b/clang/test/SemaCXX/lambda-capture-type-deduction.cpp @@ -298,6 +298,22 @@ void __trans_tmp_1() { } +namespace GH115931 { + +struct Range {}; + +template +struct LengthPercentage {}; + +void reflectSum() { + Range resultR; + [&] (auto) -> LengthPercentage { +return {}; + }(0); +} + +} // namespace GH115931 + namespace GH47400 { struct Foo {}; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [lld] [llvm] [Windows] Add support for emitting PGO/LTO magic strings in the Windows PE debug directory (PR #114260)
aganea wrote: I had a more in-depth look at this. Overall I don't agree with the whole direction of this patch. I don't think it's wise for LLD to emit debug records/`coffgrp` that do not match what MSVC is generating. We can't just blindly emit a record with the string of the debug type (ie. PGI/PGU/LTCG). These strings are headers for opaque/undocumented structures that Microsoft is generating for its tooling (debugger). Unless we're willing to understand and document those structures, so that LLD can emit them proper, I wouldn't emit these `coffgrp` at all. Also as a reference: https://www.hexacorn.com/blog/2015/07/30/gctl-debug-section-in-windows-10-binaries/ https://github.com/llvm/llvm-project/pull/114260 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Add quick fix to automatically adds NOLINTNEXTLINE comment (PR #114661)
chomosuke wrote: Hi @kadircet, I have just started looking into `FeatureModule` and could not find any example of it being used apart from testing. Just want to confirm that this infrastructure isn't currently being used by anything in Clangd. I assume I should extend `FeatureModule` to add my NOLINT fix feature and add it in `ClangMain.cpp` based on command line options. Would that be the correct approach? https://github.com/llvm/llvm-project/pull/114661 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] fix cppcoreguidelines-narrowing-conversions false positives when narrowing integer to signed integer in C++20 (PR #116591)
5chmidti wrote: > Whether it well-defined behavior in C++20 or implementation-defined behavior > pre-C++20 does not seem relevant to me. We could certainly adjust the warning > message to avoid saying it's "implementation-defined" in C++20. +1 > When implementing guidelines, we must make sure we implement exactly what the > guidelines say, and not make them less restrictive (at least not by default). > The user expectation is that a C++ Core Guideline check will implement just > that, not something else. > people can choose if they want to relax the rule or not. > Maybe we should move this check to bugprone and use some configuration to > fulfill guideline in cppcoreguidelines parts. The cppcoreguideline check should implement what the guidelines say, but giving the user choice is a plus. There is no need to move the check to bugprone, because this check is already an alias from the cppcoreguidelines to bugprone. So instead, we could configure the alias in bugprone differently? Right now it is an unconfigured alias. https://github.com/llvm/llvm-project/pull/116591 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Tooling/Inclusion] Update std symbol mapping to v20241111 (PR #118174)
https://github.com/vvd170501 created https://github.com/llvm/llvm-project/pull/118174 None >From 4c2d6a11ad6364182e93686f6e0bc8b834355877 Mon Sep 17 00:00:00 2001 From: Vadim Dudkin Date: Sat, 30 Nov 2024 18:09:23 +0300 Subject: [PATCH] Update std symbol mapping to v2024 --- .../Inclusions/Stdlib/StdSpecialSymbolMap.inc | 8 --- .../Inclusions/Stdlib/StdSymbolMap.inc| 56 +-- 2 files changed, 50 insertions(+), 14 deletions(-) diff --git a/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc b/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc index 8f20ce98152f08..22232a34995f2d 100644 --- a/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc +++ b/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc @@ -389,18 +389,10 @@ SYMBOL(make_error_condition, std::, /*no headers*/) SYMBOL(erase, std::, /*no headers*/) SYMBOL(erase_if, std::, /*no headers*/) -// cppreference symbol index page was missing these symbols. -// Remove them when the cppreference offline archive catches up. -SYMBOL(regular_invocable, std::, ) - // Symbols missing from the generated symbol map as reported by users. // Remove when the generator starts producing them. SYMBOL(div, std::, ) SYMBOL(abort, std::, ) -SYMBOL(atomic_wait, std::, ) -SYMBOL(atomic_wait_explicit, std::, ) -SYMBOL(move_backward, std::, ) -SYMBOL(month_weekday, std::chrono::, ) SYMBOL(binary_search, std::ranges::, ) SYMBOL(equal_range, std::ranges::, ) diff --git a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc index b4afd0228694ff..c1927180d33976 100644 --- a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc +++ b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc @@ -6,7 +6,7 @@ // This file was generated automatically by // clang/tools/include-mapping/gen_std.py, DO NOT EDIT! // -// Generated from cppreference offline HTML book (modified on 2024-06-10). +// Generated from cppreference offline HTML book (modified on 2024-11-10). //===--===// SYMBOL(ATOMIC_BOOL_LOCK_FREE, None, ) @@ -578,6 +578,7 @@ SYMBOL(add_pointer, std::, ) SYMBOL(add_pointer_t, std::, ) SYMBOL(add_rvalue_reference, std::, ) SYMBOL(add_rvalue_reference_t, std::, ) +SYMBOL(add_sat, std::, ) SYMBOL(add_volatile, std::, ) SYMBOL(add_volatile_t, std::, ) SYMBOL(addressof, std::, ) @@ -699,6 +700,10 @@ SYMBOL(atomic_fetch_add, std::, ) SYMBOL(atomic_fetch_add_explicit, std::, ) SYMBOL(atomic_fetch_and, std::, ) SYMBOL(atomic_fetch_and_explicit, std::, ) +SYMBOL(atomic_fetch_max, std::, ) +SYMBOL(atomic_fetch_max_explicit, std::, ) +SYMBOL(atomic_fetch_min, std::, ) +SYMBOL(atomic_fetch_min_explicit, std::, ) SYMBOL(atomic_fetch_or, std::, ) SYMBOL(atomic_fetch_or_explicit, std::, ) SYMBOL(atomic_fetch_sub, std::, ) @@ -727,6 +732,8 @@ SYMBOL(atomic_signal_fence, std::, ) SYMBOL(atomic_store, std::, ) SYMBOL(atomic_store_explicit, std::, ) SYMBOL(atomic_thread_fence, std::, ) +SYMBOL(atomic_wait, std::, ) +SYMBOL(atomic_wait_explicit, std::, ) SYMBOL(atto, std::, ) SYMBOL(auto_ptr, std::, ) SYMBOL(back_insert_iterator, std::, ) @@ -829,6 +836,8 @@ SYMBOL(boolalpha, std::, ) SYMBOL(boolalpha, std::, ) SYMBOL(boyer_moore_horspool_searcher, std::, ) SYMBOL(boyer_moore_searcher, std::, ) +SYMBOL(breakpoint, std::, ) +SYMBOL(breakpoint_if_debugging, std::, ) SYMBOL(bsearch, std::, ) SYMBOL(bsearch, None, ) SYMBOL(bsearch, None, ) @@ -951,6 +960,7 @@ SYMBOL(copy_constructible, std::, ) SYMBOL(copy_if, std::, ) SYMBOL(copy_n, std::, ) SYMBOL(copyable, std::, ) +SYMBOL(copyable_function, std::, ) SYMBOL(copysign, std::, ) SYMBOL(copysign, None, ) SYMBOL(copysign, None, ) @@ -1048,12 +1058,14 @@ SYMBOL(dextents, std::, ) SYMBOL(difftime, std::, ) SYMBOL(difftime, None, ) SYMBOL(difftime, None, ) +SYMBOL(dims, std::, ) SYMBOL(disable_sized_sentinel_for, std::, ) SYMBOL(discard_block_engine, std::, ) SYMBOL(discrete_distribution, std::, ) SYMBOL(disjunction, std::, ) SYMBOL(disjunction_v, std::, ) SYMBOL(distance, std::, ) +SYMBOL(div_sat, std::, ) SYMBOL(div_t, std::, ) SYMBOL(div_t, None, ) SYMBOL(div_t, None, ) @@ -1077,6 +1089,7 @@ SYMBOL(emit_on_flush, std::, ) SYMBOL(emit_on_flush, std::, ) SYMBOL(enable_if, std::, ) SYMBOL(enable_if_t, std::, ) +SYMBOL(enable_nonlocking_formatter_optimization, std::, ) SYMBOL(enable_shared_from_this, std::, ) SYMBOL(endian, std::, ) SYMBOL(endl, std::, ) @@ -1241,8 +1254,7 @@ SYMBOL(fgetwc, None, ) SYMBOL(fgetws, std::, ) SYMBOL(fgetws, None, ) SYMBOL(fgetws, None, ) -SYMBOL(filebuf, std::, ) -SYMBOL(filebuf, std::, ) +SYMBOL(filebuf, std::, ) SYMBOL(filebuf, std::, ) SYMBOL(fill, std::, ) SYMBOL(fill_n, std::, ) @@ -1322,11 +1334,13 @@ SYMBOL(format, std::, ) SYMBOL(format_args, std::, ) SYMBOL(format_context, std::, ) SYMBOL(format_error, std::, ) +SYMBOL(format_kind, std::, ) SYMBOL(format_parse_
[clang] [Tooling/Inclusion] Update std symbol mapping (PR #118174)
https://github.com/vvd170501 edited https://github.com/llvm/llvm-project/pull/118174 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Tooling/Inclusion] Update std symbol mapping (PR #118174)
https://github.com/vvd170501 edited https://github.com/llvm/llvm-project/pull/118174 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Tooling/Inclusion] Update std symbol mapping (PR #118174)
https://github.com/vvd170501 updated https://github.com/llvm/llvm-project/pull/118174 >From 4c2d6a11ad6364182e93686f6e0bc8b834355877 Mon Sep 17 00:00:00 2001 From: Vadim Dudkin Date: Sat, 30 Nov 2024 18:09:23 +0300 Subject: [PATCH 1/2] Update std symbol mapping to v2024 --- .../Inclusions/Stdlib/StdSpecialSymbolMap.inc | 8 --- .../Inclusions/Stdlib/StdSymbolMap.inc| 56 +-- 2 files changed, 50 insertions(+), 14 deletions(-) diff --git a/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc b/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc index 8f20ce98152f08..22232a34995f2d 100644 --- a/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc +++ b/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc @@ -389,18 +389,10 @@ SYMBOL(make_error_condition, std::, /*no headers*/) SYMBOL(erase, std::, /*no headers*/) SYMBOL(erase_if, std::, /*no headers*/) -// cppreference symbol index page was missing these symbols. -// Remove them when the cppreference offline archive catches up. -SYMBOL(regular_invocable, std::, ) - // Symbols missing from the generated symbol map as reported by users. // Remove when the generator starts producing them. SYMBOL(div, std::, ) SYMBOL(abort, std::, ) -SYMBOL(atomic_wait, std::, ) -SYMBOL(atomic_wait_explicit, std::, ) -SYMBOL(move_backward, std::, ) -SYMBOL(month_weekday, std::chrono::, ) SYMBOL(binary_search, std::ranges::, ) SYMBOL(equal_range, std::ranges::, ) diff --git a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc index b4afd0228694ff..c1927180d33976 100644 --- a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc +++ b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc @@ -6,7 +6,7 @@ // This file was generated automatically by // clang/tools/include-mapping/gen_std.py, DO NOT EDIT! // -// Generated from cppreference offline HTML book (modified on 2024-06-10). +// Generated from cppreference offline HTML book (modified on 2024-11-10). //===--===// SYMBOL(ATOMIC_BOOL_LOCK_FREE, None, ) @@ -578,6 +578,7 @@ SYMBOL(add_pointer, std::, ) SYMBOL(add_pointer_t, std::, ) SYMBOL(add_rvalue_reference, std::, ) SYMBOL(add_rvalue_reference_t, std::, ) +SYMBOL(add_sat, std::, ) SYMBOL(add_volatile, std::, ) SYMBOL(add_volatile_t, std::, ) SYMBOL(addressof, std::, ) @@ -699,6 +700,10 @@ SYMBOL(atomic_fetch_add, std::, ) SYMBOL(atomic_fetch_add_explicit, std::, ) SYMBOL(atomic_fetch_and, std::, ) SYMBOL(atomic_fetch_and_explicit, std::, ) +SYMBOL(atomic_fetch_max, std::, ) +SYMBOL(atomic_fetch_max_explicit, std::, ) +SYMBOL(atomic_fetch_min, std::, ) +SYMBOL(atomic_fetch_min_explicit, std::, ) SYMBOL(atomic_fetch_or, std::, ) SYMBOL(atomic_fetch_or_explicit, std::, ) SYMBOL(atomic_fetch_sub, std::, ) @@ -727,6 +732,8 @@ SYMBOL(atomic_signal_fence, std::, ) SYMBOL(atomic_store, std::, ) SYMBOL(atomic_store_explicit, std::, ) SYMBOL(atomic_thread_fence, std::, ) +SYMBOL(atomic_wait, std::, ) +SYMBOL(atomic_wait_explicit, std::, ) SYMBOL(atto, std::, ) SYMBOL(auto_ptr, std::, ) SYMBOL(back_insert_iterator, std::, ) @@ -829,6 +836,8 @@ SYMBOL(boolalpha, std::, ) SYMBOL(boolalpha, std::, ) SYMBOL(boyer_moore_horspool_searcher, std::, ) SYMBOL(boyer_moore_searcher, std::, ) +SYMBOL(breakpoint, std::, ) +SYMBOL(breakpoint_if_debugging, std::, ) SYMBOL(bsearch, std::, ) SYMBOL(bsearch, None, ) SYMBOL(bsearch, None, ) @@ -951,6 +960,7 @@ SYMBOL(copy_constructible, std::, ) SYMBOL(copy_if, std::, ) SYMBOL(copy_n, std::, ) SYMBOL(copyable, std::, ) +SYMBOL(copyable_function, std::, ) SYMBOL(copysign, std::, ) SYMBOL(copysign, None, ) SYMBOL(copysign, None, ) @@ -1048,12 +1058,14 @@ SYMBOL(dextents, std::, ) SYMBOL(difftime, std::, ) SYMBOL(difftime, None, ) SYMBOL(difftime, None, ) +SYMBOL(dims, std::, ) SYMBOL(disable_sized_sentinel_for, std::, ) SYMBOL(discard_block_engine, std::, ) SYMBOL(discrete_distribution, std::, ) SYMBOL(disjunction, std::, ) SYMBOL(disjunction_v, std::, ) SYMBOL(distance, std::, ) +SYMBOL(div_sat, std::, ) SYMBOL(div_t, std::, ) SYMBOL(div_t, None, ) SYMBOL(div_t, None, ) @@ -1077,6 +1089,7 @@ SYMBOL(emit_on_flush, std::, ) SYMBOL(emit_on_flush, std::, ) SYMBOL(enable_if, std::, ) SYMBOL(enable_if_t, std::, ) +SYMBOL(enable_nonlocking_formatter_optimization, std::, ) SYMBOL(enable_shared_from_this, std::, ) SYMBOL(endian, std::, ) SYMBOL(endl, std::, ) @@ -1241,8 +1254,7 @@ SYMBOL(fgetwc, None, ) SYMBOL(fgetws, std::, ) SYMBOL(fgetws, None, ) SYMBOL(fgetws, None, ) -SYMBOL(filebuf, std::, ) -SYMBOL(filebuf, std::, ) +SYMBOL(filebuf, std::, ) SYMBOL(filebuf, std::, ) SYMBOL(fill, std::, ) SYMBOL(fill_n, std::, ) @@ -1322,11 +1334,13 @@ SYMBOL(format, std::, ) SYMBOL(format_args, std::, ) SYMBOL(format_context, std::, ) SYMBOL(format_error, std::, ) +SYMBOL(format_kind, std::, ) SYMBOL(format_parse_co
[clang] [Tooling/Inclusion] Update std symbol mapping (PR #118174)
@@ -1241,8 +1254,7 @@ SYMBOL(fgetwc, None, ) SYMBOL(fgetws, std::, ) SYMBOL(fgetws, None, ) SYMBOL(fgetws, None, ) -SYMBOL(filebuf, std::, ) -SYMBOL(filebuf, std::, ) +SYMBOL(filebuf, std::, ) vvd170501 wrote: Previous versions of cppreference mentioned incorrect headers for `filebuf` and `wfilebuf`. `` is the correct one: https://eel.is/c++draft/fstream.syn#lib:filebuf https://github.com/llvm/llvm-project/pull/118174 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libcxx] [Clang] Add __builtin_invoke and detect std::invoke as a builtin (PR #116709)
https://github.com/philnik777 edited https://github.com/llvm/llvm-project/pull/116709 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] ensure mangled names are valid identifiers before being suggested in ifunc/alias attributes notes (PR #118170)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Oleksandr T. (a-tarasyuk) Changes Fixes #112205 --- Commit that introduced this feature - https://github.com/llvm/llvm-project/commit/9306ef9750b7a319d59f6d3e4977e01e39b8f161 --- Full diff: https://github.com/llvm/llvm-project/pull/118170.diff 3 Files Affected: - (modified) clang/docs/ReleaseNotes.rst (+1) - (modified) clang/lib/CodeGen/CodeGenModule.cpp (+2-1) - (modified) clang/test/CodeGen/alias.cpp (+3) ``diff diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index e44aefa90ab386..5c24471bbf7c93 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -763,6 +763,7 @@ Bug Fixes to C++ Support - Fixed a bug where bounds of partially expanded pack indexing expressions were checked too early. (#GH116105) - Fixed an assertion failure caused by using ``consteval`` in condition in consumed analyses. (#GH117385) - Fix a crash caused by incorrect argument position in merging deduced template arguments. (#GH113659) +- Fixed an assertion failure caused by mangled names with invalid identifiers. (#GH112205) Bug Fixes to AST Handling ^ diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 7189a4689e8156..d3d5c0743a520b 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -602,7 +602,8 @@ static bool checkAliasedGlobal( // mangled name. for (const auto &[Decl, Name] : MangledDeclNames) { if (const auto *ND = dyn_cast(Decl.getDecl())) { -if (ND->getName() == GV->getName()) { +IdentifierInfo *II = ND->getIdentifier(); +if (II && II->getName() == GV->getName()) { Diags.Report(Location, diag::note_alias_mangled_name_alternative) << Name << FixItHint::CreateReplacement( diff --git a/clang/test/CodeGen/alias.cpp b/clang/test/CodeGen/alias.cpp index a468c31d369ed0..43be6b99ce8491 100644 --- a/clang/test/CodeGen/alias.cpp +++ b/clang/test/CodeGen/alias.cpp @@ -26,6 +26,9 @@ __attribute__((unused, alias("resolver"), deprecated("hahahaha, isn't C great?") void func(); // expected-error@-2 {{alias must point to a defined variable or function}} // expected-note@-3 {{must refer to its mangled name}} + +void *operator new(unsigned long) __attribute__((alias("A"))); // expected-error {{alias must point to a defined variable or function}} \ + // expected-note {{the function or variable specified in an alias must refer to its mangled name}} #endif // CHECK: @_ZN4libc4log2Ed ={{.*}} alias double (double), ptr @log2 `` https://github.com/llvm/llvm-project/pull/118170 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libcxx] [Clang] Add __builtin_invoke and detect std::invoke as a builtin (PR #116709)
https://github.com/philnik777 updated https://github.com/llvm/llvm-project/pull/116709 >From 025f937646f190978325c58967ccb02828a78bd2 Mon Sep 17 00:00:00 2001 From: Nikolas Klauser Date: Mon, 18 Nov 2024 16:06:31 +0100 Subject: [PATCH 1/2] [libc++] Define an internal API for std::invoke and friends --- libcxx/include/__algorithm/make_projected.h | 12 +++--- libcxx/include/__functional/bind.h| 22 +-- libcxx/include/__functional/function.h| 11 ++ libcxx/include/__functional/hash.h| 2 +- libcxx/include/__functional/mem_fn.h | 6 +-- .../include/__functional/reference_wrapper.h | 2 +- libcxx/include/__hash_table | 4 +- libcxx/include/__tree | 2 +- libcxx/include/__type_traits/invoke.h | 38 +++ libcxx/include/__type_traits/result_of.h | 4 +- libcxx/include/future | 6 +-- libcxx/include/unordered_map | 4 +- libcxx/include/unordered_set | 4 +- 13 files changed, 76 insertions(+), 41 deletions(-) diff --git a/libcxx/include/__algorithm/make_projected.h b/libcxx/include/__algorithm/make_projected.h index 22cceb4cb2fb85..e2f2e174768ae1 100644 --- a/libcxx/include/__algorithm/make_projected.h +++ b/libcxx/include/__algorithm/make_projected.h @@ -37,16 +37,16 @@ struct _ProjectedPred { : __pred(__pred_arg), __proj(__proj_arg) {} template - typename __invoke_of<_Pred&, decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_Tp>()))>::type - _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI - operator()(_Tp&& __v) const { + __invoke_result_t<_Pred&, decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_Tp>()))> _LIBCPP_CONSTEXPR + _LIBCPP_HIDE_FROM_ABI + operator()(_Tp&& __v) const { return std::__invoke(__pred, std::__invoke(__proj, std::forward<_Tp>(__v))); } template - typename __invoke_of<_Pred&, - decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_T1>())), - decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_T2>()))>::type _LIBCPP_CONSTEXPR + __invoke_result_t<_Pred&, +decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_T1>())), +decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_T2>()))> _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI operator()(_T1&& __lhs, _T2&& __rhs) const { return std::__invoke( diff --git a/libcxx/include/__functional/bind.h b/libcxx/include/__functional/bind.h index f82c1517249b16..54ec0062932cbf 100644 --- a/libcxx/include/__functional/bind.h +++ b/libcxx/include/__functional/bind.h @@ -82,13 +82,13 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp& __mu(reference_w } template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename __invoke_of<_Ti&, _Uj...>::type +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __invoke_result_t<_Ti&, _Uj...> __mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>) { return __ti(std::forward<_Uj>(std::get<_Indx>(__uj))...); } template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename __invoke_of<_Ti&, _Uj...>::type +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __invoke_result_t<_Ti&, _Uj...> __mu(_Ti& __ti, tuple<_Uj...>& __uj) { typedef typename __make_tuple_indices::type __indices; return std::__mu_expand(__ti, __uj, __indices()); @@ -130,12 +130,12 @@ struct __mu_return_invokable // false template struct __mu_return_invokable { - typedef typename __invoke_of<_Ti&, _Uj...>::type type; + using type = __invoke_result_t<_Ti&, _Uj...>; }; template struct __mu_return_impl<_Ti, false, true, false, tuple<_Uj...> > -: public __mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...> {}; +: public __mu_return_invokable<__is_invocable_v<_Ti&, _Uj...>, _Ti, _Uj...> {}; template struct __mu_return_impl<_Ti, false, false, true, _TupleUj> { @@ -168,12 +168,12 @@ struct __is_valid_bind_return { template struct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj> { - static const bool value = __invokable<_Fp, typename __mu_return<_BoundArgs, _TupleUj>::type...>::value; + static const bool value = __is_invocable_v<_Fp, typename __mu_return<_BoundArgs, _TupleUj>::type...>; }; template struct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj> { - static const bool value = __invokable<_Fp, typename __mu_return::type...>::value; + static const bool value = __is_invocable_v<_Fp, typename __mu_return::type...>; }; template ::value> @@ -181,12 +181,12 @@ struct __bind_return; template struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true> { - typedef typename __invoke_of< _Fp&, typename __mu_return< _BoundArgs, _TupleUj >::type... >::type type; + using type = __invoke
[clang] [Clang] ensure mangled names are valid identifiers before being suggested in ifunc/alias attributes notes (PR #118170)
https://github.com/a-tarasyuk created https://github.com/llvm/llvm-project/pull/118170 Fixes #112205 --- Commit that introduced this feature - https://github.com/llvm/llvm-project/commit/9306ef9750b7a319d59f6d3e4977e01e39b8f161 >From f667cf6d39845ae7143ec6481297b7bb41b313fe Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Sat, 30 Nov 2024 15:33:30 +0200 Subject: [PATCH] [Clang] ensure mangled names are valid identifiers before being suggested in ifunc/alias attributes notes --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/CodeGen/CodeGenModule.cpp | 3 ++- clang/test/CodeGen/alias.cpp| 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index e44aefa90ab386..5c24471bbf7c93 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -763,6 +763,7 @@ Bug Fixes to C++ Support - Fixed a bug where bounds of partially expanded pack indexing expressions were checked too early. (#GH116105) - Fixed an assertion failure caused by using ``consteval`` in condition in consumed analyses. (#GH117385) - Fix a crash caused by incorrect argument position in merging deduced template arguments. (#GH113659) +- Fixed an assertion failure caused by mangled names with invalid identifiers. (#GH112205) Bug Fixes to AST Handling ^ diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 7189a4689e8156..d3d5c0743a520b 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -602,7 +602,8 @@ static bool checkAliasedGlobal( // mangled name. for (const auto &[Decl, Name] : MangledDeclNames) { if (const auto *ND = dyn_cast(Decl.getDecl())) { -if (ND->getName() == GV->getName()) { +IdentifierInfo *II = ND->getIdentifier(); +if (II && II->getName() == GV->getName()) { Diags.Report(Location, diag::note_alias_mangled_name_alternative) << Name << FixItHint::CreateReplacement( diff --git a/clang/test/CodeGen/alias.cpp b/clang/test/CodeGen/alias.cpp index a468c31d369ed0..43be6b99ce8491 100644 --- a/clang/test/CodeGen/alias.cpp +++ b/clang/test/CodeGen/alias.cpp @@ -26,6 +26,9 @@ __attribute__((unused, alias("resolver"), deprecated("hahahaha, isn't C great?") void func(); // expected-error@-2 {{alias must point to a defined variable or function}} // expected-note@-3 {{must refer to its mangled name}} + +void *operator new(unsigned long) __attribute__((alias("A"))); // expected-error {{alias must point to a defined variable or function}} \ + // expected-note {{the function or variable specified in an alias must refer to its mangled name}} #endif // CHECK: @_ZN4libc4log2Ed ={{.*}} alias double (double), ptr @log2 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] f89fa23 - [clang-tidy][use-internal-linkage]fix false positives for global overloaded operator new and operator delete (#117945)
Author: Congcong Cai Date: 2024-11-30T22:14:36+08:00 New Revision: f89fa238faa6a63168997a8a1d03c15b71da8080 URL: https://github.com/llvm/llvm-project/commit/f89fa238faa6a63168997a8a1d03c15b71da8080 DIFF: https://github.com/llvm/llvm-project/commit/f89fa238faa6a63168997a8a1d03c15b71da8080.diff LOG: [clang-tidy][use-internal-linkage]fix false positives for global overloaded operator new and operator delete (#117945) Added: Modified: clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp clang-tools-extra/docs/ReleaseNotes.rst clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-func.cpp Removed: diff --git a/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp b/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp index 71eb2d94cd4f26..0c417f6374bc50 100644 --- a/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp @@ -15,7 +15,9 @@ #include "clang/Basic/SourceLocation.h" #include "clang/Basic/Specifiers.h" #include "clang/Lex/Token.h" +#include "llvm/ADT/DenseSet.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallVector.h" using namespace clang::ast_matchers; @@ -78,6 +80,22 @@ AST_POLYMORPHIC_MATCHER(isExternStorageClass, return Node.getStorageClass() == SC_Extern; } +AST_MATCHER(FunctionDecl, isAllocationOrDeallocationOverloadedFunction) { + // [basic.stc.dynamic.allocation] + // An allocation function that is not a class member function shall belong to + // the global scope and not have a name with internal linkage. + // [basic.stc.dynamic.deallocation] + // A deallocation function that is not a class member function shall belong to + // the global scope and not have a name with internal linkage. + static const llvm::DenseSet OverloadedOperators{ + OverloadedOperatorKind::OO_New, + OverloadedOperatorKind::OO_Array_New, + OverloadedOperatorKind::OO_Delete, + OverloadedOperatorKind::OO_Array_Delete, + }; + return OverloadedOperators.contains(Node.getOverloadedOperator()); +} + } // namespace UseInternalLinkageCheck::UseInternalLinkageCheck(StringRef Name, @@ -103,7 +121,10 @@ void UseInternalLinkageCheck::registerMatchers(MatchFinder *Finder) { // 4. friend hasAncestor(friendDecl(); Finder->addMatcher( - functionDecl(Common, hasBody(), unless(cxxMethodDecl()), unless(isMain())) + functionDecl(Common, hasBody(), + unless(anyOf(cxxMethodDecl(), +isAllocationOrDeallocationOverloadedFunction(), +isMain( .bind("fn"), this); Finder->addMatcher(varDecl(Common, hasGlobalStorage()).bind("var"), this); diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 62577b9248fef3..ec666aeb2ad8ab 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -247,7 +247,8 @@ Changes in existing checks - Improved :doc:`misc-use-internal-linkage ` check to insert ``static`` keyword before type qualifiers such as ``const`` and ``volatile`` and fix - false positives for function declaration without body. + false positives for function declaration without body and fix false positives + for global scoped overloaded ``operator new`` and ``operator delete``. - Improved :doc:`modernize-avoid-c-arrays ` check to suggest using diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-func.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-func.cpp index bf0d2c2513e562..68951fcf0aaac9 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-func.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-func.cpp @@ -85,3 +85,13 @@ void func_with_body() {} void func_without_body(); void func_without_body(); } + +// gh117489 start +namespace std { +using size_t = decltype(sizeof(int)); +} +void * operator new(std::size_t) { return nullptr; } +void * operator new[](std::size_t) { return nullptr; } +void operator delete(void*) noexcept {} +void operator delete[](void*) noexcept {} +// gh117489 end ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][use-internal-linkage]fix false positives for global overloaded operator new and operator delete (PR #117945)
https://github.com/HerrCai0907 closed https://github.com/llvm/llvm-project/pull/117945 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [clang-tidy][use-internal-linkage]fix false positives for ExportDecl (PR #117901)
HerrCai0907 wrote: > Please add the matcher to > https://github.com/llvm/llvm-project/blob/main/clang/lib/ASTMatchers/Dynamic/Registry.cpp > as well (clang-query). i will do it separately to avoid this pr become bigger. https://github.com/llvm/llvm-project/pull/117901 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [clang-tidy][use-internal-linkage]fix false positives for ExportDecl (PR #117901)
https://github.com/PiotrZSL approved this pull request. https://github.com/llvm/llvm-project/pull/117901 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [clang-tidy][use-internal-linkage]fix false positives for ExportDecl (PR #117901)
@@ -926,6 +926,8 @@ AST Matchers - Ensure ``hasName`` matches template specializations across inline namespaces, making `matchesNodeFullSlow` and `matchesNodeFullFast` consistent. +- Add ``exportDecl`` matches export declaration. 5chmidti wrote: > Add a `exportDecl` matcher to match export declarations. https://github.com/llvm/llvm-project/pull/117901 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [clang-tidy][use-internal-linkage]fix false positives for ExportDecl (PR #117901)
https://github.com/5chmidti commented: Please add the matcher to https://github.com/llvm/llvm-project/blob/main/clang/lib/ASTMatchers/Dynamic/Registry.cpp as well (clang-query). https://github.com/llvm/llvm-project/pull/117901 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [clang-tidy][use-internal-linkage]fix false positives for ExportDecl (PR #117901)
https://github.com/5chmidti edited https://github.com/llvm/llvm-project/pull/117901 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Add quick fix to automatically adds NOLINTNEXTLINE comment (PR #114661)
https://github.com/chomosuke closed https://github.com/llvm/llvm-project/pull/114661 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add readability-use-span-first-last check (PR #118074)
@@ -0,0 +1,110 @@ +//===--- UseSpanFirstLastCheck.cpp - clang-tidy-*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "UseSpanFirstLastCheck.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/ASTMatchers/ASTMatchers.h" +#include "clang/Lex/Lexer.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::readability { + +void UseSpanFirstLastCheck::registerMatchers(MatchFinder *Finder) { + if (!getLangOpts().CPlusPlus20) +return; + + // Match span::subspan calls + const auto HasSpanType = + hasType(hasUnqualifiedDesugaredType(recordType(hasDeclaration( + classTemplateSpecializationDecl(hasName("::std::span")); + + Finder->addMatcher(cxxMemberCallExpr(callee(memberExpr(hasDeclaration( + cxxMethodDecl(hasName("subspan"), + on(expr(HasSpanType))) + .bind("subspan"), + this); +} + +void UseSpanFirstLastCheck::check(const MatchFinder::MatchResult &Result) { + const auto *Call = Result.Nodes.getNodeAs("subspan"); + if (!Call) +return; + + handleSubspanCall(Result, Call); +} + +void UseSpanFirstLastCheck::handleSubspanCall( +const MatchFinder::MatchResult &Result, const CXXMemberCallExpr *Call) { + unsigned NumArgs = Call->getNumArgs(); + if (NumArgs == 0 || NumArgs > 2) +return; + + const Expr *Offset = Call->getArg(0); + const Expr *Count = NumArgs > 1 ? Call->getArg(1) : nullptr; + auto &Context = *Result.Context; + + // Check if this is subspan(0, n) -> first(n) + bool IsZeroOffset = false; + const Expr *OffsetE = Offset->IgnoreImpCasts(); + if (const auto *IL = dyn_cast(OffsetE)) { +IsZeroOffset = IL->getValue() == 0; + } + + // Check if this is subspan(size() - n) -> last(n) + bool IsSizeMinusN = false; + const Expr *SizeMinusArg = nullptr; + if (const auto *BO = dyn_cast(OffsetE)) { +if (BO->getOpcode() == BO_Sub) { + if (const auto *SizeCall = dyn_cast(BO->getLHS())) { +if (SizeCall->getMethodDecl()->getName() == "size") { + IsSizeMinusN = true; + SizeMinusArg = BO->getRHS(); +} + } +} + } + + // Build replacement text + std::string Replacement; 5chmidti wrote: This replacement should be possible to do without the need to go through the lexer, and just replace the needed parts instead. As in, replace from `substr` until before the `n` with `first(/last(` (though that would be problematic with a macro that does `#define K s.size() - 3`, because the `3` would be inside the macro (location wise))... https://github.com/llvm/llvm-project/pull/118074 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add readability-use-span-first-last check (PR #118074)
https://github.com/5chmidti requested changes to this pull request. It would be great to have this check work with uninstantiated templates and use `TK_TraversUnlessSpelledInSource` as well. Here is an example of a matcher for the uninstantiated case: https://godbolt.org/z/1xnGGj7z9 I couldn't fully write it, because there is no matcher to get the member information and constrain it to `subspan`. -- Please also adjust your PR comment to reflect the change for what pattern is matched in the `last` case. --- Overall a good readability improvement check, nice https://github.com/llvm/llvm-project/pull/118074 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add readability-use-span-first-last check (PR #118074)
@@ -0,0 +1,110 @@ +//===--- UseSpanFirstLastCheck.cpp - clang-tidy-*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "UseSpanFirstLastCheck.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/ASTMatchers/ASTMatchers.h" +#include "clang/Lex/Lexer.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::readability { + +void UseSpanFirstLastCheck::registerMatchers(MatchFinder *Finder) { + if (!getLangOpts().CPlusPlus20) +return; + + // Match span::subspan calls + const auto HasSpanType = + hasType(hasUnqualifiedDesugaredType(recordType(hasDeclaration( + classTemplateSpecializationDecl(hasName("::std::span")); + + Finder->addMatcher(cxxMemberCallExpr(callee(memberExpr(hasDeclaration( + cxxMethodDecl(hasName("subspan"), + on(expr(HasSpanType))) + .bind("subspan"), + this); +} + +void UseSpanFirstLastCheck::check(const MatchFinder::MatchResult &Result) { + const auto *Call = Result.Nodes.getNodeAs("subspan"); + if (!Call) +return; + + handleSubspanCall(Result, Call); +} + +void UseSpanFirstLastCheck::handleSubspanCall( +const MatchFinder::MatchResult &Result, const CXXMemberCallExpr *Call) { + unsigned NumArgs = Call->getNumArgs(); + if (NumArgs == 0 || NumArgs > 2) +return; + + const Expr *Offset = Call->getArg(0); + const Expr *Count = NumArgs > 1 ? Call->getArg(1) : nullptr; + auto &Context = *Result.Context; + + // Check if this is subspan(0, n) -> first(n) + bool IsZeroOffset = false; + const Expr *OffsetE = Offset->IgnoreImpCasts(); + if (const auto *IL = dyn_cast(OffsetE)) { +IsZeroOffset = IL->getValue() == 0; + } + + // Check if this is subspan(size() - n) -> last(n) + bool IsSizeMinusN = false; + const Expr *SizeMinusArg = nullptr; + if (const auto *BO = dyn_cast(OffsetE)) { +if (BO->getOpcode() == BO_Sub) { + if (const auto *SizeCall = dyn_cast(BO->getLHS())) { +if (SizeCall->getMethodDecl()->getName() == "size") { + IsSizeMinusN = true; + SizeMinusArg = BO->getRHS(); +} + } +} + } + + // Build replacement text + std::string Replacement; + if (IsZeroOffset && Count) { +// subspan(0, count) -> first(count) +auto CountStr = Lexer::getSourceText( 5chmidti wrote: Please add `const` https://github.com/llvm/llvm-project/pull/118074 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add readability-use-span-first-last check (PR #118074)
@@ -0,0 +1,110 @@ +//===--- UseSpanFirstLastCheck.cpp - clang-tidy-*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "UseSpanFirstLastCheck.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/ASTMatchers/ASTMatchers.h" +#include "clang/Lex/Lexer.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::readability { + +void UseSpanFirstLastCheck::registerMatchers(MatchFinder *Finder) { + if (!getLangOpts().CPlusPlus20) +return; + + // Match span::subspan calls + const auto HasSpanType = + hasType(hasUnqualifiedDesugaredType(recordType(hasDeclaration( + classTemplateSpecializationDecl(hasName("::std::span")); + + Finder->addMatcher(cxxMemberCallExpr(callee(memberExpr(hasDeclaration( + cxxMethodDecl(hasName("subspan"), + on(expr(HasSpanType))) + .bind("subspan"), + this); +} + +void UseSpanFirstLastCheck::check(const MatchFinder::MatchResult &Result) { + const auto *Call = Result.Nodes.getNodeAs("subspan"); + if (!Call) +return; + + handleSubspanCall(Result, Call); +} + +void UseSpanFirstLastCheck::handleSubspanCall( +const MatchFinder::MatchResult &Result, const CXXMemberCallExpr *Call) { + unsigned NumArgs = Call->getNumArgs(); + if (NumArgs == 0 || NumArgs > 2) +return; + + const Expr *Offset = Call->getArg(0); + const Expr *Count = NumArgs > 1 ? Call->getArg(1) : nullptr; + auto &Context = *Result.Context; + + // Check if this is subspan(0, n) -> first(n) + bool IsZeroOffset = false; + const Expr *OffsetE = Offset->IgnoreImpCasts(); + if (const auto *IL = dyn_cast(OffsetE)) { +IsZeroOffset = IL->getValue() == 0; + } + + // Check if this is subspan(size() - n) -> last(n) + bool IsSizeMinusN = false; + const Expr *SizeMinusArg = nullptr; + if (const auto *BO = dyn_cast(OffsetE)) { +if (BO->getOpcode() == BO_Sub) { + if (const auto *SizeCall = dyn_cast(BO->getLHS())) { +if (SizeCall->getMethodDecl()->getName() == "size") { + IsSizeMinusN = true; + SizeMinusArg = BO->getRHS(); +} + } +} + } + + // Build replacement text + std::string Replacement; + if (IsZeroOffset && Count) { +// subspan(0, count) -> first(count) +auto CountStr = Lexer::getSourceText( +CharSourceRange::getTokenRange(Count->getSourceRange()), +Context.getSourceManager(), Context.getLangOpts()); +const auto *Base = +cast(Call)->getImplicitObjectArgument(); +auto BaseStr = Lexer::getSourceText( +CharSourceRange::getTokenRange(Base->getSourceRange()), +Context.getSourceManager(), Context.getLangOpts()); +Replacement = BaseStr.str() + ".first(" + CountStr.str() + ")"; + } else if (IsSizeMinusN && SizeMinusArg) { +// subspan(size() - n) -> last(n) +auto ArgStr = Lexer::getSourceText( +CharSourceRange::getTokenRange(SizeMinusArg->getSourceRange()), +Context.getSourceManager(), Context.getLangOpts()); +const auto *Base = +cast(Call)->getImplicitObjectArgument(); +auto BaseStr = Lexer::getSourceText( +CharSourceRange::getTokenRange(Base->getSourceRange()), +Context.getSourceManager(), Context.getLangOpts()); +Replacement = BaseStr.str() + ".last(" + ArgStr.str() + ")"; + } + + if (!Replacement.empty()) { +if (IsZeroOffset && Count) { + diag(Call->getBeginLoc(), "prefer span::first() over subspan()") + << FixItHint::CreateReplacement(Call->getSourceRange(), Replacement); +} else { + diag(Call->getBeginLoc(), "prefer span::last() over subspan()") + << FixItHint::CreateReplacement(Call->getSourceRange(), Replacement); 5chmidti wrote: Names from code should be put into `'` inside of diagnostics. (Because it's the default behavior when streaming named AST nodes into diagnostics) https://github.com/llvm/llvm-project/pull/118074 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add readability-use-span-first-last check (PR #118074)
5chmidti wrote: Please add tests with macros involved (e.g., fully wrapped `#define F(obj, n)...` or `#define N 2`, etc), and with templates https://github.com/llvm/llvm-project/pull/118074 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add readability-use-span-first-last check (PR #118074)
https://github.com/5chmidti edited https://github.com/llvm/llvm-project/pull/118074 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add readability-use-span-first-last check (PR #118074)
@@ -0,0 +1,110 @@ +//===--- UseSpanFirstLastCheck.cpp - clang-tidy-*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "UseSpanFirstLastCheck.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/ASTMatchers/ASTMatchers.h" +#include "clang/Lex/Lexer.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::readability { + +void UseSpanFirstLastCheck::registerMatchers(MatchFinder *Finder) { + if (!getLangOpts().CPlusPlus20) +return; 5chmidti wrote: This should be done in `isLanguageVersionSupported` instead: https://github.com/llvm/llvm-project/blob/a8a494faab8af60754c4647dbb7b24bc86a80aab/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.h#L26-L28 https://github.com/llvm/llvm-project/pull/118074 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add readability-use-span-first-last check (PR #118074)
@@ -0,0 +1,110 @@ +//===--- UseSpanFirstLastCheck.cpp - clang-tidy-*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "UseSpanFirstLastCheck.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/ASTMatchers/ASTMatchers.h" +#include "clang/Lex/Lexer.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::readability { + +void UseSpanFirstLastCheck::registerMatchers(MatchFinder *Finder) { + if (!getLangOpts().CPlusPlus20) +return; + + // Match span::subspan calls + const auto HasSpanType = + hasType(hasUnqualifiedDesugaredType(recordType(hasDeclaration( + classTemplateSpecializationDecl(hasName("::std::span")); + + Finder->addMatcher(cxxMemberCallExpr(callee(memberExpr(hasDeclaration( + cxxMethodDecl(hasName("subspan"), + on(expr(HasSpanType))) + .bind("subspan"), + this); +} + +void UseSpanFirstLastCheck::check(const MatchFinder::MatchResult &Result) { + const auto *Call = Result.Nodes.getNodeAs("subspan"); + if (!Call) +return; + + handleSubspanCall(Result, Call); +} + +void UseSpanFirstLastCheck::handleSubspanCall( +const MatchFinder::MatchResult &Result, const CXXMemberCallExpr *Call) { + unsigned NumArgs = Call->getNumArgs(); + if (NumArgs == 0 || NumArgs > 2) +return; + + const Expr *Offset = Call->getArg(0); + const Expr *Count = NumArgs > 1 ? Call->getArg(1) : nullptr; + auto &Context = *Result.Context; + + // Check if this is subspan(0, n) -> first(n) + bool IsZeroOffset = false; + const Expr *OffsetE = Offset->IgnoreImpCasts(); + if (const auto *IL = dyn_cast(OffsetE)) { +IsZeroOffset = IL->getValue() == 0; + } + + // Check if this is subspan(size() - n) -> last(n) + bool IsSizeMinusN = false; + const Expr *SizeMinusArg = nullptr; + if (const auto *BO = dyn_cast(OffsetE)) { +if (BO->getOpcode() == BO_Sub) { + if (const auto *SizeCall = dyn_cast(BO->getLHS())) { +if (SizeCall->getMethodDecl()->getName() == "size") { + IsSizeMinusN = true; + SizeMinusArg = BO->getRHS(); +} + } +} + } + + // Build replacement text + std::string Replacement; + if (IsZeroOffset && Count) { +// subspan(0, count) -> first(count) +auto CountStr = Lexer::getSourceText( +CharSourceRange::getTokenRange(Count->getSourceRange()), +Context.getSourceManager(), Context.getLangOpts()); +const auto *Base = +cast(Call)->getImplicitObjectArgument(); +auto BaseStr = Lexer::getSourceText( 5chmidti wrote: Please add `const` https://github.com/llvm/llvm-project/pull/118074 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add readability-use-span-first-last check (PR #118074)
@@ -0,0 +1,110 @@ +//===--- UseSpanFirstLastCheck.cpp - clang-tidy-*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "UseSpanFirstLastCheck.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/ASTMatchers/ASTMatchers.h" +#include "clang/Lex/Lexer.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::readability { + +void UseSpanFirstLastCheck::registerMatchers(MatchFinder *Finder) { + if (!getLangOpts().CPlusPlus20) +return; + + // Match span::subspan calls + const auto HasSpanType = + hasType(hasUnqualifiedDesugaredType(recordType(hasDeclaration( + classTemplateSpecializationDecl(hasName("::std::span")); + + Finder->addMatcher(cxxMemberCallExpr(callee(memberExpr(hasDeclaration( + cxxMethodDecl(hasName("subspan"), + on(expr(HasSpanType))) + .bind("subspan"), + this); +} + +void UseSpanFirstLastCheck::check(const MatchFinder::MatchResult &Result) { + const auto *Call = Result.Nodes.getNodeAs("subspan"); + if (!Call) +return; + + handleSubspanCall(Result, Call); +} + +void UseSpanFirstLastCheck::handleSubspanCall( +const MatchFinder::MatchResult &Result, const CXXMemberCallExpr *Call) { + unsigned NumArgs = Call->getNumArgs(); + if (NumArgs == 0 || NumArgs > 2) +return; + + const Expr *Offset = Call->getArg(0); + const Expr *Count = NumArgs > 1 ? Call->getArg(1) : nullptr; + auto &Context = *Result.Context; + + // Check if this is subspan(0, n) -> first(n) + bool IsZeroOffset = false; + const Expr *OffsetE = Offset->IgnoreImpCasts(); + if (const auto *IL = dyn_cast(OffsetE)) { +IsZeroOffset = IL->getValue() == 0; + } 5chmidti wrote: nit: simple single-expr `if`-bodies don't use braces in LLVM https://github.com/llvm/llvm-project/pull/118074 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add readability-use-span-first-last check (PR #118074)
5chmidti wrote: You removed this by mistake, it's from another check https://github.com/llvm/llvm-project/pull/118074 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add readability-use-span-first-last check (PR #118074)
@@ -0,0 +1,110 @@ +//===--- UseSpanFirstLastCheck.cpp - clang-tidy-*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "UseSpanFirstLastCheck.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/ASTMatchers/ASTMatchers.h" +#include "clang/Lex/Lexer.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::readability { + +void UseSpanFirstLastCheck::registerMatchers(MatchFinder *Finder) { + if (!getLangOpts().CPlusPlus20) +return; + + // Match span::subspan calls + const auto HasSpanType = + hasType(hasUnqualifiedDesugaredType(recordType(hasDeclaration( + classTemplateSpecializationDecl(hasName("::std::span")); + + Finder->addMatcher(cxxMemberCallExpr(callee(memberExpr(hasDeclaration( + cxxMethodDecl(hasName("subspan"), + on(expr(HasSpanType))) + .bind("subspan"), + this); +} + +void UseSpanFirstLastCheck::check(const MatchFinder::MatchResult &Result) { + const auto *Call = Result.Nodes.getNodeAs("subspan"); + if (!Call) +return; + + handleSubspanCall(Result, Call); +} + +void UseSpanFirstLastCheck::handleSubspanCall( +const MatchFinder::MatchResult &Result, const CXXMemberCallExpr *Call) { + unsigned NumArgs = Call->getNumArgs(); + if (NumArgs == 0 || NumArgs > 2) +return; + + const Expr *Offset = Call->getArg(0); + const Expr *Count = NumArgs > 1 ? Call->getArg(1) : nullptr; + auto &Context = *Result.Context; + + // Check if this is subspan(0, n) -> first(n) + bool IsZeroOffset = false; + const Expr *OffsetE = Offset->IgnoreImpCasts(); + if (const auto *IL = dyn_cast(OffsetE)) { +IsZeroOffset = IL->getValue() == 0; + } + + // Check if this is subspan(size() - n) -> last(n) + bool IsSizeMinusN = false; + const Expr *SizeMinusArg = nullptr; + if (const auto *BO = dyn_cast(OffsetE)) { +if (BO->getOpcode() == BO_Sub) { + if (const auto *SizeCall = dyn_cast(BO->getLHS())) { +if (SizeCall->getMethodDecl()->getName() == "size") { 5chmidti wrote: Please merge each pair of matching `if`s to reduce nesting (e.g. `if (const auto*p...; p && ...)`) https://github.com/llvm/llvm-project/pull/118074 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add readability-use-span-first-last check (PR #118074)
https://github.com/5chmidti edited https://github.com/llvm/llvm-project/pull/118074 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add readability-use-span-first-last check (PR #118074)
@@ -0,0 +1,44 @@ +//===--- UseSpanFirstLastCheck.h - clang-tidy---*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_USESPANFIRSTLASTCHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_USESPANFIRSTLASTCHECK_H + +#include "../ClangTidyCheck.h" + +namespace clang::tidy::readability { + +/// Suggests using clearer std::span member functions first()/last() instead of +/// equivalent subspan() calls where applicable. 5chmidti wrote: Please escape the function/class names with `'` https://github.com/llvm/llvm-project/pull/118074 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Add readability-use-span-first-last check (PR #118074)
@@ -172,6 +173,8 @@ class ReadabilityModule : public ClangTidyModule { "readability-use-anyofallof"); CheckFactories.registerCheck( "readability-use-std-min-max"); +CheckFactories.registerCheck( +"readability-use-span-first-last"); 5chmidti wrote: Please move this up one entry, so that the list is alphabetically sorted https://github.com/llvm/llvm-project/pull/118074 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AArch64][SME] Fix bug on SMELd1St1 (PR #118109)
wwwatermiao wrote: Hi, @tuliom, can you help review my patch plz? Thank you! https://github.com/llvm/llvm-project/pull/118109 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Revert [Clang] prevent errors for deduction guides using deduced type aliases (PR #118165)
https://github.com/a-tarasyuk created https://github.com/llvm/llvm-project/pull/118165 Reverts https://github.com/llvm/llvm-project/pull/117450 --- https://github.com/llvm/llvm-project/issues/54909#issuecomment-2508418355 https://github.com/llvm/llvm-project/pull/117450#issuecomment-2508796132 >From a8235518c9326c7e3c28931313d5d4344ce8c031 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Sat, 30 Nov 2024 11:38:10 +0200 Subject: [PATCH] Revert [Clang] prevent errors for deduction guides using deduced type aliases --- clang/docs/ReleaseNotes.rst | 3 -- clang/lib/Sema/SemaDeclCXX.cpp | 40 +--- clang/test/CXX/temp/temp.deduct.guide/p3.cpp | 10 + 3 files changed, 18 insertions(+), 35 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index e44aefa90ab386..d867f2ea3e8e2e 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -624,9 +624,6 @@ Improvements to Clang's diagnostics - Fixed a false negative ``-Wunused-private-field`` diagnostic when a defaulted comparison operator is defined out of class (#GH116961). -- Clang now supports using alias templates in deduction guides, aligning with the C++ standard, - which treats alias templates as synonyms for their underlying types (#GH54909). - - Clang now diagnoses dangling references for C++20's parenthesized aggregate initialization (#101957). Improvements to Clang's time-trace diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index c2ae9a9d5e1a0c..7e8e321c4b90e6 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -11451,29 +11451,23 @@ bool Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R, bool MightInstantiateToSpecialization = false; if (auto RetTST = TSI->getTypeLoc().getAsAdjusted()) { - const TemplateSpecializationType *TST = RetTST.getTypePtr(); - while (TST && TST->isTypeAlias()) -TST = TST->getAliasedType()->getAs(); - - if (TST) { -TemplateName SpecifiedName = TST->getTemplateName(); -bool TemplateMatches = Context.hasSameTemplateName( -SpecifiedName, GuidedTemplate, /*IgnoreDeduced=*/true); - -const QualifiedTemplateName *Qualifiers = -SpecifiedName.getAsQualifiedTemplateName(); -assert(Qualifiers && "expected QualifiedTemplate"); -bool SimplyWritten = !Qualifiers->hasTemplateKeyword() && - Qualifiers->getQualifier() == nullptr; -if (SimplyWritten && TemplateMatches) - AcceptableReturnType = true; -else { - // This could still instantiate to the right type, unless we know it - // names the wrong class template. - auto *TD = SpecifiedName.getAsTemplateDecl(); - MightInstantiateToSpecialization = - !(TD && isa(TD) && !TemplateMatches); -} + TemplateName SpecifiedName = RetTST.getTypePtr()->getTemplateName(); + bool TemplateMatches = Context.hasSameTemplateName( + SpecifiedName, GuidedTemplate, /*IgnoreDeduced=*/true); + + const QualifiedTemplateName *Qualifiers = + SpecifiedName.getAsQualifiedTemplateName(); + assert(Qualifiers && "expected QualifiedTemplate"); + bool SimplyWritten = !Qualifiers->hasTemplateKeyword() && + Qualifiers->getQualifier() == nullptr; + if (SimplyWritten && TemplateMatches) +AcceptableReturnType = true; + else { +// This could still instantiate to the right type, unless we know it +// names the wrong class template. +auto *TD = SpecifiedName.getAsTemplateDecl(); +MightInstantiateToSpecialization = +!(TD && isa(TD) && !TemplateMatches); } } else if (!RetTy.hasQualifiers() && RetTy->isDependentType()) { MightInstantiateToSpecialization = true; diff --git a/clang/test/CXX/temp/temp.deduct.guide/p3.cpp b/clang/test/CXX/temp/temp.deduct.guide/p3.cpp index 195ba2831439d0..c5404847beb066 100644 --- a/clang/test/CXX/temp/temp.deduct.guide/p3.cpp +++ b/clang/test/CXX/temp/temp.deduct.guide/p3.cpp @@ -33,7 +33,7 @@ template typename TT> struct E { // expected-note 2{{template }; A(int) -> int; // expected-error {{deduced type 'int' of deduction guide is not a specialization of template 'A'}} -template A(T)->B; +template A(T)->B; // expected-error {{deduced type 'B' (aka 'A') of deduction guide is not written as a specialization of template 'A'}} template A(T*) -> const A; // expected-error {{deduced type 'const A' of deduction guide is not a specialization of template 'A'}} // A deduction-guide shall be declared in the same scope as the corresponding @@ -71,11 +71,3 @@ namespace WrongScope { Local(int) -> Local; // expected-error {{expected}} } } - -namespace GH54909 { -template struct A {}; -struct B {}; - -template using C = B; -templ
[clang] Revert [Clang] prevent errors for deduction guides using deduced type aliases (PR #118165)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Oleksandr T. (a-tarasyuk) Changes Reverts https://github.com/llvm/llvm-project/pull/117450 --- https://github.com/llvm/llvm-project/issues/54909#issuecomment-2508418355 https://github.com/llvm/llvm-project/pull/117450#issuecomment-2508796132 --- Full diff: https://github.com/llvm/llvm-project/pull/118165.diff 3 Files Affected: - (modified) clang/docs/ReleaseNotes.rst (-3) - (modified) clang/lib/Sema/SemaDeclCXX.cpp (+17-23) - (modified) clang/test/CXX/temp/temp.deduct.guide/p3.cpp (+1-9) ``diff diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index e44aefa90ab386..d867f2ea3e8e2e 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -624,9 +624,6 @@ Improvements to Clang's diagnostics - Fixed a false negative ``-Wunused-private-field`` diagnostic when a defaulted comparison operator is defined out of class (#GH116961). -- Clang now supports using alias templates in deduction guides, aligning with the C++ standard, - which treats alias templates as synonyms for their underlying types (#GH54909). - - Clang now diagnoses dangling references for C++20's parenthesized aggregate initialization (#101957). Improvements to Clang's time-trace diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index c2ae9a9d5e1a0c..7e8e321c4b90e6 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -11451,29 +11451,23 @@ bool Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R, bool MightInstantiateToSpecialization = false; if (auto RetTST = TSI->getTypeLoc().getAsAdjusted()) { - const TemplateSpecializationType *TST = RetTST.getTypePtr(); - while (TST && TST->isTypeAlias()) -TST = TST->getAliasedType()->getAs(); - - if (TST) { -TemplateName SpecifiedName = TST->getTemplateName(); -bool TemplateMatches = Context.hasSameTemplateName( -SpecifiedName, GuidedTemplate, /*IgnoreDeduced=*/true); - -const QualifiedTemplateName *Qualifiers = -SpecifiedName.getAsQualifiedTemplateName(); -assert(Qualifiers && "expected QualifiedTemplate"); -bool SimplyWritten = !Qualifiers->hasTemplateKeyword() && - Qualifiers->getQualifier() == nullptr; -if (SimplyWritten && TemplateMatches) - AcceptableReturnType = true; -else { - // This could still instantiate to the right type, unless we know it - // names the wrong class template. - auto *TD = SpecifiedName.getAsTemplateDecl(); - MightInstantiateToSpecialization = - !(TD && isa(TD) && !TemplateMatches); -} + TemplateName SpecifiedName = RetTST.getTypePtr()->getTemplateName(); + bool TemplateMatches = Context.hasSameTemplateName( + SpecifiedName, GuidedTemplate, /*IgnoreDeduced=*/true); + + const QualifiedTemplateName *Qualifiers = + SpecifiedName.getAsQualifiedTemplateName(); + assert(Qualifiers && "expected QualifiedTemplate"); + bool SimplyWritten = !Qualifiers->hasTemplateKeyword() && + Qualifiers->getQualifier() == nullptr; + if (SimplyWritten && TemplateMatches) +AcceptableReturnType = true; + else { +// This could still instantiate to the right type, unless we know it +// names the wrong class template. +auto *TD = SpecifiedName.getAsTemplateDecl(); +MightInstantiateToSpecialization = +!(TD && isa(TD) && !TemplateMatches); } } else if (!RetTy.hasQualifiers() && RetTy->isDependentType()) { MightInstantiateToSpecialization = true; diff --git a/clang/test/CXX/temp/temp.deduct.guide/p3.cpp b/clang/test/CXX/temp/temp.deduct.guide/p3.cpp index 195ba2831439d0..c5404847beb066 100644 --- a/clang/test/CXX/temp/temp.deduct.guide/p3.cpp +++ b/clang/test/CXX/temp/temp.deduct.guide/p3.cpp @@ -33,7 +33,7 @@ template typename TT> struct E { // expected-note 2{{template }; A(int) -> int; // expected-error {{deduced type 'int' of deduction guide is not a specialization of template 'A'}} -template A(T)->B; +template A(T)->B; // expected-error {{deduced type 'B' (aka 'A') of deduction guide is not written as a specialization of template 'A'}} template A(T*) -> const A; // expected-error {{deduced type 'const A' of deduction guide is not a specialization of template 'A'}} // A deduction-guide shall be declared in the same scope as the corresponding @@ -71,11 +71,3 @@ namespace WrongScope { Local(int) -> Local; // expected-error {{expected}} } } - -namespace GH54909 { -template struct A {}; -struct B {}; - -template using C = B; -template A() -> C; // expected-error {{deduced type 'C' (aka 'GH54909::B') of deduction guide is not a specialization of template 'A'}} -} `` https://github.com/llvm/llvm-project/
[clang] [clang] constexpr built-in elementwise bitreverse function. (PR #118177)
https://github.com/c8ef edited https://github.com/llvm/llvm-project/pull/118177 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] constexpr built-in elementwise bitreverse function. (PR #118177)
https://github.com/c8ef edited https://github.com/llvm/llvm-project/pull/118177 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] constexpr built-in elementwise bitreverse function. (PR #118177)
https://github.com/c8ef ready_for_review https://github.com/llvm/llvm-project/pull/118177 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] constexpr built-in elementwise bitreverse function. (PR #118177)
llvmbot wrote: @llvm/pr-subscribers-clang Author: None (c8ef) Changes Part of #51787. This patch adds constexpr support for the built-in elementwise bitreverse function. --- Full diff: https://github.com/llvm/llvm-project/pull/118177.diff 6 Files Affected: - (modified) clang/docs/LanguageExtensions.rst (+1-1) - (modified) clang/docs/ReleaseNotes.rst (+1) - (modified) clang/include/clang/Basic/Builtins.td (+1-1) - (modified) clang/lib/AST/ExprConstant.cpp (+17-5) - (modified) clang/test/CodeGen/builtins-elementwise-math.c (+1-1) - (modified) clang/test/Sema/constant_builtins_vector.cpp (+5) ``diff diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index c053a5ab3c528c..52032e935928f1 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -648,7 +648,7 @@ elementwise to the input. Unless specified otherwise operation(±0) = ±0 and operation(±infinity) = ±infinity The integer elementwise intrinsics, including ``__builtin_elementwise_popcount``, -can be called in a ``constexpr`` context. +``__builtin_elementwise_bitreverse``, can be called in a ``constexpr`` context. == == = Name Operation Supported element types diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index e44aefa90ab386..7a4d58f170d297 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -402,6 +402,7 @@ Non-comprehensive list of changes in this release - ``__builtin_reduce_and`` function can now be used in constant expressions. - ``__builtin_reduce_or`` and ``__builtin_reduce_xor`` functions can now be used in constant expressions. - ``__builtin_elementwise_popcount`` function can now be used in constant expressions. +- ``__builtin_elementwise_bitreverse`` function can now be used in constant expressions. New Compiler Flags -- diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index db5cd73fba8ad1..f953f869d726bb 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -1270,7 +1270,7 @@ def ElementwiseATan2 : Builtin { def ElementwiseBitreverse : Builtin { let Spellings = ["__builtin_elementwise_bitreverse"]; - let Attributes = [NoThrow, Const, CustomTypeChecking]; + let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr]; let Prototype = "void(...)"; } diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index bb5ab67328fbc6..a99e91ff7b786e 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -11310,7 +11310,8 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) { switch (E->getBuiltinCallee()) { default: return false; - case Builtin::BI__builtin_elementwise_popcount: { + case Builtin::BI__builtin_elementwise_popcount: + case Builtin::BI__builtin_elementwise_bitreverse: { APValue Source; if (!EvaluateAsRValue(Info, E->getArg(0), Source)) return false; @@ -11322,9 +11323,19 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) { for (unsigned EltNum = 0; EltNum < SourceLen; ++EltNum) { APSInt Elt = Source.getVectorElt(EltNum).getInt(); - ResultElements.push_back( - APValue(APSInt(APInt(Info.Ctx.getIntWidth(DestEltTy), Elt.popcount()), - DestEltTy->isUnsignedIntegerOrEnumerationType(; + switch (E->getBuiltinCallee()) { + case Builtin::BI__builtin_elementwise_popcount: +ResultElements.push_back(APValue( +APSInt(APInt(Info.Ctx.getIntWidth(DestEltTy), Elt.popcount()), + DestEltTy->isUnsignedIntegerOrEnumerationType(; +break; + case Builtin::BI__builtin_elementwise_bitreverse: +ResultElements.push_back( +APValue(APSInt(Elt.reverseBits(), + DestEltTy->isUnsignedIntegerOrEnumerationType()) +.extOrTrunc(Info.Ctx.getIntWidth(DestEltTy; +break; + } } return Success(APValue(ResultElements.data(), ResultElements.size()), E); @@ -12833,7 +12844,8 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E, case Builtin::BI__builtin_bitreverse8: case Builtin::BI__builtin_bitreverse16: case Builtin::BI__builtin_bitreverse32: - case Builtin::BI__builtin_bitreverse64: { + case Builtin::BI__builtin_bitreverse64: + case Builtin::BI__builtin_elementwise_bitreverse: { APSInt Val; if (!EvaluateInteger(E->getArg(0), Val, Info)) return false; diff --git a/clang/test/CodeGen/builtins-elementwise-math.c b/clang/test/CodeGen/builtins-elementwise-math.c index f1f34432ca0ea1..82f82dd1ed
[clang] [clang-format] Add BreakBeforeTemplateClose option (PR #118046)
https://github.com/leijurv updated https://github.com/llvm/llvm-project/pull/118046 >From efb5b98de8817ce02a226353d9f5e36095874b27 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 29 Nov 2024 21:54:36 -0600 Subject: [PATCH] [clang-format] Add BreakBeforeTemplateClose option --- clang/docs/ClangFormatStyleOptions.rst | 21 ++ clang/docs/ReleaseNotes.rst| 1 + clang/include/clang/Format/Format.h| 20 ++ clang/lib/Format/ContinuationIndenter.cpp | 19 ++ clang/lib/Format/Format.cpp| 2 + clang/unittests/Format/ConfigParseTest.cpp | 1 + clang/unittests/Format/FormatTest.cpp | 78 ++ 7 files changed, 142 insertions(+) diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst index 4be448171699ca..84ab1b0a2eff61 100644 --- a/clang/docs/ClangFormatStyleOptions.rst +++ b/clang/docs/ClangFormatStyleOptions.rst @@ -3416,6 +3416,27 @@ the configuration (without a prefix: ``Auto``). +.. _BreakBeforeTemplateClose: + +**BreakBeforeTemplateClose** (``Boolean``) :versionbadge:`clang-format 20` :ref:`¶ ` + If ``true``, a line break will be placed before the ``>`` in a multiline + template declaration. + + .. code-block:: c++ + + true: + template < + typename Foo, + typename Bar, + typename Baz + > + + false: + template < + typename Foo, + typename Bar, + typename Baz> + .. _BreakBeforeTernaryOperators: **BreakBeforeTernaryOperators** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ ` diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index e44aefa90ab386..867d4b5d8c3f18 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -976,6 +976,7 @@ clang-format ``Never``, and ``true`` to ``Always``. - Adds ``RemoveEmptyLinesInUnwrappedLines`` option. - Adds ``KeepFormFeed`` option and set it to ``true`` for ``GNU`` style. +- Adds ``BreakBeforeTemplateClose`` option. libclang diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h index 6383934afa2c40..bffd964f6aa8aa 100644 --- a/clang/include/clang/Format/Format.h +++ b/clang/include/clang/Format/Format.h @@ -2248,6 +2248,25 @@ struct FormatStyle { /// \version 16 BreakBeforeInlineASMColonStyle BreakBeforeInlineASMColon; + /// If ``true``, a line break will be placed before the ``>`` in a multiline + /// template declaration. + /// \code + ///true: + ///template < + ///typename Foo, + ///typename Bar, + ///typename Baz + ///> + /// + ///false: + ///template < + ///typename Foo, + ///typename Bar, + ///typename Baz> + /// \endcode + /// \version 20 + bool BreakBeforeTemplateClose; + /// If ``true``, ternary operators will be placed after line breaks. /// \code ///true: @@ -5184,6 +5203,7 @@ struct FormatStyle { BreakBeforeBraces == R.BreakBeforeBraces && BreakBeforeConceptDeclarations == R.BreakBeforeConceptDeclarations && BreakBeforeInlineASMColon == R.BreakBeforeInlineASMColon && + BreakBeforeTemplateClose == R.BreakBeforeTemplateClose && BreakBeforeTernaryOperators == R.BreakBeforeTernaryOperators && BreakBinaryOperations == R.BreakBinaryOperations && BreakConstructorInitializers == R.BreakConstructorInitializers && diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index aed86c1fb99551..f42574e135c91c 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -382,10 +382,25 @@ bool ContinuationIndenter::canBreak(const LineState &State) { return !State.NoLineBreak && !CurrentState.NoLineBreak; } +bool isMatchingBraceOnSameLine(const FormatToken *Token) { + if (!Token->MatchingParen) +return false; + const FormatToken *Matching = Token->MatchingParen; + const FormatToken *Current = Token; + while (Current && Current != Matching) { +if (Current->NewlinesBefore > 0) + return false; +Current = Current->Previous; + } + return true; +} + bool ContinuationIndenter::mustBreak(const LineState &State) { const FormatToken &Current = *State.NextToken; const FormatToken &Previous = *Current.Previous; const auto &CurrentState = State.Stack.back(); + if (Current.ClosesTemplateDeclaration && Style.BreakBeforeTemplateClose) +return !isMatchingBraceOnSameLine(State.NextToken); if (Style.BraceWrapping.BeforeLambdaBody && Current.CanBreakBefore && Current.is(TT_LambdaLBrace) && Previous.isNot(TT_LineComment)) { auto LambdaBodyLength = getLengthToMatchingParen(Current, State.Stack); @@ -1370,6 +1385,10 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) { State.Stack.size() > 1) { return State.Stack[State.Stack.size()
[clang] Fix build error (PR #118192)
https://github.com/phuang created https://github.com/llvm/llvm-project/pull/118192 For ohos targets, libclang_rt.builtins.a, clang_rt.crtbegin.o and clang_rt.crtend.o are installed in clang/20/lib/${arch}-unknown-linux-ohos. However OHOS toolchain search them in clang/20/lib/${arch}-linux-ohos folder. It causes link error. Fix the problem by seaching both folders. >From 28314d98ca5b8e66f01b7bdb3ca610961cc1e133 Mon Sep 17 00:00:00 2001 From: Peng Huang Date: Tue, 15 Oct 2024 13:39:03 -0400 Subject: [PATCH] Fix build error For ohos targets, libclang_rt.builtins.a, clang_rt.crtbegin.o and clang_rt.crtend.o are installed in clang/20/lib/${arch}-unknown-linux-ohos. However OHOS toolchain search them in clang/20/lib/${arch}-linux-ohos folder. It causes link error. Fix the problem by seaching both folders. --- clang/lib/Driver/ToolChains/OHOS.cpp | 56 +++- 1 file changed, 22 insertions(+), 34 deletions(-) diff --git a/clang/lib/Driver/ToolChains/OHOS.cpp b/clang/lib/Driver/ToolChains/OHOS.cpp index 6e1a09ae908b2f..9a52fbf9b70959 100644 --- a/clang/lib/Driver/ToolChains/OHOS.cpp +++ b/clang/lib/Driver/ToolChains/OHOS.cpp @@ -19,8 +19,8 @@ #include "llvm/ProfileData/InstrProf.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" -#include "llvm/Support/VirtualFileSystem.h" #include "llvm/Support/ScopedPrinter.h" +#include "llvm/Support/VirtualFileSystem.h" using namespace clang::driver; using namespace clang::driver::toolchains; @@ -58,11 +58,9 @@ static bool findOHOSMuslMultilibs(const Driver &D, return false; } -static bool findOHOSMultilibs(const Driver &D, - const ToolChain &TC, - const llvm::Triple &TargetTriple, - StringRef Path, const ArgList &Args, - DetectedMultilibs &Result) { +static bool findOHOSMultilibs(const Driver &D, const ToolChain &TC, + const llvm::Triple &TargetTriple, StringRef Path, + const ArgList &Args, DetectedMultilibs &Result) { Multilib::flags_list Flags; bool IsA7 = false; if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) @@ -172,8 +170,7 @@ OHOS::OHOS(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) Paths); } -ToolChain::RuntimeLibType OHOS::GetRuntimeLibType( -const ArgList &Args) const { +ToolChain::RuntimeLibType OHOS::GetRuntimeLibType(const ArgList &Args) const { if (Arg *A = Args.getLastArg(clang::driver::options::OPT_rtlib_EQ)) { StringRef Value = A->getValue(); if (Value != "compiler-rt") @@ -184,20 +181,19 @@ ToolChain::RuntimeLibType OHOS::GetRuntimeLibType( return ToolChain::RLT_CompilerRT; } -ToolChain::CXXStdlibType -OHOS::GetCXXStdlibType(const ArgList &Args) const { +ToolChain::CXXStdlibType OHOS::GetCXXStdlibType(const ArgList &Args) const { if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { StringRef Value = A->getValue(); if (Value != "libc++") getDriver().Diag(diag::err_drv_invalid_stdlib_name) -<< A->getAsString(Args); + << A->getAsString(Args); } return ToolChain::CST_Libcxx; } void OHOS::AddClangSystemIncludeArgs(const ArgList &DriverArgs, -ArgStringList &CC1Args) const { + ArgStringList &CC1Args) const { const Driver &D = getDriver(); const llvm::Triple &Triple = getTriple(); std::string SysRoot = computeSysRoot(); @@ -258,7 +254,7 @@ void OHOS::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, } void OHOS::AddCXXStdlibLibArgs(const ArgList &Args, - ArgStringList &CmdArgs) const { + ArgStringList &CmdArgs) const { switch (GetCXXStdlibType(Args)) { case ToolChain::CST_Libcxx: CmdArgs.push_back("-lc++"); @@ -291,7 +287,8 @@ ToolChain::path_list OHOS::getRuntimePaths() const { // First try the triple passed to driver as --target=. P.assign(D.ResourceDir); - llvm::sys::path::append(P, "lib", D.getTargetTriple(), SelectedMultilib.gccSuffix()); + llvm::sys::path::append(P, "lib", D.getTargetTriple(), + SelectedMultilib.gccSuffix()); Paths.push_back(P.c_str()); // Second try the normalized triple. @@ -340,26 +337,16 @@ std::string OHOS::getDynamicLinker(const ArgList &Args) const { std::string OHOS::getCompilerRT(const ArgList &Args, StringRef Component, FileType Type) const { + std::string CRTBasename = + buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/false); + SmallString<128> Path(getDriver().ResourceDir); llvm::sys::path::append(Path, "lib", getMultiarchTriple(getTriple()), - SelectedMultilib.gccSuffix()); - const char *Prefix = - Type == ToolChain::FT_Object ? "" : "lib"; -
[clang] Fix build error for OHOS (PR #118192)
https://github.com/phuang edited https://github.com/llvm/llvm-project/pull/118192 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add an off-by-default warning to complain about MSVC bitfield padding (PR #117428)
https://github.com/ojhunt updated https://github.com/llvm/llvm-project/pull/117428 >From 3e25d7ef2e223942298078dace8979905956d05c Mon Sep 17 00:00:00 2001 From: Oliver Hunt Date: Fri, 22 Nov 2024 17:53:24 +0100 Subject: [PATCH 1/2] Add an off-by-default warning to complain about MSVC bitfield padding --- clang/include/clang/Basic/DiagnosticGroups.td | 1 + .../clang/Basic/DiagnosticSemaKinds.td| 6 + clang/lib/Sema/SemaDecl.cpp | 27 ++- .../SemaCXX/ms_struct-bitfield-padding.cpp| 180 ++ 4 files changed, 212 insertions(+), 2 deletions(-) create mode 100644 clang/test/SemaCXX/ms_struct-bitfield-padding.cpp diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index df9bf94b5d0398..57bdda4b8f8b47 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -631,6 +631,7 @@ def Packed : DiagGroup<"packed", [PackedNonPod]>; def PaddedBitField : DiagGroup<"padded-bitfield">; def Padded : DiagGroup<"padded", [PaddedBitField]>; def UnalignedAccess : DiagGroup<"unaligned-access">; +def MSBitfieldCompatibility : DiagGroup<"ms-bitfield-packing-compatibility">; def PessimizingMove : DiagGroup<"pessimizing-move">; def ReturnStdMove : DiagGroup<"return-std-move">; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index eb05a6a77978af..aa13e3438d3739 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -6418,6 +6418,12 @@ def warn_signed_bitfield_enum_conversion : Warning< InGroup, DefaultIgnore; def note_change_bitfield_sign : Note< "consider making the bitfield type %select{unsigned|signed}0">; +def warn_ms_bitfield_mismatched_storage_packing : Warning< + "bit-field %0 of type %1 has a different storage size (%2 vs %3 bytes) than the " + "preceding bit-field and may not be packed under MSVC ABI">, + InGroup, DefaultIgnore; +def note_ms_bitfield_mismatched_storage_size_previous : Note< + "preceding bit-field %0 declared here with type %1">; def warn_missing_braces : Warning< "suggest braces around initialization of subobject">, diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 74b0e5ad23bd48..18aeca3b34f659 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -19001,9 +19001,9 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl, // Verify that all the fields are okay. SmallVector RecFields; - + std::optional PreviousField; for (ArrayRef::iterator i = Fields.begin(), end = Fields.end(); - i != end; ++i) { + i != end; PreviousField = cast(*i), ++i) { FieldDecl *FD = cast(*i); // Get the type for the field. @@ -19213,6 +19213,29 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl, if (Record && FD->getType().isVolatileQualified()) Record->setHasVolatileMember(true); +auto IsNonDependentBitField = [](const FieldDecl *FD) { + if (!FD->isBitField()) +return false; + if (FD->getType()->isDependentType()) +return false; + return true; +}; + +if (Record && PreviousField && IsNonDependentBitField(FD) && +IsNonDependentBitField(*PreviousField)) { + unsigned FDStorageSize = + Context.getTypeSizeInChars(FD->getType()).getQuantity(); + unsigned PreviousFieldStorageSize = + Context.getTypeSizeInChars((*PreviousField)->getType()).getQuantity(); + if (FDStorageSize != PreviousFieldStorageSize) { +Diag(FD->getLocation(), + diag::warn_ms_bitfield_mismatched_storage_packing) +<< FD << FD->getType() << FDStorageSize << PreviousFieldStorageSize; +Diag((*PreviousField)->getLocation(), + diag::note_ms_bitfield_mismatched_storage_size_previous) +<< *PreviousField << (*PreviousField)->getType(); + } +} // Keep track of the number of named members. if (FD->getIdentifier()) ++NumNamedMembers; diff --git a/clang/test/SemaCXX/ms_struct-bitfield-padding.cpp b/clang/test/SemaCXX/ms_struct-bitfield-padding.cpp new file mode 100644 index 00..001086de5bbd10 --- /dev/null +++ b/clang/test/SemaCXX/ms_struct-bitfield-padding.cpp @@ -0,0 +1,180 @@ + +// RUN: %clang_cc1 -fsyntax-only -Wms-bitfield-packing-compatibility -verify -triple armv8 -std=c++23 %s +// RUN: %clang_cc1 -fsyntax-only -DMS_BITFIELDS -mms-bitfields -verify=msbitfields -triple armv8-apple-macos10.15 -std=c++23 %s + +// msbitfields-no-diagnostics + +enum Enum1 { Enum1_A, Enum1_B }; +enum Enum2 { Enum2_A, Enum2_B }; + +enum class EnumU32_1 : unsigned { A, B }; +enum class EnumU32_2 : unsigned { A, B }; +enum class EnumU64 : unsigned long long { A, B }; +enum class EnumI32 : int { A, B }; +enum class EnumU8 : unsigned char { A, B };
[clang] [clang] Absoultify paths in dependency file output (PR #117458)
xtexChooser wrote: cc @jansvoboda11 https://github.com/llvm/llvm-project/pull/117458 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format][CMake] Generate formatting options docs during build (PR #113739)
owenca wrote: > What's the point of adding it to the `FormatTests` target though? Just to > ensure proper test coverage of the `dump_format_style.py` file? That and to also ensure that the edited Format.h doesn't break the python script. > Thinking about this a bit more, I think we can probably satisfy all the > constraints if we write a lit test that ensures the in-tree > ClangFormatStyleOptions.rst matches what the script will produce > (https://github.com/llvm/llvm-project/pull/118154)? That solves the original > problem that https://github.com/llvm/llvm-project/pull/111513 set out to > solve (if I remember correctly) and will show up as a failure in CI if not > done. If we are to leave the generated part of the rst file in the repo, #111513 would satisfy my requirements nicely. Something like #118154 may be a useful addition. > I'm also planning on making the documentation build action upload the built > docs as artifacts, which would also let reviewers just download the built > HTML files and inspect those if that's easier/useful. That would be nice. https://github.com/llvm/llvm-project/pull/113739 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add `.cjs` extension handling for JavaScript Language. (PR #118188)
owenca wrote: You need to also update the command-line input file extensions, docs, and git-clang-format. https://github.com/llvm/llvm-project/pull/118188 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [clang][driver] Special care for -l flags in config files (PR #117573)
thesamesam wrote: I took a look and I think it may be too awkward to do, as we'd want to run e.g. readelf afterwards. But an example is `lld/test/ELF/as-needed-not-in-regular.s`. The idea being: if `-Wl,--as-needed` is in the config file, do we correctly prune an unnecessary library from a built object, or is the order wrong? We can check that with `llvm-readelf`. https://github.com/llvm/llvm-project/pull/117573 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Fix build error (PR #118192)
llvmbot wrote: @llvm/pr-subscribers-clang-driver Author: Peng Huang (phuang) Changes For ohos targets, libclang_rt.builtins.a, clang_rt.crtbegin.o and clang_rt.crtend.o are installed in clang/20/lib/${arch}-unknown-linux-ohos. However OHOS toolchain search them in clang/20/lib/${arch}-linux-ohos folder. It causes link error. Fix the problem by seaching both folders. --- Full diff: https://github.com/llvm/llvm-project/pull/118192.diff 1 Files Affected: - (modified) clang/lib/Driver/ToolChains/OHOS.cpp (+22-34) ``diff diff --git a/clang/lib/Driver/ToolChains/OHOS.cpp b/clang/lib/Driver/ToolChains/OHOS.cpp index 6e1a09ae908b2f..9a52fbf9b70959 100644 --- a/clang/lib/Driver/ToolChains/OHOS.cpp +++ b/clang/lib/Driver/ToolChains/OHOS.cpp @@ -19,8 +19,8 @@ #include "llvm/ProfileData/InstrProf.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" -#include "llvm/Support/VirtualFileSystem.h" #include "llvm/Support/ScopedPrinter.h" +#include "llvm/Support/VirtualFileSystem.h" using namespace clang::driver; using namespace clang::driver::toolchains; @@ -58,11 +58,9 @@ static bool findOHOSMuslMultilibs(const Driver &D, return false; } -static bool findOHOSMultilibs(const Driver &D, - const ToolChain &TC, - const llvm::Triple &TargetTriple, - StringRef Path, const ArgList &Args, - DetectedMultilibs &Result) { +static bool findOHOSMultilibs(const Driver &D, const ToolChain &TC, + const llvm::Triple &TargetTriple, StringRef Path, + const ArgList &Args, DetectedMultilibs &Result) { Multilib::flags_list Flags; bool IsA7 = false; if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) @@ -172,8 +170,7 @@ OHOS::OHOS(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) Paths); } -ToolChain::RuntimeLibType OHOS::GetRuntimeLibType( -const ArgList &Args) const { +ToolChain::RuntimeLibType OHOS::GetRuntimeLibType(const ArgList &Args) const { if (Arg *A = Args.getLastArg(clang::driver::options::OPT_rtlib_EQ)) { StringRef Value = A->getValue(); if (Value != "compiler-rt") @@ -184,20 +181,19 @@ ToolChain::RuntimeLibType OHOS::GetRuntimeLibType( return ToolChain::RLT_CompilerRT; } -ToolChain::CXXStdlibType -OHOS::GetCXXStdlibType(const ArgList &Args) const { +ToolChain::CXXStdlibType OHOS::GetCXXStdlibType(const ArgList &Args) const { if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { StringRef Value = A->getValue(); if (Value != "libc++") getDriver().Diag(diag::err_drv_invalid_stdlib_name) -<< A->getAsString(Args); + << A->getAsString(Args); } return ToolChain::CST_Libcxx; } void OHOS::AddClangSystemIncludeArgs(const ArgList &DriverArgs, -ArgStringList &CC1Args) const { + ArgStringList &CC1Args) const { const Driver &D = getDriver(); const llvm::Triple &Triple = getTriple(); std::string SysRoot = computeSysRoot(); @@ -258,7 +254,7 @@ void OHOS::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, } void OHOS::AddCXXStdlibLibArgs(const ArgList &Args, - ArgStringList &CmdArgs) const { + ArgStringList &CmdArgs) const { switch (GetCXXStdlibType(Args)) { case ToolChain::CST_Libcxx: CmdArgs.push_back("-lc++"); @@ -291,7 +287,8 @@ ToolChain::path_list OHOS::getRuntimePaths() const { // First try the triple passed to driver as --target=. P.assign(D.ResourceDir); - llvm::sys::path::append(P, "lib", D.getTargetTriple(), SelectedMultilib.gccSuffix()); + llvm::sys::path::append(P, "lib", D.getTargetTriple(), + SelectedMultilib.gccSuffix()); Paths.push_back(P.c_str()); // Second try the normalized triple. @@ -340,26 +337,16 @@ std::string OHOS::getDynamicLinker(const ArgList &Args) const { std::string OHOS::getCompilerRT(const ArgList &Args, StringRef Component, FileType Type) const { + std::string CRTBasename = + buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/false); + SmallString<128> Path(getDriver().ResourceDir); llvm::sys::path::append(Path, "lib", getMultiarchTriple(getTriple()), - SelectedMultilib.gccSuffix()); - const char *Prefix = - Type == ToolChain::FT_Object ? "" : "lib"; - const char *Suffix; - switch (Type) { - case ToolChain::FT_Object: -Suffix = ".o"; -break; - case ToolChain::FT_Static: -Suffix = ".a"; -break; - case ToolChain::FT_Shared: -Suffix = ".so"; -break; - } - llvm::sys::path::append( - Path, Prefix + Twine("clang_rt.") + Component + Suffix); - return static_cast(Path.str()); + SelectedMultil
[clang] Fix build error (PR #118192)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Peng Huang (phuang) Changes For ohos targets, libclang_rt.builtins.a, clang_rt.crtbegin.o and clang_rt.crtend.o are installed in clang/20/lib/${arch}-unknown-linux-ohos. However OHOS toolchain search them in clang/20/lib/${arch}-linux-ohos folder. It causes link error. Fix the problem by seaching both folders. --- Full diff: https://github.com/llvm/llvm-project/pull/118192.diff 1 Files Affected: - (modified) clang/lib/Driver/ToolChains/OHOS.cpp (+22-34) ``diff diff --git a/clang/lib/Driver/ToolChains/OHOS.cpp b/clang/lib/Driver/ToolChains/OHOS.cpp index 6e1a09ae908b2f..9a52fbf9b70959 100644 --- a/clang/lib/Driver/ToolChains/OHOS.cpp +++ b/clang/lib/Driver/ToolChains/OHOS.cpp @@ -19,8 +19,8 @@ #include "llvm/ProfileData/InstrProf.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" -#include "llvm/Support/VirtualFileSystem.h" #include "llvm/Support/ScopedPrinter.h" +#include "llvm/Support/VirtualFileSystem.h" using namespace clang::driver; using namespace clang::driver::toolchains; @@ -58,11 +58,9 @@ static bool findOHOSMuslMultilibs(const Driver &D, return false; } -static bool findOHOSMultilibs(const Driver &D, - const ToolChain &TC, - const llvm::Triple &TargetTriple, - StringRef Path, const ArgList &Args, - DetectedMultilibs &Result) { +static bool findOHOSMultilibs(const Driver &D, const ToolChain &TC, + const llvm::Triple &TargetTriple, StringRef Path, + const ArgList &Args, DetectedMultilibs &Result) { Multilib::flags_list Flags; bool IsA7 = false; if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) @@ -172,8 +170,7 @@ OHOS::OHOS(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) Paths); } -ToolChain::RuntimeLibType OHOS::GetRuntimeLibType( -const ArgList &Args) const { +ToolChain::RuntimeLibType OHOS::GetRuntimeLibType(const ArgList &Args) const { if (Arg *A = Args.getLastArg(clang::driver::options::OPT_rtlib_EQ)) { StringRef Value = A->getValue(); if (Value != "compiler-rt") @@ -184,20 +181,19 @@ ToolChain::RuntimeLibType OHOS::GetRuntimeLibType( return ToolChain::RLT_CompilerRT; } -ToolChain::CXXStdlibType -OHOS::GetCXXStdlibType(const ArgList &Args) const { +ToolChain::CXXStdlibType OHOS::GetCXXStdlibType(const ArgList &Args) const { if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { StringRef Value = A->getValue(); if (Value != "libc++") getDriver().Diag(diag::err_drv_invalid_stdlib_name) -<< A->getAsString(Args); + << A->getAsString(Args); } return ToolChain::CST_Libcxx; } void OHOS::AddClangSystemIncludeArgs(const ArgList &DriverArgs, -ArgStringList &CC1Args) const { + ArgStringList &CC1Args) const { const Driver &D = getDriver(); const llvm::Triple &Triple = getTriple(); std::string SysRoot = computeSysRoot(); @@ -258,7 +254,7 @@ void OHOS::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, } void OHOS::AddCXXStdlibLibArgs(const ArgList &Args, - ArgStringList &CmdArgs) const { + ArgStringList &CmdArgs) const { switch (GetCXXStdlibType(Args)) { case ToolChain::CST_Libcxx: CmdArgs.push_back("-lc++"); @@ -291,7 +287,8 @@ ToolChain::path_list OHOS::getRuntimePaths() const { // First try the triple passed to driver as --target=. P.assign(D.ResourceDir); - llvm::sys::path::append(P, "lib", D.getTargetTriple(), SelectedMultilib.gccSuffix()); + llvm::sys::path::append(P, "lib", D.getTargetTriple(), + SelectedMultilib.gccSuffix()); Paths.push_back(P.c_str()); // Second try the normalized triple. @@ -340,26 +337,16 @@ std::string OHOS::getDynamicLinker(const ArgList &Args) const { std::string OHOS::getCompilerRT(const ArgList &Args, StringRef Component, FileType Type) const { + std::string CRTBasename = + buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/false); + SmallString<128> Path(getDriver().ResourceDir); llvm::sys::path::append(Path, "lib", getMultiarchTriple(getTriple()), - SelectedMultilib.gccSuffix()); - const char *Prefix = - Type == ToolChain::FT_Object ? "" : "lib"; - const char *Suffix; - switch (Type) { - case ToolChain::FT_Object: -Suffix = ".o"; -break; - case ToolChain::FT_Static: -Suffix = ".a"; -break; - case ToolChain::FT_Shared: -Suffix = ".so"; -break; - } - llvm::sys::path::append( - Path, Prefix + Twine("clang_rt.") + Component + Suffix); - return static_cast(Path.str()); + SelectedMultilib.gccS
[clang] Fix build error (PR #118192)
github-actions[bot] wrote: Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using `@` followed by their GitHub username. If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html). You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/). https://github.com/llvm/llvm-project/pull/118192 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Absoultify paths in dependency file output (PR #117458)
xtexChooser wrote: Ping https://github.com/llvm/llvm-project/pull/117458 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Fix build error for OHOS (PR #118192)
https://github.com/phuang updated https://github.com/llvm/llvm-project/pull/118192 >From 206f8f800df7e51648ec00b110f2437dca5a3ff6 Mon Sep 17 00:00:00 2001 From: Peng Huang Date: Tue, 15 Oct 2024 13:39:03 -0400 Subject: [PATCH] Fix build error for OHOS For ohos targets, libclang_rt.builtins.a, clang_rt.crtbegin.o and clang_rt.crtend.o are installed in clang/20/lib/${arch}-unknown-linux-ohos. However OHOS toolchain search them in clang/20/lib/${arch}-linux-ohos folder. It causes link error. Fix the problem by seaching both folders. --- clang/lib/Driver/ToolChains/OHOS.cpp | 60 1 file changed, 26 insertions(+), 34 deletions(-) diff --git a/clang/lib/Driver/ToolChains/OHOS.cpp b/clang/lib/Driver/ToolChains/OHOS.cpp index 6e1a09ae908b2f..723c891d2a89ca 100644 --- a/clang/lib/Driver/ToolChains/OHOS.cpp +++ b/clang/lib/Driver/ToolChains/OHOS.cpp @@ -19,8 +19,8 @@ #include "llvm/ProfileData/InstrProf.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" -#include "llvm/Support/VirtualFileSystem.h" #include "llvm/Support/ScopedPrinter.h" +#include "llvm/Support/VirtualFileSystem.h" using namespace clang::driver; using namespace clang::driver::toolchains; @@ -58,11 +58,9 @@ static bool findOHOSMuslMultilibs(const Driver &D, return false; } -static bool findOHOSMultilibs(const Driver &D, - const ToolChain &TC, - const llvm::Triple &TargetTriple, - StringRef Path, const ArgList &Args, - DetectedMultilibs &Result) { +static bool findOHOSMultilibs(const Driver &D, const ToolChain &TC, + const llvm::Triple &TargetTriple, StringRef Path, + const ArgList &Args, DetectedMultilibs &Result) { Multilib::flags_list Flags; bool IsA7 = false; if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) @@ -172,8 +170,7 @@ OHOS::OHOS(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) Paths); } -ToolChain::RuntimeLibType OHOS::GetRuntimeLibType( -const ArgList &Args) const { +ToolChain::RuntimeLibType OHOS::GetRuntimeLibType(const ArgList &Args) const { if (Arg *A = Args.getLastArg(clang::driver::options::OPT_rtlib_EQ)) { StringRef Value = A->getValue(); if (Value != "compiler-rt") @@ -184,20 +181,19 @@ ToolChain::RuntimeLibType OHOS::GetRuntimeLibType( return ToolChain::RLT_CompilerRT; } -ToolChain::CXXStdlibType -OHOS::GetCXXStdlibType(const ArgList &Args) const { +ToolChain::CXXStdlibType OHOS::GetCXXStdlibType(const ArgList &Args) const { if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { StringRef Value = A->getValue(); if (Value != "libc++") getDriver().Diag(diag::err_drv_invalid_stdlib_name) -<< A->getAsString(Args); + << A->getAsString(Args); } return ToolChain::CST_Libcxx; } void OHOS::AddClangSystemIncludeArgs(const ArgList &DriverArgs, -ArgStringList &CC1Args) const { + ArgStringList &CC1Args) const { const Driver &D = getDriver(); const llvm::Triple &Triple = getTriple(); std::string SysRoot = computeSysRoot(); @@ -258,7 +254,7 @@ void OHOS::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, } void OHOS::AddCXXStdlibLibArgs(const ArgList &Args, - ArgStringList &CmdArgs) const { + ArgStringList &CmdArgs) const { switch (GetCXXStdlibType(Args)) { case ToolChain::CST_Libcxx: CmdArgs.push_back("-lc++"); @@ -291,7 +287,8 @@ ToolChain::path_list OHOS::getRuntimePaths() const { // First try the triple passed to driver as --target=. P.assign(D.ResourceDir); - llvm::sys::path::append(P, "lib", D.getTargetTriple(), SelectedMultilib.gccSuffix()); + llvm::sys::path::append(P, "lib", D.getTargetTriple(), + SelectedMultilib.gccSuffix()); Paths.push_back(P.c_str()); // Second try the normalized triple. @@ -340,26 +337,20 @@ std::string OHOS::getDynamicLinker(const ArgList &Args) const { std::string OHOS::getCompilerRT(const ArgList &Args, StringRef Component, FileType Type) const { + std::string CRTBasename = + buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/false); + SmallString<128> Path(getDriver().ResourceDir); llvm::sys::path::append(Path, "lib", getMultiarchTriple(getTriple()), - SelectedMultilib.gccSuffix()); - const char *Prefix = - Type == ToolChain::FT_Object ? "" : "lib"; - const char *Suffix; - switch (Type) { - case ToolChain::FT_Object: -Suffix = ".o"; -break; - case ToolChain::FT_Static: -Suffix = ".a"; -break; - case ToolChain::FT_Shared: -Suffix = ".so"; -break; - } - llvm::sys::path::append( - Path, Prefix
[clang] [flang] [clang][driver] Special care for -l flags in config files (PR #117573)
https://github.com/pawosm-arm updated https://github.com/llvm/llvm-project/pull/117573 >From e5769df6180f6b89ad2c494e74d3e4dc9d88dec8 Mon Sep 17 00:00:00 2001 From: Pawel Osmialowski Date: Mon, 25 Nov 2024 14:46:55 + Subject: [PATCH] [clang][driver] Special care for -l and -Wl, flags in config files Currently, if a -l (or -Wl,) flag is added into a config file (e.g. clang.cfg), it is situated before any object file in the effective command line. If the library requested by given -l flag is static, its symbols will not be made visible to any of the object files provided by the user. Also, the presence of any of the linker flags in a config file confuses the driver whenever the user invokes clang without any parameters. This patch solves both of those problems, by moving the -l and -Wl, flags specified in a config file to the end of the input list, and by discarding them when there are no other inputs provided by the user, or the last phase is not the linking phase. --- clang/include/clang/Driver/Driver.h | 3 +++ clang/lib/Driver/Driver.cpp | 36 +++ clang/test/Driver/Inputs/config-l.cfg | 1 + clang/test/Driver/config-file.c | 26 +++ flang/test/Driver/Inputs/config-l.cfg | 1 + flang/test/Driver/config-file.f90 | 26 +++ 6 files changed, 93 insertions(+) create mode 100644 clang/test/Driver/Inputs/config-l.cfg create mode 100644 flang/test/Driver/Inputs/config-l.cfg diff --git a/clang/include/clang/Driver/Driver.h b/clang/include/clang/Driver/Driver.h index 9177d56718ee77..b21606b6f54b77 100644 --- a/clang/include/clang/Driver/Driver.h +++ b/clang/include/clang/Driver/Driver.h @@ -297,6 +297,9 @@ class Driver { /// Object that stores strings read from configuration file. llvm::StringSaver Saver; + /// Linker inputs originated from configuration file. + std::unique_ptr CfgLinkerInputs; + /// Arguments originated from configuration file. std::unique_ptr CfgOptions; diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index ad14b5c9b6dc80..007b25f31d5aee 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -1062,6 +1062,19 @@ bool Driver::readConfigFile(StringRef FileName, for (Arg *A : *NewOptions) A->claim(); + // Filter out all -l and -Wl, options, put them into a separate list and erase + // from the original list of configuration file options. These will be used + // only when linking and appended after all of the command line options. + auto NewLinkerIns = std::make_unique(); + for (Arg *A : NewOptions->filtered(options::OPT_Wl_COMMA, options::OPT_l)) { +const Arg *BaseArg = &A->getBaseArg(); +if (BaseArg == A) + BaseArg = nullptr; +appendOneArg(*NewLinkerIns, A, BaseArg); + } + NewOptions->eraseArg(options::OPT_Wl_COMMA); + NewOptions->eraseArg(options::OPT_l); + if (!CfgOptions) CfgOptions = std::move(NewOptions); else { @@ -1073,6 +1086,19 @@ bool Driver::readConfigFile(StringRef FileName, appendOneArg(*CfgOptions, Opt, BaseArg); } } + + if (!CfgLinkerInputs) +CfgLinkerInputs = std::move(NewLinkerIns); + else { +// If this is a subsequent config file, append options to the previous one. +for (auto *Opt : *NewLinkerIns) { + const Arg *BaseArg = &Opt->getBaseArg(); + if (BaseArg == Opt) +BaseArg = nullptr; + appendOneArg(*CfgLinkerInputs, Opt, BaseArg); +} + } + ConfigFiles.push_back(std::string(CfgFileName)); return false; } @@ -1250,6 +1276,7 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) { if (!ContainsError) ContainsError = loadConfigFiles(); bool HasConfigFile = !ContainsError && (CfgOptions.get() != nullptr); + bool HasConfigLinkerIn = !ContainsError && CfgLinkerInputs; // All arguments, from both config file and command line. InputArgList Args = std::move(HasConfigFile ? std::move(*CfgOptions) @@ -1552,6 +1579,15 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) { // Construct the list of inputs. InputList Inputs; BuildInputs(C->getDefaultToolChain(), *TranslatedArgs, Inputs); + if (HasConfigLinkerIn && Inputs.size()) { +Arg *FinalPhaseArg; +if (getFinalPhase(*TranslatedArgs, &FinalPhaseArg) == phases::Link) { + DerivedArgList TranslatedLinkerIns(*CfgLinkerInputs); + for (Arg *A : *CfgLinkerInputs) +TranslatedLinkerIns.append(A); + BuildInputs(C->getDefaultToolChain(), TranslatedLinkerIns, Inputs); +} + } // Populate the tool chains for the offloading devices, if any. CreateOffloadingDeviceToolChains(*C, Inputs); diff --git a/clang/test/Driver/Inputs/config-l.cfg b/clang/test/Driver/Inputs/config-l.cfg new file mode 100644 index 00..853b179bd2da85 --- /dev/null +++ b/clang/test/Driver/Inputs/config-l.cfg @@ -0,0 +1 @@ +-Wall -lm -Wl,-Bstatic -lhappy -Wl,-Bdynamic diff --git a/clang/test/Driver/config-file.c b/clang/test/Driv
[clang] [flang] [clang][driver] Special care for -l flags in config files (PR #117573)
@@ -82,3 +82,29 @@ // CHECK-TWO-CONFIGS: -isysroot // CHECK-TWO-CONFIGS-SAME: /opt/data // CHECK-TWO-CONFIGS-SAME: -Wall + +//--- The linker input flags should be moved to the end of input list and appear only when linking. +// RUN: %clang --target=aarch64-unknown-linux-gnu --config %S/Inputs/config-l.cfg %s -lmylib -Wl,foo.a -### 2>&1 | FileCheck %s -check-prefix CHECK-LINKING +// RUN: %clang --target=aarch64-unknown-linux-gnu --config %S/Inputs/config-l.cfg -fopenmp %s -lmylib -Wl,foo.a -### 2>&1 | FileCheck %s -check-prefix CHECK-LINKING-LIBOMP-GOES-LAST +// RUN: %clang --target=aarch64-unknown-linux-gnu --config %S/Inputs/config-l.cfg -S %s -### 2>&1 | FileCheck %s -check-prefix CHECK-NOLINKING +// RUN: %clang --target=aarch64-unknown-linux-gnu --config %S/Inputs/config-l.cfg -fopenmp -S %s -### 2>&1 | FileCheck %s -check-prefix CHECK-NOLINKING +// RUN: %clang --target=x86_64-pc-windows-msvc--config %S/Inputs/config-l.cfg %s -lmylib -Wl,foo.lib -### 2>&1 | FileCheck %s -check-prefix CHECK-LINKING-MSVC +// RUN: %clang --target=x86_64-pc-windows-msvc--config %S/Inputs/config-l.cfg -S %s -### 2>&1 | FileCheck %s -check-prefix CHECK-NOLINKING-MSVC +// CHECK-LINKING: Configuration file: {{.*}}Inputs{{.}}config-l.cfg +// CHECK-LINKING: "-Wall" +// CHECK-LINKING: "{{.*}}-{{.*}}.o" "-lmylib" "foo.a" "-lm" "-Bstatic" "-lhappy" "-Bdynamic" +// CHECK-LINKING-LIBOMP-GOES-LAST: Configuration file: {{.*}}Inputs{{.}}config-l.cfg +// CHECK-LINKING-LIBOMP-GOES-LAST: "-Wall" pawosm-arm wrote: ??? https://github.com/llvm/llvm-project/pull/117573 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [clang][driver] Special care for -l flags in config files (PR #117573)
@@ -61,3 +61,29 @@ ! CHECK-TWO-CONFIGS-NEXT: Configuration file: {{.*}}Inputs{{.}}config2{{.}}config-4.cfg ! CHECK-TWO-CONFIGS: -ffp-contract=fast ! CHECK-TWO-CONFIGS: -O3 + +!--- The linker input flags should be moved to the end of input list and appear only when linking. +! RUN: %flang --target=aarch64-unknown-linux-gnu --config %S/Inputs/config-l.cfg %s -lmylib -Wl,foo.a -### 2>&1 | FileCheck %s -check-prefix CHECK-LINKING +! RUN: %flang --target=aarch64-unknown-linux-gnu --config %S/Inputs/config-l.cfg -fopenmp %s -lmylib -Wl,foo.a -### 2>&1 | FileCheck %s -check-prefix CHECK-LINKING-LIBOMP-GOES-LAST +! RUN: %flang --target=aarch64-unknown-linux-gnu --config %S/Inputs/config-l.cfg -S %s -### 2>&1 | FileCheck %s -check-prefix CHECK-NOLINKING +! RUN: %flang --target=aarch64-unknown-linux-gnu --config %S/Inputs/config-l.cfg -fopenmp -S %s -### 2>&1 | FileCheck %s -check-prefix CHECK-NOLINKING +! RUN: %flang --target=x86_64-pc-windows-msvc--config %S/Inputs/config-l.cfg %s -lmylib -Wl,foo.lib -### 2>&1 | FileCheck %s -check-prefix CHECK-LINKING-MSVC +! RUN: %flang --target=x86_64-pc-windows-msvc--config %S/Inputs/config-l.cfg -S %s -### 2>&1 | FileCheck %s -check-prefix CHECK-NOLINKING-MSVC +! CHECK-LINKING: Configuration file: {{.*}}Inputs{{.}}config-l.cfg +! CHECK-LINKING: "-ffast-math" +! CHECK-LINKING: "{{.*}}-{{.*}}.o" "-lmylib" "foo.a" "-lm" "-Bstatic" "-lhappy" "-Bdynamic" +! CHECK-LINKING-LIBOMP-GOES-LAST: Configuration file: {{.*}}Inputs{{.}}config-l.cfg +! CHECK-LINKING-LIBOMP-GOES-LAST: "-ffast-math" pawosm-arm wrote: I need some help here. https://github.com/llvm/llvm-project/pull/117573 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [clang][driver] Special care for -l flags in config files (PR #117573)
@@ -1073,6 +1086,19 @@ bool Driver::readConfigFile(StringRef FileName, appendOneArg(*CfgOptions, Opt, BaseArg); } } + + if (!CfgLinkerInputs) +CfgLinkerInputs = std::move(NewLinkerIns); + else { +// If this is a subsequent config file, append options to the previous one. +for (auto *Opt : *NewLinkerIns) { + const Arg *BaseArg = &Opt->getBaseArg(); MaskRay wrote: Remove `getBaseArg` https://github.com/llvm/llvm-project/pull/117573 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [clang][driver] Special care for -l flags in config files (PR #117573)
@@ -61,3 +61,29 @@ ! CHECK-TWO-CONFIGS-NEXT: Configuration file: {{.*}}Inputs{{.}}config2{{.}}config-4.cfg ! CHECK-TWO-CONFIGS: -ffp-contract=fast ! CHECK-TWO-CONFIGS: -O3 + +!--- The linker input flags should be moved to the end of input list and appear only when linking. +! RUN: %flang --target=aarch64-unknown-linux-gnu --config %S/Inputs/config-l.cfg %s -lmylib -Wl,foo.a -### 2>&1 | FileCheck %s -check-prefix CHECK-LINKING +! RUN: %flang --target=aarch64-unknown-linux-gnu --config %S/Inputs/config-l.cfg -fopenmp %s -lmylib -Wl,foo.a -### 2>&1 | FileCheck %s -check-prefix CHECK-LINKING-LIBOMP-GOES-LAST +! RUN: %flang --target=aarch64-unknown-linux-gnu --config %S/Inputs/config-l.cfg -S %s -### 2>&1 | FileCheck %s -check-prefix CHECK-NOLINKING +! RUN: %flang --target=aarch64-unknown-linux-gnu --config %S/Inputs/config-l.cfg -fopenmp -S %s -### 2>&1 | FileCheck %s -check-prefix CHECK-NOLINKING +! RUN: %flang --target=x86_64-pc-windows-msvc--config %S/Inputs/config-l.cfg %s -lmylib -Wl,foo.lib -### 2>&1 | FileCheck %s -check-prefix CHECK-LINKING-MSVC +! RUN: %flang --target=x86_64-pc-windows-msvc--config %S/Inputs/config-l.cfg -S %s -### 2>&1 | FileCheck %s -check-prefix CHECK-NOLINKING-MSVC +! CHECK-LINKING: Configuration file: {{.*}}Inputs{{.}}config-l.cfg +! CHECK-LINKING: "-ffast-math" +! CHECK-LINKING: "{{.*}}-{{.*}}.o" "-lmylib" "foo.a" "-lm" "-Bstatic" "-lhappy" "-Bdynamic" +! CHECK-LINKING-LIBOMP-GOES-LAST: Configuration file: {{.*}}Inputs{{.}}config-l.cfg +! CHECK-LINKING-LIBOMP-GOES-LAST: "-ffast-math" MaskRay wrote: Sorry, perhaps not here. But use -SAME: for some lines below, e.g. `! CHECK-NOLINKING-NO: "-lomp"` https://github.com/llvm/llvm-project/pull/117573 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [clang][driver] Special care for -l flags in config files (PR #117573)
https://github.com/thesamesam commented: This seems OK to me, although I'd feel more comfortable if we had a test which relied on `--Wl,--as-needed`. https://github.com/llvm/llvm-project/pull/117573 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add BreakBeforeTemplateClose option (PR #118046)
https://github.com/leijurv updated https://github.com/llvm/llvm-project/pull/118046 >From 1caf823165b16f6701993d586df51d5cdbf0885e Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 29 Nov 2024 21:54:36 -0600 Subject: [PATCH] [clang-format] Add BreakBeforeTemplateClose option --- clang/docs/ClangFormatStyleOptions.rst | 21 clang/docs/ReleaseNotes.rst| 1 + clang/include/clang/Format/Format.h| 20 clang/lib/Format/ContinuationIndenter.cpp | 11 ++ clang/lib/Format/ContinuationIndenter.h| 26 ++-- clang/lib/Format/Format.cpp| 2 + clang/lib/Format/TokenAnnotator.cpp| 2 +- clang/unittests/Format/ConfigParseTest.cpp | 1 + clang/unittests/Format/FormatTest.cpp | 131 + 9 files changed, 206 insertions(+), 9 deletions(-) diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst index 4be448171699ca..84ab1b0a2eff61 100644 --- a/clang/docs/ClangFormatStyleOptions.rst +++ b/clang/docs/ClangFormatStyleOptions.rst @@ -3416,6 +3416,27 @@ the configuration (without a prefix: ``Auto``). +.. _BreakBeforeTemplateClose: + +**BreakBeforeTemplateClose** (``Boolean``) :versionbadge:`clang-format 20` :ref:`¶ ` + If ``true``, a line break will be placed before the ``>`` in a multiline + template declaration. + + .. code-block:: c++ + + true: + template < + typename Foo, + typename Bar, + typename Baz + > + + false: + template < + typename Foo, + typename Bar, + typename Baz> + .. _BreakBeforeTernaryOperators: **BreakBeforeTernaryOperators** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ ` diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index e44aefa90ab386..867d4b5d8c3f18 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -976,6 +976,7 @@ clang-format ``Never``, and ``true`` to ``Always``. - Adds ``RemoveEmptyLinesInUnwrappedLines`` option. - Adds ``KeepFormFeed`` option and set it to ``true`` for ``GNU`` style. +- Adds ``BreakBeforeTemplateClose`` option. libclang diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h index 6383934afa2c40..bffd964f6aa8aa 100644 --- a/clang/include/clang/Format/Format.h +++ b/clang/include/clang/Format/Format.h @@ -2248,6 +2248,25 @@ struct FormatStyle { /// \version 16 BreakBeforeInlineASMColonStyle BreakBeforeInlineASMColon; + /// If ``true``, a line break will be placed before the ``>`` in a multiline + /// template declaration. + /// \code + ///true: + ///template < + ///typename Foo, + ///typename Bar, + ///typename Baz + ///> + /// + ///false: + ///template < + ///typename Foo, + ///typename Bar, + ///typename Baz> + /// \endcode + /// \version 20 + bool BreakBeforeTemplateClose; + /// If ``true``, ternary operators will be placed after line breaks. /// \code ///true: @@ -5184,6 +5203,7 @@ struct FormatStyle { BreakBeforeBraces == R.BreakBeforeBraces && BreakBeforeConceptDeclarations == R.BreakBeforeConceptDeclarations && BreakBeforeInlineASMColon == R.BreakBeforeInlineASMColon && + BreakBeforeTemplateClose == R.BreakBeforeTemplateClose && BreakBeforeTernaryOperators == R.BreakBeforeTernaryOperators && BreakBinaryOperations == R.BreakBinaryOperations && BreakConstructorInitializers == R.BreakConstructorInitializers && diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index aed86c1fb99551..4c783623afc535 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -406,6 +406,10 @@ bool ContinuationIndenter::mustBreak(const LineState &State) { } if (CurrentState.BreakBeforeClosingParen && Current.is(tok::r_paren)) return true; + if (CurrentState.BreakBeforeClosingAngle && + Current.ClosesTemplateDeclaration && Style.BreakBeforeTemplateClose) { +return true; + } if (Style.Language == FormatStyle::LK_ObjC && Style.ObjCBreakBeforeNestedBlockParam && Current.ObjCSelectorNameParts > 1 && @@ -1234,6 +1238,9 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State, Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent; } + if (PreviousNonComment && PreviousNonComment->is(tok::less)) +CurrentState.BreakBeforeClosingAngle = true; + if (CurrentState.AvoidBinPacking) { // If we are breaking after '(', '{', '<', or this is the break after a ':' // to start a member initializer list in a constructor, this should not @@ -1370,6 +1377,10 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) { State.Stack.size() > 1) { return State.Stack[State.Stack.size() - 2].LastSpac
[clang] Fix double-quotes in diagnostic when attempting to access a ext_vector of bools (PR #118186)
https://github.com/smallp-o-p created https://github.com/llvm/llvm-project/pull/118186 Fixes #116932 >From 3b7cf6e65bdfedf8d15e393c9c2f819c4ed70386 Mon Sep 17 00:00:00 2001 From: William Tran-Viet Date: Sat, 30 Nov 2024 15:53:32 -0500 Subject: [PATCH] Fix double-quotes in diagnostic when attempting to access a ext_vector of bools --- clang/lib/Sema/SemaExprMember.cpp | 4 +++- clang/test/SemaCXX/vector-bool.cpp | 8 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/clang/lib/Sema/SemaExprMember.cpp b/clang/lib/Sema/SemaExprMember.cpp index 434768b99d631e..3d843bb84d9d8b 100644 --- a/clang/lib/Sema/SemaExprMember.cpp +++ b/clang/lib/Sema/SemaExprMember.cpp @@ -1655,8 +1655,10 @@ static ExprResult LookupMemberExpr(Sema &S, LookupResult &R, // We disallow element access for ext_vector_type bool. There is no way to // materialize a reference to a vector element as a pointer (each element is // one bit in the vector). +assert(MemberName.isIdentifier() && + "Ext vector component name not an identifier!"); S.Diag(R.getNameLoc(), diag::err_ext_vector_component_name_illegal) -<< MemberName +<< MemberName.getAsIdentifierInfo()->getName() << (BaseExpr.get() ? BaseExpr.get()->getSourceRange() : SourceRange()); return ExprError(); } diff --git a/clang/test/SemaCXX/vector-bool.cpp b/clang/test/SemaCXX/vector-bool.cpp index e99d420e73fab2..cd638056f348b0 100644 --- a/clang/test/SemaCXX/vector-bool.cpp +++ b/clang/test/SemaCXX/vector-bool.cpp @@ -85,10 +85,10 @@ void foo(const bool& X); // Disallow element-wise access. bool* ElementRefs() { - eight_bools.y = false; // expected-error@88 {{illegal vector component name ''y''}} - &eight_bools.z;// expected-error@89 {{illegal vector component name ''z''}} - foo(eight_bools.w);// expected-error@90 {{illegal vector component name ''w''}} - foo(eight_bools.wyx); // expected-error@91 {{illegal vector component name ''wyx''}} + eight_bools.y = false; // expected-error@88 {{illegal vector component name 'y'}} + &eight_bools.z;// expected-error@89 {{illegal vector component name 'z'}} + foo(eight_bools.w);// expected-error@90 {{illegal vector component name 'w'}} + foo(eight_bools.wyx); // expected-error@91 {{illegal vector component name 'wyx'}} } void Sizeof() { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Fix double-quotes in diagnostic when attempting to access a ext_vector of bools (PR #118186)
llvmbot wrote: @llvm/pr-subscribers-clang Author: William Tran-Viet (smallp-o-p) Changes Fixes #116932 --- Full diff: https://github.com/llvm/llvm-project/pull/118186.diff 2 Files Affected: - (modified) clang/lib/Sema/SemaExprMember.cpp (+3-1) - (modified) clang/test/SemaCXX/vector-bool.cpp (+4-4) ``diff diff --git a/clang/lib/Sema/SemaExprMember.cpp b/clang/lib/Sema/SemaExprMember.cpp index 434768b99d631e..3d843bb84d9d8b 100644 --- a/clang/lib/Sema/SemaExprMember.cpp +++ b/clang/lib/Sema/SemaExprMember.cpp @@ -1655,8 +1655,10 @@ static ExprResult LookupMemberExpr(Sema &S, LookupResult &R, // We disallow element access for ext_vector_type bool. There is no way to // materialize a reference to a vector element as a pointer (each element is // one bit in the vector). +assert(MemberName.isIdentifier() && + "Ext vector component name not an identifier!"); S.Diag(R.getNameLoc(), diag::err_ext_vector_component_name_illegal) -<< MemberName +<< MemberName.getAsIdentifierInfo()->getName() << (BaseExpr.get() ? BaseExpr.get()->getSourceRange() : SourceRange()); return ExprError(); } diff --git a/clang/test/SemaCXX/vector-bool.cpp b/clang/test/SemaCXX/vector-bool.cpp index e99d420e73fab2..cd638056f348b0 100644 --- a/clang/test/SemaCXX/vector-bool.cpp +++ b/clang/test/SemaCXX/vector-bool.cpp @@ -85,10 +85,10 @@ void foo(const bool& X); // Disallow element-wise access. bool* ElementRefs() { - eight_bools.y = false; // expected-error@88 {{illegal vector component name ''y''}} - &eight_bools.z;// expected-error@89 {{illegal vector component name ''z''}} - foo(eight_bools.w);// expected-error@90 {{illegal vector component name ''w''}} - foo(eight_bools.wyx); // expected-error@91 {{illegal vector component name ''wyx''}} + eight_bools.y = false; // expected-error@88 {{illegal vector component name 'y'}} + &eight_bools.z;// expected-error@89 {{illegal vector component name 'z'}} + foo(eight_bools.w);// expected-error@90 {{illegal vector component name 'w'}} + foo(eight_bools.wyx); // expected-error@91 {{illegal vector component name 'wyx'}} } void Sizeof() { `` https://github.com/llvm/llvm-project/pull/118186 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [clang][driver] Special care for -l flags in config files (PR #117573)
pawosm-arm wrote: > This seems OK to me, although I'd feel more comfortable if we had a test > which relied on `--Wl,--as-needed` too. Could you provide or describe some example? https://github.com/llvm/llvm-project/pull/117573 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [clang-tidy][use-internal-linkage]fix false positives for ExportDecl (PR #117901)
5chmidti wrote: > > Please add the matcher to > > https://github.com/llvm/llvm-project/blob/main/clang/lib/ASTMatchers/Dynamic/Registry.cpp > > as well (clang-query). > > i will do it separately to avoid this pr become bigger. I think you only have to add it into that file for it to work, and IMO a single PR for this change would be better. But as long as it gets added, I'm fine with it https://github.com/llvm/llvm-project/pull/117901 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add BreakBeforeTemplateClose option (PR #118046)
https://github.com/leijurv updated https://github.com/llvm/llvm-project/pull/118046 >From b254c9311fb91374a21ba6ac5d44e087e4a55e98 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 29 Nov 2024 21:54:36 -0600 Subject: [PATCH] [clang-format] Add BreakBeforeTemplateClose option --- clang/docs/ClangFormatStyleOptions.rst | 21 clang/docs/ReleaseNotes.rst| 1 + clang/include/clang/Format/Format.h| 20 clang/lib/Format/ContinuationIndenter.cpp | 11 ++ clang/lib/Format/ContinuationIndenter.h| 26 ++-- clang/lib/Format/Format.cpp| 2 + clang/lib/Format/TokenAnnotator.cpp| 2 +- clang/unittests/Format/ConfigParseTest.cpp | 1 + clang/unittests/Format/FormatTest.cpp | 131 + 9 files changed, 206 insertions(+), 9 deletions(-) diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst index 4be448171699ca..84ab1b0a2eff61 100644 --- a/clang/docs/ClangFormatStyleOptions.rst +++ b/clang/docs/ClangFormatStyleOptions.rst @@ -3416,6 +3416,27 @@ the configuration (without a prefix: ``Auto``). +.. _BreakBeforeTemplateClose: + +**BreakBeforeTemplateClose** (``Boolean``) :versionbadge:`clang-format 20` :ref:`¶ ` + If ``true``, a line break will be placed before the ``>`` in a multiline + template declaration. + + .. code-block:: c++ + + true: + template < + typename Foo, + typename Bar, + typename Baz + > + + false: + template < + typename Foo, + typename Bar, + typename Baz> + .. _BreakBeforeTernaryOperators: **BreakBeforeTernaryOperators** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ ` diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index e44aefa90ab386..867d4b5d8c3f18 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -976,6 +976,7 @@ clang-format ``Never``, and ``true`` to ``Always``. - Adds ``RemoveEmptyLinesInUnwrappedLines`` option. - Adds ``KeepFormFeed`` option and set it to ``true`` for ``GNU`` style. +- Adds ``BreakBeforeTemplateClose`` option. libclang diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h index 6383934afa2c40..bffd964f6aa8aa 100644 --- a/clang/include/clang/Format/Format.h +++ b/clang/include/clang/Format/Format.h @@ -2248,6 +2248,25 @@ struct FormatStyle { /// \version 16 BreakBeforeInlineASMColonStyle BreakBeforeInlineASMColon; + /// If ``true``, a line break will be placed before the ``>`` in a multiline + /// template declaration. + /// \code + ///true: + ///template < + ///typename Foo, + ///typename Bar, + ///typename Baz + ///> + /// + ///false: + ///template < + ///typename Foo, + ///typename Bar, + ///typename Baz> + /// \endcode + /// \version 20 + bool BreakBeforeTemplateClose; + /// If ``true``, ternary operators will be placed after line breaks. /// \code ///true: @@ -5184,6 +5203,7 @@ struct FormatStyle { BreakBeforeBraces == R.BreakBeforeBraces && BreakBeforeConceptDeclarations == R.BreakBeforeConceptDeclarations && BreakBeforeInlineASMColon == R.BreakBeforeInlineASMColon && + BreakBeforeTemplateClose == R.BreakBeforeTemplateClose && BreakBeforeTernaryOperators == R.BreakBeforeTernaryOperators && BreakBinaryOperations == R.BreakBinaryOperations && BreakConstructorInitializers == R.BreakConstructorInitializers && diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index aed86c1fb99551..4c783623afc535 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -406,6 +406,10 @@ bool ContinuationIndenter::mustBreak(const LineState &State) { } if (CurrentState.BreakBeforeClosingParen && Current.is(tok::r_paren)) return true; + if (CurrentState.BreakBeforeClosingAngle && + Current.ClosesTemplateDeclaration && Style.BreakBeforeTemplateClose) { +return true; + } if (Style.Language == FormatStyle::LK_ObjC && Style.ObjCBreakBeforeNestedBlockParam && Current.ObjCSelectorNameParts > 1 && @@ -1234,6 +1238,9 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State, Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent; } + if (PreviousNonComment && PreviousNonComment->is(tok::less)) +CurrentState.BreakBeforeClosingAngle = true; + if (CurrentState.AvoidBinPacking) { // If we are breaking after '(', '{', '<', or this is the break after a ':' // to start a member initializer list in a constructor, this should not @@ -1370,6 +1377,10 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) { State.Stack.size() > 1) { return State.Stack[State.Stack.size() - 2].LastSpac
[clang] Add `.cjs` extension handling for JavaScript Language. (PR #118188)
https://github.com/d3x0r created https://github.com/llvm/llvm-project/pull/118188 None >From 8ce527dc2cc7ac285f782648838664491abffc30 Mon Sep 17 00:00:00 2001 From: d3x0r Date: Sat, 30 Nov 2024 02:32:40 -0800 Subject: [PATCH] Add *.cjs handling for JavaScript Language. --- clang/lib/Format/Format.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index ee52972ce66f4a..dcaac4b0d42cc5 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -3950,6 +3950,7 @@ static FormatStyle::LanguageKind getLanguageByFileName(StringRef FileName) { return FormatStyle::LK_Java; if (FileName.ends_with_insensitive(".js") || FileName.ends_with_insensitive(".mjs") || + FileName.ends_with_insensitive(".cjs") || FileName.ends_with_insensitive(".ts")) { return FormatStyle::LK_JavaScript; // (module) JavaScript or TypeScript. } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add `.cjs` extension handling for JavaScript Language. (PR #118188)
github-actions[bot] wrote: Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using `@` followed by their GitHub username. If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html). You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/). https://github.com/llvm/llvm-project/pull/118188 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add `.cjs` extension handling for JavaScript Language. (PR #118188)
llvmbot wrote: @llvm/pr-subscribers-clang-format Author: Jim B (d3x0r) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/118188.diff 1 Files Affected: - (modified) clang/lib/Format/Format.cpp (+1) ``diff diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index ee52972ce66f4a..dcaac4b0d42cc5 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -3950,6 +3950,7 @@ static FormatStyle::LanguageKind getLanguageByFileName(StringRef FileName) { return FormatStyle::LK_Java; if (FileName.ends_with_insensitive(".js") || FileName.ends_with_insensitive(".mjs") || + FileName.ends_with_insensitive(".cjs") || FileName.ends_with_insensitive(".ts")) { return FormatStyle::LK_JavaScript; // (module) JavaScript or TypeScript. } `` https://github.com/llvm/llvm-project/pull/118188 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add `.cjs` extension handling for JavaScript Language. (PR #118188)
https://github.com/d3x0r edited https://github.com/llvm/llvm-project/pull/118188 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [clang][driver] Special care for -l flags in config files (PR #117573)
@@ -1062,6 +1062,16 @@ bool Driver::readConfigFile(StringRef FileName, for (Arg *A : *NewOptions) A->claim(); + std::unique_ptr NewLinkerIns = std::make_unique(); pawosm-arm wrote: changed and added a comment https://github.com/llvm/llvm-project/pull/117573 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [clang][driver] Special care for -l flags in config files (PR #117573)
@@ -61,3 +61,29 @@ ! CHECK-TWO-CONFIGS-NEXT: Configuration file: {{.*}}Inputs{{.}}config2{{.}}config-4.cfg ! CHECK-TWO-CONFIGS: -ffp-contract=fast ! CHECK-TWO-CONFIGS: -O3 + +!--- The linker input flags should be moved to the end of input list and appear only when linking. +! RUN: %flang --target=aarch64-unknown-linux-gnu --config %S/Inputs/config-l.cfg %s -lmylib -Wl,foo.a -### 2>&1 | FileCheck %s -check-prefix CHECK-LINKING +! RUN: %flang --target=aarch64-unknown-linux-gnu --config %S/Inputs/config-l.cfg -fopenmp %s -lmylib -Wl,foo.a -### 2>&1 | FileCheck %s -check-prefix CHECK-LINKING-LIBOMP-GOES-LAST +! RUN: %flang --target=aarch64-unknown-linux-gnu --config %S/Inputs/config-l.cfg -S %s -### 2>&1 | FileCheck %s -check-prefix CHECK-NOLINKING +! RUN: %flang --target=aarch64-unknown-linux-gnu --config %S/Inputs/config-l.cfg -fopenmp -S %s -### 2>&1 | FileCheck %s -check-prefix CHECK-NOLINKING +! RUN: %flang --target=x86_64-pc-windows-msvc--config %S/Inputs/config-l.cfg %s -lmylib -Wl,foo.lib -### 2>&1 | FileCheck %s -check-prefix CHECK-LINKING-MSVC +! RUN: %flang --target=x86_64-pc-windows-msvc--config %S/Inputs/config-l.cfg -S %s -### 2>&1 | FileCheck %s -check-prefix CHECK-NOLINKING-MSVC +! CHECK-LINKING: Configuration file: {{.*}}Inputs{{.}}config-l.cfg +! CHECK-LINKING: "-ffast-math" +! CHECK-LINKING: "{{.*}}-{{.*}}.o" "-lmylib" "foo.a" "-lm" "-Bstatic" "-lhappy" "-Bdynamic" +! CHECK-LINKING-LIBOMP-GOES-LAST: Configuration file: {{.*}}Inputs{{.}}config-l.cfg +! CHECK-LINKING-LIBOMP-GOES-LAST: "-ffast-math" pawosm-arm wrote: Seems I had wrong idea of how "SAME:" works. I'll make adjustments you're suggesting here. https://github.com/llvm/llvm-project/pull/117573 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [clang][driver] Special care for -l flags in config files (PR #117573)
https://github.com/pawosm-arm edited https://github.com/llvm/llvm-project/pull/117573 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [clang][driver] Special care for -l flags in config files (PR #117573)
@@ -61,3 +61,29 @@ ! CHECK-TWO-CONFIGS-NEXT: Configuration file: {{.*}}Inputs{{.}}config2{{.}}config-4.cfg ! CHECK-TWO-CONFIGS: -ffp-contract=fast ! CHECK-TWO-CONFIGS: -O3 + +!--- The linker input flags should be moved to the end of input list and appear only when linking. +! RUN: %flang --target=aarch64-unknown-linux-gnu --config %S/Inputs/config-l.cfg %s -lmylib -Wl,foo.a -### 2>&1 | FileCheck %s -check-prefix CHECK-LINKING +! RUN: %flang --target=aarch64-unknown-linux-gnu --config %S/Inputs/config-l.cfg -fopenmp %s -lmylib -Wl,foo.a -### 2>&1 | FileCheck %s -check-prefix CHECK-LINKING-LIBOMP-GOES-LAST +! RUN: %flang --target=aarch64-unknown-linux-gnu --config %S/Inputs/config-l.cfg -S %s -### 2>&1 | FileCheck %s -check-prefix CHECK-NOLINKING +! RUN: %flang --target=aarch64-unknown-linux-gnu --config %S/Inputs/config-l.cfg -fopenmp -S %s -### 2>&1 | FileCheck %s -check-prefix CHECK-NOLINKING +! RUN: %flang --target=x86_64-pc-windows-msvc--config %S/Inputs/config-l.cfg %s -lmylib -Wl,foo.lib -### 2>&1 | FileCheck %s -check-prefix CHECK-LINKING-MSVC +! RUN: %flang --target=x86_64-pc-windows-msvc--config %S/Inputs/config-l.cfg -S %s -### 2>&1 | FileCheck %s -check-prefix CHECK-NOLINKING-MSVC +! CHECK-LINKING: Configuration file: {{.*}}Inputs{{.}}config-l.cfg +! CHECK-LINKING: "-ffast-math" +! CHECK-LINKING: "{{.*}}-{{.*}}.o" "-lmylib" "foo.a" "-lm" "-Bstatic" "-lhappy" "-Bdynamic" +! CHECK-LINKING-LIBOMP-GOES-LAST: Configuration file: {{.*}}Inputs{{.}}config-l.cfg +! CHECK-LINKING-LIBOMP-GOES-LAST: "-ffast-math" pawosm-arm wrote: Adding "-fopenmp" may result in: "-latomic" "-lm" "-lomp" https://github.com/llvm/llvm-project/pull/117573 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add an off-by-default warning to complain about MSVC bitfield padding (PR #117428)
https://github.com/ojhunt updated https://github.com/llvm/llvm-project/pull/117428 >From 3e25d7ef2e223942298078dace8979905956d05c Mon Sep 17 00:00:00 2001 From: Oliver Hunt Date: Fri, 22 Nov 2024 17:53:24 +0100 Subject: [PATCH] Add an off-by-default warning to complain about MSVC bitfield padding --- clang/include/clang/Basic/DiagnosticGroups.td | 1 + .../clang/Basic/DiagnosticSemaKinds.td| 6 + clang/lib/Sema/SemaDecl.cpp | 27 ++- .../SemaCXX/ms_struct-bitfield-padding.cpp| 180 ++ 4 files changed, 212 insertions(+), 2 deletions(-) create mode 100644 clang/test/SemaCXX/ms_struct-bitfield-padding.cpp diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index df9bf94b5d0398..57bdda4b8f8b47 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -631,6 +631,7 @@ def Packed : DiagGroup<"packed", [PackedNonPod]>; def PaddedBitField : DiagGroup<"padded-bitfield">; def Padded : DiagGroup<"padded", [PaddedBitField]>; def UnalignedAccess : DiagGroup<"unaligned-access">; +def MSBitfieldCompatibility : DiagGroup<"ms-bitfield-packing-compatibility">; def PessimizingMove : DiagGroup<"pessimizing-move">; def ReturnStdMove : DiagGroup<"return-std-move">; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index eb05a6a77978af..aa13e3438d3739 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -6418,6 +6418,12 @@ def warn_signed_bitfield_enum_conversion : Warning< InGroup, DefaultIgnore; def note_change_bitfield_sign : Note< "consider making the bitfield type %select{unsigned|signed}0">; +def warn_ms_bitfield_mismatched_storage_packing : Warning< + "bit-field %0 of type %1 has a different storage size (%2 vs %3 bytes) than the " + "preceding bit-field and may not be packed under MSVC ABI">, + InGroup, DefaultIgnore; +def note_ms_bitfield_mismatched_storage_size_previous : Note< + "preceding bit-field %0 declared here with type %1">; def warn_missing_braces : Warning< "suggest braces around initialization of subobject">, diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 74b0e5ad23bd48..18aeca3b34f659 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -19001,9 +19001,9 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl, // Verify that all the fields are okay. SmallVector RecFields; - + std::optional PreviousField; for (ArrayRef::iterator i = Fields.begin(), end = Fields.end(); - i != end; ++i) { + i != end; PreviousField = cast(*i), ++i) { FieldDecl *FD = cast(*i); // Get the type for the field. @@ -19213,6 +19213,29 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl, if (Record && FD->getType().isVolatileQualified()) Record->setHasVolatileMember(true); +auto IsNonDependentBitField = [](const FieldDecl *FD) { + if (!FD->isBitField()) +return false; + if (FD->getType()->isDependentType()) +return false; + return true; +}; + +if (Record && PreviousField && IsNonDependentBitField(FD) && +IsNonDependentBitField(*PreviousField)) { + unsigned FDStorageSize = + Context.getTypeSizeInChars(FD->getType()).getQuantity(); + unsigned PreviousFieldStorageSize = + Context.getTypeSizeInChars((*PreviousField)->getType()).getQuantity(); + if (FDStorageSize != PreviousFieldStorageSize) { +Diag(FD->getLocation(), + diag::warn_ms_bitfield_mismatched_storage_packing) +<< FD << FD->getType() << FDStorageSize << PreviousFieldStorageSize; +Diag((*PreviousField)->getLocation(), + diag::note_ms_bitfield_mismatched_storage_size_previous) +<< *PreviousField << (*PreviousField)->getType(); + } +} // Keep track of the number of named members. if (FD->getIdentifier()) ++NumNamedMembers; diff --git a/clang/test/SemaCXX/ms_struct-bitfield-padding.cpp b/clang/test/SemaCXX/ms_struct-bitfield-padding.cpp new file mode 100644 index 00..001086de5bbd10 --- /dev/null +++ b/clang/test/SemaCXX/ms_struct-bitfield-padding.cpp @@ -0,0 +1,180 @@ + +// RUN: %clang_cc1 -fsyntax-only -Wms-bitfield-packing-compatibility -verify -triple armv8 -std=c++23 %s +// RUN: %clang_cc1 -fsyntax-only -DMS_BITFIELDS -mms-bitfields -verify=msbitfields -triple armv8-apple-macos10.15 -std=c++23 %s + +// msbitfields-no-diagnostics + +enum Enum1 { Enum1_A, Enum1_B }; +enum Enum2 { Enum2_A, Enum2_B }; + +enum class EnumU32_1 : unsigned { A, B }; +enum class EnumU32_2 : unsigned { A, B }; +enum class EnumU64 : unsigned long long { A, B }; +enum class EnumI32 : int { A, B }; +enum class EnumU8 : unsigned char { A, B }; +enu
[clang] [flang] [clang][driver] Special care for -l flags in config files (PR #117573)
https://github.com/thesamesam edited https://github.com/llvm/llvm-project/pull/117573 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Add Qualcomm uC Xqcia (Arithmetic) extension (PR #118113)
https://github.com/topperc approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/118113 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [clang][driver] Special care for -l flags in config files (PR #117573)
@@ -1062,6 +1062,19 @@ bool Driver::readConfigFile(StringRef FileName, for (Arg *A : *NewOptions) A->claim(); + // Filter out all -l and -Wl, options, put them into a separate list and erase + // from the original list of configuration file options. These will be used + // only when linking and appended after all of the command line options. + auto NewLinkerIns = std::make_unique(); + for (Arg *A : NewOptions->filtered(options::OPT_Wl_COMMA, options::OPT_l)) { +const Arg *BaseArg = &A->getBaseArg(); +if (BaseArg == A) + BaseArg = nullptr; MaskRay wrote: `getBaseArg()` is always nullptr. I've cleaned up the existing code using it. Please rebase https://github.com/llvm/llvm-project/pull/117573 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [clang][driver] Special care for -l flags in config files (PR #117573)
@@ -61,3 +61,29 @@ ! CHECK-TWO-CONFIGS-NEXT: Configuration file: {{.*}}Inputs{{.}}config2{{.}}config-4.cfg ! CHECK-TWO-CONFIGS: -ffp-contract=fast ! CHECK-TWO-CONFIGS: -O3 + +!--- The linker input flags should be moved to the end of input list and appear only when linking. +! RUN: %flang --target=aarch64-unknown-linux-gnu --config %S/Inputs/config-l.cfg %s -lmylib -Wl,foo.a -### 2>&1 | FileCheck %s -check-prefix CHECK-LINKING +! RUN: %flang --target=aarch64-unknown-linux-gnu --config %S/Inputs/config-l.cfg -fopenmp %s -lmylib -Wl,foo.a -### 2>&1 | FileCheck %s -check-prefix CHECK-LINKING-LIBOMP-GOES-LAST +! RUN: %flang --target=aarch64-unknown-linux-gnu --config %S/Inputs/config-l.cfg -S %s -### 2>&1 | FileCheck %s -check-prefix CHECK-NOLINKING +! RUN: %flang --target=aarch64-unknown-linux-gnu --config %S/Inputs/config-l.cfg -fopenmp -S %s -### 2>&1 | FileCheck %s -check-prefix CHECK-NOLINKING +! RUN: %flang --target=x86_64-pc-windows-msvc--config %S/Inputs/config-l.cfg %s -lmylib -Wl,foo.lib -### 2>&1 | FileCheck %s -check-prefix CHECK-LINKING-MSVC +! RUN: %flang --target=x86_64-pc-windows-msvc--config %S/Inputs/config-l.cfg -S %s -### 2>&1 | FileCheck %s -check-prefix CHECK-NOLINKING-MSVC +! CHECK-LINKING: Configuration file: {{.*}}Inputs{{.}}config-l.cfg +! CHECK-LINKING: "-ffast-math" +! CHECK-LINKING: "{{.*}}-{{.*}}.o" "-lmylib" "foo.a" "-lm" "-Bstatic" "-lhappy" "-Bdynamic" +! CHECK-LINKING-LIBOMP-GOES-LAST: Configuration file: {{.*}}Inputs{{.}}config-l.cfg +! CHECK-LINKING-LIBOMP-GOES-LAST: "-ffast-math" MaskRay wrote: If two options are adjacent, place them on the same SAME line. Otherwise, if they are on the same line in the output, use `-SAME:` https://github.com/llvm/llvm-project/pull/117573 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [clang][driver] Special care for -l flags in config files (PR #117573)
@@ -82,3 +82,29 @@ // CHECK-TWO-CONFIGS: -isysroot // CHECK-TWO-CONFIGS-SAME: /opt/data // CHECK-TWO-CONFIGS-SAME: -Wall + +//--- The linker input flags should be moved to the end of input list and appear only when linking. +// RUN: %clang --target=aarch64-unknown-linux-gnu --config %S/Inputs/config-l.cfg %s -lmylib -Wl,foo.a -### 2>&1 | FileCheck %s -check-prefix CHECK-LINKING +// RUN: %clang --target=aarch64-unknown-linux-gnu --config %S/Inputs/config-l.cfg -fopenmp %s -lmylib -Wl,foo.a -### 2>&1 | FileCheck %s -check-prefix CHECK-LINKING-LIBOMP-GOES-LAST +// RUN: %clang --target=aarch64-unknown-linux-gnu --config %S/Inputs/config-l.cfg -S %s -### 2>&1 | FileCheck %s -check-prefix CHECK-NOLINKING +// RUN: %clang --target=aarch64-unknown-linux-gnu --config %S/Inputs/config-l.cfg -fopenmp -S %s -### 2>&1 | FileCheck %s -check-prefix CHECK-NOLINKING +// RUN: %clang --target=x86_64-pc-windows-msvc--config %S/Inputs/config-l.cfg %s -lmylib -Wl,foo.lib -### 2>&1 | FileCheck %s -check-prefix CHECK-LINKING-MSVC +// RUN: %clang --target=x86_64-pc-windows-msvc--config %S/Inputs/config-l.cfg -S %s -### 2>&1 | FileCheck %s -check-prefix CHECK-NOLINKING-MSVC +// CHECK-LINKING: Configuration file: {{.*}}Inputs{{.}}config-l.cfg +// CHECK-LINKING: "-Wall" +// CHECK-LINKING: "{{.*}}-{{.*}}.o" "-lmylib" "foo.a" "-lm" "-Bstatic" "-lhappy" "-Bdynamic" +// CHECK-LINKING-LIBOMP-GOES-LAST: Configuration file: {{.*}}Inputs{{.}}config-l.cfg +// CHECK-LINKING-LIBOMP-GOES-LAST: "-Wall" MaskRay wrote: If two options are adjacent, place them on the same SAME line. Otherwise, if they are on the same line in the output, use -SAME: https://github.com/llvm/llvm-project/pull/117573 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [clang][driver] Special care for -l flags in config files (PR #117573)
@@ -1073,6 +1086,19 @@ bool Driver::readConfigFile(StringRef FileName, appendOneArg(*CfgOptions, Opt, BaseArg); } } + + if (!CfgLinkerInputs) +CfgLinkerInputs = std::move(NewLinkerIns); + else { +// If this is a subsequent config file, append options to the previous one. +for (auto *Opt : *NewLinkerIns) { + const Arg *BaseArg = &Opt->getBaseArg(); pawosm-arm wrote: removed https://github.com/llvm/llvm-project/pull/117573 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [clang][driver] Special care for -l flags in config files (PR #117573)
@@ -1062,6 +1062,19 @@ bool Driver::readConfigFile(StringRef FileName, for (Arg *A : *NewOptions) A->claim(); + // Filter out all -l and -Wl, options, put them into a separate list and erase + // from the original list of configuration file options. These will be used + // only when linking and appended after all of the command line options. + auto NewLinkerIns = std::make_unique(); + for (Arg *A : NewOptions->filtered(options::OPT_Wl_COMMA, options::OPT_l)) { +const Arg *BaseArg = &A->getBaseArg(); +if (BaseArg == A) + BaseArg = nullptr; pawosm-arm wrote: rebased https://github.com/llvm/llvm-project/pull/117573 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [clang][driver] Special care for -l flags in config files (PR #117573)
@@ -82,3 +82,29 @@ // CHECK-TWO-CONFIGS: -isysroot // CHECK-TWO-CONFIGS-SAME: /opt/data // CHECK-TWO-CONFIGS-SAME: -Wall + +//--- The linker input flags should be moved to the end of input list and appear only when linking. +// RUN: %clang --target=aarch64-unknown-linux-gnu --config %S/Inputs/config-l.cfg %s -lmylib -Wl,foo.a -### 2>&1 | FileCheck %s -check-prefix CHECK-LINKING +// RUN: %clang --target=aarch64-unknown-linux-gnu --config %S/Inputs/config-l.cfg -fopenmp %s -lmylib -Wl,foo.a -### 2>&1 | FileCheck %s -check-prefix CHECK-LINKING-LIBOMP-GOES-LAST +// RUN: %clang --target=aarch64-unknown-linux-gnu --config %S/Inputs/config-l.cfg -S %s -### 2>&1 | FileCheck %s -check-prefix CHECK-NOLINKING +// RUN: %clang --target=aarch64-unknown-linux-gnu --config %S/Inputs/config-l.cfg -fopenmp -S %s -### 2>&1 | FileCheck %s -check-prefix CHECK-NOLINKING +// RUN: %clang --target=x86_64-pc-windows-msvc--config %S/Inputs/config-l.cfg %s -lmylib -Wl,foo.lib -### 2>&1 | FileCheck %s -check-prefix CHECK-LINKING-MSVC +// RUN: %clang --target=x86_64-pc-windows-msvc--config %S/Inputs/config-l.cfg -S %s -### 2>&1 | FileCheck %s -check-prefix CHECK-NOLINKING-MSVC +// CHECK-LINKING: Configuration file: {{.*}}Inputs{{.}}config-l.cfg +// CHECK-LINKING: "-Wall" +// CHECK-LINKING: "{{.*}}-{{.*}}.o" "-lmylib" "foo.a" "-lm" "-Bstatic" "-lhappy" "-Bdynamic" +// CHECK-LINKING-LIBOMP-GOES-LAST: Configuration file: {{.*}}Inputs{{.}}config-l.cfg +// CHECK-LINKING-LIBOMP-GOES-LAST: "-Wall" pawosm-arm wrote: the changes have been made https://github.com/llvm/llvm-project/pull/117573 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [RFC] Initial implementation of P2719 (PR #113510)
https://github.com/ojhunt ready_for_review https://github.com/llvm/llvm-project/pull/113510 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits