2018-05-17 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gcc.target / i386 / asm-mem.c
blob89b713f0201cb4f03eb786abd7fd7068fb55f3ff
1 /* { dg-do run } */
2 /* { dg-options "-O3" } */
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. */
8 static int
9 f1 (const char *p)
11 int count;
13 __asm__ ("repne scasb"
14 : "=c" (count), "+D" (p)
15 : "m" (*(const char (*)[]) p), "0" (-1), "a" (0));
16 return -2 - count;
19 static int
20 f2 (const char *p)
22 int count;
24 __asm__ ("repne scasb"
25 : "=c" (count), "+D" (p)
26 : "m" (*(const char (*)[48]) p), "0" (-1), "a" (0));
27 return -2 - count;
30 static int
31 f3 (int n, const char *p)
33 int count;
35 __asm__ ("repne scasb"
36 : "=c" (count), "+D" (p)
37 : "m" (*(const char (*)[n]) p), "0" (-1), "a" (0));
38 return -2 - count;
41 int
42 main ()
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;