Skip to content

Commit cc2ed20

Browse files
committed
debug-info: Don't write temporary file names in the debug info.
This would prevent incremental llvm compilation because we would generate different IR on every compiler invocation.
1 parent 23cbd11 commit cc2ed20

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

lib/Frontend/CompilerInvocation.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,10 +1252,17 @@ static bool ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
12521252
}
12531253

12541254
// Lifted from the clang driver.
1255-
static void PrintArg(raw_ostream &OS, const char *Arg, bool Quote) {
1255+
static void PrintArg(raw_ostream &OS, const char *Arg, StringRef TempDir) {
12561256
const bool Escape = std::strpbrk(Arg, "\"\\$ ");
12571257

1258-
if (!Quote && !Escape) {
1258+
if (StringRef(Arg).startswith(TempDir)) {
1259+
// Don't write temporary file names in the debug info. This would prevent
1260+
// incremental llvm compilation because we would generate different IR on
1261+
// every compiler invocation.
1262+
Arg = "<temporary-file>";
1263+
}
1264+
1265+
if (!Escape) {
12591266
OS << Arg;
12601267
return;
12611268
}
@@ -1479,9 +1486,14 @@ void CompilerInvocation::buildDWARFDebugFlags(std::string &Output,
14791486
const ArrayRef<const char*> &Args,
14801487
StringRef SDKPath,
14811488
StringRef ResourceDir) {
1489+
// This isn't guaranteed to be the same temp directory as what the driver
1490+
// uses, but it's highly likely.
1491+
llvm::SmallString<128> TDir;
1492+
llvm::sys::path::system_temp_directory(true, TDir);
1493+
14821494
llvm::raw_string_ostream OS(Output);
14831495
interleave(Args,
1484-
[&](const char *Argument) { PrintArg(OS, Argument, false); },
1496+
[&](const char *Argument) { PrintArg(OS, Argument, TDir.str()); },
14851497
[&] { OS << " "; });
14861498

14871499
// Inject the SDK path and resource dir if they are nonempty and missing.
@@ -1497,11 +1509,11 @@ void CompilerInvocation::buildDWARFDebugFlags(std::string &Output,
14971509
}
14981510
if (!haveSDKPath) {
14991511
OS << " -sdk ";
1500-
PrintArg(OS, SDKPath.data(), false);
1512+
PrintArg(OS, SDKPath.data(), TDir.str());
15011513
}
15021514
if (!haveResourceDir) {
15031515
OS << " -resource-dir ";
1504-
PrintArg(OS, ResourceDir.data(), false);
1516+
PrintArg(OS, ResourceDir.data(), TDir.str());
15051517
}
15061518
}
15071519

test/DebugInfo/compiler-flags.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@
2121
// CHECK-LLDB-NOT: debug_pubnames
2222
// CHECK-LLDB: apple_names
2323
// CHECK-LLDB-NOT: debug_pubnames
24+
25+
// Check that we don't write temporary file names in the debug info
26+
// RUN: TMPDIR=abc/def %target-swift-frontend %s -I abc/def/xyz -g -emit-ir -o - | %FileCheck --check-prefix CHECK-TEMP %s
27+
// CHECK-TEMP: !DICompileUnit({{.*}} flags: "{{.*}} -I <temporary-file>
28+

0 commit comments

Comments
 (0)