public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/21392] New: Wrong code generated for array of enum with "mode" attribute
@ 2005-05-04 21:33 pkoning at equallogic dot com
  2005-05-05  0:03 ` [Bug middle-end/21392] " pinskia at gcc dot gnu dot org
  2005-05-05  0:04 ` pinskia at gcc dot gnu dot org
  0 siblings, 2 replies; 4+ messages in thread
From: pkoning at equallogic dot com @ 2005-05-04 21:33 UTC (permalink / raw)
  To: gcc-bugs

Test code:

typedef enum { false, true } bool __attribute__((mode (byte)));

bool foo[16];

bool test (int i)
{
    return foo[i];
}

This works with v3.3.3.  With V4.0.0, the generated code is wrong -- it
references the array element as a word (4 bytes) yet indexes it as bytes.  In
this particular test case, the generated code does unaligned loads (why is not
clear); in an example in my application where the bool array is on the stack, it
generated a regular word load, killing the program due to an unaligned access.

Presumably related: when I ask gdb what it thinks sizeof(foo[0]) is, I get 4
rather than the expected 1.

-- 
           Summary: Wrong code generated for array of enum with "mode"
                    attribute
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pkoning at equallogic dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i386-unknown-netbsdelf1.6.2
  GCC host triplet: i386-unknown-netbsdelf1.6.2
GCC target triplet: mipsel-netbsdelf


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21392


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug middle-end/21392] Wrong code generated for array of enum with "mode" attribute
  2005-05-04 21:33 [Bug c/21392] New: Wrong code generated for array of enum with "mode" attribute pkoning at equallogic dot com
@ 2005-05-05  0:03 ` pinskia at gcc dot gnu dot org
  2005-05-05  0:04 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-05  0:03 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |middle-end


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21392


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug middle-end/21392] Wrong code generated for array of enum with "mode" attribute
  2005-05-04 21:33 [Bug c/21392] New: Wrong code generated for array of enum with "mode" attribute pkoning at equallogic dot com
  2005-05-05  0:03 ` [Bug middle-end/21392] " pinskia at gcc dot gnu dot org
@ 2005-05-05  0:04 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-05  0:04 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
  GCC build triplet|i386-unknown-netbsdelf1.6.2 |
   GCC host triplet|i386-unknown-netbsdelf1.6.2 |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21392


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug middle-end/21392] Wrong code generated for array of enum with "mode" attribute
       [not found] <bug-21392-8722@http.gcc.gnu.org/bugzilla/>
@ 2006-02-16  2:26 ` jde at google dot com
  0 siblings, 0 replies; 4+ messages in thread
From: jde at google dot com @ 2006-02-16  2:26 UTC (permalink / raw)
  To: gcc-bugs



------- 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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-02-16  2:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-04 21:33 [Bug c/21392] New: Wrong code generated for array of enum with "mode" attribute pkoning at equallogic dot com
2005-05-05  0:03 ` [Bug middle-end/21392] " pinskia at gcc dot gnu dot org
2005-05-05  0:04 ` pinskia at gcc dot gnu dot org
     [not found] <bug-21392-8722@http.gcc.gnu.org/bugzilla/>
2006-02-16  2:26 ` jde at google dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).