@@ -2661,12 +2661,18 @@ void IRGenDebugInfoImpl::addFailureMessageToCurrentLoc(IRBuilder &Builder,
2661
2661
else {
2662
2662
std::string FuncName = " Swift runtime failure: " ;
2663
2663
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 ();
2665
2670
TrapSP = DBuilder.createFunction (
2666
2671
File, FuncName, StringRef (), File, 0 ,
2667
2672
DIFnTy, 0 , llvm::DINode::FlagArtificial,
2668
2673
llvm::DISubprogram::SPFlagDefinition, nullptr , nullptr , nullptr );
2669
- RuntimeErrorFnCache.insert ({failureMsg, llvm::TrackingMDNodeRef (TrapSP)});
2674
+ if (useCompilerGeneratedFile)
2675
+ RuntimeErrorFnCache.insert ({failureMsg, llvm::TrackingMDNodeRef (TrapSP)});
2670
2676
}
2671
2677
2672
2678
ScopeCache[TrapSc] = llvm::TrackingMDNodeRef (TrapSP);
@@ -2675,7 +2681,11 @@ void IRGenDebugInfoImpl::addFailureMessageToCurrentLoc(IRBuilder &Builder,
2675
2681
assert (parentScopesAreSane (TrapSc) && " parent scope sanity check failed" );
2676
2682
2677
2683
// 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);
2679
2689
Builder.SetCurrentDebugLocation (DL);
2680
2690
}
2681
2691
0 commit comments