diff options
author | Anders Carlsson <andersca@mac.com> | 2009-10-06 17:54:23 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-10-06 17:54:23 +0000 |
commit | 80ef6f1a46663d33dfaffb5170014e047890727f (patch) | |
tree | 56160075844b98110e2fbdcce18ecbc40a400ef9 | |
parent | e66abdc58f628a026ba3eee1bf4caaa182e07262 (diff) | |
download | bcm5719-llvm-80ef6f1a46663d33dfaffb5170014e047890727f.tar.gz bcm5719-llvm-80ef6f1a46663d33dfaffb5170014e047890727f.zip |
Pass the right type to GetAddrOfFunction when getting functions for the VTable. Fixes PR5021.
llvm-svn: 83395
-rw-r--r-- | clang/lib/CodeGen/CGCXX.cpp | 20 | ||||
-rw-r--r-- | clang/test/CodeGenCXX/virtual-function-calls.cpp | 16 |
2 files changed, 32 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CGCXX.cpp b/clang/lib/CodeGen/CGCXX.cpp index 2d5c62e3e23..a119c5af932 100644 --- a/clang/lib/CodeGen/CGCXX.cpp +++ b/clang/lib/CodeGen/CGCXX.cpp @@ -891,7 +891,13 @@ public: ++mi) if (mi->isVirtual()) { const CXXMethodDecl *MD = *mi; - llvm::Constant *m = wrap(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 *m = wrap(CGM.GetAddrOfFunction(MD, Ty)); OverrideMethod(MD, m, MorallyVirtual, Offset); } } @@ -901,9 +907,15 @@ public: llvm::Constant *m = 0; if (const CXXDestructorDecl *Dtor = dyn_cast<CXXDestructorDecl>(MD)) m = wrap(CGM.GetAddrOfCXXDestructor(Dtor, Dtor_Complete)); - else - m = wrap(CGM.GetAddrOfFunction(MD)); - + else { + const FunctionProtoType *FPT = MD->getType()->getAs<FunctionProtoType>(); + const llvm::Type *Ty = + CGM.getTypes().GetFunctionType(CGM.getTypes().getFunctionInfo(MD), + FPT->isVariadic()); + + m = wrap(CGM.GetAddrOfFunction(MD, Ty)); + } + // If we can find a previously allocated slot for this, reuse it. if (OverrideMethod(MD, m, MorallyVirtual, Offset)) return; diff --git a/clang/test/CodeGenCXX/virtual-function-calls.cpp b/clang/test/CodeGenCXX/virtual-function-calls.cpp new file mode 100644 index 00000000000..40028596381 --- /dev/null +++ b/clang/test/CodeGenCXX/virtual-function-calls.cpp @@ -0,0 +1,16 @@ +// PR5021 +struct A { + virtual void f(char); +}; + +void f(A *a) { + a->f('c'); +} +// PR5021 +struct A { + virtual void f(char); +}; + +void f(A *a) { + a->f('c'); +} |