From: Reid Kleckner Date: Thu, 7 Aug 2014 21:29:25 +0000 (+0000) Subject: Debug info: Use the vbtable offset for virtual bases in the MS ABI X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8bf63d9dda9fe10813e61ef68406b9c2a78892e4;p=clang Debug info: Use the vbtable offset for virtual bases in the MS ABI There are no vtable offset offsets in the MS ABI, but vbtable offsets are analogous. There are no consumers of this information yet, but at least we don't crash now. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@215149 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index ddb8a83887..7ccea08901 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -1193,11 +1193,18 @@ CollectCXXBases(const CXXRecordDecl *RD, llvm::DIFile Unit, cast(BI.getType()->getAs()->getDecl()); if (BI.isVirtual()) { - // virtual base offset offset is -ve. The code generator emits dwarf - // expression where it expects +ve number. - BaseOffset = - 0 - CGM.getItaniumVTableContext() - .getVirtualBaseOffsetOffset(RD, Base).getQuantity(); + if (CGM.getTarget().getCXXABI().isItaniumFamily()) { + // virtual base offset offset is -ve. The code generator emits dwarf + // expression where it expects +ve number. + BaseOffset = + 0 - CGM.getItaniumVTableContext() + .getVirtualBaseOffsetOffset(RD, Base).getQuantity(); + } else { + // In the MS ABI, store the vbtable offset, which is analogous to the + // vbase offset offset in Itanium. + BaseOffset = + 4 * CGM.getMicrosoftVTableContext().getVBTableIndex(RD, Base); + } BFlags = llvm::DIDescriptor::FlagVirtual; } else BaseOffset = CGM.getContext().toBits(RL.getBaseClassOffset(Base)); diff --git a/test/CodeGenCXX/debug-info.cpp b/test/CodeGenCXX/debug-info.cpp index 7c89dfc04c..b8446bedbf 100644 --- a/test/CodeGenCXX/debug-info.cpp +++ b/test/CodeGenCXX/debug-info.cpp @@ -1,4 +1,6 @@ // RUN: %clang_cc1 -triple x86_64-none-linux-gnu -emit-llvm -g %s -o - | FileCheck %s +// RUN: %clang_cc1 -triple i686-pc-windows-msvc -emit-llvm -g %s -o - | FileCheck %s --check-prefix=MSVC + template struct Identity { typedef T Type; }; @@ -43,14 +45,25 @@ namespace VirtualDtor { } namespace VirtualBase { - struct A { }; - struct B : virtual A { }; + struct A { int a; }; + struct B : virtual A { int b; }; void f() { B b; } } +// MSVC: [[VBASE_B:![0-9]+]] = metadata !{i32 {{.*}}, metadata !"B", i32 {{[0-9]*}}, i64 96, i64 32, i32 0, i32 0, null, metadata [[VBASE_B_DEF:![0-9]+]], i32 0, {{.*}}} ; [ DW_TAG_structure_type ] [B] [line 49, size 96, align 32, offset 0] [def] [from ] +// MSVC: [[VBASE_B_DEF]] = metadata !{metadata [[VBASE_A_IN_B:![0-9]+]], +// +// Look for the vbtable offset of A, which should be 4. +// MSVC: [[VBASE_A_IN_B]] = metadata !{i32 786460, null, metadata [[VBASE_B]], null, i32 0, i64 0, i64 0, i64 4, i32 32, metadata !{{[0-9]*}}} ; [ DW_TAG_inheritance ] [line 0, size 0, align 0, offset 4] [from A] + +// CHECK: metadata !{{{.*}}, metadata !"B", i32 {{[0-9]*}}, i64 128, i64 64, i32 0, i32 0, null, metadata [[VBASE_B_DEF:![0-9]+]], i32 0, {{.*}}} ; [ DW_TAG_structure_type ] [B] [line 49, size 128, align 64, offset 0] [def] [from ] +// CHECK: [[VBASE_B_DEF]] = metadata !{metadata [[VBASE_A_IN_B:![0-9]+]], +// +// Look for the vtable offset offset, which should be -24. +// CHECK: [[VBASE_A_IN_B]] = metadata !{i32 786460, null, metadata !"_ZTSN11VirtualBase1BE", null, i32 0, i64 0, i64 0, i64 24, i32 32, metadata !"_ZTSN11VirtualBase1AE"} ; [ DW_TAG_inheritance ] [line 0, size 0, align 0, offset 24] [from _ZTSN11VirtualBase1AE] namespace b5249287 { template class A { struct B;