[Bug inline-asm/64951] g++ generates incorrect code when using a register variable within a template function

2015-09-19 Thread gdelu...@security-labs.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64951

Guillaume Delugré  changed:

   What|Removed |Added

Version|4.9.2   |5.2.0

--- Comment #1 from Guillaume Delugré  ---
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.

[Bug inline-asm/64951] New: g++ generates incorrect code when using a register variable within a template function

2015-02-05 Thread gdelu...@security-labs.org
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: gdelu...@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
  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.