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

Reply via email to