Skip to content

Commit c001a14

Browse files
authored
Merge pull request #14421 from eeckstein/fix-nd-4.1
[4.1] Fix two issues which prevents incremental llvm compilation
2 parents a95faf7 + e5f1064 commit c001a14

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
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

lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,11 +477,18 @@ SILInstruction *SILCombiner::visitLoadInst(LoadInst *LI) {
477477
// Given a load with multiple struct_extracts/tuple_extracts and no other
478478
// uses, canonicalize the load into several (struct_element_addr (load))
479479
// pairs.
480-
using ProjInstPairTy = std::pair<Projection, SingleValueInstruction *>;
480+
481+
struct ProjInstPair {
482+
Projection P;
483+
SingleValueInstruction *I;
484+
485+
// When sorting, just look at the projection and ignore the instruction.
486+
bool operator<(const ProjInstPair &RHS) const { return P < RHS.P; }
487+
};
481488

482489
// Go through the loads uses and add any users that are projections to the
483490
// projection list.
484-
llvm::SmallVector<ProjInstPairTy, 8> Projections;
491+
llvm::SmallVector<ProjInstPair, 8> Projections;
485492
for (auto *UI : getNonDebugUses(LI)) {
486493
auto *User = UI->getUser();
487494

@@ -503,8 +510,8 @@ SILInstruction *SILCombiner::visitLoadInst(LoadInst *LI) {
503510
Projection *LastProj = nullptr;
504511
LoadInst *LastNewLoad = nullptr;
505512
for (auto &Pair : Projections) {
506-
auto &Proj = Pair.first;
507-
auto *Inst = Pair.second;
513+
auto &Proj = Pair.P;
514+
auto *Inst = Pair.I;
508515

509516
// If this projection is the same as the last projection we processed, just
510517
// replace all uses of the projection with the load we created previously.

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)