| 1 |
// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix,debug.ExprInspection \ |
| 2 |
// RUN: -verify -analyzer-config eagerly-assume=false -std=c99 %s \ |
| 3 |
// RUN: -Wno-implicit-function-declaration |
| 4 |
|
| 5 |
int printf(const char *restrict,...); |
| 6 |
|
| 7 |
void clang_analyzer_eval(int); |
| 8 |
void clang_analyzer_dump(int*); |
| 9 |
|
| 10 |
// Testing core functionality of the region store. |
| 11 |
int compoundLiteralTest(void) { |
| 12 |
int index = 0; |
| 13 |
for (index = 0; index < 2; index++) { |
| 14 |
int thing = (int []){0, 1}[index]; |
| 15 |
printf("thing: %i\n", thing); |
| 16 |
} |
| 17 |
return 0; |
| 18 |
} |
| 19 |
|
| 20 |
int compoundLiteralTest2(void) { |
| 21 |
int index = 0; |
| 22 |
for (index = 0; index < 3; index++) { |
| 23 |
int thing = (int [][3]){{0,0,0}, {1,1,1}, {2,2,2}}[index][index]; |
| 24 |
printf("thing: %i\n", thing); |
| 25 |
} |
| 26 |
return 0; |
| 27 |
} |
| 28 |
|
| 29 |
int concreteOffsetBindingIsInvalidatedBySymbolicOffsetAssignment(int length, |
| 30 |
int i) { |
| 31 |
int values[length]; |
| 32 |
values[i] = 4; |
| 33 |
return values[0]; // no-warning |
| 34 |
} |
| 35 |
|
| 36 |
struct X{ |
| 37 |
int mem; |
| 38 |
}; |
| 39 |
int initStruct(struct X *st); |
| 40 |
int structOffsetBindingIsInvalidated(int length, int i){ |
| 41 |
struct X l; |
| 42 |
initStruct(&l); |
| 43 |
return l.mem; // no-warning |
| 44 |
} |
| 45 |
|
| 46 |
void testConstraintOnRegionOffset(int *values, int length, int i){ |
| 47 |
if (values[1] == 4) { |
| 48 |
values[i] = 5; |
| 49 |
clang_analyzer_eval(values[1] == 4);// expected-warning {{UNKNOWN}} |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
int initArray(int *values); |
| 54 |
void testConstraintOnRegionOffsetStack(int *values, int length, int i) { |
| 55 |
if (values[0] == 4) { |
| 56 |
initArray(values); |
| 57 |
clang_analyzer_eval(values[0] == 4);// expected-warning {{UNKNOWN}} |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
int buffer[10]; |
| 62 |
void b(); // expected-warning {{a function declaration without a prototype is deprecated in all versions of C and is treated as a zero-parameter prototype in C23, conflicting with a subsequent definition}} |
| 63 |
void missingPrototypeCallsiteMatchingArgsAndParams() { |
| 64 |
// expected-warning@+1 {{passing arguments to 'b' without a prototype is deprecated in all versions of C and is not supported in C23}} |
| 65 |
b(&buffer); |
| 66 |
} |
| 67 |
void b(int *c) { // expected-note {{conflicting prototype is here}} |
| 68 |
clang_analyzer_dump(c); // expected-warning {{&Element{buffer,0 S64b,int}}} |
| 69 |
*c = 42; // no-crash |
| 70 |
} |
| 71 |
|
| 72 |
void c(); // expected-warning {{a function declaration without a prototype is deprecated in all versions of C and is treated as a zero-parameter prototype in C23, conflicting with a subsequent definition}} |
| 73 |
void missingPrototypeCallsiteMismatchingArgsAndParams() { |
| 74 |
// expected-warning@+1 {{passing arguments to 'c' without a prototype is deprecated in all versions of C and is not supported in C23}} |
| 75 |
c(&buffer, &buffer); |
| 76 |
} |
| 77 |
void c(int *c) { // expected-note {{conflicting prototype is here}} |
| 78 |
clang_analyzer_dump(c); // expected-warning {{Unknown}} |
| 79 |
*c = 42; // no-crash |
| 80 |
} |