Skip to content

Commit 3fd5afc

Browse files
committed
Debug Info: Assert that the main source file name is non-empty.
The Darwin linker won't process the debug info if the source file name is invalid so there is no point in having a fallback implemented there. <rdar://problem/25130236>
1 parent 0375994 commit 3fd5afc

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ IRGenDebugInfo::IRGenDebugInfo(const IRGenOptions &Opts,
9595
ClangImporter &CI,
9696
IRGenModule &IGM,
9797
llvm::Module &M,
98-
SourceFile *SF)
98+
StringRef MainSourceFileName)
9999
: Opts(Opts),
100100
CI(CI),
101101
SM(IGM.Context.SourceMgr),
@@ -107,18 +107,8 @@ IRGenDebugInfo::IRGenDebugInfo(const IRGenOptions &Opts,
107107
LastDebugLoc({}),
108108
LastScope(nullptr)
109109
{
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-
}
110+
assert(Opts.DebugInfoKind > IRGenDebugInfoKind::None &&
111+
"no debug info should be generated");
122112

123113
unsigned Lang = llvm::dwarf::DW_LANG_Swift;
124114
std::string Producer = version::getSwiftFullVersion(
@@ -131,6 +121,14 @@ IRGenDebugInfo::IRGenDebugInfo(const IRGenOptions &Opts,
131121

132122
// No split DWARF on Darwin.
133123
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+
134132
// Note that File + Dir need not result in a valid path.
135133
// Clang is doing the same thing here.
136134
TheCU = DBuilder.createCompileUnit(

lib/IRGen/IRGenDebugInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class IRGenDebugInfo {
9797

9898
public:
9999
IRGenDebugInfo(const IRGenOptions &Opts, ClangImporter &CI, IRGenModule &IGM,
100-
llvm::Module &M, SourceFile *SF);
100+
llvm::Module &M, StringRef MainSourceFileName);
101101

102102
/// Finalize the llvm::DIBuilder owned by this object.
103103
void finalize();

lib/IRGen/IRGenModule.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,11 @@ IRGenModule::IRGenModule(IRGenerator &irgen,
384384
else
385385
RegisterPreservingCC = DefaultCC;
386386

387-
if (IRGen.Opts.DebugInfoKind > IRGenDebugInfoKind::None)
388-
DebugInfo = new IRGenDebugInfo(IRGen.Opts, *CI, *this, Module, SF);
387+
if (IRGen.Opts.DebugInfoKind > IRGenDebugInfoKind::None) {
388+
StringRef MainFile(SF ? SF->getFilename()
389+
: StringRef(IRGen.Opts.MainInputFilename));
390+
DebugInfo = new IRGenDebugInfo(IRGen.Opts, *CI, *this, Module, MainFile);
391+
}
389392

390393
initClangTypeConverter();
391394
}

0 commit comments

Comments
 (0)