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]

Fix for regression in gcc.c-torture/execute/20011114-1.c


This regression as been annoying me, so I fixed it.  In the code:

  char foo(char bar[])
  {
    return bar[1];
  }
  extern char foo(char *);
  int main(void)
  {
    if (foo("xy") != 'y')
      abort ();
    exit (0);
  }

compiled with gcc -finline-functions, inlining would cause the function
definition to be deferred, and the second declaration cause "foo" to loose
it's tree.  In the function duplicate_decls in c-decls.c, there's a memcpy
of the contents of the new definition to the old one at the end of the
function, but the tree has not been copied to the new definition in this 
case.
The following patch fixes that.  It generated no new regressions in x86 and
PowerPC.

-Corey

2001-11-30  Corey Minyard <minyard@acm.org>

	* c-cdecl.c (duplicate_decls): Copy the saved tree as well
	as the initial value if a function declaration occurs
	after the functions definition.  This solves a problem
	with testcase gcc.c-torture/execute/20011114-1.c.

Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.271
diff -u -p -r1.271 c-decl.c
--- c-decl.c	2001/11/23 02:05:08	1.271
+++ c-decl.c	2001/11/30 17:47:04
@@ -2019,7 +2019,10 @@ duplicate_decls (newdecl, olddecl, diffe
 	     DECL_INITIAL, so that we don't accidentally change function
 	     declarations into function definitions.  */
 	  if (! different_binding_level)
-	    DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
+	    {
+	      DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
+	      DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
+	    }
 	  DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl);
 	  DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
 	  if (DECL_INLINE (newdecl))

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