https://github.com/dougsonos updated https://github.com/llvm/llvm-project/pull/166110
>From 0ab16b664773bd7b3859ec9e6fc84217dbac1de9 Mon Sep 17 00:00:00 2001 From: Doug Wyatt <[email protected]> Date: Sun, 2 Nov 2025 15:55:48 -0800 Subject: [PATCH 1/2] [Clang] FunctionEffect analysis was missing a CXXBindTemporaryExpr's implicit call to a destructor. --- clang/lib/Sema/SemaFunctionEffects.cpp | 8 ++++++++ clang/test/Sema/attr-nonblocking-constraints.cpp | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/clang/lib/Sema/SemaFunctionEffects.cpp b/clang/lib/Sema/SemaFunctionEffects.cpp index 8590ee831084f..468f157f2e0bd 100644 --- a/clang/lib/Sema/SemaFunctionEffects.cpp +++ b/clang/lib/Sema/SemaFunctionEffects.cpp @@ -1271,7 +1271,15 @@ class Analyzer { const CXXConstructorDecl *Ctor = Construct->getConstructor(); CallableInfo CI(*Ctor); followCall(CI, Construct->getLocation()); + return true; + } + bool VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *BTE) override { + const CXXDestructorDecl* Dtor = BTE->getTemporary()->getDestructor(); + if (Dtor != nullptr) { + CallableInfo CI(*Dtor); + followCall(CI, BTE->getBeginLoc()); + } return true; } diff --git a/clang/test/Sema/attr-nonblocking-constraints.cpp b/clang/test/Sema/attr-nonblocking-constraints.cpp index b26a945843696..4b831c0a6be09 100644 --- a/clang/test/Sema/attr-nonblocking-constraints.cpp +++ b/clang/test/Sema/attr-nonblocking-constraints.cpp @@ -354,6 +354,20 @@ struct Unsafe { Unsafe(float y) [[clang::nonblocking]] : Unsafe(int(y)) {} // expected-warning {{constructor with 'nonblocking' attribute must not call non-'nonblocking' constructor 'Unsafe::Unsafe'}} }; +// Exercise the case of a temporary with a safe constructor and unsafe destructor. +void nb23() +{ + struct X { + int *ptr = nullptr; + X() {} + ~X() { delete ptr; } // expected-note {{destructor cannot be inferred 'nonblocking' because it allocates or deallocates memory}} + }; + + auto inner = []() [[clang::nonblocking]] { + X(); // expected-warning {{lambda with 'nonblocking' attribute must not call non-'nonblocking' destructor 'nb23()::X::~X'}} + }; +} + struct DerivedFromUnsafe : public Unsafe { DerivedFromUnsafe() [[clang::nonblocking]] {} // expected-warning {{constructor with 'nonblocking' attribute must not call non-'nonblocking' constructor 'Unsafe::Unsafe'}} DerivedFromUnsafe(int x) [[clang::nonblocking]] : Unsafe(x) {} // expected-warning {{constructor with 'nonblocking' attribute must not call non-'nonblocking' constructor 'Unsafe::Unsafe'}} >From f7bb4a279569f2fa742fe18e80ad04bbb0e92b5b Mon Sep 17 00:00:00 2001 From: Doug Wyatt <[email protected]> Date: Sun, 2 Nov 2025 16:19:51 -0800 Subject: [PATCH 2/2] format --- clang/lib/Sema/SemaFunctionEffects.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaFunctionEffects.cpp b/clang/lib/Sema/SemaFunctionEffects.cpp index 468f157f2e0bd..d68158f8425d8 100644 --- a/clang/lib/Sema/SemaFunctionEffects.cpp +++ b/clang/lib/Sema/SemaFunctionEffects.cpp @@ -1275,7 +1275,7 @@ class Analyzer { } bool VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *BTE) override { - const CXXDestructorDecl* Dtor = BTE->getTemporary()->getDestructor(); + const CXXDestructorDecl *Dtor = BTE->getTemporary()->getDestructor(); if (Dtor != nullptr) { CallableInfo CI(*Dtor); followCall(CI, BTE->getBeginLoc()); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
