public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/56715] New: Explicit Reg Vars are being ignored for consts when using g++
@ 2013-03-24 23:25 goswin-v-b at web dot de
  2013-03-24 23:33 ` [Bug c++/56715] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: goswin-v-b at web dot de @ 2013-03-24 23:25 UTC (permalink / raw)
  To: gcc-bugs


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: unassigned@gcc.gnu.org
        ReportedBy: goswin-v-b@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.


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

* [Bug c++/56715] Explicit Reg Vars are being ignored for consts when using g++
  2013-03-24 23:25 [Bug c++/56715] New: Explicit Reg Vars are being ignored for consts when using g++ goswin-v-b at web dot de
@ 2013-03-24 23:33 ` pinskia at gcc dot gnu.org
  2013-03-25  0:07 ` goswin-v-b at web dot de
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2013-03-24 23:33 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2013-03-24 23:33:16 UTC ---
const is a bit special in C++, it can be used as part of a const integer
expression which is what is happening here.


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

* [Bug c++/56715] Explicit Reg Vars are being ignored for consts when using g++
  2013-03-24 23:25 [Bug c++/56715] New: Explicit Reg Vars are being ignored for consts when using g++ goswin-v-b at web dot de
  2013-03-24 23:33 ` [Bug c++/56715] " pinskia at gcc dot gnu.org
@ 2013-03-25  0:07 ` goswin-v-b at web dot de
  2013-03-25  8:50 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: goswin-v-b at web dot de @ 2013-03-25  0:07 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #2 from Goswin von Brederlow <goswin-v-b at web dot de> 2013-03-25 00:07:19 UTC ---
(In reply to comment #1)
> const is a bit special in C++, it can be used as part of a const integer
> expression which is what is happening here.

How does that make it right to ignore the register specification? Or how do you
specify which register to use to pass the constant to asm in a specific
register?

To me it seems wrong to ignore the asm("r4") without even a warning. This does
break asm() statements that expect specific registers to be used.


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

* [Bug c++/56715] Explicit Reg Vars are being ignored for consts when using g++
  2013-03-24 23:25 [Bug c++/56715] New: Explicit Reg Vars are being ignored for consts when using g++ goswin-v-b at web dot de
  2013-03-24 23:33 ` [Bug c++/56715] " pinskia at gcc dot gnu.org
  2013-03-25  0:07 ` goswin-v-b at web dot de
@ 2013-03-25  8:50 ` jakub at gcc dot gnu.org
  2013-03-25 10:18 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-03-25  8:50 UTC (permalink / raw)
  To: gcc-bugs


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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-03-25 08:50:15 UTC ---
Simply don't use const on the register asm vars for C++.  The thing is that
already the C++ frontend is replacing all the r4 const var uses with just
0x1000 (i.e. the initializer), that isn't really an optimization, but part of
C++ semantics.  r4 is an integral constant expression that evaluates to 0x1000.
 See
ISO C++ 98, [expr.const]/1.  So in foo what you are doing is actually
void foo() {
    register const int r4 asm("r4") = 0x1000;
    asm volatile("swi #1" : : "r"(0x1000));
}
and that of course can use any available register.


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

* [Bug c++/56715] Explicit Reg Vars are being ignored for consts when using g++
  2013-03-24 23:25 [Bug c++/56715] New: Explicit Reg Vars are being ignored for consts when using g++ goswin-v-b at web dot de
                   ` (2 preceding siblings ...)
  2013-03-25  8:50 ` jakub at gcc dot gnu.org
@ 2013-03-25 10:18 ` rguenth at gcc dot gnu.org
  2013-03-25 11:11 ` goswin-v-b at web dot de
  2013-03-25 11:23 ` jakub at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-03-25 10:18 UTC (permalink / raw)
  To: gcc-bugs


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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> 2013-03-25 10:18:10 UTC ---
Thus invalid.


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

* [Bug c++/56715] Explicit Reg Vars are being ignored for consts when using g++
  2013-03-24 23:25 [Bug c++/56715] New: Explicit Reg Vars are being ignored for consts when using g++ goswin-v-b at web dot de
                   ` (3 preceding siblings ...)
  2013-03-25 10:18 ` rguenth at gcc dot gnu.org
@ 2013-03-25 11:11 ` goswin-v-b at web dot de
  2013-03-25 11:23 ` jakub at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: goswin-v-b at web dot de @ 2013-03-25 11:11 UTC (permalink / raw)
  To: gcc-bugs


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

Goswin von Brederlow <goswin-v-b at web dot de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |

--- Comment #5 from Goswin von Brederlow <goswin-v-b at web dot de> 2013-03-25 11:11:52 UTC ---
If it is invalid, as in not allowed, then I would expect an error. If it is
undefined behaviour then I would expect a warning.

For example:

    register const int r4 asm("r4") = 0x1000;
Warning: const expression wont be bound to a specific register.


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

* [Bug c++/56715] Explicit Reg Vars are being ignored for consts when using g++
  2013-03-24 23:25 [Bug c++/56715] New: Explicit Reg Vars are being ignored for consts when using g++ goswin-v-b at web dot de
                   ` (4 preceding siblings ...)
  2013-03-25 11:11 ` goswin-v-b at web dot de
@ 2013-03-25 11:23 ` jakub at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-03-25 11:23 UTC (permalink / raw)
  To: gcc-bugs


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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-03-25 11:22:53 UTC ---
But it isn't invalid, as in not allowed, just your assumptions about what it
does are wrong.


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

end of thread, other threads:[~2013-03-25 11:23 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-24 23:25 [Bug c++/56715] New: Explicit Reg Vars are being ignored for consts when using g++ goswin-v-b at web dot de
2013-03-24 23:33 ` [Bug c++/56715] " pinskia at gcc dot gnu.org
2013-03-25  0:07 ` goswin-v-b at web dot de
2013-03-25  8:50 ` jakub at gcc dot gnu.org
2013-03-25 10:18 ` rguenth at gcc dot gnu.org
2013-03-25 11:11 ` goswin-v-b at web dot de
2013-03-25 11:23 ` jakub at gcc dot gnu.org

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