summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/abi/regparm1.C
blob: 42a54a0e02aa1e4e4a6b13b2638603d746efbbf3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// PR c++/29911 (9381)
// { dg-options -std=c++0x }
// { dg-do run { target i?86-*-* x86_64-*-* } }

extern "C" int printf(const char *, ...);

void *save_this;
int *save_addr1, *save_addr2;

int fail;

struct Base
{
  __attribute((regparm(3))) void
  set(int *addr1, int *addr2)
  {
    if (this != save_this)
      {
	++fail;
	printf("error! this == %p, should be %p\n", this, save_this);
      }
    if (addr1 != save_addr1)
      {
	++fail;
	printf("error! addr1 == %p, should be %p\n", addr1, save_addr1);
      }
    if (addr2 != save_addr2)
      {
	++fail;
	printf("error! addr2 == %p, should be %p\n", addr2, save_addr1);
      }
  }
};

int main()
{
  void (__attribute((regparm(3))) Base::* pfm)(int *, int *) = &Base::set;
  __typeof (&Base::set) pfm2 = &Base::set;
  decltype (&Base::set) pfm3 = &Base::set;
  auto pfm4 = &Base::set;

  Base obj; save_this = &obj;
  int x, y; save_addr1 = &x; save_addr2 = &y;

  (obj.* pfm) (&x, &y);
  (obj.* pfm2) (&x, &y);
  (obj.* pfm3) (&x, &y);
  (obj.* pfm4) (&x, &y);

  return fail;
}