1 /* Verify that strlen doesn't (inadvertently) use the size of an array 2 of char pointers to put an upper bound on the length of the strings 3 they point to. 4 { dg-do compile } 5 { dg-options "-O2 -Wall -fdump-tree-optimized" } */ 6 eaa_test(void)7void eaa_test (void) 8 { 9 extern char eaa[4][4]; 10 11 char (*p)[4] = eaa; 12 13 if (!*p) 14 return; 15 16 /* The longest string stored in EAA is 15 characters. */ 17 if (__builtin_strlen (*p) > 14) 18 { 19 extern void eaa_ok (void); 20 eaa_ok (); 21 } 22 23 if (__builtin_strlen (*p) > 15) 24 { 25 extern void eaa_fail (void); 26 eaa_fail (); 27 } 28 } 29 30 /* { dg-final { scan-tree-dump-times "eaa_ok" 1 "optimized" } } 31 { dg-final { scan-tree-dump-not "eaa_fail" "optimized" } } */ 32 33 epa_test(void)34void epa_test (void) 35 { 36 extern char* epa[4]; 37 char **p = epa; 38 39 if (*p && __builtin_strlen (*p) > 123) 40 { 41 extern void epa_ok (void); 42 epa_ok (); 43 } 44 } 45 46 /* { dg-final { scan-tree-dump-times "epa_ok" 1 "optimized" } } */ 47 48 49 static char* spa[4]; 50 spa_test(void)51void spa_test (void) 52 { 53 char **p = spa; 54 55 if (*p && __builtin_strlen (*p) > 123) 56 { 57 extern void spa_ok (); 58 spa_ok (); 59 } 60 } 61 62 /* { dg-final { scan-tree-dump-times "spa_ok" 1 "optimized" } } */ 63 64 65 void sink (void*, ...); 66 init(void)67void init (void) 68 { 69 /* Make believe even the static array SA may be non-zero. */ 70 sink (spa); 71 } 72