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.
This commit is contained in:
Erik Eckstein
2018-01-30 16:59:39 -08:00
parent 72d2f84471
commit 17d4459227
2 changed files with 22 additions and 5 deletions

View File

@@ -478,10 +478,17 @@ static bool ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
} }
// Lifted from the clang driver. // Lifted from the clang driver.
static void PrintArg(raw_ostream &OS, const char *Arg, bool Quote) { static void PrintArg(raw_ostream &OS, const char *Arg, StringRef TempDir) {
const bool Escape = std::strpbrk(Arg, "\"\\$ "); const bool Escape = std::strpbrk(Arg, "\"\\$ ");
if (!Quote && !Escape) { if (StringRef(Arg).startswith(TempDir)) {
// 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.
Arg = "<temporary-file>";
}
if (!Escape) {
OS << Arg; OS << Arg;
return; return;
} }
@@ -705,9 +712,14 @@ void CompilerInvocation::buildDWARFDebugFlags(std::string &Output,
const ArrayRef<const char*> &Args, const ArrayRef<const char*> &Args,
StringRef SDKPath, StringRef SDKPath,
StringRef ResourceDir) { StringRef ResourceDir) {
// This isn't guaranteed to be the same temp directory as what the driver
// uses, but it's highly likely.
llvm::SmallString<128> TDir;
llvm::sys::path::system_temp_directory(true, TDir);
llvm::raw_string_ostream OS(Output); llvm::raw_string_ostream OS(Output);
interleave(Args, interleave(Args,
[&](const char *Argument) { PrintArg(OS, Argument, false); }, [&](const char *Argument) { PrintArg(OS, Argument, TDir.str()); },
[&] { OS << " "; }); [&] { OS << " "; });
// Inject the SDK path and resource dir if they are nonempty and missing. // Inject the SDK path and resource dir if they are nonempty and missing.
@@ -723,11 +735,11 @@ void CompilerInvocation::buildDWARFDebugFlags(std::string &Output,
} }
if (!haveSDKPath) { if (!haveSDKPath) {
OS << " -sdk "; OS << " -sdk ";
PrintArg(OS, SDKPath.data(), false); PrintArg(OS, SDKPath.data(), TDir.str());
} }
if (!haveResourceDir) { if (!haveResourceDir) {
OS << " -resource-dir "; OS << " -resource-dir ";
PrintArg(OS, ResourceDir.data(), false); PrintArg(OS, ResourceDir.data(), TDir.str());
} }
} }

View File

@@ -21,3 +21,8 @@
// CHECK-LLDB-NOT: debug_pubnames // CHECK-LLDB-NOT: debug_pubnames
// CHECK-LLDB: apple_names // CHECK-LLDB: apple_names
// CHECK-LLDB-NOT: debug_pubnames // CHECK-LLDB-NOT: debug_pubnames
// Check that we don't write temporary file names in the debug info
// RUN: TMPDIR=abc/def %target-swift-frontend %s -I abc/def/xyz -g -emit-ir -o - | %FileCheck --check-prefix CHECK-TEMP %s
// CHECK-TEMP: !DICompileUnit({{.*}} flags: "{{.*}} -I <temporary-file>