@@ -95,7 +95,7 @@ IRGenDebugInfo::IRGenDebugInfo(const IRGenOptions &Opts,
95
95
ClangImporter &CI,
96
96
IRGenModule &IGM,
97
97
llvm::Module &M,
98
- StringRef MainSourceFileName )
98
+ SourceFile *SF )
99
99
: Opts(Opts),
100
100
CI(CI),
101
101
SM(IGM.Context.SourceMgr),
@@ -107,8 +107,18 @@ IRGenDebugInfo::IRGenDebugInfo(const IRGenOptions &Opts,
107
107
LastDebugLoc({}),
108
108
LastScope(nullptr )
109
109
{
110
- assert (Opts.DebugInfoKind > IRGenDebugInfoKind::None &&
111
- " no debug info should be generated" );
110
+ assert (Opts.DebugInfoKind > IRGenDebugInfoKind::None
111
+ && " no debug info should be generated" );
112
+ StringRef SourceFileName = SF ? SF->getFilename () :
113
+ StringRef (Opts.MainInputFilename );
114
+ StringRef Dir;
115
+ llvm::SmallString<256 > AbsMainFile;
116
+ if (SourceFileName.empty ())
117
+ AbsMainFile = " <unknown>" ;
118
+ else {
119
+ AbsMainFile = SourceFileName;
120
+ llvm::sys::fs::make_absolute (AbsMainFile);
121
+ }
112
122
113
123
unsigned Lang = llvm::dwarf::DW_LANG_Swift;
114
124
std::string Producer = version::getSwiftFullVersion (
@@ -121,14 +131,6 @@ IRGenDebugInfo::IRGenDebugInfo(const IRGenOptions &Opts,
121
131
122
132
// No split DWARF on Darwin.
123
133
StringRef SplitName = StringRef ();
124
-
125
- // The Darwin linker ld64 depends on DW_AT_comp_dir to determine
126
- // whether an object file has debug info.
127
- assert (!MainSourceFileName.empty () && " main source file name is empty" );
128
- llvm::SmallString<256 > AbsMainFile;
129
- AbsMainFile = MainSourceFileName;
130
- llvm::sys::fs::make_absolute (AbsMainFile);
131
-
132
134
// Note that File + Dir need not result in a valid path.
133
135
// Clang is doing the same thing here.
134
136
TheCU = DBuilder.createCompileUnit (
0 commit comments