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] Fix PR c/5163 (take 2)


On Fri, Dec 21, 2001 at 02:32:53PM -0800, Richard Henderson wrote:
> On Fri, Dec 21, 2001 at 11:43:57PM +0100, Jakub Jelinek wrote:
> > (or why is actually a DECL_EXTERNAL ever marked DECL_INLINE).
> 
> I'm sure that this is part of the bug.  While "extern inline"
> has a defined meaning, "extern void bar(int)" should never be
> marked inline.

The following patch does that. The DECL_INITIAL (olddecl) check is still
needed, as shown by the second test case (where the first declaration
is marked inline explicitely).
Bootstrapped, no regressions.
Ok to commit?

2001-12-22  Jakub Jelinek  <jakub@redhat.com>

	* c-decl.c (duplicate_decls): Set DECL_INLINE if not
	function definition and olddecl was DECL_INLINE.
	Don't set abstract origin to origin if olddecl from different
	binding level is not function definition.
	(grokdeclarator): Set DECL_INLINE with -finline-functions only for
	function definitions.
	Fixes PR c/5163.

	* gcc.dg/20011221-1.c: New test.
	* gcc.dg/20011221-2.c: New test.

--- gcc/c-decl.c.jj	Tue Dec 18 01:28:02 2001
+++ gcc/c-decl.c	Sat Dec 22 13:10:29 2001
@@ -1979,6 +1979,9 @@ duplicate_decls (newdecl, olddecl, diffe
 
 	  DECL_DECLARED_INLINE_P (newdecl) = DECL_DECLARED_INLINE_P (olddecl);
 
+	  if (! new_is_definition && DECL_INLINE (olddecl))
+	    DECL_INLINE (newdecl) = 1;
+
 	  DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
 	    = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
 	}
@@ -2019,7 +2022,7 @@ duplicate_decls (newdecl, olddecl, diffe
 	  DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
 	  if (DECL_INLINE (newdecl))
 	    DECL_ABSTRACT_ORIGIN (newdecl)
-	      = (different_binding_level
+	      = ((different_binding_level && DECL_INITIAL (olddecl))
 		 ? DECL_ORIGIN (olddecl)
 		 : DECL_ABSTRACT_ORIGIN (olddecl));
 	}
@@ -5055,10 +5058,11 @@ grokdeclarator (declarator, declspecs, d
 	    if (specbits & (1 << (int) RID_EXTERN))
 	      current_extern_inline = 1;
 	  }
-	/* If -finline-functions, assume it can be inlined.  This does
-	   two things: let the function be deferred until it is actually
-	   needed, and let dwarf2 know that the function is inlinable.  */
-	else if (flag_inline_trees == 2)
+	/* If -finline-functions, assume it can be inlined if it is a function
+	   definition.  This does two things: let the function be deferred
+	   until it is actually needed, and let dwarf2 know that the function
+	   is inlinable.  */
+	else if (flag_inline_trees == 2 && initialized)
 	  {
 	    DECL_INLINE (decl) = 1;
 	    DECL_DECLARED_INLINE_P (decl) = 0;
--- gcc/testsuite/gcc.dg/20011221-1.c.jj	Sat Dec 22 00:18:38 2001
+++ gcc/testsuite/gcc.dg/20011221-1.c	Sat Dec 22 00:29:00 2001
@@ -0,0 +1,13 @@
+/* Origin: PR c/5163 from aj@suse.de.  */
+/* { dg-do compile } */
+/* { dg-options "-O3 -g" } */
+
+extern int bar (int);
+
+int
+foo (void)
+{
+  extern int bar (int);
+  
+  return bar (5);
+}
--- gcc/testsuite/gcc.dg/20011221-2.c.jj	Sat Dec 22 13:19:15 2001
+++ gcc/testsuite/gcc.dg/20011221-2.c	Sat Dec 22 13:17:32 2001
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -g" } */
+
+extern inline int bar (int);
+
+int
+foo (void)
+{
+  extern int bar (int);
+  
+  return bar (5);
+}


	Jakub


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