re PR c/42708 (ICE in gimplify_expr, at gimplify.c:6993)
authorJoseph Myers <joseph@codesourcery.com>
Tue, 12 Jan 2010 23:09:00 +0000 (23:09 +0000)
committerJoseph Myers <jsm28@gcc.gnu.org>
Tue, 12 Jan 2010 23:09:00 +0000 (23:09 +0000)
PR c/42708
* c-typeck.c (build_c_cast): Fold value cast to union type before
wrapping it in a CONSTRUCTOR.

testsuite:
* gcc.c-torture/compile/pr42708-1.c: New test.

From-SVN: r155846

gcc/ChangeLog
gcc/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/pr42708-1.c [new file with mode: 0644]

index 256e1d085f25af0e72ea2317eac030a36da573f2..315ebee026f82b95cce168d8a379b608f1c84c19 100644 (file)
@@ -1,3 +1,9 @@
+2010-01-12  Joseph Myers  <joseph@codesourcery.com>
+
+       PR c/42708
+       * c-typeck.c (build_c_cast): Fold value cast to union type before
+       wrapping it in a CONSTRUCTOR.
+
 2010-01-12  Jakub Jelinek  <jakub@redhat.com>
 
        PR rtl-optimization/42699
index dbaddd684666cf22ae9d79c31f6b1b99a42fe182..17bdbf92b3b187ab00283c72d9b7bdbe466fbd0f 100644 (file)
@@ -4429,10 +4429,14 @@ build_c_cast (location_t loc, tree type, tree expr)
       if (field)
        {
          tree t;
+         bool maybe_const = true;
 
          pedwarn (loc, OPT_pedantic, "ISO C forbids casts to union type");
-         t = digest_init (loc, type,
-                          build_constructor_single (type, field, value),
+         t = c_fully_fold (value, false, &maybe_const);
+         t = build_constructor_single (type, field, t);
+         if (!maybe_const)
+           t = c_wrap_maybe_const (t, true);
+         t = digest_init (loc, type, t,
                           NULL_TREE, false, true, 0);
          TREE_CONSTANT (t) = TREE_CONSTANT (value);
          return t;
index 4bdc4819385bc36e5bf6edfa8ffa6566713c6cd4..ae31eae0e363a1d045c9615c225863f4f4850972 100644 (file)
@@ -1,3 +1,8 @@
+2010-01-12  Joseph Myers  <joseph@codesourcery.com>
+
+       PR c/42708
+       * gcc.c-torture/compile/pr42708-1.c: New test.
+
 2010-01-12  Jakub Jelinek  <jakub@redhat.com>
 
        PR debug/42662
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr42708-1.c b/gcc/testsuite/gcc.c-torture/compile/pr42708-1.c
new file mode 100644 (file)
index 0000000..9124a85
--- /dev/null
@@ -0,0 +1,10 @@
+typedef __SIZE_TYPE__ size_t;
+void *malloc(size_t);
+typedef union YYSTYPE {
+    char *id;
+}  YYSTYPE;
+extern YYSTYPE yylval;
+void yylex (int b)
+{
+  yylval = (YYSTYPE) (b ? 0 : (char *) malloc (4));
+}