]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c/54552 (Cast to pointer to VLA crash the compiler)
authorJoseph Myers <joseph@codesourcery.com>
Sat, 15 Sep 2012 00:29:28 +0000 (01:29 +0100)
committerJoseph Myers <jsm28@gcc.gnu.org>
Sat, 15 Sep 2012 00:29:28 +0000 (01:29 +0100)
PR c/54552
* c-typeck.c (c_cast_expr): When casting to a type requiring
C_MAYBE_CONST_EXPR to be created, pass the inner expression to
c_fully_fold first.

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

From-SVN: r191337

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

index 2fa20734ef2c072cd30ce2d8f62511e3f1c92d35..f77a5c8602041e66500d56e76c38821279831dbb 100644 (file)
@@ -1,3 +1,10 @@
+2012-09-15  Joseph Myers  <joseph@codesourcery.com>
+
+       PR c/54552
+       * c-typeck.c (c_cast_expr): When casting to a type requiring
+       C_MAYBE_CONST_EXPR to be created, pass the inner expression to
+       c_fully_fold first.
+
 2012-09-15  Joseph Myers  <joseph@codesourcery.com>
 
        PR c/54103
index adb88c2e7c8dcd420806358a495dedd05f6d0223..ac37751ac26820441cf693437099cb87d792f429 100644 (file)
@@ -4761,8 +4761,11 @@ c_cast_expr (location_t loc, struct c_type_name *type_name, tree expr)
   ret = build_c_cast (loc, type, expr);
   if (type_expr)
     {
+      bool inner_expr_const = true;
+      ret = c_fully_fold (ret, require_constant_value, &inner_expr_const);
       ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret), type_expr, ret);
-      C_MAYBE_CONST_EXPR_NON_CONST (ret) = !type_expr_const;
+      C_MAYBE_CONST_EXPR_NON_CONST (ret) = !(type_expr_const
+                                            && inner_expr_const);
       SET_EXPR_LOCATION (ret, loc);
     }
 
index 7ba883ab1e966b91c4c6e99021705b8055e062e4..43cee8c70d59a715b8a8a37ed80de0c19d4d6441 100644 (file)
@@ -1,4 +1,9 @@
-2012-09-14  Joseph Myers  <joseph@codesourcery.com>
+2012-09-15  Joseph Myers  <joseph@codesourcery.com>
+
+       PR c/54552
+       * gcc.c-torture/compile/pr54552-1.c: New test.
+
+2012-09-15  Joseph Myers  <joseph@codesourcery.com>
 
        PR c/54103
        * gcc.c-torture/compile/pr54103-1.c,
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr54552-1.c b/gcc/testsuite/gcc.c-torture/compile/pr54552-1.c
new file mode 100644 (file)
index 0000000..bc20053
--- /dev/null
@@ -0,0 +1,8 @@
+void
+f (void)
+{
+  unsigned n = 10;
+
+  typedef double T[n];
+  (double (*)[n])((unsigned char (*)[sizeof (T)]){ 0 });
+}