Index: tools/clang-diff/ClangDiff.cpp =================================================================== --- tools/clang-diff/ClangDiff.cpp +++ tools/clang-diff/ClangDiff.cpp @@ -84,27 +84,33 @@ Compilations = std::move(AdjustingCompilations); } -static std::unique_ptr -getAST(const std::unique_ptr &CommonCompilations, - const StringRef Filename) { +static std::unique_ptr +getCompilationDatabase(StringRef Filename) { std::string ErrorMessage; - std::unique_ptr Compilations; - if (!CommonCompilations) { - Compilations = CompilationDatabase::autoDetectFromSource( - BuildPath.empty() ? Filename : BuildPath, ErrorMessage); - if (!Compilations) { - llvm::errs() - << "Error while trying to load a compilation database, running " - "without flags.\n" - << ErrorMessage; - Compilations = - llvm::make_unique( - ".", std::vector()); - } + std::unique_ptr Compilations = + CompilationDatabase::autoDetectFromSource( + BuildPath.empty() ? Filename : BuildPath, ErrorMessage); + if (!Compilations) { + llvm::errs() + << "Error while trying to load a compilation database, running " + "without flags.\n" + << ErrorMessage; + Compilations = llvm::make_unique( + ".", std::vector()); } addExtraArgs(Compilations); + return Compilations; +} + +static std::unique_ptr +getAST(const std::unique_ptr &CommonCompilations, + const StringRef Filename) { std::array Files = {{Filename}}; - ClangTool Tool(Compilations ? *Compilations : *CommonCompilations, Files); + std::unique_ptr FileCompilations; + if (!CommonCompilations) + FileCompilations = getCompilationDatabase(Filename); + ClangTool Tool(CommonCompilations ? *CommonCompilations : *FileCompilations, + Files); std::vector> ASTs; Tool.buildASTs(ASTs); if (ASTs.size() != Files.size())