PR 41469 followup: improve __builtin_stack_restore removal

H.J. Lu hjl.tools@gmail.com
Mon Nov 9 17:23:00 GMT 2009


On Sun, Nov 8, 2009 at 3:53 PM, Eric Botcazou <ebotcazou@adacore.com> wrote:
>> It's only wrong if the RESX resolves within the function, i.e. the block
>> has successors.  If there are no successors to the bb, then we're about
>> to (effectively) perform a longjmp, and there's no point in keeping the
>> stack restore.
>
> You're right, and that the problem arises on x86-64 but not on i586 should
> have prompted me to further investigate.
>
> It turns out that SP is set to a bogus value on entry to the cleanup because
> of a bogus DW_CFA_GNU_args_size entry in the FDE at -O.  Insns that adjust
> the stack but aren't FRAME_RELATED_P are processed by dwarf2out_frame_debug
> and discarded for ACCUMULATE_OUTGOING_ARGS targets:
>
>  if (! RTX_FRAME_RELATED_P (insn))
>    {
>      if (!ACCUMULATE_OUTGOING_ARGS)
>        dwarf2out_stack_adjust (insn, after_p);
>      return;
>    }
>
> But if one of them is merged in a FRAME_RELATED_P insn by the csa pass, it is
> further processed by dwarf2out_frame_debug_expr:
>
>      for (par_index = 0; par_index < limit; par_index++)
>        {
>          elem = XVECEXP (expr, 0, par_index);
>          if (GET_CODE (elem) == SET
>              && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
>              && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
>            dwarf2out_frame_debug_expr (elem, label);
>          else if (GET_CODE (elem) == SET
>                   && par_index != 0
>                   && !RTX_FRAME_RELATED_P (elem))
>            {
>              /* Stack adjustment combining might combine some post-prologue
>                 stack adjustment into a prologue stack adjustment.  */
>              HOST_WIDE_INT offset = stack_adjust_offset (elem, args_size, 0);
>
>              if (offset != 0)
>                dwarf2out_args_size_adjust (offset, label);
>            }
>        }
>
> Now the arg size adjustment is recorded whatever ACCUMULATE_OUTGOING_ARGS,
> thus leading to a bogus discrepancy.
>
> Hence the attached patch which fixes the bug as well as move some related
> functions in dwarf2out.c around.  Tested on x86-64, OK for mainline?
>
>
> 2009-11-08  Eric Botcazou  <ebotcazou@adacore.com>
>
>        * tree.h (dwarf2out_args_size): Delete.
>        * dwarf2out.c (dwarf2out_args_size): Make static and move around.
>        (dwarf2out_args_size_adjust): Delete prototype and move around.
>        (dwarf2out_frame_debug_expr): Do not record arg size adjustments for
>        ACCUMULATE_OUTGOING_ARGS targets.
>


Will it fix

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37022



-- 
H.J.



More information about the Gcc-patches mailing list