This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug target/31938] New: Wrong code on int to short cast on armeb


Casting a 32 bit integer to a 16 bit integer on armeb with -Os causes the
compiler to generate wrong code.

Short sample:
int foo = 4;

int blah()
{
        int bar;

        bar = (unsigned short)foo;

        return bar;
}

This function returns 0 when compiled with -Os on GCC 4.2.0, -Os on 4.1.2 and
with -O2 or -Os on 3.4.6. Correct code is generated on 4.2.0 and 4.1.2 with -O2

Compiled like this:
$ armeb-elf-gcc -v -Os -c gcctest.c -save-temps
Using built-in specs.
Target: armeb-elf
Configured with: ../gcc-4.2.0/configure --target=armeb-elf
--enable-languages=c,c++
Thread model: single
gcc version 4.2.0
 /usr/local/libexec/gcc/armeb-elf/4.2.0/cc1 -E -quiet -v -D__USES_INITFINI__
gcctest.c -Os -fpch-preprocess -o gcctest.i
ignoring nonexistent directory
"/usr/local/lib/gcc/armeb-elf/4.2.0/../../../../armeb-elf/sys-include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/lib/gcc/armeb-elf/4.2.0/include
 /usr/local/lib/gcc/armeb-elf/4.2.0/../../../../armeb-elf/include
End of search list.
 /usr/local/libexec/gcc/armeb-elf/4.2.0/cc1 -fpreprocessed gcctest.i -quiet
-dumpbase gcctest.c -auxbase gcctest -Os -version -o gcctest.s
GNU C version 4.2.0 (armeb-elf)
        compiled by GNU C version 4.1.3 20070429 (prerelease) (Debian 4.1.2-6).
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 8a7e5f1c6981e39f06bc8d2ace868d72
 /usr/local/lib/gcc/armeb-elf/4.2.0/../../../../armeb-elf/bin/as -o gcctest.o
gcctest.s

Generates the following code:

        .file   "gcctest.c"
        .text
        .align  2
        .global blah
        .type   blah, %function
blah:
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        @ link register save eliminated.
        ldr     r3, .L3
        ldrh    r0, [r3, #0]
        @ lr needed for prologue
        bx      lr
.L4:
        .align  2
.L3:
        .word   foo
        .size   blah, .-blah
        .global foo
        .data
        .align  2
        .type   foo, %object
        .size   foo, 4
foo:
        .word   4
        .ident  "GCC: (GNU) 4.2.0"

Which tries to load a 16 bit value from the address of foo, which will always
be 0.


-- 
           Summary: Wrong code on int to short cast on armeb
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bigfoot at private dot dk
 GCC build triplet: i686-linux-gnu
  GCC host triplet: i686-linux-gnu
GCC target triplet: armeb-unknown-elf


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]