[PATCH] D75171: [Analyzer] Fix for incorrect use of container and iterator checkers

Kristóf Umann via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 6 08:14:02 PST 2020


Szelethus added a comment.

Actually, this is the diff:

  diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td
  index ecd871e36ee..1f2c8c50a01 100644
  --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
  +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
  @@ -341,6 +341,8 @@ def err_analyzer_checker_option_unknown : Error<
     "checker '%0' has no option called '%1'">;
   def err_analyzer_checker_option_invalid_input : Error<
     "invalid input for checker option '%0', that expects %1">;
  +def err_analyzer_checker_incompatible_analyzer_option : Error<
  +  "checker cannot be enabled with analyzer option '%0' == %1">;
   
   def err_drv_invalid_hvx_length : Error<
     "-mhvx-length is not supported without a -mhvx/-mhvx= flag">;
  diff --git a/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h b/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
  index a3a85bfac13..680cb92e1ff 100644
  --- a/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
  +++ b/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
  @@ -169,8 +169,8 @@ public:
     void finishedCheckerRegistration();
   
     const LangOptions &getLangOpts() const { return LangOpts; }
  -  AnalyzerOptions &getAnalyzerOptions() { return AOptions; }
  -  ASTContext &getASTContext() {
  +  AnalyzerOptions &getAnalyzerOptions() const { return AOptions; }
  +  ASTContext &getASTContext() const {
       assert(Context);
       return *Context;
     }
  diff --git a/clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp b/clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp
  index 16a913e761c..f739417a37b 100644
  --- a/clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp
  +++ b/clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp
  @@ -12,6 +12,7 @@
   
   #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
   #include "clang/AST/DeclTemplate.h"
  +#include "clang/Driver/DriverDiagnostic.h"
   #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
   #include "clang/StaticAnalyzer/Core/Checker.h"
   #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
  @@ -1036,5 +1037,15 @@ void ento::registerContainerModeling(CheckerManager &mgr) {
   }
   
   bool ento::shouldRegisterContainerModeling(const CheckerManager &mgr) {
  +  if (!mgr.getLangOpts().CPlusPlus)
  +    return false;
  +
  +  if (!mgr.getAnalyzerOptions().ShouldAggressivelySimplifyBinaryOperation) {
  +    mgr.getASTContext().getDiagnostics().Report(
  +        diag::err_analyzer_checker_incompatible_analyzer_option)
  +      << "aggressive-binary-operation-simplification" << "false";
  +    return false;
  +  }
  +
     return true;
   }
  diff --git a/clang/test/Analysis/checker-dependencies.c b/clang/test/Analysis/checker-dependencies.c
  index 6c8583adb35..54d585561d1 100644
  --- a/clang/test/Analysis/checker-dependencies.c
  +++ b/clang/test/Analysis/checker-dependencies.c
  @@ -18,3 +18,11 @@
   
   // CHECK-IMPLICITLY-DISABLED-NOT: osx.cocoa.RetainCountBase
   // CHECK-IMPLICITLY-DISABLED-NOT: osx.cocoa.RetainCount
  +
  +// RUN: %clang_analyze_cc1 %s \
  +// RUN:   -analyzer-checker=cplusplus.IteratorModeling \
  +// RUN:   -analyzer-config aggressive-binary-operation-simplification=false \
  +// RUN:   -analyzer-list-enabled-checkers \
  +// RUN:   2>&1 | FileCheck %s -check-prefix=DEPENDENCY-SHOULD-NOT-REGISTER
  +
  +// DEPENDENCY-SHOULD-NOT-REGISTER: 'aggressive-binary-operation-simplification' == false


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75171/new/

https://reviews.llvm.org/D75171





More information about the cfe-commits mailing list