summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2010-02-04 16:38:05 +0000
committerAnders Carlsson <andersca@mac.com>2010-02-04 16:38:05 +0000
commit7914dad72dbfa20afc42046e0901a5885eabfba4 (patch)
tree9019c5376e0d7e6f67a24818ea8d75730f73bdf6 /clang/lib/CodeGen
parent0b56af81139fdde8461504c5978982da0aede690 (diff)
downloadbcm5719-llvm-7914dad72dbfa20afc42046e0901a5885eabfba4.tar.gz
bcm5719-llvm-7914dad72dbfa20afc42046e0901a5885eabfba4.zip
Calculate offset correctly when taking the address of a virtual member function.
llvm-svn: 95305
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/CGExprAgg.cpp6
-rw-r--r--clang/lib/CodeGen/CGExprConstant.cpp7
2 files changed, 10 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index cb6e1d81403..928cb616b24 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/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/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp
index 81209da6c6f..a358b54fa3c 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/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);
OpenPOWER on IntegriCloud