[llvm] r312773 - Fix a crash when emitting debug info for multi-reg function arguments

Adrian Prantl via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 7 19:31:37 PDT 2017


Author: adrian
Date: Thu Sep  7 19:31:37 2017
New Revision: 312773

URL: http://llvm.org/viewvc/llvm-project?rev=312773&view=rev
Log:
Fix a crash when emitting debug info for multi-reg function arguments
by reusing more of the existing machinery

This is a follow-up to r312169.
Thanks to Björn Pettersson for the testcase!

Added:
    llvm/trunk/test/DebugInfo/X86/sdag-split-arg.ll
Modified:
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp?rev=312773&r1=312772&r2=312773&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp Thu Sep  7 19:31:37 2017
@@ -4809,23 +4809,27 @@ bool SelectionDAGBuilder::EmitFuncArgume
     // Check if ValueMap has reg number.
     DenseMap<const Value *, unsigned>::iterator VMI = FuncInfo.ValueMap.find(V);
     if (VMI != FuncInfo.ValueMap.end()) {
-      auto *Ty = V->getType();
       const auto &TLI = DAG.getTargetLoweringInfo();
-      EVT VT = TLI.getValueType(DAG.getDataLayout(), Ty);
-      unsigned NumRegs = TLI.getNumRegisters(Ty->getContext(), VT);
+      RegsForValue RFV(V->getContext(), TLI, DAG.getDataLayout(), VMI->second,
+                       V->getType(), isABIRegCopy(V));
+      unsigned NumRegs =
+          std::accumulate(RFV.RegCount.begin(), RFV.RegCount.end(), 0);
       if (NumRegs > 1) {
-        // The registers are guaranteed to be allocated in sequence.
+        unsigned I = 0;
         unsigned Offset = 0;
-        MVT RegisterVT = TLI.getRegisterType(Ty->getContext(), VT);
-        unsigned RegisterSize = RegisterVT.getSizeInBits();
-        for (unsigned I = 0; I != NumRegs; ++I) {
-          Op = MachineOperand::CreateReg(VMI->second + I, false);
-          auto *FragmentExpr = DIExpression::createFragmentExpression(
-              Expr, Offset, RegisterSize);
-          FuncInfo.ArgDbgValues.push_back(
-              BuildMI(MF, DL, TII->get(TargetOpcode::DBG_VALUE), IsDbgDeclare,
-                      Op->getReg(), Variable, FragmentExpr));
-          Offset += RegisterSize;
+        auto RegisterVT = RFV.RegVTs.begin();
+        for (auto RegCount : RFV.RegCount) {
+          unsigned RegisterSize = (RegisterVT++)->getSizeInBits();
+          for (unsigned E = I + RegCount; I != E; ++I) {
+            // The vregs are guaranteed to be allocated in sequence.
+            Op = MachineOperand::CreateReg(VMI->second + I, false);
+            auto *FragmentExpr = DIExpression::createFragmentExpression(
+                Expr, Offset, RegisterSize);
+            FuncInfo.ArgDbgValues.push_back(
+                BuildMI(MF, DL, TII->get(TargetOpcode::DBG_VALUE), IsDbgDeclare,
+                        Op->getReg(), Variable, FragmentExpr));
+            Offset += RegisterSize;
+          }
         }
         return true;
       }

Added: llvm/trunk/test/DebugInfo/X86/sdag-split-arg.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/sdag-split-arg.ll?rev=312773&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/sdag-split-arg.ll (added)
+++ llvm/trunk/test/DebugInfo/X86/sdag-split-arg.ll Thu Sep  7 19:31:37 2017
@@ -0,0 +1,51 @@
+; RUN: llc -O0 -filetype=asm %s -o - | FileCheck %s
+; Test large integral function arguments passed in multiple registers.
+; CHECK: DEBUG_VALUE: foo:bar <- [DW_OP_LLVM_fragment 64 16] %AX
+; CHECK: DEBUG_VALUE: foo:bar <- [DW_OP_LLVM_fragment 48 16] %R9W
+; CHECK: DEBUG_VALUE: foo:bar <- [DW_OP_LLVM_fragment 32 16] %R10W
+; CHECK: DEBUG_VALUE: foo:bar <- [DW_OP_LLVM_fragment 16 16] %R11W
+; CHECK: DEBUG_VALUE: foo:bar <- [DW_OP_LLVM_fragment 0 16] %BX
+
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-unknown"
+
+%rec789 = type { [5 x i16] }
+
+define void @foo(%rec789 %bar) !dbg !6 {
+  %bar.2 = alloca %rec789, align 1
+  call void @llvm.dbg.value(metadata %rec789 %bar, metadata !17, metadata !DIExpression()), !dbg !18
+  %1 = extractvalue %rec789 %bar, 0
+  %.repack = getelementptr inbounds %rec789, %rec789* %bar.2, i16 0, i32 0, i16 0
+  %.elt = extractvalue [5 x i16] %1, 0
+  store i16 %.elt, i16* %.repack, align 1
+  ret void, !dbg !19
+}
+
+; Function Attrs: nounwind readnone speculatable
+declare void @llvm.dbg.value(metadata, metadata, metadata) #6
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4}
+!llvm.ident = !{!5}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !2)
+!1 = !DIFile(filename: "a.c", directory: "b")
+!2 = !{}
+!3 = !{i32 2, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{!""}
+!6 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 13, type: !7, isLocal: false, isDefinition: true, scopeLine: 14, isOptimized: false, unit: !0, variables: !2)
+!7 = !DISubroutineType(types: !8)
+!8 = !{!9, !9}
+!9 = !DIDerivedType(tag: DW_TAG_typedef, name: "MyStruct", file: !1, line: 11, baseType: !10)
+!10 = !DICompositeType(tag: DW_TAG_structure_type, file: !1, line: 9, size: 80, elements: !11)
+!11 = !{!12}
+!12 = !DIDerivedType(tag: DW_TAG_member, name: "Array", scope: !10, file: !1, line: 10, baseType: !13, size: 80)
+!13 = !DICompositeType(tag: DW_TAG_array_type, baseType: !14, size: 80, elements: !15)
+!14 = !DIBasicType(name: "int", size: 16, encoding: DW_ATE_signed)
+!15 = !{!16}
+!16 = !DISubrange(count: 5)
+!17 = !DILocalVariable(name: "bar", arg: 1, scope: !6, line: 13, type: !9)
+!18 = !DILocation(line: 13, column: 23, scope: !6)
+!19 = !DILocation(line: 15, column: 5, scope: !6)
+!20 = !DILocation(line: 16, column: 1, scope: !6)




More information about the llvm-commits mailing list