2010-12-23 10:42:43 +08:00
|
|
|
//== ArrayBoundCheckerV2.cpp ------------------------------------*- C++ -*--==//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-12-23 10:42:43 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines ArrayBoundCheckerV2, which is a path-sensitive check
|
|
|
|
// which looks for an out-of-bound array element access.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
[analyzer][NFC] Move CheckerRegistry from the Core directory to Frontend
ClangCheckerRegistry is a very non-obvious, poorly documented, weird concept.
It derives from CheckerRegistry, and is placed in lib/StaticAnalyzer/Frontend,
whereas it's base is located in lib/StaticAnalyzer/Core. It was, from what I can
imagine, used to circumvent the problem that the registry functions of the
checkers are located in the clangStaticAnalyzerCheckers library, but that
library depends on clangStaticAnalyzerCore. However, clangStaticAnalyzerFrontend
depends on both of those libraries.
One can make the observation however, that CheckerRegistry has no place in Core,
it isn't used there at all! The only place where it is used is Frontend, which
is where it ultimately belongs.
This move implies that since
include/clang/StaticAnalyzer/Checkers/ClangCheckers.h only contained a single function:
class CheckerRegistry;
void registerBuiltinCheckers(CheckerRegistry ®istry);
it had to re purposed, as CheckerRegistry is no longer available to
clangStaticAnalyzerCheckers. It was renamed to BuiltinCheckerRegistration.h,
which actually describes it a lot better -- it does not contain the registration
functions for checkers, but only those generated by the tblgen files.
Differential Revision: https://reviews.llvm.org/D54436
llvm-svn: 349275
2018-12-16 00:23:51 +08:00
|
|
|
#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/AST/CharUnits.h"
|
|
|
|
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
|
2011-03-01 09:16:21 +08:00
|
|
|
#include "clang/StaticAnalyzer/Core/Checker.h"
|
2011-02-28 09:26:57 +08:00
|
|
|
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
|
2016-08-22 18:07:32 +08:00
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/APSIntType.h"
|
2011-02-28 09:26:57 +08:00
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
|
2011-02-10 09:03:03 +08:00
|
|
|
#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
|
2012-02-04 21:45:25 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2012-12-02 01:12:56 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2010-12-23 10:42:43 +08:00
|
|
|
|
|
|
|
using namespace clang;
|
2010-12-23 15:20:52 +08:00
|
|
|
using namespace ento;
|
2010-12-23 10:42:43 +08:00
|
|
|
|
|
|
|
namespace {
|
2015-09-08 11:50:52 +08:00
|
|
|
class ArrayBoundCheckerV2 :
|
2011-03-01 09:16:21 +08:00
|
|
|
public Checker<check::Location> {
|
2014-03-08 04:03:18 +08:00
|
|
|
mutable std::unique_ptr<BuiltinBug> BT;
|
|
|
|
|
2012-01-21 13:07:33 +08:00
|
|
|
enum OOB_Kind { OOB_Precedes, OOB_Excedes, OOB_Tainted };
|
2015-09-08 11:50:52 +08:00
|
|
|
|
2018-05-02 20:11:22 +08:00
|
|
|
void reportOOB(CheckerContext &C, ProgramStateRef errorState, OOB_Kind kind,
|
|
|
|
std::unique_ptr<BugReporterVisitor> Visitor = nullptr) const;
|
2015-09-08 11:50:52 +08:00
|
|
|
|
2010-12-23 10:42:43 +08:00
|
|
|
public:
|
2011-10-06 08:43:15 +08:00
|
|
|
void checkLocation(SVal l, bool isLoad, const Stmt*S,
|
|
|
|
CheckerContext &C) const;
|
2010-12-23 10:42:43 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// FIXME: Eventually replace RegionRawOffset with this class.
|
|
|
|
class RegionRawOffsetV2 {
|
|
|
|
private:
|
|
|
|
const SubRegion *baseRegion;
|
|
|
|
SVal byteOffset;
|
2014-05-27 10:45:47 +08:00
|
|
|
|
2010-12-23 10:42:43 +08:00
|
|
|
RegionRawOffsetV2()
|
2014-05-27 10:45:47 +08:00
|
|
|
: baseRegion(nullptr), byteOffset(UnknownVal()) {}
|
2010-12-23 10:42:43 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
RegionRawOffsetV2(const SubRegion* base, SVal offset)
|
|
|
|
: baseRegion(base), byteOffset(offset) {}
|
|
|
|
|
2013-02-20 13:52:05 +08:00
|
|
|
NonLoc getByteOffset() const { return byteOffset.castAs<NonLoc>(); }
|
2010-12-23 10:42:43 +08:00
|
|
|
const SubRegion *getRegion() const { return baseRegion; }
|
2015-09-08 11:50:52 +08:00
|
|
|
|
2012-01-27 05:29:00 +08:00
|
|
|
static RegionRawOffsetV2 computeOffset(ProgramStateRef state,
|
2010-12-23 10:42:43 +08:00
|
|
|
SValBuilder &svalBuilder,
|
|
|
|
SVal location);
|
|
|
|
|
|
|
|
void dump() const;
|
2011-08-13 07:37:29 +08:00
|
|
|
void dumpToStream(raw_ostream &os) const;
|
2010-12-23 10:42:43 +08:00
|
|
|
};
|
2015-06-23 07:07:51 +08:00
|
|
|
}
|
2010-12-23 10:42:43 +08:00
|
|
|
|
2015-09-08 11:50:52 +08:00
|
|
|
static SVal computeExtentBegin(SValBuilder &svalBuilder,
|
2011-04-13 01:21:33 +08:00
|
|
|
const MemRegion *region) {
|
2016-09-20 04:39:52 +08:00
|
|
|
const MemSpaceRegion *SR = region->getMemorySpace();
|
|
|
|
if (SR->getKind() == MemRegion::UnknownSpaceRegionKind)
|
|
|
|
return UnknownVal();
|
|
|
|
else
|
|
|
|
return svalBuilder.makeZeroArrayIndex();
|
2011-04-13 01:21:33 +08:00
|
|
|
}
|
|
|
|
|
2016-08-22 18:07:32 +08:00
|
|
|
// TODO: once the constraint manager is smart enough to handle non simplified
|
|
|
|
// symbolic expressions remove this function. Note that this can not be used in
|
|
|
|
// the constraint manager as is, since this does not handle overflows. It is
|
|
|
|
// safe to assume, however, that memory offsets will not overflow.
|
|
|
|
static std::pair<NonLoc, nonloc::ConcreteInt>
|
|
|
|
getSimplifiedOffsets(NonLoc offset, nonloc::ConcreteInt extent,
|
|
|
|
SValBuilder &svalBuilder) {
|
|
|
|
Optional<nonloc::SymbolVal> SymVal = offset.getAs<nonloc::SymbolVal>();
|
|
|
|
if (SymVal && SymVal->isExpression()) {
|
|
|
|
if (const SymIntExpr *SIE = dyn_cast<SymIntExpr>(SymVal->getSymbol())) {
|
|
|
|
llvm::APSInt constant =
|
|
|
|
APSIntType(extent.getValue()).convert(SIE->getRHS());
|
|
|
|
switch (SIE->getOpcode()) {
|
|
|
|
case BO_Mul:
|
|
|
|
// The constant should never be 0 here, since it the result of scaling
|
|
|
|
// based on the size of a type which is never 0.
|
|
|
|
if ((extent.getValue() % constant) != 0)
|
|
|
|
return std::pair<NonLoc, nonloc::ConcreteInt>(offset, extent);
|
|
|
|
else
|
|
|
|
return getSimplifiedOffsets(
|
|
|
|
nonloc::SymbolVal(SIE->getLHS()),
|
|
|
|
svalBuilder.makeIntVal(extent.getValue() / constant),
|
|
|
|
svalBuilder);
|
|
|
|
case BO_Add:
|
|
|
|
return getSimplifiedOffsets(
|
|
|
|
nonloc::SymbolVal(SIE->getLHS()),
|
|
|
|
svalBuilder.makeIntVal(extent.getValue() - constant), svalBuilder);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::pair<NonLoc, nonloc::ConcreteInt>(offset, extent);
|
|
|
|
}
|
|
|
|
|
2011-02-28 09:26:57 +08:00
|
|
|
void ArrayBoundCheckerV2::checkLocation(SVal location, bool isLoad,
|
2011-10-06 08:43:15 +08:00
|
|
|
const Stmt* LoadS,
|
2011-02-28 09:26:57 +08:00
|
|
|
CheckerContext &checkerContext) const {
|
2010-12-23 10:42:43 +08:00
|
|
|
|
2011-08-16 06:09:50 +08:00
|
|
|
// NOTE: Instead of using ProgramState::assumeInBound(), we are prototyping
|
2010-12-23 10:42:43 +08:00
|
|
|
// some new logic here that reasons directly about memory region extents.
|
|
|
|
// Once that logic is more mature, we can bring it back to assumeInBound()
|
|
|
|
// for all clients to use.
|
|
|
|
//
|
|
|
|
// The algorithm we are using here for bounds checking is to see if the
|
|
|
|
// memory access is within the extent of the base region. Since we
|
|
|
|
// have some flexibility in defining the base region, we can achieve
|
|
|
|
// various levels of conservatism in our buffer overflow checking.
|
2015-09-08 11:50:52 +08:00
|
|
|
ProgramStateRef state = checkerContext.getState();
|
2010-12-23 10:42:43 +08:00
|
|
|
|
|
|
|
SValBuilder &svalBuilder = checkerContext.getSValBuilder();
|
2015-09-08 11:50:52 +08:00
|
|
|
const RegionRawOffsetV2 &rawOffset =
|
2010-12-23 10:42:43 +08:00
|
|
|
RegionRawOffsetV2::computeOffset(state, svalBuilder, location);
|
|
|
|
|
|
|
|
if (!rawOffset.getRegion())
|
|
|
|
return;
|
|
|
|
|
2016-08-22 18:07:32 +08:00
|
|
|
NonLoc rawOffsetVal = rawOffset.getByteOffset();
|
|
|
|
|
2015-09-08 11:50:52 +08:00
|
|
|
// CHECK LOWER BOUND: Is byteOffset < extent begin?
|
2011-04-13 01:21:33 +08:00
|
|
|
// If so, we are doing a load/store
|
2010-12-23 10:42:43 +08:00
|
|
|
// before the first valid offset in the memory region.
|
|
|
|
|
2011-04-13 01:21:33 +08:00
|
|
|
SVal extentBegin = computeExtentBegin(svalBuilder, rawOffset.getRegion());
|
2015-09-08 11:50:52 +08:00
|
|
|
|
2013-02-21 06:23:23 +08:00
|
|
|
if (Optional<NonLoc> NV = extentBegin.getAs<NonLoc>()) {
|
2016-08-22 18:07:32 +08:00
|
|
|
if (NV->getAs<nonloc::ConcreteInt>()) {
|
|
|
|
std::pair<NonLoc, nonloc::ConcreteInt> simplifiedOffsets =
|
|
|
|
getSimplifiedOffsets(rawOffset.getByteOffset(),
|
|
|
|
NV->castAs<nonloc::ConcreteInt>(),
|
|
|
|
svalBuilder);
|
|
|
|
rawOffsetVal = simplifiedOffsets.first;
|
|
|
|
*NV = simplifiedOffsets.second;
|
|
|
|
}
|
|
|
|
|
|
|
|
SVal lowerBound = svalBuilder.evalBinOpNN(state, BO_LT, rawOffsetVal, *NV,
|
|
|
|
svalBuilder.getConditionType());
|
2010-12-23 10:42:43 +08:00
|
|
|
|
2013-02-21 06:23:23 +08:00
|
|
|
Optional<NonLoc> lowerBoundToCheck = lowerBound.getAs<NonLoc>();
|
2011-04-13 01:21:33 +08:00
|
|
|
if (!lowerBoundToCheck)
|
|
|
|
return;
|
2015-09-08 11:50:52 +08:00
|
|
|
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef state_precedesLowerBound, state_withinLowerBound;
|
2014-03-02 21:01:17 +08:00
|
|
|
std::tie(state_precedesLowerBound, state_withinLowerBound) =
|
2010-12-23 10:42:43 +08:00
|
|
|
state->assume(*lowerBoundToCheck);
|
|
|
|
|
2011-04-13 01:21:33 +08:00
|
|
|
// Are we constrained enough to definitely precede the lower bound?
|
|
|
|
if (state_precedesLowerBound && !state_withinLowerBound) {
|
|
|
|
reportOOB(checkerContext, state_precedesLowerBound, OOB_Precedes);
|
|
|
|
return;
|
|
|
|
}
|
2015-09-08 11:50:52 +08:00
|
|
|
|
2011-04-13 01:21:33 +08:00
|
|
|
// Otherwise, assume the constraint of the lower bound.
|
|
|
|
assert(state_withinLowerBound);
|
|
|
|
state = state_withinLowerBound;
|
|
|
|
}
|
2015-09-08 11:50:52 +08:00
|
|
|
|
2010-12-23 10:42:43 +08:00
|
|
|
do {
|
|
|
|
// CHECK UPPER BOUND: Is byteOffset >= extent(baseRegion)? If so,
|
|
|
|
// we are doing a load/store after the last valid offset.
|
|
|
|
DefinedOrUnknownSVal extentVal =
|
|
|
|
rawOffset.getRegion()->getExtent(svalBuilder);
|
2013-02-20 13:52:05 +08:00
|
|
|
if (!extentVal.getAs<NonLoc>())
|
2010-12-23 10:42:43 +08:00
|
|
|
break;
|
|
|
|
|
2016-08-22 18:07:32 +08:00
|
|
|
if (extentVal.getAs<nonloc::ConcreteInt>()) {
|
|
|
|
std::pair<NonLoc, nonloc::ConcreteInt> simplifiedOffsets =
|
|
|
|
getSimplifiedOffsets(rawOffset.getByteOffset(),
|
|
|
|
extentVal.castAs<nonloc::ConcreteInt>(),
|
|
|
|
svalBuilder);
|
|
|
|
rawOffsetVal = simplifiedOffsets.first;
|
|
|
|
extentVal = simplifiedOffsets.second;
|
|
|
|
}
|
|
|
|
|
|
|
|
SVal upperbound = svalBuilder.evalBinOpNN(state, BO_GE, rawOffsetVal,
|
|
|
|
extentVal.castAs<NonLoc>(),
|
|
|
|
svalBuilder.getConditionType());
|
2015-09-08 11:50:52 +08:00
|
|
|
|
2013-02-21 06:23:23 +08:00
|
|
|
Optional<NonLoc> upperboundToCheck = upperbound.getAs<NonLoc>();
|
2010-12-23 10:42:43 +08:00
|
|
|
if (!upperboundToCheck)
|
|
|
|
break;
|
2015-09-08 11:50:52 +08:00
|
|
|
|
2012-01-27 05:29:00 +08:00
|
|
|
ProgramStateRef state_exceedsUpperBound, state_withinUpperBound;
|
2014-03-02 21:01:17 +08:00
|
|
|
std::tie(state_exceedsUpperBound, state_withinUpperBound) =
|
2010-12-23 10:42:43 +08:00
|
|
|
state->assume(*upperboundToCheck);
|
2011-11-17 03:58:17 +08:00
|
|
|
|
|
|
|
// If we are under constrained and the index variables are tainted, report.
|
|
|
|
if (state_exceedsUpperBound && state_withinUpperBound) {
|
2018-05-02 20:11:22 +08:00
|
|
|
SVal ByteOffset = rawOffset.getByteOffset();
|
|
|
|
if (state->isTainted(ByteOffset)) {
|
|
|
|
reportOOB(checkerContext, state_exceedsUpperBound, OOB_Tainted,
|
|
|
|
llvm::make_unique<TaintBugVisitor>(ByteOffset));
|
2011-11-17 03:58:17 +08:00
|
|
|
return;
|
2016-08-22 18:07:32 +08:00
|
|
|
}
|
|
|
|
} else if (state_exceedsUpperBound) {
|
|
|
|
// If we are constrained enough to definitely exceed the upper bound,
|
|
|
|
// report.
|
2011-11-17 03:58:17 +08:00
|
|
|
assert(!state_withinUpperBound);
|
2010-12-23 10:42:43 +08:00
|
|
|
reportOOB(checkerContext, state_exceedsUpperBound, OOB_Excedes);
|
|
|
|
return;
|
|
|
|
}
|
2015-09-08 11:50:52 +08:00
|
|
|
|
2010-12-23 10:42:43 +08:00
|
|
|
assert(state_withinUpperBound);
|
|
|
|
state = state_withinUpperBound;
|
|
|
|
}
|
|
|
|
while (false);
|
2015-09-08 11:50:52 +08:00
|
|
|
|
2018-05-30 19:46:45 +08:00
|
|
|
checkerContext.addTransition(state);
|
2010-12-23 10:42:43 +08:00
|
|
|
}
|
|
|
|
|
2018-05-02 20:11:22 +08:00
|
|
|
void ArrayBoundCheckerV2::reportOOB(
|
|
|
|
CheckerContext &checkerContext, ProgramStateRef errorState, OOB_Kind kind,
|
|
|
|
std::unique_ptr<BugReporterVisitor> Visitor) const {
|
2015-09-08 11:50:52 +08:00
|
|
|
|
2015-09-17 06:03:05 +08:00
|
|
|
ExplodedNode *errorNode = checkerContext.generateErrorNode(errorState);
|
2010-12-23 10:42:43 +08:00
|
|
|
if (!errorNode)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!BT)
|
2014-02-12 05:49:21 +08:00
|
|
|
BT.reset(new BuiltinBug(this, "Out-of-bound access"));
|
2010-12-23 10:42:43 +08:00
|
|
|
|
|
|
|
// FIXME: This diagnostics are preliminary. We should get far better
|
|
|
|
// diagnostics for explaining buffer overruns.
|
|
|
|
|
2012-02-05 10:13:05 +08:00
|
|
|
SmallString<256> buf;
|
2010-12-23 10:42:43 +08:00
|
|
|
llvm::raw_svector_ostream os(buf);
|
2012-01-21 13:07:33 +08:00
|
|
|
os << "Out of bound memory access ";
|
|
|
|
switch (kind) {
|
|
|
|
case OOB_Precedes:
|
|
|
|
os << "(accessed memory precedes memory block)";
|
|
|
|
break;
|
|
|
|
case OOB_Excedes:
|
|
|
|
os << "(access exceeds upper limit of memory block)";
|
|
|
|
break;
|
|
|
|
case OOB_Tainted:
|
|
|
|
os << "(index is tainted)";
|
|
|
|
break;
|
|
|
|
}
|
2010-12-23 10:42:43 +08:00
|
|
|
|
2018-05-02 20:11:22 +08:00
|
|
|
auto BR = llvm::make_unique<BugReport>(*BT, os.str(), errorNode);
|
|
|
|
BR->addVisitor(std::move(Visitor));
|
|
|
|
checkerContext.emitReport(std::move(BR));
|
2010-12-23 10:42:43 +08:00
|
|
|
}
|
|
|
|
|
2017-11-16 11:18:09 +08:00
|
|
|
#ifndef NDEBUG
|
2016-01-30 03:38:18 +08:00
|
|
|
LLVM_DUMP_METHOD void RegionRawOffsetV2::dump() const {
|
2010-12-23 10:42:43 +08:00
|
|
|
dumpToStream(llvm::errs());
|
|
|
|
}
|
|
|
|
|
2011-08-13 07:37:29 +08:00
|
|
|
void RegionRawOffsetV2::dumpToStream(raw_ostream &os) const {
|
2010-12-23 10:42:43 +08:00
|
|
|
os << "raw_offset_v2{" << getRegion() << ',' << getByteOffset() << '}';
|
|
|
|
}
|
2017-11-16 11:18:09 +08:00
|
|
|
#endif
|
2010-12-23 10:42:43 +08:00
|
|
|
|
|
|
|
// Lazily computes a value to be used by 'computeOffset'. If 'val'
|
|
|
|
// is unknown or undefined, we lazily substitute '0'. Otherwise,
|
|
|
|
// return 'val'.
|
|
|
|
static inline SVal getValue(SVal val, SValBuilder &svalBuilder) {
|
2013-02-20 13:52:05 +08:00
|
|
|
return val.getAs<UndefinedVal>() ? svalBuilder.makeArrayIndex(0) : val;
|
2010-12-23 10:42:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Scale a base value by a scaling factor, and return the scaled
|
|
|
|
// value as an SVal. Used by 'computeOffset'.
|
2012-01-27 05:29:00 +08:00
|
|
|
static inline SVal scaleValue(ProgramStateRef state,
|
2010-12-23 10:42:43 +08:00
|
|
|
NonLoc baseVal, CharUnits scaling,
|
|
|
|
SValBuilder &sb) {
|
|
|
|
return sb.evalBinOpNN(state, BO_Mul, baseVal,
|
|
|
|
sb.makeArrayIndex(scaling.getQuantity()),
|
|
|
|
sb.getArrayIndexType());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add an SVal to another, treating unknown and undefined values as
|
|
|
|
// summing to UnknownVal. Used by 'computeOffset'.
|
2012-01-27 05:29:00 +08:00
|
|
|
static SVal addValue(ProgramStateRef state, SVal x, SVal y,
|
2010-12-23 10:42:43 +08:00
|
|
|
SValBuilder &svalBuilder) {
|
|
|
|
// We treat UnknownVals and UndefinedVals the same here because we
|
|
|
|
// only care about computing offsets.
|
|
|
|
if (x.isUnknownOrUndef() || y.isUnknownOrUndef())
|
|
|
|
return UnknownVal();
|
2013-02-20 13:52:05 +08:00
|
|
|
|
|
|
|
return svalBuilder.evalBinOpNN(state, BO_Add, x.castAs<NonLoc>(),
|
|
|
|
y.castAs<NonLoc>(),
|
2010-12-23 10:42:43 +08:00
|
|
|
svalBuilder.getArrayIndexType());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Compute a raw byte offset from a base region. Used for array bounds
|
|
|
|
/// checking.
|
2012-01-27 05:29:00 +08:00
|
|
|
RegionRawOffsetV2 RegionRawOffsetV2::computeOffset(ProgramStateRef state,
|
2010-12-23 10:42:43 +08:00
|
|
|
SValBuilder &svalBuilder,
|
|
|
|
SVal location)
|
|
|
|
{
|
|
|
|
const MemRegion *region = location.getAsRegion();
|
|
|
|
SVal offset = UndefinedVal();
|
2015-09-08 11:50:52 +08:00
|
|
|
|
2010-12-23 10:42:43 +08:00
|
|
|
while (region) {
|
|
|
|
switch (region->getKind()) {
|
|
|
|
default: {
|
2011-04-13 01:21:33 +08:00
|
|
|
if (const SubRegion *subReg = dyn_cast<SubRegion>(region)) {
|
|
|
|
offset = getValue(offset, svalBuilder);
|
2010-12-23 10:42:43 +08:00
|
|
|
if (!offset.isUnknownOrUndef())
|
|
|
|
return RegionRawOffsetV2(subReg, offset);
|
2011-04-13 01:21:33 +08:00
|
|
|
}
|
2010-12-23 10:42:43 +08:00
|
|
|
return RegionRawOffsetV2();
|
|
|
|
}
|
|
|
|
case MemRegion::ElementRegionKind: {
|
|
|
|
const ElementRegion *elemReg = cast<ElementRegion>(region);
|
|
|
|
SVal index = elemReg->getIndex();
|
2013-02-20 13:52:05 +08:00
|
|
|
if (!index.getAs<NonLoc>())
|
2010-12-23 10:42:43 +08:00
|
|
|
return RegionRawOffsetV2();
|
|
|
|
QualType elemType = elemReg->getElementType();
|
|
|
|
// If the element is an incomplete type, go no further.
|
|
|
|
ASTContext &astContext = svalBuilder.getContext();
|
2014-10-04 05:49:03 +08:00
|
|
|
if (elemType->isIncompleteType())
|
2010-12-23 10:42:43 +08:00
|
|
|
return RegionRawOffsetV2();
|
2015-09-08 11:50:52 +08:00
|
|
|
|
2010-12-23 10:42:43 +08:00
|
|
|
// Update the offset.
|
|
|
|
offset = addValue(state,
|
|
|
|
getValue(offset, svalBuilder),
|
|
|
|
scaleValue(state,
|
2013-02-20 13:52:05 +08:00
|
|
|
index.castAs<NonLoc>(),
|
2011-11-17 03:58:17 +08:00
|
|
|
astContext.getTypeSizeInChars(elemType),
|
|
|
|
svalBuilder),
|
2010-12-23 10:42:43 +08:00
|
|
|
svalBuilder);
|
|
|
|
|
|
|
|
if (offset.isUnknownOrUndef())
|
|
|
|
return RegionRawOffsetV2();
|
|
|
|
|
|
|
|
region = elemReg->getSuperRegion();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return RegionRawOffsetV2();
|
|
|
|
}
|
|
|
|
|
2011-02-28 09:26:57 +08:00
|
|
|
void ento::registerArrayBoundCheckerV2(CheckerManager &mgr) {
|
|
|
|
mgr.registerChecker<ArrayBoundCheckerV2>();
|
|
|
|
}
|
2019-01-26 22:23:08 +08:00
|
|
|
|
|
|
|
bool ento::shouldRegisterArrayBoundCheckerV2(const LangOptions &LO) {
|
|
|
|
return true;
|
|
|
|
}
|