Fix latent bug in __expand_buitin_nonlocal_goto

Richard Guenther richard.guenther@gmail.com
Tue Jun 17 19:02:00 GMT 2008


On Tue, Jun 17, 2008 at 2:58 PM, Jan Hubicka <jh@suse.cz> wrote:
> Hi,
> with SSA at O0 the following testcase in testsuite:
> #ifndef NO_TRAMPOLINES
> extern void abort (void);
>
> int x(int a, int b)
> {
>  __label__ xlab;
>  __label__ xlab2;
>
>  __attribute__ ((noinline)) void y(int b)
>    {
>       switch (b)
>        {
>          case 1: goto xlab;
>          case 2: goto xlab;
>        }
>    }
>
>  a = a + 2;
>  y (b);
>
>  xlab:
>  return a;
>
>  xlab2:
>  a++;
>  return a;
>
> }
>
> is now compile nonlocal goto as
>
>  __builtin_nonlocal_goto (&<L0>, &CHAIN.1_2(D)->__nl_goto_buf);
>
> Instead of
>
>  D.1571_3 = &CHAIN.1_2(D)->__nl_goto_buf;
>  __builtin_nonlocal_goto (&<L0>, D.1571_3);
>  # SUCC:
>
> That leads to miscompilation
>
>
>        movl    $.L3, %eax
>        movq    -16(%rbp), %rdx
>        movq    (%rdx), %rbp
>        movq    -16(%rbp), %rdx
>        movq    8(%rdx), %rsp
>        jmp     *%rax
>
> Note the use of RBP to read RDX after RBP was restored.
>
> Honza

Ok if you bootstrapped/tested this and add the testcase to the testsuite.

Richard.

>        * builtins.c (expand_builtin_nonlocal_goto): Stabilize r_sp.
> Index: builtins.c
> ===================================================================
> --- builtins.c  (revision 136084)
> +++ builtins.c  (working copy)
> @@ -891,6 +891,7 @@
>  #endif
>     {
>       r_label = copy_to_reg (r_label);
> +      r_sp = copy_to_reg (r_sp);
>
>       emit_insn (gen_rtx_CLOBBER (VOIDmode,
>                                  gen_rtx_MEM (BLKmode,
>



More information about the Gcc-patches mailing list