r192822 - [-cxx-abi microsoft] Fix this argument/parameter offsets for virtual destructors in the presence of virtual bases

Timur Iskhodzhanov timurrrr at google.com
Wed Oct 16 11:24:07 PDT 2013


Author: timurrrr
Date: Wed Oct 16 13:24:06 2013
New Revision: 192822

URL: http://llvm.org/viewvc/llvm-project?rev=192822&view=rev
Log:
[-cxx-abi microsoft] Fix this argument/parameter offsets for virtual destructors in the presence of virtual bases

Reviewed at http://llvm-reviews.chandlerc.com/D1939

Modified:
    cfe/trunk/lib/AST/VTableBuilder.cpp
    cfe/trunk/lib/CodeGen/CGClass.cpp
    cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
    cfe/trunk/test/CodeGenCXX/microsoft-abi-multiple-nonvirtual-inheritance.cpp
    cfe/trunk/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp
    cfe/trunk/test/CodeGenCXX/microsoft-abi-vtables-multiple-nonvirtual-inheritance.cpp
    cfe/trunk/test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance.cpp

Modified: cfe/trunk/lib/AST/VTableBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/VTableBuilder.cpp?rev=192822&r1=192821&r2=192822&view=diff
==============================================================================
--- cfe/trunk/lib/AST/VTableBuilder.cpp (original)
+++ cfe/trunk/lib/AST/VTableBuilder.cpp Wed Oct 16 13:24:06 2013
@@ -2668,11 +2668,6 @@ CharUnits
 VFTableBuilder::ComputeThisOffset(const CXXMethodDecl *MD,
                                   BaseSubobject Base,
                                   FinalOverriders::OverriderInfo Overrider) {
-  // Complete object virtual destructors are always emitted in the most derived
-  // class, thus don't have this offset.
-  if (isa<CXXDestructorDecl>(MD))
-    return CharUnits();
-
   InitialOverriddenDefinitionCollector Collector;
   visitAllOverriddenMethods(MD, Collector);
 
@@ -2690,6 +2685,7 @@ VFTableBuilder::ComputeThisOffset(const
        I != E; ++I) {
     const CXXBasePath &Path = (*I);
     CharUnits ThisOffset = Base.getBaseOffset();
+    bool SeenVBase = false;
 
     // For each path from the overrider to the parents of the overridden methods,
     // traverse the path, calculating the this offset in the most derived class.
@@ -2701,6 +2697,7 @@ VFTableBuilder::ComputeThisOffset(const
       const ASTRecordLayout &Layout = Context.getASTRecordLayout(PrevRD);
 
       if (Element.Base->isVirtual()) {
+        SeenVBase = true;
         if (Overrider.Method->getParent() == PrevRD) {
           // This one's interesting. If the final overrider is in a vbase B of the
           // most derived class and it overrides a method of the B's own vbase A,
@@ -2713,11 +2710,22 @@ VFTableBuilder::ComputeThisOffset(const
         } else {
           ThisOffset = MostDerivedClassLayout.getVBaseClassOffset(CurRD);
         }
+
+        // A virtual destructor of a virtual base takes the address of the
+        // virtual base subobject as the "this" argument.
+        if (isa<CXXDestructorDecl>(MD))
+          break;
       } else {
         ThisOffset += Layout.getBaseClassOffset(CurRD);
       }
     }
 
+    // If a "Base" class has at least one non-virtual base with a virtual
+    // destructor, the "Base" virtual destructor will take the address of the
+    // "Base" subobject as the "this" argument.
+    if (!SeenVBase && isa<CXXDestructorDecl>(MD))
+      return Base.getBaseOffset();
+
     if (Ret > ThisOffset || First) {
       First = false;
       Ret = ThisOffset;

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=192822&r1=192821&r2=192822&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Wed Oct 16 13:24:06 2013
@@ -1829,8 +1829,8 @@ void CodeGenFunction::EmitCXXDestructorC
                                             bool ForVirtualBase,
                                             bool Delegating,
                                             llvm::Value *This) {
-  llvm::Value *VTT = GetVTTParameter(GlobalDecl(DD, Type),
-                                     ForVirtualBase, Delegating);
+  GlobalDecl GD(DD, Type);
+  llvm::Value *VTT = GetVTTParameter(GD, ForVirtualBase, Delegating);
   llvm::Value *Callee = 0;
   if (getLangOpts().AppleKext)
     Callee = BuildAppleKextVirtualDestructorCall(DD, Type, 
@@ -1838,7 +1838,10 @@ void CodeGenFunction::EmitCXXDestructorC
     
   if (!Callee)
     Callee = CGM.GetAddrOfCXXDestructor(DD, Type);
-  
+
+  if (DD->isVirtual())
+    This = CGM.getCXXABI().adjustThisArgumentForVirtualCall(*this, GD, This);
+
   // FIXME: Provide a source location here.
   EmitCXXMemberCall(DD, SourceLocation(), Callee, ReturnValueSlot(), This,
                     VTT, getContext().getPointerType(getContext().VoidPtrTy),

Modified: cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp?rev=192822&r1=192821&r2=192822&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp Wed Oct 16 13:24:06 2013
@@ -563,21 +563,65 @@ llvm::Value *MicrosoftCXXABI::adjustThis
     CodeGenFunction &CGF, GlobalDecl GD, llvm::Value *This) {
   GD = GD.getCanonicalDecl();
   const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
-  if (isa<CXXDestructorDecl>(MD))
-    return This;
+  // FIXME: consider splitting the vdtor vs regular method code into two
+  // functions.
 
+  GlobalDecl LookupGD = GD;
+  if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(MD)) {
+    // Complete dtors take a pointer to the complete object,
+    // thus don't need adjustment.
+    if (GD.getDtorType() == Dtor_Complete)
+      return This;
+
+    // There's only Dtor_Deleting in vftable but it shares the this adjustment
+    // with the base one, so look up the deleting one instead.
+    LookupGD = GlobalDecl(DD, Dtor_Deleting);
+  }
   MicrosoftVFTableContext::MethodVFTableLocation ML =
-      CGM.getVFTableContext().getMethodVFTableLocation(GD);
+      CGM.getVFTableContext().getMethodVFTableLocation(LookupGD);
 
   unsigned AS = cast<llvm::PointerType>(This->getType())->getAddressSpace();
   llvm::Type *charPtrTy = CGF.Int8Ty->getPointerTo(AS);
+  CharUnits StaticOffset = ML.VFTableOffset;
   if (ML.VBase) {
-    This = CGF.Builder.CreateBitCast(This, charPtrTy);
-    llvm::Value *VBaseOffset = CGM.getCXXABI()
-        .GetVirtualBaseClassOffset(CGF, This, MD->getParent(), ML.VBase);
-    This = CGF.Builder.CreateInBoundsGEP(This, VBaseOffset);
+    bool AvoidVirtualOffset = false;
+    if (isa<CXXDestructorDecl>(MD) && GD.getDtorType() == Dtor_Base) {
+      // A base destructor can only be called from a complete destructor of the
+      // same record type or another destructor of a more derived type.
+      const CXXRecordDecl *CurRD =
+          cast<CXXDestructorDecl>(CGF.CurGD.getDecl())->getParent();
+
+      if (MD->getParent() == CurRD) {
+        assert(CGF.CurGD.getDtorType() == Dtor_Complete);
+        // We're calling the main base dtor from a complete dtor, so we know the
+        // "this" offset statically.
+        AvoidVirtualOffset = true;
+      } else {
+        // Let's see if we try to call a destructor of a non-virtual base.
+        for (CXXRecordDecl::base_class_const_iterator I = CurRD->bases_begin(),
+             E = CurRD->bases_end(); I != E; ++I) {
+          if (I->getType()->getAsCXXRecordDecl() != MD->getParent())
+            continue;
+          // If we call a base destructor for a non-virtual base, we statically
+          // know where it expects the vfptr and "this" to be.
+          AvoidVirtualOffset = true;
+          break;
+        }
+      }
+    }
+
+    if (AvoidVirtualOffset) {
+      const ASTRecordLayout &Layout =
+          CGF.getContext().getASTRecordLayout(MD->getParent());
+      // This reflects the logic from VFTableBuilder::ComputeThisOffset().
+      StaticOffset += Layout.getVBaseClassOffset(ML.VBase);
+    } else {
+      This = CGF.Builder.CreateBitCast(This, charPtrTy);
+      llvm::Value *VBaseOffset = CGM.getCXXABI()
+          .GetVirtualBaseClassOffset(CGF, This, MD->getParent(), ML.VBase);
+      This = CGF.Builder.CreateInBoundsGEP(This, VBaseOffset);
+    }
   }
-  CharUnits StaticOffset = ML.VFTableOffset;
   if (!StaticOffset.isZero()) {
     assert(StaticOffset.isPositive());
     This = CGF.Builder.CreateBitCast(This, charPtrTy);
@@ -625,8 +669,18 @@ llvm::Value *MicrosoftCXXABI::adjustThis
     CodeGenFunction &CGF, GlobalDecl GD, llvm::Value *This) {
   GD = GD.getCanonicalDecl();
   const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
-  if (isa<CXXDestructorDecl>(MD))
-    return This;
+
+  GlobalDecl LookupGD = GD;
+  if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(MD)) {
+    // Complete destructors take a pointer to the complete object as a
+    // parameter, thus don't need this adjustment.
+    if (GD.getDtorType() == Dtor_Complete)
+      return This;
+
+    // There's no Dtor_Base in vftable but it shares the this adjustment with
+    // the deleting one, so look it up instead.
+    LookupGD = GlobalDecl(DD, Dtor_Deleting);
+  }
 
   // In this ABI, every virtual function takes a pointer to one of the
   // subobjects that first defines it as the 'this' parameter, rather than a
@@ -635,7 +689,7 @@ llvm::Value *MicrosoftCXXABI::adjustThis
   // See comments in the MicrosoftVFTableContext implementation for the details.
 
   MicrosoftVFTableContext::MethodVFTableLocation ML =
-      CGM.getVFTableContext().getMethodVFTableLocation(GD);
+      CGM.getVFTableContext().getMethodVFTableLocation(LookupGD);
   CharUnits Adjustment = ML.VFTableOffset;
   if (ML.VBase) {
     const ASTRecordLayout &DerivedLayout =
@@ -850,17 +904,18 @@ void MicrosoftCXXABI::EmitVirtualDestruc
 
   // We have only one destructor in the vftable but can get both behaviors
   // by passing an implicit int parameter.
+  GlobalDecl GD(Dtor, Dtor_Deleting);
   const CGFunctionInfo *FInfo =
       &CGM.getTypes().arrangeCXXDestructor(Dtor, Dtor_Deleting);
   llvm::Type *Ty = CGF.CGM.getTypes().GetFunctionType(*FInfo);
-  llvm::Value *Callee =
-      getVirtualFunctionPointer(CGF, GlobalDecl(Dtor, Dtor_Deleting), This, Ty);
+  llvm::Value *Callee = getVirtualFunctionPointer(CGF, GD, This, Ty);
 
   ASTContext &Context = CGF.getContext();
   llvm::Value *ImplicitParam =
       llvm::ConstantInt::get(llvm::IntegerType::getInt32Ty(CGF.getLLVMContext()),
                              DtorType == Dtor_Deleting);
 
+  This = adjustThisArgumentForVirtualCall(CGF, GD, This);
   CGF.EmitCXXMemberCall(Dtor, CallLoc, Callee, ReturnValueSlot(), This,
                         ImplicitParam, Context.IntTy, 0, 0);
 }

Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-multiple-nonvirtual-inheritance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-multiple-nonvirtual-inheritance.cpp?rev=192822&r1=192821&r2=192822&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/microsoft-abi-multiple-nonvirtual-inheritance.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/microsoft-abi-multiple-nonvirtual-inheritance.cpp Wed Oct 16 13:24:06 2013
@@ -181,3 +181,21 @@ void emit_ctors() {
   // CHECK:   store [1 x i8*]* @"\01??_7GrandchildOverride@@6BRight@@@", [1 x i8*]** %[[VFPTR]]
   // CHECK: ret
 }
+
+struct LeftWithNonVirtualDtor {
+  virtual void left();
+  ~LeftWithNonVirtualDtor();
+};
+
+struct AsymmetricChild : LeftWithNonVirtualDtor, Right {
+  virtual ~AsymmetricChild();
+};
+
+void call_asymmetric_child_complete_dtor() {
+  // CHECK-LABEL: define void @"\01?call_asymmetric_child_complete_dtor@@YAXXZ"
+  AsymmetricChild obj;
+  // CHECK: call x86_thiscallcc %struct.AsymmetricChild* @"\01??0AsymmetricChild@@QAE at XZ"(%struct.AsymmetricChild* %[[OBJ:.*]])
+  // CHECK-NOT: getelementptr
+  // CHECK: call x86_thiscallcc void @"\01??1AsymmetricChild@@UAE at XZ"(%struct.AsymmetricChild* %[[OBJ]])
+  // CHECK: ret
+}

Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp?rev=192822&r1=192821&r2=192822&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp Wed Oct 16 13:24:06 2013
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 %s -fno-rtti -cxx-abi microsoft -triple=i386-pc-win32 -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -fno-rtti -cxx-abi microsoft -triple=i386-pc-win32 -emit-llvm -o %t
+// RUN: FileCheck %s < %t
+// RUN: FileCheck --check-prefix=CHECK2 %s < %t
 
 // For now, just make sure x86_64 doesn't crash.
 // RUN: %clang_cc1 %s -fno-rtti -cxx-abi microsoft -triple=x86_64-pc-win32 -emit-llvm -o %t
@@ -50,7 +52,12 @@ B::B() {
 
 B::~B() {
   // CHECK-LABEL: define x86_thiscallcc void @"\01??1B@@UAE at XZ"
-  // CHECK:   %[[THIS:.*]] = load %struct.B**
+  // Adjust the this parameter:
+  // CHECK:   %[[THIS_PARAM_i8:.*]] = bitcast %struct.B* {{.*}} to i8*
+  // CHECK:   %[[THIS_i8:.*]] = getelementptr i8* %[[THIS_PARAM_i8]], i64 -8
+  // CHECK:   %[[THIS:.*]] = bitcast i8* %[[THIS_i8]] to %struct.B*
+  // CHECK:   store %struct.B* %[[THIS]], %struct.B** %[[THIS_ADDR:.*]], align 4
+  // CHECK:   %[[THIS:.*]] = load %struct.B** %[[THIS_ADDR]]
 
   // Restore the vfptr that could have been changed by a subclass.
   // CHECK:   %[[THIS_i8:.*]] = bitcast %struct.B* %[[THIS]] to i8*
@@ -76,6 +83,28 @@ B::~B() {
   foo();  // Avoid the "trivial destructor" optimization.
 
   // CHECK: ret
+
+  // CHECK2-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_DB@@UAE at XZ"(%struct.B*
+  // CHECK2: %[[THIS:.*]] = load %struct.B** {{.*}}
+  // CHECK2: %[[THIS_i8:.*]] = bitcast %struct.B* %[[THIS]] to i8*
+  // CHECK2: %[[B_i8:.*]] = getelementptr inbounds i8* %[[THIS_i8]], i64 8
+  // CHECK2: %[[B:.*]] = bitcast i8* %[[B_i8]] to %struct.B*
+  // CHECK2: call x86_thiscallcc void @"\01??1B@@UAE at XZ"(%struct.B* %[[B]])
+  // CHECK2: %[[THIS_i8:.*]] = bitcast %struct.B* %[[THIS]] to i8*
+  // CHECK2: %[[VBASE_i8:.*]] = getelementptr inbounds i8* %[[THIS_i8]], i64 8
+  // CHECK2: %[[VBASE:.*]] = bitcast i8* %[[VBASE_i8]] to %struct.VBase*
+  // CHECK2: call x86_thiscallcc void @"\01??1VBase@@UAE at XZ"(%struct.VBase* %[[VBASE]])
+  // CHECK2: ret
+
+  // CHECK2-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_GB@@UAEPAXI at Z"
+  // CHECK2:   %[[THIS_PARAM_i8:.*]] = bitcast %struct.B* {{.*}} to i8*
+  // CHECK2:   %[[THIS_i8:.*]] = getelementptr i8* %[[THIS_PARAM_i8:.*]], i64 -8
+  // CHECK2:   %[[THIS:.*]] = bitcast i8* %[[THIS_i8]] to %struct.B*
+  // CHECK2:   store %struct.B* %[[THIS]], %struct.B** %[[THIS_ADDR:.*]], align 4
+  // CHECK2:   %[[THIS:.*]] = load %struct.B** %[[THIS_ADDR]]
+  // CHECK2:   call x86_thiscallcc void @"\01??_DB@@UAE at XZ"(%struct.B* %[[THIS]])
+  // ...
+  // CHECK2: ret
 }
 
 void B::foo() {
@@ -145,13 +174,58 @@ void call_vbase_bar(B *obj) {
 // CHECK: ret void
 }
 
+void delete_B(B *obj) {
+// CHECK-LABEL: define void @"\01?delete_B@@YAXPAUB@@@Z"(%struct.B* %obj)
+// CHECK: %[[OBJ:.*]] = load %struct.B
+
+  delete obj;
+// CHECK: %[[OBJ_i8:.*]] = bitcast %struct.B* %[[OBJ]] to i8*
+// CHECK: %[[VBPTR:.*]] = getelementptr inbounds i8* %[[OBJ_i8]], i32 0
+// CHECK: %[[VBPTR8:.*]] = bitcast i8* %[[VBPTR]] to i8**
+// CHECK: %[[VBTABLE:.*]] = load i8** %[[VBPTR8]]
+// CHECK: %[[VBENTRY8:.*]] = getelementptr inbounds i8* %[[VBTABLE]], i32 4
+// CHECK: %[[VBENTRY:.*]] = bitcast i8* %[[VBENTRY8]] to i32*
+// CHECK: %[[VBOFFSET32:.*]] = load i32* %[[VBENTRY]]
+// CHECK: %[[VBOFFSET:.*]] = add nsw i32 0, %[[VBOFFSET32]]
+// CHECK: %[[VBASE_i8:.*]] = getelementptr inbounds i8* %[[OBJ_i8]], i32 %[[VBOFFSET]]
+// CHECK: %[[VFPTR:.*]] = bitcast i8* %[[VBASE_i8]] to void (%struct.B*, i32)***
+// CHECK: %[[VFTABLE:.*]] = load void (%struct.B*, i32)*** %[[VFPTR]]
+// CHECK: %[[VFUN:.*]] = getelementptr inbounds void (%struct.B*, i32)** %[[VFTABLE]], i64 0
+// CHECK: %[[VFUN_VALUE:.*]] = load void (%struct.B*, i32)** %[[VFUN]]
+//
+// CHECK: %[[OBJ_i8:.*]] = bitcast %struct.B* %[[OBJ]] to i8*
+// CHECK: %[[VBPTR:.*]] = getelementptr inbounds i8* %[[OBJ_i8]], i32 0
+// CHECK: %[[VBPTR8:.*]] = bitcast i8* %[[VBPTR]] to i8**
+// CHECK: %[[VBTABLE:.*]] = load i8** %[[VBPTR8]]
+// CHECK: %[[VBENTRY8:.*]] = getelementptr inbounds i8* %[[VBTABLE]], i32 4
+// CHECK: %[[VBENTRY:.*]] = bitcast i8* %[[VBENTRY8]] to i32*
+// CHECK: %[[VBOFFSET32:.*]] = load i32* %[[VBENTRY]]
+// CHECK: %[[VBOFFSET:.*]] = add nsw i32 0, %[[VBOFFSET32]]
+// CHECK: %[[VBASE_i8:.*]] = getelementptr inbounds i8* %[[OBJ_i8]], i32 %[[VBOFFSET]]
+// CHECK: %[[VBASE:.*]] = bitcast i8* %[[VBASE_i8]] to %struct.B*
+//
+// CHECK: call x86_thiscallcc void %[[VFUN_VALUE]](%struct.B* %[[VBASE]], i32 1)
+// CHECK: ret void
+}
+
+void call_complete_dtor() {
+  // CHECK-LABEL: define void @"\01?call_complete_dtor@@YAXXZ"
+  B b;
+  // CHECK: call x86_thiscallcc %struct.B* @"\01??0B@@QAE at XZ"(%struct.B* %[[B:.*]], i32 1)
+  // CHECK-NOT: getelementptr
+  // CHECK: call x86_thiscallcc void @"\01??_DB@@UAE at XZ"(%struct.B* %[[B]])
+  // CHECK: ret
+}
+
 struct C : B {
   C();
   // has an implicit vdtor.
 };
 
 // Used to crash on an assertion.
-C::C() {}
+C::C() {
+// CHECK-LABEL: define x86_thiscallcc %struct.C* @"\01??0C@@QAE at XZ"
+}
 
 namespace multiple_vbases {
 struct A {
@@ -185,5 +259,56 @@ D::D() {
   // CHECK: store i32 %{{.*}}, i32* %{{.*}}
   // CHECK: ret
 }
+}
+
+namespace diamond {
+struct A {
+  A();
+  virtual ~A();
+};
+
+struct B : virtual A {
+  B();
+  ~B();
+};
+
+struct C : virtual A {
+  C();
+  ~C();
+  int c1, c2, c3;
+};
+
+struct Z {
+  int z;
+};
+
+struct D : virtual Z, B, C {
+  D();
+  ~D();
+} d;
+
+D::~D() {
+  // CHECK-LABEL: define x86_thiscallcc void @"\01??1D at diamond@@UAE at XZ"(%"struct.diamond::D"*)
+  // CHECK: %[[ARG_i8:.*]] = bitcast %"struct.diamond::D"* %{{.*}} to i8*
+  // CHECK: %[[THIS_i8:.*]] = getelementptr i8* %[[ARG_i8]], i64 -24
+  // CHECK: %[[THIS:.*]] = bitcast i8* %[[THIS_i8]] to %"struct.diamond::D"*
+  // CHECK: store %"struct.diamond::D"* %[[THIS]], %"struct.diamond::D"** %[[THIS_VAL:.*]], align 4
+  // CHECK: %[[THIS:.*]] = load %"struct.diamond::D"** %[[THIS_VAL]]
+  // CHECK: %[[D_i8:.*]] = bitcast %"struct.diamond::D"* %[[THIS]] to i8*
+  // CHECK: %[[C_i8:.*]] = getelementptr inbounds i8* %[[D_i8]], i64 4
+  // CHECK: %[[C:.*]] = bitcast i8* %[[C_i8]] to %"struct.diamond::C"*
+  // CHECK: %[[C_i8:.*]] = bitcast %"struct.diamond::C"* %[[C]] to i8*
+  // CHECK: %[[ARG_i8:.*]] = getelementptr inbounds i8* %{{.*}}, i64 16
+  // FIXME: We might consider changing the dtor this parameter type to i8*.
+  // CHECK: %[[ARG:.*]] = bitcast i8* %[[ARG_i8]] to %"struct.diamond::C"*
+  // CHECK: call x86_thiscallcc void @"\01??1C at diamond@@UAE at XZ"(%"struct.diamond::C"* %[[ARG]])
+
+  // CHECK: %[[B:.*]] = bitcast %"struct.diamond::D"* %[[THIS]] to %"struct.diamond::B"*
+  // CHECK: %[[B_i8:.*]] = bitcast %"struct.diamond::B"* %[[B]] to i8*
+  // CHECK: %[[ARG_i8:.*]] = getelementptr inbounds i8* %[[B_i8]], i64 4
+  // CHECK: %[[ARG:.*]] = bitcast i8* %[[ARG_i8]] to %"struct.diamond::B"*
+  // CHECK: call x86_thiscallcc void @"\01??1B at diamond@@UAE at XZ"(%"struct.diamond::B"* %[[ARG]])
+  // CHECK: ret void
+}
 
 }

Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-vtables-multiple-nonvirtual-inheritance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-vtables-multiple-nonvirtual-inheritance.cpp?rev=192822&r1=192821&r2=192822&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/microsoft-abi-vtables-multiple-nonvirtual-inheritance.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/microsoft-abi-vtables-multiple-nonvirtual-inheritance.cpp Wed Oct 16 13:24:06 2013
@@ -13,6 +13,10 @@
 // RUN: FileCheck --check-prefix=THIS-THUNKS-Test1 %s < %t
 // RUN: FileCheck --check-prefix=THIS-THUNKS-Test2 %s < %t
 // RUN: FileCheck --check-prefix=THIS-THUNKS-Test3 %s < %t
+// RUN: FileCheck --check-prefix=VDTOR-THUNKS-Test3 %s < %t
+// RUN: FileCheck --check-prefix=VDTOR-THUNKS-Test5 %s < %t
+// RUN: FileCheck --check-prefix=VDTOR-THUNKS-Test6 %s < %t
+// RUN: FileCheck --check-prefix=VDTOR-THUNKS-Test7 %s < %t
 // RUN: FileCheck --check-prefix=RET-THUNKS-Test1 %s < %t
 // RUN: FileCheck --check-prefix=RET-THUNKS-Test2 %s < %t
 // RUN: FileCheck --check-prefix=RET-THUNKS-Test3 %s < %t
@@ -349,6 +353,101 @@ struct Test3: no_thunks::Test1, no_thunk
 Test3 t3;
 }
 
+namespace vdtor {
+struct Test1 {
+  virtual ~Test1();
+  virtual void z1();
+};
+
+struct Test2 {
+  virtual ~Test2();
+};
+
+struct Test3 : Test1, Test2 {
+  // VDTOR-THUNKS-Test3: VFTable for 'vdtor::Test1' in 'vdtor::Test3' (2 entries).
+  // VDTOR-THUNKS-Test3-NEXT: 0 | vdtor::Test3::~Test3() [scalar deleting]
+  // VDTOR-THUNKS-Test3-NEXT: 1 | void vdtor::Test1::z1()
+
+  // VDTOR-THUNKS-Test3: VFTable for 'vdtor::Test2' in 'vdtor::Test3' (1 entries).
+  // VDTOR-THUNKS-Test3-NEXT: 0 | vdtor::Test3::~Test3() [scalar deleting]
+  // VDTOR-THUNKS-Test3-NEXT:     [this adjustment: -4 non-virtual]
+
+  // VDTOR-THUNKS-Test3: Thunks for 'vdtor::Test3::~Test3()' (1 entry).
+  // VDTOR-THUNKS-Test3-NEXT: 0 | this adjustment: -4 non-virtual
+
+  // VDTOR-THUNKS-Test3: VFTable indices for 'vdtor::Test3' (1 entries).
+  // VDTOR-THUNKS-Test3-NEXT: 0 | vdtor::Test3::~Test3() [scalar deleting]
+  virtual ~Test3();
+};
+
+Test3 t3;
+
+struct Test4 {
+  // No virtual destructor here!
+  virtual void z4();
+};
+
+struct Test5 : Test4, Test2 {
+  // Implicit virtual dtor here!
+
+  // VDTOR-THUNKS-Test5: VFTable for 'vdtor::Test4' in 'vdtor::Test5' (1 entries).
+  // VDTOR-THUNKS-Test5-NEXT: 0 | void vdtor::Test4::z4()
+
+  // VDTOR-THUNKS-Test5: VFTable for 'vdtor::Test2' in 'vdtor::Test5' (1 entries).
+  // VDTOR-THUNKS-Test5-NEXT: 0 | vdtor::Test5::~Test5() [scalar deleting]
+  // VDTOR-THUNKS-Test5-NEXT:     [this adjustment: -4 non-virtual]
+
+  // VDTOR-THUNKS-Test5: Thunks for 'vdtor::Test5::~Test5()' (1 entry).
+  // VDTOR-THUNKS-Test5-NEXT: 0 | this adjustment: -4 non-virtual
+
+  // VDTOR-THUNKS-Test5: VFTable indices for 'vdtor::Test5' (1 entries).
+  // VDTOR-THUNKS-Test5-NEXT: -- accessible via vfptr at offset 4 --
+  // VDTOR-THUNKS-Test5-NEXT: 0 | vdtor::Test5::~Test5() [scalar deleting]
+};
+
+Test5 t5;
+
+struct Test6 : Test4, Test2 {
+  // Implicit virtual dtor here!
+
+  // VDTOR-THUNKS-Test6: VFTable for 'vdtor::Test4' in 'vdtor::Test6' (1 entries).
+  // VDTOR-THUNKS-Test6-NEXT: 0 | void vdtor::Test4::z4()
+
+  // VDTOR-THUNKS-Test6: VFTable for 'vdtor::Test2' in 'vdtor::Test6' (1 entries).
+  // VDTOR-THUNKS-Test6-NEXT: 0 | vdtor::Test6::~Test6() [scalar deleting]
+  // VDTOR-THUNKS-Test6-NEXT:     [this adjustment: -4 non-virtual]
+
+  // VDTOR-THUNKS-Test6: Thunks for 'vdtor::Test6::~Test6()' (1 entry).
+  // VDTOR-THUNKS-Test6-NEXT: 0 | this adjustment: -4 non-virtual
+
+  // VDTOR-THUNKS-Test6: VFTable indices for 'vdtor::Test6' (1 entries).
+  // VDTOR-THUNKS-Test6-NEXT: -- accessible via vfptr at offset 4 --
+  // VDTOR-THUNKS-Test6-NEXT: 0 | vdtor::Test6::~Test6() [scalar deleting]
+};
+
+Test6 t6;
+
+struct Test7 : Test5 {
+  // VDTOR-THUNKS-Test7: VFTable for 'vdtor::Test4' in 'vdtor::Test5' in 'vdtor::Test7' (1 entries).
+  // VDTOR-THUNKS-Test7-NEXT: 0 | void vdtor::Test4::z4()
+
+  // VDTOR-THUNKS-Test7: VFTable for 'vdtor::Test2' in 'vdtor::Test5' in 'vdtor::Test7' (1 entries).
+  // VDTOR-THUNKS-Test7-NEXT: 0 | vdtor::Test7::~Test7() [scalar deleting]
+  // VDTOR-THUNKS-Test7-NEXT:     [this adjustment: -4 non-virtual]
+
+  // VDTOR-THUNKS-Test7: Thunks for 'vdtor::Test7::~Test7()' (1 entry).
+  // VDTOR-THUNKS-Test7-NEXT: 0 | this adjustment: -4 non-virtual
+
+  // VDTOR-THUNKS-Test7: VFTable indices for 'vdtor::Test7' (1 entries).
+  // VDTOR-THUNKS-Test7-NEXT: -- accessible via vfptr at offset 4 --
+  // VDTOR-THUNKS-Test7-NEXT: 0 | vdtor::Test7::~Test7() [scalar deleting]
+  virtual ~Test7();
+};
+
+Test7 t7;
+
+}
+
 namespace return_adjustment {
 
 struct Ret1 {

Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance.cpp?rev=192822&r1=192821&r2=192822&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance.cpp Wed Oct 16 13:24:06 2013
@@ -15,6 +15,10 @@
 // RUN: FileCheck --check-prefix=TEST9-W %s < %t
 // RUN: FileCheck --check-prefix=TEST9-T %s < %t
 // RUN: FileCheck --check-prefix=TEST10 %s < %t
+// RUN: FileCheck --check-prefix=VDTORS-Y %s < %t
+// RUN: FileCheck --check-prefix=VDTORS-U %s < %t
+// RUN: FileCheck --check-prefix=VDTORS-V %s < %t
+// RUN: FileCheck --check-prefix=VDTORS-P %s < %t
 // RUN: FileCheck --check-prefix=RET-W %s < %t
 // RUN: FileCheck --check-prefix=RET-T %s < %t
 
@@ -408,6 +412,87 @@ void X::f() {}
 X x;
 }
 
+namespace vdtors {
+struct X {
+  virtual ~X();
+  virtual void zzz();
+};
+
+struct Y : virtual X {
+  // VDTORS-Y: VFTable for 'vdtors::X' in 'vdtors::Y' (2 entries).
+  // VDTORS-Y-NEXT: 0 | vdtors::Y::~Y() [scalar deleting]
+  // VDTORS-Y-NEXT: 1 | void vdtors::X::zzz()
+
+  // VDTORS-Y-NOT: Thunks for 'vdtors::Y::~Y()'
+  virtual ~Y();
+};
+
+Y y;
+
+struct Z {
+  virtual void z();
+};
+
+struct W : Z, X {
+  // Implicit virtual dtor.
+};
+
+struct U : virtual W {
+  // VDTORS-U: VFTable for 'vdtors::Z' in 'vdtors::W' in 'vdtors::U' (1 entries).
+  // VDTORS-U-NEXT: 0 | void vdtors::Z::z()
+
+  // VDTORS-U: VFTable for 'vdtors::X' in 'vdtors::W' in 'vdtors::U' (2 entries).
+  // VDTORS-U-NEXT: 0 | vdtors::U::~U() [scalar deleting]
+  // VDTORS-U-NEXT:     [this adjustment: -4 non-virtual]
+  // VDTORS-U-NEXT: 1 | void vdtors::X::zzz()
+
+  // VDTORS-U: Thunks for 'vdtors::W::~W()' (1 entry).
+  // VDTORS-U-NEXT: 0 | this adjustment: -4 non-virtual
+
+  // VDTORS-U: VFTable indices for 'vdtors::U' (1 entries).
+  // VDTORS-U-NEXT: -- accessible via vbtable index 1, vfptr at offset 4 --
+  // VDTORS-U-NEXT: 0 | vdtors::U::~U() [scalar deleting]
+  virtual ~U();
+};
+
+U u;
+
+struct V : virtual W {
+  // VDTORS-V: VFTable for 'vdtors::Z' in 'vdtors::W' in 'vdtors::V' (1 entries).
+  // VDTORS-V-NEXT: 0 | void vdtors::Z::z()
+
+  // VDTORS-V: VFTable for 'vdtors::X' in 'vdtors::W' in 'vdtors::V' (2 entries).
+  // VDTORS-V-NEXT: 0 | vdtors::V::~V() [scalar deleting]
+  // VDTORS-V-NEXT:     [this adjustment: -4 non-virtual]
+  // VDTORS-V-NEXT: 1 | void vdtors::X::zzz()
+
+  // VDTORS-V: Thunks for 'vdtors::W::~W()' (1 entry).
+  // VDTORS-V-NEXT: 0 | this adjustment: -4 non-virtual
+
+  // VDTORS-V: VFTable indices for 'vdtors::V' (1 entries).
+  // VDTORS-V-NEXT: -- accessible via vbtable index 1, vfptr at offset 4 --
+  // VDTORS-V-NEXT: 0 | vdtors::V::~V() [scalar deleting]
+};
+
+V v;
+
+struct T : virtual X {
+  virtual ~T();
+};
+
+struct P : T, Y {
+  // VDTORS-P: VFTable for 'vdtors::X' in 'vdtors::T' in 'vdtors::P' (2 entries).
+  // VDTORS-P-NEXT: 0 | vdtors::P::~P() [scalar deleting]
+  // VDTORS-P-NEXT: 1 | void vdtors::X::zzz()
+
+  // VDTORS-P-NOT: Thunks for 'vdtors::P::~P()'
+  virtual ~P();
+};
+
+P p;
+
+}
+
 namespace return_adjustment {
 
 struct X : virtual A {





More information about the cfe-commits mailing list