@@ -2661,12 +2661,18 @@ void IRGenDebugInfoImpl::addFailureMessageToCurrentLoc(IRBuilder &Builder,
26612661 else {
26622662 std::string FuncName = " Swift runtime failure: " ;
26632663 FuncName += failureMsg;
2664- llvm::DIFile *File = getOrCreateFile ({}, {});
2664+ // CodeView consumers do not correctly handle an artificially generated
2665+ // file, thus use the original location's file as the file for the debug
2666+ // function, and prevent reuse of this debug function.
2667+ bool useCompilerGeneratedFile = !Opts.isDebugInfoCodeView ();
2668+ llvm::DIFile *File =
2669+ useCompilerGeneratedFile ? getOrCreateFile ({}, {}) : TrapLoc->getFile ();
26652670 TrapSP = DBuilder.createFunction (
26662671 File, FuncName, StringRef (), File, 0 ,
26672672 DIFnTy, 0 , llvm::DINode::FlagArtificial,
26682673 llvm::DISubprogram::SPFlagDefinition, nullptr , nullptr , nullptr );
2669- RuntimeErrorFnCache.insert ({failureMsg, llvm::TrackingMDNodeRef (TrapSP)});
2674+ if (useCompilerGeneratedFile)
2675+ RuntimeErrorFnCache.insert ({failureMsg, llvm::TrackingMDNodeRef (TrapSP)});
26702676 }
26712677
26722678 ScopeCache[TrapSc] = llvm::TrackingMDNodeRef (TrapSP);
@@ -2675,7 +2681,11 @@ void IRGenDebugInfoImpl::addFailureMessageToCurrentLoc(IRBuilder &Builder,
26752681 assert (parentScopesAreSane (TrapSc) && " parent scope sanity check failed" );
26762682
26772683 // Wrap the existing TrapLoc into the failure function.
2678- auto DL = llvm::DILocation::get (IGM.getLLVMContext (), 0 , 0 , TrapSP, TrapLoc);
2684+ // Line 0 is invalid in CodeView, so use the line and column from the original
2685+ // trap location.
2686+ auto DL = llvm::DILocation::get (
2687+ IGM.getLLVMContext (), Opts.isDebugInfoCodeView () ? TrapLoc.getLine () : 0 ,
2688+ Opts.isDebugInfoCodeView () ? TrapLoc.getCol () : 0 , TrapSP, TrapLoc);
26792689 Builder.SetCurrentDebugLocation (DL);
26802690}
26812691
0 commit comments