From: Steven Bosscher Date: Sat, 11 Sep 2004 19:48:58 +0000 (+0000) Subject: re PR c++/17412 (tree check failure in fold-const) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=05cf561db41aa56f53e0c77b4489987f25fe2efa;p=gcc.git re PR c++/17412 (tree check failure in fold-const) PR c++/17412 * fold-const.c (fold): Do not try to fold the operand of a CLEANUP_POINT_EXPR if that operand does itself not have any operands. testsuite/ * g++.dg/parse/break-in-for.C: New test. PR middle-end/17417 * langhooks.c (lhd_decl_printable_name): Make sure that this function is called with is a decl node that has an identifier. * tree-pretty-print.c (dump_function_name): New function to wrap PRINT_FUNCTION_NAME and dump_decl_name. (print_call_name): Use it. From-SVN: r87363 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d584ea6e0d3..c469e2712bd 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,17 @@ +2004-09-11 Steven Bosscher + + PR c++/17412 + * fold-const.c (fold): Do not try to fold the operand of a + CLEANUP_POINT_EXPR if that operand does itself not have any + operands. + + PR middle-end/17417 + * langhooks.c (lhd_decl_printable_name): Make sure that this + function is called with is a decl node that has an identifier. + * tree-pretty-print.c (dump_function_name): New function to + wrap PRINT_FUNCTION_NAME and dump_decl_name. + (print_call_name): Use it. + 2004-09-11 Mohan Embar * ggc-none.c: Include "bconfig.h" if -DGENERATOR_FILE, diff --git a/gcc/fold-const.c b/gcc/fold-const.c index d0720e9f023..31bf7fd649f 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -8946,29 +8946,31 @@ fold (tree expr) TREE_OPERAND (arg0, 1))))); return t; + case CLEANUP_POINT_EXPR: /* Pull arithmetic ops out of the CLEANUP_POINT_EXPR where appropriate. */ - case CLEANUP_POINT_EXPR: if (! has_cleanups (arg0)) return TREE_OPERAND (t, 0); { enum tree_code code0 = TREE_CODE (arg0); int kind0 = TREE_CODE_CLASS (code0); - tree arg00 = TREE_OPERAND (arg0, 0); - tree arg01; if (kind0 == '1' || code0 == TRUTH_NOT_EXPR) - return fold (build1 (code0, type, - fold (build1 (CLEANUP_POINT_EXPR, - TREE_TYPE (arg00), arg00)))); + { + tree arg00 = TREE_OPERAND (arg0, 0); + return fold (build1 (code0, type, + fold (build1 (CLEANUP_POINT_EXPR, + TREE_TYPE (arg00), arg00)))); + } if (kind0 == '<' || kind0 == '2' || code0 == TRUTH_ANDIF_EXPR || code0 == TRUTH_ORIF_EXPR || code0 == TRUTH_AND_EXPR || code0 == TRUTH_OR_EXPR || code0 == TRUTH_XOR_EXPR) { - arg01 = TREE_OPERAND (arg0, 1); + tree arg00 = TREE_OPERAND (arg0, 0); + tree arg01 = TREE_OPERAND (arg0, 1); if (TREE_CONSTANT (arg00) || ((code0 == TRUTH_ANDIF_EXPR || code0 == TRUTH_ORIF_EXPR) diff --git a/gcc/langhooks.c b/gcc/langhooks.c index 9f0a236e8d3..309bef57794 100644 --- a/gcc/langhooks.c +++ b/gcc/langhooks.c @@ -267,6 +267,7 @@ lhd_expand_decl (tree ARG_UNUSED (t)) const char * lhd_decl_printable_name (tree decl, int ARG_UNUSED (verbosity)) { + gcc_assert (decl && DECL_NAME (decl)); return IDENTIFIER_POINTER (DECL_NAME (decl)); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3727d52ce4d..27c1ecf8644 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2004-09-11 Steven Bosscher + + * g++.dg/parse/break-in-for.C: New test. + 2004-09-11 Jakub Jelinek * gcc.dg/tree-ssa/20040911-1.c: New test. diff --git a/gcc/testsuite/g++.dg/parse/break-in-for.C b/gcc/testsuite/g++.dg/parse/break-in-for.C new file mode 100644 index 00000000000..92cac42417e --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/break-in-for.C @@ -0,0 +1,11 @@ +/* PR17412 + fold-const would try to fold the operands of the break statement. */ +/* { dg-do compile } */ + + +void foo () +{ + for (;;) + for (;;({break;})); +} + diff --git a/gcc/tree-pretty-print.c b/gcc/tree-pretty-print.c index 5aa174369bb..d0b9aedc156 100644 --- a/gcc/tree-pretty-print.c +++ b/gcc/tree-pretty-print.c @@ -172,6 +172,17 @@ dump_decl_name (pretty_printer *buffer, tree node, int flags) } } +/* Like the above, but used for pretty printing function calls. */ + +static void +dump_function_name (pretty_printer *buffer, tree node) +{ + if (DECL_NAME (node)) + PRINT_FUNCTION_NAME (node); + else + dump_decl_name (buffer, node, 0); +} + /* Dump a function declaration. NODE is the FUNCTION_TYPE. BUFFER, SPC and FLAGS are as in dump_generic_node. */ @@ -1892,7 +1903,7 @@ print_call_name (pretty_printer *buffer, tree node) { case VAR_DECL: case PARM_DECL: - PRINT_FUNCTION_NAME (op0); + dump_function_name (buffer, op0); break; case ADDR_EXPR: @@ -1914,7 +1925,7 @@ print_call_name (pretty_printer *buffer, tree node) /* The function is a pointer contained in a structure. */ if (TREE_CODE (TREE_OPERAND (op0, 0)) == INDIRECT_REF || TREE_CODE (TREE_OPERAND (op0, 0)) == VAR_DECL) - PRINT_FUNCTION_NAME (TREE_OPERAND (op0, 1)); + dump_function_name (buffer, TREE_OPERAND (op0, 1)); else dump_generic_node (buffer, TREE_OPERAND (op0, 0), 0, 0, false); /* else @@ -1925,7 +1936,7 @@ print_call_name (pretty_printer *buffer, tree node) case ARRAY_REF: if (TREE_CODE (TREE_OPERAND (op0, 0)) == VAR_DECL) - PRINT_FUNCTION_NAME (TREE_OPERAND (op0, 0)); + dump_function_name (buffer, TREE_OPERAND (op0, 0)); else dump_generic_node (buffer, op0, 0, 0, false); break;