| 1 |
/* |
| 2 |
{ dg-do compile } |
| 3 |
{ dg-options "-O2 -Wall -fdump-tree-optimized" } */ |
| 4 |
|
| 5 |
typedef __SIZE_TYPE__ size_t; |
| 6 |
|
| 7 |
extern void abort (void); |
| 8 |
extern int snprintf (char*, size_t, const char*, ...); |
| 9 |
|
| 10 |
const char s0[] = ""; |
| 11 |
const char s1[] = "a"; |
| 12 |
const char s2[] = "ab"; |
| 13 |
|
| 14 |
extern char ax[]; |
| 15 |
extern const char* const ptr; |
| 16 |
|
| 17 |
#define CAT(x, y) x ## y |
| 18 |
#define CONCAT(x, y) CAT (x, y) |
| 19 |
#define TEST CONCAT (test_on_line_, __LINE__) |
| 20 |
|
| 21 |
#define KEEP(expr) do { \ |
| 22 |
if ((expr)) { \ |
| 23 |
extern void TEST (void); \ |
| 24 |
TEST (); \ |
| 25 |
} \ |
| 26 |
} while (0) |
| 27 |
|
| 28 |
|
| 29 |
void test_literal (int i) |
| 30 |
{ |
| 31 |
KEEP (0 < snprintf (0, 0, "%s", i ? "" : ax)); |
| 32 |
KEEP (1 < snprintf (0, 0, "%s", i ? ax : "1")); |
| 33 |
KEEP (2 < snprintf (0, 0, "%s", i ? "12" : ptr)); |
| 34 |
|
| 35 |
KEEP (1 > snprintf (0, 0, "%s", i ? "" : ax)); |
| 36 |
KEEP (1 > snprintf (0, 0, "%s", i ? ax : "1")); |
| 37 |
KEEP (2 > snprintf (0, 0, "%s", i ? "12" : ptr)); |
| 38 |
} |
| 39 |
|
| 40 |
void test_cststr (int i) |
| 41 |
{ |
| 42 |
KEEP (0 < snprintf (0, 0, "%s", i ? s0 : ax)); |
| 43 |
KEEP (1 < snprintf (0, 0, "%s", i ? ax : s1)); |
| 44 |
KEEP (2 < snprintf (0, 0, "%s", i ? s2 : ptr)); |
| 45 |
|
| 46 |
KEEP (1 > snprintf (0, 0, "%s", i ? s0 : ax)); |
| 47 |
KEEP (1 > snprintf (0, 0, "%s", i ? ax : s1)); |
| 48 |
KEEP (2 > snprintf (0, 0, "%s", i ? s2 : ptr)); |
| 49 |
} |
| 50 |
|
| 51 |
/* { dg-final { scan-tree-dump-times "test_on_line_" 12 "optimized" } } */ |