[clang] [LifetimeSafety] Add dtor for failing CFG-based tests (PR #177362)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 22 05:58:40 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-temporal-safety
Author: Utkarsh Saxena (usx95)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/177362.diff
1 Files Affected:
- (modified) clang/test/Sema/warn-lifetime-analysis-nocfg.cpp (+12-6)
``````````diff
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}}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/177362
More information about the cfe-commits
mailing list