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]

[C++ PATCH] Fix 21117


I've installed this patch to fix 21117 an gimple ICE caused by a FE bug.

The problem was that the code in decl.c to set the return type to VOID, created the correct fntype straight into TREE_TYPE (decl), and then carefully ignored it when setting the exception variant
TREE_TYPE (decl)
= build_exception_variant (fntype,
TYPE_RAISES_EXCEPTIONS (fntype));


booted & tested on i686-pc-linux-gnu.

nathan
--
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

2005-10-12  Nathan Sidwell  <nathan@codesourcery.com>

	PR c++/21117
	* decl.c (check_function_type): Correctly overwrite incomplete
	return type with void type.
	* typeck.c (check_return_expr): If the function's return type is
	void, don't try and convert a return expr.

Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1431
diff -c -3 -p -r1.1431 decl.c
*** cp/decl.c	10 Oct 2005 14:41:49 -0000	1.1431
--- cp/decl.c	12 Oct 2005 16:53:25 -0000
*************** check_function_type (tree decl, tree cur
*** 10012,10036 ****
      return;
    if (!COMPLETE_OR_VOID_TYPE_P (return_type))
      {
!       error ("return type %q#T is incomplete", TREE_TYPE (fntype));
  
!       /* Make it return void instead, but don't change the
! 	 type of the DECL_RESULT, in case we have a named return value.  */
        if (TREE_CODE (fntype) == METHOD_TYPE)
! 	{
! 	  tree ctype = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype)));
! 	  TREE_TYPE (decl)
! 	    = build_method_type_directly (ctype,
! 					  void_type_node,
! 					  FUNCTION_ARG_CHAIN (decl));
! 	}
        else
! 	TREE_TYPE (decl)
! 	  = build_function_type (void_type_node,
! 				 TYPE_ARG_TYPES (TREE_TYPE (decl)));
        TREE_TYPE (decl)
  	= build_exception_variant (fntype,
! 				   TYPE_RAISES_EXCEPTIONS (fntype));
      }
    else
      abstract_virtuals_error (decl, TREE_TYPE (fntype));
--- 10012,10031 ----
      return;
    if (!COMPLETE_OR_VOID_TYPE_P (return_type))
      {
!       tree args = TYPE_ARG_TYPES (fntype);
! 	  
!       error ("return type %q#T is incomplete", return_type);
  
!       /* Make it return void instead.  */
        if (TREE_CODE (fntype) == METHOD_TYPE)
! 	fntype = build_method_type_directly (TREE_TYPE (TREE_VALUE (args)),
! 					     void_type_node,
! 					     TREE_CHAIN (args));
        else
! 	fntype = build_function_type (void_type_node, args);
        TREE_TYPE (decl)
  	= build_exception_variant (fntype,
! 				   TYPE_RAISES_EXCEPTIONS (TREE_TYPE (decl)));
      }
    else
      abstract_virtuals_error (decl, TREE_TYPE (fntype));
Index: cp/typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/typeck.c,v
retrieving revision 1.654
diff -c -3 -p -r1.654 typeck.c
*** cp/typeck.c	11 Oct 2005 20:58:44 -0000	1.654
--- cp/typeck.c	12 Oct 2005 16:53:46 -0000
*************** check_return_expr (tree retval, bool *no
*** 6326,6331 ****
--- 6325,6335 ----
        /* The type the function is declared to return.  */
        tree functype = TREE_TYPE (TREE_TYPE (current_function_decl));
  
+       /* The functype's return type will have been set to void, if it
+ 	 was an incomplete type.  Just treat this as 'return;' */
+       if (VOID_TYPE_P (functype))
+ 	return error_mark_node;
+       
        /* First convert the value to the function's return type, then
  	 to the type of return value's location to handle the
  	 case that functype is smaller than the valtype.  */
// Copyright (C) 2005 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 12 Oct 2005 <nathan@codesourcery.com>

// PR 21117:ICE after error
// Origin: Andrew Pinski <pinskia@gcc.gnu.org>

struct wxString;
struct wxString* wxGetEmptyString();

struct wxString GetHeader() // { dg-error "return type" "" }
{
  return *wxGetEmptyString();
}



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