<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 13, 2017 at 2:54 PM, Reid Kleckner via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rnk<br>
Date: Wed Sep 13 14:54:20 2017<br>
New Revision: 313203<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=313203&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=313203&view=rev</a><br>
Log:<br>
[codeview] VLAs and unsized arrays should use a size of zero<br>
<br>
Previously we used a size of '1' for VLAs because we weren't sure what<br>
MSVC did. However, MSVC does support declaring an array without a size,<br>
for which it emits an array type with a size of zero. Clang emits the<br>
same DI metadata for VLAs and arrays without bound, so we would describe<br>
arrays without bound as having one element. This lead to Microsoft<br>
debuggers only printing a single element.<br>
<br>
Emitting a size of zero appears to cause these debuggers to search the<br>
symbol information to find a definition of the variable with accurate<br>
array bounds.<br>
<br>
Fixes <a href="http://crbug.com/763580" rel="noreferrer" target="_blank">http://crbug.com/763580</a><br>
<br>
Added:<br>
    llvm/trunk/test/DebugInfo/<wbr>COFF/types-array-unsized.ll<br>
Modified:<br>
    llvm/trunk/lib/CodeGen/<wbr>AsmPrinter/CodeViewDebug.cpp<br>
    llvm/trunk/test/DebugInfo/<wbr>COFF/types-array-advanced.ll<br>
<br>
Modified: llvm/trunk/lib/CodeGen/<wbr>AsmPrinter/CodeViewDebug.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp?rev=313203&r1=313202&r2=313203&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/lib/<wbr>CodeGen/AsmPrinter/<wbr>CodeViewDebug.cpp?rev=313203&<wbr>r1=313202&r2=313203&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/lib/CodeGen/<wbr>AsmPrinter/CodeViewDebug.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/<wbr>AsmPrinter/CodeViewDebug.cpp Wed Sep 13 14:54:20 2017<br>
@@ -1277,11 +1277,12 @@ TypeIndex CodeViewDebug::lowerTypeArray(<br>
            "codeview doesn't support subranges with lower bounds");<br>
     int64_t Count = Subrange->getCount();<br>
<br>
-    // Variable Length Array (VLA) has Count equal to '-1'.<br>
-    // Replace with Count '1', assume it is the minimum VLA length.<br>
+    // Variable length arrays and forward declarations of arrays without a size<br>
+    // use a count of -1. Emit a count (and overall size) or zero in these cases<br>
+    // to match what MSVC does for array declarations with no count.<br>
     // FIXME: Make front-end support VLA subrange and emit LF_DIMVARLU.<br></blockquote><div><br></div><div>I think this FIXME can go away.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
     if (Count == -1)<br>
-      Count = 1;<br>
+      Count = 0;<br>
<br>
     // Update the element size and element type index for subsequent subranges.<br>
     ElementSize *= Count;<br>
<br>
Modified: llvm/trunk/test/DebugInfo/<wbr>COFF/types-array-advanced.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/COFF/types-array-advanced.ll?rev=313203&r1=313202&r2=313203&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/test/<wbr>DebugInfo/COFF/types-array-<wbr>advanced.ll?rev=313203&r1=<wbr>313202&r2=313203&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/test/DebugInfo/<wbr>COFF/types-array-advanced.ll (original)<br>
+++ llvm/trunk/test/DebugInfo/<wbr>COFF/types-array-advanced.ll Wed Sep 13 14:54:20 2017<br>
@@ -47,7 +47,7 @@<br>
 ; CHECK:     TypeLeafKind: LF_ARRAY (0x1503)<br>
 ; CHECK:     ElementType: int (0x74)<br>
 ; CHECK:     IndexType: unsigned long (0x22)<br>
