[PATCH] D52537: Ignore dropped call operands when allocating MD slot numbers

David Stenberg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 26 02:09:24 PDT 2018


dstenb created this revision.
dstenb added reviewers: vsk, dexonsmith.
Herald added a subscriber: llvm-commits.

This patch fixes crashes in situations where the funtion operand of a
call instruction was dropped, and later on a metadata-carrying
instruction was printed out. When allocating the metadata slot numbers,
getCalledFunction() would be invoked on the call with the dropped
operand, resulting in a failed non-null assertion in isa<>.

To fix this, simply look past null call operands in
SlotTracker::processFunctionMetadata(), as suggested by vsk.

This fixes PR38924, in which a printout in DBCE crashed due to this.


Repository:
  rL LLVM

https://reviews.llvm.org/D52537

Files:
  lib/IR/AsmWriter.cpp
  test/Transforms/BDCE/dump-crash.ll


Index: test/Transforms/BDCE/dump-crash.ll
===================================================================
--- /dev/null
+++ test/Transforms/BDCE/dump-crash.ll
@@ -0,0 +1,48 @@
+; RUN: opt -S -bdce -debug < %s 2>&1 | FileCheck %s
+
+; Reproducer for PR38924.
+;
+; Verify that it is possible to print the dbg.value when salvaging debug
+; information for the or instruction.
+
+; CHECK: SALVAGE: call void @llvm.dbg.value(metadata i32 123, metadata ![[VAR:[0-9]+]], metadata !DIExpression(DW_OP_constu, 456, DW_OP_or, DW_OP_stack_value)), !dbg ![[LOC:[0-9]+]]
+;
+; CHECK: call void @llvm.dbg.value(metadata i32 123, metadata ![[VAR]], metadata !DIExpression(DW_OP_constu, 456, DW_OP_or, DW_OP_stack_value)), !dbg ![[LOC]]
+;
+; CHECK-DAG: ![[VAR]] = !DILocalVariable(name: "local"
+; CHECK-DAG: ![[LOC]] = !DILocation(line: 234, column: 116
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; Function Attrs: noinline norecurse nounwind readnone
+declare fastcc i16 @foo() unnamed_addr #0
+
+; Function Attrs: noinline norecurse noreturn nounwind readonly
+define internal fastcc void @bar() unnamed_addr #1 !dbg !4 {
+entry:
+  %call = tail call fastcc i16 @foo()
+  %or = or i32 123, 456
+  call void @llvm.dbg.value(metadata i32 %or, metadata !7, metadata !DIExpression()), !dbg !6
+  ret void
+}
+
+; Function Attrs: nounwind readnone speculatable
+declare void @llvm.dbg.value(metadata, metadata, metadata) #2
+
+attributes #0 = { noinline norecurse nounwind readnone }
+attributes #1 = { noinline norecurse noreturn nounwind readonly }
+attributes #2 = { nounwind readnone }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 8.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !2)
+!1 = !DIFile(filename: "foo.c", directory: "/")
+!2 = !{}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 176, type: !5, isLocal: true, isDefinition: true, scopeLine: 177, flags: DIFlagPrototyped, isOptimized: false, unit: !0)
+!5 = !DISubroutineType(types: !2)
+!6 = !DILocation(line: 234, column: 116, scope: !4)
+!7 = !DILocalVariable(name: "local", scope: !4, file: !1, line: 221, type: !8)
+!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
Index: lib/IR/AsmWriter.cpp
===================================================================
--- lib/IR/AsmWriter.cpp
+++ lib/IR/AsmWriter.cpp
@@ -1060,12 +1060,13 @@
 void SlotTracker::processInstructionMetadata(const Instruction &I) {
   // Process metadata used directly by intrinsics.
   if (const CallInst *CI = dyn_cast<CallInst>(&I))
-    if (Function *F = CI->getCalledFunction())
-      if (F->isIntrinsic())
-        for (auto &Op : I.operands())
-          if (auto *V = dyn_cast_or_null<MetadataAsValue>(Op))
-            if (MDNode *N = dyn_cast<MDNode>(V->getMetadata()))
-              CreateMetadataSlot(N);
+    if (CI->getCalledValue())
+      if (Function *F = CI->getCalledFunction())
+        if (F->isIntrinsic())
+          for (auto &Op : I.operands())
+            if (auto *V = dyn_cast_or_null<MetadataAsValue>(Op))
+              if (MDNode *N = dyn_cast<MDNode>(V->getMetadata()))
+                CreateMetadataSlot(N);
 
   // Process metadata attached to this instruction.
   SmallVector<std::pair<unsigned, MDNode *>, 4> MDs;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52537.167083.patch
Type: text/x-patch
Size: 3474 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180926/de1bea81/attachment.bin>


More information about the llvm-commits mailing list