Skip to content

Fix memory violation when build record is bad. #28444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/swift/Driver/Compilation.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ using CommandSet = llvm::SmallPtrSet<const Job *, 16>;
class Compilation {
public:
class IncrementalSchemeComparator {
const bool EnableIncrementalBuildWhenConstructed;
const bool &EnableIncrementalBuild;
const bool EnableSourceRangeDependencies;
const bool &UseSourceRangeDependencies;
Expand Down Expand Up @@ -108,7 +109,8 @@ class Compilation {
const StringRef CompareIncrementalSchemesPath,
unsigned SwiftInputCount,
DiagnosticEngine &Diags)
: EnableIncrementalBuild(EnableIncrementalBuild),
: EnableIncrementalBuildWhenConstructed(EnableIncrementalBuild),
EnableIncrementalBuild(EnableIncrementalBuild),
EnableSourceRangeDependencies(EnableSourceRangeDependencies),
UseSourceRangeDependencies(UseSourceRangeDependencies),
CompareIncrementalSchemesPath(CompareIncrementalSchemesPath),
Expand Down
4 changes: 4 additions & 0 deletions lib/Driver/Compilation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2003,6 +2003,10 @@ void Compilation::IncrementalSchemeComparator::outputComparison() const {

void Compilation::IncrementalSchemeComparator::outputComparison(
llvm::raw_ostream &out) const {
if (!EnableIncrementalBuildWhenConstructed) {
out << "*** Incremental build was not enabled in the command line ***\n";
return;
}
if (!EnableIncrementalBuild) {
// No stats will have been gathered
assert(!WhyIncrementalWasDisabled.empty() && "Must be a reason");
Expand Down
8 changes: 4 additions & 4 deletions lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ static bool getCompilationRecordPath(std::string &buildRecordPath,
return false;
}

static StringRef failedToReadOutOfDateMap(bool ShowIncrementalBuildDecisions,
static std::string failedToReadOutOfDateMap(bool ShowIncrementalBuildDecisions,
StringRef buildRecordPath,
StringRef reason = "") {
std::string why = "malformed build record file";
Expand All @@ -398,7 +398,7 @@ static void dealWithRemovedInputs(ArrayRef<StringRef> removedInputs,
bool ShowIncrementalBuildDecisions);

/// Returns why ignore incrementality
static StringRef
static std::string
populateOutOfDateMap(InputInfoMap &map, llvm::sys::TimePoint<> &LastBuildTime,
StringRef argsHashStr, const InputFileList &inputs,
StringRef buildRecordPath,
Expand Down Expand Up @@ -893,7 +893,7 @@ Driver::buildCompilation(const ToolChain &TC,
computeArgsHash(ArgsHash, *TranslatedArgList);
llvm::sys::TimePoint<> LastBuildTime = llvm::sys::TimePoint<>::min();
InputInfoMap outOfDateMap;
StringRef whyIgnoreIncrementallity =
std::string whyIgnoreIncrementallity =
!Incremental
? ""
: buildRecordPath.empty()
Expand Down Expand Up @@ -1027,7 +1027,7 @@ Driver::buildCompilation(const ToolChain &TC,
// This has to happen after building jobs, because otherwise we won't even
// emit .swiftdeps files for the next build.
if (!whyIgnoreIncrementallity.empty())
C->disableIncrementalBuild(whyIgnoreIncrementallity.str());
C->disableIncrementalBuild(whyIgnoreIncrementallity);

if (Diags.hadAnyError())
return nullptr;
Expand Down