xref: /llvm-project/clang/test/CodeGenCXX/member-function-pointer-calls.cpp (revision 1b9a6e58a8b831193c9e5e733f881aabe0d2d06b)
1 // RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -O3 -o - | FileCheck %s
2 /// Check that we pass the member pointers indirectly for MinGW64
3 // RUN: %clang_cc1 %s -triple=x86_64-windows-gnu -emit-llvm -o - | FileCheck %s -check-prefix MINGW64
4 /// We should be able to optimize calls via the indirectly passed member pointers
5 // RUN: %clang_cc1 %s -triple=x86_64-windows-gnu -emit-llvm -O3 -o - | FileCheck %s
6 struct A {
vf1A7   virtual int vf1() { return 1; }
vf2A8   virtual int vf2() { return 2; }
9 };
10 
f(A * a,int (A::* fp)())11 int f(A* a, int (A::*fp)()) {
12   return (a->*fp)();
13 }
14 
15 // CHECK-LABEL: define{{.*}} i32 @_Z2g1v()
16 // CHECK-NOT: }
17 // CHECK: ret i32 1
18 // MINGW64-LABEL: define dso_local noundef i32 @_Z2g1v()
19 // MINGW64: call noundef i32 @_Z1fP1AMS_FivE(ptr noundef %{{.*}}, ptr noundef %{{.*}})
g1()20 int g1() {
21   A a;
22   return f(&a, &A::vf1);
23 }
24 
25 // CHECK-LABEL: define{{.*}} i32 @_Z2g2v()
26 // CHECK-NOT: }
27 // CHECK: ret i32 2
28 // MINGW64-LABEL: define dso_local noundef i32 @_Z2g2v()
29 // MINGW64: call noundef i32 @_Z1fP1AMS_FivE(ptr noundef %{{.*}}, ptr noundef %{{.*}})
g2()30 int g2() {
31   A a;
32   return f(&a, &A::vf2);
33 }
34