• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -analyze -analyzer-checker=core,unix,debug.ExprInspection -verify %s
2 
3 int printf(const char *restrict,...);
4 
5 // Testing core functionality of the region store.
6 // radar://10127782
compoundLiteralTest()7 int compoundLiteralTest() {
8     int index = 0;
9     for (index = 0; index < 2; index++) {
10         int thing = (int []){0, 1}[index];
11         printf("thing: %i\n", thing);
12     }
13     return 0;
14 }
15 
compoundLiteralTest2()16 int compoundLiteralTest2() {
17     int index = 0;
18     for (index = 0; index < 3; index++) {
19         int thing = (int [][3]){{0,0,0}, {1,1,1}, {2,2,2}}[index][index];
20         printf("thing: %i\n", thing);
21     }
22     return 0;
23 }
24 
concreteOffsetBindingIsInvalidatedBySymbolicOffsetAssignment(int length,int i)25 int concreteOffsetBindingIsInvalidatedBySymbolicOffsetAssignment(int length,
26                                                                  int i) {
27   int values[length];
28   values[i] = 4;
29   return values[0]; // no-warning
30 }
31 
32 struct X{
33   int mem;
34 };
35 int initStruct(struct X *st);
structOffsetBindingIsInvalidated(int length,int i)36 int structOffsetBindingIsInvalidated(int length, int i){
37   struct X l;
38   initStruct(&l);
39   return l.mem; // no-warning
40 }
41 
42 void clang_analyzer_eval(int);
testConstraintOnRegionOffset(int * values,int length,int i)43 void testConstraintOnRegionOffset(int *values, int length, int i){
44   if (values[1] == 4) {
45     values[i] = 5;
46     clang_analyzer_eval(values[1] == 4);// expected-warning {{UNKNOWN}}
47   }
48 }
49 
50 int initArray(int *values);
testConstraintOnRegionOffsetStack(int * values,int length,int i)51 void testConstraintOnRegionOffsetStack(int *values, int length, int i) {
52   if (values[0] == 4) {
53     initArray(values);
54     clang_analyzer_eval(values[0] == 4);// expected-warning {{UNKNOWN}}
55   }
56 }
57