[clang] 35563fa - [LifetimeSafety] Add dtor for failing CFG-based tests (#177362)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 22 11:08:07 PST 2026
Author: Utkarsh Saxena
Date: 2026-01-22T20:08:02+01:00
New Revision: 35563fa37c5abd3fc91fd0ac026f3345a02d37a0
URL: https://github.com/llvm/llvm-project/commit/35563fa37c5abd3fc91fd0ac026f3345a02d37a0
DIFF: https://github.com/llvm/llvm-project/commit/35563fa37c5abd3fc91fd0ac026f3345a02d37a0.diff
LOG: [LifetimeSafety] Add dtor for failing CFG-based tests (#177362)
Added:
Modified:
clang/test/Sema/warn-lifetime-analysis-nocfg.cpp
Removed:
################################################################################
diff --git a/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp b/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp
index a38a4b440891c..99a796c360a7f 100644
--- a/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp
+++ b/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp
@@ -36,6 +36,8 @@ struct [[gsl::Pointer(long)]] MyLongPointerFromConversion {
struct [[gsl::Owner(long)]] MyLongOwnerWithConversion {
MyLongOwnerWithConversion();
+ // TODO: Do this behind a macro and run tests without this dtor to verify trivial dtor cases.
+ ~MyLongOwnerWithConversion();
operator MyLongPointerFromConversion();
long &operator*();
MyIntPointer releaseAsMyPointer();
@@ -121,7 +123,8 @@ MyIntPointer danglingGslPtrFromTemporary2() {
}
MyLongPointerFromConversion danglingGslPtrFromTemporaryConv() {
- return MyLongOwnerWithConversion{}; // expected-warning {{returning address of local temporary object}}
+ return MyLongOwnerWithConversion{}; // expected-warning {{returning address of local temporary object}} \
+ // cfg-warning {{address of stack memory is returned later}} cfg-note {{returned here}}
}
int *noFalsePositive(MyIntOwner &o) {
@@ -152,12 +155,15 @@ void initLocalGslPtrWithTempOwner() {
// cfg-warning {{object whose reference is captured does not live long enough}} cfg-note {{destroyed here}}
use(global); // cfg-note {{later used here}}
- MyLongPointerFromConversion p2 = MyLongOwnerWithConversion{}; // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}}
- use(p2);
+ MyLongPointerFromConversion p2 = MyLongOwnerWithConversion{}; // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}} \
+ // cfg-warning {{object whose reference is captured does not live long enough}} cfg-note {{destroyed here}}
+ use(p2); // cfg-note {{later used here}}
- p2 = MyLongOwnerWithConversion{}; // expected-warning {{object backing the pointer 'p2' }}
- global2 = MyLongOwnerWithConversion{}; // expected-warning {{object backing the pointer 'global2' }}
- use(global2, p2);
+ p2 = MyLongOwnerWithConversion{}; // expected-warning {{object backing the pointer 'p2' }} \
+ // cfg-warning {{object whose reference is captured does not live long enough}} cfg-note {{destroyed here}}
+ global2 = MyLongOwnerWithConversion{}; // expected-warning {{object backing the pointer 'global2' }} \
+ // cfg-warning {{object whose reference is captured does not live long enough}} cfg-note {{destroyed here}}
+ use(global2, p2); // cfg-note 2 {{later used here}}
}
More information about the cfe-commits
mailing list