[PATCH] GIMPLE_BINDs with blocks containing IMPORT_DECLs aren't useless (PR debug/39379)

Jakub Jelinek jakub@redhat.com
Thu Mar 5 12:10:00 GMT 2009


Hi!

The following testcases fail on the trunk (regression from 4.3), because
the useless pass decides to nuke GIMPLE_BINDs with BLOCKs containing needed
IMPORT_DECLs, as that block doesn't contain any gimple_bind_vars.

The following patch fixes it, bootstrapped/regtested on x86_64-linux, ok for
trunk?

2009-03-05  Jakub Jelinek  <jakub@redhat.com>

	PR debug/39379
	* tree-cfg.c (remove_useless_stmts_bind): Don't remove GIMPLE_BINDs
	with blocks containing IMPORTED_DECLs in BLOCK_VARS.

	* g++.dg/debug/dwarf2/imported-module-3.C: New test.
	* g++.dg/debug/dwarf2/imported-module-4.C: New test.

--- gcc/tree-cfg.c.jj	2009-03-02 09:45:47.000000000 +0100
+++ gcc/tree-cfg.c	2009-03-05 09:44:31.000000000 +0100
@@ -1796,9 +1796,21 @@ remove_useless_stmts_bind (gimple_stmt_i
 	  || (TREE_CODE (BLOCK_ABSTRACT_ORIGIN (block))
 	      != FUNCTION_DECL)))
     {
-      gsi_insert_seq_before (gsi, body_seq, GSI_SAME_STMT);
-      gsi_remove (gsi, false);
-      data->repeat = true;
+      tree var = NULL_TREE;
+      /* Even if there are no gimple_bind_vars, there might be other
+	 decls in BLOCK_VARS rendering the GIMPLE_BIND not useless.  */
+      if (block)
+	for (var = BLOCK_VARS (block); var; var = TREE_CHAIN (var))
+	  if (TREE_CODE (var) == IMPORTED_DECL)
+	    break;
+      if (var)
+	gsi_next (gsi);
+      else
+	{
+	  gsi_insert_seq_before (gsi, body_seq, GSI_SAME_STMT);
+	  gsi_remove (gsi, false);
+	  data->repeat = true;
+	}
     }
   else
     gsi_next (gsi);
--- gcc/testsuite/g++.dg/debug/dwarf2/imported-module-3.C.jj	2009-03-05 09:49:23.000000000 +0100
+++ gcc/testsuite/g++.dg/debug/dwarf2/imported-module-3.C	2009-03-05 09:57:15.000000000 +0100
@@ -0,0 +1,17 @@
+// PR debug/39379
+// { dg-do compile }
+// { dg-options "-g -dA" }
+// { dg-final { scan-assembler "DW_TAG_imported" }  }
+
+namespace A
+{
+  int v;
+}
+
+int
+main ()
+{
+  using namespace A;
+  v++;
+  return v - 1;
+}
--- gcc/testsuite/g++.dg/debug/dwarf2/imported-module-4.C.jj	2009-03-05 09:51:16.000000000 +0100
+++ gcc/testsuite/g++.dg/debug/dwarf2/imported-module-4.C	2009-03-05 09:57:21.000000000 +0100
@@ -0,0 +1,21 @@
+// PR debug/39379
+// { dg-do compile }
+// { dg-options "-g -dA" }
+// { dg-final { scan-assembler "DW_TAG_imported" }  }
+
+namespace A
+{
+  int v;
+}
+
+int
+f ()
+{
+  int i;
+  {
+    using namespace A;
+    v++;
+    i = v - 1;
+  }
+  return i;
+}

	Jakub



More information about the Gcc-patches mailing list