================
@@ -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@-1 {{Returning value bound to 's' that will go out of
scope}}
// expected-warning@-2 {{Address of stack memory associated with local
variable 's' returned}}
- // expected-warning@-3 {{address of stack memory associated with local
variable 's' returned}}
+ // expected-note@-3 {{Address of stack memory associated with local
variable 's' returned to caller}}
+ // expected-warning@-4 {{address of stack memory associated with local
variable 's' returned}}
}
int *danglingParam(S param) {
return param.get();
// expected-warning@-1 {{Returning value bound to 'param' that will go out
of scope}}
- // expected-warning@-2 {{Address of stack memory associated with local
variable 'param' returned}}
- // expected-warning@-3 {{address of stack memory associated with parameter
'param' returned}}
+ // expected-note@-2 {{Returning value bound to 'param' that will go out
of scope}}
+ // expected-warning@-3 {{Address of stack memory associated with local
variable 'param' returned}}
+ // expected-note@-4 {{Address of stack memory associated with local
variable 'param' returned to caller}}
+ // expected-warning@-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@-1 {{Returning value bound to 'pair' that will go out of
scope}}
+ // expected-note@-2 {{Returning value bound to 'pair' that will go out of
scope}}
+ // expected-warning@-3 {{Address of stack memory associated with local
variable 'pair' returned to caller}}
+ // expected-note@-4 {{Address of stack memory associated with local
variable 'pair' returned to caller}}
+ // expected-warning@-5 {{address of stack memory associated with local
variable 'pair' returned}}
+}
+
+int *getBasePtr(Derived &d [[clang::lifetimebound]]) {
+ return &static_cast<Base &>(d).x;
+}
+
+int *base_subobject_dangling() {
+ Derived derived{}; // expected-note {{'derived' initialized here}}
+ return getBasePtr(derived);
+ // expected-warning@-1 {{Returning value bound to 'derived' that will go out
of scope}}
+ // expected-note@-2 {{Returning value bound to 'derived' that will go out
of scope}}
+ // expected-warning@-3 {{Address of stack memory associated with local
variable 'derived' returned to caller}}
+ // expected-note@-4 {{Address of stack memory associated with local
variable 'derived' returned to caller}}
+ // expected-warning@-5 {{address of stack memory associated with local
variable 'derived' returned}}
----------------
benedekaibas wrote:
Applied changes here:
[6ab0609](https://github.com/llvm/llvm-project/pull/212254/commits/6ab0609cb0535c7a12c93abe9e8f7e1b905256b8)
https://github.com/llvm/llvm-project/pull/212254
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits