| 1 |
/* PR tree-optimization/92226 - live nul char store to array eliminated |
| 2 |
{ dg-do run } |
| 3 |
{ dg-options "-O2 -Wall" } */ |
| 4 |
|
| 5 |
#include "strlenopt.h" |
| 6 |
|
| 7 |
#define NOIPA __attribute__ ((noipa)) |
| 8 |
|
| 9 |
unsigned nfails; |
| 10 |
|
| 11 |
char a[8]; |
| 12 |
|
| 13 |
void test (int line, const char *func, size_t expect) |
| 14 |
{ |
| 15 |
size_t len = strlen (a); |
| 16 |
if (len == expect) |
| 17 |
return; |
| 18 |
|
| 19 |
++nfails; |
| 20 |
|
| 21 |
__builtin_printf ("assertion failed in %s on line %i: " |
| 22 |
"strlen (\"%s\") == %zu, got %zu\n", |
| 23 |
func, line, a, expect, len); |
| 24 |
} |
| 25 |
|
| 26 |
NOIPA const char* str (size_t n) |
| 27 |
{ |
| 28 |
return "9876543210" + 10 - n; |
| 29 |
} |
| 30 |
|
| 31 |
#define T(name, CMPEXP, LEN, IDX, EXPECT) \ |
| 32 |
NOIPA static void name (void) \ |
| 33 |
{ \ |
| 34 |
const char *s = str (LEN); \ |
| 35 |
if (strlen (s) CMPEXP) \ |
| 36 |
{ \ |
| 37 |
strcpy (a, s); \ |
| 38 |
a[IDX] = 0; \ |
| 39 |
test (__LINE__, #name, EXPECT); \ |
| 40 |
} \ |
| 41 |
} typedef void dummy_type |
| 42 |
|
| 43 |
|
| 44 |
T (len_eq_1_store_nul_0, == 1, 1, 0, 0); |
| 45 |
T (len_eq_1_store_nul_1, == 1, 1, 1, 1); |
| 46 |
T (len_eq_1_store_nul_2, == 1, 1, 2, 1); |
| 47 |
T (len_eq_1_store_nul_3, == 1, 1, 3, 1); |
| 48 |
T (len_eq_1_store_nul_4, == 1, 1, 4, 1); |
| 49 |
|
| 50 |
T (len_eq_2_store_nul_0, == 2, 2, 0, 0); |
| 51 |
T (len_eq_2_store_nul_1, == 2, 2, 1, 1); |
| 52 |
T (len_eq_2_store_nul_2, == 2, 2, 2, 2); |
| 53 |
T (len_eq_2_store_nul_3, == 2, 2, 3, 2); |
| 54 |
T (len_eq_2_store_nul_4, == 2, 2, 4, 2); |
| 55 |
|
| 56 |
T (len_eq_3_store_nul_0, == 3, 3, 0, 0); |
| 57 |
T (len_eq_3_store_nul_1, == 3, 3, 1, 1); |
| 58 |
T (len_eq_3_store_nul_2, == 3, 3, 2, 2); |
| 59 |
T (len_eq_3_store_nul_3, == 3, 3, 3, 3); |
| 60 |
T (len_eq_3_store_nul_4, == 3, 3, 4, 3); |
| 61 |
|
| 62 |
|
| 63 |
T (len_gt_1_store_nul_0, > 2, 2, 0, 0); |
| 64 |
T (len_gt_1_store_nul_1, > 2, 2, 1, 1); |
| 65 |
T (len_gt_1_store_nul_2, > 2, 2, 2, 2); |
| 66 |
T (len_gt_1_store_nul_3, > 2, 2, 3, 2); |
| 67 |
T (len_gt_1_store_nul_4, > 2, 2, 4, 2); |
| 68 |
|
| 69 |
T (len_gt_2_store_nul_0, > 2, 3, 0, 0); |
| 70 |
T (len_gt_2_store_nul_1, > 2, 3, 1, 1); |
| 71 |
T (len_gt_2_store_nul_2, > 2, 3, 2, 2); |
| 72 |
T (len_gt_2_store_nul_3, > 2, 3, 3, 3); |
| 73 |
T (len_gt_2_store_nul_4, > 2, 3, 4, 3); |
| 74 |
|
| 75 |
T (len_gt_3_store_nul_0, > 2, 4, 0, 0); |
| 76 |
T (len_gt_3_store_nul_1, > 2, 4, 1, 1); |
| 77 |
T (len_gt_3_store_nul_2, > 2, 4, 2, 2); |
| 78 |
T (len_gt_3_store_nul_3, > 2, 4, 3, 3); |
| 79 |
T (len_gt_3_store_nul_4, > 2, 4, 4, 4); |
| 80 |
|
| 81 |
|
| 82 |
T (len_1_lt_4_store_nul_0, < 4, 1, 0, 0); |
| 83 |
T (len_1_lt_4_store_nul_1, < 4, 1, 1, 1); |
| 84 |
T (len_1_lt_4_store_nul_2, < 4, 1, 2, 1); |
| 85 |
T (len_1_lt_4_store_nul_3, < 4, 1, 3, 1); |
| 86 |
T (len_1_lt_4_store_nul_4, < 4, 1, 4, 1); |
| 87 |
T (len_1_lt_4_store_nul_5, < 4, 1, 5, 1); |
| 88 |
T (len_1_lt_4_store_nul_6, < 4, 1, 6, 1); |
| 89 |
T (len_1_lt_4_store_nul_7, < 4, 1, 7, 1); |
| 90 |
|
| 91 |
T (len_2_lt_4_store_nul_0, < 4, 2, 0, 0); |
| 92 |
T (len_2_lt_4_store_nul_1, < 4, 2, 1, 1); |
| 93 |
T (len_2_lt_4_store_nul_2, < 4, 2, 2, 2); |
| 94 |
T (len_2_lt_4_store_nul_3, < 4, 2, 3, 2); |
| 95 |
T (len_2_lt_4_store_nul_4, < 4, 2, 4, 2); |
| 96 |
T (len_2_lt_4_store_nul_5, < 4, 2, 5, 2); |
| 97 |
T (len_2_lt_4_store_nul_6, < 4, 2, 6, 2); |
| 98 |
T (len_2_lt_4_store_nul_7, < 4, 2, 7, 2); |
| 99 |
|
| 100 |
T (len_3_lt_4_store_nul_0, < 4, 3, 0, 0); |
| 101 |
T (len_3_lt_4_store_nul_1, < 4, 3, 1, 1); |
| 102 |
T (len_3_lt_4_store_nul_2, < 4, 3, 2, 2); |
| 103 |
T (len_3_lt_4_store_nul_3, < 4, 3, 3, 3); |
| 104 |
T (len_3_lt_4_store_nul_4, < 4, 3, 4, 3); |
| 105 |
T (len_3_lt_4_store_nul_5, < 4, 3, 5, 3); |
| 106 |
T (len_3_lt_4_store_nul_6, < 4, 3, 6, 3); |
| 107 |
T (len_3_lt_4_store_nul_7, < 4, 3, 7, 3); |
| 108 |
|
| 109 |
T (len_7_lt_8_store_nul_0, < 8, 7, 0, 0); |
| 110 |
T (len_7_lt_8_store_nul_1, < 8, 7, 1, 1); |
| 111 |
T (len_7_lt_8_store_nul_2, < 8, 7, 2, 2); |
| 112 |
T (len_7_lt_8_store_nul_3, < 8, 7, 3, 3); |
| 113 |
T (len_7_lt_8_store_nul_4, < 8, 7, 4, 4); |
| 114 |
T (len_7_lt_8_store_nul_5, < 8, 7, 5, 5); |
| 115 |
T (len_7_lt_8_store_nul_6, < 8, 7, 6, 6); |
| 116 |
T (len_7_lt_8_store_nul_7, < 8, 7, 7, 7); |
| 117 |
|
| 118 |
|
| 119 |
int main (void) |
| 120 |
{ |
| 121 |
len_eq_1_store_nul_0 (); |
| 122 |
len_eq_1_store_nul_1 (); |
| 123 |
len_eq_1_store_nul_2 (); |
| 124 |
len_eq_1_store_nul_3 (); |
| 125 |
len_eq_1_store_nul_4 (); |
| 126 |
|
| 127 |
len_eq_2_store_nul_0 (); |
| 128 |
len_eq_2_store_nul_1 (); |
| 129 |
len_eq_2_store_nul_2 (); |
| 130 |
len_eq_2_store_nul_3 (); |
| 131 |
len_eq_2_store_nul_4 (); |
| 132 |
|
| 133 |
len_eq_3_store_nul_0 (); |
| 134 |
len_eq_3_store_nul_1 (); |
| 135 |
len_eq_3_store_nul_2 (); |
| 136 |
len_eq_3_store_nul_3 (); |
| 137 |
len_eq_3_store_nul_4 (); |
| 138 |
|
| 139 |
|
| 140 |
len_gt_1_store_nul_0 (); |
| 141 |
len_gt_1_store_nul_1 (); |
| 142 |
len_gt_1_store_nul_2 (); |
| 143 |
len_gt_1_store_nul_3 (); |
| 144 |
len_gt_1_store_nul_4 (); |
| 145 |
|
| 146 |
len_gt_2_store_nul_0 (); |
| 147 |
len_gt_2_store_nul_1 (); |
| 148 |
len_gt_2_store_nul_2 (); |
| 149 |
len_gt_2_store_nul_3 (); |
| 150 |
len_gt_2_store_nul_4 (); |
| 151 |
|
| 152 |
len_gt_3_store_nul_0 (); |
| 153 |
len_gt_3_store_nul_1 (); |
| 154 |
len_gt_3_store_nul_2 (); |
| 155 |
len_gt_3_store_nul_3 (); |
| 156 |
len_gt_3_store_nul_4 (); |
| 157 |
|
| 158 |
len_1_lt_4_store_nul_0 (); |
| 159 |
len_1_lt_4_store_nul_1 (); |
| 160 |
len_1_lt_4_store_nul_2 (); |
| 161 |
len_1_lt_4_store_nul_3 (); |
| 162 |
len_1_lt_4_store_nul_4 (); |
| 163 |
len_1_lt_4_store_nul_5 (); |
| 164 |
len_1_lt_4_store_nul_6 (); |
| 165 |
len_1_lt_4_store_nul_7 (); |
| 166 |
|
| 167 |
len_2_lt_4_store_nul_0 (); |
| 168 |
len_2_lt_4_store_nul_1 (); |
| 169 |
len_2_lt_4_store_nul_2 (); |
| 170 |
len_2_lt_4_store_nul_3 (); |
| 171 |
len_2_lt_4_store_nul_4 (); |
| 172 |
len_2_lt_4_store_nul_5 (); |
| 173 |
len_2_lt_4_store_nul_6 (); |
| 174 |
len_2_lt_4_store_nul_7 (); |
| 175 |
|
| 176 |
len_3_lt_4_store_nul_0 (); |
| 177 |
len_3_lt_4_store_nul_1 (); |
| 178 |
len_3_lt_4_store_nul_2 (); |
| 179 |
len_3_lt_4_store_nul_3 (); |
| 180 |
len_3_lt_4_store_nul_4 (); |
| 181 |
len_3_lt_4_store_nul_5 (); |
| 182 |
len_3_lt_4_store_nul_6 (); |
| 183 |
len_3_lt_4_store_nul_7 (); |
| 184 |
|
| 185 |
len_7_lt_8_store_nul_0 (); |
| 186 |
len_7_lt_8_store_nul_1 (); |
| 187 |
len_7_lt_8_store_nul_2 (); |
| 188 |
len_7_lt_8_store_nul_3 (); |
| 189 |
len_7_lt_8_store_nul_4 (); |
| 190 |
len_7_lt_8_store_nul_5 (); |
| 191 |
len_7_lt_8_store_nul_6 (); |
| 192 |
len_7_lt_8_store_nul_7 (); |
| 193 |
|
| 194 |
if (nfails) |
| 195 |
abort (); |
| 196 |
} |