This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C PATCH] Fix error-recovery with variable-sized compound literals (PR c/68090)
- From: Marek Polacek <polacek at redhat dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>, Joseph Myers <joseph at codesourcery dot com>
- Date: Thu, 5 Nov 2015 18:30:25 +0100
- Subject: [C PATCH] Fix error-recovery with variable-sized compound literals (PR c/68090)
- Authentication-results: sourceware.org; auth=none
This fixes an error-recovery problem, where we were trying to build
a C_MAYBE_CONST_EXPR even though the type is invalid. I think let's
just skip this for error_mark_nodes.
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2015-11-05 Marek Polacek <polacek@redhat.com>
PR c/68090
* c-parser.c (c_parser_postfix_expression_after_paren_type): Don't
deal with pre-evaluation on invalid types.
* gcc.dg/pr68090.c: New test.
diff --git gcc/c/c-parser.c gcc/c/c-parser.c
index ab324d3..e2f55b3 100644
--- gcc/c/c-parser.c
+++ gcc/c/c-parser.c
@@ -7855,7 +7855,7 @@ c_parser_postfix_expression_after_paren_type (c_parser *parser,
expr.value = build_compound_literal (start_loc, type, init.value, non_const);
expr.original_code = ERROR_MARK;
expr.original_type = NULL;
- if (type_expr)
+ if (type != error_mark_node && type_expr)
{
if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR)
{
diff --git gcc/testsuite/gcc.dg/pr68090.c gcc/testsuite/gcc.dg/pr68090.c
index e69de29..87b3b93 100644
--- gcc/testsuite/gcc.dg/pr68090.c
+++ gcc/testsuite/gcc.dg/pr68090.c
@@ -0,0 +1,13 @@
+/* PR c/68090 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+void
+fn (int i)
+{
+ (int[(0, 1)]) { 0 }; /* { dg-error "compound literal has variable size" } */
+ (int[i]) { 0 }; /* { dg-error "compound literal has variable size" } */
+ (int[(0, i)]) { 0 }; /* { dg-error "compound literal has variable size" } */
+ (int [][i]){ 0 }; /* { dg-error "compound literal has variable size" } */
+ (int [][(1, 2)]){ 0 }; /* { dg-error "compound literal has variable size" } */
+}
Marek