PR inline-asm/84742
[official-gcc.git] / gcc / testsuite / gcc.target / i386 / pr9771-1.c
blob9fa21ff0fa0d72b6b12c48c8ffff7c8c39eddc8a
1 /* PR rtl-optimization/9771 */
2 /* { dg-do run } */
3 /* { dg-require-effective-target ia32 } */
4 /* { dg-options "-O2 -fomit-frame-pointer -ffixed-ebp" } */
6 extern void abort(void);
7 extern void exit(int);
9 register long *B asm ("ebp");
11 long x = 10;
12 long y = 20;
14 void bar(void)
16 B = &y;
19 void foo()
21 long *adr = B;
22 long save = *adr;
24 *adr = 123;
26 bar();
28 *adr = save;
31 /* This must not be inlined because main() requires the frame pointer
32 for stack alignment. */
33 void test(void) __attribute__((noinline));
34 void test(void)
36 B = &x;
38 foo();
40 if (x != 10 || y != 20)
41 abort();
43 /* We can't return, as our caller may assume %ebp is preserved! */
44 /* We could save/restore it (like foo), but its easier to exit. */
45 exit(0);
48 /* main usually performs dynamic realignment of the stack in case
49 _start would fail to properly align the stack, but for dynamic
50 stack realignment we need frame pointer which is incompatible
51 with -ffixed-ebp and the global register var. So, cheat here
52 and hide from the compiler that main is really main. */
53 #define ASMNAME(cname) ASMNAME2 (__USER_LABEL_PREFIX__, cname)
54 #define ASMNAME2(prefix, cname) STRING (prefix) cname
55 #define STRING(x) #x
56 int real_main() __asm (ASMNAME ("main"));
58 int real_main()
60 test();
61 return 0;