Daily bump.
[official-gcc.git] / gcc / testsuite / gcc.dg / strlenopt-93.c
blobdc5f12d2ce348d5664765760d537eeb7f80dc1c7
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" } */
7 void eaa_test (void)
9 extern char eaa[4][4];
11 char (*p)[4] = eaa;
13 if (!*p)
14 return;
16 /* The longest string stored in EAA is 15 characters. */
17 if (__builtin_strlen (*p) > 14)
19 extern void eaa_ok (void);
20 eaa_ok ();
23 if (__builtin_strlen (*p) > 15)
25 extern void eaa_fail (void);
26 eaa_fail ();
30 /* { dg-final { scan-tree-dump-times "eaa_ok" 1 "optimized" } }
31 { dg-final { scan-tree-dump-not "eaa_fail" "optimized" } } */
34 void epa_test (void)
36 extern char* epa[4];
37 char **p = epa;
39 if (*p && __builtin_strlen (*p) > 123)
41 extern void epa_ok (void);
42 epa_ok ();
46 /* { dg-final { scan-tree-dump-times "epa_ok" 1 "optimized" } } */
49 static char* spa[4];
51 void spa_test (void)
53 char **p = spa;
55 if (*p && __builtin_strlen (*p) > 123)
57 extern void spa_ok ();
58 spa_ok ();
62 /* { dg-final { scan-tree-dump-times "spa_ok" 1 "optimized" } } */
65 void sink (void*, ...);
67 void init (void)
69 /* Make believe even the static array SA may be non-zero. */
70 sink (spa);