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]

(C++) patch for EH with -fno-rtti


This patch changes the compiler to use the same EH matching mechanisms
whether or not you compile with -fno-rtti; now, the only effect of
-fno-rtti is that the vtable slots used by typeid and dynamic_cast won't be
filled in, and so typeinfo stuff will only be emitted when required by EH.

It also fixes a bug that made throws inefficient; we were looking at the
vtable for a thrown object to find its typeinfo, but we know its type
because we just created it.

1999-09-29  Jason Merrill  <jason@yorick.cygnus.com>

	Support normal type_info-based EH mechanisms with -fno-rtti.
	* except.c (build_eh_type_type): Remove special -fno-rtti handling.
	(build_eh_type_type_ref): Likewise.
	(build_eh_type): Remove.
	(expand_throw): Call build_eh_type_type, not build_eh_type.
	* decl2.c (import_export_decl): Don't associate the tinfo fn with
	the vtable if -fno-rtti.
	* decl.c (init_decl_processing): Always init_rtti_processing.

	* rtti.c (get_typeid): Don't complain about -fno-rtti.

Index: decl.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/decl.c,v
retrieving revision 1.473
diff -c -p -r1.473 decl.c
*** decl.c	1999/09/29 22:52:52	1.473
--- decl.c	1999/09/30 00:30:44
*************** init_decl_processing ()
*** 6330,6337 ****
    init_class_processing ();
    init_init_processing ();
    init_search_processing ();
!   if (flag_rtti)
!     init_rtti_processing ();
  
    if (flag_exceptions)
      init_exception_processing ();
--- 6330,6336 ----
    init_class_processing ();
    init_init_processing ();
    init_search_processing ();
!   init_rtti_processing ();
  
    if (flag_exceptions)
      init_exception_processing ();
Index: decl2.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/decl2.c,v
retrieving revision 1.268
diff -c -p -r1.268 decl2.c
*** decl2.c	1999/09/29 08:06:20	1.268
--- decl2.c	1999/09/30 00:30:44
*************** import_export_decl (decl)
*** 2685,2690 ****
--- 2685,2694 ----
  
        if (IS_AGGR_TYPE (ctype) && CLASSTYPE_INTERFACE_KNOWN (ctype)
  	  && TYPE_VIRTUAL_P (ctype)
+ 	  /* If -fno-rtti, we're not necessarily emitting this stuff with
+ 	     the class, so go ahead and emit it now.  This can happen
+ 	     when a class is used in exception handling.  */
+ 	  && flag_rtti
  	  /* If the type is a cv-qualified variant of a type, then we
  	     must emit the tinfo function in this translation unit
  	     since it will not be emitted when the vtable for the type
Index: except.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/except.c,v
retrieving revision 1.84
diff -c -p -r1.84 except.c
*** except.c	1999/09/27 01:27:17	1.84
--- except.c	1999/09/30 00:30:44
*************** Boston, MA 02111-1307, USA.  */
*** 38,44 ****
  
  static void push_eh_cleanup PROTO((void));
  static tree build_eh_type_type PROTO((tree));
- static tree build_eh_type PROTO((tree));
  static tree call_eh_info PROTO((void));
  static void push_eh_info PROTO((void));
  static tree get_eh_info PROTO((void));
--- 38,43 ----
*************** static tree
*** 333,341 ****
  build_eh_type_type (type)
       tree type;
  {
-   const char *typestring;
-   tree exp;
- 
    if (type == error_mark_node)
      return error_mark_node;
  
--- 332,337 ----
*************** build_eh_type_type (type)
*** 345,367 ****
  
    /* Peel off cv qualifiers.  */
    type = TYPE_MAIN_VARIANT (type);
- 
-   if (flag_rtti)
-     return build1 (ADDR_EXPR, ptr_type_node, get_typeid_1 (type));
  
!   typestring = build_overload_name (type, 1, 1);
!   exp = combine_strings (build_string (strlen (typestring)+1, typestring));
!   return build1 (ADDR_EXPR, ptr_type_node, exp);
  }
  
! /* Build the address of a runtime type for use in the runtime matching
!    field of the new exception model */
  
  static tree
  build_eh_type_type_ref (type)
       tree type;
  {
-   const char *typestring;
    tree exp;
  
    if (type == error_mark_node)
--- 341,357 ----
  
    /* Peel off cv qualifiers.  */
    type = TYPE_MAIN_VARIANT (type);
  
!   return build1 (ADDR_EXPR, ptr_type_node, get_typeid_1 (type));
  }
  
! /* Build the address of a typeinfo function for use in the runtime
!    matching field of the new exception model */
  
  static tree
  build_eh_type_type_ref (type)
       tree type;
  {
    tree exp;
  
    if (type == error_mark_node)
*************** build_eh_type_type_ref (type)
*** 374,414 ****
    /* Peel off cv qualifiers.  */
    type = TYPE_MAIN_VARIANT (type);
  
!   push_permanent_obstack ();
  
-   if (flag_rtti)
-     {
-       exp = get_tinfo_fn (type);
-       TREE_USED (exp) = 1;
-       mark_inline_for_output (exp);
-       exp = build1 (ADDR_EXPR, ptr_type_node, exp);
-     }
-   else
-     {
-       typestring = build_overload_name (type, 1, 1);
-       exp = combine_strings (build_string (strlen (typestring)+1, typestring));
-       exp = build1 (ADDR_EXPR, ptr_type_node, exp);
-     }
-   pop_obstacks ();
    return (exp);
  }
  
- 
- /* Build a type value for use at runtime for a exp that is thrown or
-    matched against by the exception handling system.  */
- 
- static tree
- build_eh_type (exp)
-      tree exp;
- {
-   if (flag_rtti)
-     {
-       exp = build_typeid (exp);
-       return build1 (ADDR_EXPR, ptr_type_node, exp);
-     }
-   return build_eh_type_type (TREE_TYPE (exp));
- }
- 
  /* This routine is called to mark all the symbols representing runtime
     type functions in the exception table as haveing been referenced.
     This will make sure code is emitted for them. Called from finish_file. */
--- 364,375 ----
    /* Peel off cv qualifiers.  */
    type = TYPE_MAIN_VARIANT (type);
  
!   exp = get_tinfo_fn (type);
!   exp = build1 (ADDR_EXPR, ptr_type_node, exp);
  
    return (exp);
  }
  
  /* This routine is called to mark all the symbols representing runtime
     type functions in the exception table as haveing been referenced.
     This will make sure code is emitted for them. Called from finish_file. */
