From: Quentin Colombet Date: Thu, 15 Oct 2015 00:41:26 +0000 (+0000) Subject: [ARM] Make sure we do not dereference the end iterator when accessing debug X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=2c6d721466eea010c1be424d550aee6dadc1dabd [ARM] Make sure we do not dereference the end iterator when accessing debug information. Although the problem was always here, it would only be exposed when shrink-wrapping is enable. rdar://problem/23110493 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250352 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/ARM/ARMFrameLowering.cpp b/lib/Target/ARM/ARMFrameLowering.cpp index 802946aa8d9..f0f077e0bc2 100644 --- a/lib/Target/ARM/ARMFrameLowering.cpp +++ b/lib/Target/ARM/ARMFrameLowering.cpp @@ -1060,7 +1060,7 @@ static void emitAlignedDPRCS2Spills(MachineBasicBlock &MBB, const TargetRegisterInfo *TRI) { MachineFunction &MF = *MBB.getParent(); ARMFunctionInfo *AFI = MF.getInfo(); - DebugLoc DL = MI->getDebugLoc(); + DebugLoc DL = MI != MBB.end() ? MI->getDebugLoc() : DebugLoc(); const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo(); MachineFrameInfo &MFI = *MF.getFrameInfo(); @@ -1220,7 +1220,7 @@ static void emitAlignedDPRCS2Restores(MachineBasicBlock &MBB, const TargetRegisterInfo *TRI) { MachineFunction &MF = *MBB.getParent(); ARMFunctionInfo *AFI = MF.getInfo(); - DebugLoc DL = MI->getDebugLoc(); + DebugLoc DL = MI != MBB.end() ? MI->getDebugLoc() : DebugLoc(); const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo(); // Find the frame index assigned to d8. diff --git a/test/CodeGen/ARM/arm-shrink-wrapping.ll b/test/CodeGen/ARM/arm-shrink-wrapping.ll index 1313fefdd58..9375df4b15c 100644 --- a/test/CodeGen/ARM/arm-shrink-wrapping.ll +++ b/test/CodeGen/ARM/arm-shrink-wrapping.ll @@ -624,3 +624,60 @@ loop2b: ; preds = %loop1 end: ret void } + +; Function Attrs: nounwind readnone +declare double @llvm.pow.f64(double, double) + +; This function needs to spill floating point registers to +; exerce the path where we were deferencing the end iterator +; to access debug info location while inserting the spill code +; during PEI with shrink-wrapping enable. +; CHECK-LABEL: debug_info: +; +; ENABLE: tst{{(\.w)?}} r2, #1 +; ENABLE-NEXT: beq [[BB13:LBB[0-9_]+]] +; +; CHECK: push +; +; DISABLE: tst{{(\.w)?}} r2, #1 +; DISABLE-NEXT: beq [[BB13:LBB[0-9_]+]] +; +; CHECK: bl{{x?}} _pow +; +; +; ENABLE: pop +; +; CHECK: [[BB13]]: +; CHECK: vldr +; +; DISABLE: pop +; +; CHECK: bl +define float @debug_info(float %gamma, float %slopeLimit, i1 %or.cond, double %tmp) { +bb: + br i1 %or.cond, label %bb3, label %bb13 + +bb3: ; preds = %bb + %tmp4 = fcmp ogt float %gamma, 1.000000e+00 + %tmp5 = fadd double 1.000000e+00, %tmp + %tmp6 = select i1 %tmp4, double %tmp5, double %tmp + %tmp10 = tail call double @llvm.pow.f64(double %tmp, double %tmp) + %tmp11 = fcmp une double %tmp6, %tmp + %tmp12 = fadd double %tmp10, %tmp10 + %cutoff.0 = select i1 %tmp11, double %tmp12, double %tmp + %phitmp = fptrunc double %cutoff.0 to float + br label %bb13 + +bb13: ; preds = %bb3, %bb + %cutoff.1 = phi float [ 0.000000e+00, %bb ], [ %phitmp, %bb3 ] + ret float %cutoff.1 +} + + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3} + +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "LLVM", isOptimized: true, runtimeVersion: 0, emissionKind: 1, enums: !2, retainedTypes: !2, subprograms: !2, globals: !2, imports: !2) +!1 = !DIFile(filename: "a.cpp", directory: "b") +!2 = !{} +!3 = !{i32 2, !"Debug Info Version", i32 3}