diff options
-rw-r--r-- | lib/CodeGen/CGVtable.cpp | 12 | ||||
-rw-r--r-- | test/CodeGenCXX/virt-call-offsets.cpp | 8 |
2 files changed, 18 insertions, 2 deletions
diff --git a/lib/CodeGen/CGVtable.cpp b/lib/CodeGen/CGVtable.cpp index 868a341440..5283ed9366 100644 --- a/lib/CodeGen/CGVtable.cpp +++ b/lib/CodeGen/CGVtable.cpp @@ -952,7 +952,15 @@ void CGVtableInfo::ComputeMethodVtableIndices(const CXXRecordDecl *RD) { // we need to start counting at the end of the primary base's vtable. CurrentIndex = getNumVirtualFunctionPointers(PrimaryBase); } - + + // Collect all the primary bases, so we can check whether methods override + // a method from the base. + llvm::SmallPtrSet<const CXXRecordDecl *, 5> PrimaryBases; + for (ASTRecordLayout::primary_base_info_iterator + I = Layout.primary_base_begin(), E = Layout.primary_base_end(); + I != E; ++I) + PrimaryBases.insert((*I).getBase()); + const CXXDestructorDecl *ImplicitVirtualDtor = 0; for (CXXRecordDecl::method_iterator i = RD->method_begin(), @@ -973,7 +981,7 @@ void CGVtableInfo::ComputeMethodVtableIndices(const CXXRecordDecl *RD) { assert(OverriddenMD->isCanonicalDecl() && "Should have the canonical decl of the overridden RD!"); - if (OverriddenRD == PrimaryBase) { + if (PrimaryBases.count(OverriddenRD)) { // Check if converting from the return type of the method to the // return type of the overridden method requires conversion. QualType ReturnType = diff --git a/test/CodeGenCXX/virt-call-offsets.cpp b/test/CodeGenCXX/virt-call-offsets.cpp new file mode 100644 index 0000000000..db0ba2f483 --- /dev/null +++ b/test/CodeGenCXX/virt-call-offsets.cpp @@ -0,0 +1,8 @@ +// RUN: clang -cc1 %s -emit-llvm -o - | FileCheck %s + +struct A { virtual void a(); }; +struct B : A {}; +struct C : B { virtual void a(); }; +void (C::*x)() = &C::a; + +// CHECK: @x = global %0 { i{{[0-9]+}} 1, i{{[0-9]+}} 0 } |