From c70d101ab087b8321762228b8705148ae5041f57 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Sat, 24 Sep 2016 17:48:04 -0700 Subject: [PATCH] Debug info: When skipping over cleanup locations in the middle of a basic block, revert to line number 0 instead of reusing the last location. This avoids emitting illegal IR if there was no previous location and the instruction being emitted is a function call. rdar://problem/28237133 --- lib/IRGen/GenProto.cpp | 2 ++ lib/IRGen/IRGenSIL.cpp | 6 ++++-- test/DebugInfo/cleanupskip.swift | 16 ++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 test/DebugInfo/cleanupskip.swift diff --git a/lib/IRGen/GenProto.cpp b/lib/IRGen/GenProto.cpp index d5fb1b5a32f74..16b3a2a2c29df 100644 --- a/lib/IRGen/GenProto.cpp +++ b/lib/IRGen/GenProto.cpp @@ -2837,6 +2837,8 @@ llvm::Value *irgen::emitAssociatedTypeMetadataRef(IRGenFunction &IGF, witness = IGF.Builder.CreateBitCast(witness, witnessTy->getPointerTo()); // Call the accessor. + assert((!IGF.IGM.DebugInfo || IGF.Builder.getCurrentDebugLocation()) && + "creating a function call without a debug location"); auto call = IGF.Builder.CreateCall(witness, { parentMetadata, wtable }); call->setDoesNotThrow(); call->setCallingConv(IGF.IGM.DefaultCC); diff --git a/lib/IRGen/IRGenSIL.cpp b/lib/IRGen/IRGenSIL.cpp index 03bf4ce71141f..159705617be8b 100644 --- a/lib/IRGen/IRGenSIL.cpp +++ b/lib/IRGen/IRGenSIL.cpp @@ -1569,10 +1569,12 @@ void IRGenSILFunction::visitSILBasicBlock(SILBasicBlock *BB) { assert(maybeScopeless(I) && "instruction has location, but no scope"); } - // Ignore scope-less instructions and have IRBuilder reuse the - // previous location and scope. + // Set the builder's debug location. if (DS && !KeepCurrentLocation) IGM.DebugInfo->setCurrentLoc(Builder, DS, ILoc); + else + // Use an artificial (line 0) location. + IGM.DebugInfo->setCurrentLoc(Builder, DS); // Function argument handling. if (InEntryBlock && !ArgsEmitted) { diff --git a/test/DebugInfo/cleanupskip.swift b/test/DebugInfo/cleanupskip.swift new file mode 100644 index 0000000000000..c1c54a790af1c --- /dev/null +++ b/test/DebugInfo/cleanupskip.swift @@ -0,0 +1,16 @@ +// RUN: %target-swift-frontend -emit-ir -g %s -o - -O -disable-llvm-optzns | %FileCheck %s +// REQUIRES: objc_interop +import Foundation + +public class NSCoder : NSObject {} + +public class AClass : NSObject { + // Ensure that the call to the type metadata accessor has a line number. + // CHECK: call %swift.type* @_TMaC11cleanupskip7NSCoder() + // CHECK-SAME: !dbg ![[LINEZ:[0-9]+]] + // CHECK: ![[LINEZ]] = {{.*}}line: 0 + public required init?(coder aDecoder: NSCoder) { + return nil + } +} +