This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Avoid -fcompare-debug differences caused by the inliner (PR tree-optimization/42645)


Hi!

On the testcases below which lack return stmt -fcompare-debug fails, because
remap_ssa_name called indirectly from copy_debug_stmt creates a SSA_NAME
which obviously for -g0 isn't created, and differences in SSA_NAME versions
are known to cause code differences.  On these testcases remap_decl fails
(returns just the passed in decl and sets processing_debug_stmt = -1,
so the created SSA_NAME is completely useless, as the debug stmt is
immediately reset, but even if remap_decl didn't fail, we don't want to
create it.

Bootstrapped/regtested on x86_64-linux, additionally tested with assert
on cc1files/{MICO,FF3D,TRAMP3D} to make sure this sort of thing doesn't
happen very often on real-world code (it didn't hit at all, except for
the 2 testcases from this PR).

Ok for trunk?

2010-01-11  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/42645
	* tree-inline.c (processing_debug_stmt): Move earlier.
	(remap_ssa_name): If processing_debug_stmt and name wasn't found in
	decl_map, set processing_debug_stmt to -1 and return name without
	any remapping.

	* g++.dg/other/pr42645-1.C: New test.
	* g++.dg/other/pr42645-2.C: New test.

--- gcc/tree-inline.c.jj	2010-01-08 20:48:10.000000000 +0100
+++ gcc/tree-inline.c	2010-01-11 12:56:46.000000000 +0100
@@ -171,6 +171,12 @@ insert_debug_decl_map (copy_body_data *i
   *pointer_map_insert (id->debug_map, key) = value;
 }
 
+/* If nonzero, we're remapping the contents of inlined debug
+   statements.  If negative, an error has occurred, such as a
+   reference to a variable that isn't available in the inlined
+   context.  */
+int processing_debug_stmt = 0;
+
 /* Construct new SSA name for old NAME. ID is the inline context.  */
 
 static tree
@@ -185,6 +191,12 @@ remap_ssa_name (tree name, copy_body_dat
   if (n)
     return unshare_expr (*n);
 
+  if (processing_debug_stmt)
+    {
+      processing_debug_stmt = -1;
+      return name;
+    }
+
   /* Do not set DEF_STMT yet as statement is not copied yet. We do that
      in copy_bb.  */
   new_tree = remap_decl (SSA_NAME_VAR (name), id);
@@ -244,12 +256,6 @@ remap_ssa_name (tree name, copy_body_dat
   return new_tree;
 }
 
-/* If nonzero, we're remapping the contents of inlined debug
-   statements.  If negative, an error has occurred, such as a
-   reference to a variable that isn't available in the inlined
-   context.  */
-int processing_debug_stmt = 0;
-
 /* Remap DECL during the copying of the BLOCK tree for the function.  */
 
 tree
--- gcc/testsuite/g++.dg/other/pr42645-1.C.jj	2010-01-11 12:59:50.000000000 +0100
+++ gcc/testsuite/g++.dg/other/pr42645-1.C	2010-01-11 13:00:40.000000000 +0100
@@ -0,0 +1,26 @@
+// PR tree-optimization/42645
+// { dg-do compile }
+// { dg-options "-fcompare-debug -O1" }
+
+extern void foo ();
+
+struct S
+{
+  struct T
+  {
+    int t1;
+    char t2[4];
+    T *t3;
+  } t;
+  int m1 () const { return t.t3[0].t1; }
+  char *m2 () { foo (); }
+  void m3 (int x) { char *m = m2 (); if (m1 () > 0 && x > 0); }
+  void m4 () { if (m1 () > 0) for (int i = 0; i < 4; i++) t.t2[i] = 0; }
+};
+
+void
+f (S *a)
+{
+  a->m3 (0);
+  a->m4 ();
+}
--- gcc/testsuite/g++.dg/other/pr42645-2.C.jj	2010-01-11 12:59:53.000000000 +0100
+++ gcc/testsuite/g++.dg/other/pr42645-2.C	2010-01-11 13:00:55.000000000 +0100
@@ -0,0 +1,34 @@
+// PR tree-optimization/42645
+// { dg-do compile }
+// { dg-options "-fcompare-debug -O1" }
+
+struct C
+{
+  bool b;
+  C ();
+};
+
+static inline C *foo () {}
+
+extern void f4 ();
+
+static inline int
+f3 ()
+{
+  f4 ();
+}
+
+static inline void
+f2 (bool b)
+{
+  int tmp = f3 ();
+  if (C ().b && b)
+    C ();
+}
+
+void
+f1 ()
+{
+  C *c = foo ();
+  f2 (c->b);
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]