-; CHECK:     SizeOf: 4<br>
+; CHECK:     SizeOf: 0<br>
 ; CHECK:     Name:<br>
 ; CHECK:   }<br>
 ; CHECK:   Pointer (0x1004) {<br>
<br>
Added: llvm/trunk/test/DebugInfo/<wbr>COFF/types-array-unsized.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/COFF/types-array-unsized.ll?rev=313203&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/test/<wbr>DebugInfo/COFF/types-array-<wbr>unsized.ll?rev=313203&view=<wbr>auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/test/DebugInfo/<wbr>COFF/types-array-unsized.ll (added)<br>
+++ llvm/trunk/test/DebugInfo/<wbr>COFF/types-array-unsized.ll Wed Sep 13 14:54:20 2017<br>
@@ -0,0 +1,84 @@<br>
+; RUN: llc -filetype=obj < %s | llvm-readobj -codeview | FileCheck %s<br>
+<br>
+; We should emit two array types: one used to describe the static data member,<br>
+; and the other used by the S_GDATA32 for the definition.<br>
+<br>
+; C++ source:<br>
+; struct Foo {<br>
+;   static const char str[];<br>
+; };<br>
+; const char Foo::str[] = "asdf";<br>
+; Foo f; // FIXME: only needed to force emit 'Foo'<br>
+<br>
+; CHECK:      CodeViewTypes [<br>
+; CHECK:        Array ([[ARRAY_COMPLETE:0x.*]]) {<br>
+; CHECK-NEXT:     TypeLeafKind: LF_ARRAY (0x1503)<br>
+; CHECK-NEXT:     ElementType: const char ({{.*}})<br>
+; CHECK-NEXT:     IndexType: unsigned __int64 (0x23)<br>
+; CHECK-NEXT:     SizeOf: 5<br>
+; CHECK-NEXT:     Name:<br>
+; CHECK-NEXT:   }<br>
+; CHECK:        Array ([[ARRAY_FWD:0x.*]]) {<br>
+; CHECK-NEXT:     TypeLeafKind: LF_ARRAY (0x1503)<br>
+; CHECK-NEXT:     ElementType: const char ({{.*}})<br>
+; CHECK-NEXT:     IndexType: unsigned __int64 (0x23)<br>
+; CHECK-NEXT:     SizeOf: 0<br>
+; CHECK-NEXT:     Name:<br>
+; CHECK-NEXT:   }<br>
+; CHECK:        FieldList (0x1004) {<br>
+; CHECK-NEXT:     TypeLeafKind: LF_FIELDLIST (0x1203)<br>
+; CHECK-NEXT:     StaticDataMember {<br>
+; CHECK-NEXT:       TypeLeafKind: LF_STMEMBER (0x150E)<br>
+; CHECK-NEXT:       AccessSpecifier: Public (0x3)<br>
+; CHECK-NEXT:       Type: [[ARRAY_FWD]]<br>
+; CHECK-NEXT:       Name: str<br>
+; CHECK-NEXT:     }<br>
+; CHECK-NEXT:   }<br>
+; CHECK:      ]<br>
+<br>
+; CHECK:          GlobalData {<br>
+; CHECK-NEXT:       Kind: S_GDATA32 (0x110D)<br>
+; CHECK-NEXT:       DataOffset: ?str@Foo@@2QBDB+0x0<br>
+; CHECK-NEXT:       Type: [[ARRAY_COMPLETE]]<br>
+; CHECK-NEXT:       DisplayName: str<br>
+; CHECK-NEXT:       LinkageName: ?str@Foo@@2QBDB<br>
+; CHECK-NEXT:     }<br>
+<br>
+; ModuleID = 't.cpp'<br>
+source_filename = "t.cpp"<br>
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:<wbr>32:64-S128"<br>
+target triple = "x86_64-pc-windows-msvc19.0.<wbr>24215"<br>
+<br>
+%struct.Foo = type { i8 }<br>
+<br>
+@"\01?str@Foo@@2QBDB" = constant [5 x i8] c"asdf\00", align 1, !dbg !0<br>
+@"\01?f@@3UFoo@@A" = global %struct.Foo zeroinitializer, align 1, !dbg !6<br>
+<br>
+!<a href="http://llvm.dbg.cu" rel="noreferrer" target="_blank">llvm.dbg.cu</a> = !{!2}<br>
+!llvm.module.flags = !{!19, !20, !21, !22}<br>
+!llvm.ident = !{!23}<br>
+<br>
+!0 = !DIGlobalVariableExpression(<wbr>var: !1, expr: !DIExpression())<br>
+!1 = distinct !DIGlobalVariable(name: "str", linkageName: "\01?str@Foo@@2QBDB", scope: !2, file: !3, line: 4, type: !16, isLocal: false, isDefinition: true, declaration: !10)<br>
+!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 6.0.0 ", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)<br>
+!3 = !DIFile(filename: "t.cpp", directory: "C:\5Csrc\5Cllvm-project\<wbr>5Cbuild", checksumkind: CSK_MD5, checksum: "<wbr>15aa843c5a80301928caf03e71f87a<wbr>54")<br>
+!4 = !{}<br>
+!5 = !{!0, !6}<br>
+!6 = !DIGlobalVariableExpression(<wbr>var: !7, expr: !DIExpression())<br>
+!7 = distinct !DIGlobalVariable(name: "f", linkageName: "\01?f@@3UFoo@@A", scope: !2, file: !3, line: 5, type: !8, isLocal: false, isDefinition: true)<br>
+!8 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo", file: !3, line: 1, size: 8, elements: !9, identifier: ".?AUFoo@@")<br>
+!9 = !{!10}<br>
+!10 = !DIDerivedType(tag: DW_TAG_member, name: "str", scope: !8, file: !3, line: 2, baseType: !11, flags: DIFlagStaticMember)<br>
+!11 = !DICompositeType(tag: DW_TAG_array_type, baseType: !12, elements: !14)<br>
+!12 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !13)<br>
+!13 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)<br>
+!14 = !{!15}<br>
+!15 = !DISubrange(count: -1)<br>
+!16 = !DICompositeType(tag: DW_TAG_array_type, baseType: !12, size: 40, elements: !17)<br>
+!17 = !{!18}<br>
+!18 = !DISubrange(count: 5)<br>
+!19 = !{i32 2, !"CodeView", i32 1}<br>
+!20 = !{i32 2, !"Debug Info Version", i32 3}<br>
+!21 = !{i32 1, !"wchar_size", i32 2}<br>
+!22 = !{i32 7, !"PIC Level", i32 2}<br>
+!23 = !{!"clang version 6.0.0 "}<br>
<br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>