re PR c/54552 (Cast to pointer to VLA crash the compiler)
authorJoseph Myers <joseph@codesourcery.com>
Fri, 14 Sep 2012 21:16:56 +0000 (22:16 +0100)
committerJoseph Myers <jsm28@gcc.gnu.org>
Fri, 14 Sep 2012 21:16:56 +0000 (22:16 +0100)
c:
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: r191313

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

index bd6ef8fbf98f8fdd4837e72df55e5baa21de053e..6aed2c3de847fd0f42c99a64e196362e71c848cc 100644 (file)
@@ -1,3 +1,10 @@
+2012-09-14  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-14  Joseph Myers  <joseph@codesourcery.com>
 
        PR c/54103
index 628857c38b202de8ad4b1c98c7dbcb93a3a7e585..5b4ad28587448a2b0a857b3715d39d0e15305e8a 100644 (file)
@@ -4779,8 +4779,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 4a9715ea5dbb9b65f4f1f640baa5ffb1b3d22887..cd1c5fa5cd4b0c81bd05501388056ec5b2c7c2fb 100644 (file)
@@ -1,3 +1,8 @@
+2012-09-14  Joseph Myers  <joseph@codesourcery.com>
+
+       PR c/54552
+       * gcc.c-torture/compile/pr54552-1.c: New test.
+
 2012-09-14  Marc Glisse  <marc.glisse@inria.fr>
 
        PR c++/54427
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 });
+}