[clang] [HLSL] Forward arguments in BuiltinTypeMethodBuilder::callBuiltin. NFC (PR #117789)
@@ -656,18 +670,20 @@ BuiltinTypeDeclBuilder::addSimpleTemplateParams(ArrayRef Names, } BuiltinTypeDeclBuilder &BuiltinTypeDeclBuilder::addIncrementCounterMethod() { + using PH = BuiltinTypeMethodBuilder::PlaceHolder; return BuiltinTypeMethodBuilder(SemaRef, *this, "IncrementCounter", SemaRef.getASTContext().UnsignedIntTy) - .callBuiltin("__builtin_hlsl_buffer_update_counter", - {getConstantIntExpr(1)}) + .callBuiltin("__builtin_hlsl_buffer_update_counter", PH::Handle, + getConstantIntExpr(1)) damyanp wrote: How evil would it be to add a `Expr *convertPlaceholder(int)` that does the `getConstantIntExpr` for you, so this could be written as: `.callBuiltin("__builtin_hlsl_buffer_update_conter", PH::Handle, 1)`? https://github.com/llvm/llvm-project/pull/117789 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Forward arguments in BuiltinTypeMethodBuilder::callBuiltin. NFC (PR #117789)
https://github.com/damyanp commented: LGTM - a nit and an idea in the comments. https://github.com/llvm/llvm-project/pull/117789 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Forward arguments in BuiltinTypeMethodBuilder::callBuiltin. NFC (PR #117789)
https://github.com/damyanp edited https://github.com/llvm/llvm-project/pull/117789 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Forward arguments in BuiltinTypeMethodBuilder::callBuiltin. NFC (PR #117789)
@@ -564,9 +585,9 @@ struct BuiltinTypeMethodBuilder { OK_Ordinary); } - BuiltinTypeMethodBuilder & - callBuiltin(StringRef BuiltinName, ArrayRef CallParms, - bool AddResourceHandleAsFirstArg = true) { + template + BuiltinTypeMethodBuilder &callBuiltin(StringRef BuiltinName, Ts... ArgSpecs) { +SmallVector Args{convertPlaceholder(std::forward(ArgSpecs))...}; damyanp wrote: Is SmallVector smart enough for this to evaporate into being a stack allocated array, or is there a chance that it might make a heap allocation to store the args? https://github.com/llvm/llvm-project/pull/117789 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ubsan] Change ubsan-unique-traps to use nomerge instead of counter (PR #117651)
https://github.com/thurstond updated https://github.com/llvm/llvm-project/pull/117651 >From f24a87de48c42f310ee73ecf480ea2dcf631881f Mon Sep 17 00:00:00 2001 From: Thurston Dang Date: Tue, 26 Nov 2024 00:33:09 + Subject: [PATCH 1/9] [ubsan] Change ubsan-unique-traps to use nomerge instead of counter https://github.com/llvm/llvm-project/pull/65972 (continuation of https://reviews.llvm.org/D148654) had considered adding nomerge to ubsantrap, but did not proceed with that because of https://github.com/llvm/llvm-project/issues/53011. Instead, it added a counter (based on TrapBB->getParent()->size()) to each ubsantrap call. However, this counter is not guaranteed to be unique after inlining, as shown by https://github.com/llvm/llvm-project/pull/83470, which can result in ubsantraps being merged by the backend. https://github.com/llvm/llvm-project/pull/101549 fixed has since fixed the nomerge limitation ("It sets nomerge flag for the node if the instruction has nomerge arrtibute."). This patch therefore takes advantage of nomerge instead of using the counter, guaranteeing that the ubsantraps are not merged. This patch is equivalent to https://github.com/llvm/llvm-project/pull/83470 but also adds nomerge and updates the test that was precommitted in https://github.com/llvm/llvm-project/pull/117649. --- clang/lib/CodeGen/CGExpr.cpp | 6 +- clang/test/CodeGen/bounds-checking.c | 4 +- clang/test/CodeGen/ubsan-trap-merge.c | 106 ++ 3 files changed, 110 insertions(+), 6 deletions(-) create mode 100644 clang/test/CodeGen/ubsan-trap-merge.c diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index d3f470d401b3d4..f8c1e1cd7a4d68 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -3921,16 +3921,14 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked, llvm::CallInst *TrapCall = Builder.CreateCall( CGM.getIntrinsic(llvm::Intrinsic::ubsantrap), -llvm::ConstantInt::get(CGM.Int8Ty, - ClSanitizeDebugDeoptimization - ? TrapBB->getParent()->size() - : static_cast(CheckHandlerID))); +llvm::ConstantInt::get(CGM.Int8Ty, CheckHandlerID)); if (!CGM.getCodeGenOpts().TrapFuncName.empty()) { auto A = llvm::Attribute::get(getLLVMContext(), "trap-func-name", CGM.getCodeGenOpts().TrapFuncName); TrapCall->addFnAttr(A); } +TrapCall->addFnAttr(llvm::Attribute::NoMerge); TrapCall->setDoesNotReturn(); TrapCall->setDoesNotThrow(); Builder.CreateUnreachable(); diff --git a/clang/test/CodeGen/bounds-checking.c b/clang/test/CodeGen/bounds-checking.c index 8100e30d0650ad..f6c4880e70a150 100644 --- a/clang/test/CodeGen/bounds-checking.c +++ b/clang/test/CodeGen/bounds-checking.c @@ -74,11 +74,11 @@ char B2[10]; // CHECK-LABEL: @f8 void f8(int i, int k) { // NOOPTLOCAL: call void @llvm.ubsantrap(i8 3) - // NOOPTARRAY: call void @llvm.ubsantrap(i8 2) + // NOOPTARRAY: call void @llvm.ubsantrap(i8 18) B[i] = '\0'; // NOOPTLOCAL: call void @llvm.ubsantrap(i8 5) - // NOOPTARRAY: call void @llvm.ubsantrap(i8 4) + // NOOPTARRAY: call void @llvm.ubsantrap(i8 18) B2[k] = '\0'; } diff --git a/clang/test/CodeGen/ubsan-trap-merge.c b/clang/test/CodeGen/ubsan-trap-merge.c new file mode 100644 index 00..e6aa7902262813 --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-merge.c @@ -0,0 +1,106 @@ +// NOTE: Assertions have mostly been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5 +// The most important assertion is the attributes at the end of the file, which +// shows that ubsan attaches 'nomerge' to each ubsantrap intrinsic. +// +// RUN: %clang -fsanitize=signed-integer-overflow -S -emit-llvm -fsanitize-trap=all -O3 -mllvm -ubsan-unique-traps %s -o - \ +// RUN: | FileCheck %s + +#include +#include + +// CHECK-LABEL: define dso_local range(i32 -2147483523, -2147483648) i32 @f( +// CHECK-SAME: i32 noundef [[X:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT:[[TMP0:%.*]] = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[X]], i32 125), !nosanitize [[META5:![0-9]+]] +// CHECK-NEXT:[[TMP1:%.*]] = extractvalue { i32, i1 } [[TMP0]], 1, !nosanitize [[META5]] +// CHECK-NEXT:br i1 [[TMP1]], label %[[TRAP:.*]], label %[[CONT:.*]], !nosanitize [[META5]] +// CHECK: [[TRAP]]: +// CHECK-NEXT:tail call void @llvm.ubsantrap(i8 0) #[[ATTR4:[0-9]+]], !nosanitize [[META5]] +// CHECK-NEXT:unreachable, !nosanitize [[META5]] +// CHECK: [[CONT]]: +// CHECK-NEXT:[[TMP2:%.*]] = extractvalue { i32, i1 } [[TMP0]], 0, !nosanitize [[META5]] +// CHECK-NEXT:ret i32 [[TMP2]] +// +int f(int x) { + return x + 125; +} + +// CHECK-LABEL: define dso_local range(i32 -2147483521, -2147483648) i32 @g( +// CHECK-SAME
[clang] [llvm] [ubsan] Change ubsan-unique-traps to use nomerge instead of counter (PR #117651)
@@ -3919,18 +3919,16 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked, Builder.CreateCondBr(Checked, Cont, TrapBB); EmitBlock(TrapBB); -llvm::CallInst *TrapCall = Builder.CreateCall( -CGM.getIntrinsic(llvm::Intrinsic::ubsantrap), -llvm::ConstantInt::get(CGM.Int8Ty, - ClSanitizeDebugDeoptimization - ? TrapBB->getParent()->size() - : static_cast(CheckHandlerID))); +llvm::CallInst *TrapCall = +Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::ubsantrap), + llvm::ConstantInt::get(CGM.Int8Ty, CheckHandlerID)); if (!CGM.getCodeGenOpts().TrapFuncName.empty()) { auto A = llvm::Attribute::get(getLLVMContext(), "trap-func-name", CGM.getCodeGenOpts().TrapFuncName); TrapCall->addFnAttr(A); } +TrapCall->addFnAttr(llvm::Attribute::NoMerge); thurstond wrote: Ah, I see, thanks. I've fixed it (and the test) in https://github.com/llvm/llvm-project/pull/117651/commits/5107ce194c9b03c2f32eb1508df0c92b13b3e2fd https://github.com/llvm/llvm-project/pull/117651 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ubsan] Change ubsan-unique-traps to use nomerge instead of counter (PR #117651)
https://github.com/thurstond updated https://github.com/llvm/llvm-project/pull/117651 >From f24a87de48c42f310ee73ecf480ea2dcf631881f Mon Sep 17 00:00:00 2001 From: Thurston Dang Date: Tue, 26 Nov 2024 00:33:09 + Subject: [PATCH 01/10] [ubsan] Change ubsan-unique-traps to use nomerge instead of counter https://github.com/llvm/llvm-project/pull/65972 (continuation of https://reviews.llvm.org/D148654) had considered adding nomerge to ubsantrap, but did not proceed with that because of https://github.com/llvm/llvm-project/issues/53011. Instead, it added a counter (based on TrapBB->getParent()->size()) to each ubsantrap call. However, this counter is not guaranteed to be unique after inlining, as shown by https://github.com/llvm/llvm-project/pull/83470, which can result in ubsantraps being merged by the backend. https://github.com/llvm/llvm-project/pull/101549 fixed has since fixed the nomerge limitation ("It sets nomerge flag for the node if the instruction has nomerge arrtibute."). This patch therefore takes advantage of nomerge instead of using the counter, guaranteeing that the ubsantraps are not merged. This patch is equivalent to https://github.com/llvm/llvm-project/pull/83470 but also adds nomerge and updates the test that was precommitted in https://github.com/llvm/llvm-project/pull/117649. --- clang/lib/CodeGen/CGExpr.cpp | 6 +- clang/test/CodeGen/bounds-checking.c | 4 +- clang/test/CodeGen/ubsan-trap-merge.c | 106 ++ 3 files changed, 110 insertions(+), 6 deletions(-) create mode 100644 clang/test/CodeGen/ubsan-trap-merge.c diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index d3f470d401b3d4..f8c1e1cd7a4d68 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -3921,16 +3921,14 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked, llvm::CallInst *TrapCall = Builder.CreateCall( CGM.getIntrinsic(llvm::Intrinsic::ubsantrap), -llvm::ConstantInt::get(CGM.Int8Ty, - ClSanitizeDebugDeoptimization - ? TrapBB->getParent()->size() - : static_cast(CheckHandlerID))); +llvm::ConstantInt::get(CGM.Int8Ty, CheckHandlerID)); if (!CGM.getCodeGenOpts().TrapFuncName.empty()) { auto A = llvm::Attribute::get(getLLVMContext(), "trap-func-name", CGM.getCodeGenOpts().TrapFuncName); TrapCall->addFnAttr(A); } +TrapCall->addFnAttr(llvm::Attribute::NoMerge); TrapCall->setDoesNotReturn(); TrapCall->setDoesNotThrow(); Builder.CreateUnreachable(); diff --git a/clang/test/CodeGen/bounds-checking.c b/clang/test/CodeGen/bounds-checking.c index 8100e30d0650ad..f6c4880e70a150 100644 --- a/clang/test/CodeGen/bounds-checking.c +++ b/clang/test/CodeGen/bounds-checking.c @@ -74,11 +74,11 @@ char B2[10]; // CHECK-LABEL: @f8 void f8(int i, int k) { // NOOPTLOCAL: call void @llvm.ubsantrap(i8 3) - // NOOPTARRAY: call void @llvm.ubsantrap(i8 2) + // NOOPTARRAY: call void @llvm.ubsantrap(i8 18) B[i] = '\0'; // NOOPTLOCAL: call void @llvm.ubsantrap(i8 5) - // NOOPTARRAY: call void @llvm.ubsantrap(i8 4) + // NOOPTARRAY: call void @llvm.ubsantrap(i8 18) B2[k] = '\0'; } diff --git a/clang/test/CodeGen/ubsan-trap-merge.c b/clang/test/CodeGen/ubsan-trap-merge.c new file mode 100644 index 00..e6aa7902262813 --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-merge.c @@ -0,0 +1,106 @@ +// NOTE: Assertions have mostly been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5 +// The most important assertion is the attributes at the end of the file, which +// shows that ubsan attaches 'nomerge' to each ubsantrap intrinsic. +// +// RUN: %clang -fsanitize=signed-integer-overflow -S -emit-llvm -fsanitize-trap=all -O3 -mllvm -ubsan-unique-traps %s -o - \ +// RUN: | FileCheck %s + +#include +#include + +// CHECK-LABEL: define dso_local range(i32 -2147483523, -2147483648) i32 @f( +// CHECK-SAME: i32 noundef [[X:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT:[[TMP0:%.*]] = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[X]], i32 125), !nosanitize [[META5:![0-9]+]] +// CHECK-NEXT:[[TMP1:%.*]] = extractvalue { i32, i1 } [[TMP0]], 1, !nosanitize [[META5]] +// CHECK-NEXT:br i1 [[TMP1]], label %[[TRAP:.*]], label %[[CONT:.*]], !nosanitize [[META5]] +// CHECK: [[TRAP]]: +// CHECK-NEXT:tail call void @llvm.ubsantrap(i8 0) #[[ATTR4:[0-9]+]], !nosanitize [[META5]] +// CHECK-NEXT:unreachable, !nosanitize [[META5]] +// CHECK: [[CONT]]: +// CHECK-NEXT:[[TMP2:%.*]] = extractvalue { i32, i1 } [[TMP0]], 0, !nosanitize [[META5]] +// CHECK-NEXT:ret i32 [[TMP2]] +// +int f(int x) { + return x + 125; +} + +// CHECK-LABEL: define dso_local range(i32 -2147483521, -2147483648) i32 @g( +// CHECK-SA
[clang] [llvm] [ubsan] Change ubsan-unique-traps to use nomerge instead of counter (PR #117651)
https://github.com/thurstond converted_to_draft https://github.com/llvm/llvm-project/pull/117651 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Improve the lifetime_capture_by diagnostic on the constructor. (PR #117792)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Haojian Wu (hokein) Changes With this change, the lifetime_capture_by code path will not handle the constructor decl to avoid bogus diagnostics (see the testcase). Instead, we reuse the lifetimebound code as the lifetime_capture_by(this) has the same semantic as lifetimebound in constructor. The downside is that the lifetimebound diagnostic is reused for the capture case (I think it is not a big issue). Fixes #117680 --- Full diff: https://github.com/llvm/llvm-project/pull/117792.diff 3 Files Affected: - (modified) clang/lib/Sema/CheckExprLifetime.cpp (+11) - (modified) clang/lib/Sema/SemaChecking.cpp (+6) - (modified) clang/test/Sema/warn-lifetime-analysis-capture-by.cpp (+19) ``diff diff --git a/clang/lib/Sema/CheckExprLifetime.cpp b/clang/lib/Sema/CheckExprLifetime.cpp index 6cdd4dc629e50a..c4fa73127410b5 100644 --- a/clang/lib/Sema/CheckExprLifetime.cpp +++ b/clang/lib/Sema/CheckExprLifetime.cpp @@ -535,6 +535,9 @@ static void visitFunctionCallArguments(IndirectLocalPath &Path, Expr *Call, bool EnableGSLAnalysis = !Callee->getASTContext().getDiagnostics().isIgnored( diag::warn_dangling_lifetime_pointer, SourceLocation()); + bool EnableDanglingCapture = + !Callee->getASTContext().getDiagnostics().isIgnored( + diag::warn_dangling_reference_captured, SourceLocation()); Expr *ObjectArg = nullptr; if (isa(Call) && Callee->isCXXInstanceMember()) { ObjectArg = Args[0]; @@ -623,6 +626,14 @@ static void visitFunctionCallArguments(IndirectLocalPath &Path, Expr *Call, } if (CheckCoroCall || Callee->getParamDecl(I)->hasAttr()) VisitLifetimeBoundArg(Callee->getParamDecl(I), Arg); +else if (const auto *CaptureAttr = + Callee->getParamDecl(I)->getAttr(); + EnableDanglingCapture && CaptureAttr && + isa(Callee) && + llvm::any_of(CaptureAttr->params(), [](int ArgIdx) { + return ArgIdx == LifetimeCaptureByAttr::THIS; + })) + VisitLifetimeBoundArg(Callee->getParamDecl(I), Arg); else if (EnableGSLAnalysis && I == 0) { // Perform GSL analysis for the first argument if (shouldTrackFirstArgument(Callee)) { diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index a49605e4867651..1605523097a6b1 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -3240,8 +3240,14 @@ void Sema::checkLifetimeCaptureBy(FunctionDecl *FD, bool IsMemberFunction, unsigned ArgIdx) { if (!Attr) return; + Expr *Captured = const_cast(GetArgAt(ArgIdx)); for (int CapturingParamIdx : Attr->params()) { + // lifetime_capture_by(this) case is handled in the lifetimebound expr + // initialization codepath. + if (CapturingParamIdx == LifetimeCaptureByAttr::THIS && + isa(FD)) +continue; Expr *Capturing = const_cast(GetArgAt(CapturingParamIdx)); CapturingEntity CE{Capturing}; // Ensure that 'Captured' outlives the 'Capturing' entity. diff --git a/clang/test/Sema/warn-lifetime-analysis-capture-by.cpp b/clang/test/Sema/warn-lifetime-analysis-capture-by.cpp index 4d562bac1e305b..77523210e50203 100644 --- a/clang/test/Sema/warn-lifetime-analysis-capture-by.cpp +++ b/clang/test/Sema/warn-lifetime-analysis-capture-by.cpp @@ -411,3 +411,22 @@ void use() { } } // namespace with_span } // namespace inferred_capture_by + +namespace on_constructor { +struct T { + T(const int& t [[clang::lifetime_capture_by(this)]]); +}; +struct T2 { + T2(const int& t [[clang::lifetime_capture_by(x)]], int& x); +}; +int foo(const T& t); + +void test() { + auto x = foo(T(1)); // OK. no diagnosic + T(1); // OK. no diagnostic + T t(1); // expected-warning {{temporary whose address is used}} + + int a; + T2(1, a); // expected-warning {{object whose reference is captured by}} +} +} // namespace on_constructor `` https://github.com/llvm/llvm-project/pull/117792 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add ByteAddressBuffer definition to HLSLExternalSemaSource #113477 (PR #116699)
https://github.com/joaosaffran updated https://github.com/llvm/llvm-project/pull/116699 >From 7210fcc7de181be6cad451ce1e885498c90c55fe Mon Sep 17 00:00:00 2001 From: Joao Saffran Date: Sat, 9 Nov 2024 01:34:16 + Subject: [PATCH 01/14] adding definition --- clang/lib/Sema/HLSLExternalSemaSource.cpp | 10 + .../test/AST/HLSL/ByteAddressBuffer-AST.hlsl | 41 +++ 2 files changed, 51 insertions(+) create mode 100644 clang/test/AST/HLSL/ByteAddressBuffer-AST.hlsl diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp b/clang/lib/Sema/HLSLExternalSemaSource.cpp index 822202fd81dc89..100d5be5516767 100644 --- a/clang/lib/Sema/HLSLExternalSemaSource.cpp +++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp @@ -710,6 +710,16 @@ void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() { .addArraySubscriptOperators() .completeDefinition(); }); + + Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "ByteAddressBuffer") + .Record; + onCompletion(Decl, [this](CXXRecordDecl *Decl) { +setupBufferType(Decl, *SemaPtr, ResourceClass::UAV, ResourceKind::RawBuffer, +/*IsROV=*/true, +/*RawBuffer=*/true) +.addArraySubscriptOperators() +.completeDefinition(); + }); } void HLSLExternalSemaSource::onCompletion(CXXRecordDecl *Record, diff --git a/clang/test/AST/HLSL/ByteAddressBuffer-AST.hlsl b/clang/test/AST/HLSL/ByteAddressBuffer-AST.hlsl new file mode 100644 index 00..013974369d033a --- /dev/null +++ b/clang/test/AST/HLSL/ByteAddressBuffer-AST.hlsl @@ -0,0 +1,41 @@ +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump -DEMPTY %s | FileCheck -check-prefix=EMPTY %s +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump %s | FileCheck %s + + +// EMPTY: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <> implicit class ByteAddressBuffer +// EMPTY-NEXT: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final + +// There should be no more occurrences of ByteAddressBuffer +// EMPTY-NOT: {{[^[:alnum:]]}}ByteAddressBuffer + +#ifndef EMPTY + +ByteAddressBuffer Buffer; + +#endif + +// CHECK: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <> implicit referenced class ByteAddressBuffer definition + + +// CHECK: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final +// CHECK-NEXT: FieldDecl 0x{{[0-9A-Fa-f]+}} <> implicit h '__hlsl_resource_t +// CHECK-SAME{LITERAL}: [[hlsl::resource_class(UAV)]] +// CHECK-SAME{LITERAL}: [[hlsl::raw_buffer]] +// CHECK-SAME{LITERAL}: [[hlsl::contained_type(char8_t)]] +// CHECK-NEXT: HLSLResourceAttr 0x{{[0-9A-Fa-f]+}} <> Implicit RawBuffer + +// CHECK: CXXMethodDecl 0x{{[0-9A-Fa-f]+}} <> operator[] 'char8_t &const (unsigned int) const' +// CHECK-NEXT: ParmVarDecl 0x{{[0-9A-Fa-f]+}} <> Idx 'unsigned int' +// CHECK-NEXT: CompoundStmt 0x{{[0-9A-Fa-f]+}} <> +// CHECK-NEXT: ReturnStmt 0x{{[0-9A-Fa-f]+}} <> +// CHECK-NEXT: MemberExpr 0x{{[0-9A-Fa-f]+}} <> 'char8_t' lvalue .e 0x{{[0-9A-Fa-f]+}} +// CHECK-NEXT: CXXThisExpr 0x{{[0-9A-Fa-f]+}} <> 'const hlsl::ByteAddressBuffer' lvalue implicit this +// CHECK-NEXT: AlwaysInlineAttr 0x{{[0-9A-Fa-f]+}} <> Implicit always_inline + +// CHECK-NEXT: CXXMethodDecl 0x{{[0-9A-Fa-f]+}} <> operator[] 'char8_t &(unsigned int)' +// CHECK-NEXT: ParmVarDecl 0x{{[0-9A-Fa-f]+}} <> Idx 'unsigned int' +// CHECK-NEXT: CompoundStmt 0x{{[0-9A-Fa-f]+}} <> +// CHECK-NEXT: ReturnStmt 0x{{[0-9A-Fa-f]+}} <> +// CHECK-NEXT: MemberExpr 0x{{[0-9A-Fa-f]+}} <> 'char8_t' lvalue .e 0x{{[0-9A-Fa-f]+}} +// CHECK-NEXT: CXXThisExpr 0x{{[0-9A-Fa-f]+}} <> 'hlsl::ByteAddressBuffer' lvalue implicit this +// CHECK-NEXT: AlwaysInlineAttr 0x{{[0-9A-Fa-f]+}} <> Implicit always_inline >From b1f6a9468e01619d38ae3c5283381c566c130108 Mon Sep 17 00:00:00 2001 From: Joao Saffran Date: Mon, 18 Nov 2024 21:11:47 + Subject: [PATCH 02/14] adding tests --- clang/test/AST/HLSL/ByteAddressBuffer-AST.ll| 13 + .../CodeGenHLSL/builtins/ByteAddressBuffer.hlsl | 8 2 files changed, 21 insertions(+) create mode 100644 clang/test/AST/HLSL/ByteAddressBuffer-AST.ll create mode 100644 clang/test/CodeGenHLSL/builtins/ByteAddressBuffer.hlsl diff --git a/clang/test/AST/HLSL/ByteAddressBuffer-AST.ll b/clang/test/AST/HLSL/ByteAddressBuffer-AST.ll new file mode 100644 index 00..7df06100d69fe5 --- /dev/null +++ b/clang/test/AST/HLSL/ByteAddressBuffer-AST.ll @@ -0,0 +1,13 @@ +; ModuleID = '/workspace/llvm-project/clang/test/AST/HLSL/ByteAddressBuffer-AST.hlsl' +source_filename = "/workspace/llvm-project/clang/test/AST/HLSL/ByteAddressBuffer-AST.hlsl" +target datalayout = "e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:32-f64:64-n8:16:32:64" +target triple = "dxilv1.0-pc-shadermodel6.0-library" + +!llvm.module.flags = !{!0, !1} +!dx.valver = !{!2} +!llvm.ident = !{!3} + +!0 = !{i32 1, !"wchar_size", i32 4} +!1 = !{i32 4, !"dx.disable_optimizations", i32 1} +!2 = !{i32 1, i32 8} +!3 = !{!"clang v
[clang-tools-extra] [clang-tidy] modernize-make-shared: Add MakeSmartPtrType option (PR #117529)
https://github.com/hjanuschka updated https://github.com/llvm/llvm-project/pull/117529 >From 9466fb73adfb050e9eac426459c18a7a5bca1982 Mon Sep 17 00:00:00 2001 From: Helmut Januschka Date: Mon, 25 Nov 2024 09:59:21 +0100 Subject: [PATCH 1/4] WIP: [clang-tidy] Add SmartPtrName to MakeSmartPtrCheck for flexible type matching Introduced a `SmartPtrName` field in `MakeSmartPtrCheck` to allow matching on other smart pointer types, such as `base::scoped_refptr`, in addition to `std::shared_ptr`. This enables more versatile usage of the check without duplicating matcher logic. --- clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.cpp | 5 +++-- clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h| 3 +++ .../clang-tidy/modernize/MakeSmartPtrCheck.cpp | 6 +++--- clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.h | 1 + .../docs/clang-tidy/checks/modernize/make-shared.rst| 6 ++ 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.cpp b/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.cpp index 69f7d9f69eeed0..34009046fec6ae 100644 --- a/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.cpp @@ -16,13 +16,14 @@ using namespace clang::ast_matchers; namespace clang::tidy::modernize { MakeSharedCheck::MakeSharedCheck(StringRef Name, ClangTidyContext *Context) -: MakeSmartPtrCheck(Name, Context, "std::make_shared") {} +: MakeSmartPtrCheck(Name, Context, "std::make_shared"), + MakeSmartPtrType(Options.get("MakeSmartPtrType", "::std::shared_ptr")) {} MakeSharedCheck::SmartPtrTypeMatcher MakeSharedCheck::getSmartPointerTypeMatcher() const { return qualType(hasUnqualifiedDesugaredType( recordType(hasDeclaration(classTemplateSpecializationDecl( - hasName("::std::shared_ptr"), templateArgumentCountIs(1), + hasName(MakeSmartPtrType), templateArgumentCountIs(1), hasTemplateArgument(0, templateArgument(refersToType( qualType().bind(PointerType); } diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h b/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h index caaf4ae403c34f..932796e3a147f1 100644 --- a/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h +++ b/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h @@ -26,6 +26,9 @@ namespace clang::tidy::modernize { /// For the user-facing documentation see: /// http://clang.llvm.org/extra/clang-tidy/checks/modernize/make-shared.html class MakeSharedCheck : public MakeSmartPtrCheck { +private: + const StringRef MakeSmartPtrType; + public: MakeSharedCheck(StringRef Name, ClangTidyContext *Context); diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp index d1d7e9dcfa9c0d..3f77e6727d19f8 100644 --- a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp @@ -46,6 +46,7 @@ MakeSmartPtrCheck::MakeSmartPtrCheck(StringRef Name, ClangTidyContext *Context, areDiagsSelfContained()), MakeSmartPtrFunctionHeader( Options.get("MakeSmartPtrFunctionHeader", "")), + MakeSmartPtrType(Options.get("MakeSmartPtrType", "::std::shared_ptr")), MakeSmartPtrFunctionName( Options.get("MakeSmartPtrFunction", MakeSmartPtrFunctionName)), IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)), @@ -55,6 +56,7 @@ MakeSmartPtrCheck::MakeSmartPtrCheck(StringRef Name, ClangTidyContext *Context, void MakeSmartPtrCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "IncludeStyle", Inserter.getStyle()); Options.store(Opts, "MakeSmartPtrFunctionHeader", MakeSmartPtrFunctionHeader); + Options.store(Opts, "MakeSmartPtrType", MakeSmartPtrType); Options.store(Opts, "MakeSmartPtrFunction", MakeSmartPtrFunctionName); Options.store(Opts, "IgnoreMacros", IgnoreMacros); Options.store(Opts, "IgnoreDefaultInitialization", @@ -115,7 +117,6 @@ void MakeSmartPtrCheck::check(const MatchFinder::MatchResult &Result) { // 'smart_ptr' refers to 'std::shared_ptr' or 'std::unique_ptr' or other // pointer, 'make_smart_ptr' refers to 'std::make_shared' or // 'std::make_unique' or other function that creates smart_ptr. - SourceManager &SM = *Result.SourceManager; const auto *Construct = Result.Nodes.getNodeAs(ConstructorCall); @@ -361,8 +362,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag, Diag << FixItHint::CreateRemoval( SourceRange(NewStart, InitRange.getBegin())); Diag << FixItHint::CreateRemoval(SourceRange(InitRange.getEnd(), NewEnd)); -} -else { +} else { // New array expression with default/value initialization: // smart_ptr(new int[5]
[clang-tools-extra] [clang-tidy] modernize-make-shared: Add MakeSmartPtrType option (PR #117529)
https://github.com/hjanuschka updated https://github.com/llvm/llvm-project/pull/117529 >From 9466fb73adfb050e9eac426459c18a7a5bca1982 Mon Sep 17 00:00:00 2001 From: Helmut Januschka Date: Mon, 25 Nov 2024 09:59:21 +0100 Subject: [PATCH 1/5] WIP: [clang-tidy] Add SmartPtrName to MakeSmartPtrCheck for flexible type matching Introduced a `SmartPtrName` field in `MakeSmartPtrCheck` to allow matching on other smart pointer types, such as `base::scoped_refptr`, in addition to `std::shared_ptr`. This enables more versatile usage of the check without duplicating matcher logic. --- clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.cpp | 5 +++-- clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h| 3 +++ .../clang-tidy/modernize/MakeSmartPtrCheck.cpp | 6 +++--- clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.h | 1 + .../docs/clang-tidy/checks/modernize/make-shared.rst| 6 ++ 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.cpp b/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.cpp index 69f7d9f69eeed0..34009046fec6ae 100644 --- a/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.cpp @@ -16,13 +16,14 @@ using namespace clang::ast_matchers; namespace clang::tidy::modernize { MakeSharedCheck::MakeSharedCheck(StringRef Name, ClangTidyContext *Context) -: MakeSmartPtrCheck(Name, Context, "std::make_shared") {} +: MakeSmartPtrCheck(Name, Context, "std::make_shared"), + MakeSmartPtrType(Options.get("MakeSmartPtrType", "::std::shared_ptr")) {} MakeSharedCheck::SmartPtrTypeMatcher MakeSharedCheck::getSmartPointerTypeMatcher() const { return qualType(hasUnqualifiedDesugaredType( recordType(hasDeclaration(classTemplateSpecializationDecl( - hasName("::std::shared_ptr"), templateArgumentCountIs(1), + hasName(MakeSmartPtrType), templateArgumentCountIs(1), hasTemplateArgument(0, templateArgument(refersToType( qualType().bind(PointerType); } diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h b/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h index caaf4ae403c34f..932796e3a147f1 100644 --- a/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h +++ b/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h @@ -26,6 +26,9 @@ namespace clang::tidy::modernize { /// For the user-facing documentation see: /// http://clang.llvm.org/extra/clang-tidy/checks/modernize/make-shared.html class MakeSharedCheck : public MakeSmartPtrCheck { +private: + const StringRef MakeSmartPtrType; + public: MakeSharedCheck(StringRef Name, ClangTidyContext *Context); diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp index d1d7e9dcfa9c0d..3f77e6727d19f8 100644 --- a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp @@ -46,6 +46,7 @@ MakeSmartPtrCheck::MakeSmartPtrCheck(StringRef Name, ClangTidyContext *Context, areDiagsSelfContained()), MakeSmartPtrFunctionHeader( Options.get("MakeSmartPtrFunctionHeader", "")), + MakeSmartPtrType(Options.get("MakeSmartPtrType", "::std::shared_ptr")), MakeSmartPtrFunctionName( Options.get("MakeSmartPtrFunction", MakeSmartPtrFunctionName)), IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)), @@ -55,6 +56,7 @@ MakeSmartPtrCheck::MakeSmartPtrCheck(StringRef Name, ClangTidyContext *Context, void MakeSmartPtrCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "IncludeStyle", Inserter.getStyle()); Options.store(Opts, "MakeSmartPtrFunctionHeader", MakeSmartPtrFunctionHeader); + Options.store(Opts, "MakeSmartPtrType", MakeSmartPtrType); Options.store(Opts, "MakeSmartPtrFunction", MakeSmartPtrFunctionName); Options.store(Opts, "IgnoreMacros", IgnoreMacros); Options.store(Opts, "IgnoreDefaultInitialization", @@ -115,7 +117,6 @@ void MakeSmartPtrCheck::check(const MatchFinder::MatchResult &Result) { // 'smart_ptr' refers to 'std::shared_ptr' or 'std::unique_ptr' or other // pointer, 'make_smart_ptr' refers to 'std::make_shared' or // 'std::make_unique' or other function that creates smart_ptr. - SourceManager &SM = *Result.SourceManager; const auto *Construct = Result.Nodes.getNodeAs(ConstructorCall); @@ -361,8 +362,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag, Diag << FixItHint::CreateRemoval( SourceRange(NewStart, InitRange.getBegin())); Diag << FixItHint::CreateRemoval(SourceRange(InitRange.getEnd(), NewEnd)); -} -else { +} else { // New array expression with default/value initialization: // smart_ptr(new int[5]
[clang] [llvm] [ubsan] Change ubsan-unique-traps to use nomerge instead of counter (PR #117651)
@@ -3919,18 +3919,16 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked, Builder.CreateCondBr(Checked, Cont, TrapBB); EmitBlock(TrapBB); -llvm::CallInst *TrapCall = Builder.CreateCall( -CGM.getIntrinsic(llvm::Intrinsic::ubsantrap), -llvm::ConstantInt::get(CGM.Int8Ty, - ClSanitizeDebugDeoptimization - ? TrapBB->getParent()->size() - : static_cast(CheckHandlerID))); +llvm::CallInst *TrapCall = +Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::ubsantrap), + llvm::ConstantInt::get(CGM.Int8Ty, CheckHandlerID)); if (!CGM.getCodeGenOpts().TrapFuncName.empty()) { auto A = llvm::Attribute::get(getLLVMContext(), "trap-func-name", CGM.getCodeGenOpts().TrapFuncName); TrapCall->addFnAttr(A); } +TrapCall->addFnAttr(llvm::Attribute::NoMerge); thurstond wrote: https://github.com/llvm/llvm-project/commit/5107ce194c9b03c2f32eb1508df0c92b13b3e2fd doesn't work because of inlining: none of the ubsantraps in function m() have nomerge, because they were each unique ubsantraps in the non-inlined functions. Is there a downside to emitting nomerge for every ubsantrap (even the first instance)? https://github.com/llvm/llvm-project/pull/117651 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] modernize-make-shared: Add MakeSmartPtrType option (PR #117529)
https://github.com/hjanuschka edited https://github.com/llvm/llvm-project/pull/117529 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] modernize-make-shared: Add MakeSmartPtrType option (PR #117529)
https://github.com/hjanuschka commented: @PiotrZSL - [x] Add MakeSmartPtrType in MakeSmartPtrCheck as protected (do not initialize in constructor) - [x] Add MakeSmartPtrType to storeOptions - [x] Read MakeSmartPtrType in MakeSharedPtrCheck & MakeUniquePtrCheck constructors (set different default values) - [x] Use MakeSmartPtrType in getSmartPointerTypeMatcher in both classes - [x] Modify documentation for both checks - [x] Add entry for both checks in release notes - [x] Consider doing same for 'std::make_shared' > Consider supporting multiple smart ptr types and multiple make functions a bit unsure about this one, do you have any sample where there is usage of multiple?! really not sure about this! the rest is addressed, and ready for another review https://github.com/llvm/llvm-project/pull/117529 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ubsan] Change ubsan-unique-traps to use nomerge instead of counter (PR #117651)
https://github.com/thurstond edited https://github.com/llvm/llvm-project/pull/117651 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Add stack clash protection (PR #117612)
https://github.com/rzinsly updated https://github.com/llvm/llvm-project/pull/117612 >From f6bb44ca2242623399eb0ea946f38399fed3807c Mon Sep 17 00:00:00 2001 From: Raphael Moreira Zinsly Date: Tue, 26 Nov 2024 16:40:37 -0300 Subject: [PATCH 1/3] [NFC][RISCV] Remove CFIIndex argument from RISCVFrameLowering::allocateStack Calculates CFIIndex inside RISCVFrameLowering::allocateStack instead of sending it by argument. --- llvm/lib/Target/RISCV/RISCVFrameLowering.cpp | 23 +--- llvm/lib/Target/RISCV/RISCVFrameLowering.h | 3 ++- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp index 1ff435b76ad68a..e2c9baa1b7b1f6 100644 --- a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp +++ b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp @@ -612,8 +612,9 @@ static MCCFIInstruction createDefCFAOffset(const TargetRegisterInfo &TRI, void RISCVFrameLowering::allocateStack(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, - StackOffset Offset, bool EmitCFI, - unsigned CFIIndex) const { + MachineFunction &MF, StackOffset Offset, + uint64_t RealStackSize, + bool EmitCFI) const { DebugLoc DL; const RISCVRegisterInfo *RI = STI.getRegisterInfo(); const RISCVInstrInfo *TII = STI.getInstrInfo(); @@ -622,7 +623,9 @@ void RISCVFrameLowering::allocateStack(MachineBasicBlock &MBB, getStackAlign()); if (EmitCFI) { -// Emit ".cfi_def_cfa_offset StackSize" +// Emit ".cfi_def_cfa_offset RealStackSize" +unsigned CFIIndex = MF.addFrameInst( + MCCFIInstruction::cfiDefCfaOffset(nullptr, RealStackSize)); BuildMI(MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION)) .addCFIIndex(CFIIndex) .setMIFlag(MachineInstr::FrameSetup); @@ -745,10 +748,8 @@ void RISCVFrameLowering::emitPrologue(MachineFunction &MF, if (StackSize != 0) { // Allocate space on the stack if necessary. -unsigned CFIIndex = MF.addFrameInst( -MCCFIInstruction::cfiDefCfaOffset(nullptr, RealStackSize)); -allocateStack(MBB, MBBI, StackOffset::getFixed(-StackSize), - /*EmitCFI=*/ true, CFIIndex); +allocateStack(MBB, MBBI, MF, StackOffset::getFixed(-StackSize), + RealStackSize, /*EmitCFI=*/ true); } // The frame pointer is callee-saved, and code has been generated for us to @@ -790,12 +791,8 @@ void RISCVFrameLowering::emitPrologue(MachineFunction &MF, assert(SecondSPAdjustAmount > 0 && "SecondSPAdjustAmount should be greater than zero"); -// If we are using a frame-pointer, and thus emitted ".cfi_def_cfa fp, 0", -// don't emit an sp-based .cfi_def_cfa_offset -unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::cfiDefCfaOffset( -nullptr, getStackSizeWithRVVPadding(MF))); -allocateStack(MBB, MBBI, StackOffset::getFixed(-SecondSPAdjustAmount), - !hasFP(MF), CFIIndex); +allocateStack(MBB, MBBI, MF, StackOffset::getFixed(-SecondSPAdjustAmount), + getStackSizeWithRVVPadding(MF), !hasFP(MF)); } if (RVVStackSize) { diff --git a/llvm/lib/Target/RISCV/RISCVFrameLowering.h b/llvm/lib/Target/RISCV/RISCVFrameLowering.h index 9aff4dc9e4089a..8c2e3f0f3e5638 100644 --- a/llvm/lib/Target/RISCV/RISCVFrameLowering.h +++ b/llvm/lib/Target/RISCV/RISCVFrameLowering.h @@ -79,7 +79,8 @@ class RISCVFrameLowering : public TargetFrameLowering { } void allocateStack(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, - StackOffset Offset, bool EmitCFI, unsigned CFIIndex) const; + MachineFunction &MF, StackOffset Offset, + uint64_t RealStackSize, bool EmitCFI) const; protected: const RISCVSubtarget &STI; >From 132e8598b2d044463d4d9fb6ef391e6095b75f87 Mon Sep 17 00:00:00 2001 From: Raphael Moreira Zinsly Date: Mon, 25 Nov 2024 14:51:35 -0300 Subject: [PATCH 2/3] [RISCV] Add initial stack clash protection Enable `-fstack-clash-protection` for RISCV and stack probe for function prologues. We probe the stack by creating an unrolled loop that allocates and probe the stack in ProbeSize chunks, this is not ideal if the loop has many iterations. --- clang/lib/Driver/ToolChains/Clang.cpp | 3 +- llvm/lib/Target/RISCV/RISCVFrameLowering.cpp | 90 +++ llvm/lib/Target/RISCV/RISCVFrameLowering.h| 5 +- llvm/lib/Target/RISCV/RISCVISelLowering.cpp | 22 + llvm/lib/Target/RISCV/RISCVISelLowering.h | 6 ++ .../Target/RISCV/RISCVMachineFunctionInfo.cpp | 30 +++ .../Target/RISCV/RISCVMachineFunctionInfo.h | 7 +- llvm/lib/Target/RISCV/RISCVTargetMachine.cpp | 4 +- .../RISCV/stack-clash-prologue-
[clang] [llvm] AMDGPU: Builtins & Codegen support for v_cvt_scalef32_pk_f32_{fp8|bf8} for gfx950 (PR #117741)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/117741 >From ba67e2e766f1432825a505a8e34188c893bd5b75 Mon Sep 17 00:00:00 2001 From: Pravin Jagtap Date: Thu, 18 Apr 2024 01:18:49 -0400 Subject: [PATCH] AMDGPU: Builtins & Codegen support for v_cvt_scalef32_pk_f32_{fp8|bf8} for gfx950 OPSEL[0] determines low/high 16 bits of src0 to read. Co-authored-by: Pravin Jagtap --- clang/include/clang/Basic/BuiltinsAMDGPU.def | 3 + .../builtins-amdgcn-gfx950-err.cl | 6 +- .../CodeGenOpenCL/builtins-amdgcn-gfx950.cl | 56 ++- .../builtins-amdgcn-error-gfx950-param.cl | 5 +- llvm/include/llvm/IR/IntrinsicsAMDGPU.td | 12 .../AMDGPU/AMDGPUInstructionSelector.cpp | 7 +++ .../Target/AMDGPU/AMDGPUInstructionSelector.h | 3 + .../Target/AMDGPU/AMDGPURegisterBankInfo.cpp | 2 + llvm/lib/Target/AMDGPU/VOP3Instructions.td| 15 + .../llvm.amdgcn.cvt.scalef32.pk.gfx950.ll | 42 ++ 10 files changed, 147 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def b/clang/include/clang/Basic/BuiltinsAMDGPU.def index a292640b7c4f21..f92e5c17188ec9 100644 --- a/clang/include/clang/Basic/BuiltinsAMDGPU.def +++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def @@ -576,5 +576,8 @@ TARGET_BUILTIN(__builtin_amdgcn_cvt_scalef32_f32_fp8, "fifIi", "nc", "fp8-cvt-sc TARGET_BUILTIN(__builtin_amdgcn_cvt_scalef32_f32_bf8, "fifIi", "nc", "bf8-cvt-scale-insts") TARGET_BUILTIN(__builtin_amdgcn_cvt_scalef32_pk_fp8_f32, "V2sV2sfffIb", "nc", "fp8-cvt-scale-insts") TARGET_BUILTIN(__builtin_amdgcn_cvt_scalef32_pk_bf8_f32, "V2sV2sfffIb", "nc", "bf8-cvt-scale-insts") +TARGET_BUILTIN(__builtin_amdgcn_cvt_scalef32_pk_f32_fp8, "V2fUifIb", "nc", "fp8-cvt-scale-insts") +TARGET_BUILTIN(__builtin_amdgcn_cvt_scalef32_pk_f32_bf8, "V2fUifIb", "nc", "bf8-cvt-scale-insts") + #undef BUILTIN #undef TARGET_BUILTIN diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx950-err.cl b/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx950-err.cl index 5ec769dc6a84bc..54b8573a1b4de3 100644 --- a/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx950-err.cl +++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx950-err.cl @@ -14,8 +14,10 @@ typedef unsigned int uint; typedef unsigned int uint2 __attribute__((ext_vector_type(2))); typedef half __attribute__((ext_vector_type(2))) half2; typedef short __attribute__((ext_vector_type(2))) short2; +typedef float __attribute__((ext_vector_type(2))) float2; -void test(global uint* out, global uint2* out_v2u32, uint a, uint b, global half2* out_v2f16, global float* out_f32, float scale, global short2* out_v2i16, float src0, float src1) { +void test(global uint* out, global uint2* out_v2u32, uint a, uint b, global half2* out_v2f16, global float* out_f32, float scale, global short2* out_v2i16, float src0, float src1, + global float2* out_v2f32) { *out = __builtin_amdgcn_prng_b32(a); // expected-error{{'__builtin_amdgcn_prng_b32' needs target feature prng-inst}} *out_v2u32 = __builtin_amdgcn_permlane16_swap(a, b, false, false); // expected-error{{'__builtin_amdgcn_permlane16_swap' needs target feature permlane16-swap}} *out_v2u32 = __builtin_amdgcn_permlane32_swap(a, b, false, false); // expected-error{{'__builtin_amdgcn_permlane32_swap' needs target feature permlane32-swap}} @@ -25,4 +27,6 @@ void test(global uint* out, global uint2* out_v2u32, uint a, uint b, global half *out_f32 = __builtin_amdgcn_cvt_scalef32_f32_bf8(a, scale, 0); // expected-error{{'__builtin_amdgcn_cvt_scalef32_f32_bf8' needs target feature bf8-cvt-scale-insts}} *out_v2i16 = __builtin_amdgcn_cvt_scalef32_pk_fp8_f32(*out_v2i16, src0, src1, scale, true); // expected-error{{'__builtin_amdgcn_cvt_scalef32_pk_fp8_f32' needs target feature fp8-cvt-scale-insts}} *out_v2i16 = __builtin_amdgcn_cvt_scalef32_pk_bf8_f32(*out_v2i16, src0, src1, scale, true); // expected-error{{'__builtin_amdgcn_cvt_scalef32_pk_bf8_f32' needs target feature bf8-cvt-scale-insts}} + *out_v2f32 = __builtin_amdgcn_cvt_scalef32_pk_f32_fp8(a, scale, true); // expected-error{{'__builtin_amdgcn_cvt_scalef32_pk_f32_fp8' needs target feature fp8-cvt-scale-insts}} + *out_v2f32 = __builtin_amdgcn_cvt_scalef32_pk_f32_bf8(a, scale, true); // expected-error{{'__builtin_amdgcn_cvt_scalef32_pk_f32_bf8' needs target feature bf8-cvt-scale-insts}} } diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx950.cl b/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx950.cl index 9f23474226791c..1313c5ec8d5443 100644 --- a/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx950.cl +++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx950.cl @@ -13,6 +13,7 @@ typedef short __attribute__((ext_vector_type(2))) short2; typedef __bf16 __attribute__((ext_vector_type(2))) bfloat2; typedef float __attribute__((ext_vector_type(16))) float16; typedef half __attribute__((ext_vector_type(2))) half2; +typedef float __attribute__((ext_vector_type(2)))
[clang] [llvm] [ubsan] Change ubsan-unique-traps to use nomerge instead of counter (PR #117651)
https://github.com/thurstond updated https://github.com/llvm/llvm-project/pull/117651 >From f24a87de48c42f310ee73ecf480ea2dcf631881f Mon Sep 17 00:00:00 2001 From: Thurston Dang Date: Tue, 26 Nov 2024 00:33:09 + Subject: [PATCH 01/12] [ubsan] Change ubsan-unique-traps to use nomerge instead of counter https://github.com/llvm/llvm-project/pull/65972 (continuation of https://reviews.llvm.org/D148654) had considered adding nomerge to ubsantrap, but did not proceed with that because of https://github.com/llvm/llvm-project/issues/53011. Instead, it added a counter (based on TrapBB->getParent()->size()) to each ubsantrap call. However, this counter is not guaranteed to be unique after inlining, as shown by https://github.com/llvm/llvm-project/pull/83470, which can result in ubsantraps being merged by the backend. https://github.com/llvm/llvm-project/pull/101549 fixed has since fixed the nomerge limitation ("It sets nomerge flag for the node if the instruction has nomerge arrtibute."). This patch therefore takes advantage of nomerge instead of using the counter, guaranteeing that the ubsantraps are not merged. This patch is equivalent to https://github.com/llvm/llvm-project/pull/83470 but also adds nomerge and updates the test that was precommitted in https://github.com/llvm/llvm-project/pull/117649. --- clang/lib/CodeGen/CGExpr.cpp | 6 +- clang/test/CodeGen/bounds-checking.c | 4 +- clang/test/CodeGen/ubsan-trap-merge.c | 106 ++ 3 files changed, 110 insertions(+), 6 deletions(-) create mode 100644 clang/test/CodeGen/ubsan-trap-merge.c diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index d3f470d401b3d4..f8c1e1cd7a4d68 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -3921,16 +3921,14 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked, llvm::CallInst *TrapCall = Builder.CreateCall( CGM.getIntrinsic(llvm::Intrinsic::ubsantrap), -llvm::ConstantInt::get(CGM.Int8Ty, - ClSanitizeDebugDeoptimization - ? TrapBB->getParent()->size() - : static_cast(CheckHandlerID))); +llvm::ConstantInt::get(CGM.Int8Ty, CheckHandlerID)); if (!CGM.getCodeGenOpts().TrapFuncName.empty()) { auto A = llvm::Attribute::get(getLLVMContext(), "trap-func-name", CGM.getCodeGenOpts().TrapFuncName); TrapCall->addFnAttr(A); } +TrapCall->addFnAttr(llvm::Attribute::NoMerge); TrapCall->setDoesNotReturn(); TrapCall->setDoesNotThrow(); Builder.CreateUnreachable(); diff --git a/clang/test/CodeGen/bounds-checking.c b/clang/test/CodeGen/bounds-checking.c index 8100e30d0650ad..f6c4880e70a150 100644 --- a/clang/test/CodeGen/bounds-checking.c +++ b/clang/test/CodeGen/bounds-checking.c @@ -74,11 +74,11 @@ char B2[10]; // CHECK-LABEL: @f8 void f8(int i, int k) { // NOOPTLOCAL: call void @llvm.ubsantrap(i8 3) - // NOOPTARRAY: call void @llvm.ubsantrap(i8 2) + // NOOPTARRAY: call void @llvm.ubsantrap(i8 18) B[i] = '\0'; // NOOPTLOCAL: call void @llvm.ubsantrap(i8 5) - // NOOPTARRAY: call void @llvm.ubsantrap(i8 4) + // NOOPTARRAY: call void @llvm.ubsantrap(i8 18) B2[k] = '\0'; } diff --git a/clang/test/CodeGen/ubsan-trap-merge.c b/clang/test/CodeGen/ubsan-trap-merge.c new file mode 100644 index 00..e6aa7902262813 --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-merge.c @@ -0,0 +1,106 @@ +// NOTE: Assertions have mostly been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5 +// The most important assertion is the attributes at the end of the file, which +// shows that ubsan attaches 'nomerge' to each ubsantrap intrinsic. +// +// RUN: %clang -fsanitize=signed-integer-overflow -S -emit-llvm -fsanitize-trap=all -O3 -mllvm -ubsan-unique-traps %s -o - \ +// RUN: | FileCheck %s + +#include +#include + +// CHECK-LABEL: define dso_local range(i32 -2147483523, -2147483648) i32 @f( +// CHECK-SAME: i32 noundef [[X:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT:[[TMP0:%.*]] = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[X]], i32 125), !nosanitize [[META5:![0-9]+]] +// CHECK-NEXT:[[TMP1:%.*]] = extractvalue { i32, i1 } [[TMP0]], 1, !nosanitize [[META5]] +// CHECK-NEXT:br i1 [[TMP1]], label %[[TRAP:.*]], label %[[CONT:.*]], !nosanitize [[META5]] +// CHECK: [[TRAP]]: +// CHECK-NEXT:tail call void @llvm.ubsantrap(i8 0) #[[ATTR4:[0-9]+]], !nosanitize [[META5]] +// CHECK-NEXT:unreachable, !nosanitize [[META5]] +// CHECK: [[CONT]]: +// CHECK-NEXT:[[TMP2:%.*]] = extractvalue { i32, i1 } [[TMP0]], 0, !nosanitize [[META5]] +// CHECK-NEXT:ret i32 [[TMP2]] +// +int f(int x) { + return x + 125; +} + +// CHECK-LABEL: define dso_local range(i32 -2147483521, -2147483648) i32 @g( +// CHECK-SA
[clang] [llvm] [ubsan] Change ubsan-unique-traps to use nomerge instead of counter (PR #117651)
https://github.com/thurstond ready_for_review https://github.com/llvm/llvm-project/pull/117651 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ubsan] Change ubsan-unique-traps to use nomerge instead of counter (PR #117651)
https://github.com/thurstond edited https://github.com/llvm/llvm-project/pull/117651 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Modernize, improve and promote chroot checker (PR #117791)
https://github.com/vabridgers updated https://github.com/llvm/llvm-project/pull/117791 >From 1b073f9a06f4a0844d703923c3edd97085b47918 Mon Sep 17 00:00:00 2001 From: einvbri Date: Mon, 25 Nov 2024 10:31:57 +0100 Subject: [PATCH] [analyzer] Modernize, improve and promote chroot checker This change modernizes, improves and promotes the chroot checker from alpha to the Unix family of checkers. This checker covers the POS05 recommendations for use of chroot. The improvements included modeling of a success or failure from chroot and not falsely reporting a warning along an error path. This was made possible through modernizing the checker to be flow sensitive. --- clang/docs/ReleaseNotes.rst | 3 + clang/docs/analyzer/checkers.rst | 30 ++-- .../clang/StaticAnalyzer/Checkers/Checkers.td | 8 +- .../StaticAnalyzer/Checkers/ChrootChecker.cpp | 149 ++ clang/test/Analysis/chroot.c | 36 - 5 files changed, 172 insertions(+), 54 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 6c40e48e2f49b3..292a41e127bfd0 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -985,6 +985,9 @@ Moved checkers original checkers were implemented only using AST matching and make more sense as a single clang-tidy check. +- The checker ``alpha.unix.Chroot`` was modernized, improved and moved from + alpha to a main Unix family checker. + .. _release-notes-sanitizers: Sanitizers diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst index f34b25cd04bd18..5149faa50f72cf 100644 --- a/clang/docs/analyzer/checkers.rst +++ b/clang/docs/analyzer/checkers.rst @@ -1750,6 +1750,21 @@ Critical section handling functions modeled by this checker: } } +.. _unix-Chroot: + +unix.Chroot (C) +" +Check improper use of chroot. + +.. code-block:: c + + void f(); + + void test() { + chroot("/usr/local"); + f(); // warn: no call of chdir("/") immediately after chroot + } + .. _unix-Errno: unix.Errno (C) @@ -3275,21 +3290,6 @@ SEI CERT checkers which tries to find errors based on their `C coding rules , HelpText<"Check for proper usage of vfork">, Documentation; -} // end "unix" - -let ParentPackage = UnixAlpha in { - def ChrootChecker : Checker<"Chroot">, HelpText<"Check improper use of chroot">, Documentation; +} // end "unix" + +let ParentPackage = UnixAlpha in { + def PthreadLockChecker : Checker<"PthreadLock">, HelpText<"Simple lock -> unlock checker">, Dependencies<[PthreadLockBase]>, diff --git a/clang/lib/StaticAnalyzer/Checkers/ChrootChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/ChrootChecker.cpp index 3a0a01c23de03e..d957ce9ed2ffc7 100644 --- a/clang/lib/StaticAnalyzer/Checkers/ChrootChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/ChrootChecker.cpp @@ -10,6 +10,8 @@ // //===--===// +#include "clang/AST/ASTContext.h" +#include "clang/Basic/TargetInfo.h" #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h" #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h" #include "clang/StaticAnalyzer/Core/Checker.h" @@ -24,21 +26,30 @@ using namespace clang; using namespace ento; -namespace { - // enum value that represent the jail state -enum Kind { NO_CHROOT, ROOT_CHANGED, JAIL_ENTERED }; +enum ChrootKind { NO_CHROOT, ROOT_CHANGED, ROOT_CHANGE_FAILED, JAIL_ENTERED }; -bool isRootChanged(intptr_t k) { return k == ROOT_CHANGED; } -//bool isJailEntered(intptr_t k) { return k == JAIL_ENTERED; } +// Track chroot state changes for success, failure, state change +// and "jail" +REGISTER_TRAIT_WITH_PROGRAMSTATE(ChrootState, ChrootKind) + +// Track the call expression to chroot for accurate +// warning messages +REGISTER_TRAIT_WITH_PROGRAMSTATE(ChrootCall, const Expr *) + +namespace { // This checker checks improper use of chroot. -// The state transition: +// The state transitions +// +// -> ROOT_CHANGE_FAILED +// | // NO_CHROOT ---chroot(path)--> ROOT_CHANGED ---chdir(/) --> JAIL_ENTERED // | | // ROOT_CHANGED<--chdir(..)-- JAIL_ENTERED<--chdir(..)-- // | | // bug<--foo()-- JAIL_ENTERED<--foo()-- +// class ChrootChecker : public Checker { // This bug refers to possibly break out of a chroot() jail. const BugType BT_BreakJail{this, "Break out of jail"}; @@ -49,20 +60,17 @@ class ChrootChecker : public Checker { public: ChrootChecker() {} - static void *getTag() { -static int x; -return &x; - } - bool evalCall(const CallEvent &Call, CheckerContext &C) const; void checkPreCall(const CallEvent &Call, CheckerContext &C) const; private: void evalChroot(const CallEvent
[clang] [llvm] [RISCV] Add stack clash protection (PR #117612)
@@ -0,0 +1,208 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py +; RUN: llc -mtriple=riscv64 -mattr=+m,+v -O2 < %s \ +; RUN: | FileCheck %s -check-prefix=RV64I rzinsly wrote: It was an oversight on my part, fixed now. https://github.com/llvm/llvm-project/pull/117612 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Enable AST mutation in the constant evaluator (PR #115168)
zygoloid wrote: > Hey Richard - We added idempotency to `define_aggregate` in response to > concern from Clang maintainers that it could interact poorly with > `clang-repl`. The argument was that idempotency would provide a better > experience for a user that wanted to re-evaluate an expression that was > previously submitted for evaluation. I see. I've given it some thought, and I don't agree that this argument should govern the behavior of `define_aggregate`. I would expect ```c++ struct S; struct S { ... }; ``` to behave exactly the same in a C++ interpreter / REPL as ```c++ struct S; consteval { define_aggregate(^^S, {}); } ``` I think not following that principle would create unnecessary work for the implementation and confusion for users, as well as harming the general idea that code generated by metaprogramming works the same way as code generated by source declarations. If, for a syntactic struct definition, an implementation can "undo" defining the struct and rewind back to before the definition, then I'd expect the same behavior for a metaprogramming struct definition (and your proposal shouldn't try to get in the way of that or dictate the behavior in that case, because it's outside the scope of the C++ standard). Conversely, if the implementation can't undo it in one case, I'd expect it to undo it in neither case. More broadly, if this is a real problem for an interpreter, then it's not unique to `define_aggregate` and applies to all syntactic and metaprogramming-introduced declarations and definitions, and such an interpreter should endeavor to use the same solution in all the places where the problem appears -- but, again, that situation and its chosen solution are outside the scope of the C++ standard and we don't need rules in the standard to enable the implementation to solve this problem. Instead of supporting some kind of an "undo" mechanism, it might make sense for an interpreter to treat definitions as idempotent in general (perhaps with a special rule that we use the most recent body for a *function* definition). For such an implementation that makes that choice, it would seem appropriate for `define_aggregate` to also be idempotent. But that should be a specific rule for that implementation, not a rule that appears in the standard. And we certainly shouldn't change the standard to require this unusual implementation-specific rule to be implemented by all C++ implementations, because it might better fit a non-conforming model that `clang-repl` *might* adopt (and as far as I'm aware, we haven't chosen to make definitions idempotent in `clang-repl`). https://github.com/llvm/llvm-project/pull/115168 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ubsan] Change ubsan-unique-traps to use nomerge instead of counter (PR #117651)
https://github.com/thurstond updated https://github.com/llvm/llvm-project/pull/117651 >From cffa7c3081a1d7b9cb64ac129109cb358d11a751 Mon Sep 17 00:00:00 2001 From: Thurston Dang Date: Tue, 26 Nov 2024 00:33:09 + Subject: [PATCH 01/14] [ubsan] Change ubsan-unique-traps to use nomerge instead of counter https://github.com/llvm/llvm-project/pull/65972 (continuation of https://reviews.llvm.org/D148654) had considered adding nomerge to ubsantrap, but did not proceed with that because of https://github.com/llvm/llvm-project/issues/53011. Instead, it added a counter (based on TrapBB->getParent()->size()) to each ubsantrap call. However, this counter is not guaranteed to be unique after inlining, as shown by https://github.com/llvm/llvm-project/pull/83470, which can result in ubsantraps being merged by the backend. https://github.com/llvm/llvm-project/pull/101549 fixed has since fixed the nomerge limitation ("It sets nomerge flag for the node if the instruction has nomerge arrtibute."). This patch therefore takes advantage of nomerge instead of using the counter, guaranteeing that the ubsantraps are not merged. This patch is equivalent to https://github.com/llvm/llvm-project/pull/83470 but also adds nomerge and updates the test that was precommitted in https://github.com/llvm/llvm-project/pull/117649. --- clang/lib/CodeGen/CGExpr.cpp| 6 ++-- clang/test/CodeGen/bounds-checking.c| 4 +-- clang/test/CodeGen/ubsan-trap-merge.c | 24 +++ llvm/test/CodeGen/X86/ubsan-trap-merge.ll | 31 ++- llvm/test/CodeGen/X86/ubsan-trap-nomerge.ll | 33 ++--- 5 files changed, 47 insertions(+), 51 deletions(-) diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index d3f470d401b3d4..f8c1e1cd7a4d68 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -3921,16 +3921,14 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked, llvm::CallInst *TrapCall = Builder.CreateCall( CGM.getIntrinsic(llvm::Intrinsic::ubsantrap), -llvm::ConstantInt::get(CGM.Int8Ty, - ClSanitizeDebugDeoptimization - ? TrapBB->getParent()->size() - : static_cast(CheckHandlerID))); +llvm::ConstantInt::get(CGM.Int8Ty, CheckHandlerID)); if (!CGM.getCodeGenOpts().TrapFuncName.empty()) { auto A = llvm::Attribute::get(getLLVMContext(), "trap-func-name", CGM.getCodeGenOpts().TrapFuncName); TrapCall->addFnAttr(A); } +TrapCall->addFnAttr(llvm::Attribute::NoMerge); TrapCall->setDoesNotReturn(); TrapCall->setDoesNotThrow(); Builder.CreateUnreachable(); diff --git a/clang/test/CodeGen/bounds-checking.c b/clang/test/CodeGen/bounds-checking.c index 8100e30d0650ad..f6c4880e70a150 100644 --- a/clang/test/CodeGen/bounds-checking.c +++ b/clang/test/CodeGen/bounds-checking.c @@ -74,11 +74,11 @@ char B2[10]; // CHECK-LABEL: @f8 void f8(int i, int k) { // NOOPTLOCAL: call void @llvm.ubsantrap(i8 3) - // NOOPTARRAY: call void @llvm.ubsantrap(i8 2) + // NOOPTARRAY: call void @llvm.ubsantrap(i8 18) B[i] = '\0'; // NOOPTLOCAL: call void @llvm.ubsantrap(i8 5) - // NOOPTARRAY: call void @llvm.ubsantrap(i8 4) + // NOOPTARRAY: call void @llvm.ubsantrap(i8 18) B2[k] = '\0'; } diff --git a/clang/test/CodeGen/ubsan-trap-merge.c b/clang/test/CodeGen/ubsan-trap-merge.c index b4de97b5e08f33..ef32605c73174a 100644 --- a/clang/test/CodeGen/ubsan-trap-merge.c +++ b/clang/test/CodeGen/ubsan-trap-merge.c @@ -1,20 +1,20 @@ // NOTE: Assertions have mostly been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5 // The most important assertion is the attributes at the end of the file, which -// shows that ubsan does not currently attach 'nomerge'. +// shows that ubsan attaches 'nomerge' to each ubsantrap intrinsic. // // RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -fsanitize=signed-integer-overflow -fsanitize-trap=signed-integer-overflow -O3 -mllvm -ubsan-unique-traps %s -o - \ // RUN: | FileCheck %s // // REQUIRES: x86-registered-target -// CHECK-LABEL: define dso_local noundef i32 @f( +// CHECK-LABEL: define dso_local range(i32 -2147483523, -2147483648) i32 @f( // CHECK-SAME: i32 noundef [[X:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] { // CHECK-NEXT: [[ENTRY:.*:]] // CHECK-NEXT:[[TMP0:%.*]] = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[X]], i32 125), !nosanitize [[META2:![0-9]+]] // CHECK-NEXT:[[TMP1:%.*]] = extractvalue { i32, i1 } [[TMP0]], 1, !nosanitize [[META2]] // CHECK-NEXT:br i1 [[TMP1]], label %[[TRAP:.*]], label %[[CONT:.*]], !nosanitize [[META2]] // CHECK: [[TRAP]]: -// CHECK-NEXT:tail call void @llvm.ubsantrap(i8 2) #[[ATTR4:[0-9]+]], !nosanitize [[META2]] +// CHECK-NEXT:tail call void @llvm.ubsantrap(i8 0) #[[ATTR4:[0-
[clang] 47dbf35 - Reapply "[NFC][clang] Add ubsan-trap-merge.c test to show absence of nomerge" (#117804) (#117805)
Author: Thurston Dang Date: 2024-11-26T14:58:44-08:00 New Revision: 47dbf359041299c5f19f82e7204c6c9675b6e69a URL: https://github.com/llvm/llvm-project/commit/47dbf359041299c5f19f82e7204c6c9675b6e69a DIFF: https://github.com/llvm/llvm-project/commit/47dbf359041299c5f19f82e7204c6c9675b6e69a.diff LOG: Reapply "[NFC][clang] Add ubsan-trap-merge.c test to show absence of nomerge" (#117804) (#117805) This reverts commit c8bdb31ff66e8934060c60816c57925fdec42a2c. It was reverted because I forgot to update the auto-generated assertions after adding the target triple. Original commit message: This test (copied from https://github.com/llvm/llvm-project/pull/83470) demonstrates that UBSan does not add the nomerge annotation. This is significant because it can result in them being merged by the backend, even when -ubsan-unique-traps is enabled. N.B. https://github.com/llvm/llvm-project/pull/65972 (continuation of https://reviews.llvm.org/D148654) had considered adding nomerge to ubsantrap, but did not proceed with that because of https://github.com/llvm/llvm-project/issues/53011. https://github.com/llvm/llvm-project/pull/101549 fixed that limitation ("It sets nomerge flag for the node if the instruction has nomerge arrtibute."); planned upcoming work (https://github.com/llvm/llvm-project/pull/117651) will add nomerge for ubsan. Added: clang/test/CodeGen/ubsan-trap-merge.c Modified: Removed: diff --git a/clang/test/CodeGen/ubsan-trap-merge.c b/clang/test/CodeGen/ubsan-trap-merge.c new file mode 100644 index 00..0f50d8c1ff47f2 --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-merge.c @@ -0,0 +1,105 @@ +// NOTE: Assertions have mostly been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5 +// The most important assertion is the attributes at the end of the file, which +// shows that ubsan does not currently attach 'nomerge'. +// +// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -fsanitize=signed-integer-overflow -fsanitize-trap=signed-integer-overflow -O3 -mllvm -ubsan-unique-traps %s -o - \ +// RUN: | FileCheck %s +// +// REQUIRES: x86-registered-target + +// CHECK-LABEL: define dso_local range(i32 -2147483523, -2147483648) i32 @f( +// CHECK-SAME: i32 noundef [[X:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT:[[TMP0:%.*]] = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[X]], i32 125), !nosanitize [[META2:![0-9]+]] +// CHECK-NEXT:[[TMP1:%.*]] = extractvalue { i32, i1 } [[TMP0]], 1, !nosanitize [[META2]] +// CHECK-NEXT:br i1 [[TMP1]], label %[[TRAP:.*]], label %[[CONT:.*]], !nosanitize [[META2]] +// CHECK: [[TRAP]]: +// CHECK-NEXT:tail call void @llvm.ubsantrap(i8 2) #[[ATTR4:[0-9]+]], !nosanitize [[META2]] +// CHECK-NEXT:unreachable, !nosanitize [[META2]] +// CHECK: [[CONT]]: +// CHECK-NEXT:[[TMP2:%.*]] = extractvalue { i32, i1 } [[TMP0]], 0, !nosanitize [[META2]] +// CHECK-NEXT:ret i32 [[TMP2]] +// +int f(int x) { + return x + 125; +} + +// CHECK-LABEL: define dso_local range(i32 -2147483521, -2147483648) i32 @g( +// CHECK-SAME: i32 noundef [[X:%.*]]) local_unnamed_addr #[[ATTR0]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT:[[TMP0:%.*]] = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[X]], i32 127), !nosanitize [[META2]] +// CHECK-NEXT:[[TMP1:%.*]] = extractvalue { i32, i1 } [[TMP0]], 1, !nosanitize [[META2]] +// CHECK-NEXT:br i1 [[TMP1]], label %[[TRAP:.*]], label %[[CONT:.*]], !nosanitize [[META2]] +// CHECK: [[TRAP]]: +// CHECK-NEXT:tail call void @llvm.ubsantrap(i8 2) #[[ATTR4]], !nosanitize [[META2]] +// CHECK-NEXT:unreachable, !nosanitize [[META2]] +// CHECK: [[CONT]]: +// CHECK-NEXT:[[TMP2:%.*]] = extractvalue { i32, i1 } [[TMP0]], 0, !nosanitize [[META2]] +// CHECK-NEXT:ret i32 [[TMP2]] +// +int g(int x) { + return x + 127; +} + +// CHECK-LABEL: define dso_local range(i32 -2147483521, -2147483648) i32 @h( +// CHECK-SAME: i32 noundef [[X:%.*]], i32 noundef [[Y:%.*]]) local_unnamed_addr #[[ATTR0]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT:[[TMP0:%.*]] = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[X]], i32 127), !nosanitize [[META2]] +// CHECK-NEXT:[[TMP1:%.*]] = extractvalue { i32, i1 } [[TMP0]], 1, !nosanitize [[META2]] +// CHECK-NEXT:br i1 [[TMP1]], label %[[TRAP:.*]], label %[[CONT:.*]], !nosanitize [[META2]] +// CHECK: [[TRAP]]: +// CHECK-NEXT:tail call void @llvm.ubsantrap(i8 2) #[[ATTR4]], !nosanitize [[META2]] +// CHECK-NEXT:unreachable, !nosanitize [[META2]] +// CHECK: [[CONT]]: +// CHECK-NEXT:[[TMP2:%.*]] = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[Y]], i32 129), !nosanitize [[META2]] +// CHECK-NEXT:[[TMP3:%.*]] = extractvalue { i32, i1 } [[TMP2]], 1, !nosanitize [[META2]] +// CHECK-NEXT:br i1 [[TMP3]], lab
[clang] Reapply "[NFC][clang] Add ubsan-trap-merge.c test to show absence of nomerge" (#117804) (PR #117805)
https://github.com/thurstond closed https://github.com/llvm/llvm-project/pull/117805 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ubsan] Change ubsan-unique-traps to use nomerge instead of counter (PR #117651)
https://github.com/vitalybuka approved this pull request. https://github.com/llvm/llvm-project/pull/117651 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] modernize-make-shared: Add MakeSmartPtrType option (PR #117529)
@@ -150,6 +150,16 @@ New check aliases Changes in existing checks ^^ +- Improved :doc:modernize-make-shared + check by adding a new option + `MakeSmartPtrType`` to specify the corresponding smart pointer type, with a + default value of ``::std::shared_ptr`. EugeneZelenko wrote: ```suggestion default value of `::std::shared_ptr`. ``` https://github.com/llvm/llvm-project/pull/117529 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] modernize-make-shared: Add MakeSmartPtrType option (PR #117529)
@@ -150,6 +150,16 @@ New check aliases Changes in existing checks ^^ +- Improved :doc:modernize-make-shared + check by adding a new option + `MakeSmartPtrType`` to specify the corresponding smart pointer type, with a EugeneZelenko wrote: ```suggestion `MakeSmartPtrType` to specify the corresponding smart pointer type, with a ``` https://github.com/llvm/llvm-project/pull/117529 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] modernize-make-shared: Add MakeSmartPtrType option (PR #117529)
@@ -150,6 +150,16 @@ New check aliases Changes in existing checks ^^ +- Improved :doc:modernize-make-shared + check by adding a new option + `MakeSmartPtrType`` to specify the corresponding smart pointer type, with a + default value of ``::std::shared_ptr`. + +- Improved :doc:modernize-make-unique + check by adding a new option EugeneZelenko wrote: ```suggestion ` check by adding a new option ``` https://github.com/llvm/llvm-project/pull/117529 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ubsan] Change ubsan-unique-traps to use nomerge instead of counter (PR #117651)
https://github.com/thurstond updated https://github.com/llvm/llvm-project/pull/117651 >From e635c76812eb8a6346e8602ec2eb6e4c389fcf6c Mon Sep 17 00:00:00 2001 From: Thurston Dang Date: Tue, 26 Nov 2024 00:33:09 + Subject: [PATCH 01/15] [ubsan] Change ubsan-unique-traps to use nomerge instead of counter https://github.com/llvm/llvm-project/pull/65972 (continuation of https://reviews.llvm.org/D148654) had considered adding nomerge to ubsantrap, but did not proceed with that because of https://github.com/llvm/llvm-project/issues/53011. Instead, it added a counter (based on TrapBB->getParent()->size()) to each ubsantrap call. However, this counter is not guaranteed to be unique after inlining, as shown by https://github.com/llvm/llvm-project/pull/83470, which can result in ubsantraps being merged by the backend. https://github.com/llvm/llvm-project/pull/101549 fixed has since fixed the nomerge limitation ("It sets nomerge flag for the node if the instruction has nomerge arrtibute."). This patch therefore takes advantage of nomerge instead of using the counter, guaranteeing that the ubsantraps are not merged. This patch is equivalent to https://github.com/llvm/llvm-project/pull/83470 but also adds nomerge and updates the test that was precommitted in https://github.com/llvm/llvm-project/pull/117649. --- clang/lib/CodeGen/CGExpr.cpp| 6 ++-- clang/test/CodeGen/bounds-checking.c| 4 +-- clang/test/CodeGen/ubsan-trap-merge.c | 18 +-- llvm/test/CodeGen/X86/ubsan-trap-merge.ll | 31 ++- llvm/test/CodeGen/X86/ubsan-trap-nomerge.ll | 33 ++--- 5 files changed, 44 insertions(+), 48 deletions(-) diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index d3f470d401b3d4..f8c1e1cd7a4d68 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -3921,16 +3921,14 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked, llvm::CallInst *TrapCall = Builder.CreateCall( CGM.getIntrinsic(llvm::Intrinsic::ubsantrap), -llvm::ConstantInt::get(CGM.Int8Ty, - ClSanitizeDebugDeoptimization - ? TrapBB->getParent()->size() - : static_cast(CheckHandlerID))); +llvm::ConstantInt::get(CGM.Int8Ty, CheckHandlerID)); if (!CGM.getCodeGenOpts().TrapFuncName.empty()) { auto A = llvm::Attribute::get(getLLVMContext(), "trap-func-name", CGM.getCodeGenOpts().TrapFuncName); TrapCall->addFnAttr(A); } +TrapCall->addFnAttr(llvm::Attribute::NoMerge); TrapCall->setDoesNotReturn(); TrapCall->setDoesNotThrow(); Builder.CreateUnreachable(); diff --git a/clang/test/CodeGen/bounds-checking.c b/clang/test/CodeGen/bounds-checking.c index 8100e30d0650ad..f6c4880e70a150 100644 --- a/clang/test/CodeGen/bounds-checking.c +++ b/clang/test/CodeGen/bounds-checking.c @@ -74,11 +74,11 @@ char B2[10]; // CHECK-LABEL: @f8 void f8(int i, int k) { // NOOPTLOCAL: call void @llvm.ubsantrap(i8 3) - // NOOPTARRAY: call void @llvm.ubsantrap(i8 2) + // NOOPTARRAY: call void @llvm.ubsantrap(i8 18) B[i] = '\0'; // NOOPTLOCAL: call void @llvm.ubsantrap(i8 5) - // NOOPTARRAY: call void @llvm.ubsantrap(i8 4) + // NOOPTARRAY: call void @llvm.ubsantrap(i8 18) B2[k] = '\0'; } diff --git a/clang/test/CodeGen/ubsan-trap-merge.c b/clang/test/CodeGen/ubsan-trap-merge.c index 0f50d8c1ff47f2..ef32605c73174a 100644 --- a/clang/test/CodeGen/ubsan-trap-merge.c +++ b/clang/test/CodeGen/ubsan-trap-merge.c @@ -1,6 +1,6 @@ // NOTE: Assertions have mostly been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5 // The most important assertion is the attributes at the end of the file, which -// shows that ubsan does not currently attach 'nomerge'. +// shows that ubsan attaches 'nomerge' to each ubsantrap intrinsic. // // RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -fsanitize=signed-integer-overflow -fsanitize-trap=signed-integer-overflow -O3 -mllvm -ubsan-unique-traps %s -o - \ // RUN: | FileCheck %s @@ -14,7 +14,7 @@ // CHECK-NEXT:[[TMP1:%.*]] = extractvalue { i32, i1 } [[TMP0]], 1, !nosanitize [[META2]] // CHECK-NEXT:br i1 [[TMP1]], label %[[TRAP:.*]], label %[[CONT:.*]], !nosanitize [[META2]] // CHECK: [[TRAP]]: -// CHECK-NEXT:tail call void @llvm.ubsantrap(i8 2) #[[ATTR4:[0-9]+]], !nosanitize [[META2]] +// CHECK-NEXT:tail call void @llvm.ubsantrap(i8 0) #[[ATTR4:[0-9]+]], !nosanitize [[META2]] // CHECK-NEXT:unreachable, !nosanitize [[META2]] // CHECK: [[CONT]]: // CHECK-NEXT:[[TMP2:%.*]] = extractvalue { i32, i1 } [[TMP0]], 0, !nosanitize [[META2]] @@ -31,7 +31,7 @@ int f(int x) { // CHECK-NEXT:[[TMP1:%.*]] = extractvalue { i32, i1 } [[TMP0]], 1, !nosanitize [[META2]] // CHECK-NEXT:br i1 [[TMP1]], label %[[TRAP:.*]], label %[[CONT:.
[clang] [llvm] [ubsan] Change ubsan-unique-traps to use nomerge instead of counter (PR #117651)
@@ -3919,18 +3919,16 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked, Builder.CreateCondBr(Checked, Cont, TrapBB); EmitBlock(TrapBB); -llvm::CallInst *TrapCall = Builder.CreateCall( -CGM.getIntrinsic(llvm::Intrinsic::ubsantrap), -llvm::ConstantInt::get(CGM.Int8Ty, - ClSanitizeDebugDeoptimization - ? TrapBB->getParent()->size() - : static_cast(CheckHandlerID))); +llvm::CallInst *TrapCall = +Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::ubsantrap), + llvm::ConstantInt::get(CGM.Int8Ty, CheckHandlerID)); if (!CGM.getCodeGenOpts().TrapFuncName.empty()) { auto A = llvm::Attribute::get(getLLVMContext(), "trap-func-name", CGM.getCodeGenOpts().TrapFuncName); TrapCall->addFnAttr(A); } +TrapCall->addFnAttr(llvm::Attribute::NoMerge); thurstond wrote: Thanks, fixed in https://github.com/llvm/llvm-project/pull/117651/commits/0e8a4143ddc7b5c6e9ca7e64729ba5adcb0d92fb https://github.com/llvm/llvm-project/pull/117651 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Enable AST mutation in the constant evaluator (PR #115168)
zygoloid wrote: > @zygoloid would it be correct to say that you want the Standard to leave > idempotency of functions with side effects up to implementations, and, > consequently, you want the model of how side effects are integrated into > constant evaluation to work for both idempotent and non-idempotent functions? No, I think the standard should specify the exact semantics of its metaprogramming primitives. And for metaprogramming actions that generate code in particular, I think they should behave the same as the source code they are intended to be equivalent to -- and thus should produce redefinition errors as usual if the same definition is created more than once, regardless of whether one or both of the definitions came from a metaprogram. For other side effects, the rules for that primitive should specify what the behavior is -- and for example, whether we want some kind of deduplication or not. Separately, I think if an interpreter wants to apply some level of idempotency to redefinitions that the standard says are invalid, in order to better support things like re-parsing the same code (but with, say, a function body changed), it should do so consistently across different kinds of entity and regardless of whether they come directly from parsing source code or from metaprogramming. But that's out of scope for current standardization efforts (one could imagine explicit support for REPL-style interpreters in the C++ standard, but we don't have any such thing right now). https://github.com/llvm/llvm-project/pull/115168 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ubsan] Change ubsan-unique-traps to use nomerge instead of counter (PR #117651)
https://github.com/thurstond updated https://github.com/llvm/llvm-project/pull/117651 >From e635c76812eb8a6346e8602ec2eb6e4c389fcf6c Mon Sep 17 00:00:00 2001 From: Thurston Dang Date: Tue, 26 Nov 2024 00:33:09 + Subject: [PATCH 01/16] [ubsan] Change ubsan-unique-traps to use nomerge instead of counter https://github.com/llvm/llvm-project/pull/65972 (continuation of https://reviews.llvm.org/D148654) had considered adding nomerge to ubsantrap, but did not proceed with that because of https://github.com/llvm/llvm-project/issues/53011. Instead, it added a counter (based on TrapBB->getParent()->size()) to each ubsantrap call. However, this counter is not guaranteed to be unique after inlining, as shown by https://github.com/llvm/llvm-project/pull/83470, which can result in ubsantraps being merged by the backend. https://github.com/llvm/llvm-project/pull/101549 fixed has since fixed the nomerge limitation ("It sets nomerge flag for the node if the instruction has nomerge arrtibute."). This patch therefore takes advantage of nomerge instead of using the counter, guaranteeing that the ubsantraps are not merged. This patch is equivalent to https://github.com/llvm/llvm-project/pull/83470 but also adds nomerge and updates the test that was precommitted in https://github.com/llvm/llvm-project/pull/117649. --- clang/lib/CodeGen/CGExpr.cpp| 6 ++-- clang/test/CodeGen/bounds-checking.c| 4 +-- clang/test/CodeGen/ubsan-trap-merge.c | 18 +-- llvm/test/CodeGen/X86/ubsan-trap-merge.ll | 31 ++- llvm/test/CodeGen/X86/ubsan-trap-nomerge.ll | 33 ++--- 5 files changed, 44 insertions(+), 48 deletions(-) diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index d3f470d401b3d4..f8c1e1cd7a4d68 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -3921,16 +3921,14 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked, llvm::CallInst *TrapCall = Builder.CreateCall( CGM.getIntrinsic(llvm::Intrinsic::ubsantrap), -llvm::ConstantInt::get(CGM.Int8Ty, - ClSanitizeDebugDeoptimization - ? TrapBB->getParent()->size() - : static_cast(CheckHandlerID))); +llvm::ConstantInt::get(CGM.Int8Ty, CheckHandlerID)); if (!CGM.getCodeGenOpts().TrapFuncName.empty()) { auto A = llvm::Attribute::get(getLLVMContext(), "trap-func-name", CGM.getCodeGenOpts().TrapFuncName); TrapCall->addFnAttr(A); } +TrapCall->addFnAttr(llvm::Attribute::NoMerge); TrapCall->setDoesNotReturn(); TrapCall->setDoesNotThrow(); Builder.CreateUnreachable(); diff --git a/clang/test/CodeGen/bounds-checking.c b/clang/test/CodeGen/bounds-checking.c index 8100e30d0650ad..f6c4880e70a150 100644 --- a/clang/test/CodeGen/bounds-checking.c +++ b/clang/test/CodeGen/bounds-checking.c @@ -74,11 +74,11 @@ char B2[10]; // CHECK-LABEL: @f8 void f8(int i, int k) { // NOOPTLOCAL: call void @llvm.ubsantrap(i8 3) - // NOOPTARRAY: call void @llvm.ubsantrap(i8 2) + // NOOPTARRAY: call void @llvm.ubsantrap(i8 18) B[i] = '\0'; // NOOPTLOCAL: call void @llvm.ubsantrap(i8 5) - // NOOPTARRAY: call void @llvm.ubsantrap(i8 4) + // NOOPTARRAY: call void @llvm.ubsantrap(i8 18) B2[k] = '\0'; } diff --git a/clang/test/CodeGen/ubsan-trap-merge.c b/clang/test/CodeGen/ubsan-trap-merge.c index 0f50d8c1ff47f2..ef32605c73174a 100644 --- a/clang/test/CodeGen/ubsan-trap-merge.c +++ b/clang/test/CodeGen/ubsan-trap-merge.c @@ -1,6 +1,6 @@ // NOTE: Assertions have mostly been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5 // The most important assertion is the attributes at the end of the file, which -// shows that ubsan does not currently attach 'nomerge'. +// shows that ubsan attaches 'nomerge' to each ubsantrap intrinsic. // // RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -fsanitize=signed-integer-overflow -fsanitize-trap=signed-integer-overflow -O3 -mllvm -ubsan-unique-traps %s -o - \ // RUN: | FileCheck %s @@ -14,7 +14,7 @@ // CHECK-NEXT:[[TMP1:%.*]] = extractvalue { i32, i1 } [[TMP0]], 1, !nosanitize [[META2]] // CHECK-NEXT:br i1 [[TMP1]], label %[[TRAP:.*]], label %[[CONT:.*]], !nosanitize [[META2]] // CHECK: [[TRAP]]: -// CHECK-NEXT:tail call void @llvm.ubsantrap(i8 2) #[[ATTR4:[0-9]+]], !nosanitize [[META2]] +// CHECK-NEXT:tail call void @llvm.ubsantrap(i8 0) #[[ATTR4:[0-9]+]], !nosanitize [[META2]] // CHECK-NEXT:unreachable, !nosanitize [[META2]] // CHECK: [[CONT]]: // CHECK-NEXT:[[TMP2:%.*]] = extractvalue { i32, i1 } [[TMP0]], 0, !nosanitize [[META2]] @@ -31,7 +31,7 @@ int f(int x) { // CHECK-NEXT:[[TMP1:%.*]] = extractvalue { i32, i1 } [[TMP0]], 1, !nosanitize [[META2]] // CHECK-NEXT:br i1 [[TMP1]], label %[[TRAP:.*]], label %[[CONT:.
[clang] [clang] Diagnose dangling references for parenthesized aggregate initialization. (PR #117690)
https://github.com/usx95 approved this pull request. https://github.com/llvm/llvm-project/pull/117690 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Diagnose dangling references for parenthesized aggregate initialization. (PR #117690)
@@ -961,6 +963,17 @@ static void visitLocalsRetainedByInitializer(IndirectLocalPath &Path, if (isa(Init) || isa(Init)) return visitFunctionCallArguments(Path, Init, Visit); + if (auto *CPE = dyn_cast(Init)) { +Path.push_back({IndirectLocalPathEntry::ParenAggInit, CPE}); +for (auto *I : CPE->getInitExprs()) { + if (I->isGLValue()) +visitLocalsRetainedByReferenceBinding(Path, I, RK_ReferenceBinding, + Visit); + else +visitLocalsRetainedByInitializer(Path, I, Visit, true); +} +Path.pop_back(); usx95 wrote: nit: Use `RevertToOldSizeRAII`. https://github.com/llvm/llvm-project/pull/117690 ___ 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,24 @@ ! CHECK-TWO-CONFIGS-NEXT: Configuration file: {{.*}}Inputs{{.}}config2{{.}}config-4.cfg ! CHECK-TWO-CONFIGS: -ffp-contract=fast ! CHECK-TWO-CONFIGS: -O3 + +!--- The -l 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 -o %s.out %s -### 2>&1 | FileCheck %s -check-prefix CHECK-LINKING DavidTruby wrote: Sorry, the comments about -Bstatic/-Bdynamic that I made were from a draft of this comment that I didn't mean to send 😓 -Wl,... options like -Bstatic and -Bdynamic will just be passed on to the linker the same as on other platforms, regardless of if the linker will accept them or not (and it won't for these two but that doesn't really matter for the purposes of the test) 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] Only build static analyzer sources if requested (PR #71653)
steakhal wrote: As a CSA maintainer, I believe having this component optional is valuable just like @whisperity described. To me, it's not an important subject such that I'd invest time here, but I'm ready to review patches improving the status quo. What is important here that by default it would still compile CSA; and I believe clang should be shipped including the CSA component, but users should be able to disable it if they want to. Probably this CMake option worked like this in the past, and it's just not really used in an build bots so it rot. https://github.com/llvm/llvm-project/pull/71653 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][SME] Ignore flatten/clang::always_inline statements for callees with mismatched streaming attributes (PR #116391)
https://github.com/sdesmalen-arm approved this pull request. https://github.com/llvm/llvm-project/pull/116391 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [Flang] LoongArch64 support for BIND(C) derived types in mabi=lp64d. (PR #117108)
@@ -1151,6 +1154,311 @@ struct TargetLoongArch64 : public GenericTarget { return GenericTarget::integerArgumentType(loc, argTy); } + + /// Flatten non-basic types, resulting in an array of types containing only + /// `IntegerType` and `FloatType`. + std::vector flattenTypeList(mlir::Location loc, + const mlir::Type type) const { +std::vector flatTypes; + +llvm::TypeSwitch(type) +.template Case([&](mlir::IntegerType intTy) { + if (intTy.getWidth() != 0) +flatTypes.push_back(intTy); +}) +.template Case([&](mlir::FloatType floatTy) { + if (floatTy.getWidth() != 0) +flatTypes.push_back(floatTy); +}) +.template Case([&](mlir::ComplexType cmplx) { + const auto *sem = &floatToSemantics(kindMap, cmplx.getElementType()); + if (sem == &llvm::APFloat::IEEEsingle() || + sem == &llvm::APFloat::IEEEdouble() || + sem == &llvm::APFloat::IEEEquad()) +std::fill_n(std::back_inserter(flatTypes), 2, +cmplx.getElementType()); + else +TODO(loc, "unsupported complx type(not IEEEsingle, IEEEdouble, " + "IEEEquad) as a structure component for BIND(C), " + "VALUE derived type argument and type return"); +}) +.template Case([&](fir::LogicalType logicalTy) { + const auto width = kindMap.getLogicalBitsize(logicalTy.getFKind()); + if (width != 0) +flatTypes.push_back( +mlir::IntegerType::get(type.getContext(), width)); +}) +.template Case([&](fir::CharacterType charTy) { + flatTypes.push_back(mlir::IntegerType::get(type.getContext(), 8)); ylzsx wrote: It seems that the demo you provided can only be used outside of ISO_C_BINDING. Below is a test I created: ``` program main implicit none character(kind=4) :: i call foo(i) contains subroutine foo(i) bind(c) character(kind=4) :: i end subroutine foo end program main ``` and when I compile it in a X86-64 machine using flang, I got a compilation error: ``` error: Semantic errors in char-struct.f90 ./char-struct.f90:9:30: error: A BIND(C) object must have an interoperable type character(kind=4) :: i ``` When I delete the `bind(c)` attribute, it compile success. However, the argument is passed by reference, and it does not enter functions for architecture-specific processing. >From the results above, it appears that the `character` type used for >Interoperability with C is only one byte, which seems to be the same as the >last line of Table 18.2 in section 18.3.1 of the manual >[18-007r1](https://j3-fortran.org/doc/year/18/18-007r1.pdf#subsection.3437) >I'm still a beginner in Fortran, I'm not sure if there is any >misunderstanding. I would appreciate your suggestions. https://github.com/llvm/llvm-project/pull/117108 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Treat escaped newlines as whitespace in Lexer::getRawToken. (PR #117548)
bazuzi wrote: > > If an escaped newline should not be considered whitespace, then instead of > > this change, getRawToken should be modified to return true when whitespace > > follows the escaped newline present at Loc > > That sounds like a more promising approach. Is that something you would be > willing to explore? Certainly. Some initial testing reveals that getPreviousTokenAndStart is not in conflict with this approach as I had feared, because Lexer::GetBeginningOfToken will include an escaped newline immediately followed by non-whitespace as being part of the token. I see no failing existing tests with just the new change to getRawToken, so I will update this PR to take that approach. https://github.com/llvm/llvm-project/pull/117548 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Treat escaped newlines as whitespace in Lexer::getRawToken. (PR #117548)
https://github.com/bazuzi updated https://github.com/llvm/llvm-project/pull/117548 >From 9c8b31dc266b770927785834c841b8ae5a7ebb58 Mon Sep 17 00:00:00 2001 From: Samira Bazuzi Date: Fri, 22 Nov 2024 15:45:55 -0500 Subject: [PATCH 1/2] Treat escaped newlines as whitespace in Lexer::getRawToken. The Lexer used in getRawToken is not told to keep whitespace, so when it skips over escaped newlines, it also ignores whitespace, regardless of getRawToken's IgnoreWhiteSpace parameter. My suspicion is that users that want to not IgnoreWhiteSpace and therefore return true for a whitespace character would also safely accept true for an escaped newline. For users that do use IgnoreWhiteSpace, there is no behavior change, and the handling of escaped newlines is already correct. If an escaped newline should not be considered whitespace, then instead of this change, getRawToken should be modified to return true when whitespace follows the escaped newline present at `Loc`, perhaps by using isWhitespace(SkipEscapedNewLines(StrData)[0]). However, this is incompatible with functions like clang::tidy::utils::lexer::getPreviousTokenAndStart. getPreviousTokenAndStart loops backwards through source location offsets, always decrementing by 1 without regard for potential character sizes larger than 1, such as escaped newlines. It seems more likely to me that there are more functions like this that would break than there are users who rely on escaped newlines not being treated as whitespace by getRawToken, but I'm open to that not being true. The modified test was printing `\\nF` for the name of the expanded macro and now does not find a macro name. In my opinion, this is not an indication that the new behavior for getRawToken is incorrect. Rather, this is, both before and after this change, due to an incorrect storage of the backslash's source location as the spelling location of the expansion location of `F`. --- clang/lib/Lex/Lexer.cpp | 4 +++- clang/test/Frontend/highlight-text.c | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp index e58c8bc72ae5b3..392cce6be0d171 100644 --- a/clang/lib/Lex/Lexer.cpp +++ b/clang/lib/Lex/Lexer.cpp @@ -527,7 +527,9 @@ bool Lexer::getRawToken(SourceLocation Loc, Token &Result, const char *StrData = Buffer.data()+LocInfo.second; - if (!IgnoreWhiteSpace && isWhitespace(StrData[0])) + if (!IgnoreWhiteSpace && (isWhitespace(StrData[0]) || +// Treat escaped newlines as whitespace. +SkipEscapedNewLines(StrData) != StrData)) return true; // Create a lexer starting at the beginning of this token. diff --git a/clang/test/Frontend/highlight-text.c b/clang/test/Frontend/highlight-text.c index a81d26caa4c24c..eefa4ebeec8ca4 100644 --- a/clang/test/Frontend/highlight-text.c +++ b/clang/test/Frontend/highlight-text.c @@ -12,8 +12,7 @@ int a = M; // CHECK-NEXT: :5:11: note: expanded from macro 'M' // CHECK-NEXT: 5 | #define M \ // CHECK-NEXT: | ^ -// CHECK-NEXT: :3:14: note: expanded from macro '\ -// CHECK-NEXT: F' +// CHECK-NEXT: :3:14: note: expanded from here // CHECK-NEXT: 3 | #define F (1 << 99) // CHECK-NEXT: | ^ ~~ // CHECK-NEXT: :8:9: warning: shift count >= width of type [-Wshift-count-overflow] >From 7dec0bb67491a20e8e010713640ce5f69503ec25 Mon Sep 17 00:00:00 2001 From: Samira Bazuzi Date: Tue, 26 Nov 2024 09:53:36 -0500 Subject: [PATCH 2/2] Switch to checking for whitespace after escaped newlines. --- clang/lib/Lex/Lexer.cpp | 714 ++- clang/test/Frontend/highlight-text.c | 3 +- 2 files changed, 382 insertions(+), 335 deletions(-) diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp index 392cce6be0d171..ea2c2aeebdcfd0 100644 --- a/clang/lib/Lex/Lexer.cpp +++ b/clang/lib/Lex/Lexer.cpp @@ -141,8 +141,8 @@ void Lexer::InitLexer(const char *BufStart, const char *BufPtr, // Determine the size of the BOM. StringRef Buf(BufferStart, BufferEnd - BufferStart); size_t BOMLength = llvm::StringSwitch(Buf) - .StartsWith("\xEF\xBB\xBF", 3) // UTF-8 BOM - .Default(0); + .StartsWith("\xEF\xBB\xBF", 3) // UTF-8 BOM + .Default(0); // Skip the BOM. BufferPtr += BOMLength; @@ -256,14 +256,14 @@ Lexer *Lexer::Create_PragmaLexer(SourceLocation SpellingLoc, const char *StrData = SM.getCharacterData(SpellingLoc); L->BufferPtr = StrData; - L->BufferEnd = StrData+TokLen; + L->BufferEnd = StrData + TokLen; assert(L->BufferEnd[0] == 0 && "Buffer is not nul terminated!"); // Set the SourceLocation with the remapping information. This ensures that // GetMappedTokenLoc will remap the tokens as they are lexed. - L->FileLoc = SM.createExpansionLoc(SM.getLocForStartOfFile(SpellingFID), - Expans
[clang] [flang] [flang] Preserve fixed form in fc1 -x value (PR #117563)
macurtis-amd wrote: Thanks @banach-space and @DavidTruby for looking at this. > banach-space: Adding new types to > [Types.def](https://github.com/llvm/llvm-project/pull/117563/files#diff-b2abf750cadedc6109158e6f82b66abfaabd7c7c86c650d2a5163dc3e5fc44a7) > is a fairly huge design update. I'm not saying this is approach is > incorrect, but it definitely deserves a bit of discussion. Perhaps under a > GitHub issue? I don't really mind. Created issue [117712](https://github.com/llvm/llvm-project/issues/117712). We can continue discussion there if that is the right place. > banach-space: Could you quickly summarise what's not working >From that issue: Here is the problematic fixed form fortran source `reduced.f`: ``` subroutine foo(a, b) if ( (a .eq. 0) .and. > (b . eq. 1) ) then print *, "foo" end if end subroutine ``` Prior to [9fb2db1](https://github.com/llvm/llvm-project/commit/9fb2db1e1f42ae10a9d8c1d9410b5f4e719fdac0) `flang -save-temps -c` produced `reduced.i`: ``` subroutine foo(a, b) if ( (a .eq. 0) .and.(b.eq.1))then print *, "foo" end if end subroutine ``` which compiles without error. With [9fb2db1](https://github.com/llvm/llvm-project/commit/9fb2db1e1f42ae10a9d8c1d9410b5f4e719fdac0), `flang -save-temps -c` produces `reduced.i`: ``` subroutine foo(a, b) if ( (a .eq. 0) .and.(b. eq. 1)) then print *, "foo" end if end subroutine ``` Which produces: ``` error: Could not parse reduced.i ./reduced.f:2:31: error: expected ')' if ( (a .eq. 0) .and.(b. eq. 1)) then ^ ... ``` In either case the commands produced by the driver look like: ``` flang-new -fc1 -E -o reduced.i -x f95-cpp-input reduced.f flangnew -fc1 -emit-llvm-bc ... -o reduced.bc -x f95 reduced.i ... ``` > banach-space: ... and why adding new types to Types.def solves that? With this change, the driver produces: ``` flang-new -fc1 -E ... -o reduced.i -x f95-fixed-cpp-input reduced.f flang-new -fc1 -emit-llvm-bc -o reduced.bc -x f95-fixed reduced.i ``` Which preserves the fact that reduced.i contains fixed form fortran. > banach-space: Is that the only solution? No. I initially looked at modifying [Flang::ConstructJob](https://github.com/llvm/llvm-project/blob/65c36179be68dda0d1cc5d7e5c5b312a6b52cc0e/clang/lib/Driver/ToolChains/Flang.cpp#L709) to add `-ffixed-form` to the compilation command. But I found myself having to walk back through the compilation graph to get the original filename extension so I could determine if it was fixed or free. It worked, but seemed brittle. It does have the benefit of being more surgical. Another solution I considered, was propagating the fixed vs free information in some way other than the type. I didn't go down this path because it seemed more natural to consider it part of the type. FWIW, I don't have strong feelings here. I'm happy to implement the fix however you all think is best. > DavidTruby: what is the difference between the proposed flang -fc1 -x > f95-fixed and the existing flang -fc1 -ffixed-form? > DavidTruby: In the test case in here I already don't see an error with flang > -fc1 -ffixed-form, is there an example you have where this fails to compile > but -x f95-fixed works? Sorry. I should have put this in the commit description, but the issue is specific to the use of `-save-temps`. If manually invoking flang -fc1 there is no benefit to -x f95-fixed. The problem is the driver needs to know to add `-ffixed-form` when building the compilation command. As noted above, I tried doing this, but was not happy with the resulting code. https://github.com/llvm/llvm-project/pull/117563 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Emit stub version of OpenCL Kernel (PR #115821)
https://github.com/shiltian edited https://github.com/llvm/llvm-project/pull/115821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Skip escaped newlines before checking for whitespace in Lexer::getRawToken. (PR #117548)
https://github.com/bazuzi edited https://github.com/llvm/llvm-project/pull/117548 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Clang tooling generated visibility macros for Clang (PR #109702)
AaronBallman wrote: > > > The default behaviour of `ids` is to assume that anything declared in the > > > header is public and it will ensure that anything added in the headers is > > > annotated properly to say it is exposed, making something private would > > > be an explicit decision that the developer need to take. > > > > > > Is this the correct default though? It seems to me that usual best > > practices is to limit the visibility unless there's an opt in saying > > something is public (aka, the `class` model in C++ rather than the `struct` > > model which is rooted in C compatibility). I would have thought we'd do an > > initial pass to make everything public that needs to be public, and then > > require explicit opt-in rather than explicit opt-out, mostly because > > anything we list as being opted in is something someone, somewhere is > > likely to take as a promise that we'll always support it because it's part > > of the public interface. > > I can absolutely see the value in the opposite - minimise the ABI surface. > For many projects, there is a split of internal and external headers. The > idea is that this tool is only run on the external headers, so those are > meant to be ABI. > > While the idea of making everything private and requiring opt-in to make it > public is enticing, I don't see how to verify that the ABI surface is > correct/complete. If we were to do that, then the default behaviour would > require iteration until the minimal bounds is determined which would be > frustrating for the developer as you might require O(function) iterations. Well, we're currently approaching this from the angle of "expose everything and then the user can do whatever they want", but perhaps the discussion we should be having is "what use cases do we explicitly want to support?" and then we write plugins to demonstrate that we do support those use cases, exposing what's necessary as part of that process. This does mean that use cases we hadn't anticipated may be frustrating for users, but we can more easily expand the surface area of what we expose than we can claw it back once we've exposed it publicly. But that does mean a lot more up front work on our part. (Note, I don't insist on this, just having the discussion to see where the ideas lead.) > On the other hand, it does help with ABI stability because additions to the > ABI surface are okay, removal is not permitted for stability (Hyrum's Law). Exactly; and I worry about the long-term maintenance impacts of exposing everything. > > From what I'm seeing on the PR, it sounds like most of the outstanding > > concerns are around how to keep these annotations up to date. There have > > been a few requests for something like precommit CI or a github action. I > > think we should try to come to a decision on what we feel comfortable with > > there. (I tend to lean on the side of a github action that's run once a day > > as suggested by @tstellar > > I agree that a GHA workflow would work for this. However, if/when we are able > to get a Windows DLL build stood up, that would also likely be less > interesting as that would immediately catch any regressions. Furthermore, I > expect that once this work is fully complete, we should be able to switch to > `-fvisbility=hidden -fvisbility-inlines-hidden` which would also provide a > pretty good overlap on Linux and macOS builds. The remaining uncaught > differences would be platform specific due to ABI specific constraints (e.g. > RTTI representation and vtable layouts). > > Note that this doesn't mean that I'm against the GHA - quite the opposite. I > think that is a good solution and will help bridge us to the point where we > can rely on regular iteration to identify these issues more quickly. +1 https://github.com/llvm/llvm-project/pull/109702 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Emit stub version of OpenCL Kernel (PR #115821)
https://github.com/shiltian edited https://github.com/llvm/llvm-project/pull/115821 ___ 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 false positive in bugprone-return-const-ref-from-parameter (PR #117734)
@@ -179,7 +179,8 @@ Changes in existing checks - Improved :doc:`bugprone-return-const-ref-from-parameter ` check to diagnose potential dangling references when returning a ``const &`` parameter - by using the conditional operator ``cond ? var1 : var2``. + by using the conditional operator ``cond ? var1 : var2``and no longer giving EugeneZelenko wrote: ```suggestion by using the conditional operator ``cond ? var1 : var2`` and no longer giving ``` https://github.com/llvm/llvm-project/pull/117734 ___ 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 false positive in bugprone-return-const-ref-from-parameter (PR #117734)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff f7dc1d0ac83b7c6b691167d8d02561ba0837b631 80e12b2ed1f324181d280cbd2fd242f63642bed6 --extensions cpp -- clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp clang-tools-extra/test/clang-tidy/checkers/bugprone/return-const-ref-from-parameter.cpp `` View the diff from clang-format here. ``diff diff --git a/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp index 80d1487ba5..64c66ee4ae 100644 --- a/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp @@ -18,14 +18,17 @@ namespace clang::tidy::bugprone { void ReturnConstRefFromParameterCheck::registerMatchers(MatchFinder *Finder) { const auto DRef = ignoringParens( declRefExpr( - to(parmVarDecl(hasType(hasCanonicalType( - qualType(lValueReferenceType(pointee( - qualType(isConstQualified() - .bind("type"))), parmVarDecl(hasDeclContext(functionDecl().bind("owner" + to(parmVarDecl( + hasType(hasCanonicalType( + qualType(lValueReferenceType( + pointee(qualType(isConstQualified() + .bind("type"))), + parmVarDecl(hasDeclContext(functionDecl().bind("owner" .bind("param"))) .bind("dref")); const auto Func = - functionDecl(equalsBoundNode("owner"), hasReturnTypeLoc(loc( + functionDecl(equalsBoundNode("owner"), + hasReturnTypeLoc(loc( qualType(hasCanonicalType(equalsBoundNode("type")) .bind("func"); `` https://github.com/llvm/llvm-project/pull/117734 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] prevent errors for deduction guides using deduced type aliases (PR #117450)
@@ -11451,7 +11451,11 @@ bool Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R, bool MightInstantiateToSpecialization = false; if (auto RetTST = TSI->getTypeLoc().getAsAdjusted()) { - TemplateName SpecifiedName = RetTST.getTypePtr()->getTemplateName(); + const TemplateSpecializationType *TST = RetTST.getTypePtr(); + while (TST && TST->isTypeAlias()) +TST = TST->getAliasedType()->getAs(); + + TemplateName SpecifiedName = TST->getTemplateName(); a-tarasyuk wrote: @antangelo thanks for the review. I've added assert or would an additional condition be better? https://github.com/llvm/llvm-project/pull/117450 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Add [[clang::no_specializations]] (PR #101469)
https://github.com/philnik777 updated https://github.com/llvm/llvm-project/pull/101469 >From 82ab798fc72c6de64ae527d96393f0dc67307e98 Mon Sep 17 00:00:00 2001 From: Nikolas Klauser Date: Thu, 1 Aug 2024 12:30:22 +0200 Subject: [PATCH 1/8] [Clang] Add [[clang::diagnose_specializations]] --- clang/include/clang/Basic/Attr.td | 13 ++- clang/include/clang/Basic/AttrDocs.td | 14 ++-- clang/include/clang/Basic/DiagnosticGroups.td | 1 + .../clang/Basic/DiagnosticSemaKinds.td| 3 ++ clang/lib/Sema/SemaDeclAttr.cpp | 9 + clang/lib/Sema/SemaTemplate.cpp | 6 .../SemaCXX/attr-diagnose-specializations.cpp | 34 +++ 7 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 clang/test/SemaCXX/attr-diagnose-specializations.cpp diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 8ac2079099c854..e074cc8b285a95 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -103,6 +103,9 @@ def NonParmVar : SubsetSubjecthasLocalStorage()}], "variables with non-local storage">; +def VarTmpl : SubsetSubjectgetDescribedVarTemplate()}], +"variable template">; + def NonBitField : SubsetSubjectisBitField()}], "non-bit-field non-static data members">; @@ -3327,6 +3330,14 @@ def DiagnoseIf : InheritableAttr { let Documentation = [DiagnoseIfDocs]; } +def DiagnoseSpecializations : InheritableAttr { + let Spellings = [Clang<"diagnose_specializations", /*AllowInC*/0>]; + let Subjects = SubjectList<[ClassTmpl, VarTmpl]>; + let Documentation = [DiagnoseSpecializationsDocs]; + let MeaningfulToClassTemplateDefinition = 1; + let TemplateDependent = 1; +} + def ArcWeakrefUnavailable : InheritableAttr { let Spellings = [Clang<"objc_arc_weak_reference_unavailable">]; let Subjects = SubjectList<[ObjCInterface], ErrorDiag>; @@ -4581,7 +4592,7 @@ def HLSLResource : InheritableAttr { let Spellings = []; let Subjects = SubjectList<[Struct]>; let LangOpts = [HLSL]; - let Args = [ + let Args = [ EnumArgument< "ResourceKind", "llvm::hlsl::ResourceKind", /*is_string=*/0, diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index 94c284fc731589..4ca67a63714d4b 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -975,6 +975,15 @@ Query for this feature with ``__has_attribute(diagnose_if)``. }]; } +def DiagnoseSpecializationsDocs : Documentation { + let Category = DocCatDecl; + let Content = [{ +``clang::diagnose_specializations`` can be appied to class templates which +should not be specialized by users. This is primarily used to diagnose user +specializations of standard library type traits. + }]; +} + def PassObjectSizeDocs : Documentation { let Category = DocCatVariable; // Technically it's a parameter doc, but eh. let Heading = "pass_object_size, pass_dynamic_object_size"; @@ -7388,10 +7397,10 @@ def HLSLLoopHintDocs : Documentation { let Content = [{ The ``[loop]`` directive allows loop optimization hints to be specified for the subsequent loop. The directive allows unrolling to -be disabled and is not compatible with [unroll(x)]. +be disabled and is not compatible with [unroll(x)]. Specifying the parameter, ``[loop]``, directs the -unroller to not unroll the loop. +unroller to not unroll the loop. .. code-block:: hlsl @@ -8306,4 +8315,3 @@ Declares that a function potentially allocates heap memory, and prevents any pot of ``nonallocating`` by the compiler. }]; } - diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 19c3f1e0433496..d6f6111f708684 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -472,6 +472,7 @@ def ExpansionToDefined : DiagGroup<"expansion-to-defined">; def FlagEnum : DiagGroup<"flag-enum">; def IncrementBool : DiagGroup<"increment-bool", [DeprecatedIncrementBool]>; def InfiniteRecursion : DiagGroup<"infinite-recursion">; +def InvalidSpecialization : DiagGroup<"invalid-specialization">; def PureVirtualCallFromCtorDtor: DiagGroup<"call-to-pure-virtual-from-ctor-dtor">; def GNUImaginaryConstant : DiagGroup<"gnu-imaginary-constant">; def IgnoredGCH : DiagGroup<"ignored-gch">; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 581434d33c5c9a..5972d630347ec4 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -5407,6 +5407,9 @@ def note_dependent_function_template_spec_discard_reason : Note< "candidate ignored: %select{not a function template|" "not a member of the enclosing %select{class template|" "namespace; did y
[clang-tools-extra] [clang-tidy] fix false positive in bugprone-return-const-ref-from-parameter (PR #117734)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/117734 >From 7dd899ec58a61b02a2bd584d021dcddfb20ceaba Mon Sep 17 00:00:00 2001 From: Qizhi Hu <836744...@qq.com> Date: Wed, 27 Nov 2024 00:57:00 +0800 Subject: [PATCH] [clang-tidy] fix false positive in bugprone-return-const-ref-from-parameter --- .../bugprone/ReturnConstRefFromParameterCheck.cpp | 4 ++-- clang-tools-extra/docs/ReleaseNotes.rst | 3 ++- .../checkers/bugprone/return-const-ref-from-parameter.cpp | 6 ++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp index 7cc4fe519d3a64..80d1487ba5d6fb 100644 --- a/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp @@ -21,11 +21,11 @@ void ReturnConstRefFromParameterCheck::registerMatchers(MatchFinder *Finder) { to(parmVarDecl(hasType(hasCanonicalType( qualType(lValueReferenceType(pointee( qualType(isConstQualified() - .bind("type" + .bind("type"))), parmVarDecl(hasDeclContext(functionDecl().bind("owner" .bind("param"))) .bind("dref")); const auto Func = - functionDecl(hasReturnTypeLoc(loc( + functionDecl(equalsBoundNode("owner"), hasReturnTypeLoc(loc( qualType(hasCanonicalType(equalsBoundNode("type")) .bind("func"); diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index f8507156aa4198..4d3cfa00fd2766 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -179,7 +179,8 @@ Changes in existing checks - Improved :doc:`bugprone-return-const-ref-from-parameter ` check to diagnose potential dangling references when returning a ``const &`` parameter - by using the conditional operator ``cond ? var1 : var2``. + by using the conditional operator ``cond ? var1 : var2`` and no longer giving + false positives for lambda. - Improved :doc:`bugprone-sizeof-expression ` check to find suspicious diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/return-const-ref-from-parameter.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/return-const-ref-from-parameter.cpp index d83d997a455d50..5179a80f4d5b4b 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/return-const-ref-from-parameter.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/return-const-ref-from-parameter.cpp @@ -151,6 +151,12 @@ void instantiate(const int ¶m, const float ¶mf, int &mut_param, float &m itf6(mut_paramf); } +template +void f(const T& t) { +const auto get = [&t] -> const T& { return t; }; +return T{}; +} + } // namespace valid namespace overload { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Add [[clang::no_specializations]] (PR #101469)
@@ -473,6 +473,7 @@ def ExpansionToDefined : DiagGroup<"expansion-to-defined">; def FlagEnum : DiagGroup<"flag-enum">; def IncrementBool : DiagGroup<"increment-bool", [DeprecatedIncrementBool]>; def InfiniteRecursion : DiagGroup<"infinite-recursion">; +def InvalidSpecialization : DiagGroup<"invalid-specialization">; philnik777 wrote: Ah, I didn't realize you could do that. https://github.com/llvm/llvm-project/pull/101469 ___ 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 false positive in bugprone-return-const-ref-from-parameter (PR #117734)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/117734 >From 5d35398c45631a58e283899419f00e4a5e0ba722 Mon Sep 17 00:00:00 2001 From: Qizhi Hu <836744...@qq.com> Date: Wed, 27 Nov 2024 00:57:00 +0800 Subject: [PATCH] [clang-tidy] fix false positive in bugprone-return-const-ref-from-parameter --- .../bugprone/ReturnConstRefFromParameterCheck.cpp | 13 - clang-tools-extra/docs/ReleaseNotes.rst | 3 ++- .../bugprone/return-const-ref-from-parameter.cpp| 6 ++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp index 7cc4fe519d3a64..64c66ee4ae1306 100644 --- a/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp @@ -18,14 +18,17 @@ namespace clang::tidy::bugprone { void ReturnConstRefFromParameterCheck::registerMatchers(MatchFinder *Finder) { const auto DRef = ignoringParens( declRefExpr( - to(parmVarDecl(hasType(hasCanonicalType( - qualType(lValueReferenceType(pointee( - qualType(isConstQualified() - .bind("type" + to(parmVarDecl( + hasType(hasCanonicalType( + qualType(lValueReferenceType( + pointee(qualType(isConstQualified() + .bind("type"))), + parmVarDecl(hasDeclContext(functionDecl().bind("owner" .bind("param"))) .bind("dref")); const auto Func = - functionDecl(hasReturnTypeLoc(loc( + functionDecl(equalsBoundNode("owner"), + hasReturnTypeLoc(loc( qualType(hasCanonicalType(equalsBoundNode("type")) .bind("func"); diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index f8507156aa4198..4d3cfa00fd2766 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -179,7 +179,8 @@ Changes in existing checks - Improved :doc:`bugprone-return-const-ref-from-parameter ` check to diagnose potential dangling references when returning a ``const &`` parameter - by using the conditional operator ``cond ? var1 : var2``. + by using the conditional operator ``cond ? var1 : var2`` and no longer giving + false positives for lambda. - Improved :doc:`bugprone-sizeof-expression ` check to find suspicious diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/return-const-ref-from-parameter.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/return-const-ref-from-parameter.cpp index d83d997a455d50..5179a80f4d5b4b 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/return-const-ref-from-parameter.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/return-const-ref-from-parameter.cpp @@ -151,6 +151,12 @@ void instantiate(const int ¶m, const float ¶mf, int &mut_param, float &m itf6(mut_paramf); } +template +void f(const T& t) { +const auto get = [&t] -> const T& { return t; }; +return T{}; +} + } // namespace valid namespace overload { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [lldb] [Clang] Improve Sema diagnostic performance for __builtin_counted_by_ref (PR #116719)
https://github.com/AaronBallman commented: Is there a branch up for this on https://llvm-compile-time-tracker.com/ so that we've verified that this actually improves performance? https://github.com/llvm/llvm-project/pull/116719 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [lldb] [Clang] Improve Sema diagnostic performance for __builtin_counted_by_ref (PR #116719)
https://github.com/AaronBallman edited https://github.com/llvm/llvm-project/pull/116719 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [lldb] [Clang] Improve Sema diagnostic performance for __builtin_counted_by_ref (PR #116719)
@@ -14690,6 +14690,13 @@ void Sema::FinalizeDeclaration(Decl *ThisDecl) { } } + // The result of __builtin_counted_by_ref cannot be assigned to a variable. + // It allows leaking and modification of bounds safety information. + if (IsBuiltinCountedByRef(VD->getInit())) +Diag(VD->getInit()->getExprLoc(), + diag::err_builtin_counted_by_ref_cannot_leak_reference) +<< VD->getInit()->getSourceRange(); AaronBallman wrote: Should we split this off into a helper function like `bool CheckInvalidBuiltinCountedByRef(const Expr *E);` ? https://github.com/llvm/llvm-project/pull/116719 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Propagate lifetimebound from formal parameters to those in the canonical declaration and use that for analysis (PR #107627)
https://github.com/higher-performance updated https://github.com/llvm/llvm-project/pull/107627 >From dffc6abf0a1e4b1e8977bf9476bb65d808b46986 Mon Sep 17 00:00:00 2001 From: higher-performance Date: Fri, 6 Sep 2024 14:16:15 -0400 Subject: [PATCH 1/3] Propagate lifetimebound from formal parameters to those in the canonical declaration, then use the canonical declaration for analysis Note that this doesn't handle the implicit 'this' parameter; that can be addressed in a separate commit. --- clang/lib/Sema/CheckExprLifetime.cpp | 15 +- clang/lib/Sema/SemaAttr.cpp | 34 +++ clang/test/SemaCXX/attr-lifetimebound.cpp | 5 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/clang/lib/Sema/CheckExprLifetime.cpp b/clang/lib/Sema/CheckExprLifetime.cpp index 8886e5e307ddf86..e7c8a7591804efb 100644 --- a/clang/lib/Sema/CheckExprLifetime.cpp +++ b/clang/lib/Sema/CheckExprLifetime.cpp @@ -611,9 +611,9 @@ static void visitFunctionCallArguments(IndirectLocalPath &Path, Expr *Call, } } - for (unsigned I = 0, -N = std::min(Callee->getNumParams(), Args.size()); - I != N; ++I) { + const FunctionDecl *CanonCallee = Callee->getCanonicalDecl(); + unsigned NP = std::min(Callee->getNumParams(), CanonCallee->getNumParams()); + for (unsigned I = 0, N = std::min(NP, Args.size()); I != N; ++I) { Expr *Arg = Args[I]; RevertToOldSizeRAII RAII(Path); if (auto *DAE = dyn_cast(Arg)) { @@ -621,12 +621,13 @@ static void visitFunctionCallArguments(IndirectLocalPath &Path, Expr *Call, {IndirectLocalPathEntry::DefaultArg, DAE, DAE->getParam()}); Arg = DAE->getExpr(); } -if (CheckCoroCall || Callee->getParamDecl(I)->hasAttr()) - VisitLifetimeBoundArg(Callee->getParamDecl(I), Arg); +if (CheckCoroCall || +CanonCallee->getParamDecl(I)->hasAttr()) + VisitLifetimeBoundArg(CanonCallee->getParamDecl(I), Arg); else if (EnableGSLAnalysis && I == 0) { // Perform GSL analysis for the first argument - if (shouldTrackFirstArgument(Callee)) { -VisitGSLPointerArg(Callee, Arg); + if (shouldTrackFirstArgument(CanonCallee)) { +VisitGSLPointerArg(CanonCallee, Arg); } else if (auto *Ctor = dyn_cast(Call); Ctor && shouldTrackFirstArgumentForConstructor(Ctor)) { VisitGSLPointerArg(Ctor->getConstructor(), Arg); diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp index 9fbad7ed67ccbe2..85274aee785a58f 100644 --- a/clang/lib/Sema/SemaAttr.cpp +++ b/clang/lib/Sema/SemaAttr.cpp @@ -216,7 +216,8 @@ void Sema::inferGslOwnerPointerAttribute(CXXRecordDecl *Record) { } void Sema::inferLifetimeBoundAttribute(FunctionDecl *FD) { - if (FD->getNumParams() == 0) + unsigned NumParams = FD->getNumParams(); + if (NumParams == 0) return; if (unsigned BuiltinID = FD->getBuiltinID()) { @@ -238,18 +239,13 @@ void Sema::inferLifetimeBoundAttribute(FunctionDecl *FD) { default: break; } -return; - } - if (auto *CMD = dyn_cast(FD)) { -const auto *CRD = CMD->getParent(); -if (!CRD->isInStdNamespace() || !CRD->getIdentifier()) - return; - -if (isa(CMD)) { + } else if (auto *CMD = dyn_cast(FD)) { +const CXXRecordDecl *CRD = CMD->getParent(); +if (CRD->isInStdNamespace() && CRD->getIdentifier() && +isa(CMD)) { auto *Param = CMD->getParamDecl(0); - if (Param->hasAttr()) -return; - if (CRD->getName() == "basic_string_view" && + if (!Param->hasAttr() && + CRD->getName() == "basic_string_view" && Param->getType()->isPointerType()) { // construct from a char array pointed by a pointer. // basic_string_view(const CharT* s); @@ -265,6 +261,20 @@ void Sema::inferLifetimeBoundAttribute(FunctionDecl *FD) { LifetimeBoundAttr::CreateImplicit(Context, FD->getLocation())); } } + } else if (auto *CanonDecl = FD->getCanonicalDecl(); FD != CanonDecl) { +// Propagate the lifetimebound attribute from parameters to the canonical +// declaration. +// Note that this doesn't include the implicit 'this' parameter, as the +// attribute is applied to the function type in that case. +unsigned NP = std::min(NumParams, CanonDecl->getNumParams()); +for (unsigned I = 0; I < NP; ++I) { + auto *CanonParam = CanonDecl->getParamDecl(I); + if (!CanonParam->hasAttr() && + FD->getParamDecl(I)->hasAttr()) { +CanonParam->addAttr(LifetimeBoundAttr::CreateImplicit( +Context, CanonParam->getLocation())); + } +} } } diff --git a/clang/test/SemaCXX/attr-lifetimebound.cpp b/clang/test/SemaCXX/attr-lifetimebound.cpp index f89b556f5bba088..c4a4e5415252e7f 100644 --- a/clang/test/SemaCXX/attr-lifetimebound.cpp +++ b/clang/test/SemaCXX/attr-lifetimebound.cpp @@ -19,6 +19,10 @@ namespace usage_invalid { namespace usage_ok { struct I
[clang] Propagate lifetimebound from formal parameters to those in the canonical declaration and use that for analysis (PR #107627)
@@ -266,6 +262,20 @@ void Sema::inferLifetimeBoundAttribute(FunctionDecl *FD) { LifetimeBoundAttr::CreateImplicit(Context, FD->getLocation())); } } + } else if (auto *CanonDecl = FD->getCanonicalDecl(); FD != CanonDecl) { +// Propagate the lifetimebound attribute from parameters to the canonical +// declaration. +// Note that this doesn't include the implicit 'this' parameter, as the +// attribute is applied to the function type in that case. +const unsigned int NP = std::min(NumParams, CanonDecl->getNumParams()); +for (unsigned int I = 0; I < NP; ++I) { + auto *CanonParam = CanonDecl->getParamDecl(I); + if (!CanonParam->hasAttr() && + FD->getParamDecl(I)->hasAttr()) { higher-performance wrote: Okay sure, let's see if `getMostRecentDecl` works. https://github.com/llvm/llvm-project/pull/107627 ___ 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 false positive in bugprone-return-const-ref-from-parameter (PR #117734)
@@ -18,14 +18,17 @@ namespace clang::tidy::bugprone { void ReturnConstRefFromParameterCheck::registerMatchers(MatchFinder *Finder) { const auto DRef = ignoringParens( declRefExpr( - to(parmVarDecl(hasType(hasCanonicalType( - qualType(lValueReferenceType(pointee( - qualType(isConstQualified() - .bind("type" + to(parmVarDecl( + hasType(hasCanonicalType( + qualType(lValueReferenceType( + pointee(qualType(isConstQualified() + .bind("type"))), + parmVarDecl(hasDeclContext(functionDecl().bind("owner" PiotrZSL wrote: no need for duplicating parmVarDecl https://github.com/llvm/llvm-project/pull/117734 ___ 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 false positive in bugprone-return-const-ref-from-parameter (PR #117734)
@@ -151,6 +151,12 @@ void instantiate(const int ¶m, const float ¶mf, int &mut_param, float &m itf6(mut_paramf); } +template +void f(const T& t) { +const auto get = [&t] -> const T& { return t; }; +return T{}; +} PiotrZSL wrote: Please add test: ``` const auto get = [](const T& t2) -> const T& { return t2; }; ``` and verify that it's being still detected. https://github.com/llvm/llvm-project/pull/117734 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Propagate lifetimebound from formal parameters to those in the canonical declaration and use that for analysis (PR #107627)
https://github.com/higher-performance updated https://github.com/llvm/llvm-project/pull/107627 >From e9af4e3d8f629fff790f2f573ceccdf01fcb9495 Mon Sep 17 00:00:00 2001 From: higher-performance Date: Fri, 6 Sep 2024 14:16:15 -0400 Subject: [PATCH 1/3] Propagate lifetimebound from formal parameters to those in the canonical declaration, then use the canonical declaration for analysis Note that this doesn't handle the implicit 'this' parameter; that can be addressed in a separate commit. --- clang/lib/Sema/CheckExprLifetime.cpp | 15 +- clang/lib/Sema/SemaAttr.cpp | 34 +++ clang/test/SemaCXX/attr-lifetimebound.cpp | 5 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/clang/lib/Sema/CheckExprLifetime.cpp b/clang/lib/Sema/CheckExprLifetime.cpp index 6cdd4dc629e50a..d3423b50f3b051 100644 --- a/clang/lib/Sema/CheckExprLifetime.cpp +++ b/clang/lib/Sema/CheckExprLifetime.cpp @@ -611,9 +611,9 @@ static void visitFunctionCallArguments(IndirectLocalPath &Path, Expr *Call, } } - for (unsigned I = 0, -N = std::min(Callee->getNumParams(), Args.size()); - I != N; ++I) { + const FunctionDecl *CanonCallee = Callee->getCanonicalDecl(); + unsigned NP = std::min(Callee->getNumParams(), CanonCallee->getNumParams()); + for (unsigned I = 0, N = std::min(NP, Args.size()); I != N; ++I) { Expr *Arg = Args[I]; RevertToOldSizeRAII RAII(Path); if (auto *DAE = dyn_cast(Arg)) { @@ -621,12 +621,13 @@ static void visitFunctionCallArguments(IndirectLocalPath &Path, Expr *Call, {IndirectLocalPathEntry::DefaultArg, DAE, DAE->getParam()}); Arg = DAE->getExpr(); } -if (CheckCoroCall || Callee->getParamDecl(I)->hasAttr()) - VisitLifetimeBoundArg(Callee->getParamDecl(I), Arg); +if (CheckCoroCall || +CanonCallee->getParamDecl(I)->hasAttr()) + VisitLifetimeBoundArg(CanonCallee->getParamDecl(I), Arg); else if (EnableGSLAnalysis && I == 0) { // Perform GSL analysis for the first argument - if (shouldTrackFirstArgument(Callee)) { -VisitGSLPointerArg(Callee, Arg); + if (shouldTrackFirstArgument(CanonCallee)) { +VisitGSLPointerArg(CanonCallee, Arg); } else if (auto *Ctor = dyn_cast(Call); Ctor && shouldTrackFirstArgumentForConstructor(Ctor)) { VisitGSLPointerArg(Ctor->getConstructor(), Arg); diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp index 716d8ed1fae4f8..754f36fa03f1d1 100644 --- a/clang/lib/Sema/SemaAttr.cpp +++ b/clang/lib/Sema/SemaAttr.cpp @@ -217,7 +217,8 @@ void Sema::inferGslOwnerPointerAttribute(CXXRecordDecl *Record) { } void Sema::inferLifetimeBoundAttribute(FunctionDecl *FD) { - if (FD->getNumParams() == 0) + unsigned NumParams = FD->getNumParams(); + if (NumParams == 0) return; if (unsigned BuiltinID = FD->getBuiltinID()) { @@ -239,18 +240,13 @@ void Sema::inferLifetimeBoundAttribute(FunctionDecl *FD) { default: break; } -return; - } - if (auto *CMD = dyn_cast(FD)) { -const auto *CRD = CMD->getParent(); -if (!CRD->isInStdNamespace() || !CRD->getIdentifier()) - return; - -if (isa(CMD)) { + } else if (auto *CMD = dyn_cast(FD)) { +const CXXRecordDecl *CRD = CMD->getParent(); +if (CRD->isInStdNamespace() && CRD->getIdentifier() && +isa(CMD)) { auto *Param = CMD->getParamDecl(0); - if (Param->hasAttr()) -return; - if (CRD->getName() == "basic_string_view" && + if (!Param->hasAttr() && + CRD->getName() == "basic_string_view" && Param->getType()->isPointerType()) { // construct from a char array pointed by a pointer. // basic_string_view(const CharT* s); @@ -266,6 +262,20 @@ void Sema::inferLifetimeBoundAttribute(FunctionDecl *FD) { LifetimeBoundAttr::CreateImplicit(Context, FD->getLocation())); } } + } else if (auto *CanonDecl = FD->getCanonicalDecl(); FD != CanonDecl) { +// Propagate the lifetimebound attribute from parameters to the canonical +// declaration. +// Note that this doesn't include the implicit 'this' parameter, as the +// attribute is applied to the function type in that case. +unsigned NP = std::min(NumParams, CanonDecl->getNumParams()); +for (unsigned I = 0; I < NP; ++I) { + auto *CanonParam = CanonDecl->getParamDecl(I); + if (!CanonParam->hasAttr() && + FD->getParamDecl(I)->hasAttr()) { +CanonParam->addAttr(LifetimeBoundAttr::CreateImplicit( +Context, CanonParam->getLocation())); + } +} } } diff --git a/clang/test/SemaCXX/attr-lifetimebound.cpp b/clang/test/SemaCXX/attr-lifetimebound.cpp index f89b556f5bba08..c4a4e5415252e7 100644 --- a/clang/test/SemaCXX/attr-lifetimebound.cpp +++ b/clang/test/SemaCXX/attr-lifetimebound.cpp @@ -19,6 +19,10 @@ namespace usage_invalid { namespace usage_ok { struct IntRef
[clang-tools-extra] [clang-tidy] fix false positive in bugprone-return-const-ref-from-parameter (PR #117734)
https://github.com/PiotrZSL requested changes to this pull request. Please add positive test for lambdas. https://github.com/llvm/llvm-project/pull/117734 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LoongArch] Support LA V1.1 feature that div.w[u] and mod.w[u] instructions with inputs not signed-extended. (PR #116764)
https://github.com/SixWeining approved this pull request. https://github.com/llvm/llvm-project/pull/116764 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Emit stub version of OpenCL Kernel (PR #115821)
shiltian wrote: Yes, that's the idea. In that way, we will not have any function call to a `amdgpu_kernel`. https://github.com/llvm/llvm-project/pull/115821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [PAC][ELF][AArch64] Support signed personality function pointer (PR #113148)
kovdan01 wrote: Would be glad to see everyone's feedback on the changes. https://github.com/llvm/llvm-project/pull/113148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Emit stub version of OpenCL Kernel (PR #115821)
@@ -126,3 +137,19 @@ void use() { // FVIS-DEFAULT: declare void @ext_func_default() // FVIS-PROTECTED: declare void @ext_func_default() // FVIS-HIDDEN: declare void @ext_func_default() + +// FVIS-DEFAULT: define{{.*}} void @__clang_ocl_kern_imp_kern() +// FVIS-PROTECTED: define protected void @__clang_ocl_kern_imp_kern() +// FVIS-HIDDEN: define protected void @__clang_ocl_kern_imp_kern() + +// FVIS-DEFAULT: define protected void @__clang_ocl_kern_imp_kern_hidden() +// FVIS-PROTECTED: define protected void @__clang_ocl_kern_imp_kern_hidden() +// FVIS-HIDDEN: define protected void @__clang_ocl_kern_imp_kern_hidden() + +// FVIS-DEFAULT: define protected void @__clang_ocl_kern_imp_kern_protected() +// FVIS-PROTECTED: define protected void @__clang_ocl_kern_imp_kern_protected() +// FVIS-HIDDEN: define protected void @__clang_ocl_kern_imp_kern_protected() + +// FVIS-DEFAULT: define{{.*}} void @__clang_ocl_kern_imp_kern_default() +// FVIS-PROTECTED: define{{.*}} void @__clang_ocl_kern_imp_kern_default() +// FVIS-HIDDEN: define{{.*}} void @__clang_ocl_kern_imp_kern_default() jhuber6 wrote: Fix https://github.com/llvm/llvm-project/pull/115821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] skip consumed analysis for consteval conditions in control-flow terminators (PR #117403)
a-tarasyuk wrote: @cor3ntin Thanks for there feedback. I've added release notes and updated the description. @AaronBallman could you review these changes? https://github.com/llvm/llvm-project/pull/117403 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Emit stub version of OpenCL Kernel (PR #115821)
@@ -0,0 +1,43 @@ +// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -emit-llvm -o - %s | FileCheck %s shiltian wrote: I think we really need to force auto generate to make (other's) future life much easier. https://github.com/llvm/llvm-project/pull/115821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [flang] Preserve fixed form in fc1 -x value (PR #117563)
tarunprabhu wrote: ``` if ( (a .eq. 0) .and.(b. eq. 1)) then ``` It seems like something in [9fb2db1](https://github.com/llvm/llvm-project/commit/9fb2db1e1f42ae10a9d8c1d9410b5f4e719fdac0) has caused a space to appear between `.` and `eq`. Should we be looking at what that commit did more closely or am I missing something obvious? (alas, it wouldn't surprise me if I was) https://github.com/llvm/llvm-project/pull/117563 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [AArch64][SVE] Change the immediate argument in svextq (PR #115340)
https://github.com/SpencerAbson updated https://github.com/llvm/llvm-project/pull/115340 >From bac0e8b46c284b17f04a68d95b87e8b8bf28f438 Mon Sep 17 00:00:00 2001 From: Spencer Abson Date: Thu, 7 Nov 2024 11:44:27 + Subject: [PATCH] [AArch64][SVE] Fix the immediate argument in svextq The meaning of the immediate argument in svextq should be tied to the element size of its operands. For example: svextq_f64(zn_f64, zm_f64, 1) would, for each 128-bit segment of zn_f64, concatenate the highest 15 bytes of this segment with the first byte of the corresponding segment of zm_f64. The intuitive behavior of svextq_f64(zn_f64, zm_f64, 1) is to concatenate the higher doubleword of zn_f64 with the lower doubleword of zm_f64. The range of the immediate argument in svextq has been modified such that it is: - [0,15] for svextq_{s8,u8} - [0,7] for svextq_{s16,u16,f16,bf16} - [0,3] for svextq_{s32,u32,f32} - [0,1] for svextq_{s64,u64,f64} --- clang/include/clang/Basic/arm_sve.td | 2 +- .../sve2p1-intrinsics/acle_sve2p1_extq.c | 42 +- .../acle_sve2p1_imm.cpp | 44 +-- .../lib/Target/AArch64/AArch64InstrFormats.td | 33 ++ llvm/lib/Target/AArch64/SVEInstrFormats.td| 17 --- .../CodeGen/AArch64/sve2p1-intrinsics-extq.ll | 28 ++-- 6 files changed, 118 insertions(+), 48 deletions(-) diff --git a/clang/include/clang/Basic/arm_sve.td b/clang/include/clang/Basic/arm_sve.td index d492fae4145b92..c6b7cd637b9ece 100644 --- a/clang/include/clang/Basic/arm_sve.td +++ b/clang/include/clang/Basic/arm_sve.td @@ -2286,7 +2286,7 @@ let SVETargetGuard = "sve2p1", SMETargetGuard = InvalidMode in { def SVTBLQ : SInst<"svtblq[_{d}]", "ddu", "cUcsUsiUilUlbhfd", MergeNone, "aarch64_sve_tblq">; def SVTBXQ : SInst<"svtbxq[_{d}]", "dddu", "cUcsUsiUilUlbhfd", MergeNone, "aarch64_sve_tbxq">; // EXTQ - def EXTQ : SInst<"svextq[_{d}]", "dddk", "cUcsUsiUilUlbhfd", MergeNone, "aarch64_sve_extq", [], [ImmCheck<2, ImmCheck0_15>]>; + def EXTQ : SInst<"svextq[_{d}]", "dddk", "cUcsUsiUilUlbhfd", MergeNone, "aarch64_sve_extq", [], [ImmCheck<2, ImmCheckLaneIndex, 0>]>; // PMOV // Move to Pred diff --git a/clang/test/CodeGen/AArch64/sve2p1-intrinsics/acle_sve2p1_extq.c b/clang/test/CodeGen/AArch64/sve2p1-intrinsics/acle_sve2p1_extq.c index 5fbfa881500ba1..06eec1e00900cc 100644 --- a/clang/test/CodeGen/AArch64/sve2p1-intrinsics/acle_sve2p1_extq.c +++ b/clang/test/CodeGen/AArch64/sve2p1-intrinsics/acle_sve2p1_extq.c @@ -103,111 +103,111 @@ svuint32_t test_svextq_u32(svuint32_t zn, svuint32_t zm) { // CHECK-LABEL: define dso_local @test_svextq_s32 // CHECK-SAME: ( [[ZN:%.*]], [[ZM:%.*]]) #[[ATTR0]] { // CHECK-NEXT: entry: -// CHECK-NEXT:[[TMP0:%.*]] = tail call @llvm.aarch64.sve.extq.nxv4i32( [[ZN]], [[ZM]], i32 6) +// CHECK-NEXT:[[TMP0:%.*]] = tail call @llvm.aarch64.sve.extq.nxv4i32( [[ZN]], [[ZM]], i32 3) // CHECK-NEXT:ret [[TMP0]] // // CPP-CHECK-LABEL: define dso_local @_Z15test_svextq_s32u11__SVInt32_tS_ // CPP-CHECK-SAME: ( [[ZN:%.*]], [[ZM:%.*]]) #[[ATTR0]] { // CPP-CHECK-NEXT: entry: -// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call @llvm.aarch64.sve.extq.nxv4i32( [[ZN]], [[ZM]], i32 6) +// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call @llvm.aarch64.sve.extq.nxv4i32( [[ZN]], [[ZM]], i32 3) // CPP-CHECK-NEXT:ret [[TMP0]] // svint32_t test_svextq_s32(svint32_t zn, svint32_t zm) { -return SVE_ACLE_FUNC(svextq, _s32,,)(zn, zm, 6); +return SVE_ACLE_FUNC(svextq, _s32,,)(zn, zm, 3); } // CHECK-LABEL: define dso_local @test_svextq_u64 // CHECK-SAME: ( [[ZN:%.*]], [[ZM:%.*]]) #[[ATTR0]] { // CHECK-NEXT: entry: -// CHECK-NEXT:[[TMP0:%.*]] = tail call @llvm.aarch64.sve.extq.nxv2i64( [[ZN]], [[ZM]], i32 3) +// CHECK-NEXT:[[TMP0:%.*]] = tail call @llvm.aarch64.sve.extq.nxv2i64( [[ZN]], [[ZM]], i32 1) // CHECK-NEXT:ret [[TMP0]] // // CPP-CHECK-LABEL: define dso_local @_Z15test_svextq_u64u12__SVUint64_tS_ // CPP-CHECK-SAME: ( [[ZN:%.*]], [[ZM:%.*]]) #[[ATTR0]] { // CPP-CHECK-NEXT: entry: -// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call @llvm.aarch64.sve.extq.nxv2i64( [[ZN]], [[ZM]], i32 3) +// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call @llvm.aarch64.sve.extq.nxv2i64( [[ZN]], [[ZM]], i32 1) // CPP-CHECK-NEXT:ret [[TMP0]] // svuint64_t test_svextq_u64(svuint64_t zn, svuint64_t zm) { - return SVE_ACLE_FUNC(svextq, _u64,,)(zn, zm, 3); + return SVE_ACLE_FUNC(svextq, _u64,,)(zn, zm, 1); } // CHECK-LABEL: define dso_local @test_svextq_s64 // CHECK-SAME: ( [[ZN:%.*]], [[ZM:%.*]]) #[[ATTR0]] { // CHECK-NEXT: entry: -// CHECK-NEXT:[[TMP0:%.*]] = tail call @llvm.aarch64.sve.extq.nxv2i64( [[ZN]], [[ZM]], i32 7) +// CHECK-NEXT:[[TMP0:%.*]] = tail call @llvm.aarch64.sve.extq.nxv2i64( [[ZN]], [[ZM]], i32 0) // CHECK-NEXT:ret [[TMP0]] // // CPP-CHECK-LABEL: define dso_local @_Z15test_svextq_s64u11
[clang] [clang] Avoid re-evaluating field bitwidth (PR #117732)
https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/117732 >From 6a1c51fd8b6b1d04294eaac65b261bedb451f22b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Tue, 26 Nov 2024 13:10:33 +0100 Subject: [PATCH] [clang] Avoid re-evaluating field bitwidth --- clang/include/clang/AST/Decl.h| 26 +++- clang/include/clang/AST/DeclObjC.h| 34 - clang/include/clang/Sema/Sema.h | 2 +- clang/lib/AST/ASTContext.cpp | 83 +--- clang/lib/AST/ASTImporter.cpp | 2 +- clang/lib/AST/Decl.cpp| 23 +++- clang/lib/AST/DeclObjC.cpp| 34 +++-- clang/lib/CodeGen/CGObjCMac.cpp | 14 +- clang/lib/CodeGen/CGOpenMPRuntime.cpp | 3 +- clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp | 6 +- clang/lib/CodeGen/CodeGenModule.cpp | 12 +- .../Frontend/Rewrite/RewriteModernObjC.cpp| 122 +++--- clang/lib/Frontend/Rewrite/RewriteObjC.cpp| 52 +++- clang/lib/Sema/HLSLExternalSemaSource.cpp | 6 +- clang/lib/Sema/SemaDecl.cpp | 71 +- clang/lib/Sema/SemaDeclObjC.cpp | 23 ++-- clang/lib/Sema/SemaLambda.cpp | 2 +- 17 files changed, 259 insertions(+), 256 deletions(-) diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h index 8c39ef3d5a9fa6..db3c86a09bfb49 100644 --- a/clang/include/clang/AST/Decl.h +++ b/clang/include/clang/AST/Decl.h @@ -3089,17 +3089,27 @@ class FieldDecl : public DeclaratorDecl, public Mergeable { // Active member if ISK is ISK_CapturedVLAType. const VariableArrayType *CapturedVLAType; }; + unsigned BitWidthValue = 0; protected: FieldDecl(Kind DK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, -TypeSourceInfo *TInfo, Expr *BW, bool Mutable, -InClassInitStyle InitStyle) +TypeSourceInfo *TInfo, bool Mutable, InClassInitStyle InitStyle) + : DeclaratorDecl(DK, DC, IdLoc, Id, T, TInfo, StartLoc), BitField(false), +Mutable(Mutable), StorageKind((InitStorageKind)InitStyle), +CachedFieldIndex(0), Init() {} + + FieldDecl(Kind DK, DeclContext *DC, SourceLocation StartLoc, +SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, +TypeSourceInfo *TInfo, Expr *BW, unsigned BitWidthValue, +bool Mutable, InClassInitStyle InitStyle) : DeclaratorDecl(DK, DC, IdLoc, Id, T, TInfo, StartLoc), BitField(false), Mutable(Mutable), StorageKind((InitStorageKind)InitStyle), CachedFieldIndex(0), Init() { -if (BW) +if (BW) { setBitWidth(BW); + this->BitWidthValue = BitWidthValue; +} } public: @@ -3109,7 +3119,15 @@ class FieldDecl : public DeclaratorDecl, public Mergeable { static FieldDecl *Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, - TypeSourceInfo *TInfo, Expr *BW, bool Mutable, + TypeSourceInfo *TInfo, Expr *BW, + unsigned BitWidthValue, bool Mutable, + InClassInitStyle InitStyle); + + /// For non-bit-fields. + static FieldDecl *Create(const ASTContext &C, DeclContext *DC, + SourceLocation StartLoc, SourceLocation IdLoc, + const IdentifierInfo *Id, QualType T, + TypeSourceInfo *TInfo, bool Mutable, InClassInitStyle InitStyle); static FieldDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID); diff --git a/clang/include/clang/AST/DeclObjC.h b/clang/include/clang/AST/DeclObjC.h index 4663603f797545..17bccfda784fed 100644 --- a/clang/include/clang/AST/DeclObjC.h +++ b/clang/include/clang/AST/DeclObjC.h @@ -1960,8 +1960,15 @@ class ObjCIvarDecl : public FieldDecl { ObjCIvarDecl(ObjCContainerDecl *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, AccessControl ac, Expr *BW, - bool synthesized) - : FieldDecl(ObjCIvar, DC, StartLoc, IdLoc, Id, T, TInfo, BW, + unsigned BWValue, bool synthesized) + : FieldDecl(ObjCIvar, DC, StartLoc, IdLoc, Id, T, TInfo, BW, BWValue, + /*Mutable=*/false, /*HasInit=*/ICIS_NoInit), +DeclAccess(ac), Synthesized(synthesized) {} + + ObjCIvarDecl(ObjCContainerDecl *DC, SourceLocation StartLoc, + SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, + TypeSourceInfo *TInfo, AccessControl ac, bool synthesized) + : FieldDecl(ObjCIvar, DC, StartLoc, IdLoc, Id, T, TInfo, /*Mutable=*/false,
[clang-tools-extra] [clang-tidy] fix false positive in bugprone-return-const-ref-from-parameter (PR #117734)
https://github.com/jcsxky created https://github.com/llvm/llvm-project/pull/117734 Fix https://github.com/llvm/llvm-project/issues/115743 >From 37a518b35b205e3e2e7bfbeab64d2a334519c30d Mon Sep 17 00:00:00 2001 From: Qizhi Hu <836744...@qq.com> Date: Wed, 27 Nov 2024 00:22:05 +0800 Subject: [PATCH] [clang-tidy] fix false positive in bugprone-return-const-ref-from-parameter --- .../bugprone/ReturnConstRefFromParameterCheck.cpp | 4 ++-- clang-tools-extra/docs/ReleaseNotes.rst | 4 .../checkers/bugprone/return-const-ref-from-parameter.cpp | 6 ++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp index adb26ade955c5e..874f35f055094e 100644 --- a/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp @@ -21,10 +21,10 @@ void ReturnConstRefFromParameterCheck::registerMatchers(MatchFinder *Finder) { to(parmVarDecl(hasType(hasCanonicalType( qualType(lValueReferenceType(pointee( qualType(isConstQualified() - .bind("type" + .bind("type"))), parmVarDecl(hasDeclContext(functionDecl().bind("owner" .bind("param", hasAncestor( - functionDecl(hasReturnTypeLoc(loc(qualType( + functionDecl(equalsBoundNode("owner"), hasReturnTypeLoc(loc(qualType( hasCanonicalType(equalsBoundNode("type")) .bind("func"))) .bind("ret"), diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index b72d109b3d3938..9c3a5e4f40f930 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -104,6 +104,10 @@ New check aliases Changes in existing checks ^^ +- Improved :doc:`bugprone-return-const-ref-from-parameter + ` check by no longer + giving false positives for lambda. + - Improved :doc:`readability-redundant-smartptr-get ` check to remove `->`, when reduntant `get()` is removed. diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/return-const-ref-from-parameter.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/return-const-ref-from-parameter.cpp index d13c127da7c2a1..391e8f96401ab4 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/return-const-ref-from-parameter.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/return-const-ref-from-parameter.cpp @@ -142,6 +142,12 @@ void instantiate(const int ¶m, const float ¶mf, int &mut_param, float &m itf6(mut_paramf); } +template +void f(const T& t) { +const auto get = [&t] -> const T& { return t; }; +return T{}; +} + } // namespace valid namespace overload { ___ 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 false positive in bugprone-return-const-ref-from-parameter (PR #117734)
llvmbot wrote: @llvm/pr-subscribers-clang-tidy Author: Qizhi Hu (jcsxky) Changes Fix https://github.com/llvm/llvm-project/issues/115743 --- Full diff: https://github.com/llvm/llvm-project/pull/117734.diff 3 Files Affected: - (modified) clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp (+2-2) - (modified) clang-tools-extra/docs/ReleaseNotes.rst (+4) - (modified) clang-tools-extra/test/clang-tidy/checkers/bugprone/return-const-ref-from-parameter.cpp (+6) ``diff diff --git a/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp index adb26ade955c5e..874f35f055094e 100644 --- a/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp @@ -21,10 +21,10 @@ void ReturnConstRefFromParameterCheck::registerMatchers(MatchFinder *Finder) { to(parmVarDecl(hasType(hasCanonicalType( qualType(lValueReferenceType(pointee( qualType(isConstQualified() - .bind("type" + .bind("type"))), parmVarDecl(hasDeclContext(functionDecl().bind("owner" .bind("param", hasAncestor( - functionDecl(hasReturnTypeLoc(loc(qualType( + functionDecl(equalsBoundNode("owner"), hasReturnTypeLoc(loc(qualType( hasCanonicalType(equalsBoundNode("type")) .bind("func"))) .bind("ret"), diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index b72d109b3d3938..9c3a5e4f40f930 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -104,6 +104,10 @@ New check aliases Changes in existing checks ^^ +- Improved :doc:`bugprone-return-const-ref-from-parameter + ` check by no longer + giving false positives for lambda. + - Improved :doc:`readability-redundant-smartptr-get ` check to remove `->`, when reduntant `get()` is removed. diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/return-const-ref-from-parameter.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/return-const-ref-from-parameter.cpp index d13c127da7c2a1..391e8f96401ab4 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/return-const-ref-from-parameter.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/return-const-ref-from-parameter.cpp @@ -142,6 +142,12 @@ void instantiate(const int ¶m, const float ¶mf, int &mut_param, float &m itf6(mut_paramf); } +template +void f(const T& t) { +const auto get = [&t] -> const T& { return t; }; +return T{}; +} + } // namespace valid namespace overload { `` https://github.com/llvm/llvm-project/pull/117734 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Fix name lookup for dependent bases (PR #114978)
erichkeane wrote: Hmm, that compile time regression is unfortunate. @vbe-sc as a part of your next version of this patch, can you do some sort of analysis why this would result in further lookups/instantiation/etc? I could comprehend that perhaps we're skipping the 'current instantiation' now for these bases so now there is more work to do in instantiations (of which there are more of those than the base, sort of out of necessity), but would like some sort of analysis/confirmation that is the case/what is happening in some of those 'worst' comparisons. https://github.com/llvm/llvm-project/pull/114978 ___ 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 false positive in bugprone-return-const-ref-from-parameter (PR #117734)
EugeneZelenko wrote: Please rebase from current `main`. https://github.com/llvm/llvm-project/pull/117734 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64]Refactor typespec handling in SveEmitter.cpp (PR #117717)
https://github.com/SpencerAbson edited https://github.com/llvm/llvm-project/pull/117717 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][AArch64]Refactor typespec handling in SveEmitter.cpp (PR #117717)
https://github.com/SpencerAbson updated https://github.com/llvm/llvm-project/pull/117717 >From eac5704250a454ede434d4967fb88902b689fce3 Mon Sep 17 00:00:00 2001 From: Spencer Abson Date: Tue, 26 Nov 2024 13:49:12 + Subject: [PATCH 1/2] Refactor parts of SveEmitter.cpp --- clang/include/clang/Basic/arm_sve.td | 28 +-- clang/utils/TableGen/SveEmitter.cpp | 356 --- 2 files changed, 167 insertions(+), 217 deletions(-) diff --git a/clang/include/clang/Basic/arm_sve.td b/clang/include/clang/Basic/arm_sve.td index d492fae4145b92..3e4eb55213c39e 100644 --- a/clang/include/clang/Basic/arm_sve.td +++ b/clang/include/clang/Basic/arm_sve.td @@ -762,14 +762,14 @@ def SVCMPLS_WIDE_N : SInst<"svcmple_wide[_n_{d}]", "PPdj", "UcUsUi", MergeNone, // While comparisons -def SVWHILELE_S32 : SInst<"svwhilele_{d}[_{1}]", "Pkk", "PcPsPiPl", MergeNone, "aarch64_sve_whilele", [IsOverloadWhileOrMultiVecCvt, VerifyRuntimeMode]>; -def SVWHILELE_S64 : SInst<"svwhilele_{d}[_{1}]", "Pll", "PcPsPiPl", MergeNone, "aarch64_sve_whilele", [IsOverloadWhileOrMultiVecCvt, VerifyRuntimeMode]>; -def SVWHILELO_U32 : SInst<"svwhilelt_{d}[_{1}]", "Pmm", "PUcPUsPUiPUl", MergeNone, "aarch64_sve_whilelo", [IsOverloadWhileOrMultiVecCvt, VerifyRuntimeMode]>; -def SVWHILELO_U64 : SInst<"svwhilelt_{d}[_{1}]", "Pnn", "PUcPUsPUiPUl", MergeNone, "aarch64_sve_whilelo", [IsOverloadWhileOrMultiVecCvt, VerifyRuntimeMode]>; -def SVWHILELS_U32 : SInst<"svwhilele_{d}[_{1}]", "Pmm", "PUcPUsPUiPUl", MergeNone, "aarch64_sve_whilels", [IsOverloadWhileOrMultiVecCvt, VerifyRuntimeMode]>; -def SVWHILELS_U64 : SInst<"svwhilele_{d}[_{1}]", "Pnn", "PUcPUsPUiPUl", MergeNone, "aarch64_sve_whilels", [IsOverloadWhileOrMultiVecCvt, VerifyRuntimeMode]>; -def SVWHILELT_S32 : SInst<"svwhilelt_{d}[_{1}]", "Pkk", "PcPsPiPl", MergeNone, "aarch64_sve_whilelt", [IsOverloadWhileOrMultiVecCvt, VerifyRuntimeMode]>; -def SVWHILELT_S64 : SInst<"svwhilelt_{d}[_{1}]", "Pll", "PcPsPiPl", MergeNone, "aarch64_sve_whilelt", [IsOverloadWhileOrMultiVecCvt, VerifyRuntimeMode]>; +def SVWHILELE_S32 : SInst<"svwhilele_{d}[_{1}]", "Pkk", "PcPsPiPl", MergeNone, "aarch64_sve_whilele", [IsOverloadWhileOrMultiVecCvt, VerifyRuntimeMode]>; +def SVWHILELE_S64 : SInst<"svwhilele_{d}[_{1}]", "Pll", "PcPsPiPl", MergeNone, "aarch64_sve_whilele", [IsOverloadWhileOrMultiVecCvt, VerifyRuntimeMode]>; +def SVWHILELO_U32 : SInst<"svwhilelt_{d}[_{1}]", "Pmm", "PcPsPiPl", MergeNone, "aarch64_sve_whilelo", [IsOverloadWhileOrMultiVecCvt, VerifyRuntimeMode]>; +def SVWHILELO_U64 : SInst<"svwhilelt_{d}[_{1}]", "Pnn", "PcPsPiPl", MergeNone, "aarch64_sve_whilelo", [IsOverloadWhileOrMultiVecCvt, VerifyRuntimeMode]>; +def SVWHILELS_U32 : SInst<"svwhilele_{d}[_{1}]", "Pmm", "PcPsPiPl", MergeNone, "aarch64_sve_whilels", [IsOverloadWhileOrMultiVecCvt, VerifyRuntimeMode]>; +def SVWHILELS_U64 : SInst<"svwhilele_{d}[_{1}]", "Pnn", "PcPsPiPl", MergeNone, "aarch64_sve_whilels", [IsOverloadWhileOrMultiVecCvt, VerifyRuntimeMode]>; +def SVWHILELT_S32 : SInst<"svwhilelt_{d}[_{1}]", "Pkk", "PcPsPiPl", MergeNone, "aarch64_sve_whilelt", [IsOverloadWhileOrMultiVecCvt, VerifyRuntimeMode]>; +def SVWHILELT_S64 : SInst<"svwhilelt_{d}[_{1}]", "Pll", "PcPsPiPl", MergeNone, "aarch64_sve_whilelt", [IsOverloadWhileOrMultiVecCvt, VerifyRuntimeMode]>; // Counting bit @@ -1365,10 +1365,10 @@ def SVWHILEGE_S32 : SInst<"svwhilege_{d}[_{1}]", "Pkk", "PcPsPiPl", MergeNon def SVWHILEGE_S64 : SInst<"svwhilege_{d}[_{1}]", "Pll", "PcPsPiPl", MergeNone, "aarch64_sve_whilege", [IsOverloadWhileOrMultiVecCvt, VerifyRuntimeMode]>; def SVWHILEGT_S32 : SInst<"svwhilegt_{d}[_{1}]", "Pkk", "PcPsPiPl", MergeNone, "aarch64_sve_whilegt", [IsOverloadWhileOrMultiVecCvt, VerifyRuntimeMode]>; def SVWHILEGT_S64 : SInst<"svwhilegt_{d}[_{1}]", "Pll", "PcPsPiPl", MergeNone, "aarch64_sve_whilegt", [IsOverloadWhileOrMultiVecCvt, VerifyRuntimeMode]>; -def SVWHILEHI_U32 : SInst<"svwhilegt_{d}[_{1}]", "Pmm", "PUcPUsPUiPUl", MergeNone, "aarch64_sve_whilehi", [IsOverloadWhileOrMultiVecCvt, VerifyRuntimeMode]>; -def SVWHILEHI_U64 : SInst<"svwhilegt_{d}[_{1}]", "Pnn", "PUcPUsPUiPUl", MergeNone, "aarch64_sve_whilehi", [IsOverloadWhileOrMultiVecCvt, VerifyRuntimeMode]>; -def SVWHILEHS_U32 : SInst<"svwhilege_{d}[_{1}]", "Pmm", "PUcPUsPUiPUl", MergeNone, "aarch64_sve_whilehs", [IsOverloadWhileOrMultiVecCvt, VerifyRuntimeMode]>; -def SVWHILEHS_U64 : SInst<"svwhilege_{d}[_{1}]", "Pnn", "PUcPUsPUiPUl", MergeNone, "aarch64_sve_whilehs", [IsOverloadWhileOrMultiVecCvt, VerifyRuntimeMode]>; +def SVWHILEHI_U32 : SInst<"svwhilegt_{d}[_{1}]", "Pmm", "PcPsPiPl", MergeNone, "aarch64_sve_whilehi", [IsOverloadWhileOrMultiVecCvt, VerifyRuntimeMode]>; +def SVWHILEHI_U64 : SInst<"svwhilegt_{d}[_{1}]", "Pnn", "PcPsPiPl", MergeNone, "aar
[clang] [SYCL] Change SYCL version according to standard (PR #114790)
https://github.com/gmlueck approved this pull request. https://github.com/llvm/llvm-project/pull/114790 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Move warning about memset/memcpy to NonTriviallyCopyable type… (PR #117387)
https://github.com/AaronBallman edited https://github.com/llvm/llvm-project/pull/117387 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Add `Increment`/`DecrementCounter` methods to structured buffers (PR #117608)
llvmbot wrote: @llvm/pr-subscribers-hlsl Author: Helena Kotas (hekota) Changes Introduces `__builtin_hlsl_buffer_update_counter` clang buildin that is used to implement the `IncrementCounter` and `DecrementCounter` methods on `RWStructuredBuffer` and `RasterizerOrderedStructuredBuffer` (see Note). The builtin is translated to LLVM intrisic `llvm.dx.bufferUpdateCounter` or `llvm.spv.bufferUpdateCounter`. Introduces `BuiltinTypeMethodBuilder` helper in `HLSLExternalSemaSource` that enables adding methods to builtin types using builder pattern like this: ``` BuiltinTypeMethodBuilder(Sema, RecordBuilder, "MethodName", ReturnType) .addParam("param_name", Type, InOutModifier) .callBuiltin("buildin_name", { BuiltinParams }) .finalizeMethod(); ``` Fixes #113513 [First version](llvm/llvm-project#114148) of this PR was reverted because of build break. --- Patch is 46.65 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/117608.diff 15 Files Affected: - (modified) clang/include/clang/Basic/Builtins.td (+6-1) - (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+6) - (modified) clang/lib/CodeGen/CGBuiltin.cpp (+9) - (modified) clang/lib/CodeGen/CGHLSLRuntime.h (+1) - (modified) clang/lib/Sema/HLSLExternalSemaSource.cpp (+321-93) - (modified) clang/lib/Sema/SemaExpr.cpp (+3) - (modified) clang/lib/Sema/SemaHLSL.cpp (+54) - (modified) clang/test/AST/HLSL/RWStructuredBuffer-AST.hlsl (+26) - (added) clang/test/CodeGenHLSL/builtins/StructuredBuffers-methods-lib.hlsl (+25) - (added) clang/test/CodeGenHLSL/builtins/StructuredBuffers-methods-ps.hlsl (+28) - (added) clang/test/SemaHLSL/BuiltIns/buffer_update_counter-errors.hlsl (+48) - (modified) llvm/include/llvm/IR/IntrinsicsDirectX.td (+1-1) - (modified) llvm/include/llvm/IR/IntrinsicsSPIRV.td (+5) - (modified) llvm/lib/Target/DirectX/DXILOpLowering.cpp (+1-1) - (renamed) llvm/test/CodeGen/DirectX/bufferUpdateCounter.ll (+3-3) ``diff diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 83c90b3d6e681b..eaff744924805e 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -4882,7 +4882,6 @@ def HLSLSaturate : LangBuiltin<"HLSL_LANG"> { let Prototype = "void(...)"; } - def HLSLSelect : LangBuiltin<"HLSL_LANG"> { let Spellings = ["__builtin_hlsl_select"]; let Attributes = [NoThrow, Const]; @@ -4907,6 +4906,12 @@ def HLSLRadians : LangBuiltin<"HLSL_LANG"> { let Prototype = "void(...)"; } +def HLSLBufferUpdateCounter : LangBuiltin<"HLSL_LANG"> { + let Spellings = ["__builtin_hlsl_buffer_update_counter"]; + let Attributes = [NoThrow]; + let Prototype = "uint32_t(...)"; +} + def HLSLSplitDouble: LangBuiltin<"HLSL_LANG"> { let Spellings = ["__builtin_hlsl_elementwise_splitdouble"]; let Attributes = [NoThrow, Const]; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 6ff24c2bc8faad..834e588c18e376 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -7287,6 +7287,8 @@ def err_typecheck_illegal_increment_decrement : Error< "cannot %select{decrement|increment}1 value of type %0">; def err_typecheck_expect_int : Error< "used type %0 where integer is required">; +def err_typecheck_expect_hlsl_resource : Error< + "used type %0 where __hlsl_resource_t is required">; def err_typecheck_arithmetic_incomplete_or_sizeless_type : Error< "arithmetic on a pointer to %select{an incomplete|sizeless}0 type %1">; def err_typecheck_pointer_arith_function_type : Error< @@ -12528,6 +12530,10 @@ def warn_attr_min_eq_max: Warning< def err_hlsl_attribute_number_arguments_insufficient_shader_model: Error< "attribute %0 with %1 arguments requires shader model %2 or greater">; +def err_hlsl_expect_arg_const_int_one_or_neg_one: Error< + "argument %0 must be constant integer 1 or -1">; +def err_invalid_hlsl_resource_type: Error< + "invalid __hlsl_resource_t type attributes">; // Layout randomization diagnostics. def err_non_designated_init_used : Error< diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 91b70b4fdf3d20..f32d5a2f43559a 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -19409,6 +19409,15 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: { CGM.getHLSLRuntime().getRadiansIntrinsic(), ArrayRef{Op0}, nullptr, "hlsl.radians"); } + case Builtin::BI__builtin_hlsl_buffer_update_counter: { +Value *ResHandle = EmitScalarExpr(E->getArg(0)); +Value *Offset = EmitScalarExpr(E->getArg(1)); +Value *OffsetI8 = Builder.CreateIntCast(Offset, Int8Ty, true); +return Builder.CreateIntrinsic( +/*ReturnType=*/Offset->getType(), +CGM.getHLSLRuntime().getBufferUpdateCounterIntrinsic(), +ArrayRe
[clang] [clang][sema] Add support and documentation for `__has_extension(c_fixed_enum)` (PR #117507)
https://github.com/AaronBallman edited https://github.com/llvm/llvm-project/pull/117507 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 78c7024 - [OpenACC] Implement 'present' for combined constructs.
Author: erichkeane Date: 2024-11-26T10:49:41-08:00 New Revision: 78c7024640a5b511685c445f554b7d985a7cf286 URL: https://github.com/llvm/llvm-project/commit/78c7024640a5b511685c445f554b7d985a7cf286 DIFF: https://github.com/llvm/llvm-project/commit/78c7024640a5b511685c445f554b7d985a7cf286.diff LOG: [OpenACC] Implement 'present' for combined constructs. This is another clause where the parsing does all the required enforcement besides the construct it appertains to, so this patch removes the restriction and adds sufficient test coverage for combined constructs. Added: clang/test/SemaOpenACC/combined-construct-present-ast.cpp clang/test/SemaOpenACC/combined-construct-present-clause.c clang/test/SemaOpenACC/combined-construct-present-clause.cpp Modified: clang/lib/Sema/SemaOpenACC.cpp clang/test/AST/ast-print-openacc-combined-construct.cpp clang/test/SemaOpenACC/combined-construct-auto_seq_independent-clauses.c clang/test/SemaOpenACC/combined-construct-default-clause.c Removed: diff --git a/clang/lib/Sema/SemaOpenACC.cpp b/clang/lib/Sema/SemaOpenACC.cpp index 76be9a2abf5e46..d146edeabab741 100644 --- a/clang/lib/Sema/SemaOpenACC.cpp +++ b/clang/lib/Sema/SemaOpenACC.cpp @@ -859,10 +859,11 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitNoCreateClause( OpenACCClause *SemaOpenACCClauseVisitor::VisitPresentClause( SemaOpenACC::OpenACCParsedClause &Clause) { - // Restrictions only properly implemented on 'compute' constructs, and - // 'compute' constructs are the only construct that can do anything with - // this yet, so skip/treat as unimplemented in this case. - if (!isOpenACCComputeDirectiveKind(Clause.getDirectiveKind())) + // Restrictions only properly implemented on 'compute'/'combined constructs, + // and 'compute'/'combined' constructs are the only construct that can do + // anything with this yet, so skip/treat as unimplemented in this case. + if (!isOpenACCComputeDirectiveKind(Clause.getDirectiveKind()) && + !isOpenACCCombinedDirectiveKind(Clause.getDirectiveKind())) return isNotImplemented(); // ActOnVar ensured that everything is a valid variable reference, so there // really isn't anything to do here. GCC does some duplicate-finding, though diff --git a/clang/test/AST/ast-print-openacc-combined-construct.cpp b/clang/test/AST/ast-print-openacc-combined-construct.cpp index 6885806584f3d1..e04c39ac9bc5be 100644 --- a/clang/test/AST/ast-print-openacc-combined-construct.cpp +++ b/clang/test/AST/ast-print-openacc-combined-construct.cpp @@ -122,4 +122,13 @@ void foo() { #pragma acc kernels loop async for(int i = 0;i<5;++i); +// CHECK: #pragma acc parallel loop present(i, array[1], array, array[1:2]) +#pragma acc parallel loop present(i, array[1], array, array[1:2]) + for(int i = 0;i<5;++i); +// CHECK: #pragma acc serial loop present(i, array[1], array, array[1:2]) +#pragma acc serial loop present(i, array[1], array, array[1:2]) + for(int i = 0;i<5;++i); +// CHECK: #pragma acc kernels loop present(i, array[1], array, array[1:2]) +#pragma acc kernels loop present(i, array[1], array, array[1:2]) + for(int i = 0;i<5;++i); } diff --git a/clang/test/SemaOpenACC/combined-construct-auto_seq_independent-clauses.c b/clang/test/SemaOpenACC/combined-construct-auto_seq_independent-clauses.c index a770020764d356..69f93a6c605156 100644 --- a/clang/test/SemaOpenACC/combined-construct-auto_seq_independent-clauses.c +++ b/clang/test/SemaOpenACC/combined-construct-auto_seq_independent-clauses.c @@ -111,8 +111,6 @@ void uses() { // expected-warning@+1{{OpenACC clause 'no_create' not yet implemented}} #pragma acc parallel loop auto no_create(Var) for(unsigned i = 0; i < 5; ++i); - // TODOexpected-error@+1{{OpenACC 'present' clause is not valid on 'parallel loop' directive}} - // expected-warning@+1{{OpenACC clause 'present' not yet implemented}} #pragma acc parallel loop auto present(Var) for(unsigned i = 0; i < 5; ++i); #pragma acc parallel loop auto private(Var) @@ -274,8 +272,6 @@ void uses() { // expected-warning@+1{{OpenACC clause 'no_create' not yet implemented}} #pragma acc parallel loop no_create(Var) auto for(unsigned i = 0; i < 5; ++i); - // TODOexpected-error@+1{{OpenACC 'present' clause is not valid on 'parallel loop' directive}} - // expected-warning@+1{{OpenACC clause 'present' not yet implemented}} #pragma acc parallel loop present(Var) auto for(unsigned i = 0; i < 5; ++i); #pragma acc parallel loop private(Var) auto @@ -438,8 +434,6 @@ void uses() { // expected-warning@+1{{OpenACC clause 'no_create' not yet implemented}} #pragma acc parallel loop independent no_create(Var) for(unsigned i = 0; i < 5; ++i); - // TODOexpected-error@+1{{OpenACC 'present' clause is not valid on 'parallel loop' directive}} - // expected-warning@+1{{OpenACC clause 'present' not yet implemented}} #pragma acc parallel loop i
[clang] [clang] Move warning about memset/memcpy to NonTriviallyCopyable type… (PR #117387)
https://github.com/AaronBallman edited https://github.com/llvm/llvm-project/pull/117387 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Move warning about memset/memcpy to NonTriviallyCopyable type… (PR #117387)
@@ -683,11 +683,13 @@ def SizeofArrayDecay : DiagGroup<"sizeof-array-decay">; def SizeofPointerMemaccess : DiagGroup<"sizeof-pointer-memaccess">; def MemsetTransposedArgs : DiagGroup<"memset-transposed-args">; def DynamicClassMemaccess : DiagGroup<"dynamic-class-memaccess">; -def NonTrivialMemaccess : DiagGroup<"nontrivial-memaccess">; +def NonTrivialMemcall : DiagGroup<"nontrivial-memcall">; +def NonTrivialMemaccess : DiagGroup<"nontrivial-memaccess", [NonTrivialMemcall]>; def SuspiciousBzero : DiagGroup<"suspicious-bzero">; def SuspiciousMemaccess : DiagGroup<"suspicious-memaccess", [SizeofPointerMemaccess, DynamicClassMemaccess, - NonTrivialMemaccess, MemsetTransposedArgs, SuspiciousBzero]>; + NonTrivialMemaccess, NonTrivialMemcall, MemsetTransposedArgs, AaronBallman wrote: It should be transitively included, I believe. (Test coverage would tell us for sure though!) https://github.com/llvm/llvm-project/pull/117387 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Move warning about memset/memcpy to NonTriviallyCopyable type… (PR #117387)
https://github.com/AaronBallman commented: Generally LGTM modulo comments from @zmodem https://github.com/llvm/llvm-project/pull/117387 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Only build static analyzer sources if requested (PR #71653)
whisperity wrote: Took some measurements on X86. Size-wise the CSA-related libraries and objects are roughly the same. We have 2.2G for the three libraries `lib/libclangStaticAnalzyer{Checkers,Core,Frontend}.a` and then another 2.2G for the `tools/clang/lib/StaticAnalyzer/**` object files. The sizes are a LOT different on X86, however, as the build directory is close to 90 GiB, so now CSA only accounts for "just" 5.5%. Here, I got 201 build actions to (re-)execute with a raw `ninja` to generate these files as opposed to `ninja clang`, and with `-j 16` and 64 GiB RAM available, the execution of these ~200 commands took 4 min 47 seconds to execute, which is ~9.8% of the total build time otherwise (42 min). https://github.com/llvm/llvm-project/pull/71653 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [flang] [Flang] LoongArch64 support for BIND(C) derived types in mabi=lp64d. (PR #117108)
@@ -1151,6 +1154,311 @@ struct TargetLoongArch64 : public GenericTarget { return GenericTarget::integerArgumentType(loc, argTy); } + + /// Flatten non-basic types, resulting in an array of types containing only + /// `IntegerType` and `FloatType`. + std::vector flattenTypeList(mlir::Location loc, + const mlir::Type type) const { +std::vector flatTypes; + +llvm::TypeSwitch(type) +.template Case([&](mlir::IntegerType intTy) { + if (intTy.getWidth() != 0) +flatTypes.push_back(intTy); +}) +.template Case([&](mlir::FloatType floatTy) { + if (floatTy.getWidth() != 0) +flatTypes.push_back(floatTy); +}) +.template Case([&](mlir::ComplexType cmplx) { + const auto *sem = &floatToSemantics(kindMap, cmplx.getElementType()); + if (sem == &llvm::APFloat::IEEEsingle() || + sem == &llvm::APFloat::IEEEdouble() || + sem == &llvm::APFloat::IEEEquad()) +std::fill_n(std::back_inserter(flatTypes), 2, +cmplx.getElementType()); + else +TODO(loc, "unsupported complx type(not IEEEsingle, IEEEdouble, " + "IEEEquad) as a structure component for BIND(C), " + "VALUE derived type argument and type return"); +}) +.template Case([&](fir::LogicalType logicalTy) { + const auto width = kindMap.getLogicalBitsize(logicalTy.getFKind()); + if (width != 0) +flatTypes.push_back( +mlir::IntegerType::get(type.getContext(), width)); +}) +.template Case([&](fir::CharacterType charTy) { + flatTypes.push_back(mlir::IntegerType::get(type.getContext(), 8)); tblah wrote: Okay that sounds plausible. Please could you add an assertion that the character has size 1 (mostly to document the assumption). Other than that the current approach looks good. https://github.com/llvm/llvm-project/pull/117108 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implement SV_GroupID semantic (PR #115911)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `openmp-offload-libc-amdgpu-runtime` running on `omp-vega20-1` while building `clang` at step 7 "Add check check-offload". Full details are available at: https://lab.llvm.org/buildbot/#/builders/73/builds/9177 Here is the relevant piece of the build log for the reference ``` Step 7 (Add check check-offload) failure: test (failure) TEST 'libomptarget :: amdgcn-amd-amdhsa :: sanitizer/kernel_crash_async.c' FAILED Exit Code: 1 Command Output (stdout): -- # RUN: at line 2 /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/clang -fopenmp-I /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test -I /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -nogpulib -Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib -fopenmp-targets=amdgcn-amd-amdhsa -O3 /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c -o /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp -Xoffload-linker -lc -Xoffload-linker -lm /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a # executed command: /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/clang -fopenmp -I /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test -I /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib -L /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -nogpulib -Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -Wl,-rpath,/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib -fopenmp-targets=amdgcn-amd-amdhsa -O3 /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c -o /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp -Xoffload-linker -lc -Xoffload-linker -lm /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a # RUN: at line 3 /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/not --crash env -u LLVM_DISABLE_SYMBOLIZATION OFFLOAD_TRACK_NUM_KERNEL_LAUNCH_TRACES=1 /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp 2>&1 | /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/FileCheck /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c --check-prefixes=TRACE # executed command: /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/not --crash env -u LLVM_DISABLE_SYMBOLIZATION OFFLOAD_TRACK_NUM_KERNEL_LAUNCH_TRACES=1 /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp # executed command: /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/FileCheck /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c --check-prefixes=TRACE # RUN: at line 4 /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/not --crash /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp 2>&1 | /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/FileCheck /home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c --check-prefixes=CH
[clang] [llvm] [ubsan] Change ubsan-unique-traps to use nomerge instead of counter (PR #117651)
https://github.com/thurstond updated https://github.com/llvm/llvm-project/pull/117651 >From f24a87de48c42f310ee73ecf480ea2dcf631881f Mon Sep 17 00:00:00 2001 From: Thurston Dang Date: Tue, 26 Nov 2024 00:33:09 + Subject: [PATCH 1/7] [ubsan] Change ubsan-unique-traps to use nomerge instead of counter https://github.com/llvm/llvm-project/pull/65972 (continuation of https://reviews.llvm.org/D148654) had considered adding nomerge to ubsantrap, but did not proceed with that because of https://github.com/llvm/llvm-project/issues/53011. Instead, it added a counter (based on TrapBB->getParent()->size()) to each ubsantrap call. However, this counter is not guaranteed to be unique after inlining, as shown by https://github.com/llvm/llvm-project/pull/83470, which can result in ubsantraps being merged by the backend. https://github.com/llvm/llvm-project/pull/101549 fixed has since fixed the nomerge limitation ("It sets nomerge flag for the node if the instruction has nomerge arrtibute."). This patch therefore takes advantage of nomerge instead of using the counter, guaranteeing that the ubsantraps are not merged. This patch is equivalent to https://github.com/llvm/llvm-project/pull/83470 but also adds nomerge and updates the test that was precommitted in https://github.com/llvm/llvm-project/pull/117649. --- clang/lib/CodeGen/CGExpr.cpp | 6 +- clang/test/CodeGen/bounds-checking.c | 4 +- clang/test/CodeGen/ubsan-trap-merge.c | 106 ++ 3 files changed, 110 insertions(+), 6 deletions(-) create mode 100644 clang/test/CodeGen/ubsan-trap-merge.c diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index d3f470d401b3d4..f8c1e1cd7a4d68 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -3921,16 +3921,14 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked, llvm::CallInst *TrapCall = Builder.CreateCall( CGM.getIntrinsic(llvm::Intrinsic::ubsantrap), -llvm::ConstantInt::get(CGM.Int8Ty, - ClSanitizeDebugDeoptimization - ? TrapBB->getParent()->size() - : static_cast(CheckHandlerID))); +llvm::ConstantInt::get(CGM.Int8Ty, CheckHandlerID)); if (!CGM.getCodeGenOpts().TrapFuncName.empty()) { auto A = llvm::Attribute::get(getLLVMContext(), "trap-func-name", CGM.getCodeGenOpts().TrapFuncName); TrapCall->addFnAttr(A); } +TrapCall->addFnAttr(llvm::Attribute::NoMerge); TrapCall->setDoesNotReturn(); TrapCall->setDoesNotThrow(); Builder.CreateUnreachable(); diff --git a/clang/test/CodeGen/bounds-checking.c b/clang/test/CodeGen/bounds-checking.c index 8100e30d0650ad..f6c4880e70a150 100644 --- a/clang/test/CodeGen/bounds-checking.c +++ b/clang/test/CodeGen/bounds-checking.c @@ -74,11 +74,11 @@ char B2[10]; // CHECK-LABEL: @f8 void f8(int i, int k) { // NOOPTLOCAL: call void @llvm.ubsantrap(i8 3) - // NOOPTARRAY: call void @llvm.ubsantrap(i8 2) + // NOOPTARRAY: call void @llvm.ubsantrap(i8 18) B[i] = '\0'; // NOOPTLOCAL: call void @llvm.ubsantrap(i8 5) - // NOOPTARRAY: call void @llvm.ubsantrap(i8 4) + // NOOPTARRAY: call void @llvm.ubsantrap(i8 18) B2[k] = '\0'; } diff --git a/clang/test/CodeGen/ubsan-trap-merge.c b/clang/test/CodeGen/ubsan-trap-merge.c new file mode 100644 index 00..e6aa7902262813 --- /dev/null +++ b/clang/test/CodeGen/ubsan-trap-merge.c @@ -0,0 +1,106 @@ +// NOTE: Assertions have mostly been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5 +// The most important assertion is the attributes at the end of the file, which +// shows that ubsan attaches 'nomerge' to each ubsantrap intrinsic. +// +// RUN: %clang -fsanitize=signed-integer-overflow -S -emit-llvm -fsanitize-trap=all -O3 -mllvm -ubsan-unique-traps %s -o - \ +// RUN: | FileCheck %s + +#include +#include + +// CHECK-LABEL: define dso_local range(i32 -2147483523, -2147483648) i32 @f( +// CHECK-SAME: i32 noundef [[X:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT:[[TMP0:%.*]] = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[X]], i32 125), !nosanitize [[META5:![0-9]+]] +// CHECK-NEXT:[[TMP1:%.*]] = extractvalue { i32, i1 } [[TMP0]], 1, !nosanitize [[META5]] +// CHECK-NEXT:br i1 [[TMP1]], label %[[TRAP:.*]], label %[[CONT:.*]], !nosanitize [[META5]] +// CHECK: [[TRAP]]: +// CHECK-NEXT:tail call void @llvm.ubsantrap(i8 0) #[[ATTR4:[0-9]+]], !nosanitize [[META5]] +// CHECK-NEXT:unreachable, !nosanitize [[META5]] +// CHECK: [[CONT]]: +// CHECK-NEXT:[[TMP2:%.*]] = extractvalue { i32, i1 } [[TMP0]], 0, !nosanitize [[META5]] +// CHECK-NEXT:ret i32 [[TMP2]] +// +int f(int x) { + return x + 125; +} + +// CHECK-LABEL: define dso_local range(i32 -2147483521, -2147483648) i32 @g( +// CHECK-SAME
[clang] [llvm] [ubsan] Change ubsan-unique-traps to use nomerge instead of counter (PR #117651)
https://github.com/thurstond edited https://github.com/llvm/llvm-project/pull/117651 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [X86] Enhance kCFI type IDs with a 3-bit arity indicator. (PR #117121)
Darksonn wrote: Rust already supports kCFI and I see no reason it can't also support this scheme. We just need to be careful to introduce it in a good way that reduces the risk of mismatched hashing strategies. https://github.com/llvm/llvm-project/pull/117121 ___ 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)
@@ -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; AaronBallman wrote: This seems like a warning we should probably enable by default when the user specifies `-fms-compatibility` or is compiling for an MSVC target. WDYT @rnk? https://github.com/llvm/llvm-project/pull/117428 ___ 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/AaronBallman commented: Thank you for working on this! Please be sure to also add a release note to `clang/docs/ReleaseNotes.rst` so users know about the new diagnostic. https://github.com/llvm/llvm-project/pull/117428 ___ 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/AaronBallman edited https://github.com/llvm/llvm-project/pull/117428 ___ 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)
@@ -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; AaronBallman wrote: ```suggestion return !FD->getType()->isDependentType(); ``` https://github.com/llvm/llvm-project/pull/117428 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Only build static analyzer sources if requested (PR #71653)
smeenai wrote: I think this makes sense in that case, though I'd wait for @llvm-beanz and @petrhosek too. https://github.com/llvm/llvm-project/pull/71653 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [SystemZ] Add support for half (fp16) (PR #109164)
@@ -513,11 +514,26 @@ SystemZTargetLowering::SystemZTargetLowering(const TargetMachine &TM, } // Handle floating-point types. + // Promote all f16 operations to float, with some exceptions below. + for (unsigned Opc = 0; Opc < ISD::BUILTIN_OP_END; ++Opc) +setOperationAction(Opc, MVT::f16, Promote); + setOperationAction(ISD::ConstantFP, MVT::f16, Expand); + for (MVT VT : {MVT::f32, MVT::f64, MVT::f128}) { +setLoadExtAction(ISD::EXTLOAD, VT, MVT::f16, Expand); +setTruncStoreAction(VT, MVT::f16, Expand); +setOperationAction(ISD::FP_EXTEND, VT, Custom); +setOperationAction(ISD::STRICT_FP_EXTEND, VT, Custom); JonPsson1 wrote: Moved them down but not sure if they should be together (as they are treated the same), or if we should maintain the separation of the STRICT operations (-> move FP_EXTEND up) https://github.com/llvm/llvm-project/pull/109164 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits