[clang] [clang][analyzer] Add StoreToImmutable checker (PR #150417)

DonĂ¡t Nagy via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 1 04:24:32 PDT 2025


================
@@ -0,0 +1,21 @@
+const int global_const = 42;
+
+struct TestStruct {
+  const int x;
+  int y;
+};
+
+void immutable_violation_examples() {
+  *(int *)&global_const = 100; // warn: Trying to write to immutable memory
+
+  const int local_const = 42;
+  *(int *)&local_const = 43; // warn: Trying to write to immutable memory
+
+  // NOTE: The following works in C++, but not in C, as the analyzer treats
----------------
NagyDonat wrote:

Perhaps replace "works" with "is reported" because "works" can be misunderstood as "is standard-compliant".

https://github.com/llvm/llvm-project/pull/150417


More information about the cfe-commits mailing list