[llvm] r322257 - [CodeView] Fix the type for a variadic argument

Aaron Smith via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 10 22:42:11 PST 2018


Author: asmith
Date: Wed Jan 10 22:42:11 2018
New Revision: 322257

URL: http://llvm.org/viewvc/llvm-project?rev=322257&view=rev
Log:
[CodeView] Fix the type for a variadic argument

Summary:
- MSVC uses the none type for a variadic argument in CodeView
- Add a unit test

Reviewers: zturner, llvm-commits

Reviewed By: zturner

Differential Revision: https://reviews.llvm.org/D41931

Added:
    llvm/trunk/test/DebugInfo/COFF/types-cvarargs.ll
Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp?rev=322257&r1=322256&r2=322257&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp Wed Jan 10 22:42:11 2018
@@ -1281,6 +1281,8 @@ TypeIndex CodeViewDebug::lowerType(const
     return lowerTypeClass(cast<DICompositeType>(Ty));
   case dwarf::DW_TAG_union_type:
     return lowerTypeUnion(cast<DICompositeType>(Ty));
+  case dwarf::DW_TAG_unspecified_type:
+    return TypeIndex::None();
   default:
     // Use the null type index.
     return TypeIndex();
@@ -1573,6 +1575,11 @@ TypeIndex CodeViewDebug::lowerTypeFuncti
   for (DITypeRef ArgTypeRef : Ty->getTypeArray())
     ReturnAndArgTypeIndices.push_back(getTypeIndex(ArgTypeRef));
 
+  // MSVC uses type none for variadic argument.
+  if (ReturnAndArgTypeIndices.size() > 1 &&
+      ReturnAndArgTypeIndices.back() == TypeIndex::Void()) {
+    ReturnAndArgTypeIndices.back() = TypeIndex::None();
+  }
   TypeIndex ReturnTypeIndex = TypeIndex::Void();
   ArrayRef<TypeIndex> ArgTypeIndices = None;
   if (!ReturnAndArgTypeIndices.empty()) {
@@ -1602,6 +1609,11 @@ TypeIndex CodeViewDebug::lowerTypeMember
   for (DITypeRef ArgTypeRef : Ty->getTypeArray())
     ReturnAndArgTypeIndices.push_back(getTypeIndex(ArgTypeRef));
 
+  // MSVC uses type none for variadic argument.
+  if (ReturnAndArgTypeIndices.size() > 1 &&
+      ReturnAndArgTypeIndices.back() == TypeIndex::Void()) {
+    ReturnAndArgTypeIndices.back() = TypeIndex::None();
+  }
   TypeIndex ReturnTypeIndex = TypeIndex::Void();
   ArrayRef<TypeIndex> ArgTypeIndices = None;
   if (!ReturnAndArgTypeIndices.empty()) {

Added: llvm/trunk/test/DebugInfo/COFF/types-cvarargs.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/COFF/types-cvarargs.ll?rev=322257&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/COFF/types-cvarargs.ll (added)
+++ llvm/trunk/test/DebugInfo/COFF/types-cvarargs.ll Wed Jan 10 22:42:11 2018
@@ -0,0 +1,117 @@
+; RUN: llc < %s -filetype=obj | llvm-readobj - -codeview | FileCheck %s
+
+; C++ source to regenerate:
+; $ cat t.cpp
+; typedef void (*FuncTypedef)(int, float, ...);
+; FuncTypedef funcVar;
+; namespace MemberTest {
+;   class A {
+;   public:
+;     int MemberFunc(...) { return 1; }
+;   };
+; }
+; int f () {
+;   MemberTest::A v1;
+;   v1.MemberFunc(1,20,0);
+;   return 1;
+; }
+; $ clang t.cpp -S -emit-llvm -g -gcodeview -o t.ll
+
+; CHECK:  MemberFuncId (0x100B) {
+; CHECK:    TypeLeafKind: LF_MFUNC_ID (0x1602)
+; CHECK:    ClassType: MemberTest::A (0x1003)
+; CHECK:    FunctionType: int MemberTest::A::(<no type>) (0x1006)
+; CHECK:    Name: MemberFunc
+; CHECK:  }
+; CHECK:  Subsection [
+; CHECK:    SubSectionType: Symbols (0xF1)
+; CHECK:    SubSectionSize: 0x2A
+; CHECK:    UDTSym {
+; CHECK:      Kind: S_UDT (0x1108)
+; CHECK:      Type: MemberTest::A (0x1008)
+; CHECK:      UDTName: MemberTest::A
+; CHECK:    }
+; CHECK:    UDTSym {
+; CHECK:      Kind: S_UDT (0x1108)
+; CHECK:      Type: void (int, float, <no type>)* (0x100E)
+; CHECK:      UDTName: FuncTypedef
+; CHECK:    }
+; CHECK:  ]
+
+; ModuleID = 't.cpp'
+source_filename = "t.cpp"
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc19.11.25507"
+
+%"class.MemberTest::A" = type { i8 }
+
+$"\01?MemberFunc at A@MemberTest@@QEAAHZZ" = comdat any
+
+@"\01?funcVar@@3P6AXHMZZEA" = global void (i32, float, ...)* null, align 8, !dbg !0
+
+; Function Attrs: noinline optnone uwtable
+define i32 @"\01?f@@YAHXZ"() #0 !dbg !17 {
+entry:
+  %v1 = alloca %"class.MemberTest::A", align 1
+  call void @llvm.dbg.declare(metadata %"class.MemberTest::A"* %v1, metadata !20, metadata !DIExpression()), !dbg !28
+  %call = call i32 (%"class.MemberTest::A"*, ...) @"\01?MemberFunc at A@MemberTest@@QEAAHZZ"(%"class.MemberTest::A"* %v1, i32 1, i32 20, i64 0), !dbg !29
+  ret i32 1, !dbg !30
+}
+
+; Function Attrs: nounwind readnone speculatable
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
+
+; Function Attrs: noinline nounwind optnone uwtable
+define linkonce_odr i32 @"\01?MemberFunc at A@MemberTest@@QEAAHZZ"(%"class.MemberTest::A"* %this, ...) #2 comdat align 2 !dbg !31 {
+entry:
+  %this.addr = alloca %"class.MemberTest::A"*, align 8
+  store %"class.MemberTest::A"* %this, %"class.MemberTest::A"** %this.addr, align 8
+  call void @llvm.dbg.declare(metadata %"class.MemberTest::A"** %this.addr, metadata !32, metadata !DIExpression()), !dbg !34
+  %this1 = load %"class.MemberTest::A"*, %"class.MemberTest::A"** %this.addr, align 8
+  ret i32 1, !dbg !35
+}
+
+attributes #0 = { noinline optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { nounwind readnone speculatable }
+attributes #2 = { noinline nounwind optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!12, !13, !14, !15}
+!llvm.ident = !{!16}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "funcVar", linkageName: "\01?funcVar@@3P6AXHMZZEA", scope: !2, file: !3, line: 4, type: !6, isLocal: false, isDefinition: true)
+!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 7.0.0 ", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)
+!3 = !DIFile(filename: "t.cpp", directory: "D:\5Cupstream\5Cllvm\5Ctest\5CDebugInfo\5CCOFF", checksumkind: CSK_MD5, checksum: "d6582aff49f975763b736524db75f999")
+!4 = !{}
+!5 = !{!0}
+!6 = !DIDerivedType(tag: DW_TAG_typedef, name: "FuncTypedef", file: !3, line: 3, baseType: !7)
+!7 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64)
+!8 = !DISubroutineType(types: !9)
+!9 = !{null, !10, !11, null}
+!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!11 = !DIBasicType(name: "float", size: 32, encoding: DW_ATE_float)
+!12 = !{i32 2, !"CodeView", i32 1}
+!13 = !{i32 2, !"Debug Info Version", i32 3}
+!14 = !{i32 1, !"wchar_size", i32 2}
+!15 = !{i32 7, !"PIC Level", i32 2}
+!16 = !{!"clang version 7.0.0 "}
+!17 = distinct !DISubprogram(name: "f", linkageName: "\01?f@@YAHXZ", scope: !3, file: !3, line: 11, type: !18, isLocal: false, isDefinition: true, scopeLine: 11, flags: DIFlagPrototyped, isOptimized: false, unit: !2, variables: !4)
+!18 = !DISubroutineType(types: !19)
+!19 = !{!10}
+!20 = !DILocalVariable(name: "v1", scope: !17, file: !3, line: 12, type: !21)
+!21 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "A", scope: !22, file: !3, line: 6, size: 8, elements: !23, identifier: ".?AVA at MemberTest@@")
+!22 = !DINamespace(name: "MemberTest", scope: null)
+!23 = !{!24}
+!24 = !DISubprogram(name: "MemberFunc", linkageName: "\01?MemberFunc at A@MemberTest@@QEAAHZZ", scope: !21, file: !3, line: 8, type: !25, isLocal: false, isDefinition: false, scopeLine: 8, flags: DIFlagPublic | DIFlagPrototyped, isOptimized: false)
+!25 = !DISubroutineType(types: !26)
+!26 = !{!10, !27, null}
+!27 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !21, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
+!28 = !DILocation(line: 12, column: 18, scope: !17)
+!29 = !DILocation(line: 13, column: 7, scope: !17)
+!30 = !DILocation(line: 14, column: 4, scope: !17)
+!31 = distinct !DISubprogram(name: "MemberFunc", linkageName: "\01?MemberFunc at A@MemberTest@@QEAAHZZ", scope: !21, file: !3, line: 8, type: !25, isLocal: false, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: false, unit: !2, declaration: !24, variables: !4)
+!32 = !DILocalVariable(name: "this", arg: 1, scope: !31, type: !33, flags: DIFlagArtificial | DIFlagObjectPointer)
+!33 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !21, size: 64)
+!34 = !DILocation(line: 0, scope: !31)
+!35 = !DILocation(line: 8, column: 28, scope: !31)




More information about the llvm-commits mailing list