1 // RUN: %clang_cc1 -analyze -analyzer-checker=core.experimental.CastToStruct -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=basic -verify %s
2 // RUN: %clang_cc1 -analyze -analyzer-checker=core.experimental.CastToStruct -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -verify %s
3 // RUN: %clang_cc1 -analyze -analyzer-checker=core.experimental.CastToStruct -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=basic -verify %s
4 // RUN: %clang_cc1 -analyze -analyzer-checker=core.experimental.CastToStruct -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify %s
18 // Array to pointer conversion. Array in the struct field.
32 // StringLiteral in lvalue context and pointer to array type.
33 // p: ElementRegion, q: StringRegion
35 char *p
= "/usr/local";
40 // Typedef'ed struct definition.
45 // Initialize array with InitExprList.
49 struct s c
[] = {{1,{1}}};
52 // Struct variable in lvalue context.
53 // Assign UnknownVal to the whole struct.
62 p
= __builtin_alloca(10);
66 // Test if RegionStore::EvalBinOp converts the alloca region to element
73 void g2(struct s2
*p
);
75 // Incomplete struct pointer used as function argument.
77 struct s2
*p
= __builtin_alloca(10);
81 // sizeof() is unsigned while -1 is signed in array index.
84 a
[sizeof(a
)/sizeof(int) - 1] = 1; // no-warning
87 // Initialization of struct array elements.
92 // Initializing array with string literal.
98 // Retrieve the default value of element/field region.
102 if (a
.data
== 0) // no-warning
106 // Convert unsigned offset to signed when creating ElementRegion from
108 void f12(int *list
) {
119 // The binding of a.e.d should not be removed. Test recursive subregion map
120 // building: a->e, e->d. Only then 'a' could be added to live region roots.
121 void f13(double timeout
) {
123 a
.e
.d
= (int) timeout
;
132 static struct s3 opt
;
134 // Test if the embedded array is retrieved correctly.
136 struct s3 my_opt
= opt
;
141 // Test if the array is correctly invalidated.
145 if (a
[1]) // no-warning
151 // Code from postgresql.
152 // Current cast logic of region store mistakenly leaves the final result region
153 // an ElementRegion of type 'char'. Then load a nonloc::SymbolVal from it and
155 void f16(struct s3
*p
) {
156 struct s3 a
= *((struct s3
*) ((char*) &p
[0])); // expected-warning{{Casting a non-structure type to a structure type and accessing a field can lead to memory access errors or data corruption.}}
159 void inv(struct s1
*);
161 // Invalidate the struct field.
174 char *p
= (char *) __builtin_alloca(10);
178 if (*q
) { // no-warning