Skip to content

Commit 1218515

Browse files
authored
Merge pull request swiftlang#14338 from eeckstein/fix-nd
Fix two issues which prevents incremental llvm compilation
2 parents 5dd3572 + 43c5373 commit 1218515

File tree

4 files changed

+37
-12
lines changed

4 files changed

+37
-12
lines changed

lib/Frontend/CompilerInvocation.cpp

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

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

484-
if (!Quote && !Escape) {
484+
if (StringRef(Arg).startswith(TempDir)) {
485+
// Don't write temporary file names in the debug info. This would prevent
486+
// incremental llvm compilation because we would generate different IR on
487+
// every compiler invocation.
488+
Arg = "<temporary-file>";
489+
}
490+
491+
if (!Escape) {
485492
OS << Arg;
486493
return;
487494
}
@@ -705,9 +712,14 @@ void CompilerInvocation::buildDWARFDebugFlags(std::string &Output,
705712
const ArrayRef<const char*> &Args,
706713
StringRef SDKPath,
707714
StringRef ResourceDir) {
715+
// This isn't guaranteed to be the same temp directory as what the driver
716+
// uses, but it's highly likely.
717+
llvm::SmallString<128> TDir;
718+
llvm::sys::path::system_temp_directory(true, TDir);
719+
708720
llvm::raw_string_ostream OS(Output);
709721
interleave(Args,
710-
[&](const char *Argument) { PrintArg(OS, Argument, false); },
722+
[&](const char *Argument) { PrintArg(OS, Argument, TDir.str()); },
711723
[&] { OS << " "; });
712724

713725
// Inject the SDK path and resource dir if they are nonempty and missing.
@@ -723,11 +735,11 @@ void CompilerInvocation::buildDWARFDebugFlags(std::string &Output,
723735
}
724736
if (!haveSDKPath) {
725737
OS << " -sdk ";
726-
PrintArg(OS, SDKPath.data(), false);
738+
PrintArg(OS, SDKPath.data(), TDir.str());
727739
}
728740
if (!haveResourceDir) {
729741
OS << " -resource-dir ";
730-
PrintArg(OS, ResourceDir.data(), false);
742+
PrintArg(OS, ResourceDir.data(), TDir.str());
731743
}
732744
}
733745

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+

utils/check-incremental

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ from __future__ import print_function
2323
import os
2424
import subprocess
2525
import sys
26+
import time
2627

2728

2829
VERBOSE = False
@@ -37,11 +38,11 @@ def compile_and_stat(compile_args, output_file):
3738
subprocess.check_call(compile_args)
3839

3940
md5 = subprocess.check_output(["md5", "-q", output_file])
40-
mtime = os.path.getmtime(output_file)
41+
mtime = time.ctime(os.path.getmtime(output_file))
4142

4243
if VERBOSE:
43-
print(" time = {}".format(md5))
44-
print(" md5 = " + mtime)
44+
print(" time = " + str(mtime))
45+
print(" md5 = " + md5)
4546

4647
return (md5, mtime)
4748

0 commit comments

Comments
 (0)