aboutsummaryrefslogtreecommitdiffstats
path: root/main/gcc/pr57748.patch
blob: 23a87ba70509d41cc523c5853166f9489d2f8b62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57748
(comment #36, attachment 30782)

--- a/gcc/expr.c	2013-08-06 00:09:45.000000000 +0200
+++ b/gcc/expr.c	2013-09-10 08:23:09.570951685 +0200
@@ -4691,8 +4691,6 @@ expand_assignment (tree to, tree from, b
       int unsignedp;
       int volatilep = 0;
       tree tem;
-      bool misalignp;
-      rtx mem = NULL_RTX;
 
       push_temp_slots ();
       tem = get_inner_reference (to, &bitsize, &bitpos, &offset, &mode1,
@@ -4702,40 +4700,7 @@ expand_assignment (tree to, tree from, b
 	  && DECL_BIT_FIELD_TYPE (TREE_OPERAND (to, 1)))
 	get_bit_range (&bitregion_start, &bitregion_end, to, &bitpos, &offset);
 
-      /* If we are going to use store_bit_field and extract_bit_field,
-	 make sure to_rtx will be safe for multiple use.  */
-      mode = TYPE_MODE (TREE_TYPE (tem));
-      if (TREE_CODE (tem) == MEM_REF
-	  && mode != BLKmode
-	  && ((align = get_object_alignment (tem))
-	      < GET_MODE_ALIGNMENT (mode))
-	  && ((icode = optab_handler (movmisalign_optab, mode))
-	      != CODE_FOR_nothing))
-	{
-	  struct expand_operand ops[2];
-
-	  misalignp = true;
-	  to_rtx = gen_reg_rtx (mode);
-	  mem = expand_expr (tem, NULL_RTX, VOIDmode, EXPAND_WRITE);
-
-	  /* If the misaligned store doesn't overwrite all bits, perform
-	     rmw cycle on MEM.  */
-	  if (bitsize != GET_MODE_BITSIZE (mode))
-	    {
-	      create_input_operand (&ops[0], to_rtx, mode);
-	      create_fixed_operand (&ops[1], mem);
-	      /* The movmisalign<mode> pattern cannot fail, else the assignment
-		 would silently be omitted.  */
-	      expand_insn (icode, 2, ops);
-
-	      mem = copy_rtx (mem);
-	    }
-	}
-      else
-	{
-	  misalignp = false;
-	  to_rtx = expand_expr (tem, NULL_RTX, VOIDmode, EXPAND_WRITE);
-	}
+      to_rtx = expand_expr (tem, NULL_RTX, VOIDmode, EXPAND_WRITE);
 
       /* If the bitfield is volatile, we want to access it in the
 	 field's mode, not the computed mode.
@@ -4773,6 +4738,8 @@ expand_assignment (tree to, tree from, b
 	  if (MEM_P (to_rtx)
 	      && GET_MODE (to_rtx) == BLKmode
 	      && GET_MODE (XEXP (to_rtx, 0)) != VOIDmode
+	      && bitregion_start == 0
+	      && bitregion_end == 0
 	      && bitsize > 0
 	      && (bitpos % bitsize) == 0
 	      && (bitsize % GET_MODE_ALIGNMENT (mode1)) == 0
@@ -4874,17 +4841,6 @@ expand_assignment (tree to, tree from, b
 				  get_alias_set (to), nontemporal);
 	}
 
-      if (misalignp)
-	{
-	  struct expand_operand ops[2];
-
-	  create_fixed_operand (&ops[0], mem);
-	  create_input_operand (&ops[1], to_rtx, mode);
-	  /* The movmisalign<mode> pattern cannot fail, else the assignment
-	     would silently be omitted.  */
-	  expand_insn (icode, 2, ops);
-	}
-
       if (result)
 	preserve_temp_slots (result);
       pop_temp_slots ();
@@ -9905,7 +9861,7 @@ expand_expr_real_1 (tree exp, rtx target
 			  && modifier != EXPAND_STACK_PARM
 			  ? target : NULL_RTX),
 			 VOIDmode,
-			 modifier == EXPAND_SUM ? EXPAND_NORMAL : modifier);
+			 EXPAND_MEMORY);
 
 	/* If the bitfield is volatile, we want to access it in the
 	   field's mode, not the computed mode.
--- a/gcc/testsuite/gcc.dg/torture/pr57748-1.c	1970-01-01 01:00:00.000000000 +0100
+++ b/gcc/testsuite/gcc.dg/torture/pr57748-1.c	2013-09-06 08:38:03.718686940 +0200
@@ -0,0 +1,49 @@ 
+/* PR middle-end/57748 */
+/* { dg-do run } */
+/* ICE in expand_assignment:
+   misalignp == true, !MEM_P (to_rtx), offset != 0,
+   => gcc_assert (TREE_CODE (offset) == INTEGER_CST) */
+
+#include <stdlib.h>
+
+extern void abort (void);
+
+typedef long long V
+  __attribute__ ((vector_size (2 * sizeof (long long)), may_alias));
+
+typedef struct S { V a; V b[0]; } P __attribute__((aligned (1)));
+
+struct __attribute__((packed)) T { char c; P s; };
+
+void __attribute__((noinline, noclone))
+check (struct T *t)
+{
+  if (t->s.b[0][0] != 3 || t->s.b[0][1] != 4)
+    abort ();
+}
+
+int __attribute__((noinline, noclone))
+get_i (void)
+{
+  return 0;
+}
+
+void __attribute__((noinline, noclone))
+foo (P *p)
+{
+  V a = { 3, 4 };
+  int i = get_i ();
+  p->b[i] = a;
+}
+
+int
+main ()
+{
+  struct T *t = (struct T *) calloc (128, 1);
+
+  foo (&t->s);
+  check (t);
+
+  free (t);
+  return 0;
+}
--- a/gcc/testsuite/gcc.dg/torture/pr57748-2.c	1970-01-01 01:00:00.000000000 +0100
+++ b/gcc/testsuite/gcc.dg/torture/pr57748-2.c	2013-09-06 08:38:03.718686940 +0200
@@ -0,0 +1,43 @@ 
+/* PR middle-end/57748 */
+/* { dg-do run } */
+/* wrong code in expand_assignment:
+   misalignp == true, !MEM_P (to_rtx),
+   offset == 0, bitpos >= GET_MODE_PRECISION,
+   => result = NULL.  */
+
+#include <stdlib.h>
+
+extern void abort (void);
+
+typedef long long V
+  __attribute__ ((vector_size (2 * sizeof (long long)), may_alias));
+
+typedef struct S { V a; V b[0]; } P __attribute__((aligned (1)));
+
+struct __attribute__((packed)) T { char c; P s; };
+
+void __attribute__((noinline, noclone))
+check (struct T *t)
+{
+  if (t->s.b[0][0] != 3 || t->s.b[0][1] != 4)
+    abort ();
+}
+
+void __attribute__((noinline, noclone))
+foo (P *p)
+{
+  V a = { 3, 4 };
+  p->b[0] = a;
+}
+
+int
+main ()
+{
+  struct T *t = (struct T *) calloc (128, 1);
+
+  foo (&t->s);
+  check (t);
+
+  free (t);
+  return 0;
+}
--- a/gcc/testsuite/gcc.dg/torture/pr57748-3.c	1970-01-01 01:00:00.000000000 +0100
+++ b/gcc/testsuite/gcc.dg/torture/pr57748-3.c	2013-09-09 09:54:28.937891452 +0200
@@ -0,0 +1,49 @@ 
+/* PR middle-end/57748 */
+/* { dg-do run } */
+/* { dg-final { scan-assembler-not "movdqu" } } */
+/* data store race in expand_assignment:
+   misalignp == true, !MEM_P (to_rtx),
+   offset == 0, bitsize < GET_MODE_BITSIZE,
+   => rmw cycle on MEM.  */
+
+#include <stdlib.h>
+
+typedef long long V
+  __attribute__ ((vector_size (2 * sizeof (long long)), may_alias));
+
+union x
+{
+  long long a;
+  float b;
+} __attribute__((aligned (1)));
+
+struct s
+{
+  union x xx[0];
+  V x;
+} __attribute__((packed));
+
+void __attribute__((noinline, noclone))
+check (union x *xx)
+{
+  if (xx[0].b != 3.14F || xx[1].a != 0x123456789ABCDEF)
+    abort ();
+}
+
+void __attribute__((noinline, noclone))
+foo (struct s * x)
+{
+  x->xx[0].a = -1;
+  x->xx[0].b = 3.14F;
+  x->x[1] = 0x123456789ABCDEF;
+}
+
+struct s ss;
+
+int
+main ()
+{
+  foo (&ss);
+  check (ss.xx);
+  return 0;
+}
--- a/gcc/testsuite/gcc.dg/torture/pr57748-4.c	1970-01-01 01:00:00.000000000 +0100
+++ b/gcc/testsuite/gcc.dg/torture/pr57748-4.c	2013-09-10 08:36:37.182962269 +0200
@@ -0,0 +1,50 @@ 
+/* PR middle-end/57748 */
+/* { dg-do run } */
+/* { dg-final { scan-assembler-not "movdqu" } } */
+/* wrong code in expand_expr_real_1:
+   read whole structure instead of only one member.  */
+
+#include <stdlib.h>
+
+typedef long long V
+  __attribute__ ((vector_size (2 * sizeof (long long)), may_alias));
+
+union x
+{
+  long long a;
+  float b;
+} __attribute__((aligned (1)));
+
+struct s
+{
+  union x xx[0];
+  V x;
+} __attribute__((packed));
+
+void __attribute__((noinline, noclone))
+check (struct s *x)
+{
+  if (x->xx[0].b != 3.14F || x->xx[1].a != 0x123456789ABCDEF)
+    abort ();
+  if (x->xx[2].b != 3.14F || x->xx[3].a != 0x123456789ABCDEF)
+    abort ();
+}
+
+void __attribute__((noinline, noclone))
+foo (struct s * x)
+{
+  x->xx[0].a = -1;
+  x->xx[0].b = 3.14F;
+  x->x[1] = 0x123456789ABCDEF;
+}
+
+struct s ss[2];
+
+int
+main ()
+{
+  foo (ss);
+  foo (ss+1);
+  check (ss);
+  return 0;
+}