diff options
author | Ben Langmuir <blangmuir@apple.com> | 2014-07-19 16:29:28 +0000 |
---|---|---|
committer | Ben Langmuir <blangmuir@apple.com> | 2014-07-19 16:29:28 +0000 |
commit | b797d59f031600ffe1eccefae60fc678ed1d0aad (patch) | |
tree | be4c6b13688e73cab20cf952287b5ace15d45ae1 /clang | |
parent | aac5fc9cf89c47cf6d3da16836f2098604162336 (diff) | |
download | llvm-b797d59f031600ffe1eccefae60fc678ed1d0aad.zip llvm-b797d59f031600ffe1eccefae60fc678ed1d0aad.tar.gz llvm-b797d59f031600ffe1eccefae60fc678ed1d0aad.tar.bz2 |
If a module build reports errors, don't try to load it
... just to find out that it didn't build.
llvm-svn: 213454
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 7cea9e4..6af920d 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -852,11 +852,12 @@ static InputKind getSourceInputKindFromOptions(const LangOptions &LangOpts) { } /// \brief Compile a module file for the given module, using the options -/// provided by the importing compiler instance. -static void compileModuleImpl(CompilerInstance &ImportingInstance, - SourceLocation ImportLoc, - Module *Module, - StringRef ModuleFileName) { +/// provided by the importing compiler instance. Returns true if the module +/// was built without errors. +static bool compileModuleImpl(CompilerInstance &ImportingInstance, + SourceLocation ImportLoc, + Module *Module, + StringRef ModuleFileName) { ModuleMap &ModMap = ImportingInstance.getPreprocessor().getHeaderSearchInfo().getModuleMap(); @@ -979,13 +980,20 @@ static void compileModuleImpl(CompilerInstance &ImportingInstance, if (ImportingInstance.getFrontendOpts().GenerateGlobalModuleIndex) { ImportingInstance.setBuildGlobalModuleIndex(true); } + + return !Instance.getDiagnostics().hasErrorOccurred(); } static bool compileAndLoadModule(CompilerInstance &ImportingInstance, SourceLocation ImportLoc, - SourceLocation ModuleNameLoc, - Module *Module, + SourceLocation ModuleNameLoc, Module *Module, StringRef ModuleFileName) { + auto diagnoseBuildFailure = [&] { + ImportingInstance.getDiagnostics().Report(ModuleNameLoc, + diag::err_module_not_built) + << Module->Name << SourceRange(ImportLoc, ModuleNameLoc); + }; + // FIXME: have LockFileManager return an error_code so that we can // avoid the mkdir when the directory already exists. StringRef Dir = llvm::sys::path::parent_path(ModuleFileName); @@ -1000,9 +1008,11 @@ static bool compileAndLoadModule(CompilerInstance &ImportingInstance, case llvm::LockFileManager::LFS_Owned: // We're responsible for building the module ourselves. - // FIXME: if there are errors, don't attempt to load the module. - compileModuleImpl(ImportingInstance, ModuleNameLoc, Module, - ModuleFileName); + if (!compileModuleImpl(ImportingInstance, ModuleNameLoc, Module, + ModuleFileName)) { + diagnoseBuildFailure(); + return false; + } break; case llvm::LockFileManager::LFS_Shared: @@ -1027,9 +1037,7 @@ static bool compileAndLoadModule(CompilerInstance &ImportingInstance, // consistent with this ImportingInstance. Try again... continue; } else if (ReadResult == ASTReader::Missing) { - ImportingInstance.getDiagnostics().Report(ModuleNameLoc, - diag::err_module_not_built) - << Module->Name << SourceRange(ImportLoc, ModuleNameLoc); + diagnoseBuildFailure(); } return ReadResult == ASTReader::Success; } |