+2005-11-03 Andrew Pinski <pinskia@physics.uc.edu>
+
+ PR middle-end/23155
+ * gimplifier.c (gimplify_expr): Create a temporary for lvalue
+ CONSTRUCTOR.
+
2005-11-03 Daniel Berlin <dberlin@dberlin.org>
Fix PR tree-optimization/24351
*expr_p = temp;
ret = GS_OK;
}
+ /* C99 code may assign to an array in a constructed
+ structure or union, and this has undefined behavior only
+ on execution, so create a temporary if an lvalue is
+ required. */
+ else if (fallback == fb_lvalue)
+ {
+ *expr_p = get_initialized_tmp_var (*expr_p, pre_p, post_p);
+ lang_hooks.mark_addressable (*expr_p);
+ }
else
ret = GS_ALL_DONE;
break;
+2005-11-03 Andrew Pinski <pinskia@physics.uc.edu>
+
+ PR middle-end/23155
+ * g++.dg/ext/c99struct1.C: New test.
+ * gcc.dg/union-cast-1.c: New test.
+ * gcc.dg/union-cast-2.c: New test.
+ * gcc.dg/union-cast-3.c: New test.
+
2005-11-03 Andrew Pinski <pinskia@physics.uc.edu>
PR middle-end/24589
--- /dev/null
+// { dg-options "" }
+// C99 anon struct variable with array accesses.
+
+struct s { int a[1]; };
+
+void
+foo5 (void)
+{
+ ((struct s) { { 0 } }).a[0] = 1;
+}
+
+
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-std=gnu89" } */
+/* A combine of two extensions to C89 are used here.
+ First casts to unions is used.
+ Second subscripting non lvalue arrays, this is in C99. */
+
+union vx {short f[8]; int v;};
+int vec;
+
+void
+foo5 (int vec)
+{
+ ((union vx) vec).f[5] = 1;
+}
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-std=c89 -pedantic-errors" } */
+/* PR 23155
+ We should get two error messages, one about union cast
+ and the other about array access for non lvalues. */
+
+
+union vx {short f[8]; int v;};
+int vec;
+
+void
+foo5 (int vec)
+{
+ ((union vx) vec).f[5] = 1; /* { dg-error "(forbids subscripting)|(forbids casts to union type)" } */
+}
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-std=c99 -pedantic-errors" } */
+/* PR 23155
+ We should get one error messag, one about union cast. */
+
+
+union vx {short f[8]; int v;};
+int vec;
+
+void
+foo5 (int vec)
+{
+ ((union vx) vec).f[5] = 1; /* { dg-error "forbids casts to union type" } */
+}