mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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:
@@ -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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user