]> granicus.if.org Git - llvm/commitdiff
Fix an assertion failure when duplicate dbg.declares are present.
authorAdrian Prantl <aprantl@apple.com>
Mon, 12 Jun 2017 22:41:06 +0000 (22:41 +0000)
committerAdrian Prantl <aprantl@apple.com>
Mon, 12 Jun 2017 22:41:06 +0000 (22:41 +0000)
This fixes PR33157.
https://bugs.llvm.org//show_bug.cgi?id=33157

We might also think about disallowing duplicate dbg.declare intrinsics
entirely, but this may complicate some passes needlessly.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@305244 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/AsmPrinter/DwarfDebug.h
test/DebugInfo/Generic/double-declare.ll [new file with mode: 0644]

index ebfba4cfc275ae220b83ef2cc8ea090f005cc0bf..5dfe06c64ec22b6134e7498012f16bc6c999dd2d 100644 (file)
@@ -134,6 +134,13 @@ public:
     assert(!FrameIndexExprs.empty() && "Expected an MMI entry");
     assert(!V.FrameIndexExprs.empty() && "Expected an MMI entry");
 
+    if (FrameIndexExprs.size()) {
+      auto *Expr = FrameIndexExprs.back().Expr;
+      // Get rid of duplicate non-fragment entries. More than one non-fragment
+      // dbg.declare makes no sense so ignore all but the first.
+      if (!Expr || !Expr->isFragment())
+        return;
+    }
     FrameIndexExprs.append(V.FrameIndexExprs.begin(), V.FrameIndexExprs.end());
     assert(all_of(FrameIndexExprs,
                   [](FrameIndexExpr &FIE) {
diff --git a/test/DebugInfo/Generic/double-declare.ll b/test/DebugInfo/Generic/double-declare.ll
new file mode 100644 (file)
index 0000000..6111d0b
--- /dev/null
@@ -0,0 +1,44 @@
+; RUN: %llc_dwarf -O0 -filetype=obj -o - < %s | llvm-dwarfdump -debug-dump=info - | FileCheck %s
+; PR33157. Don't crash on duplicate dbg.declare.
+; CHECK: DW_TAG_formal_parameter
+; CHECK: DW_AT_location [DW_FORM_exprloc]
+; CHECK-NOT: DW_AT_location
+@g = external global i32
+@h = external global i32
+
+declare void @llvm.dbg.declare(metadata, metadata, metadata)
+
+define void @f(i32* byval %p, i1 %c) !dbg !5 {
+  br i1 %c, label %x, label %y
+
+x:
+  call void @llvm.dbg.declare(metadata i32* %p, metadata !10, metadata !DIExpression()), !dbg !12
+  store i32 42, i32* @g, !dbg !12
+  br label %done
+
+y:
+  call void @llvm.dbg.declare(metadata i32* %p, metadata !10, metadata !DIExpression()), !dbg !12
+  store i32 42, i32* @h, !dbg !12
+  br label %done
+
+done:
+  ret void
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!22, !23}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_ObjC, file: !1, producer: "clang version 5.0.0 ", isOptimized: true, runtimeVersion: 2, emissionKind: FullDebug)
+!1 = !DIFile(filename: "<stdin>", directory: "C:\5Csrc\5Cllvm-project\5Cbuild")
+!5 = distinct !DISubprogram(name: "f", isLocal: true, isDefinition: true, scopeLine: 37, flags: DIFlagPrototyped, isOptimized: true, unit: !0, type: !99, scope: !1)
+!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!10 = !DILocalVariable(name: "aRect", arg: 1, scope: !11, file: !1, line: 38, type: !6)
+!11 = distinct !DILexicalBlock(scope: !98, file: !1, line: 38)
+!12 = !DILocation(line: 43, scope: !11, inlinedAt: !13)
+!13 = distinct !DILocation(line: 43, scope: !5)
+!22 = !{i32 2, !"Dwarf Version", i32 4}
+!23 = !{i32 2, !"Debug Info Version", i32 3}
+!62 = !{!10}
+!98 = distinct !DISubprogram(name: "NSMaxX", scope: !1, file: !1, line: 27, isLocal: true, isDefinition: true, scopeLine: 27, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !62, type: !99)
+!99 = !DISubroutineType(types: !100)
+!100 = !{null}