On 12/2/20 8:50 AM, Richard Biener wrote: > On Tue, 1 Dec 2020, Bernd Edlinger wrote: > >> Hi! >> >> >> This removes gimple_debug stmts without block info after a >> NULL INLINE_ENTRY. >> >> The line numbers from these stmts are from the inline function, >> but since the inline function is completely optimized away, >> there will be no DW_TAG_inlined_subroutine so the debugger has >> no callstack available at this point, and therefore those >> line table entries are not helpful to the user. >> >> 2020-11-20 Bernd Edlinger <bernd.edlin...@hotmail.de> >> >> * cfgexpand.c (expand_gimple_basic_block): Remove debug_begin_stmts >> following a removed debug_inline_entry. >> >> >> Bootstrapped and reg-tested on x86_64-pc-linux-gnu. >> Is it OK for trunk? > > So are those visited by clear_unused_block_pointer? If so wouldn't > it be more appropriate to remove those there, when we elide the > inlined block scope? >
That's what I thought initially, but that is only true for 99% of the inline statements. However 1% of the inline_entries without block info, and debug_begin_stmts without block info, that have line numbers from an inline header, do actually originate here: copy_debug_stmt (gdebug *stmt, copy_body_data *id) { tree t, *n; struct walk_stmt_info wi; if (tree block = gimple_block (stmt)) { n = id->decl_map->get (block); gimple_set_block (stmt, n ? *n : id->block); } because id->block is NULL, and decl_map does not have an entry. So I tracked it down why that happens. I think remap_gimple_stmt should just drop those nonbind markers on the floor when the call statement has no block information. Once that is fixed, the special handling of inline entries without block info can as well be moved from remap_gimple_stmt to clear_unused_block_pointer. What do you think of this (not yet fully tested) patch? Is it OK when bootstrap and reg-testing passes? Thanks Bernd. > Thanks, > Richard. > >> >> Thanks >> Bernd. >> >
From 1f97917fcbb15f7277dc9d6030dca05beab825c7 Mon Sep 17 00:00:00 2001 From: Bernd Edlinger <bernd.edlin...@hotmail.de> Date: Wed, 2 Dec 2020 12:32:02 +0100 Subject: [PATCH] Remove misleading debug line entries This removes gimple_debug_begin_stmts without block info which remain after a gimple block originating from an inline function is unused. The line numbers from these stmts are from the inline function, but since the inline function is completely optimized away, there will be no DW_TAG_inlined_subroutine so the debugger has no callstack available at this point, and therefore those line table entries are not helpful to the user. 2020-12-02 Bernd Edlinger <bernd.edlin...@hotmail.de> * cfgexpand.c (expand_gimple_basic_block): Remove special handling of debug_inline_entries without block info. * tree-inline.c (remap_gimple_stmt): Drop debug_nonbind_markers when the call statement has no block info. * tree-ssa-live.c (clear_unused_block_pointer): Remove debug_nonbind_markers originating from inlined functions. --- gcc/cfgexpand.c | 9 +-------- gcc/tree-inline.c | 3 ++- gcc/tree-ssa-live.c | 16 ++++++++++++++-- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c index 1df6f4b..2ef8298 100644 --- a/gcc/cfgexpand.c +++ b/gcc/cfgexpand.c @@ -5831,14 +5831,7 @@ expand_gimple_basic_block (basic_block bb, bool disable_tail_calls) else if (gimple_debug_begin_stmt_p (stmt)) val = GEN_RTX_DEBUG_MARKER_BEGIN_STMT_PAT (); else if (gimple_debug_inline_entry_p (stmt)) - { - tree block = gimple_block (stmt); - - if (block) - val = GEN_RTX_DEBUG_MARKER_INLINE_ENTRY_PAT (); - else - goto delink_debug_stmt; - } + val = GEN_RTX_DEBUG_MARKER_INLINE_ENTRY_PAT (); else gcc_unreachable (); diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index d9814bd..e87c653 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -1819,7 +1819,8 @@ remap_gimple_stmt (gimple *stmt, copy_body_data *id) /* If the inlined function has too many debug markers, don't copy them. */ if (id->src_cfun->debug_marker_count - > param_max_debug_marker_count) + > param_max_debug_marker_count + || !id->block) return stmts; gdebug *copy = as_a <gdebug *> (gimple_copy (stmt)); diff --git a/gcc/tree-ssa-live.c b/gcc/tree-ssa-live.c index 21a9ee4..ca119c6 100644 --- a/gcc/tree-ssa-live.c +++ b/gcc/tree-ssa-live.c @@ -623,13 +623,25 @@ clear_unused_block_pointer (void) { unsigned i; tree b; - gimple *stmt = gsi_stmt (gsi); + gimple *stmt; + next: + stmt = gsi_stmt (gsi); if (!is_gimple_debug (stmt) && !gimple_clobber_p (stmt)) continue; b = gimple_block (stmt); if (b && !TREE_USED (b)) - gimple_set_block (stmt, NULL); + { + if (gimple_debug_nonbind_marker_p (stmt) + && BLOCK_ABSTRACT_ORIGIN (b)) + { + gsi_remove (&gsi, true); + if (gsi_end_p (gsi)) + break; + goto next; + } + gimple_set_block (stmt, NULL); + } for (i = 0; i < gimple_num_ops (stmt); i++) walk_tree (gimple_op_ptr (stmt, i), clear_unused_block_pointer_1, NULL, NULL); -- 1.9.1