Index: lib/CodeGen/AsmPrinter/CodeViewDebug.h =================================================================== --- lib/CodeGen/AsmPrinter/CodeViewDebug.h +++ lib/CodeGen/AsmPrinter/CodeViewDebug.h @@ -190,6 +190,7 @@ codeview::TypeIndex lowerType(const DIType *Ty); codeview::TypeIndex lowerTypeAlias(const DIDerivedType *Ty); + codeview::TypeIndex lowerTypeArray(const DICompositeType *Ty); codeview::TypeIndex lowerTypeBasic(const DIBasicType *Ty); codeview::TypeIndex lowerTypePointer(const DIDerivedType *Ty); codeview::TypeIndex lowerTypeMemberPointer(const DIDerivedType *Ty); Index: lib/CodeGen/AsmPrinter/CodeViewDebug.cpp =================================================================== --- lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -736,6 +736,8 @@ TypeIndex CodeViewDebug::lowerType(const DIType *Ty) { // Generic dispatch for lowering an unknown type. switch (Ty->getTag()) { + case dwarf::DW_TAG_array_type: + return lowerTypeArray(cast(Ty)); case dwarf::DW_TAG_typedef: return lowerTypeAlias(cast(Ty)); case dwarf::DW_TAG_base_type: @@ -775,6 +777,18 @@ return UnderlyingTypeIndex; } +TypeIndex CodeViewDebug::lowerTypeArray(const DICompositeType *Ty) { + DITypeRef ElementTypeRef = Ty->getBaseType(); + TypeIndex ElementTypeIndex = getTypeIndex(ElementTypeRef); + // IndexType is size_t, which depends on the bitness of the target. + TypeIndex IndexType = Asm->MAI->getPointerSize() == 8 ? + TypeIndex(SimpleTypeKind::UInt64) : + TypeIndex(SimpleTypeKind::UInt32); + uint64_t Size = Ty->getSizeInBits() / 8; + ArrayRecord Record(ElementTypeIndex, IndexType, Size, Ty->getName()); + return TypeTable.writeArray(Record); +} + TypeIndex CodeViewDebug::lowerTypeBasic(const DIBasicType *Ty) { TypeIndex Index; dwarf::TypeKind Kind; Index: test/DebugInfo/COFF/types-array.ll =================================================================== --- /dev/null +++ test/DebugInfo/COFF/types-array.ll @@ -0,0 +1,122 @@ +; RUN: llc < %s -filetype=obj | llvm-readobj - -codeview | FileCheck %s + +; C++ source to regenerate: +; $ cat t.cpp +; void usevars(int, ...); +; void f(float p1, double p2, long long p3) { +; int a[5] = {9, 4, 5, 4, 2}; +; usevars(a[0], a); +; } +; $ clang t.cpp -S -emit-llvm -g -gcodeview -o t.ll + +; CHECK: CodeViewTypes [ +; CHECK: Section: .debug$T (6) +; CHECK: Magic: 0x4 +; CHECK: ArgList (0x1000) { +; CHECK: TypeLeafKind: LF_ARGLIST (0x1201) +; CHECK: NumArgs: 3 +; CHECK: Arguments [ +; CHECK: ArgType: float (0x40) +; CHECK: ArgType: double (0x41) +; CHECK: ArgType: __int64 (0x13) +; CHECK: ] +; CHECK: } +; CHECK: Procedure (0x1001) { +; CHECK: TypeLeafKind: LF_PROCEDURE (0x1008) +; CHECK: ReturnType: void (0x3) +; CHECK: CallingConvention: NearC (0x0) +; CHECK: FunctionOptions [ (0x0) +; CHECK: ] +; CHECK: NumParameters: 3 +; CHECK: ArgListType: (float, double, __int64) (0x1000) +; CHECK: } +; CHECK: FuncId (0x1002) { +; CHECK: TypeLeafKind: LF_FUNC_ID (0x1601) +; CHECK: ParentScope: 0x0 +; CHECK: FunctionType: void (float, double, __int64) (0x1001) +; CHECK: Name: f +; CHECK: } +; CHECK: Array (0x1003) { +; CHECK: TypeLeafKind: LF_ARRAY (0x1503) +; CHECK: ElementType: int (0x74) +; CHECK: IndexType: unsigned (0x75) +; CHECK: SizeOf: 20 +; CHECK: Name: +; CHECK: } +; CHECK: ] + +; ModuleID = 't.cpp' +source_filename = "t.cpp" +target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32" +target triple = "i686-pc-windows-msvc19.0.23918" + +@"\01?a@?1??f@@YAXMN_J@Z@3PAHA" = private unnamed_addr constant [5 x i32] [i32 9, i32 4, i32 5, i32 4, i32 2], align 4 + +define void @"\01?f@@YAXMN_J@Z"(float %p1, double %p2, i64 %p3) #0 !dbg !6 { +entry: + %p3.addr = alloca i64, align 8 + %p2.addr = alloca double, align 8 + %p1.addr = alloca float, align 4 + %a = alloca [5 x i32], align 4 + store i64 %p3, i64* %p3.addr, align 8 + call void @llvm.dbg.declare(metadata i64* %p3.addr, metadata !12, metadata !13), !dbg !14 + store double %p2, double* %p2.addr, align 8 + call void @llvm.dbg.declare(metadata double* %p2.addr, metadata !15, metadata !13), !dbg !16 + store float %p1, float* %p1.addr, align 4 + call void @llvm.dbg.declare(metadata float* %p1.addr, metadata !17, metadata !13), !dbg !18 + call void @llvm.dbg.declare(metadata [5 x i32]* %a, metadata !19, metadata !13), !dbg !24 + %0 = bitcast [5 x i32]* %a to i8*, !dbg !24 + call void @llvm.memcpy.p0i8.p0i8.i32(i8* %0, i8* bitcast ([5 x i32]* @"\01?a@?1??f@@YAXMN_J@Z@3PAHA" to i8*), i32 20, i32 4, i1 false), !dbg !24 + %arraydecay = getelementptr inbounds [5 x i32], [5 x i32]* %a, i32 0, i32 0, !dbg !25 + %arrayidx = getelementptr inbounds [5 x i32], [5 x i32]* %a, i32 0, i32 0, !dbg !26 + %1 = load i32, i32* %arrayidx, align 4, !dbg !26 + call void (i32, ...) @"\01?usevars@@YAXHZZ"(i32 %1, i32* %arraydecay), !dbg !27 + ret void, !dbg !28 +} + +; Function Attrs: nounwind readnone +declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 + +; Function Attrs: argmemonly nounwind +declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture readonly, i32, i32, i1) #2 + +declare void @"\01?usevars@@YAXHZZ"(i32, ...) #3 + +attributes #0 = { "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="pentium4" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { nounwind readnone } +attributes #2 = { argmemonly nounwind } +attributes #3 = { "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="pentium4" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4} +!llvm.ident = !{!5} + +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.9.0 ", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2) +!1 = !DIFile(filename: "t.cpp", directory: "D:\5Csrc\5Cllvm\5Cllvm\5Ctest\5CDebugInfo\5CCOFF") +!2 = !{} +!3 = !{i32 2, !"CodeView", i32 1} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{!"clang version 3.9.0 "} +!6 = distinct !DISubprogram(name: "f", linkageName: "\01?f@@YAXMN_J@Z", scope: !1, file: !1, line: 2, type: !7, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2) +!7 = !DISubroutineType(types: !8) +!8 = !{null, !9, !10, !11} +!9 = !DIBasicType(name: "float", size: 32, align: 32, encoding: DW_ATE_float) +!10 = !DIBasicType(name: "double", size: 64, align: 64, encoding: DW_ATE_float) +!11 = !DIBasicType(name: "long long int", size: 64, align: 64, encoding: DW_ATE_signed) +!12 = !DILocalVariable(name: "p3", arg: 3, scope: !6, file: !1, line: 2, type: !11) +!13 = !DIExpression() +!14 = !DILocation(line: 2, column: 39, scope: !6) +!15 = !DILocalVariable(name: "p2", arg: 2, scope: !6, file: !1, line: 2, type: !10) +!16 = !DILocation(line: 2, column: 25, scope: !6) +!17 = !DILocalVariable(name: "p1", arg: 1, scope: !6, file: !1, line: 2, type: !9) +!18 = !DILocation(line: 2, column: 14, scope: !6) +!19 = !DILocalVariable(name: "a", scope: !6, file: !1, line: 3, type: !20) +!20 = !DICompositeType(tag: DW_TAG_array_type, baseType: !21, size: 160, align: 32, elements: !22) +!21 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) +!22 = !{!23} +!23 = !DISubrange(count: 5) +!24 = !DILocation(line: 3, column: 7, scope: !6) +!25 = !DILocation(line: 4, column: 17, scope: !6) +!26 = !DILocation(line: 4, column: 11, scope: !6) +!27 = !DILocation(line: 4, column: 3, scope: !6) +!28 = !DILocation(line: 5, column: 1, scope: !6)