PATCH: Robustify loc_descriptor_from_tree

Mark Mitchell mark@codesourcery.com
Tue Aug 24 02:53:00 GMT 2004


This patch fixes PR c/14492, a crash in the debug-generators with
VLAs.

The code in loc_descriptor_from_tree aborts if it runs into a
tree-code it doesn't recognize.  This is fine for the development
branch; we want to find out about these things and add support for
them.  But, it's foolish for a release branch, since it's easy to
degrade gracefully.  Our users would rather have their code compile,
and find out later than they can't print out an array bound in the
debugger, than have the code fail to compile at all.

Tested on i686-pc-linux-gnu, applied on the 3.4 branch and on the
mainline.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2004-08-23  Mark Mitchell  <mark@codesourcery.com>

	PR c/14492
	* dwarf2out.c (loc_descriptor_from_tree): Robustify.

2004-08-23  Mark Mitchell  <mark@codesourcery.com>

	PR c/14492
	* gcc.dg/debug/crash1.c: New test.

Index: dwarf2out.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/dwarf2out.c,v
retrieving revision 1.478.2.9
diff -c -5 -p -r1.478.2.9 dwarf2out.c
*** dwarf2out.c	27 Apr 2004 23:48:51 -0000	1.478.2.9
--- dwarf2out.c	24 Aug 2004 02:04:55 -0000
*************** loc_descriptor_from_tree (tree loc, int 
*** 8856,8868 ****
--- 8856,8874 ----
  	 up, for instance, with the C STMT_EXPR.  */
        if ((unsigned int) TREE_CODE (loc)
            >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
  	return 0;
  
+ #ifdef ENABLE_CHECKING
        /* Otherwise this is a generic code; we should just lists all of
  	 these explicitly.  Aborting means we forgot one.  */
        abort ();
+ #else
+       /* In a release build, we want to degrade gracefully: better to
+ 	 generate incomplete debugging information than to crash.  */
+       return NULL;
+ #endif
      }
  
    /* Show if we can't fill the request for an address.  */
    if (addressp && indirect_p == 0)
      return 0;
Index: testsuite/gcc.dg/debug/crash1.c
===================================================================
RCS file: testsuite/gcc.dg/debug/crash1.c
diff -N testsuite/gcc.dg/debug/crash1.c
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/gcc.dg/debug/crash1.c	24 Aug 2004 02:04:55 -0000
***************
*** 0 ****
--- 1,8 ----
+ /* PR c/14492 */
+ /* { dg-options "" } */
+ 
+ int main() {
+   double d = 1.0;
+   char x[(int) d];
+   return 0;
+ }



More information about the Gcc-patches mailing list