| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-options "-O3" } */ |
| 3 |
|
| 4 |
/* Check that "m" array references are effective in preventing the |
| 5 |
array initialization from wandering past a use in the asm, and |
| 6 |
that the casts remain supported. */ |
| 7 |
|
| 8 |
static int |
| 9 |
f1 (const char *p) |
| 10 |
{ |
| 11 |
int count; |
| 12 |
|
| 13 |
__asm__ ("repne scasb" |
| 14 |
: "=c" (count), "+D" (p) |
| 15 |
: "m" (*(const char (*)[]) p), "0" (-1), "a" (0)); |
| 16 |
return -2 - count; |
| 17 |
} |
| 18 |
|
| 19 |
static int |
| 20 |
f2 (const char *p) |
| 21 |
{ |
| 22 |
int count; |
| 23 |
|
| 24 |
__asm__ ("repne scasb" |
| 25 |
: "=c" (count), "+D" (p) |
| 26 |
: "m" (*(const char (*)[48]) p), "0" (-1), "a" (0)); |
| 27 |
return -2 - count; |
| 28 |
} |
| 29 |
|
| 30 |
static int |
| 31 |
f3 (int n, const char *p) |
| 32 |
{ |
| 33 |
int count; |
| 34 |
|
| 35 |
__asm__ ("repne scasb" |
| 36 |
: "=c" (count), "+D" (p) |
| 37 |
: "m" (*(const char (*)[n]) p), "0" (-1), "a" (0)); |
| 38 |
return -2 - count; |
| 39 |
} |
| 40 |
|
| 41 |
int |
| 42 |
main () |
| 43 |
{ |
| 44 |
int a; |
| 45 |
char buff[48] = "hello world"; |
| 46 |
buff[4] = 0; |
| 47 |
a = f1 (buff); |
| 48 |
if (a != 4) |
| 49 |
__builtin_abort (); |
| 50 |
buff[4] = 'o'; |
| 51 |
a = f2 (buff); |
| 52 |
if (a != 11) |
| 53 |
__builtin_abort (); |
| 54 |
buff[4] = 0; |
| 55 |
a = f3 (48, buff); |
| 56 |
if (a != 4) |
| 57 |
__builtin_abort (); |
| 58 |
return 0; |
| 59 |
} |