aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2010-02-07 17:37:13 +0000
committerAnders Carlsson <andersca@mac.com>2010-02-07 17:37:13 +0000
commit585fa68ca00421af6c8289866a7bde27a8e8c0ce (patch)
tree523ea9e204ba16f2a2dcdc9abb972f30693496d4
parent63644fae3970d4146200e4cb25dd9aace34a3398 (diff)
Use the right type when taking the address of a non-virtual member function pointer. Fixes PR6258.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95524 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/CGExprAgg.cpp8
-rw-r--r--lib/CodeGen/CGExprConstant.cpp6
-rw-r--r--test/CodeGenCXX/member-function-pointers.cpp20
3 files changed, 28 insertions, 6 deletions
diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp
index bdeecb85be..b6340dcbb9 100644
--- a/lib/CodeGen/CGExprAgg.cpp
+++ b/lib/CodeGen/CGExprAgg.cpp
@@ -333,8 +333,12 @@ void AggExprEmitter::VisitUnaryAddrOf(const UnaryOperator *E) {
// (in bytes) of the function, represented as a ptrdiff_t.
FuncPtr = llvm::ConstantInt::get(PtrDiffTy, (Index * 8) + 1);
} else {
- FuncPtr = llvm::ConstantExpr::getPtrToInt(CGF.CGM.GetAddrOfFunction(MD),
- PtrDiffTy);
+ const FunctionProtoType *FPT = MD->getType()->getAs<FunctionProtoType>();
+ const llvm::Type *Ty =
+ CGF.CGM.getTypes().GetFunctionType(CGF.CGM.getTypes().getFunctionInfo(MD),
+ FPT->isVariadic());
+ llvm::Constant *Fn = CGF.CGM.GetAddrOfFunction(MD, Ty);
+ FuncPtr = llvm::ConstantExpr::getPtrToInt(Fn, PtrDiffTy);
}
Builder.CreateStore(FuncPtr, DstPtr, VolatileDest);
diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp
index dca09feebc..5800ce770c 100644
--- a/lib/CodeGen/CGExprConstant.cpp
+++ b/lib/CodeGen/CGExprConstant.cpp
@@ -425,8 +425,12 @@ public:
// (in bytes) of the function, represented as a ptrdiff_t.
Values[0] = llvm::ConstantInt::get(PtrDiffTy, (Index * 8) + 1);
} else {
- llvm::Constant *FuncPtr = CGM.GetAddrOfFunction(MD);
+ const FunctionProtoType *FPT = MD->getType()->getAs<FunctionProtoType>();
+ const llvm::Type *Ty =
+ CGM.getTypes().GetFunctionType(CGM.getTypes().getFunctionInfo(MD),
+ FPT->isVariadic());
+ llvm::Constant *FuncPtr = CGM.GetAddrOfFunction(MD, Ty);
Values[0] = llvm::ConstantExpr::getPtrToInt(FuncPtr, PtrDiffTy);
}
diff --git a/test/CodeGenCXX/member-function-pointers.cpp b/test/CodeGenCXX/member-function-pointers.cpp
index b69aea7fb6..f7c445b1cb 100644
--- a/test/CodeGenCXX/member-function-pointers.cpp
+++ b/test/CodeGenCXX/member-function-pointers.cpp
@@ -9,7 +9,7 @@ void (A::*volatile vpa)();
void (B::*pb)();
void (C::*pc)();
-// CHECK: @pa2 = global %0 { i64 ptrtoint (void ()* @_ZN1A1fEv to i64), i64 0 }, align 8
+// CHECK: @pa2 = global %0 { i64 ptrtoint (void (%struct.A*)* @_ZN1A1fEv to i64), i64 0 }, align 8
void (A::*pa2)() = &A::f;
// CHECK: @pa3 = global %0 { i64 1, i64 0 }, align 8
@@ -18,7 +18,7 @@ void (A::*pa3)() = &A::vf1;
// CHECK: @pa4 = global %0 { i64 9, i64 0 }, align 8
void (A::*pa4)() = &A::vf2;
-// CHECK: @pc2 = global %0 { i64 ptrtoint (void ()* @_ZN1A1fEv to i64), i64 16 }, align 8
+// CHECK: @pc2 = global %0 { i64 ptrtoint (void (%struct.A*)* @_ZN1A1fEv to i64), i64 16 }, align 8
void (C::*pc2)() = &C::f;
// CHECK: @pc3 = global %0 { i64 1, i64 0 }, align 8
@@ -46,7 +46,7 @@ void f() {
void f2() {
// CHECK: [[pa2ptr:%[a-zA-Z0-9\.]+]] = getelementptr inbounds %0* %pa2, i32 0, i32 0
- // CHECK: store i64 ptrtoint (void ()* @_ZN1A1fEv to i64), i64* [[pa2ptr]]
+ // CHECK: store i64 ptrtoint (void (%struct.A*)* @_ZN1A1fEv to i64), i64* [[pa2ptr]]
// CHECK: [[pa2adj:%[a-zA-Z0-9\.]+]] = getelementptr inbounds %0* %pa2, i32 0, i32 1
// CHECK: store i64 0, i64* [[pa2adj]]
void (A::*pa2)() = &A::f;
@@ -159,3 +159,17 @@ namespace MemberPointerImpCast {
(obj->*method)();
}
}
+
+// PR6258
+namespace PR6258 {
+
+ struct A {
+ void f(bool);
+ };
+
+ void (A::*pf)(bool) = &A::f;
+
+ void f() {
+ void (A::*pf)(bool) = &A::f;
+ }
+}