| 1 |
/* PR tree-optimization/77357 - strlen of constant strings not folded |
| 2 |
{ dg-do compile } |
| 3 |
{ dg-options "-O0 -Wall -fdump-tree-gimple" } */ |
| 4 |
|
| 5 |
#include "strlenopt.h" |
| 6 |
|
| 7 |
#define CONCAT(x, y) x ## y |
| 8 |
#define CAT(x, y) CONCAT (x, y) |
| 9 |
#define FAILNAME(name, counter) \ |
| 10 |
CAT (CAT (CAT (call_ ## name ##_on_line_, __LINE__), _), counter) |
| 11 |
|
| 12 |
#define FAIL(name, counter) do { \ |
| 13 |
extern void FAILNAME (name, counter) (void); \ |
| 14 |
FAILNAME (name, counter)(); \ |
| 15 |
} while (0) |
| 16 |
|
| 17 |
/* Macro to emit a call to funcation named |
| 18 |
call_in_true_branch_not_eliminated_on_line_NNN() |
| 19 |
for each call that's expected to be eliminated. The dg-final |
| 20 |
scan-tree-dump-times directive at the bottom of the test verifies |
| 21 |
that no such call appears in output. */ |
| 22 |
#define ELIM(expr) \ |
| 23 |
if (!(expr)) FAIL (in_true_branch_not_eliminated, __COUNTER__); else (void)0 |
| 24 |
|
| 25 |
#define T(s, n) ELIM (strlen (s) == n) |
| 26 |
|
| 27 |
|
| 28 |
struct S |
| 29 |
{ |
| 30 |
char a1[1], a2[2], a3[3], a4[4], a5[5], a6[6], a7[7], a8[8], a9[9]; |
| 31 |
}; |
| 32 |
|
| 33 |
#define S0 "" |
| 34 |
#define S1 "1" |
| 35 |
#define S2 "12" |
| 36 |
#define S3 "123" |
| 37 |
#define S4 "1234" |
| 38 |
#define S5 "12345" |
| 39 |
#define S6 "123456" |
| 40 |
#define S7 "1234567" |
| 41 |
#define S8 "12345678" |
| 42 |
|
| 43 |
const char a9[][9] = { S0, S1, S2, S3, S4, S5, S6, S7, S8 }; |
| 44 |
|
| 45 |
void test_elim_a9 (unsigned i) |
| 46 |
{ |
| 47 |
ELIM (strlen (&a9[0][i]) > 0); |
| 48 |
ELIM (strlen (&a9[1][i]) > 1); |
| 49 |
ELIM (strlen (&a9[2][i]) > 2); |
| 50 |
ELIM (strlen (&a9[3][i]) > 3); |
| 51 |
ELIM (strlen (&a9[4][i]) > 4); |
| 52 |
ELIM (strlen (&a9[5][i]) > 5); |
| 53 |
ELIM (strlen (&a9[6][i]) > 6); |
| 54 |
ELIM (strlen (&a9[7][i]) > 7); |
| 55 |
ELIM (strlen (&a9[8][i]) > 8); |
| 56 |
} |
| 57 |
|
| 58 |
const char a9_9[][9][9] = { |
| 59 |
{ S0, S1, S2, S3, S4, S5, S6, S7, S8 }, |
| 60 |
{ S1, S2, S3, S4, S5, S6, S7, S8, S0 }, |
| 61 |
{ S2, S3, S4, S5, S6, S7, S8, S0, S1 }, |
| 62 |
{ S3, S4, S5, S6, S7, S8, S0, S1, S2 }, |
| 63 |
{ S4, S5, S6, S7, S8, S0, S1, S2, S3 }, |
| 64 |
{ S5, S6, S7, S8, S0, S1, S2, S3, S4 }, |
| 65 |
{ S6, S7, S8, S0, S1, S2, S3, S4, S5 }, |
| 66 |
{ S7, S8, S0, S1, S2, S3, S4, S5, S6 }, |
| 67 |
{ S8, S0, S1, S2, S3, S4, S5, S6, S7 } |
| 68 |
}; |
| 69 |
|
| 70 |
void test_elim_a9_9 (unsigned i) |
| 71 |
{ |
| 72 |
#undef T |
| 73 |
#define T(I) \ |
| 74 |
ELIM (strlen (&a9_9[I][0][i]) > (0 + I) % 9); \ |
| 75 |
ELIM (strlen (&a9_9[I][1][i]) > (1 + I) % 9); \ |
| 76 |
ELIM (strlen (&a9_9[I][2][i]) > (2 + i) % 9); \ |
| 77 |
ELIM (strlen (&a9_9[I][3][i]) > (3 + I) % 9); \ |
| 78 |
ELIM (strlen (&a9_9[I][4][i]) > (4 + I) % 9); \ |
| 79 |
ELIM (strlen (&a9_9[I][5][i]) > (5 + I) % 9); \ |
| 80 |
ELIM (strlen (&a9_9[I][6][i]) > (6 + I) % 9); \ |
| 81 |
ELIM (strlen (&a9_9[I][7][i]) > (7 + I) % 9); \ |
| 82 |
ELIM (strlen (&a9_9[I][8][i]) > (8 + I) % 9) |
| 83 |
|
| 84 |
T (0); T (1); T (2); T (3); T (4); T (5); T (6); T (7); T (8); |
| 85 |
} |
| 86 |
|
| 87 |
/* { dg-final { scan-tree-dump-times "strlen1" 0 "gimple" } } */ |