Bug 43329

Summary: Early inlining causes suboptimal debug info
Product: gcc Reporter: Jakub Jelinek <jakub>
Component: debugAssignee: Jakub Jelinek <jakub>
Status: RESOLVED FIXED    
Severity: normal CC: aoliva, gcc-bugs, hubicka, mark
Priority: P3 Keywords: wrong-debug
Version: 4.5.0   
Target Milestone: ---   
Host: Target: x86_64-linux
Build: Known to work:
Known to fail: Last reconfirmed:
Attachments: rh572260.ii
gcc45-pr43329.patch
gcc45-pr43329.patch

Description Jakub Jelinek 2010-03-10 23:28:20 UTC
The following testcase doesn't contain DW_AT_const_value for arrg3 nor min when early inlining is used, while when normal inlining is performed all is fine.
-g -O2 --param early-inlining-insns=32 (doesn't work) vs.
-g -O2 --param early-inlining-insns=32 -fno-early-inlining
Sorry for the extra parameter, but the testcase was reported against 4.4-RH which does 4.4-ish inlining decisions, so it needs some tweaks to get the same effect in 4.5.
For arrg3, there are DEBUG stmts (and even var-tracking produces locations for it), but dwarf2out ignores them, as the var has been non-localized (var_ann has been NULL).  For min argument, a DEBUG stmt only appears when not using early inlining.
Comment 1 Jakub Jelinek 2010-03-10 23:29:51 UTC
Created attachment 20078 [details]
rh572260.ii

Testcase.
Comment 2 Jakub Jelinek 2010-03-11 12:53:18 UTC
The problem is that with early inlining, method (&inst, 24) call is inlined into
call function, then at the end of einline during arrg3 and min vars in call are removed as unused locals by remove_unused_locals (the inline asm uses 24 directly, so arrg3 is only referenced in DEBUG stmts, not sure why min didn't have any DEBUG stmts even generated).  Then when in the normal inliner call is inlined into main, both arrg3 and min are non-localized because their var_ann is NULL.  And for non-localized vars dwarf2out isn't able to find the dwarf2out_var_location tracked values.
Comment 3 Jakub Jelinek 2010-03-11 13:02:00 UTC
Wonder why we do
548    VEC_safe_push (tree, gc, *nonlocalized_list, origin_var);
instead of
548    VEC_safe_push (tree, gc, *nonlocalized_list, old_var);
The latter perhaps would need some adjustments in dwarf2out.c, but would allow it to find the location.
Comment 4 Jakub Jelinek 2010-03-11 14:46:53 UTC
Created attachment 20081 [details]
gcc45-pr43329.patch

This patch worked on this testcase.  Note that the missing min (and this) DEBUG stmts are caused by remove_forwarder_block nuking it.  Looking into that...
Comment 5 Jakub Jelinek 2010-03-11 16:08:26 UTC
Created attachment 20084 [details]
gcc45-pr43329.patch

Updated patch that also fixes remove_forwarder_block and adds a testcase.
Comment 6 Jakub Jelinek 2010-03-12 13:04:52 UTC
Subject: Bug 43329

Author: jakub
Date: Fri Mar 12 13:04:37 2010
New Revision: 157402

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=157402
Log:
	PR debug/43329
	* tree-inline.c (remap_decls): Put old_var rather than origin_var
	into *nonlocalized_list vector.
	* dwarf2out.c (gen_formal_parameter_die): Call decl_ultimate_origin
	even if origin is non-NULL.
	(gen_variable_die): Likewise.
	(process_scope_var): Don't change origin.
	(gen_decl_die): Likewise.
	* tree-cfgcleanup.c (remove_forwarder_block): Check single_pred_p
	before adding new edges instead of after it, fix moving over
	debug stmts.

	* gcc.dg/guality/pr43329-1.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/guality/pr43329-1.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/dwarf2out.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-cfgcleanup.c
    trunk/gcc/tree-inline.c

Comment 7 Jakub Jelinek 2010-03-12 23:06:21 UTC
Fixed.