[clang] [analyzer][NFC] Add test cases for the lifetime test suite (PR #212254)
Benedek Kaibas via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 27 07:25:44 PDT 2026
================
@@ -235,17 +289,74 @@ void outer() {
}
int *danglingLocal() {
- S s;
- return s.get();
+ S s; // expected-note {{'s' initialized here}}
+ return s.get(); // expected-note {{Returning value bound to 's' that will go out of scope}}
// expected-warning at -1 {{Returning value bound to 's' that will go out of scope}}
// expected-warning at -2 {{Address of stack memory associated with local variable 's' returned}}
- // expected-warning at -3 {{address of stack memory associated with local variable 's' returned}}
+ // expected-note at -3 {{Address of stack memory associated with local variable 's' returned to caller}}
+ // expected-warning at -4 {{address of stack memory associated with local variable 's' returned}}
}
int *danglingParam(S param) {
return param.get();
// expected-warning at -1 {{Returning value bound to 'param' that will go out of scope}}
- // expected-warning at -2 {{Address of stack memory associated with local variable 'param' returned}}
- // expected-warning at -3 {{address of stack memory associated with parameter 'param' returned}}
+ // expected-note at -2 {{Returning value bound to 'param' that will go out of scope}}
+ // expected-warning at -3 {{Address of stack memory associated with local variable 'param' returned}}
+ // expected-note at -4 {{Address of stack memory associated with local variable 'param' returned to caller}}
+ // expected-warning at -5 {{address of stack memory associated with parameter 'param' returned}}
+}
+
+int *getFieldPtr(Pair &p [[clang::lifetimebound]]) { return &p.a; }
+
+int *field_subobject_dangling() {
+ Pair pair{3, 5}; // expected-note {{'pair' initialized here}}
+ return getFieldPtr(pair);
+ // expected-warning at -1 {{Returning value bound to 'pair' that will go out of scope}}
+ // expected-note at -2 {{Returning value bound to 'pair' that will go out of scope}}
+ // expected-warning at -3 {{Address of stack memory associated with local variable 'pair' returned to caller}}
+ // expected-note at -4 {{Address of stack memory associated with local variable 'pair' returned to caller}}
+ // expected-warning at -5 {{address of stack memory associated with local variable 'pair' returned}}
----------------
benedekaibas wrote:
Ouch, yes this very-very bad, I did not notice it. Thanks for spotting this, corrected here: [6ab0609](https://github.com/llvm/llvm-project/pull/212254/commits/6ab0609cb0535c7a12c93abe9e8f7e1b905256b8)
https://github.com/llvm/llvm-project/pull/212254
More information about the cfe-commits
mailing list