aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2010-01-12 23:09:00 +0000
committerJoseph Myers <jsm28@gcc.gnu.org>2010-01-12 23:09:00 +0000
commite616f54d28182c80f9bfe10174a2a04befae62df (patch)
tree0e828be7f6462d1d72db441234272fd4b9656e59
parentb4ab701fcc8933f69f288ca434d3376026d23cc0 (diff)
downloadgcc-e616f54d28182c80f9bfe10174a2a04befae62df.zip
gcc-e616f54d28182c80f9bfe10174a2a04befae62df.tar.gz
gcc-e616f54d28182c80f9bfe10174a2a04befae62df.tar.bz2
re PR c/42708 (ICE in gimplify_expr, at gimplify.c:6993)
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
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/c-typeck.c8
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.c-torture/compile/pr42708-1.c10
4 files changed, 27 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 256e1d0..315ebee 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index dbaddd6..17bdbf9 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -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;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 4bdc481..ae31eae 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
index 0000000..9124a85
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr42708-1.c
@@ -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));
+}