[analyzer] SValBuilder should have an easy access to AnalyzerOptions
`SVB.getStateManager().getOwningEngine().getAnalysisManager().getAnalyzerOptions()` is quite a mouthful and might involve a few pointer indirections to get such a simple thing like an analyzer option. This patch introduces an `AnalyzerOptions` reference to the `SValBuilder` abstract class, while refactors a few cases to use this /simpler/ accessor. Reviewed By: martong, Szelethus Differential Revision: https://reviews.llvm.org/D108824
This commit is contained in:
parent
91c07eb8ee
commit
b97a96400a
|
@ -33,6 +33,7 @@
|
|||
|
||||
namespace clang {
|
||||
|
||||
class AnalyzerOptions;
|
||||
class BlockDecl;
|
||||
class CXXBoolLiteralExpr;
|
||||
class CXXMethodDecl;
|
||||
|
@ -66,6 +67,8 @@ protected:
|
|||
|
||||
ProgramStateManager &StateMgr;
|
||||
|
||||
const AnalyzerOptions &AnOpts;
|
||||
|
||||
/// The scalar type to use for array indices.
|
||||
const QualType ArrayIndexTy;
|
||||
|
||||
|
@ -96,11 +99,7 @@ protected:
|
|||
|
||||
public:
|
||||
SValBuilder(llvm::BumpPtrAllocator &alloc, ASTContext &context,
|
||||
ProgramStateManager &stateMgr)
|
||||
: Context(context), BasicVals(context, alloc),
|
||||
SymMgr(context, BasicVals, alloc), MemMgr(context, alloc),
|
||||
StateMgr(stateMgr), ArrayIndexTy(context.LongLongTy),
|
||||
ArrayIndexWidth(context.getTypeSize(ArrayIndexTy)) {}
|
||||
ProgramStateManager &stateMgr);
|
||||
|
||||
virtual ~SValBuilder() = default;
|
||||
|
||||
|
@ -188,6 +187,8 @@ public:
|
|||
MemRegionManager &getRegionManager() { return MemMgr; }
|
||||
const MemRegionManager &getRegionManager() const { return MemMgr; }
|
||||
|
||||
const AnalyzerOptions &getAnalyzerOptions() const { return AnOpts; }
|
||||
|
||||
// Forwarding methods to SymbolManager.
|
||||
|
||||
const SymbolConjured* conjureSymbol(const Stmt *stmt,
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
#include "clang/Basic/SourceManager.h"
|
||||
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
|
||||
#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicExtent.h"
|
||||
#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
|
||||
#include "clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h"
|
||||
#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
|
||||
#include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h"
|
||||
|
@ -793,11 +792,7 @@ DefinedOrUnknownSVal MemRegionManager::getStaticSize(const MemRegion *MR,
|
|||
if (Size.isNullValue())
|
||||
return true;
|
||||
|
||||
// FIXME: Acquire the AnalyzerOptions in a simpler way.
|
||||
const AnalyzerOptions &Opts = SVB.getStateManager()
|
||||
.getOwningEngine()
|
||||
.getAnalysisManager()
|
||||
.getAnalyzerOptions();
|
||||
const AnalyzerOptions &Opts = SVB.getAnalyzerOptions();
|
||||
if (Opts.ShouldConsiderSingleElementArraysAsFlexibleArrayMembers &&
|
||||
Size.isOneValue())
|
||||
return true;
|
||||
|
|
|
@ -49,6 +49,16 @@ using namespace ento;
|
|||
|
||||
void SValBuilder::anchor() {}
|
||||
|
||||
SValBuilder::SValBuilder(llvm::BumpPtrAllocator &alloc, ASTContext &context,
|
||||
ProgramStateManager &stateMgr)
|
||||
: Context(context), BasicVals(context, alloc),
|
||||
SymMgr(context, BasicVals, alloc), MemMgr(context, alloc),
|
||||
StateMgr(stateMgr),
|
||||
AnOpts(
|
||||
stateMgr.getOwningEngine().getAnalysisManager().getAnalyzerOptions()),
|
||||
ArrayIndexTy(context.LongLongTy),
|
||||
ArrayIndexWidth(context.getTypeSize(ArrayIndexTy)) {}
|
||||
|
||||
DefinedOrUnknownSVal SValBuilder::makeZeroVal(QualType type) {
|
||||
if (Loc::isLocType(type))
|
||||
return makeNull();
|
||||
|
@ -405,9 +415,7 @@ SVal SValBuilder::makeSymExprValNN(BinaryOperator::Opcode Op,
|
|||
|
||||
// TODO: When the Max Complexity is reached, we should conjure a symbol
|
||||
// instead of generating an Unknown value and propagate the taint info to it.
|
||||
const unsigned MaxComp = StateMgr.getOwningEngine()
|
||||
.getAnalysisManager()
|
||||
.options.MaxSymbolComplexity;
|
||||
const unsigned MaxComp = AnOpts.MaxSymbolComplexity;
|
||||
|
||||
if (symLHS && symRHS &&
|
||||
(symLHS->computeComplexity() + symRHS->computeComplexity()) < MaxComp)
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h"
|
||||
#include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
|
||||
#include "clang/StaticAnalyzer/Core/PathSensitive/APSIntType.h"
|
||||
#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
|
||||
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
|
||||
|
@ -25,7 +24,7 @@ class SimpleSValBuilder : public SValBuilder {
|
|||
public:
|
||||
SimpleSValBuilder(llvm::BumpPtrAllocator &alloc, ASTContext &context,
|
||||
ProgramStateManager &stateMgr)
|
||||
: SValBuilder(alloc, context, stateMgr) {}
|
||||
: SValBuilder(alloc, context, stateMgr) {}
|
||||
~SimpleSValBuilder() override {}
|
||||
|
||||
SVal evalMinus(NonLoc val) override;
|
||||
|
@ -320,13 +319,10 @@ static Optional<NonLoc> tryRearrange(ProgramStateRef State,
|
|||
// We expect everything to be of the same type - this type.
|
||||
QualType SingleTy;
|
||||
|
||||
auto &Opts =
|
||||
StateMgr.getOwningEngine().getAnalysisManager().getAnalyzerOptions();
|
||||
|
||||
// FIXME: After putting complexity threshold to the symbols we can always
|
||||
// rearrange additive operations but rearrange comparisons only if
|
||||
// option is set.
|
||||
if(!Opts.ShouldAggressivelySimplifyBinaryOperation)
|
||||
if (!SVB.getAnalyzerOptions().ShouldAggressivelySimplifyBinaryOperation)
|
||||
return None;
|
||||
|
||||
SymbolRef LSym = Lhs.getAsSymbol();
|
||||
|
|
Loading…
Reference in a new issue