Here's a revised patch, with testcase added, and with Steven's suggested change...
-cary 2012-08-06 Cary Coutant <ccout...@google.com> gcc/ * cgraphunit.c (assemble_thunk): Add source line info. * final.c (final): Check for non-null cfg pointer. * testsuite/g++.dg/debug/dwarf2/non-virtual-thunk.C: New test case. commit db557f2dabd9658e59a5111dd156aa39d691bf22 Author: Cary Coutant <ccout...@google.com> Date: Mon Aug 6 12:48:31 2012 -0700 Add line number info for thunks; fix an ICE when -dA used with thunks. gcc/ * cgraphunit.c (assemble_thunk): Add source line info. * final.c (final): Check for non-null cfg pointer. * testsuite/g++.dg/debug/dwarf2/non-virtual-thunk.C: New test case. diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c index a6591b5..2dd0871 100644 --- a/gcc/cgraphunit.c +++ b/gcc/cgraphunit.c @@ -1381,6 +1381,10 @@ assemble_thunk (struct cgraph_node *node) init_function_start (thunk_fndecl); cfun->is_thunk = 1; assemble_start_function (thunk_fndecl, fnname); + (*debug_hooks->source_line) (DECL_SOURCE_LINE (thunk_fndecl), + DECL_SOURCE_FILE (thunk_fndecl), + /* discriminator */ 0, + /* is_stmt */ 1); targetm.asm_out.output_mi_thunk (asm_out_file, thunk_fndecl, fixed_offset, virtual_value, alias); diff --git a/gcc/final.c b/gcc/final.c index cdae011..30890b3 100644 --- a/gcc/final.c +++ b/gcc/final.c @@ -1863,11 +1863,13 @@ final (rtx first, FILE *file, int optimize_p) start_to_bb = XCNEWVEC (basic_block, bb_map_size); end_to_bb = XCNEWVEC (basic_block, bb_map_size); - FOR_EACH_BB_REVERSE (bb) - { - start_to_bb[INSN_UID (BB_HEAD (bb))] = bb; - end_to_bb[INSN_UID (BB_END (bb))] = bb; - } + /* There is no cfg for a thunk. */ + if (!cfun->is_thunk) + FOR_EACH_BB_REVERSE (bb) + { + start_to_bb[INSN_UID (BB_HEAD (bb))] = bb; + end_to_bb[INSN_UID (BB_END (bb))] = bb; + } } /* Output the insns. */ diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/non-virtual-thunk.C b/gcc/testsuite/g++.dg/debug/dwar new file mode 100644 index 0000000..8ad347a --- /dev/null +++ b/gcc/testsuite/g++.dg/debug/dwarf2/non-virtual-thunk.C @@ -0,0 +1,39 @@ +// { dg-do compile } +// { dg-options "-g2 -dA" } + +// Verify that line number info is output for the non-virtual +// thunks for C::~C(). +// { dg-final { scan-assembler "thunk.C:30" } } + +class A +{ + public: + A(); + virtual ~A(); + private: + int i; +}; + +class B +{ + public: + B(); + virtual ~B(); + private: + int i; +}; + +class C : public A, public B +{ + public: + C(); + virtual ~C(); // line 30 +}; + +C::C() +{ +} + +C::~C() +{ +}