[llvm] r283784 - Teach llvm::StripDebugInfo() about global variable !dbg attachments.

Adrian Prantl via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 10 10:53:33 PDT 2016


Author: adrian
Date: Mon Oct 10 12:53:33 2016
New Revision: 283784

URL: http://llvm.org/viewvc/llvm-project?rev=283784&view=rev
Log:
Teach llvm::StripDebugInfo() about global variable !dbg attachments.
This is a regression introduced by the global variable ownership
reversal performed in r281284.

rdar://problem/28448075

Added:
    llvm/trunk/test/DebugInfo/strip-DIGlobalVariable.ll
Modified:
    llvm/trunk/lib/IR/DebugInfo.cpp
    llvm/trunk/test/Bitcode/dityperefs-3.8.ll
    llvm/trunk/test/Transforms/GlobalMerge/debug-info.ll

Modified: llvm/trunk/lib/IR/DebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfo.cpp?rev=283784&r1=283783&r2=283784&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DebugInfo.cpp (original)
+++ llvm/trunk/lib/IR/DebugInfo.cpp Mon Oct 10 12:53:33 2016
@@ -281,6 +281,15 @@ bool llvm::StripDebugInfo(Module &M) {
   for (Function &F : M)
     Changed |= stripDebugInfo(F);
 
+  for (auto &GV : M.globals()) {
+    SmallVector<MDNode *, 1> MDs;
+    GV.getMetadata(LLVMContext::MD_dbg, MDs);
+    if (!MDs.empty()) {
+      GV.eraseMetadata(LLVMContext::MD_dbg);
+      Changed = true;
+    }
+  }
+
   if (GVMaterializer *Materializer = M.getMaterializer())
     Materializer->setStripDebugInfo();
 

Modified: llvm/trunk/test/Bitcode/dityperefs-3.8.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/dityperefs-3.8.ll?rev=283784&r1=283783&r2=283784&view=diff
==============================================================================
--- llvm/trunk/test/Bitcode/dityperefs-3.8.ll (original)
+++ llvm/trunk/test/Bitcode/dityperefs-3.8.ll Mon Oct 10 12:53:33 2016
@@ -4,22 +4,24 @@
 ; Establish a stable order.
 !named = !{!0, !1, !2, !3, !4, !6, !7, !8, !9, !10, !11, !12, !13, !14, !15, !16}
 
-; CHECK: @G1 = global i32 0, !dbg !0
+; Since this is incomplete debug info the !dbg attachement will be stripped.
+; This doesn't matter for what is being tested here.
+; CHECK: @G1 = global i32 0
 
-; CHECK:      !0 = !DIGlobalVariable(name: "G",{{.*}} type: !1,
+; CHECK:      !0 = !DIFile(filename: "path/to/file", directory: "/path/to/dir")
 ; CHECK-NEXT: !1 = !DICompositeType(tag: DW_TAG_structure_type, name: "T1"{{.*}}, identifier: "T1")
-; CHECK-NEXT: !2 = !DIFile(filename: "path/to/file", directory: "/path/to/dir")
-; CHECK-NEXT: !3 = !DICompositeType(tag: DW_TAG_structure_type, name: "T2", scope: !1{{.*}}, baseType: !1, vtableHolder: !1, identifier: "T2")
-; CHECK-NEXT: !4 = !DIDerivedType(tag: DW_TAG_member, name: "M1", scope: !1{{.*}}, baseType: !3)
-; CHECK-NEXT: !5 = !DISubroutineType(types: !6)
-; CHECK-NEXT: !6 = !{!1, !3}
-; CHECK-NEXT: !7 = !DISubprogram(scope: !1,{{.*}} containingType: !1{{[,)]}}
-; CHECK-NEXT: !8 = !DILocalVariable(name: "V1", scope: !7, type: !3)
-; CHECK-NEXT: !9 = !DIObjCProperty(name: "P1", type: !1)
-; CHECK-NEXT: !10 = !DITemplateTypeParameter(type: !1)
+; CHECK-NEXT: !2 = !DICompositeType(tag: DW_TAG_structure_type, name: "T2", scope: !1{{.*}}, baseType: !1, vtableHolder: !1, identifier: "T2")
+; CHECK-NEXT: !3 = !DIDerivedType(tag: DW_TAG_member, name: "M1", scope: !1{{.*}}, baseType: !2)
+; CHECK-NEXT: !4 = !DISubroutineType(types: !5)
+; CHECK-NEXT: !5 = !{!1, !2}
+; CHECK-NEXT: !6 = !DISubprogram(scope: !1,{{.*}} containingType: !1{{[,)]}}
+; CHECK-NEXT: !7 = !DILocalVariable(name: "V1", scope: !6, type: !2)
+; CHECK-NEXT: !8 = !DIObjCProperty(name: "P1", type: !1)
+; CHECK-NEXT: !9 = !DITemplateTypeParameter(type: !1)
+; CHECK-NEXT: !10 = !DIGlobalVariable(name: "G",{{.*}} type: !1,
 ; CHECK-NEXT: !11 = !DITemplateValueParameter(type: !1, value: i32* @G1)
-; CHECK-NEXT: !12 = !DIImportedEntity(tag: DW_TAG_imported_module, name: "T2", scope: !2, entity: !1)
-; CHECK-NEXT: !13 = !DICompositeType(tag: DW_TAG_structure_type, name: "T3", file: !2, elements: !14, identifier: "T3")
+; CHECK-NEXT: !12 = !DIImportedEntity(tag: DW_TAG_imported_module, name: "T2", scope: !0, entity: !1)
+; CHECK-NEXT: !13 = !DICompositeType(tag: DW_TAG_structure_type, name: "T3", file: !0, elements: !14, identifier: "T3")
 ; CHECK-NEXT: !14 = !{!15}
 ; CHECK-NEXT: !15 = !DISubprogram(scope: !13,
 ; CHECK-NEXT: !16 = !DIDerivedType(tag: DW_TAG_ptr_to_member_type,{{.*}} extraData: !13)

Added: llvm/trunk/test/DebugInfo/strip-DIGlobalVariable.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/strip-DIGlobalVariable.ll?rev=283784&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/strip-DIGlobalVariable.ll (added)
+++ llvm/trunk/test/DebugInfo/strip-DIGlobalVariable.ll Mon Oct 10 12:53:33 2016
@@ -0,0 +1,15 @@
+; RUN: opt -S <%s 2>&1| FileCheck %s
+; CHECK: ignoring debug info with an invalid version (0)
+
+; CHECK: @Var = internal global i32 0
+; CHECK-NOT: !dbg
+ at Var = internal global i32 0, !dbg !0
+
+; Test that StripDebugInfo strips global variables.
+
+; CHECK-NOT: DIGlobalVariable
+
+!0 = !DIGlobalVariable(name: "Var", line: 2, isLocal: true, isDefinition: true, scope: !1, file: !3, type: !2)
+!1 = distinct !DICompileUnit(language: DW_LANG_C89, producer: "adrian", isOptimized: true, emissionKind: FullDebug, file: !3)
+!2 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
+!3 = !DIFile(filename: "var.c", directory: "/")

Modified: llvm/trunk/test/Transforms/GlobalMerge/debug-info.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GlobalMerge/debug-info.ll?rev=283784&r1=283783&r2=283784&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/GlobalMerge/debug-info.ll (original)
+++ llvm/trunk/test/Transforms/GlobalMerge/debug-info.ll Mon Oct 10 12:53:33 2016
@@ -18,6 +18,8 @@ define void @use1() {
 ; CHECK: [[B]] = distinct !DIGlobalVariable(name: "b", scope: null, isLocal: false, isDefinition: true, expr: [[EXPR:![0-9]+]])
 ; CHECK: [[EXPR]] = !DIExpression(DW_OP_plus, 4)
 
-
+!llvm.module.flags = !{!2, !3}
 !0 = distinct !DIGlobalVariable(name: "a")
 !1 = distinct !DIGlobalVariable(name: "b")
+!2 = !{i32 2, !"Debug Info Version", i32 3}
+!3 = !{i32 2, !"Dwarf Version", i32 4}




More information about the llvm-commits mailing list