[LTO][PATCH] Check for defintions in prevailing DECLs

Doug Kwan (關振德) dougkwan@google.com
Wed Nov 26 21:04:00 GMT 2008


Revised patch.

2008-11-26  Doug Kwan  <dougkwan@google.com>

cp/ChangeLog.lto:

	* tree.c (cp_reset_lang_specifics): Fix up FUNCTION_DECLs as needed.

testsuite/ChangeLog.lto:

	* g++.dg/lto/20081125.h: New.
	* g++.dg/lto/20081125_0.C: New.
	* g++.dg/lto/20081125_1.C: New.


2008/11/26 Doug Kwan (關振德) <dougkwan@google.com>:
> I have another patch being tested right now.  That patch fixes up
> FUNCTION_DECLs in cp_reset_lang_specifics.  When we reach there, we
> should have seen EOF and expanded all needs functions.  Any
> FUNCTION_DECL without a GIMPLE body can be treated as an external
> reference since an external definition must be provided somewhere else
> if the DECL is used at all.
>
> -Doug
>
> 2008/11/26 Diego Novillo <dnovillo@google.com>:
>> 2008/11/26 Rafael Espindola <espindola@google.com>:
>>
>>> You can probably just use the free_lang_specifics to set DECL_EXTERNAL
>>> and TREE_STATIC for FUNCTION_DECL depending on the existence of the
>>> body. With that we can also avoid streaming out DECL_EXTERNAL and
>>> TREE_STATIC for them.
>>
>> TREE_STATIC will already have been set correctly for such functions.
>> What I don't really care for is the combination
>> DECL_EXTERNAL+TREE_STATIC.  In principle, it makes little sense to me,
>> but I don't know if this is something specific to C++ or just an
>> oversight in the parser.
>>
>> Jason, Mark, is there a special meaning for a TREE_STATIC function
>> decl to also have DECL_EXTERNAL set?  We are seeing that in class
>> methods declarations that also include the body, like:
>>
>> class A {
>>   int foo (int x) { return x - 1; }
>> };
>>
>> I'm also not sure if we are consistent in the use of TREE_STATIC.  In
>> gimple, we generally rely on gimple_body() and/or the CFG to determine
>> if a function has a body.
>>
>>
>> Diego.
>>
>
-------------- next part --------------
Index: gcc/gcc/testsuite/g++.dg/lto/20081125.h
===================================================================
--- gcc/gcc/testsuite/g++.dg/lto/20081125.h	(revision 0)
+++ gcc/gcc/testsuite/g++.dg/lto/20081125.h	(revision 0)
@@ -0,0 +1,15 @@
+class base
+{
+ public:
+ base() {}
+ virtual ~base() {}
+ static base *factory (void);
+};
+
+class object : public base
+{
+ public:
+ object() {}
+ object (int);
+ virtual void key_method (void);
+};
Index: gcc/gcc/testsuite/g++.dg/lto/20081125_0.C
===================================================================
--- gcc/gcc/testsuite/g++.dg/lto/20081125_0.C	(revision 0)
+++ gcc/gcc/testsuite/g++.dg/lto/20081125_0.C	(revision 0)
@@ -0,0 +1,18 @@
+// { dg-do link }
+// { dg-options "{-fwhopr}" }
+#include "20081125.h"
+
+object::object (int x)
+{
+}
+
+void
+object::key_method (void)
+{
+}
+
+int
+main ()
+{
+  return 0;
+}
Index: gcc/gcc/testsuite/g++.dg/lto/20081125_1.C
===================================================================
--- gcc/gcc/testsuite/g++.dg/lto/20081125_1.C	(revision 0)
+++ gcc/gcc/testsuite/g++.dg/lto/20081125_1.C	(revision 0)
@@ -0,0 +1,7 @@
+#include "20081125.h"
+
+base *
+base::factory(void)
+{
+ return new object ();
+}
Index: gcc/gcc/cp/tree.c
===================================================================
--- gcc/gcc/cp/tree.c	(revision 142225)
+++ gcc/gcc/cp/tree.c	(working copy)
@@ -2821,6 +2821,22 @@ cp_reset_lang_specifics (tree t)
       if (mangle_decl_is_template_id (t, &template_info))
         DECL_CONTEXT (TREE_PURPOSE (template_info)) = NULL_TREE;
     }
+  /* Fix up DECLs for inlines and implicitly instantiated functions.  */
+  else if (TREE_CODE (t) == FUNCTION_DECL
+	   && !(DECL_BUILT_IN (t) || DECL_IS_BUILTIN (t))
+	   && !DECL_INTERFACE_KNOWN (t))
+    {
+      /* When we reach here,  we should have read the EOF and expanded all
+         needed functions.  */
+      gcc_assert (at_eof && !gimple_body (t)); 
+
+      /* If T is used in this translation unit at all,  the definition
+ 	 must exist somewhere else since we have decided to not emit it
+	 in this TU.  So make it an external reference.  */
+      DECL_EXTERNAL (t) = 1;
+      TREE_PUBLIC (t) = 1;
+      TREE_STATIC (t) = 0;
+    }
 }
 
 



More information about the Gcc-patches mailing list