NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

toolchain/40694: gcc tail-call vs. volatile bug



>Number:         40694
>Category:       toolchain
>Synopsis:       gcc tail-call vs. volatile bug
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    toolchain-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Feb 19 18:00:00 +0000 2009
>Originator:     David A. Holland
>Release:        NetBSD 5.99.7 (20090209)
>Organization:
>Environment:
System: NetBSD tanaqui 5.99.7 NetBSD 5.99.7 (TANAQUI) #24: Mon Feb 9 11:19:51 
EST 2009 root@tanaqui:/usr/src/sys/arch/i386/compile/TANAQUI i386
Architecture: i386
Machine: i386

% gcc -v
Using built-in specs.
Target: i386--netbsdelf
Configured with: /usr/src/tools/gcc/../../gnu/dist/gcc4/configure 
--enable-long-long --disable-multilib --enable-threads --disable-symvers 
--build=x86_64-unknown-netbsd4.99.72 --host=i386--netbsdelf 
--target=i386--netbsdelf --enable-__cxa_atexit
Thread model: posix
gcc version 4.1.3 20080704 prerelease (NetBSD nb2 20081120)

>Description:

Compiling the following fragment (gcc -O2 -S foo.c) generates an
invalid tail call that does not repeat the local (volatile, no less)
variable on a new stack frame.

void
recurse_inf(void)
{
   volatile char buf[16];
   buf[0] = 0;
   recurse_inf();
}

This is what I get out:

        .file   "foo.c"
        .text
        .p2align 2,,3
.globl recurse_inf
        .type   recurse_inf, @function
recurse_inf:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $16, %esp
        .p2align 2,,3
.L3:
        movb    $0, -16(%ebp)
        jmp     .L3
        .size   recurse_inf, .-recurse_inf
        .ident  "GCC: (GNU) 4.1.3 20080704 prerelease (NetBSD nb2 20081120)"


On a plain gcc 4.1.2 configured for mips I get two byte stores per
loop, too, which blatantly violates the volatile rules:

00400238 <recurse_inf>:
  400238:       27bdfff0        addiu   sp,sp,-16
  40023c:       a3a00000        sb      zero,0(sp)
  400240:       a3a00000        sb      zero,0(sp)
  400244:       0810008f        j       40023c <recurse_inf+0x4>
  400248:       00000000        nop

I don't currently have time to build our gcc for mips and test it on
that to see if that aspect has been fixed since 4.1.2.

>How-To-Repeat:

As above.

>Fix:
?

I haven't reported this upstream because I don't currently have time
to test on a gcc they're still taking bug reports for.



Home | Main Index | Thread Index | Old Index