<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jun 23, 2016 at 9:33 AM, Hans Wennborg 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: hans<br>
Date: Thu Jun 23 11:33:53 2016<br>
New Revision: 273579<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=273579&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=273579&view=rev</a><br>
Log:<br>
[codeview] Emit retained types<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D21630" rel="noreferrer" target="_blank">http://reviews.llvm.org/D21630</a><br>
<br>
Added:<br>
    llvm/trunk/test/DebugInfo/COFF/retained-types.ll<br>
Modified:<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp?rev=273579&r1=273578&r2=273579&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp?rev=273579&r1=273578&r2=273579&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp Thu Jun 23 11:33:53 2016<br>
@@ -344,6 +344,9 @@ void CodeViewDebug::endModule() {<br>
   setCurrentSubprogram(nullptr);<br>
   emitDebugInfoForGlobals();<br>
<br>
+  // Emit retained types.<br>
+  emitDebugInfoForRetainedTypes();<br>
+<br>
   // Switch back to the generic .debug$S section after potentially processing<br>
   // comdat symbol sections.<br>
   switchToDebugSectionForSymbol(nullptr);<br>
@@ -1800,6 +1803,18 @@ void CodeViewDebug::emitDebugInfoForGlob<br>
       }<br>
     }<br>
   }<br>
