re PR c++/17412 (tree check failure in fold-const)
authorSteven Bosscher <stevenb@suse.de>
Sat, 11 Sep 2004 19:48:58 +0000 (19:48 +0000)
committerSteven Bosscher <steven@gcc.gnu.org>
Sat, 11 Sep 2004 19:48:58 +0000 (19:48 +0000)
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

gcc/ChangeLog
gcc/fold-const.c
gcc/langhooks.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/break-in-for.C [new file with mode: 0644]
gcc/tree-pretty-print.c

index d584ea6e0d36c2a9fd25364afea4bd611eb0dd5d..c469e2712bdad8d1200ca3522a19585d5e592264 100644 (file)
@@ -1,3 +1,17 @@
+2004-09-11  Steven Bosscher  <stevenb@suse.de>
+
+       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  <gnustuff@thisiscool.com>
 
        * ggc-none.c: Include "bconfig.h" if -DGENERATOR_FILE,
index d0720e9f0239d08e07f195dd68bde5782e700c66..31bf7fd649f72d1c56c0288c0d17f380d0fd8d8c 100644 (file)
@@ -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)
index 9f0a236e8d3d3cb5576542498edf632a67f46fdd..309bef57794fbefa3bf22e319e1f1678aea3144e 100644 (file)
@@ -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));
 }
 
index 3727d52ce4d8321e95b25b7efc4415c5b2f4881f..27c1ecf8644df34d0c78f30bb103bc8961e1aeef 100644 (file)
@@ -1,3 +1,7 @@
+2004-09-11  Steven Bosscher  <stevenb@suse.de>
+
+       * g++.dg/parse/break-in-for.C: New test.
+
 2004-09-11  Jakub Jelinek  <jakub@redhat.com>
 
        * 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 (file)
index 0000000..92cac42
--- /dev/null
@@ -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;}));
+}
+
index 5aa174369bb654eb186e8bf201fb4341a002f3a4..d0b9aedc1566a8f0b487aafec090ec3b5888786e 100644 (file)
@@ -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;