Fix PR middle-end/102764

Message ID 1708054.VLH7GnMWUR@fomalhaut
State New
Headers
Series Fix PR middle-end/102764 |

Commit Message

Eric Botcazou Oct. 20, 2021, 8:48 a.m. UTC
  This is a regression present on the mainline in the form of a -fcompare-debug 
failure at -O3 on a compiler-generated testcase.  Fixed by disregarding a 
debug statement in the last position of a basic block to reset the current 
location for the outgoing edges.

Bootstrapped/regtested on x86-64/Linux, applied on the mainline as obvious.


2021-10-20  Eric Botcazou  <ebotcazou@adacore.com>

	PR middle-end/102764
	* cfgexpand.c (expand_gimple_basic_block): Disregard a final debug
	statement to reset the current location for the outgoing edges.


2021-10-20  Eric Botcazou  <ebotcazou@adacore.com>

	* gcc.dg/pr102764.c: New test.
  

Comments

Eric Botcazou Oct. 21, 2021, 3:59 p.m. UTC | #1
> 2021-10-20  Eric Botcazou  <ebotcazou@adacore.com>
> 
> 	PR middle-end/102764
> 	* cfgexpand.c (expand_gimple_basic_block): Disregard a final debug
> 	statement to reset the current location for the outgoing edges.

This apparently breaks -fcompare-debug with -m32 so I have made it more robust 
by means of the attached fixlet.

Bootstrapped/regtested on x86-64/Linux, applied on the mainline as obvious.


        PR middle-end/102764
        * cfgexpand.c (expand_gimple_basic_block): Robustify latest change.
  

Patch

diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c
index 03260b019e5..8b067f9d848 100644
--- a/gcc/cfgexpand.c
+++ b/gcc/cfgexpand.c
@@ -6090,7 +6090,7 @@  expand_gimple_basic_block (basic_block bb, bool disable_tail_calls)
   /* Expand implicit goto and convert goto_locus.  */
   FOR_EACH_EDGE (e, ei, bb->succs)
     {
-      if (e->goto_locus != UNKNOWN_LOCATION || !stmt)
+      if (e->goto_locus != UNKNOWN_LOCATION || !stmt || is_gimple_debug (stmt))
 	set_curr_insn_location (e->goto_locus);
       if ((e->flags & EDGE_FALLTHRU) && e->dest != bb->next_bb)
 	{