[i386] Fix wrong argument value on Windows

Uros Bizjak ubizjak@gmail.com
Wed Feb 6 10:36:00 GMT 2019


> this is a regression present on all active branches: if you compile the
> attached Ada testcase with -O2 -gnatp -fno-omit-frame-pointer for 32-bit
> Windows, you'll see that the compiler swaps a load based on the stack pointer
> with a store based on the frame pointer, thus clobbering a saved argument:
>
>        pushl   %ebp
>        movl    %esp, %ebp
>        pushl   %esi
>        pushl   %ebx
>        pushl   %eax              <- %eax save
>        movl    $4108, %eax
>        call    ___chkstk_ms
>        leal    8(%ebp), %esi
>        subl    %eax, %esp
>        movl    8(%ebp), %ebx
>        movl    %edx, -20(%ebp)
>        movl    %esi, -12(%ebp)    <- fp-based store
>        movl    (%esp,%eax), %eax  <- sp-based load
>        ... wrong value in eax...
>
> The load and the store are swapped because there are not based on the same
> register and the offset between them is seen as variable.  The proposed fix is
> to add a memory blockage, like in other frame-related constructs.
>
> Tested on x86/Windows and x86-64/Windows, OK for all active branches?
>
>
> 2019-02-06  Eric Botcazou  <ebotcazou@adacore.com>
>
> * config/i386/i386.c (ix86_expand_prologue): Generate a memory blockage
> after restoring registers saved to allocate the frame on Windows.
>
>
> 2019-02-06  Eric Botcazou  <ebotcazou@adacore.com>
>
> * gnat.dg/opt76.adb: New test.

OK everywhere.

Thanks,
Uros.



More information about the Gcc-patches mailing list