*************** expand_throw (exp)
*** 859,865 ****
  	     (NULL_TREE, integer_type_node, void_list_node))));
  
        if (TYPE_PTR_P (TREE_TYPE (exp)))
! 	throw_type = build_eh_type (exp);
        else
  	{
  	  tree object, ptr;
--- 820,826 ----
  	     (NULL_TREE, integer_type_node, void_list_node))));
  
        if (TYPE_PTR_P (TREE_TYPE (exp)))
! 	throw_type = build_eh_type_type (TREE_TYPE (exp));
        else
  	{
  	  tree object, ptr;
*************** expand_throw (exp)
*** 907,913 ****
  	  finish_cleanup_try_block (try_block);
  	  finish_cleanup (build_terminate_handler (), try_block);
  
! 	  throw_type = build_eh_type (object);
  
  	  if (TYPE_HAS_DESTRUCTOR (TREE_TYPE (object)))
  	    {
--- 868,874 ----
  	  finish_cleanup_try_block (try_block);
  	  finish_cleanup (build_terminate_handler (), try_block);
  
! 	  throw_type = build_eh_type_type (TREE_TYPE (object));
  
  	  if (TYPE_HAS_DESTRUCTOR (TREE_TYPE (object)))
  	    {
Index: rtti.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/rtti.c,v
retrieving revision 1.42
diff -c -p -r1.42 rtti.c
*** rtti.c	1999/09/21 14:40:12	1.42
--- rtti.c	1999/09/30 00:30:44
*************** get_typeid (type)
*** 424,432 ****
        return error_mark_node;
      }
    
-   if (! flag_rtti)
-     error ("requesting typeid with -fno-rtti");
- 
    if (processing_template_decl)
      return build_min_nt (TYPEID_EXPR, type);
  
--- 424,429 ----


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