expand: Throw away non-external decls without varpool nodes [PR105415]

The following testcase fails -fcompare-debug on aarch64-linux.  The problem
is that for the n variable we create a varpool node, then remove it again
because the var isn't really used, but it keeps being referenced in debug
stmts/insns with -g.  Later during sched1 pass we ask whether the n var
can be modified through some store to an anchored variable and with -g
we create a new varpool node for it again just so that we can find its
ultimate alias target.  Even later on we create some cgraph node for the
loop parallelization, but as there has been an extra varpool node creation
in between, we get higher node->order with -g than without.

The patch fixes that by throwing variables without varpool nodes away
during expansion time, they are very unlikely to actually end up with
useful debug info anyway.

I've bootstrapped/regtested the following on x86_64-linux and i686-linux,
then bootstrapped with the patch reverted, reapplied the patch and did make
cc1plus in stage3.  The debug section sizes are identical, .debug_info and
.debug_loc is identical too, so I think we don't lose any debug info through
it.
So at least on cc1plus it makes no difference.

2022-05-02  Jakub Jelinek  <jakub@redhat.com>

	PR debug/105415
	* cfgexpand.cc (expand_debug_expr): Don't make_decl_rtl_for_debug
	if there is no symtab node for the VAR_DECL.

	* gcc.dg/pr105415.c: New test.
This commit is contained in:
Jakub Jelinek 2022-05-02 11:30:58 +02:00
parent 880a9845dc
commit 02f03c5c82
2 changed files with 28 additions and 1 deletions

View File

@ -4565,7 +4565,8 @@ expand_debug_expr (tree exp)
|| !DECL_NAME (exp)
|| DECL_HARD_REGISTER (exp)
|| DECL_IN_CONSTANT_POOL (exp)
|| mode == VOIDmode)
|| mode == VOIDmode
|| symtab_node::get (exp) == NULL)
return NULL;
op0 = make_decl_rtl_for_debug (exp);

View File

@ -0,0 +1,26 @@
/* PR debug/105415 */
/* { dg-do compile } */
/* { dg-require-effective-target pthread } */
/* { dg-options "-O2 -ftree-parallelize-loops=2 -fcompare-debug" } */
int m;
static int n;
void
foo (void)
{
int s = 0;
while (m < 1)
{
s += n;
++m;
}
}
void
bar (int *arr, int i)
{
while (i < 1)
arr[i++] = 1;
}