OSDN Git Service

2005-11-03 Andrew Pinski <pinskia@physics.uc.edu>
authorpinskia <pinskia@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 3 Nov 2005 16:15:53 +0000 (16:15 +0000)
committerpinskia <pinskia@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 3 Nov 2005 16:15:53 +0000 (16:15 +0000)
        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/23155
        * gimplifier.c (gimplify_expr): Create a temporary for lvalue
        CONSTRUCTOR.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@106438 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/gimplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ext/c99struct1.C [new file with mode: 0644]
gcc/testsuite/gcc.dg/union-cast-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/union-cast-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/union-cast-3.c [new file with mode: 0644]

index a1b0097..1ab1c66 100644 (file)
@@ -1,3 +1,9 @@
+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
index 52e70bd..9e25aef 100644 (file)
@@ -4323,6 +4323,15 @@ gimplify_expr (tree *expr_p, tree *pre_p, tree *post_p,
              *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;
index ffb3ee0..9678651 100644 (file)
@@ -1,5 +1,13 @@
 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
        * gcc.c-torture/execute/zero-struct-2.c: New test.
 
diff --git a/gcc/testsuite/g++.dg/ext/c99struct1.C b/gcc/testsuite/g++.dg/ext/c99struct1.C
new file mode 100644 (file)
index 0000000..93e84b4
--- /dev/null
@@ -0,0 +1,12 @@
+// { dg-options "" }
+// C99 anon struct variable with array accesses.
+
+struct s { int a[1]; };
+
+void
+foo5 (void)
+{
+         ((struct s) { { 0 } }).a[0] = 1;
+}
+
+
diff --git a/gcc/testsuite/gcc.dg/union-cast-1.c b/gcc/testsuite/gcc.dg/union-cast-1.c
new file mode 100644 (file)
index 0000000..1d7f4d5
--- /dev/null
@@ -0,0 +1,14 @@
+/* { 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;
+}
diff --git a/gcc/testsuite/gcc.dg/union-cast-2.c b/gcc/testsuite/gcc.dg/union-cast-2.c
new file mode 100644 (file)
index 0000000..9aac5ca
--- /dev/null
@@ -0,0 +1,15 @@
+/* { 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)" } */
+}
diff --git a/gcc/testsuite/gcc.dg/union-cast-3.c b/gcc/testsuite/gcc.dg/union-cast-3.c
new file mode 100644 (file)
index 0000000..5f9b9f8
--- /dev/null
@@ -0,0 +1,14 @@
+/* { 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" } */
+}