[Bug c/13588] New: little-endian code generated inappropriately

jcphillips at yahoo dot com gcc-bugzilla@gcc.gnu.org
Tue Jan 6 18:32:00 GMT 2004


If the option -mbig-endian -m210 is not given to the mcore-elf compiler, it will
generalte little-endian code.  However, if -mlittle-endian -m210 is given, the
compiler correctly says that the mcore 210 does not support little-endian.

Test case code, test2.c (pointer subtraction)
--------------------------------------------------------------------------
//this results in a bug when compiled with mcore-elf-gcc v3.3.1
//Compile using: mcore-elf-gcc -c -O2 -m210 test2.c
//Note:  This is to explore the handling of character pointer subtraction.

extern void CFunc(char *a, char len);
extern void HFunc(char *a, short len);
extern void LFunc(char *a, long len);

extern char *buf;

void test()
  {
  char *p=buf;
  char *q=p+5;

  //CFunc(buf,q-buf);
  HFunc(buf,q-buf);
  //LFunc(buf,q-buf);

  //CFunc(buf,buf-q);
  //HFunc(buf,buf-q);
  //LFunc(buf,buf-q);
  }
--------------------------------------------------------------------------
When compiled using:
  mcore-elf-gcc -c -O2 -m210 test2.c
The following code is generated:

test2.o:     file format elf32-mcore-big

Disassembly of section .text:

00000000 <test>:
test():
   0:   2470            subi    r0, 8
   2:   9f00            st      r15, (r0, 0)
   4:   7706            lrw     r7, 0x0 // from address pool at 0x1c
   6:   8207            ld      r2, (r7, 0)
   8:   1223            mov     r3, r2
   a:   2043            addi    r3, 5
   c:   c707            ldh     r7, (r7, 0)
   e:   0573            subu    r3, r7
  10:   0173            sexth   r3
  12:   7f03            jsri    0x0     // from address pool at 0x20
  14:   8f00            ld      r15, (r0, 0)
  16:   2070            addi    r0, 8
  18:   00cf            jmp     r15

--------------------------------------------------------------------------
Note that the line 
   c:   c707            ldh     r7, (r7, 0)
is incorrect.  When I add the compile option -mbig-endian, the line gets
correctly generated as:
   c:   c717            ldh     r7, (r7, 2)

When -mbig-endian is not specified, the compiler retrieves the least-significant
halfword of the address as if it were working with a little endian machine.

-- 
           Summary: little-endian code generated inappropriately
           Product: gcc
           Version: 3.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jcphillips at yahoo dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-cygwin
  GCC host triplet: i686-cygwin
GCC target triplet: mcore-elf


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



More information about the Gcc-bugs mailing list