On Fri, Jun 15, 2018 at 12:50 PM Eric Botcazou <ebotca...@adacore.com> wrote: > > Hi, > > the motivating example is the following program in GNU C: > > void foo (int len) > { > int a = 1; > int b[len]; > > void bar (void) > { > b[0] = a; > a++; > } > > bar (); > } > > int main (void) > { > foo (4); > } > > If you look at the debug info at -O0 -g, you'll see that that the compiler > generates 2 DIEs for variable "a" and 4 DIEs for variable "b" because: > 1. It duplicates DIEs for each nested function containing up-level references > 2. It generates 2 DIEs for each VLA subject to up-level references. > > That's sort of OK for languages where nested functions and VLAs are somewhat > pathological devices but clearly doesn't scale for languages where they are > both first-class citizens like Ada. That's why AdaCore has been using a > totally different scheme in its toolchain, first using a dedicated encoding > with STABS then using standard DWARF-2 only. > > This scheme is as follows: > 1. The compiler generates only 1 DIE per variable as in the regular case, > 2. For each child function, the static link is passed and the compiler > generates a DW_AT_static_link attribute pointing to it for the child function, > 3. The debugger reconstructs the static nesting tree at run time by walking > up the static chain and thus can resolve up-level references on its own. > > It turns out that 2. and 3. were contributed a few releases ago, mainly by > Pierre-Marie, both for GCC and GDB, so the last remaining step is 1. and it's > the object of this contribution. Note that it also subsumes: > https://gcc.gnu.org/ml/gcc-patches/2018-05/msg00873.html > since contributing it piecewise turned out more problematic than helpful. > > So the patch entirely removes the support of artificial variables for debug > info of up-level reference purposes present both in the Fortran FE and the > gimplifier (the Ada FE has never had such a thing) but only disconnects it in > the nested function lowering pass because it uses for another purpose by GOMP. > > Bootstrapped/regtested (GCC and GDB) on x86-64/Linux, OK for mainline?
Looks good to me. Rather than removing dwarf2/pr37726.c can you try turning that into a guality test that verifies the debug experience is the same (or better) than before? I realize guality stuff is fragile but you can restrict it to -O0 if you like (not sure if dg-skip-if supports that). Thanks, Richard. > > 2018-06-15 Eric Botcazou <ebotca...@adacore.com> > > * gimplify.c (nonlocal_vlas): Delete. > (nonlocal_vla_vars): Likewise. > (gimplify_var_or_parm_decl): Do not add debug VAR_DECLs for non-local > referenced VLAs. > (gimplify_body): Do not create and destroy nonlocal_vlas. > * tree-nested.c: Include diagnostic.h. > (use_pointer_in_frame): Tweak. > (lookup_field_for_decl): Add assertion and declare the transformation. > (convert_nonlocal_reference_op) <PARM_DECL>: Rework and issue an > internal error when the reference is in a wrong context. Do not > create a debug decl by default. > (note_nonlocal_block_vlas): Delete. > (convert_nonlocal_reference_stmt) <GIMPLE_BIND>: Do not call it. > (convert_local_reference_op) <PARM_DECL>: Skip the frame decl. Do not > create a debug decl by default. > (convert_gimple_call) <GIMPLE_CALL>: Issue an internal error when the > call is in a wrong context. > (fixup_vla_decls): New function. > (finalize_nesting_tree_1): Adjust comment. Call fixup_vla_decls if no > debug variables were created. > * tree.c (decl_value_expr_lookup): Add checking assertion. > (decl_value_expr_insert): Likewise. > > > 2018-06-15 Eric Botcazou <ebotca...@adacore.com> > > * fortran/trans-decl.c (nonlocal_dummy_decl_pset): Delete. > (nonlocal_dummy_decls): Likewise. > (gfc_nonlocal_dummy_array_decl): Likewise. > (gfc_get_symbol_decl): Do not call gfc_nonlocal_dummy_array_decl. > (gfc_get_fake_result_decl): Do not generate a new DECL if simply > reusing the result of a recursive call. > (gfc_generate_function_code): Do not create, insert and destroy > nonlocal_dummy_decls. > > > 2018-06-15 Eric Botcazou <ebotca...@adacore.com> > > * gcc.dg/debug/dwarf2/pr37726.c: Delete. > * gnat.dg/stack_usage5.adb: New test. > > -- > Eric Botcazou