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] optimization/6323



The following patch fixes optimization/6323 which as mentioned in
the PR was uncovered by my patch to re-enable builtins in g++.

The problem is the interaction between the code in duplicate_decls
attempting to re-use the anticipated builtin's DECL and the C++ tree
inliner mechanism for inlining static noreturn functions.  This
interaction is so obscure, I had great difficulty trying to generalize
the new testcase below, and can only reproduce the problem with
non-empty no-return static inline redeclarations of "exit" and
"abort"!

Rather than track down the exact DECL field that needs to be preserved
and/or erased between newdecl and olddecl, I took the cleaner approach
of just giving up attempting to re-use the original DECL in these rare
cases.

Tested against the 3.1 branch with "make bootstrap" and "make -k check"
on i686-pc-linux-gnu, using all languages except ada, with no new
regressions.  I've placed the new test case in g++.old-deja/g++.other
with all of the existing C++ builtin tests, these should all be moved
to the new dg framework eventually, but that's a task for another day
[and hopefully for someone else :>]


Ok for branch and mainline to close PR opt/6323?


2002-04-16  Roger Sayle  <roger@eyesopen.com>
	PR opt/6323
	* decl.c (duplicate_decls): Don't attempt to reuse olddecl
	when redeclaring an anticipated built-in function when the
	function types match and newdecl includes a definition.

	* g++.old-deja/g++.other/builtins10.C: New testcase.


Index: decl.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.866.2.23
diff -c -3 -p -r1.866.2.23 decl.c
*** decl.c	16 Apr 2002 03:15:54 -0000	1.866.2.23
--- decl.c	16 Apr 2002 23:27:33 -0000
*************** duplicate_decls (newdecl, olddecl)
*** 3205,3210 ****
--- 3205,3215 ----
  	  /* Replace the old RTL to avoid problems with inlining.  */
  	  SET_DECL_RTL (olddecl, DECL_RTL (newdecl));
  	}
+       else if (DECL_ANTICIPATED (olddecl)
+                && DECL_INITIAL (newdecl) != NULL_TREE)
+         /* Even if the types match, discard an anticipated built-in
+            when the redeclaration includes a definition.  */
+         return 0;

        if (DECL_THIS_STATIC (newdecl) && !DECL_THIS_STATIC (olddecl))
  	{
*** /dev/null	Thu Aug 30 14:30:55 2001
--- g++.old-deja/g++.other/builtins10.C	Tue Apr 16 20:48:28 2002
***************
*** 0 ****
--- 1,20 ----
+ // Test that static inline redeclarations of no-return builtins don't ICE.
+ // Origin: Roger Sayle  Apr 16, 2002
+ // Copyright (C) 2002 Free Software Foundation.
+
+ extern void exit(int);
+
+ namespace std
+ {
+   static inline void
+   exit (int x)
+   {
+     ::exit (x);
+   }
+ }
+
+ int main()
+ {
+   std::exit(0);
+ }
+

Roger
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833


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