Verify SIL modules at the beginning and at the end of the SIL optimization pipelines, if -sil-verify-all is provided

Till now, a SIL module would be only verified if an optimization has changed it. But if there were no changes, then no verification would happen and some SIL module format errors would stay unnoticed. This was happening in certain cases when reading a textual SIL module representation, which turned out to be broken, but SIL verifier wouldn't catch it.

Swift SVN r31863
This commit is contained in:
Roman Levenstein
2015-09-10 22:26:37 +00:00
parent 66e13af73e
commit 141b8f814d
13 changed files with 46 additions and 33 deletions

View File

@@ -315,7 +315,7 @@ class CompilerInstance {
SourceFile *PrimarySourceFile = nullptr;
void createSILModule(bool WholeModule = false);
void createSILModule();
void setPrimarySourceFile(SourceFile *SF);
public:

View File

@@ -232,9 +232,8 @@ public:
/// \brief Create and return an empty SIL module that we can
/// later parse SIL bodies directly into, without converting from an AST.
static std::unique_ptr<SILModule> createEmptyModule(Module *M,
SILOptions &Options,
bool WholeModule = false) {
return std::unique_ptr<SILModule>(new SILModule(M, Options, M, WholeModule));
SILOptions &Options) {
return std::unique_ptr<SILModule>(new SILModule(M, Options, M, false));
}
/// Get the Swift module associated with this SIL module.

View File

@@ -34,11 +34,10 @@
using namespace swift;
void CompilerInstance::createSILModule(bool WholeModule) {
void CompilerInstance::createSILModule() {
assert(MainModule && "main module not created yet");
TheSILModule = SILModule::createEmptyModule(getMainModule(),
Invocation.getSILOptions(),
WholeModule);
Invocation.getSILOptions());
}
void CompilerInstance::setPrimarySourceFile(SourceFile *SF) {
@@ -234,8 +233,7 @@ void CompilerInstance::performSema() {
if (Kind == InputFileKind::IFK_SIL) {
assert(BufferIDs.size() == 1);
assert(MainBufferID != NO_SUCH_BUFFER);
// Assume WMO, if a -primary-file option was not provided.
createSILModule(!options.PrimaryInput.hasValue());
createSILModule();
modImpKind = SourceFile::ImplicitModuleImportKind::None;
} else if (Invocation.getParseStdlib()) {
modImpKind = SourceFile::ImplicitModuleImportKind::Builtin;

View File

@@ -64,6 +64,10 @@ static void registerAnalysisPasses(SILPassManager &PM) {
}
bool swift::runSILDiagnosticPasses(SILModule &Module) {
// Verify the module, if required.
if (Module.getOptions().VerifyAll)
Module.verify();
// If we parsed a .sil file that is already in canonical form, don't rerun
// the diagnostic passes.
if (Module.getStage() == SILStage::Canonical)
@@ -114,6 +118,13 @@ bool swift::runSILDiagnosticPasses(SILModule &Module) {
PM.runOneIteration();
}
// Verify the module, if required.
if (Module.getOptions().VerifyAll)
Module.verify();
else {
DEBUG(Module.verify());
}
// If errors were produced during SIL analysis, return true.
return Ctx.hadError();
}
@@ -214,6 +225,10 @@ void AddSSAPasses(SILPassManager &PM, OptimizationLevelKind OpLevel) {
void swift::runSILOptimizationPasses(SILModule &Module) {
// Verify the module, if required.
if (Module.getOptions().VerifyAll)
Module.verify();
if (Module.getOptions().DebugSerialization) {
SILPassManager PM(&Module);
registerAnalysisPasses(PM);
@@ -332,10 +347,19 @@ void swift::runSILOptimizationPasses(SILModule &Module) {
PM.runOneIteration();
}
// Verify the module, if required.
if (Module.getOptions().VerifyAll)
Module.verify();
else {
DEBUG(Module.verify());
}
}
void swift::runSILPassesForOnone(SILModule &Module) {
// Verify the module, if required.
if (Module.getOptions().VerifyAll)
Module.verify();
SILPassManager PM(&Module, "Onone");
registerAnalysisPasses(PM);
@@ -354,6 +378,13 @@ void swift::runSILPassesForOnone(SILModule &Module) {
PM.addExternalDefsToDecls();
PM.runOneIteration();
// Verify the module, if required.
if (Module.getOptions().VerifyAll)
Module.verify();
else {
DEBUG(Module.verify());
}
}
#ifndef NDEBUG

View File

@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -primary-file %s -emit-ir| FileCheck --check-prefix=CHECK --check-prefix=CHECK-%target-cpu %s
// RUN: %target-swift-frontend -emit-ir %s | FileCheck --check-prefix=CHECK --check-prefix=CHECK-%target-cpu %s
// REQUIRES: CPU=i386_or_x86_64

View File

@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -primary-file %s -g -emit-ir | FileCheck %s
// RUN: %target-swift-frontend -g -emit-ir %s | FileCheck %s
import Builtin
import Swift

View File

@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -primary-file %s -gnone -emit-ir | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize
// RUN: %target-swift-frontend %s -gnone -emit-ir | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize
// REQUIRES: CPU=x86_64

View File

@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -primary-file %s -emit-ir | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-runtime
// RUN: %target-swift-frontend %s -emit-ir | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-runtime
// REQUIRES: executable_test
sil_stage canonical

View File

@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -primary-file %s -O -emit-ir | FileCheck %s
// RUN: %target-swift-frontend %s -O -emit-ir | FileCheck %s
sil_stage canonical

View File

@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -primary-file %s -emit-ir | FileCheck %s
// RUN: %target-swift-frontend %s -emit-ir | FileCheck %s
// REQUIRES: CPU=x86_64

View File

@@ -1,6 +1,6 @@
// RUN: rm -rf %t && mkdir %t
// RUN: %build-irgen-test-overlays
// RUN: %target-swift-frontend(mock-sdk: -sdk %S/Inputs -I %t) -primary-file %s -emit-ir | FileCheck --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize %s
// RUN: %target-swift-frontend(mock-sdk: -sdk %S/Inputs -I %t) %s -emit-ir | FileCheck --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize %s
// REQUIRES: objc_interop

View File

@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -primary-file %s -emit-ir > %t
// RUN: %target-swift-frontend -emit-ir %s > %t
// RUN: FileCheck %s --check-prefix=CHECK-%target-object-format --check-prefix=CHECK < %t
// RUN: FileCheck -check-prefix=NEGATIVE %s < %t

View File

@@ -150,9 +150,6 @@ static llvm::cl::opt<unsigned>
ASTVerifierProcessId("ast-verifier-process-id", llvm::cl::Hidden,
llvm::cl::init(1));
static llvm::cl::opt<bool>
PerformWMO("wmo", llvm::cl::desc("Enable whole-module optimizations"));
static void runCommandLineSelectedPasses(SILModule *Module) {
SILPassManager PM(Module);
@@ -256,20 +253,8 @@ int main(int argc, char **argv) {
PrintingDiagnosticConsumer PrintDiags;
CI.addDiagnosticConsumer(&PrintDiags);
if (!PerformWMO) {
auto &FrontendOpts = Invocation.getFrontendOptions();
if (!InputFilename.empty() && InputFilename != "-") {
FrontendOpts.PrimaryInput = SelectedInput(
FrontendOpts.InputFilenames.size());
} else {
FrontendOpts.PrimaryInput = SelectedInput(
FrontendOpts.InputBuffers.size(), SelectedInput::InputKind::Buffer);
}
}
if (CI.setup(Invocation))
return 1;
CI.performSema();
// If parsing produced an error, don't run any passes.