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]

C++ PATCH for tree-optimization/62091


The C++ front end already means to clear DECL_EXTERNAL on callable functions, we just need to update that for devirtualization.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit a87e57625b130bb9e1fec2130643a4e5d7a3b807
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Aug 19 13:52:25 2014 -0400

    	PR tree-optimization/62091
    	* decl2.c (decl_needed_p): Return true for virtual functions when
    	devirtualizing.

diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index de28cb7..63583a8 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -1975,6 +1975,11 @@ decl_needed_p (tree decl)
   if (flag_keep_inline_dllexport
       && lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl)))
     return true;
+  /* Virtual functions might be needed for devirtualization.  */
+  if (flag_devirtualize
+      && TREE_CODE (decl) == FUNCTION_DECL
+      && DECL_VIRTUAL_P (decl))
+    return true;
   /* Otherwise, DECL does not need to be emitted -- yet.  A subsequent
      reference to DECL might cause it to be emitted later.  */
   return false;
diff --git a/gcc/testsuite/g++.dg/ipa/devirt-38.C b/gcc/testsuite/g++.dg/ipa/devirt-38.C
index be8cbdf..2d95bf7 100644
--- a/gcc/testsuite/g++.dg/ipa/devirt-38.C
+++ b/gcc/testsuite/g++.dg/ipa/devirt-38.C
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2"  } */
+/* { dg-options "-O2 -fdump-tree-ccp1"  } */
 class SnmpSyntax
 {
 public:
@@ -27,4 +27,5 @@ void fn1 ()
         c.m_fn1 ();
       }
 }
-// Devirtualization to A::m_fn1 would be possible, but we can not do it at the moment
+/* { dg-final { scan-tree-dump-not "OBJ_TYPE_REF" "ccp1"  } } */
+/* { dg-final { cleanup-tree-dump "ccp1" } } */

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