1 // RUN: %clang_cc1 -verify=expected -Warray-bounds-pointer-arithmetic %s 2 // RUN: %clang_cc1 -verify=expected -Warray-bounds-pointer-arithmetic %s -fstrict-flex-arrays=0 3 // RUN: %clang_cc1 -verify=expected,strict -Warray-bounds-pointer-arithmetic %s -fstrict-flex-arrays=2 4 5 // Test case from PR10615 6 struct ext2_super_block{ 7 unsigned char s_uuid[8]; // expected-note {{declared here}} 8 }; ext2_statfs(struct ext2_super_block * es,int a)9void* ext2_statfs (struct ext2_super_block *es,int a) 10 { 11 return (void *)es->s_uuid + sizeof(int); // no-warning 12 } broken(struct ext2_super_block * es,int a)13void* broken (struct ext2_super_block *es,int a) 14 { 15 return (void *)es->s_uuid + 80; // expected-warning {{refers past the end of the array}} 16 } 17 18 // Test case reduced from PR11594 19 struct S { 20 int n; 21 }; pr11594(struct S * s)22void pr11594(struct S *s) { 23 int a[10]; 24 int *p = a - s->n; 25 } 26 27 // Test case reduced from <rdar://problem/11387038>. This resulted in 28 // an assertion failure because of the typedef instead of an explicit 29 // constant array type. 30 struct RDar11387038 {}; 31 typedef struct RDar11387038 RDar11387038Array[1]; 32 struct RDar11387038_Table { 33 RDar11387038Array z; // strict-note {{array 'z' declared here}} 34 }; 35 typedef struct RDar11387038_Table *TPtr; 36 typedef TPtr *TabHandle; 37 struct RDar11387038_B { 38 TabHandle x; 39 }; 40 typedef struct RDar11387038_B RDar11387038_B; 41 radar11387038(void)42void radar11387038(void) { 43 RDar11387038_B *pRDar11387038_B; 44 struct RDar11387038 *y = &(*pRDar11387038_B->x)->z[4]; // strict-warning {{array index 4 is past the end of the array (which contains 1 element)}} 45 } 46 pr51682(void)47void pr51682(void) { 48 int arr[1]; 49 switch (0) { 50 case 0: 51 break; 52 case 1: 53 asm goto("" ::"r"(arr[42] >> 1)::failed); 54 break; 55 } 56 failed:; 57 } 58