[clang] [analyzer] Resolve initializers for fields of struct array elements i… (PR #189361)
Endre Fülöp via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 31 05:57:30 PDT 2026
================
@@ -0,0 +1,47 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s
+
+// This test verifies that the analyzer can 'see' the initializer of an
+// array of structs, covering const, non-const, and main() vs non-main cases.
+
+void clang_analyzer_warnIfReached(void);
+
+struct S {
+ int a;
+};
+
+// Non-const struct array: initializer should be visible in main().
+struct S struct_array[1] = {
+ {11},
+};
+
+int main(int argc, char **argv) {
+ if (struct_array->a == 11) {
+ clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+ } else {
+ clang_analyzer_warnIfReached(); // unreachable
+ }
----------------
gamesh411 wrote:
Updated the tests to use `clang_analyzer_value`.
https://github.com/llvm/llvm-project/pull/189361
More information about the cfe-commits
mailing list