public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug inline-asm/64951] New: g++ generates incorrect code when using a register variable within a template function
@ 2015-02-05 19:13 gdelugre@security-labs.org
  2015-09-19 15:47 ` [Bug inline-asm/64951] " gdelugre@security-labs.org
  0 siblings, 1 reply; 2+ messages in thread
From: gdelugre@security-labs.org @ 2015-02-05 19:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64951

            Bug ID: 64951
           Summary: g++ generates incorrect code when using a register
                    variable within a template function
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: inline-asm
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gdelugre@security-labs.org

Created attachment 34679
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34679&action=edit
Test case for comparing register assignment in a normal function and a template
function

g++ doesn't generate the expected code when using a register variable bound to
a specific CPU register inside a template function.
For instance:

  template<typename T>
  inline void SetRdx(T value)
  {
      register auto __foo asm ("rdx") = value;
      asm volatile ( "" :: "r" (__foo) );
  }

Calling it with: SetRdx(0x42) will generate the following assembly code:

  mov    $0x42,%eax

instead of the expected:

  mov    $0x42,%edx

Moreover, specifying a non-existent CPU register inside the "asm" directive
still compiles and does not throw any error:

  register auto __foo asm ("foobar") = value; // compiles to mov $0x42, %eax

It looks as if the asm directive is completely ignored when used within a
template function.

This behavior has been reproduced on gcc 4.9.2, 4.8 and 4.7.


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

* [Bug inline-asm/64951] g++ generates incorrect code when using a register variable within a template function
  2015-02-05 19:13 [Bug inline-asm/64951] New: g++ generates incorrect code when using a register variable within a template function gdelugre@security-labs.org
@ 2015-09-19 15:47 ` gdelugre@security-labs.org
  0 siblings, 0 replies; 2+ messages in thread
From: gdelugre@security-labs.org @ 2015-09-19 15:47 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64951

Guillaume Delugré <gdelugre@security-labs.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|4.9.2                       |5.2.0

--- Comment #1 from Guillaume Delugré <gdelugre@security-labs.org> ---
The same problem is present when using C++14 auto arguments instead of
templates:

  inline void SetRdx(auto value)
  {
      register auto __foo asm ("rdx") = value;
      asm volatile ( "" :: "r" (__foo) );
  }

This code will also store the value parameter inside register rax instead of
rdx on GCC 5.2.0.
>From gcc-bugs-return-497578-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Sat Sep 19 16:57:57 2015
Return-Path: <gcc-bugs-return-497578-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 34019 invoked by alias); 19 Sep 2015 16:57:56 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 33471 invoked by uid 48); 19 Sep 2015 16:57:52 -0000
From: "olegendo at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/67638] New: [SH] ICE with nosave_low_regs ISR and -mfmovd
Date: Sat, 19 Sep 2015 16:57:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: new
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: target
X-Bugzilla-Version: unknown
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: olegendo at gcc dot gnu.org
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Resolution:
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone cf_gcctarget
Message-ID: <bug-67638-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-09/txt/msg01556.txt.bz2
Content-length: 1484

https://gcc.gnu.org/bugzilla/show_bug.cgi?idg638

            Bug ID: 67638
           Summary: [SH] ICE with nosave_low_regs ISR and -mfmovd
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: olegendo at gcc dot gnu.org
  Target Milestone: ---
            Target: sh*-*-*

When compiling the test cases pragma-isr-nosave_low_regs.c and
attr-isr-nosave_low_regs.c in gcc.target/sh there's an ICE:

attr-isr-nosave_low_regs.c: In function 'isr':
attr-isr-nosave_low_regs.c:25:1: internal compiler error: in get_free_reg, at
config/sh/sh.c:10204
0xd9ab6a get_free_reg
        ../../gcc-trunk2/gcc/config/sh/sh.c:10204
0xd9ab6a fpscr_set_from_mem(int, unsigned long*)
        ../../gcc-trunk2/gcc/config/sh/sh.c:10217
0xd9fe17 push_regs
        ../../gcc-trunk2/gcc/config/sh/sh.c:7191
0xd9fe17 sh_expand_prologue()
        ../../gcc-trunk2/gcc/config/sh/sh.c:7942
0xe8b53a gen_prologue()
        ../../gcc-trunk2/gcc/config/sh/sh.md:11649
0xd8bbc8 target_gen_prologue
        ../../gcc-trunk2/gcc/config/sh/sh.md:16732
0x812c7d thread_prologue_and_epilogue_insns()
        ../../gcc-trunk2/gcc/function.c:6119
0x8136e2 rest_of_handle_thread_prologue_and_epilogue
        ../../gcc-trunk2/gcc/function.c:6670
0x8136e2 execute
        ../../gcc-trunk2/gcc/function.c:6712
Please submit a full bug report,


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

end of thread, other threads:[~2015-09-19 15:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-05 19:13 [Bug inline-asm/64951] New: g++ generates incorrect code when using a register variable within a template function gdelugre@security-labs.org
2015-09-19 15:47 ` [Bug inline-asm/64951] " gdelugre@security-labs.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).