+}<br>
+<br>
+void CodeViewDebug::emitDebugInfoForRetainedTypes() {<br>
+  NamedMDNode *CUs = MMI->getModule()->getNamedMetadata("<a href="http://llvm.dbg.cu" rel="noreferrer" target="_blank">llvm.dbg.cu</a>");<br>
+  for (const MDNode *Node : CUs->operands()) {<br>
+    for (auto *Ty : cast<DICompileUnit>(Node)->getRetainedTypes()) {<br>
+      if (DIType *RT = dyn_cast<DIType>(Ty)) {<br>
+        getTypeIndex(RT);<br>
+        // FIXME: Add to global/local DTU list.<br>
+      }<br>
+    }<br>
+  }<br>
 }<br>
<br>
 void CodeViewDebug::emitDebugInfoForGlobal(const DIGlobalVariable *DIGV,<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h?rev=273579&r1=273578&r2=273579&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h?rev=273579&r1=273578&r2=273579&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.h Thu Jun 23 11:33:53 2016<br>
@@ -191,6 +191,8 @@ class LLVM_LIBRARY_VISIBILITY CodeViewDe<br>
<br>
   void emitDebugInfoForGlobals();<br>
<br>
+  void emitDebugInfoForRetainedTypes();<br>
+<br>
   void emitDebugInfoForUDTs(<br>
       ArrayRef<std::pair<std::string, codeview::TypeIndex>> UDTs);<br>
<br>
<br>
Added: llvm/trunk/test/DebugInfo/COFF/retained-types.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/COFF/retained-types.ll?rev=273579&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/COFF/retained-types.ll?rev=273579&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/DebugInfo/COFF/retained-types.ll (added)<br>
+++ llvm/trunk/test/DebugInfo/COFF/retained-types.ll Thu Jun 23 11:33:53 2016<br>
@@ -0,0 +1,96 @@<br>
+; RUN: llc < %s -filetype=obj | llvm-readobj - -codeview | FileCheck %s<br>
+<br>
+; This test checks that types which are used in expressions, but for which<br>
+; there are no variables, known as retained types, get emitted.<br>
+<br>
+; C++ source to regenerate:<br>
+; $ cat /tmp/a.cc<br>
+; struct S { int x; };<br>
+; int f(void *p) {<br>
+;   return static_cast<S*>(p)->x;<br>
+; }<br></blockquote><div><br></div><div>Could simplify the test a bit, if you like:<br><br>struct S { };<br>void f() {<br>  static_cast<S*>(0);<br>}<br><br>Would remove some of those extraneous types from the output that Reid mentioned in review.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+; $ clang /tmp/a.cc -S -emit-llvm -g -gcodeview -target x86_64-windows-msvc -o t.ll<br>
+<br>
+; CHECK:       Struct (0x{{[0-9a-f]+}}) {<br>
+; CHEC-NEXT:     TypeLeafKind: LF_STRUCTURE (0x1505)<br>
+; CHEC-NEXT:     MemberCount: 0<br>
+; CHEC-NEXT:     Properties [ (0x280)<br>
+; CHEC-NEXT:       ForwardReference (0x80)<br>
+; CHEC-NEXT:       HasUniqueName (0x200)<br>
+; CHEC-NEXT:     ]<br>
+; CHEC-NEXT:     FieldList: 0x0<br>
+; CHEC-NEXT:     DerivedFrom: 0x0<br>
+; CHEC-NEXT:     VShape: 0x0<br>
+; CHEC-NEXT:     SizeOf: 0<br>
+; CHEC-NEXT:     Name: S<br>
+; CHEC-NEXT:     LinkageName: .?AUS@@<br>
+; CHEC-NEXT:   }<br>
+<br>
+; CHECK:        Struct (0x{{[0-9a-f]+}}) {<br>
+; CHECK-NEXT:     TypeLeafKind: LF_STRUCTURE (0x1505)<br>
+; CHECK-NEXT:     MemberCount: 1<br>
+; CHECK-NEXT:     Properties [ (0x200)<br>
+; CHECK-NEXT:       HasUniqueName (0x200)<br>
+; CHECK-NEXT:     ]<br>
+; CHECK-NEXT:     FieldList: <field list> (0x{{[0-9a-f]+}})<br>
+; CHECK-NEXT:     DerivedFrom: 0x0<br>
+; CHECK-NEXT:     VShape: 0x0<br>
+; CHECK-NEXT:     SizeOf: 4<br>
+; CHECK-NEXT:     Name: S<br>
+; CHECK-NEXT:     LinkageName: .?AUS@@<br>
+; CHECK-NEXT:   }<br>
+<br>
+; ModuleID = '/tmp/a.cc'<br>
+source_filename = "/tmp/a.cc"<br>
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"<br>
+target triple = "x86_64--windows-msvc18.0.0"<br>
+<br>
+%struct.S = type { i32 }<br>
+<br>
+; Function Attrs: nounwind uwtable<br>
+define i32 @"\01?f@@YAHPEAX@Z"(i8* %p) #0 !dbg !13 {<br>
+entry:<br>
+  %p.addr = alloca i8*, align 8<br>
+  store i8* %p, i8** %p.addr, align 8<br>
+  call void @llvm.dbg.declare(metadata i8** %p.addr, metadata !17, metadata !18), !dbg !19<br>
+  %0 = load i8*, i8** %p.addr, align 8, !dbg !20<br>
+  %1 = bitcast i8* %0 to %struct.S*, !dbg !21<br>
+  %x = getelementptr inbounds %struct.S, %struct.S* %1, i32 0, i32 0, !dbg !22<br>
+  %2 = load i32, i32* %x, align 4, !dbg !22<br>
+  ret i32 %2, !dbg !23<br>
+}<br>
+<br>
+; Function Attrs: nounwind readnone<br>
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #1<br>
+<br>
+attributes #0 = { nounwind uwtable "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" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }<br>
+attributes #1 = { nounwind readnone }<br>
+<br>
+!<a href="http://llvm.dbg.cu" rel="noreferrer" target="_blank">llvm.dbg.cu</a> = !{!0}<br>
+!llvm.module.flags = !{!9, !10, !11}<br>
+!llvm.ident = !{!12}<br>
+<br>
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.9.0 (trunk 273441) (llvm/trunk 273449)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3)<br>
+!1 = !DIFile(filename: "/tmp/a.cc", directory: "/usr/local/google/work/llvm/build.release")<br>
+!2 = !{}<br>
+!3 = !{!4}<br>
+!4 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !5, size: 64, align: 64)<br>
+!5 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S", file: !1, line: 1, size: 32, align: 32, elements: !6, identifier: ".?AUS@@")<br>
+!6 = !{!7}<br>
+!7 = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: !5, file: !1, line: 1, baseType: !8, size: 32, align: 32)<br>
+!8 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)<br>
+!9 = !{i32 2, !"CodeView", i32 1}<br>
+!10 = !{i32 2, !"Debug Info Version", i32 3}<br>
+!11 = !{i32 1, !"PIC Level", i32 2}<br>
+!12 = !{!"clang version 3.9.0 (trunk 273441) (llvm/trunk 273449)"}<br>
+!13 = distinct !DISubprogram(name: "f", linkageName: "\01?f@@YAHPEAX@Z", scope: !1, file: !1, line: 2, type: !14, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)<br>
+!14 = !DISubroutineType(types: !15)<br>
+!15 = !{!8, !16}<br>
+!16 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64, align: 64)<br>
+!17 = !DILocalVariable(name: "p", arg: 1, scope: !13, file: !1, line: 2, type: !16)<br>
+!18 = !DIExpression()<br>
+!19 = !DILocation(line: 2, column: 13, scope: !13)<br>
+!20 = !DILocation(line: 3, column: 26, scope: !13)<br>
+!21 = !DILocation(line: 3, column: 10, scope: !13)<br>
+!22 = !DILocation(line: 3, column: 30, scope: !13)<br>
+!23 = !DILocation(line: 3, column: 3, scope: !13)<br>
<br>
<br>
_______________________________________________<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/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>