Index: clang/include/clang/StaticAnalyzer/Core/CheckerManager.h =================================================================== --- clang/include/clang/StaticAnalyzer/Core/CheckerManager.h +++ clang/include/clang/StaticAnalyzer/Core/CheckerManager.h @@ -126,7 +126,8 @@ class CheckerManager { ASTContext *Context = nullptr; - const LangOptions LangOpts; + const LangOptions &LangOpts; + const CodeGenOptions &CodeGenOpts; const AnalyzerOptions &AOptions; const Preprocessor *PP = nullptr; CheckerNameRef CurrentCheckerName; @@ -141,7 +142,8 @@ // dependencies look like this: Core -> Checkers -> Frontend. CheckerManager( - ASTContext &Context, AnalyzerOptions &AOptions, const Preprocessor &PP, + ASTContext &Context, AnalyzerOptions &AOptions, + const CodeGenOptions &CGOpts, const Preprocessor &PP, ArrayRef plugins, ArrayRef> checkerRegistrationFns); @@ -149,14 +151,15 @@ /// checkers. Useful for unit testing, unless the checker infrastructure /// itself is tested. CheckerManager(ASTContext &Context, AnalyzerOptions &AOptions, - const Preprocessor &PP) - : CheckerManager(Context, AOptions, PP, {}, {}) {} + const CodeGenOptions &CGOpts, const Preprocessor &PP) + : CheckerManager(Context, AOptions, CGOpts, PP, {}, {}) {} /// Constructs a CheckerManager without requiring an AST. No checker /// registration will take place. Only useful when one needs to print the /// help flags through CheckerRegistryData, and the AST is unavalaible. CheckerManager(AnalyzerOptions &AOptions, const LangOptions &LangOpts, - DiagnosticsEngine &Diags, ArrayRef plugins); + const CodeGenOptions &CGOpts, DiagnosticsEngine &Diags, + ArrayRef plugins); ~CheckerManager(); @@ -168,6 +171,7 @@ void finishedCheckerRegistration(); const LangOptions &getLangOpts() const { return LangOpts; } + const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; } const AnalyzerOptions &getAnalyzerOptions() const { return AOptions; } const Preprocessor &getPreprocessor() const { assert(PP); Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h =================================================================== --- clang/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h +++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h @@ -35,6 +35,7 @@ ASTContext &Ctx; Preprocessor &PP; const LangOptions &LangOpts; + const CodeGenOptions &CodeGenOpts; PathDiagnosticConsumers PathConsumers; // Configurable components creators. @@ -51,6 +52,7 @@ StoreManagerCreator storemgr, ConstraintManagerCreator constraintmgr, CheckerManager *checkerMgr, AnalyzerOptions &Options, + const CodeGenOptions &CGOpts, CodeInjector *injector = nullptr); ~AnalysisManager() override; @@ -73,6 +75,8 @@ return options; } + const CodeGenOptions &getCodeGenOptions() const { return CodeGenOpts; } + ConstraintManagerCreator getConstraintManagerCreator() { return CreateConstraintMgr; } Index: clang/lib/StaticAnalyzer/Core/AnalysisManager.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/AnalysisManager.cpp +++ clang/lib/StaticAnalyzer/Core/AnalysisManager.cpp @@ -13,32 +13,26 @@ void AnalysisManager::anchor() { } -AnalysisManager::AnalysisManager(ASTContext &ASTCtx, Preprocessor &PP, - const PathDiagnosticConsumers &PDC, - StoreManagerCreator storemgr, - ConstraintManagerCreator constraintmgr, - CheckerManager *checkerMgr, - AnalyzerOptions &Options, - CodeInjector *injector) +AnalysisManager::AnalysisManager( + ASTContext &ASTCtx, Preprocessor &PP, const PathDiagnosticConsumers &PDC, + StoreManagerCreator storemgr, ConstraintManagerCreator constraintmgr, + CheckerManager *checkerMgr, AnalyzerOptions &Options, + const CodeGenOptions &CGOpts, CodeInjector *injector) : AnaCtxMgr( ASTCtx, Options.UnoptimizedCFG, Options.ShouldIncludeImplicitDtorsInCFG, - /*addInitializers=*/true, - Options.ShouldIncludeTemporaryDtorsInCFG, + /*addInitializers=*/true, Options.ShouldIncludeTemporaryDtorsInCFG, Options.ShouldIncludeLifetimeInCFG, // Adding LoopExit elements to the CFG is a requirement for loop // unrolling. - Options.ShouldIncludeLoopExitInCFG || - Options.ShouldUnrollLoops, - Options.ShouldIncludeScopesInCFG, - Options.ShouldSynthesizeBodies, + Options.ShouldIncludeLoopExitInCFG || Options.ShouldUnrollLoops, + Options.ShouldIncludeScopesInCFG, Options.ShouldSynthesizeBodies, Options.ShouldConditionalizeStaticInitializers, /*addCXXNewAllocator=*/true, Options.ShouldIncludeRichConstructorsInCFG, Options.ShouldElideConstructors, - /*addVirtualBaseBranches=*/true, - injector), - Ctx(ASTCtx), PP(PP), LangOpts(ASTCtx.getLangOpts()), + /*addVirtualBaseBranches=*/true, injector), + Ctx(ASTCtx), PP(PP), LangOpts(ASTCtx.getLangOpts()), CodeGenOpts(CGOpts), PathConsumers(PDC), CreateStoreMgr(storemgr), CreateConstraintMgr(constraintmgr), CheckerMgr(checkerMgr), options(Options) { Index: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp =================================================================== --- clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp +++ clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp @@ -88,6 +88,7 @@ Preprocessor &PP; const std::string OutDir; AnalyzerOptionsRef Opts; + const CodeGenOptions &CodeGenOpts; ArrayRef Plugins; CodeInjector *Injector; cross_tu::CrossTranslationUnitContext CTU; @@ -121,11 +122,11 @@ FunctionSummariesTy FunctionSummaries; AnalysisConsumer(CompilerInstance &CI, const std::string &outdir, - AnalyzerOptionsRef opts, ArrayRef plugins, - CodeInjector *injector) + AnalyzerOptionsRef opts, const CodeGenOptions &CGOpts, + ArrayRef plugins, CodeInjector *injector) : RecVisitorMode(0), RecVisitorBR(nullptr), Ctx(nullptr), PP(CI.getPreprocessor()), OutDir(outdir), Opts(std::move(opts)), - Plugins(plugins), Injector(injector), CTU(CI), + CodeGenOpts(CGOpts), Plugins(plugins), Injector(injector), CTU(CI), MacroExpansions(CI.getLangOpts()) { DigestAnalyzerOptions(); if (Opts->AnalyzerDisplayProgress || Opts->PrintStats || @@ -228,12 +229,12 @@ void Initialize(ASTContext &Context) override { Ctx = &Context; - checkerMgr = std::make_unique(*Ctx, *Opts, PP, Plugins, - CheckerRegistrationFns); + checkerMgr = std::make_unique( + *Ctx, *Opts, CodeGenOpts, PP, Plugins, CheckerRegistrationFns); - Mgr = std::make_unique(*Ctx, PP, PathConsumers, - CreateStoreMgr, CreateConstraintMgr, - checkerMgr.get(), *Opts, Injector); + Mgr = std::make_unique( + *Ctx, PP, PathConsumers, CreateStoreMgr, CreateConstraintMgr, + checkerMgr.get(), *Opts, CodeGenOpts, Injector); } /// Store the top level decls in the set to be processed later on. @@ -712,7 +713,7 @@ bool hasModelPath = analyzerOpts->Config.count("model-path") > 0; return std::make_unique( - CI, CI.getFrontendOpts().OutputFile, analyzerOpts, + CI, CI.getFrontendOpts().OutputFile, analyzerOpts, CI.getCodeGenOpts(), CI.getFrontendOpts().Plugins, hasModelPath ? new ModelInjector(CI) : nullptr); } Index: clang/lib/StaticAnalyzer/Frontend/AnalyzerHelpFlags.cpp =================================================================== --- clang/lib/StaticAnalyzer/Frontend/AnalyzerHelpFlags.cpp +++ clang/lib/StaticAnalyzer/Frontend/AnalyzerHelpFlags.cpp @@ -25,35 +25,29 @@ using namespace clang; using namespace ento; +static CheckerManager CreateCheckerManager(CompilerInstance &CI) { + return {*CI.getAnalyzerOpts(), CI.getLangOpts(), CI.getCodeGenOpts(), + CI.getDiagnostics(), CI.getFrontendOpts().Plugins}; +} + void ento::printCheckerHelp(raw_ostream &out, CompilerInstance &CI) { out << "OVERVIEW: Clang Static Analyzer Checkers List\n\n"; out << "USAGE: -analyzer-checker \n\n"; - auto CheckerMgr = std::make_unique( - *CI.getAnalyzerOpts(), CI.getLangOpts(), CI.getDiagnostics(), - CI.getFrontendOpts().Plugins); - - CheckerMgr->getCheckerRegistryData().printCheckerWithDescList( + CreateCheckerManager(CI).getCheckerRegistryData().printCheckerWithDescList( *CI.getAnalyzerOpts(), out); } void ento::printEnabledCheckerList(raw_ostream &out, CompilerInstance &CI) { out << "OVERVIEW: Clang Static Analyzer Enabled Checkers List\n\n"; - auto CheckerMgr = std::make_unique( - *CI.getAnalyzerOpts(), CI.getLangOpts(), CI.getDiagnostics(), - CI.getFrontendOpts().Plugins); - - CheckerMgr->getCheckerRegistryData().printEnabledCheckerList(out); + CreateCheckerManager(CI).getCheckerRegistryData().printEnabledCheckerList( + out); } void ento::printCheckerConfigList(raw_ostream &out, CompilerInstance &CI) { - auto CheckerMgr = std::make_unique( - *CI.getAnalyzerOpts(), CI.getLangOpts(), CI.getDiagnostics(), - CI.getFrontendOpts().Plugins); - - CheckerMgr->getCheckerRegistryData().printCheckerOptionList( + CreateCheckerManager(CI).getCheckerRegistryData().printCheckerOptionList( *CI.getAnalyzerOpts(), out); } Index: clang/lib/StaticAnalyzer/Frontend/CreateCheckerManager.cpp =================================================================== --- clang/lib/StaticAnalyzer/Frontend/CreateCheckerManager.cpp +++ clang/lib/StaticAnalyzer/Frontend/CreateCheckerManager.cpp @@ -18,11 +18,12 @@ namespace ento { CheckerManager::CheckerManager( - ASTContext &Context, AnalyzerOptions &AOptions, const Preprocessor &PP, + ASTContext &Context, AnalyzerOptions &AOptions, + const CodeGenOptions &CGOpts, const Preprocessor &PP, ArrayRef plugins, ArrayRef> checkerRegistrationFns) - : Context(&Context), LangOpts(Context.getLangOpts()), AOptions(AOptions), - PP(&PP), Diags(Context.getDiagnostics()), + : Context(&Context), LangOpts(Context.getLangOpts()), CodeGenOpts(CGOpts), + AOptions(AOptions), PP(&PP), Diags(Context.getDiagnostics()), RegistryData(std::make_unique()) { CheckerRegistry Registry(*RegistryData, plugins, Context.getDiagnostics(), AOptions, checkerRegistrationFns); @@ -33,9 +34,10 @@ CheckerManager::CheckerManager(AnalyzerOptions &AOptions, const LangOptions &LangOpts, + const CodeGenOptions &CGOpts, DiagnosticsEngine &Diags, ArrayRef plugins) - : LangOpts(LangOpts), AOptions(AOptions), Diags(Diags), + : LangOpts(LangOpts), CodeGenOpts(CGOpts), AOptions(AOptions), Diags(Diags), RegistryData(std::make_unique()) { CheckerRegistry Registry(*RegistryData, plugins, Diags, AOptions, {}); Registry.initializeRegistry(*this); Index: clang/unittests/StaticAnalyzer/Reusables.h =================================================================== --- clang/unittests/StaticAnalyzer/Reusables.h +++ clang/unittests/StaticAnalyzer/Reusables.h @@ -62,7 +62,7 @@ CTU(C), Consumers(), AMgr(C.getASTContext(), C.getPreprocessor(), Consumers, CreateRegionStoreManager, CreateRangeConstraintManager, &ChkMgr, - *C.getAnalyzerOpts()), + *C.getAnalyzerOpts(), C.getCodeGenOpts()), VisitedCallees(), FS(), Eng(CTU, AMgr, &VisitedCallees, &FS, ExprEngine::Inline_Regular) {} };