From 6d44c881286762628afce5169d921a388ae6a1ff Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Mon, 16 Mar 2020 09:03:59 +0100 Subject: [PATCH] tree-inline: Fix a -fcompare-debug issue in the inliner [PR94167] The following testcase fails with -fcompare-debug. The problem is that bar is marked as address_taken only with -g and not without. I've tracked it down to insert_init_stmt calling gimple_regimplify_operands even on DEBUG_STMTs. That function will just insert normal stmts before the DEBUG_STMT if the DEBUG_STMT operand isn't gimple val or invariant. While DCE will turn those statements into debug temporaries, it can cause differences in SSA_NAMEs and more importantly, the ipa references are generated from those before the DCE happens. On the testcase, the DEBUG_STMT value is (int)bar. We could generate DEBUG_STMTs with debug temporaries instead, but I fail to see the reason to do that, DEBUG_STMTs allow other expressions and all we want to ensure is that the expressions aren't too large (arbitrarily complex), but during inlining/function versioning I don't see why something would queue a DEBUG_STMT with arbitrarily complex expressions in there. 2020-03-16 Jakub Jelinek PR debug/94167 * tree-inline.c (insert_init_stmt): Don't gimple_regimplify_operands DEBUG_STMTs. * gcc.dg/pr94167.c: New test. --- gcc/ChangeLog | 4 ++++ gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/gcc.dg/pr94167.c | 33 +++++++++++++++++++++++++++++++++ gcc/tree-inline.c | 4 ++-- 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr94167.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8709f0c7f53..81582dd4f8c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,9 @@ 2020-03-16 Jakub Jelinek + PR debug/94167 + * tree-inline.c (insert_init_stmt): Don't gimple_regimplify_operands + DEBUG_STMTs. + PR tree-optimization/94166 * tree-ssa-reassoc.c (sort_by_mach_mode): Use SSA_NAME_VERSION as secondary comparison key. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d52cd1effa3..1297954f5df 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2020-03-16 Jakub Jelinek + PR debug/94167 + * gcc.dg/pr94167.c: New test. + PR tree-optimization/94166 * gcc.dg/pr94166.c: New test. diff --git a/gcc/testsuite/gcc.dg/pr94167.c b/gcc/testsuite/gcc.dg/pr94167.c new file mode 100644 index 00000000000..4b819d3a869 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr94167.c @@ -0,0 +1,33 @@ +/* PR debug/94167 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fcompare-debug" } */ + +struct S { int g, h; signed char i; int j; signed char k; int l[4]; } a, c; +struct T { signed char g; } e; +int *b, d; +static void foo (); + +void +bar (void) +{ + while (d) + { + int k; + struct T f[3]; + foo (bar, a); + for (k = 0;; k++) + f[k] = e; + } +} + +static inline void +foo (int x, struct S y, struct T z) +{ + for (z.g = 2; z.g; z.g--) + { + c = a = y; + *b |= 6; + if (y.g) + break; + } +} diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 59798ec0454..f095795f06f 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -3361,10 +3361,10 @@ insert_init_stmt (copy_body_data *id, basic_block bb, gimple *init_stmt) gimple_assign_set_rhs1 (init_stmt, rhs); } gsi_insert_after (&si, init_stmt, GSI_NEW_STMT); - gimple_regimplify_operands (init_stmt, &si); - if (!is_gimple_debug (init_stmt)) { + gimple_regimplify_operands (init_stmt, &si); + tree def = gimple_assign_lhs (init_stmt); insert_init_debug_bind (id, bb, def, def, init_stmt); } -- 2.30.2