[clang] [analyzer] Match dangling subobjects by their base region in DanglingPtrDeref (PR #211552)
Balázs Benics via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 23 06:55:43 PDT 2026
================
@@ -112,3 +112,56 @@ void inlined_callee_single_report() {
// expected-note at -1 {{Calling 'deref_param'}}
(void)r;
}
+
+struct MyBuffer {
+ char buffer[8];
+};
+
+void member_subregion_dangling_deref() {
+ const char *p = nullptr;
+ {
+ struct MyBuffer tmp_buffer = {};
+ p = tmp_buffer.buffer;
+ }
+ // expected-note at -1 {{'tmp_buffer.buffer[0]' is destroyed here}}
+ char c = *p;
+ // expected-warning at -1 {{Use of 'tmp_buffer.buffer[0]' after its lifetime ended}}
+ // expected-note at -2 {{Use of 'tmp_buffer.buffer[0]' after its lifetime ended}}
+ (void)c;
----------------
steakhal wrote:
An alternative way of phrasing this is `return *p;`
I don't mind this either - I just wanted to share this technique.
https://github.com/llvm/llvm-project/pull/211552
More information about the cfe-commits
mailing list