enable-checking: error_mark accessed as type

Martin v. Loewis martin@mira.isdn.cs.tu-berlin.de
Tue Mar 16 01:25:00 GMT 1999


> In most cases, if we got an error we aren't interested in doing anything
> else.  For the NEW_EXPR stuff, expand_expr should be fixed to handle
> error_mark_node properly.

Ok. Here is the next revision of this patch.

Martin

1999-03-15  Martin von Löwis  <loewis@informatik.hu-berlin.de>

	* parse.y (named_complex_class_head_sans_basetype): 
	Push std_node for error_mark_node.
	(maybe_base_class_list): Likewise.

	* decl.c (start_decl): Check for error_mark_node as a type.
	Detected by g++.brendan/array-refs.C.
	(start_decl_1): Likewise. Detected by g++.bugs/900322_01.C.
	(maybe_build_cleanup_1): Likewise. Detected by
	g++.jason/incomplete1.C.

	* tree.c (build_dummy_object): Use void_zero_node instead of the
	error_mark_node
	(is_dummy_object): Check for such a node.  Detected by
	g++.bob/inherit1.C

Index: decl.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/decl.c,v
retrieving revision 1.322
diff -c -p -r1.322 decl.c
*** decl.c	1999/03/13 01:16:31	1.322
--- decl.c	1999/03/16 08:46:53
*************** start_decl (declarator, declspecs, initi
*** 6873,6880 ****
--- 6873,6884 ----
  
    type = TREE_TYPE (decl);
  
+   if (type == error_mark_node)
+     return NULL_TREE;
+ 
    /* Don't lose if destructors must be executed at file-level.  */
    if (! processing_template_decl && TREE_STATIC (decl)
+       && type != error_mark_node
        && TYPE_NEEDS_DESTRUCTOR (complete_type (type))
        && !TREE_PERMANENT (decl))
      {
*************** start_decl_1 (decl)
*** 7119,7124 ****
--- 7123,7131 ----
    tree type = TREE_TYPE (decl);
    int initialized = (DECL_INITIAL (decl) != NULL_TREE);
  
+   if (type == error_mark_node)
+     return;
+ 
    /* If this type of object needs a cleanup, and control may
       jump past it, make a new binding level so that it is cleaned
       up only when it is initialized first.  */
*************** start_decl_1 (decl)
*** 7133,7141 ****
      {
        /* Don't allow initializations for incomplete types except for
  	 arrays which might be completed by the initialization.  */
!       if (type == error_mark_node)
! 	;			/* Don't complain again.  */
!       else if (TYPE_SIZE (complete_type (type)) != NULL_TREE)
  	;			/* A complete type is ok.  */
        else if (TREE_CODE (type) != ARRAY_TYPE)
  	{
--- 7140,7146 ----
      {
        /* Don't allow initializations for incomplete types except for
  	 arrays which might be completed by the initialization.  */
!       if (TYPE_SIZE (complete_type (type)) != NULL_TREE)
  	;			/* A complete type is ok.  */
        else if (TREE_CODE (type) != ARRAY_TYPE)
  	{
*************** maybe_build_cleanup_1 (decl, auto_delete
*** 14317,14323 ****
       tree decl, auto_delete;
  {
    tree type = TREE_TYPE (decl);
!   if (TYPE_NEEDS_DESTRUCTOR (type))
      {
        int temp = 0, flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR;
        tree rval;
--- 14322,14328 ----
       tree decl, auto_delete;
  {
    tree type = TREE_TYPE (decl);
!   if (type != error_mark_node && TYPE_NEEDS_DESTRUCTOR (type))
      {
        int temp = 0, flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR;
        tree rval;
Index: parse.y
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/parse.y,v
retrieving revision 1.108
diff -c -p -r1.108 parse.y
*** parse.y	1999/03/09 23:02:38	1.108
--- parse.y	1999/03/16 08:47:38
***************
*** 1,5 ****
  /* YACC parser for C++ syntax.
!    Copyright (C) 1988, 89, 93-97, 1998 Free Software Foundation, Inc.
     Hacked by Michael Tiemann (tiemann@cygnus.com)
  
  This file is part of GNU CC.
--- 1,5 ----
  /* YACC parser for C++ syntax.
!    Copyright (C) 1988, 89, 93-98, 1999 Free Software Foundation, Inc.
     Hacked by Michael Tiemann (tiemann@cygnus.com)
  
  This file is part of GNU CC.
*************** named_class_head:
*** 2243,2269 ****
                      xref_basetypes (current_aggr, $1, $<ttype>2, $3); 
  		}
  	| named_complex_class_head_sans_basetype 
!                 { push_scope (CP_DECL_CONTEXT ($1)); }
  	  maybe_base_class_list
  		{ 
!                   pop_scope (CP_DECL_CONTEXT ($1));
! 		  $$ = TREE_TYPE ($1);
! 		  if (current_aggr == union_type_node
! 		      && TREE_CODE ($$) != UNION_TYPE)
! 		    cp_pedwarn ("`union' tag used in declaring `%#T'", $$);
! 		  else if (TREE_CODE ($$) == UNION_TYPE
! 			   && current_aggr != union_type_node)
! 		    cp_pedwarn ("non-`union' tag used in declaring `%#T'", $$);
! 		  else if (TREE_CODE ($$) == RECORD_TYPE)
! 		    /* We might be specializing a template with a different
! 		       class-key; deal.  */
! 		    CLASSTYPE_DECLARED_CLASS ($$) = (current_aggr
! 						     == class_type_node);
! 		  if ($3)
  		    {
! 		      maybe_process_partial_specialization ($$);
! 		      xref_basetypes (current_aggr, $1, $$, $3); 
  		    }
  		}
  	;
  
--- 2243,2280 ----
                      xref_basetypes (current_aggr, $1, $<ttype>2, $3); 
  		}
  	| named_complex_class_head_sans_basetype 
!                 { 
! 		  if ($1 != error_mark_node)
! 		    push_scope (CP_DECL_CONTEXT ($1)); 
! 		  else
! 		    /* We enter a scope here, but have none to push. */
! 		    push_scope (std_node);
! 		}
  	  maybe_base_class_list
  		{ 
! 		  if ($1 != error_mark_node)
  		    {
! 		      pop_scope (CP_DECL_CONTEXT ($1));
! 		      $$ = TREE_TYPE ($1);
! 		      if (current_aggr == union_type_node
! 			  && TREE_CODE ($$) != UNION_TYPE)
! 			cp_pedwarn ("`union' tag used in declaring `%#T'", $$);
! 		      else if (TREE_CODE ($$) == UNION_TYPE
! 			       && current_aggr != union_type_node)
! 			cp_pedwarn ("non-`union' tag used in declaring `%#T'", $$);
! 		      else if (TREE_CODE ($$) == RECORD_TYPE)
! 			/* We might be specializing a template with a different
! 			   class-key; deal.  */
! 			CLASSTYPE_DECLARED_CLASS ($$) = (current_aggr
! 							 == class_type_node);
! 		      if ($3)
! 			{
! 			  maybe_process_partial_specialization ($$);
! 			  xref_basetypes (current_aggr, $1, $$, $3); 
! 			}
  		    }
+ 		  else
+ 		    pop_scope (std_node);
  		}
  	;
  
Index: tree.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/tree.c,v
retrieving revision 1.98
diff -c -p -r1.98 tree.c
*** tree.c	1999/03/06 17:41:36	1.98
--- tree.c	1999/03/16 08:47:40
*************** tree
*** 2700,2706 ****
  build_dummy_object (type)
       tree type;
  {
!   tree decl = build1 (NOP_EXPR, build_pointer_type (type), error_mark_node);
    return build_indirect_ref (decl, NULL_PTR);
  }
  
--- 2700,2706 ----
  build_dummy_object (type)
       tree type;
  {
!   tree decl = build1 (NOP_EXPR, build_pointer_type (type), void_zero_node);
    return build_indirect_ref (decl, NULL_PTR);
  }
  
*************** is_dummy_object (ob)
*** 2743,2749 ****
    if (TREE_CODE (ob) == INDIRECT_REF)
      ob = TREE_OPERAND (ob, 0);
    return (TREE_CODE (ob) == NOP_EXPR
! 	  && TREE_OPERAND (ob, 0) == error_mark_node);
  }
  
  /* Returns 1 iff type T is a POD type, as defined in [basic.types].  */
--- 2743,2749 ----
    if (TREE_CODE (ob) == INDIRECT_REF)
      ob = TREE_OPERAND (ob, 0);
    return (TREE_CODE (ob) == NOP_EXPR
! 	  && TREE_OPERAND (ob, 0) == void_zero_node);
  }
  
  /* Returns 1 iff type T is a POD type, as defined in [basic.types].  */


More information about the Gcc-patches mailing list