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



             Bug #: 56715

           Summary: Explicit Reg Vars are being ignored for consts when

                    using g++

    Classification: Unclassified

           Product: gcc

           Version: 4.7.2

            Status: UNCONFIRMED

          Severity: normal

          Priority: P3

         Component: c++

        AssignedTo: unassig...@gcc.gnu.org

        ReportedBy: goswin-...@web.de





Created attachment 29714

  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29714

example source that experiences the bug



I'm trying to pass a value to an `asm' operand using a specific register for

arm with a freestanding compiler. Following the example from the info pages I

have the following code:



void foo() {

    register const int r4 asm("r4") = 0x1000;

    asm volatile("swi #1" : : "r"(r4));

}



void bar() {

    register int r4 asm("r4") = 0x1000;

    asm volatile("swi #1" : : "r"(r4));

}



Both foo() and bar() compile correct when using gcc. But when using g++ the

foo() function suddenly uses the "r3" register instead of "r4". The bar()

function remains correct.



% arm-none-eabi-g++ -v 

Using built-in specs.

COLLECT_GCC=arm-none-eabi-g++

COLLECT_LTO_WRAPPER=/usr/local/cross/libexec/gcc/arm-none-eabi/4.7.2/lto-wrapper

Target: arm-none-eabi

Configured with: ../gcc-4.7.2/configure --target=arm-none-eabi

--prefix=/usr/local/cross --disable-nls --enable-languages=c,c++

--without-headers

Thread model: single

gcc version 4.7.2 (GCC) 



% arm-none-eabi-gcc -O2 -save-temps -S bug.c         good code

% arm-none-eabi-g++ -O2 -save-temps -S bug.c         bad code



------------------------------------------------------------------

_Z3foov:

        .fnstart

.LFB0:

        @ Function supports interworking.

        @ args = 0, pretend = 0, frame = 0

        @ frame_needed = 0, uses_anonymous_args = 0

        @ link register save eliminated.

        mov     r3, #4096

@ 3 "bug.c" 1

        swi #1

@ 0 "" 2

        bx      lr

------------------------------------------------------------------

The source explicitly asked for "r4" but g++ uses r3 instead.

Reply via email to