Subject: possible bug in gcc
To: port-powerpc <port-powerpc@netbsd.org>
From: Erik Anggard <erik.anggard@packetfront.com>
List: port-powerpc
Date: 03/16/2003 01:30:19
Hi,

I'd like to know if it is only my gcc that has been messed up somehow or 
if anyone else running NetBSD on a powerpc arch (I'm running 1.6D 
macppc) can reproduce this bug as shown below. Note: the dummy-function 
used below is of course pretty useless but I'd still like gcc to produce 
at least an blr-instruction at the end. If I remove any of the 
case-blocks or if I use -O0 or -O1 gcc will produce correct code. Very 
strange. (I've also tried the procedure below on an i386 machine and 
there gcc produced correct code with -O2, that's why I posted this 
question on port-powerpc).

Thanks,
Erik

$ cc -v
Using builtin specs.
gcc version 2.95.3 20010315 (release) (NetBSD nb3)
$ cat > dummy.c
void
dummy(int i)
{
        int n;

        switch (i) {
        case 0:
                n = 0;
                break;
        case 1:
                n = 1;
                break;
        case 2:
                n = 2;
                break;
        case 3:
                n = 3;
                break;
        case 4:
                n = 4;
                break;
        }
}
^d
$ cc -O2 -c dummy.c
$ objdump -D dummy.o

dummy.o:     file format elf32-powerpc

Disassembly of section .text:

00000000 <dummy>:
   0:   28 03 00 04     cmplwi  r3,4
Disassembly of section .data:
$