Refine codegen for covariant thunks that return references.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85916 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp
index 65ed767..3608d34 100644
--- a/lib/AST/Type.cpp
+++ b/lib/AST/Type.cpp
@@ -224,6 +224,8 @@
return OPT->getPointeeType();
if (const BlockPointerType *BPT = getAs<BlockPointerType>())
return BPT->getPointeeType();
+ if (const ReferenceType *RT = getAs<ReferenceType>())
+ return RT->getPointeeType();
return QualType();
}
diff --git a/lib/CodeGen/CGVtable.cpp b/lib/CodeGen/CGVtable.cpp
index 3980330..e2e1147 100644
--- a/lib/CodeGen/CGVtable.cpp
+++ b/lib/CodeGen/CGVtable.cpp
@@ -159,8 +159,8 @@
/// getNVOffset - Returns the non-virtual offset for the given (B) base of the
/// derived class D.
Index_t getNVOffset(QualType qB, QualType qD) {
- qD = qD->getAs<PointerType>()->getPointeeType();
- qB = qB->getAs<PointerType>()->getPointeeType();
+ qD = qD->getPointeeType();
+ qB = qB->getPointeeType();
CXXRecordDecl *D = cast<CXXRecordDecl>(qD->getAs<RecordType>()->getDecl());
CXXRecordDecl *B = cast<CXXRecordDecl>(qB->getAs<RecordType>()->getDecl());
int64_t o = getNVOffset_1(D, B);
@@ -174,8 +174,8 @@
/// getVbaseOffset - Returns the index into the vtable for the virtual base
/// offset for the given (B) virtual base of the derived class D.
Index_t getVbaseOffset(QualType qB, QualType qD) {
- qD = qD->getAs<PointerType>()->getPointeeType();
- qB = qB->getAs<PointerType>()->getPointeeType();
+ qD = qD->getPointeeType();
+ qB = qB->getPointeeType();
CXXRecordDecl *D = cast<CXXRecordDecl>(qD->getAs<RecordType>()->getDecl());
CXXRecordDecl *B = cast<CXXRecordDecl>(qB->getAs<RecordType>()->getDecl());
if (D != Class)
diff --git a/test/CodeGenCXX/virt.cpp b/test/CodeGenCXX/virt.cpp
index e0067d6..4607e6a 100644
--- a/test/CodeGenCXX/virt.cpp
+++ b/test/CodeGenCXX/virt.cpp
@@ -1113,6 +1113,38 @@
// CHECK-LP64-NEXT: .quad __ZN9test17_B13barEv
+struct test18_NV1 {
+ virtual void fooNV1() { }
+virtual void foo_NV1() { }
+ int i;
+};
+
+struct test18_NV2 {
+ virtual test18_NV2& foo1() { return *this; }
+virtual void foo_NV2() { }
+virtual void foo_NV2b() { }
+ int i;
+};
+
+struct test18_B : public test18_NV1, test18_NV2 {
+ virtual test18_B& foo1() { return *this; }
+ virtual test18_B *foo2() { return 0; }
+ virtual test18_B *foo3() { return 0; }
+virtual void foo_B() { }
+ int i;
+};
+
+struct test18_B2 : test18_NV1, virtual test18_B {
+ virtual test18_B2& foo1() { return *this; }
+ virtual test18_B2 *foo2() { return 0; }
+virtual void foo_B2() { }
+ int i;
+};
+
+struct test18_D : test18_NV1, virtual test18_B2 {
+ virtual test18_D& foo1() { return *this; }
+} d;
+
// CHECK-LP64: __ZTV1B:
// CHECK-LP64-NEXT: .space 8