diff options
author | Anders Carlsson <andersca@mac.com> | 2010-02-04 16:38:05 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2010-02-04 16:38:05 +0000 |
commit | e8a81f7e8e26275d91c073bf908a7d6d246106c5 (patch) | |
tree | 04ec611e4a0bc2af0ef0f03a00b2d56ef7beed27 /lib | |
parent | 03db470ec53315368f200a2382590e41ef9ff8d4 (diff) |
Calculate offset correctly when taking the address of a virtual member function.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95305 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CodeGen/CGExprAgg.cpp | 6 | ||||
-rw-r--r-- | lib/CodeGen/CGExprConstant.cpp | 7 |
2 files changed, 10 insertions, 3 deletions
diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp index cb6e1d8140..928cb616b2 100644 --- a/lib/CodeGen/CGExprAgg.cpp +++ b/lib/CodeGen/CGExprAgg.cpp @@ -327,7 +327,11 @@ void AggExprEmitter::VisitUnaryAddrOf(const UnaryOperator *E) { int64_t Index = CGF.CGM.getVtableInfo().getMethodVtableIndex(MD); - FuncPtr = llvm::ConstantInt::get(PtrDiffTy, Index + 1); + // Itanium C++ ABI 2.3: + // For a non-virtual function, this field is a simple function pointer. + // For a virtual function, it is 1 plus the virtual table offset + // (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); diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index 81209da6c6..a358b54fa3 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -418,8 +418,11 @@ public: // Get the function pointer (or index if this is a virtual function). if (MD->isVirtual()) { uint64_t Index = CGM.getVtableInfo().getMethodVtableIndex(MD); - - // The pointer is 1 + the virtual table offset in bytes. + + // Itanium C++ ABI 2.3: + // For a non-virtual function, this field is a simple function pointer. + // For a virtual function, it is 1 plus the virtual table offset + // (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); |