This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/21392] Wrong code generated for array of enum with "mode" attribute
- From: "jde at google dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 16 Feb 2006 02:26:19 -0000
- Subject: [Bug middle-end/21392] Wrong code generated for array of enum with "mode" attribute
- References: <bug-21392-8722@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #1 from jde at google dot com 2006-02-16 02:26 -------
I was able to reproduce this bug. Indeed the offset is bytewise but the load is
done with a movl ("movl foo+2, %eax") Below is the program used to reproduce,
the compiler and flags used, and the resultant output & assembly.
Cheers
-Jeff
[calliope]% cat main.c
#include <stdio.h>
typedef enum { false, true } bool __attribute__((mode (byte)));
bool foo[16] = { 1, 0, 1, 0, 1, 0, 1, 0,
1, 0, 1, 0, 1, 0, 1, 0 } ;
long test (int i)
{
return foo[i];
}
int main(int argc, char*argv[])
{
printf ("foo[2] (should be 1): %d\n", test(2));
printf ("foo[5] (should be 0): %d\n", test(5));
}
[calliope]% i686-piii-linux-gnu-gcc-4.0.1 -O6 main.c -o main ; ./main
foo[2] (should be 1): 0
foo[5] (should be 0): 16777216
[calliope]% cat main.s
.file "main.c"
.globl foo
.data
.type foo, @object
.size foo, 16
foo:
.long 1
.long 0
.long 1
.long 0
.long 1
.long 0
.long 1
.long 0
.long 1
.long 0
.long 1
.long 0
.long 1
.long 0
.long 1
.long 0
.text
.p2align 4,,15
.globl test
.type test, @function
test:
pushl %ebp
movl %esp, %ebp
movl 8(%ebp), %eax
popl %ebp
movl foo(%eax), %eax
ret
.size test, .-test
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "foo[2] (should be 1): %d\n"
.LC1:
.string "foo[5] (should be 0): %d\n"
.text
.p2align 4,,15
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
movl foo+2, %eax
andl $-16, %esp
subl $16, %esp
movl $.LC0, (%esp)
movl %eax, 4(%esp)
call printf
movl foo+5, %eax
movl $.LC1, 8(%ebp)
movl %eax, 12(%ebp)
leave
jmp printf
.size main, .-main
.ident "GCC: (GNU) 4.0.1"
.section .note.GNU-stack,"",@progbits
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21392