================
@@ -410,3 +394,65 @@ void no_dangling_by_value_argument() {
// The returned reference does not dangle.
takes_by_value(BoundToSelf());
}
+
+struct F {
+ int *p;
+};
+
+F makeView(int &x [[clang::lifetimebound]]) { return F{&x}; }
+
+F whole_struct_return_lazycompoundval() {
+ int x = 5; // expected-note {{'x' initialized here}}
+ return makeView(x);
+ // expected-warning@-1 {{Returning value bound to 'x' that will go out of
scope}}
+ // expected-note@-2 {{Lifetime of 'x' ended here}}
+ // expected-note@-3 {{Value's lifetime bound to the lifetime of 'x' here}}
+ // expected-warning@-4 {{Address of stack memory associated with local
variable 'x' returned to caller}}
+ // expected-note@-5 {{Address of stack memory associated with local
variable 'x' returned to caller}}
+ // expected-warning@-6 {{address of stack memory associated with local
variable 'x' returned}}
+}
+
+struct PtrPair {
+ int *p;
+ int *q;
+};
+
+int global_v = 4;
+
+PtrPair makePair(int &x [[clang::lifetimebound]]) {
+ return PtrPair{&x, &global_v};
+}
+
+PtrPair return_pair_by_value() {
+ int local = 5; // expected-note {{'local' initialized here}}
+ return makePair(local);
+ // expected-warning@-1 {{Returning value bound to 'local' that will go out
of scope}}
+ // expected-note@-2 {{Lifetime of 'local' ended here}}
+ // expected-note@-3 {{Value's lifetime bound to the lifetime of 'local'
here}}
+ // expected-warning@-4 {{Address of stack memory associated with local
variable 'local' returned to caller}}
+ // expected-note@-5 {{Address of stack memory associated with local
variable 'local' returned to caller}}
+ // expected-warning@-6 {{address of stack memory associated with local
variable 'local' returned}}
+}
+
+struct InnerS {
+ int *p;
+};
+
+struct OuterS {
+ InnerS inner;
+ int *q;
+};
----------------
benedekaibas wrote:
Applied changes:
[62d4f3c](https://github.com/llvm/llvm-project/pull/214823/commits/62d4f3ce17203c28ffff3357483a9b2883325ffb)
https://github.com/llvm/llvm-project/pull/214589
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits