================
@@ -0,0 +1,166 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.core.StoreToImmutable
-verify %s
+
+// Test basic functionality of StoreToImmutable checker
+// This tests direct writes to immutable regions without function modeling
+
+// Direct write to a const global variable
+const int global_const = 42; // expected-note {{Memory region is in immutable
space}}
+
+void test_direct_write_to_const_global() {
+ // This should trigger a warning about writing to immutable memory
+ *(int*)&global_const = 100; // expected-warning {{Writing to immutable
memory is undefined behavior}}
+ // expected-note@-1 {{Writing to immutable memory is undefined behavior.
This memory region is marked as immutable and should not be modified}}
----------------
gamesh411 wrote:
The expected-notes are alive, at near latest versions, when running the lit
tests, the substitution for `%clang_analyze_cc1` does indeed have the flag
`-analyzer-output=text`. Plus it would be nice to assert the note tag that
signifies the position of the declared position of the immutable variable
declaration, so I would rather keep the notes in the test.
https://github.com/llvm/llvm-project/pull/150417
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits