advice wanted on complex obstack bug...

Jeffrey A Law law@upchuck.cygnus.com
Sun Mar 28 00:52:00 GMT 1999


  In message <v04020a01b270ffd7f4ba@[192.168.1.254]>you write:
  > 	When compiling a function we allocate the tree for declarations
  > 	and types into the maybepermanent obstack.  When we decide that
  > 	this is a candidate for inlining, we call preserve_data() to
  > 	set the high-water-mark to keep the important data structures
  > 	from being deleted.
  > 
  > 	Now, suppose we have declared stack variable with an
  > 	anonymous type
  > 
  > 		char buffer[] = { "some text here..."};
  > 
  > 	When we get to the point of outputting the debug information
  > 	for the function, we find ourselves in sdbout_symbol() and
  > 	want to put out type information for 'buffer'.
  > 
  > 	We eventually find ourselves in the case where we're actually
  > 	treating this as if it was a pointer to a variable amount
  > 	of data.  We do a
  > 
  > 		type = build_pointer_type (TREE_TYPE (decl));
  > 
  > 	and build_pointer_type() discovers that there is no TYPE_POINTER_TO
  > 	value yet, so it allocates one on the same stack as the type
  > 	pointed-to.
  > 
  > BUT, THAT OBSTACK HAS BEEN MARKED WITH A CALL TO PRESERVE_DATA()!
  > 
  > 	Now, we've got a preserved type "array-of-char" that points
  > 	to a "pointer-to-array-of-char" that is on the wrong
  > 	side of the high-water mark....
[ ... ]
FYI, I just installed a copy of the code from dbxout.c which handles this
situation into sdbout.c.  Since you didn't provide a testcase, I can't
actually test the patch though.



	* sdbout.c (sdbout_symbol): Do not call build_pointer_type, build
	one on the fly and do not cache the result.

Index: sdbout.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/sdbout.c,v
retrieving revision 1.18
diff -c -3 -p -r1.18 sdbout.c
*** sdbout.c	1999/03/22 23:23:25	1.18
--- sdbout.c	1999/03/28 08:47:30
*************** sdbout_symbol (decl, local)
*** 929,935 ****
  	      PUT_SDB_SCL (C_AUTO);
  	    }
  
! 	  type = build_pointer_type (TREE_TYPE (decl));
  	}
        else if (GET_CODE (value) == MEM
  	       && ((GET_CODE (XEXP (value, 0)) == PLUS
--- 929,940 ----
  	      PUT_SDB_SCL (C_AUTO);
  	    }
  
! 	  /* Effectively do build_pointer_type, but don't cache this type,
! 	     since it might be temporary whereas the type it points to
! 	     might have been saved for inlining.  */
! 	  /* Don't use REFERENCE_TYPE because dbx can't handle that.  */
! 	  type = make_node (POINTER_TYPE);
! 	  TREE_TYPE (type) = TREE_TYPE (decl);
  	}
        else if (GET_CODE (value) == MEM
  	       && ((GET_CODE (XEXP (value, 0)) == PLUS


More information about the Gcc-patches mailing list