From: Gabor Horvath Date: Fri, 2 Nov 2018 11:22:22 +0000 (+0000) Subject: [analyzer][CTU] Correctly signal in the function index generation tool if there was... X-Git-Tag: llvmorg-8.0.0-rc1~5150 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9c0fdc15e00c16ac42219c26086f5bee5668d456;p=platform%2Fupstream%2Fllvm.git [analyzer][CTU] Correctly signal in the function index generation tool if there was an error Differential Revision: https://reviews.llvm.org/D53979 llvm-svn: 345965 --- diff --git a/clang/tools/clang-func-mapping/CMakeLists.txt b/clang/tools/clang-func-mapping/CMakeLists.txt index ae28e28..2fc6aba 100644 --- a/clang/tools/clang-func-mapping/CMakeLists.txt +++ b/clang/tools/clang-func-mapping/CMakeLists.txt @@ -1,8 +1,6 @@ set(LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD} - asmparser support - mc ) add_clang_executable(clang-func-mapping @@ -15,7 +13,6 @@ target_link_libraries(clang-func-mapping clangBasic clangCrossTU clangFrontend - clangIndex clangTooling ) diff --git a/clang/tools/clang-func-mapping/ClangFnMapGen.cpp b/clang/tools/clang-func-mapping/ClangFnMapGen.cpp index 8adc1fa..635bb02 100644 --- a/clang/tools/clang-func-mapping/ClangFnMapGen.cpp +++ b/clang/tools/clang-func-mapping/ClangFnMapGen.cpp @@ -14,23 +14,16 @@ #include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTContext.h" -#include "clang/AST/GlobalDecl.h" -#include "clang/AST/Mangle.h" -#include "clang/AST/StmtVisitor.h" #include "clang/Basic/SourceManager.h" -#include "clang/Basic/TargetInfo.h" #include "clang/CrossTU/CrossTranslationUnit.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendActions.h" -#include "clang/Index/USRGeneration.h" #include "clang/Tooling/CommonOptionsParser.h" #include "clang/Tooling/Tooling.h" #include "llvm/Support/CommandLine.h" -#include "llvm/Support/Path.h" #include "llvm/Support/Signals.h" #include #include -#include using namespace llvm; using namespace clang; @@ -41,21 +34,22 @@ static cl::OptionCategory ClangFnMapGenCategory("clang-fnmapgen options"); class MapFunctionNamesConsumer : public ASTConsumer { public: - MapFunctionNamesConsumer(ASTContext &Context) : Ctx(Context) {} + MapFunctionNamesConsumer(ASTContext &Context) + : SM(Context.getSourceManager()) {} ~MapFunctionNamesConsumer() { // Flush results to standard output. llvm::outs() << createCrossTUIndexString(Index); } - virtual void HandleTranslationUnit(ASTContext &Ctx) { + void HandleTranslationUnit(ASTContext &Ctx) override { handleDecl(Ctx.getTranslationUnitDecl()); } private: void handleDecl(const Decl *D); - ASTContext &Ctx; + SourceManager &SM; llvm::StringMap Index; std::string CurrentFileName; }; @@ -67,8 +61,6 @@ void MapFunctionNamesConsumer::handleDecl(const Decl *D) { if (const auto *FD = dyn_cast(D)) { if (FD->isThisDeclarationADefinition()) { if (const Stmt *Body = FD->getBody()) { - std::string LookupName = CrossTranslationUnitContext::getLookupName(FD); - const SourceManager &SM = Ctx.getSourceManager(); if (CurrentFileName.empty()) { CurrentFileName = SM.getFileEntryForID(SM.getMainFileID())->tryGetRealPathName(); @@ -80,8 +72,11 @@ void MapFunctionNamesConsumer::handleDecl(const Decl *D) { case ExternalLinkage: case VisibleNoLinkage: case UniqueExternalLinkage: - if (SM.isInMainFile(Body->getBeginLoc())) + if (SM.isInMainFile(Body->getBeginLoc())) { + std::string LookupName = + CrossTranslationUnitContext::getLookupName(FD); Index[LookupName] = CurrentFileName; + } break; default: break; @@ -99,9 +94,7 @@ class MapFunctionNamesAction : public ASTFrontendAction { protected: std::unique_ptr CreateASTConsumer(CompilerInstance &CI, llvm::StringRef) { - std::unique_ptr PFC( - new MapFunctionNamesConsumer(CI.getASTContext())); - return PFC; + return llvm::make_unique(CI.getASTContext()); } }; @@ -120,6 +113,6 @@ int main(int argc, const char **argv) { ClangTool Tool(OptionsParser.getCompilations(), OptionsParser.getSourcePathList()); - Tool.run(newFrontendActionFactory().get()); - return 0; + + return Tool.run(newFrontendActionFactory().get()); }