From: Joseph Myers Date: Sat, 15 Sep 2012 00:29:28 +0000 (+0100) Subject: re PR c/54552 (Cast to pointer to VLA crash the compiler) X-Git-Tag: releases/gcc-4.6.4~364 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6f94de3705f5c9d76aa8b20ff5e4408380b956ff;p=thirdparty%2Fgcc.git re PR c/54552 (Cast to pointer to VLA crash the compiler) 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2fa20734ef2c..f77a5c860204 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2012-09-15 Joseph Myers + + 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 PR c/54103 diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index adb88c2e7c8d..ac37751ac268 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -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); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7ba883ab1e96..43cee8c70d59 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,4 +1,9 @@ -2012-09-14 Joseph Myers +2012-09-15 Joseph Myers + + PR c/54552 + * gcc.c-torture/compile/pr54552-1.c: New test. + +2012-09-15 Joseph Myers 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 index 000000000000..bc20053a1625 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr54552-1.c @@ -0,0 +1,8 @@ +void +f (void) +{ + unsigned n = 10; + + typedef double T[n]; + (double (*)[n])((unsigned char (*)[sizeof (T)]){ 0 }); +}