[PATCH] Fix PR debug/19345
Daniel Berlin
dberlin@dberlin.org
Thu Jan 27 03:28:00 GMT 2005
Now that we actually exercise our debug info functions more, we are
starting to hit corner cases and expose a few latent bugs.
In this case, a 4.0 regression, we were trying to generate the inlined
structure type die
for the
structure inside the asm, and when we went to add the abstract origin
attribute:
1. we fall into the TREE_CODE (origin) != FUNCTION_DECL portion, because
gen_inlined_structure_type_die always passes in the type as the origin.
2. We get TYPE_STUB_DECL (origin) because origin is a RECORD_TYPE.
3. TYPE_STUB_DECL (origin) is NULL.
4. We pass null to decl_function_context.
5. decl_function_context dereferences it, and we blow up.
This means we never could have been trying to generate debug info for this
inlined structure type before, since i didn't touch this code path, and
this didn't fail in 3.4.
Compiling with 3.4 confirms this. There is no inlined structure type die
generated.
Rather than add a null check in decl_function_context, i've simply guarded
against calling it here with null (we already were assuming it could
return null, so what's 2 null checks when you've already got 1 :P).
Everything else DTRT once we exit our if block.
Bootstrapped and regtested on i686-pc-linux-gnu. Okay for mainline?
-------------- next part --------------
2005-01-26 Daniel Berlin <dberlin@dberlin.org>
Fix PR debug/19345
* dwarf2out.c (add_abstract_origin_attribute): TYPE_STUB_DECL is
not always going to give us a non-NULL result, so guard against that.
Index: dwarf2out.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/dwarf2out.c,v
retrieving revision 1.568
diff -u -p -r1.568 dwarf2out.c
--- dwarf2out.c 20 Jan 2005 20:09:22 -0000 1.568
+++ dwarf2out.c 27 Jan 2005 03:17:40 -0000
@@ -10497,8 +10497,12 @@ add_abstract_origin_attribute (dw_die_re
if (TYPE_P (fn))
fn = TYPE_STUB_DECL (fn);
+
+ /* TYPE_STUB_DECL may have given us a NULL, which decl_function_context
+ won't like. */
+ if (fn)
+ fn = decl_function_context (fn);
- fn = decl_function_context (fn);
if (fn)
dwarf2out_abstract_function (fn);
}
Index: testsuite/gcc.dg/pr19345.c
===================================================================
RCS file: testsuite/gcc.dg/pr19345.c
diff -N testsuite/gcc.dg/pr19345.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/gcc.dg/pr19345.c 27 Jan 2005 03:17:52 -0000
@@ -0,0 +1,13 @@
+/* We shouldn't crash trying to produce the inlined structure type die debug info. */
+/* { dg-do compile } */
+/* { dg-options "-O1 -g" } */
+inline void bar(char a[], unsigned int l)
+{
+ asm volatile ("" :: "m" ( *(struct {char x[l]; } *)a));
+}
+
+void foo(void)
+{
+ bar (0, 0);
+}
+
More information about the Gcc-patches
mailing list