2012-05-02 01:32:20 +08:00
|
|
|
// RUN: %clang_cc1 %s -emit-llvm -o - -triple=x86_64-unknown-unknown | FileCheck -check-prefix CODE-LP64 %s
|
|
|
|
// RUN: %clang_cc1 %s -emit-llvm -o - -triple=i386-unknown-unknown | FileCheck -check-prefix CODE-LP32 %s
|
|
|
|
// RUN: %clang_cc1 %s -emit-llvm -o - -triple=x86_64-unknown-unknown | FileCheck -check-prefix GLOBAL-LP64 %s
|
|
|
|
// RUN: %clang_cc1 %s -emit-llvm -o - -triple=i386-unknown-unknown | FileCheck -check-prefix GLOBAL-LP32 %s
|
|
|
|
// RUN: %clang_cc1 %s -emit-llvm -o - -triple=armv7-unknown-unknown | FileCheck -check-prefix GLOBAL-ARM %s
|
2013-07-25 00:25:13 +08:00
|
|
|
|
|
|
|
// PNaCl uses the same representation of method pointers as ARM.
|
|
|
|
// RUN: %clang_cc1 %s -emit-llvm -o - -triple=le32-unknown-nacl | FileCheck -check-prefix GLOBAL-ARM %s
|
2015-02-18 23:21:35 +08:00
|
|
|
// MIPS uses the same representation of method pointers as ARM.
|
|
|
|
// RUN: %clang_cc1 %s -emit-llvm -o - -triple=mips-unknown-linux-gnu | FileCheck -check-prefix GLOBAL-ARM %s
|
2015-09-04 06:51:53 +08:00
|
|
|
// WebAssembly uses the same representation of method pointers as ARM.
|
|
|
|
// RUN: %clang_cc1 %s -emit-llvm -o - -triple=wasm32-unknown-unknown | FileCheck -check-prefix GLOBAL-ARM %s
|
2009-09-29 11:38:56 +08:00
|
|
|
|
2010-02-05 00:38:05 +08:00
|
|
|
struct A { int a; void f(); virtual void vf1(); virtual void vf2(); };
|
2009-10-03 23:02:02 +08:00
|
|
|
struct B { int b; virtual void g(); };
|
2009-09-29 11:38:56 +08:00
|
|
|
struct C : B, A { };
|
|
|
|
|
|
|
|
void (A::*pa)();
|
|
|
|
void (A::*volatile vpa)();
|
|
|
|
void (B::*pb)();
|
|
|
|
void (C::*pc)();
|
|
|
|
|
2020-02-04 02:09:39 +08:00
|
|
|
// GLOBAL-LP64: @pa2 = global { i64, i64 } { i64 ptrtoint (void (%struct.A*)* @_ZN1A1fEv to i64), i64 0 }, align 8
|
2009-10-03 23:02:02 +08:00
|
|
|
void (A::*pa2)() = &A::f;
|
|
|
|
|
2020-02-04 02:09:39 +08:00
|
|
|
// GLOBAL-LP64: @pa3 = global { i64, i64 } { i64 1, i64 0 }, align 8
|
|
|
|
// GLOBAL-LP32: @pa3 = global { i32, i32 } { i32 1, i32 0 }, align 4
|
2010-02-05 00:38:05 +08:00
|
|
|
void (A::*pa3)() = &A::vf1;
|
|
|
|
|
2020-02-04 02:09:39 +08:00
|
|
|
// GLOBAL-LP64: @pa4 = global { i64, i64 } { i64 9, i64 0 }, align 8
|
|
|
|
// GLOBAL-LP32: @pa4 = global { i32, i32 } { i32 5, i32 0 }, align 4
|
2010-02-05 00:38:05 +08:00
|
|
|
void (A::*pa4)() = &A::vf2;
|
2009-10-03 23:02:02 +08:00
|
|
|
|
2020-02-04 02:09:39 +08:00
|
|
|
// GLOBAL-LP64: @pc2 = global { i64, i64 } { i64 ptrtoint (void (%struct.A*)* @_ZN1A1fEv to i64), i64 16 }, align 8
|
2009-10-03 23:13:22 +08:00
|
|
|
void (C::*pc2)() = &C::f;
|
|
|
|
|
2020-02-04 02:09:39 +08:00
|
|
|
// GLOBAL-LP64: @pc3 = global { i64, i64 } { i64 1, i64 0 }, align 8
|
2010-02-05 00:38:05 +08:00
|
|
|
void (A::*pc3)() = &A::vf1;
|
2009-10-03 23:13:22 +08:00
|
|
|
|
2009-09-29 11:38:56 +08:00
|
|
|
void f() {
|
2012-05-02 01:32:20 +08:00
|
|
|
// CODE-LP64: store { i64, i64 } zeroinitializer, { i64, i64 }* @pa
|
2009-09-29 11:38:56 +08:00
|
|
|
pa = 0;
|
2009-10-03 22:39:13 +08:00
|
|
|
|
2010-08-22 18:59:02 +08:00
|
|
|
// Is this okay? What are LLVM's volatile semantics for structs?
|
2012-05-02 01:32:20 +08:00
|
|
|
// CODE-LP64: store volatile { i64, i64 } zeroinitializer, { i64, i64 }* @vpa
|
2009-09-29 11:38:56 +08:00
|
|
|
vpa = 0;
|
2009-10-03 22:39:13 +08:00
|
|
|
|
2015-02-28 05:19:58 +08:00
|
|
|
// CODE-LP64: [[TMP:%.*]] = load { i64, i64 }, { i64, i64 }* @pa, align 8
|
2012-05-02 01:32:20 +08:00
|
|
|
// CODE-LP64: [[TMPADJ:%.*]] = extractvalue { i64, i64 } [[TMP]], 1
|
|
|
|
// CODE-LP64: [[ADJ:%.*]] = add nsw i64 [[TMPADJ]], 16
|
|
|
|
// CODE-LP64: [[RES:%.*]] = insertvalue { i64, i64 } [[TMP]], i64 [[ADJ]], 1
|
|
|
|
// CODE-LP64: store { i64, i64 } [[RES]], { i64, i64 }* @pc, align 8
|
2009-10-03 23:02:02 +08:00
|
|
|
pc = pa;
|
2009-11-27 12:56:40 +08:00
|
|
|
|
2015-02-28 05:19:58 +08:00
|
|
|
// CODE-LP64: [[TMP:%.*]] = load { i64, i64 }, { i64, i64 }* @pc, align 8
|
2012-05-02 01:32:20 +08:00
|
|
|
// CODE-LP64: [[TMPADJ:%.*]] = extractvalue { i64, i64 } [[TMP]], 1
|
|
|
|
// CODE-LP64: [[ADJ:%.*]] = sub nsw i64 [[TMPADJ]], 16
|
|
|
|
// CODE-LP64: [[RES:%.*]] = insertvalue { i64, i64 } [[TMP]], i64 [[ADJ]], 1
|
|
|
|
// CODE-LP64: store { i64, i64 } [[RES]], { i64, i64 }* @pa, align 8
|
2009-11-27 12:56:40 +08:00
|
|
|
pa = static_cast<void (A::*)()>(pc);
|
2009-09-29 11:38:56 +08:00
|
|
|
}
|
2009-10-03 23:43:24 +08:00
|
|
|
|
|
|
|
void f2() {
|
2012-05-02 01:32:20 +08:00
|
|
|
// CODE-LP64: store { i64, i64 } { i64 ptrtoint (void (%struct.A*)* @_ZN1A1fEv to i64), i64 0 }
|
2009-10-03 23:43:24 +08:00
|
|
|
void (A::*pa2)() = &A::f;
|
|
|
|
|
2012-05-02 01:32:20 +08:00
|
|
|
// CODE-LP64: store { i64, i64 } { i64 1, i64 0 }
|
|
|
|
// CODE-LP32: store { i32, i32 } { i32 1, i32 0 }
|
2010-02-05 00:38:05 +08:00
|
|
|
void (A::*pa3)() = &A::vf1;
|
|
|
|
|
2012-05-02 01:32:20 +08:00
|
|
|
// CODE-LP64: store { i64, i64 } { i64 9, i64 0 }
|
|
|
|
// CODE-LP32: store { i32, i32 } { i32 5, i32 0 }
|
2010-02-05 00:38:05 +08:00
|
|
|
void (A::*pa4)() = &A::vf2;
|
2009-10-03 23:43:24 +08:00
|
|
|
}
|
2009-10-04 03:43:08 +08:00
|
|
|
|
|
|
|
void f3(A *a, A &ar) {
|
|
|
|
(a->*pa)();
|
|
|
|
(ar.*pa)();
|
|
|
|
}
|
2009-10-14 01:41:28 +08:00
|
|
|
|
2009-11-24 04:04:44 +08:00
|
|
|
bool f4() {
|
|
|
|
return pa;
|
|
|
|
}
|
|
|
|
|
2009-10-14 01:41:28 +08:00
|
|
|
// PR5177
|
|
|
|
namespace PR5177 {
|
|
|
|
struct A {
|
|
|
|
bool foo(int*) const;
|
|
|
|
} a;
|
|
|
|
|
|
|
|
struct B1 {
|
|
|
|
bool (A::*pmf)(int*) const;
|
|
|
|
const A* pa;
|
|
|
|
|
|
|
|
B1() : pmf(&A::foo), pa(&a) {}
|
|
|
|
bool operator()() const { return (pa->*pmf)(new int); }
|
|
|
|
};
|
|
|
|
|
|
|
|
void bar(B1 b2) { while (b2()) ; }
|
|
|
|
}
|
2009-10-19 04:31:03 +08:00
|
|
|
|
|
|
|
// PR5138
|
|
|
|
namespace PR5138 {
|
|
|
|
struct foo {
|
|
|
|
virtual void bar(foo *);
|
|
|
|
};
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
void baz(foo *);
|
|
|
|
}
|
|
|
|
|
|
|
|
void (foo::*ptr1)(void *) = (void (foo::*)(void *))&foo::bar;
|
|
|
|
void (*ptr2)(void *) = (void (*)(void *))&baz;
|
|
|
|
|
|
|
|
void (foo::*ptr3)(void) = (void (foo::*)(void))&foo::bar;
|
|
|
|
}
|
2009-11-24 05:47:44 +08:00
|
|
|
|
|
|
|
// PR5593
|
|
|
|
namespace PR5593 {
|
|
|
|
struct A { };
|
|
|
|
|
|
|
|
bool f(void (A::*f)()) {
|
|
|
|
return f && f;
|
|
|
|
}
|
|
|
|
}
|
2009-12-11 15:36:43 +08:00
|
|
|
|
|
|
|
namespace PR5718 {
|
|
|
|
struct A { };
|
|
|
|
|
|
|
|
bool f(void (A::*f)(), void (A::*g)()) {
|
|
|
|
return f == g;
|
|
|
|
}
|
|
|
|
}
|
2009-12-11 17:26:29 +08:00
|
|
|
|
|
|
|
namespace BoolMemberPointer {
|
|
|
|
struct A { };
|
|
|
|
|
|
|
|
bool f(void (A::*f)()) {
|
|
|
|
return !f;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool g(void (A::*f)()) {
|
|
|
|
if (!!f)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-05 13:04:05 +08:00
|
|
|
// PR5940
|
|
|
|
namespace PR5940 {
|
|
|
|
class foo {
|
|
|
|
public:
|
|
|
|
virtual void baz(void);
|
|
|
|
};
|
|
|
|
|
|
|
|
void foo::baz(void) {
|
|
|
|
void (foo::*ptr)(void) = &foo::baz;
|
|
|
|
}
|
|
|
|
}
|
2010-01-16 08:00:48 +08:00
|
|
|
|
|
|
|
namespace MemberPointerImpCast {
|
|
|
|
struct A {
|
|
|
|
int x;
|
|
|
|
};
|
|
|
|
struct B : public A {
|
|
|
|
};
|
|
|
|
void f(B* obj, void (A::*method)()) {
|
|
|
|
(obj->*method)();
|
|
|
|
}
|
|
|
|
}
|
2010-02-08 01:37:13 +08:00
|
|
|
|
|
|
|
// PR6258
|
|
|
|
namespace PR6258 {
|
|
|
|
|
|
|
|
struct A {
|
|
|
|
void f(bool);
|
|
|
|
};
|
|
|
|
|
|
|
|
void (A::*pf)(bool) = &A::f;
|
|
|
|
|
|
|
|
void f() {
|
|
|
|
void (A::*pf)(bool) = &A::f;
|
|
|
|
}
|
|
|
|
}
|
2010-05-04 04:00:27 +08:00
|
|
|
|
|
|
|
// PR7027
|
|
|
|
namespace PR7027 {
|
|
|
|
struct X { void test( ); };
|
|
|
|
void testX() { &X::test; }
|
|
|
|
}
|
2010-08-22 14:43:33 +08:00
|
|
|
|
|
|
|
namespace test7 {
|
|
|
|
struct A { void foo(); virtual void vfoo(); };
|
|
|
|
struct B { void foo(); virtual void vfoo(); };
|
|
|
|
struct C : A, B { void foo(); virtual void vfoo(); };
|
|
|
|
|
2012-05-02 01:32:20 +08:00
|
|
|
// GLOBAL-ARM: @_ZN5test74ptr0E = global {{.*}} { i32 ptrtoint ({{.*}}* @_ZN5test71A3fooEv to i32), i32 0 }
|
|
|
|
// GLOBAL-ARM: @_ZN5test74ptr1E = global {{.*}} { i32 ptrtoint ({{.*}}* @_ZN5test71B3fooEv to i32), i32 8 }
|
|
|
|
// GLOBAL-ARM: @_ZN5test74ptr2E = global {{.*}} { i32 ptrtoint ({{.*}}* @_ZN5test71C3fooEv to i32), i32 0 }
|
|
|
|
// GLOBAL-ARM: @_ZN5test74ptr3E = global {{.*}} { i32 0, i32 1 }
|
|
|
|
// GLOBAL-ARM: @_ZN5test74ptr4E = global {{.*}} { i32 0, i32 9 }
|
|
|
|
// GLOBAL-ARM: @_ZN5test74ptr5E = global {{.*}} { i32 0, i32 1 }
|
2010-08-22 14:43:33 +08:00
|
|
|
void (C::*ptr0)() = &A::foo;
|
|
|
|
void (C::*ptr1)() = &B::foo;
|
|
|
|
void (C::*ptr2)() = &C::foo;
|
|
|
|
void (C::*ptr3)() = &A::vfoo;
|
|
|
|
void (C::*ptr4)() = &B::vfoo;
|
|
|
|
void (C::*ptr5)() = &C::vfoo;
|
|
|
|
}
|
2010-08-23 02:26:35 +08:00
|
|
|
|
|
|
|
namespace test8 {
|
|
|
|
struct X { };
|
|
|
|
typedef int (X::*pmf)(int);
|
|
|
|
|
|
|
|
// CHECK: {{define.*_ZN5test81fEv}}
|
|
|
|
pmf f() {
|
|
|
|
// CHECK: {{ret.*zeroinitializer}}
|
|
|
|
return pmf();
|
|
|
|
}
|
|
|
|
}
|
2011-03-16 05:17:48 +08:00
|
|
|
|
|
|
|
namespace test9 {
|
|
|
|
struct A {
|
|
|
|
void foo();
|
|
|
|
};
|
|
|
|
struct B : A {
|
|
|
|
void foo();
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef void (A::*fooptr)();
|
|
|
|
|
|
|
|
struct S {
|
|
|
|
fooptr p;
|
|
|
|
};
|
|
|
|
|
2020-02-04 02:09:39 +08:00
|
|
|
// CODE-LP64-LABEL: define void @_ZN5test94testEv(
|
2012-05-02 01:32:20 +08:00
|
|
|
// CODE-LP64: alloca i32
|
|
|
|
// CODE-LP64-NEXT: ret void
|
2011-03-16 05:17:48 +08:00
|
|
|
void test() {
|
|
|
|
int x;
|
|
|
|
static S array[] = { (fooptr) &B::foo };
|
|
|
|
}
|
|
|
|
}
|
2012-02-15 09:22:51 +08:00
|
|
|
|
|
|
|
// rdar://problem/10815683 - Verify that we can emit reinterprets of
|
|
|
|
// member pointers as constant initializers. For added trickiness,
|
|
|
|
// we also add some non-trivial adjustments.
|
|
|
|
namespace test10 {
|
|
|
|
struct A {
|
|
|
|
int nonEmpty;
|
|
|
|
void foo();
|
|
|
|
};
|
|
|
|
struct B : public A {
|
|
|
|
virtual void requireNonZeroAdjustment();
|
|
|
|
};
|
|
|
|
struct C {
|
|
|
|
int nonEmpty;
|
|
|
|
};
|
|
|
|
struct D : public C {
|
|
|
|
virtual void requireNonZeroAdjustment();
|
|
|
|
};
|
|
|
|
|
2012-05-02 01:32:20 +08:00
|
|
|
|
|
|
|
// It's not that the offsets are doubled on ARM, it's that they're left-shifted by 1.
|
|
|
|
|
2020-02-04 02:09:39 +08:00
|
|
|
// GLOBAL-LP64: @_ZN6test101aE = global { i64, i64 } { i64 ptrtoint (void (%"struct.test10::A"*)* @_ZN6test101A3fooEv to i64), i64 0 }, align 8
|
|
|
|
// GLOBAL-LP32: @_ZN6test101aE = global { i32, i32 } { i32 ptrtoint (void (%"struct.test10::A"*)* @_ZN6test101A3fooEv to i32), i32 0 }, align 4
|
2012-05-02 01:32:20 +08:00
|
|
|
// GLOBAL-ARM: @_ZN6test101aE = global { i32, i32 } { i32 ptrtoint (void (%"struct.test10::A"*)* @_ZN6test101A3fooEv to i32), i32 0 }, align 4
|
2012-02-15 09:22:51 +08:00
|
|
|
void (A::*a)() = &A::foo;
|
2012-05-02 01:32:20 +08:00
|
|
|
|
2020-02-04 02:09:39 +08:00
|
|
|
// GLOBAL-LP64: @_ZN6test101bE = global { i64, i64 } { i64 ptrtoint (void (%"struct.test10::A"*)* @_ZN6test101A3fooEv to i64), i64 8 }, align 8
|
2012-05-02 01:32:20 +08:00
|
|
|
// GLOBAL-LP32: @_ZN6test101bE = global { i32, i32 } { i32 ptrtoint (void (%"struct.test10::A"*)* @_ZN6test101A3fooEv to i32), i32 4 }, align 4
|
|
|
|
// GLOBAL-ARM: @_ZN6test101bE = global { i32, i32 } { i32 ptrtoint (void (%"struct.test10::A"*)* @_ZN6test101A3fooEv to i32), i32 8 }, align 4
|
2012-02-15 09:22:51 +08:00
|
|
|
void (B::*b)() = (void (B::*)()) &A::foo;
|
2012-05-02 01:32:20 +08:00
|
|
|
|
2020-02-04 02:09:39 +08:00
|
|
|
// GLOBAL-LP64: @_ZN6test101cE = global { i64, i64 } { i64 ptrtoint (void (%"struct.test10::A"*)* @_ZN6test101A3fooEv to i64), i64 8 }, align 8
|
2012-05-02 01:32:20 +08:00
|
|
|
// GLOBAL-LP32: @_ZN6test101cE = global { i32, i32 } { i32 ptrtoint (void (%"struct.test10::A"*)* @_ZN6test101A3fooEv to i32), i32 4 }, align 4
|
|
|
|
// GLOBAL-ARM: @_ZN6test101cE = global { i32, i32 } { i32 ptrtoint (void (%"struct.test10::A"*)* @_ZN6test101A3fooEv to i32), i32 8 }, align 4
|
2012-02-15 09:22:51 +08:00
|
|
|
void (C::*c)() = (void (C::*)()) (void (B::*)()) &A::foo;
|
2012-05-02 01:32:20 +08:00
|
|
|
|
2020-02-04 02:09:39 +08:00
|
|
|
// GLOBAL-LP64: @_ZN6test101dE = global { i64, i64 } { i64 ptrtoint (void (%"struct.test10::A"*)* @_ZN6test101A3fooEv to i64), i64 16 }, align 8
|
2012-05-02 01:32:20 +08:00
|
|
|
// GLOBAL-LP32: @_ZN6test101dE = global { i32, i32 } { i32 ptrtoint (void (%"struct.test10::A"*)* @_ZN6test101A3fooEv to i32), i32 8 }, align 4
|
|
|
|
// GLOBAL-ARM: @_ZN6test101dE = global { i32, i32 } { i32 ptrtoint (void (%"struct.test10::A"*)* @_ZN6test101A3fooEv to i32), i32 16 }, align 4
|
2012-02-15 09:22:51 +08:00
|
|
|
void (D::*d)() = (void (C::*)()) (void (B::*)()) &A::foo;
|
|
|
|
}
|
2012-05-02 01:32:20 +08:00
|
|
|
|
|
|
|
namespace test11 {
|
|
|
|
struct A { virtual void a(); };
|
|
|
|
struct B : A {};
|
|
|
|
struct C : B { virtual void a(); };
|
|
|
|
void (C::*x)() = &C::a;
|
|
|
|
|
2020-02-04 02:09:39 +08:00
|
|
|
// GLOBAL-LP64: @_ZN6test111xE = global { i64, i64 } { i64 1, i64 0 }
|
2012-05-02 01:32:20 +08:00
|
|
|
// GLOBAL-LP32: @_ZN6test111xE = global { i32, i32 } { i32 1, i32 0 }
|
|
|
|
// GLOBAL-ARM: @_ZN6test111xE = global { i32, i32 } { i32 0, i32 1 }
|
|
|
|
}
|