================
@@ -331,3 +331,16 @@ void dangling_through_calls() {
// expected-warning@-1 {{Use of 'local' after its lifetime ended}}
// expected-note@-2 {{Use of 'local' after its lifetime ended}}
}
+
+// If the same variable is dereferenced multiple times then only
+// report for the first dereference.
+void multiple_deref() {
+ int *ptr = nullptr;
+ {
+ int a = 5; // expected-note {{'a' initialized to 5}}
+ ptr = &a; // expected-note {{Value assigned to 'ptr'}}
+ } // expected-note {{'a' is destroyed here}}
+ *ptr = 6; // expected-note {{Use of 'a' after its lifetime ended}}
+ // expected-warning@-1 {{Use of 'a' after its lifetime ended}}
+ *ptr = 7;
----------------
steakhal wrote:
```suggestion
*ptr = 7; // no-warning: Already reported this base region.
```
https://github.com/llvm/llvm-project/pull/215409
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits