PATCH: Mark an inline function one-only if it is accessible from outside

H.J. Lu hjl.tools@gmail.com
Fri Jan 30 23:55:00 GMT 2009


On Fri, Jan 30, 2009 at 2:43 PM, Ian Lance Taylor <iant@google.com> wrote:
> "H.J. Lu" <hjl.tools@gmail.com> writes:
>
>> On Fri, Jan 30, 2009 at 7:44 AM, Ian Lance Taylor <iant@google.com> wrote:
>>> I committed this patch to the gcc-in-cxx branch.  This fixes the
>>> top-level configury to not think the c++ is missing because it was
>>> explicitly enabled.  It also comments out some code which added
>>> -fkeep-inlin-functions to stage 1.  When building with C++ this breaks
>>> the inline functions which are provided by <gmp.h>, as they wind up
>>> getting included in many .o files leading to duplicate definition
>>> errors at link time.
>>>
>>
>> I also noticed that keeping inline function led to link time error.
>> Can't we mark the kept inline function linktonce?
>
> I have no objection to that.  It would make -fkeep-inline-functions
> more useful for g++.
>

Here is a patch.


-- 
H.J.
---
gcc/

2009-01-30  H.J. Lu  <hongjiu.lu@intel.com>

	* c-decl.c (start_function): Call make_decl_one_only if an
	inline function is accessible from outside.

gcc/testsuite/

2009-01-30  H.J. Lu  <hongjiu.lu@intel.com>

	* gcc.dg/inline-33.c: New.
	* gcc.dg/inline-33a.c: Likewise.
-------------- next part --------------
gcc/

2009-01-30  H.J. Lu  <hongjiu.lu@intel.com>

	* c-decl.c (start_function): Call make_decl_one_only if an
	inline function is accessible from outside.

gcc/testsuite/

2009-01-30  H.J. Lu  <hongjiu.lu@intel.com>

	* gcc.dg/inline-33.c: New.
	* gcc.dg/inline-33a.c: Likewise.

--- gcc/c-decl.c.foo	2009-01-30 14:52:20.000000000 -0800
+++ gcc/c-decl.c	2009-01-30 15:31:58.000000000 -0800
@@ -6116,6 +6116,9 @@ start_function (struct c_declspecs *decl
 
   decl_attributes (&decl1, attributes, 0);
 
+  if (DECL_DECLARED_INLINE_P (decl1) && TREE_PUBLIC (decl1))
+    make_decl_one_only (decl1);
+
   if (DECL_DECLARED_INLINE_P (decl1)
       && DECL_UNINLINABLE (decl1)
       && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl1)))
--- gcc/testsuite/gcc.dg/inline-33.c.foo	2009-01-30 15:32:48.000000000 -0800
+++ gcc/testsuite/gcc.dg/inline-33.c	2009-01-30 15:30:32.000000000 -0800
@@ -0,0 +1,12 @@
+/* { dg-do link } */
+/* { dg-options "-std=gnu89 -pedantic-errors" } */
+/* { dg-additional-sources inline-33a.c } */
+inline int f (void) { return 0; }
+
+int
+main (void)
+{
+  extern int f();
+  extern int bar ();
+  return f () + bar ();
+}
--- gcc/testsuite/gcc.dg/inline-33a.c.foo	2009-01-30 15:32:45.000000000 -0800
+++ gcc/testsuite/gcc.dg/inline-33a.c	2009-01-30 15:33:18.000000000 -0800
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-std=gnu89 -pedantic-errors" } */
+inline int f (void) { return 0; }
+
+int
+bar (void)
+{
+  return f ();
+}


More information about the Gcc-patches mailing list