[lto] Fix handling of EH runtime types in foreach_reachable_handler

Diego Novillo dnovillo@google.com
Tue Jan 6 13:57:00 GMT 2009


When writing the EH tree out to a stream, we translate all the
original types to the corresponding runtime types using
lookup_type_for_runtime.

This means that when optimizing gimple, we cannot access the
original types in foreach_reachable_handler and its helpers, we
need to look into the translated pointer.

This fixes several tests on libstdc++.

Tested on x86_64.



	* except.c (check_handled): Handle pointers to runtime types.

testsuite/ChangeLog:

	* gcc.dg/lto/20081224_0.c: Add -fPIC.

Index: testsuite/gcc.dg/lto/20081224_0.c
===================================================================
--- testsuite/gcc.dg/lto/20081224_0.c	(revision 143097)
+++ testsuite/gcc.dg/lto/20081224_0.c	(working copy)
@@ -1,5 +1,5 @@
 /* { dg-do link } */
-/* { dg-options "{-fwhopr -shared}" } */
+/* { dg-options "{-fwhopr -shared -fPIC}" } */
 #include "20081224_0.h"
 
 extern struct foo x;
Index: except.c
===================================================================
--- except.c	(revision 143097)
+++ except.c	(working copy)
@@ -2227,8 +2227,33 @@ check_handled (tree handled, tree type)
   if (! lang_eh_type_covers)
     {
       for (t = handled; t ; t = TREE_CHAIN (t))
-	if (TREE_VALUE (t) == type)
-	  return 1;
+	{
+	  tree t1 = TREE_VALUE (t);
+	  tree t2 = type;
+
+	  /* If the types have been converted to runtime types (i.e.,
+	     when the IL is being read from disk in an LTO
+	     compilation), then T1 and T2 will be pointers to the
+	     runtime type of the form '(void *) &<runtime_type>' (See
+	     cp/except.c:build_eh_type_type).  Strip the conversion
+	     and the address.  */
+	  if (CONVERT_EXPR_P (t1))
+	    {
+	      STRIP_NOPS (t1);
+	      gcc_assert (TREE_CODE (t1) == ADDR_EXPR);
+	      t1 = TREE_OPERAND (t1, 0);
+	    }
+
+	  if (CONVERT_EXPR_P (t2))
+	    {
+	      STRIP_NOPS (t2);
+	      gcc_assert (TREE_CODE (t2) == ADDR_EXPR);
+	      t2 = TREE_OPERAND (t2, 0);
+	    }
+
+	  if (t1 == t2)
+	    return 1;
+	}
     }
   else
     {



More information about the Gcc-patches mailing list