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] PR c++/10031: Exception lists on builtins


My apologies to everyone.  I thought Michael was investigating
this one, and as I was unable to reproduce the error on any of
my primary development platforms I was waiting to hear the
replies to his request for testers.

Anyway, it turns out that a cross-compiler to powerpc-linux is
able to reproduce the failure.

The problem is that C++ has two different mechanisms for specifying
the "nothrow" property on a function declaration.  The first, shared
with the C front-end, is to set the TREE_NOTHROW field on the
function declaration.  This is used by built-in functions, the
__attribute__ ((nothrow)) and by specifying "throw ()" after the
function declaration.

The second is C++'s native specification that associates with the
type of a function, the list of specific exceptions it throws.  In
this representation unspecified is a NULL_RTX, nothrow is an empty
TREE_LIST, and lists of exceptions are represented as lists of
exceptions.

Unfortunately, both built-ins and __attribute__((nothrow)) only
record their nothrow attribute in TREE_NOTHROW and don't (shouldn't!)
modify their types to set the exception list to an empty TREE_LIST.
The problem is that for builtins (i) these function types are created
in common front-end that doesn't have the notion of exception list
and (ii) may be shared between some functions that throw exceptions
and others that don't.


The one line solution is to avoid comparing exception lists when
both functions are marked nothrow...

This has been tested with the cc1plus from my cross-compiler from
i686-pc-linux-gnu to powerpc-linux.  I'm currently bootstrapping
and regression testing on i686-pc-linux-gnu native.

Could someone test this for me on an affected platform where they
can run the testsuite?  Ok for mainline and 3.3 if there are no new
regressions?


2003-03-12  Roger Sayle  <roger at eyesopen dot com>

	PR c++/10031
	* cp/decl.c (duplicate_decls): Don't compare exception lists
	when both declarations are marked nothrow.


Index: decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1018
diff -c -3 -p -r1.1018 decl.c
*** decl.c	10 Mar 2003 22:04:09 -0000	1.1018
--- decl.c	12 Mar 2003 15:29:07 -0000
*************** duplicate_decls (tree newdecl, tree oldd
*** 3425,3432 ****
        /* Do this after calling `merge_types' so that default
  	 parameters don't confuse us.  */
        else if (TREE_CODE (newdecl) == FUNCTION_DECL
! 	  && (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl))
! 	      != TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl))))
  	{
  	  TREE_TYPE (newdecl) = build_exception_variant (newtype,
  							 TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)));
--- 3425,3433 ----
        /* Do this after calling `merge_types' so that default
  	 parameters don't confuse us.  */
        else if (TREE_CODE (newdecl) == FUNCTION_DECL
! 	       && (! TREE_NOTHROW (newdecl) || ! TREE_NOTHROW (olddecl))
! 	       && (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl))
! 		   != TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl))))
  	{
  	  TREE_TYPE (newdecl) = build_exception_variant (newtype,
  							 TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)));

Roger
--
Roger Sayle,                         E-mail: roger at eyesopen dot 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]