Fix nasty bug in reg-stack.c
Eric Botcazou
ebotcazou@adacore.com
Sat Mar 26 14:56:00 GMT 2011
The bug was introduced 6 years ago but its occurrences apparently are quite
rare since we detected it only very recently in our 4.3-based Ada compiler.
The end of convert_regs reads:
inserted |= compensate_edges ();
clear_aux_for_blocks ();
fixup_abnormal_edges ();
if (inserted)
commit_edge_insertions ();
There is a nasty ordering problem in these lines. fixup_abnormal_edges is
intended to fix up the CFG by moving insns that were inserted past the last
insn in a BB before compensate_edges is run onto the fallthrough edge. And
compensate_edges also inserts insns onto (fallthrough) edges. Now inserting
insns on edges is a FIFO process so, if an insn was inserted past the last
insn in a BB and a compensation insn is inserted afterward on the fallthrough
edge, then they end up being swapped after the call to fixup_abnormal_edges.
A possible fix would be to use in the earlier phases the same mechanism used in
compensate_edges: inserting insns on edges directly (except for the case of a
single successor). This seems inappropriate at this point of the lifetime of
the reg-stack.c code. The attached fix moves the call to fixup_abnormal_edges
up to before the call to compensate_edges instead; this in turn requires some
changes to fixup_abnormal_edges itself, mostly the uncoupling of the fixup and
the finalization codes.
Tested on i586-suse-linux, applied on the mainline.
2011-03-26 Eric Botcazou <ebotcazou@adacore.com>
* basic-block.h (fixup_abnormal_edges): Adjust prototype.
* reload1.c (reload): Adjust call to fixup_abnormal_edges. Rediscover
basic blocks and call commit_edge_insertions directly.
(fixup_abnormal_edges): Move from here to...
* cfgrtl.c (fixup_abnormal_edges): ...here. Only insert instructions
on the edges and return whether some have actually been inserted.
* reg-stack.c (convert_regs): Fix up abnormal edges before inserting
compensation code.
--
Eric Botcazou
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p.diff
Type: text/x-diff
Size: 8945 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20110326/93f9e107/attachment.bin>
More information about the Gcc-patches
mailing list