Bug 36080 - Register specification ignored in template function.
Summary: Register specification ignored in template function.
Status: RESOLVED DUPLICATE of bug 33661
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.3.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-04-29 17:02 UTC by Adam Lackorzynski
Modified: 2008-04-29 17:09 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Adam Lackorzynski 2008-04-29 17:02:17 UTC
Hi,

when doing 'register int val asm("rx")' in a template function the explicit register allocation is ignored and val is given an arbitrary register without any notice. The following test shows that the asm-statement is ignored.

class X {
public:
  template <typename T> int func_template(int *x);
  int no_template(int *x);
};

template <typename T>
int X::func_template(int *x)
{
  register int val asm("doesn't matter what's in here");
  asm volatile("mov %0, %0"   : "=r" (val) : "0" (x));
  return val;
}

int X::no_template(int *x)
{
  register int val asm("edx");
  asm volatile("mov %0, %0"   : "=r" (val) : "0" (x));
  return int(val);
}

#include <cstdio>
int main(void)
{
  X x; int y;
  printf("%d %d\n", x.no_template(&y), x.func_template<int>(&y));
  return 0;
}

A normal function works as expected. We initially found this on a ARM target but it's the same on x86. I get the same results with various versions of native and cross compilers of 3.4, 4.1, 4.2, 4.3 and trunk.
Comment 1 Andrew Pinski 2008-04-29 17:09:17 UTC

*** This bug has been marked as a duplicate of 33661 ***