1 /* { dg-do compile } */
2 /* { dg-require-effective-target nonpic } */
3 /* { dg-options "-O2" } */
4
5 /* Check volatiles are written, read or not re-read consistently */
6
7
8 /* simple assignments */
9
10 extern int volatile obj_0;
test_0(int data)11 void test_0 (int data)
12 {
13 /* should not reread obj */
14 /* { dg-final { scan-assembler "movl\[ \t\]\[^,\]+, _?obj_0(\\(%rip\\))?" } } */
15 /* { dg-final { scan-assembler-not "movl\[ \t\]_?obj_0(\\(%rip\\))?," } } */
16 obj_0 = data;
17 }
18
19 extern int volatile obj_1;
test_1(int data)20 int test_1 (int data)
21 {
22 /* should not reread obj */
23 /* { dg-final { scan-assembler "movl\[ \t\]\[^,\]+, _?obj_1(\\(%rip\\))?" } } */
24 /* { dg-final { scan-assembler-not "movl\[ \t\]_?obj_1(\\(%rip\\))?," } } */
25 return obj_1 = data;
26 }
27
28 extern int volatile obj_2;
test_2(void)29 int test_2 (void)
30 {
31 /* should not reread obj */
32 /* { dg-final { scan-assembler "movl\[ \t\]\[^,\]+, _?obj_2(\\(%rip\\))?" } } */
33 /* { dg-final { scan-assembler-not "movl\[ \t\]_?obj_2(\\(%rip\\))?," } } */
34 return obj_2 = 0;
35 }
36
37
38 /* Assignments in compound exprs */
39
40 extern int volatile obj_3;
test_3(int data)41 int test_3 (int data)
42 {
43 /* should not reread obj */
44 /* { dg-final { scan-assembler "movl\[ \t\]\[^,\]+, _?obj_3(\\(%rip\\))?" } } */
45 /* { dg-final { scan-assembler-not "movl\[ \t\]_?obj_3(\\(%rip\\))?," } } */
46 return (obj_3 = data, 0);
47 }
48
49 extern int volatile obj_4;
test_4(void)50 int test_4 (void)
51 {
52 /* should not reread obj */
53 /* { dg-final { scan-assembler "movl\[ \t\]\[^,\]+, _?obj_4(\\(%rip\\))?" } } */
54 /* { dg-final { scan-assembler-not "movl\[ \t\]_?obj_4(\\(%rip\\))?," } } */
55 return (obj_4 = 0, 0);
56 }
57 extern int volatile obj_5;
test_5(void)58 int test_5 (void)
59 {
60 /* should reread obj */
61 /* { dg-final { scan-assembler "movl\[ \t\]\[^,\]+, _?obj_5(\\(%rip\\))?" } } */
62 /* { dg-final { scan-assembler "movl\[ \t\]_?obj_5(\\(%rip\\))?," } } */
63 return (obj_5 = 0, obj_5);
64 }
65
66 /* Assignments in conditional exprs */
67
68 extern int volatile obj_6;
test_6(int data,int cond)69 void test_6 (int data, int cond)
70 {
71 /* should not reread obj */
72 /* { dg-final { scan-assembler "movl\[ \t\]\[^,\]+, _?obj_6(\\(%rip\\))?" } } */
73 /* { dg-final { scan-assembler-not "movl\[ \t\]_?obj_6(\\(%rip\\))?," } } */
74 cond ? obj_6 = data : 0;
75 }
76
77 extern int volatile obj_7;
test_7(int data,int cond)78 int test_7 (int data, int cond)
79 {
80 /* should not reread obj */
81 /* { dg-final { scan-assembler "movl\[ \t\]\[^,\]+, _?obj_7(\\(%rip\\))?" } } */
82 /* { dg-final { scan-assembler-not "movl\[ \t\]_?obj_7(\\(%rip\\))?," } } */
83 return cond ? obj_7 = data : 0;
84 }
85
86 extern int volatile obj_8;
test_8(int cond)87 int test_8 (int cond)
88 {
89 /* should not reread obj */
90 /* { dg-final { scan-assembler "movl\[ \t\]\[^,\]+, _?obj_8(\\(%rip\\))?" } } */
91 /* { dg-final { scan-assembler-not "movl\[ \t\]_?obj_8(\\(%rip\\))?," } } */
92 return cond ? obj_8 = 0 : 0;
93 }
94