================
@@ -1980,3 +1980,117 @@ void outer_pointer_outlives_inner_pointee() {
}
} // namespace LoopLocalPointers
+
+namespace array {
+
+void element_use_after_scope() {
+ int* p;
+ {
+ int a[10]{};
+ p = &a[2]; // expected-warning {{object whose reference is captured does
not live long enough}}
+ } // expected-note {{destroyed here}}
+ (void)*p; // expected-note {{later used here}}
+}
+
+int* element_use_after_return() {
+ int a[10]{};
+ int* p = &a[0]; // expected-warning {{address of stack memory is returned
later}}
+ return p; // expected-note {{returned here}}
+}
+
+void element_use_same_scope() {
+ int a[10]{};
+ int* p = &a[0];
+ (void)*p;
+}
+
+void element_reassigned_safe() {
+ int safe[10]{};
+ int* p;
+ {
+ int a[10]{};
+ p = &a[0];
+ }
+ p = &safe[0]; // rescued
----------------
usx95 wrote:
super nit: `Rescued.` (captial and fullstop)
https://github.com/llvm/llvm-project/pull/186902
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits