xref: /openbsd-src/gnu/llvm/clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp (revision 12c855180aad702bbcca06e0398d774beeafb155)
1e5dd7070Spatrick //== ArrayBoundCheckerV2.cpp ------------------------------------*- C++ -*--==//
2e5dd7070Spatrick //
3e5dd7070Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4e5dd7070Spatrick // See https://llvm.org/LICENSE.txt for license information.
5e5dd7070Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6e5dd7070Spatrick //
7e5dd7070Spatrick //===----------------------------------------------------------------------===//
8e5dd7070Spatrick //
9e5dd7070Spatrick // This file defines ArrayBoundCheckerV2, which is a path-sensitive check
10e5dd7070Spatrick // which looks for an out-of-bound array element access.
11e5dd7070Spatrick //
12e5dd7070Spatrick //===----------------------------------------------------------------------===//
13e5dd7070Spatrick 
14e5dd7070Spatrick #include "clang/AST/CharUnits.h"
15ec727ea7Spatrick #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
16*12c85518Srobert #include "clang/StaticAnalyzer/Checkers/Taint.h"
17e5dd7070Spatrick #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
18e5dd7070Spatrick #include "clang/StaticAnalyzer/Core/Checker.h"
19e5dd7070Spatrick #include "clang/StaticAnalyzer/Core/CheckerManager.h"
20e5dd7070Spatrick #include "clang/StaticAnalyzer/Core/PathSensitive/APSIntType.h"
21e5dd7070Spatrick #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
22a9ac8606Spatrick #include "clang/StaticAnalyzer/Core/PathSensitive/DynamicExtent.h"
23e5dd7070Spatrick #include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
24e5dd7070Spatrick #include "llvm/ADT/SmallString.h"
25e5dd7070Spatrick #include "llvm/Support/raw_ostream.h"
26*12c85518Srobert #include <optional>
27e5dd7070Spatrick 
28e5dd7070Spatrick using namespace clang;
29e5dd7070Spatrick using namespace ento;
30e5dd7070Spatrick using namespace taint;
31e5dd7070Spatrick 
32e5dd7070Spatrick namespace {
33e5dd7070Spatrick class ArrayBoundCheckerV2 :
34e5dd7070Spatrick     public Checker<check::Location> {
35e5dd7070Spatrick   mutable std::unique_ptr<BuiltinBug> BT;
36e5dd7070Spatrick 
37e5dd7070Spatrick   enum OOB_Kind { OOB_Precedes, OOB_Excedes, OOB_Tainted };
38e5dd7070Spatrick 
39e5dd7070Spatrick   void reportOOB(CheckerContext &C, ProgramStateRef errorState, OOB_Kind kind,
40e5dd7070Spatrick                  std::unique_ptr<BugReporterVisitor> Visitor = nullptr) const;
41e5dd7070Spatrick 
42e5dd7070Spatrick public:
43e5dd7070Spatrick   void checkLocation(SVal l, bool isLoad, const Stmt*S,
44e5dd7070Spatrick                      CheckerContext &C) const;
45e5dd7070Spatrick };
46e5dd7070Spatrick 
47e5dd7070Spatrick // FIXME: Eventually replace RegionRawOffset with this class.
48e5dd7070Spatrick class RegionRawOffsetV2 {
49e5dd7070Spatrick private:
50e5dd7070Spatrick   const SubRegion *baseRegion;
51e5dd7070Spatrick   SVal byteOffset;
52e5dd7070Spatrick 
RegionRawOffsetV2()53e5dd7070Spatrick   RegionRawOffsetV2()
54e5dd7070Spatrick     : baseRegion(nullptr), byteOffset(UnknownVal()) {}
55e5dd7070Spatrick 
56e5dd7070Spatrick public:
RegionRawOffsetV2(const SubRegion * base,SVal offset)57e5dd7070Spatrick   RegionRawOffsetV2(const SubRegion* base, SVal offset)
58e5dd7070Spatrick     : baseRegion(base), byteOffset(offset) {}
59e5dd7070Spatrick 
getByteOffset() const60e5dd7070Spatrick   NonLoc getByteOffset() const { return byteOffset.castAs<NonLoc>(); }
getRegion() const61e5dd7070Spatrick   const SubRegion *getRegion() const { return baseRegion; }
62e5dd7070Spatrick 
63e5dd7070Spatrick   static RegionRawOffsetV2 computeOffset(ProgramStateRef state,
64e5dd7070Spatrick                                          SValBuilder &svalBuilder,
65e5dd7070Spatrick                                          SVal location);
66e5dd7070Spatrick 
67e5dd7070Spatrick   void dump() const;
68e5dd7070Spatrick   void dumpToStream(raw_ostream &os) const;
69e5dd7070Spatrick };
70e5dd7070Spatrick }
71e5dd7070Spatrick 
computeExtentBegin(SValBuilder & svalBuilder,const MemRegion * region)72e5dd7070Spatrick static SVal computeExtentBegin(SValBuilder &svalBuilder,
73e5dd7070Spatrick                                const MemRegion *region) {
74e5dd7070Spatrick   const MemSpaceRegion *SR = region->getMemorySpace();
75e5dd7070Spatrick   if (SR->getKind() == MemRegion::UnknownSpaceRegionKind)
76e5dd7070Spatrick     return UnknownVal();
77e5dd7070Spatrick   else
78e5dd7070Spatrick     return svalBuilder.makeZeroArrayIndex();
79e5dd7070Spatrick }
80e5dd7070Spatrick 
81e5dd7070Spatrick // TODO: once the constraint manager is smart enough to handle non simplified
82e5dd7070Spatrick // symbolic expressions remove this function. Note that this can not be used in
83e5dd7070Spatrick // the constraint manager as is, since this does not handle overflows. It is
84e5dd7070Spatrick // safe to assume, however, that memory offsets will not overflow.
85e5dd7070Spatrick static std::pair<NonLoc, nonloc::ConcreteInt>
getSimplifiedOffsets(NonLoc offset,nonloc::ConcreteInt extent,SValBuilder & svalBuilder)86e5dd7070Spatrick getSimplifiedOffsets(NonLoc offset, nonloc::ConcreteInt extent,
87e5dd7070Spatrick                      SValBuilder &svalBuilder) {
88*12c85518Srobert   std::optional<nonloc::SymbolVal> SymVal = offset.getAs<nonloc::SymbolVal>();
89e5dd7070Spatrick   if (SymVal && SymVal->isExpression()) {
90e5dd7070Spatrick     if (const SymIntExpr *SIE = dyn_cast<SymIntExpr>(SymVal->getSymbol())) {
91e5dd7070Spatrick       llvm::APSInt constant =
92e5dd7070Spatrick           APSIntType(extent.getValue()).convert(SIE->getRHS());
93e5dd7070Spatrick       switch (SIE->getOpcode()) {
94e5dd7070Spatrick       case BO_Mul:
95e5dd7070Spatrick         // The constant should never be 0 here, since it the result of scaling
96e5dd7070Spatrick         // based on the size of a type which is never 0.
97e5dd7070Spatrick         if ((extent.getValue() % constant) != 0)
98e5dd7070Spatrick           return std::pair<NonLoc, nonloc::ConcreteInt>(offset, extent);
99e5dd7070Spatrick         else
100e5dd7070Spatrick           return getSimplifiedOffsets(
101e5dd7070Spatrick               nonloc::SymbolVal(SIE->getLHS()),
102e5dd7070Spatrick               svalBuilder.makeIntVal(extent.getValue() / constant),
103e5dd7070Spatrick               svalBuilder);
104e5dd7070Spatrick       case BO_Add:
105e5dd7070Spatrick         return getSimplifiedOffsets(
106e5dd7070Spatrick             nonloc::SymbolVal(SIE->getLHS()),
107e5dd7070Spatrick             svalBuilder.makeIntVal(extent.getValue() - constant), svalBuilder);
108e5dd7070Spatrick       default:
109e5dd7070Spatrick         break;
110e5dd7070Spatrick       }
111e5dd7070Spatrick     }
112e5dd7070Spatrick   }
113e5dd7070Spatrick 
114e5dd7070Spatrick   return std::pair<NonLoc, nonloc::ConcreteInt>(offset, extent);
115e5dd7070Spatrick }
116e5dd7070Spatrick 
checkLocation(SVal location,bool isLoad,const Stmt * LoadS,CheckerContext & checkerContext) const117e5dd7070Spatrick void ArrayBoundCheckerV2::checkLocation(SVal location, bool isLoad,
118e5dd7070Spatrick                                         const Stmt* LoadS,
119e5dd7070Spatrick                                         CheckerContext &checkerContext) const {
120e5dd7070Spatrick 
121e5dd7070Spatrick   // NOTE: Instead of using ProgramState::assumeInBound(), we are prototyping
122e5dd7070Spatrick   // some new logic here that reasons directly about memory region extents.
123e5dd7070Spatrick   // Once that logic is more mature, we can bring it back to assumeInBound()
124e5dd7070Spatrick   // for all clients to use.
125e5dd7070Spatrick   //
126e5dd7070Spatrick   // The algorithm we are using here for bounds checking is to see if the
127e5dd7070Spatrick   // memory access is within the extent of the base region.  Since we
128e5dd7070Spatrick   // have some flexibility in defining the base region, we can achieve
129e5dd7070Spatrick   // various levels of conservatism in our buffer overflow checking.
130e5dd7070Spatrick   ProgramStateRef state = checkerContext.getState();
131e5dd7070Spatrick 
132e5dd7070Spatrick   SValBuilder &svalBuilder = checkerContext.getSValBuilder();
133e5dd7070Spatrick   const RegionRawOffsetV2 &rawOffset =
134e5dd7070Spatrick     RegionRawOffsetV2::computeOffset(state, svalBuilder, location);
135e5dd7070Spatrick 
136e5dd7070Spatrick   if (!rawOffset.getRegion())
137e5dd7070Spatrick     return;
138e5dd7070Spatrick 
139e5dd7070Spatrick   NonLoc rawOffsetVal = rawOffset.getByteOffset();
140e5dd7070Spatrick 
141e5dd7070Spatrick   // CHECK LOWER BOUND: Is byteOffset < extent begin?
142e5dd7070Spatrick   //  If so, we are doing a load/store
143e5dd7070Spatrick   //  before the first valid offset in the memory region.
144e5dd7070Spatrick 
145e5dd7070Spatrick   SVal extentBegin = computeExtentBegin(svalBuilder, rawOffset.getRegion());
146e5dd7070Spatrick 
147*12c85518Srobert   if (std::optional<NonLoc> NV = extentBegin.getAs<NonLoc>()) {
148*12c85518Srobert     if (auto ConcreteNV = NV->getAs<nonloc::ConcreteInt>()) {
149e5dd7070Spatrick       std::pair<NonLoc, nonloc::ConcreteInt> simplifiedOffsets =
150*12c85518Srobert           getSimplifiedOffsets(rawOffset.getByteOffset(), *ConcreteNV,
151e5dd7070Spatrick                                svalBuilder);
152e5dd7070Spatrick       rawOffsetVal = simplifiedOffsets.first;
153e5dd7070Spatrick       *NV = simplifiedOffsets.second;
154e5dd7070Spatrick     }
155e5dd7070Spatrick 
156e5dd7070Spatrick     SVal lowerBound = svalBuilder.evalBinOpNN(state, BO_LT, rawOffsetVal, *NV,
157e5dd7070Spatrick                                               svalBuilder.getConditionType());
158e5dd7070Spatrick 
159*12c85518Srobert     std::optional<NonLoc> lowerBoundToCheck = lowerBound.getAs<NonLoc>();
160e5dd7070Spatrick     if (!lowerBoundToCheck)
161e5dd7070Spatrick       return;
162e5dd7070Spatrick 
163e5dd7070Spatrick     ProgramStateRef state_precedesLowerBound, state_withinLowerBound;
164e5dd7070Spatrick     std::tie(state_precedesLowerBound, state_withinLowerBound) =
165e5dd7070Spatrick       state->assume(*lowerBoundToCheck);
166e5dd7070Spatrick 
167e5dd7070Spatrick     // Are we constrained enough to definitely precede the lower bound?
168e5dd7070Spatrick     if (state_precedesLowerBound && !state_withinLowerBound) {
169e5dd7070Spatrick       reportOOB(checkerContext, state_precedesLowerBound, OOB_Precedes);
170e5dd7070Spatrick       return;
171e5dd7070Spatrick     }
172e5dd7070Spatrick 
173e5dd7070Spatrick     // Otherwise, assume the constraint of the lower bound.
174e5dd7070Spatrick     assert(state_withinLowerBound);
175e5dd7070Spatrick     state = state_withinLowerBound;
176e5dd7070Spatrick   }
177e5dd7070Spatrick 
178e5dd7070Spatrick   do {
179ec727ea7Spatrick     // CHECK UPPER BOUND: Is byteOffset >= size(baseRegion)?  If so,
180e5dd7070Spatrick     // we are doing a load/store after the last valid offset.
181ec727ea7Spatrick     const MemRegion *MR = rawOffset.getRegion();
182a9ac8606Spatrick     DefinedOrUnknownSVal Size = getDynamicExtent(state, MR, svalBuilder);
183*12c85518Srobert     if (!isa<NonLoc>(Size))
184e5dd7070Spatrick       break;
185e5dd7070Spatrick 
186*12c85518Srobert     if (auto ConcreteSize = Size.getAs<nonloc::ConcreteInt>()) {
187e5dd7070Spatrick       std::pair<NonLoc, nonloc::ConcreteInt> simplifiedOffsets =
188*12c85518Srobert           getSimplifiedOffsets(rawOffset.getByteOffset(), *ConcreteSize,
189*12c85518Srobert                                svalBuilder);
190e5dd7070Spatrick       rawOffsetVal = simplifiedOffsets.first;
191ec727ea7Spatrick       Size = simplifiedOffsets.second;
192e5dd7070Spatrick     }
193e5dd7070Spatrick 
194e5dd7070Spatrick     SVal upperbound = svalBuilder.evalBinOpNN(state, BO_GE, rawOffsetVal,
195ec727ea7Spatrick                                               Size.castAs<NonLoc>(),
196e5dd7070Spatrick                                               svalBuilder.getConditionType());
197e5dd7070Spatrick 
198*12c85518Srobert     std::optional<NonLoc> upperboundToCheck = upperbound.getAs<NonLoc>();
199e5dd7070Spatrick     if (!upperboundToCheck)
200e5dd7070Spatrick       break;
201e5dd7070Spatrick 
202e5dd7070Spatrick     ProgramStateRef state_exceedsUpperBound, state_withinUpperBound;
203e5dd7070Spatrick     std::tie(state_exceedsUpperBound, state_withinUpperBound) =
204e5dd7070Spatrick       state->assume(*upperboundToCheck);
205e5dd7070Spatrick 
206e5dd7070Spatrick     // If we are under constrained and the index variables are tainted, report.
207e5dd7070Spatrick     if (state_exceedsUpperBound && state_withinUpperBound) {
208e5dd7070Spatrick       SVal ByteOffset = rawOffset.getByteOffset();
209e5dd7070Spatrick       if (isTainted(state, ByteOffset)) {
210e5dd7070Spatrick         reportOOB(checkerContext, state_exceedsUpperBound, OOB_Tainted,
211e5dd7070Spatrick                   std::make_unique<TaintBugVisitor>(ByteOffset));
212e5dd7070Spatrick         return;
213e5dd7070Spatrick       }
214e5dd7070Spatrick     } else if (state_exceedsUpperBound) {
215e5dd7070Spatrick       // If we are constrained enough to definitely exceed the upper bound,
216e5dd7070Spatrick       // report.
217e5dd7070Spatrick       assert(!state_withinUpperBound);
218e5dd7070Spatrick       reportOOB(checkerContext, state_exceedsUpperBound, OOB_Excedes);
219e5dd7070Spatrick       return;
220e5dd7070Spatrick     }
221e5dd7070Spatrick 
222e5dd7070Spatrick     assert(state_withinUpperBound);
223e5dd7070Spatrick     state = state_withinUpperBound;
224e5dd7070Spatrick   }
225e5dd7070Spatrick   while (false);
226e5dd7070Spatrick 
227e5dd7070Spatrick   checkerContext.addTransition(state);
228e5dd7070Spatrick }
229e5dd7070Spatrick 
reportOOB(CheckerContext & checkerContext,ProgramStateRef errorState,OOB_Kind kind,std::unique_ptr<BugReporterVisitor> Visitor) const230e5dd7070Spatrick void ArrayBoundCheckerV2::reportOOB(
231e5dd7070Spatrick     CheckerContext &checkerContext, ProgramStateRef errorState, OOB_Kind kind,
232e5dd7070Spatrick     std::unique_ptr<BugReporterVisitor> Visitor) const {
233e5dd7070Spatrick 
234e5dd7070Spatrick   ExplodedNode *errorNode = checkerContext.generateErrorNode(errorState);
235e5dd7070Spatrick   if (!errorNode)
236e5dd7070Spatrick     return;
237e5dd7070Spatrick 
238e5dd7070Spatrick   if (!BT)
239e5dd7070Spatrick     BT.reset(new BuiltinBug(this, "Out-of-bound access"));
240e5dd7070Spatrick 
241e5dd7070Spatrick   // FIXME: This diagnostics are preliminary.  We should get far better
242e5dd7070Spatrick   // diagnostics for explaining buffer overruns.
243e5dd7070Spatrick 
244e5dd7070Spatrick   SmallString<256> buf;
245e5dd7070Spatrick   llvm::raw_svector_ostream os(buf);
246e5dd7070Spatrick   os << "Out of bound memory access ";
247e5dd7070Spatrick   switch (kind) {
248e5dd7070Spatrick   case OOB_Precedes:
249e5dd7070Spatrick     os << "(accessed memory precedes memory block)";
250e5dd7070Spatrick     break;
251e5dd7070Spatrick   case OOB_Excedes:
252e5dd7070Spatrick     os << "(access exceeds upper limit of memory block)";
253e5dd7070Spatrick     break;
254e5dd7070Spatrick   case OOB_Tainted:
255e5dd7070Spatrick     os << "(index is tainted)";
256e5dd7070Spatrick     break;
257e5dd7070Spatrick   }
258e5dd7070Spatrick 
259e5dd7070Spatrick   auto BR = std::make_unique<PathSensitiveBugReport>(*BT, os.str(), errorNode);
260e5dd7070Spatrick   BR->addVisitor(std::move(Visitor));
261e5dd7070Spatrick   checkerContext.emitReport(std::move(BR));
262e5dd7070Spatrick }
263e5dd7070Spatrick 
264e5dd7070Spatrick #ifndef NDEBUG
dump() const265e5dd7070Spatrick LLVM_DUMP_METHOD void RegionRawOffsetV2::dump() const {
266e5dd7070Spatrick   dumpToStream(llvm::errs());
267e5dd7070Spatrick }
268e5dd7070Spatrick 
dumpToStream(raw_ostream & os) const269e5dd7070Spatrick void RegionRawOffsetV2::dumpToStream(raw_ostream &os) const {
270e5dd7070Spatrick   os << "raw_offset_v2{" << getRegion() << ',' << getByteOffset() << '}';
271e5dd7070Spatrick }
272e5dd7070Spatrick #endif
273e5dd7070Spatrick 
274e5dd7070Spatrick // Lazily computes a value to be used by 'computeOffset'.  If 'val'
275e5dd7070Spatrick // is unknown or undefined, we lazily substitute '0'.  Otherwise,
276e5dd7070Spatrick // return 'val'.
getValue(SVal val,SValBuilder & svalBuilder)277e5dd7070Spatrick static inline SVal getValue(SVal val, SValBuilder &svalBuilder) {
278*12c85518Srobert   return val.isUndef() ? svalBuilder.makeZeroArrayIndex() : val;
279e5dd7070Spatrick }
280e5dd7070Spatrick 
281e5dd7070Spatrick // Scale a base value by a scaling factor, and return the scaled
282e5dd7070Spatrick // value as an SVal.  Used by 'computeOffset'.
scaleValue(ProgramStateRef state,NonLoc baseVal,CharUnits scaling,SValBuilder & sb)283e5dd7070Spatrick static inline SVal scaleValue(ProgramStateRef state,
284e5dd7070Spatrick                               NonLoc baseVal, CharUnits scaling,
285e5dd7070Spatrick                               SValBuilder &sb) {
286e5dd7070Spatrick   return sb.evalBinOpNN(state, BO_Mul, baseVal,
287e5dd7070Spatrick                         sb.makeArrayIndex(scaling.getQuantity()),
288e5dd7070Spatrick                         sb.getArrayIndexType());
289e5dd7070Spatrick }
290e5dd7070Spatrick 
291e5dd7070Spatrick // Add an SVal to another, treating unknown and undefined values as
292e5dd7070Spatrick // summing to UnknownVal.  Used by 'computeOffset'.
addValue(ProgramStateRef state,SVal x,SVal y,SValBuilder & svalBuilder)293e5dd7070Spatrick static SVal addValue(ProgramStateRef state, SVal x, SVal y,
294e5dd7070Spatrick                      SValBuilder &svalBuilder) {
295e5dd7070Spatrick   // We treat UnknownVals and UndefinedVals the same here because we
296e5dd7070Spatrick   // only care about computing offsets.
297e5dd7070Spatrick   if (x.isUnknownOrUndef() || y.isUnknownOrUndef())
298e5dd7070Spatrick     return UnknownVal();
299e5dd7070Spatrick 
300e5dd7070Spatrick   return svalBuilder.evalBinOpNN(state, BO_Add, x.castAs<NonLoc>(),
301e5dd7070Spatrick                                  y.castAs<NonLoc>(),
302e5dd7070Spatrick                                  svalBuilder.getArrayIndexType());
303e5dd7070Spatrick }
304e5dd7070Spatrick 
305e5dd7070Spatrick /// Compute a raw byte offset from a base region.  Used for array bounds
306e5dd7070Spatrick /// checking.
computeOffset(ProgramStateRef state,SValBuilder & svalBuilder,SVal location)307e5dd7070Spatrick RegionRawOffsetV2 RegionRawOffsetV2::computeOffset(ProgramStateRef state,
308e5dd7070Spatrick                                                    SValBuilder &svalBuilder,
309e5dd7070Spatrick                                                    SVal location)
310e5dd7070Spatrick {
311e5dd7070Spatrick   const MemRegion *region = location.getAsRegion();
312e5dd7070Spatrick   SVal offset = UndefinedVal();
313e5dd7070Spatrick 
314e5dd7070Spatrick   while (region) {
315e5dd7070Spatrick     switch (region->getKind()) {
316e5dd7070Spatrick       default: {
317e5dd7070Spatrick         if (const SubRegion *subReg = dyn_cast<SubRegion>(region)) {
318e5dd7070Spatrick           offset = getValue(offset, svalBuilder);
319e5dd7070Spatrick           if (!offset.isUnknownOrUndef())
320e5dd7070Spatrick             return RegionRawOffsetV2(subReg, offset);
321e5dd7070Spatrick         }
322e5dd7070Spatrick         return RegionRawOffsetV2();
323e5dd7070Spatrick       }
324e5dd7070Spatrick       case MemRegion::ElementRegionKind: {
325e5dd7070Spatrick         const ElementRegion *elemReg = cast<ElementRegion>(region);
326e5dd7070Spatrick         SVal index = elemReg->getIndex();
327*12c85518Srobert         if (!isa<NonLoc>(index))
328e5dd7070Spatrick           return RegionRawOffsetV2();
329e5dd7070Spatrick         QualType elemType = elemReg->getElementType();
330e5dd7070Spatrick         // If the element is an incomplete type, go no further.
331e5dd7070Spatrick         ASTContext &astContext = svalBuilder.getContext();
332e5dd7070Spatrick         if (elemType->isIncompleteType())
333e5dd7070Spatrick           return RegionRawOffsetV2();
334e5dd7070Spatrick 
335e5dd7070Spatrick         // Update the offset.
336e5dd7070Spatrick         offset = addValue(state,
337e5dd7070Spatrick                           getValue(offset, svalBuilder),
338e5dd7070Spatrick                           scaleValue(state,
339e5dd7070Spatrick                           index.castAs<NonLoc>(),
340e5dd7070Spatrick                           astContext.getTypeSizeInChars(elemType),
341e5dd7070Spatrick                           svalBuilder),
342e5dd7070Spatrick                           svalBuilder);
343e5dd7070Spatrick 
344e5dd7070Spatrick         if (offset.isUnknownOrUndef())
345e5dd7070Spatrick           return RegionRawOffsetV2();
346e5dd7070Spatrick 
347e5dd7070Spatrick         region = elemReg->getSuperRegion();
348e5dd7070Spatrick         continue;
349e5dd7070Spatrick       }
350e5dd7070Spatrick     }
351e5dd7070Spatrick   }
352e5dd7070Spatrick   return RegionRawOffsetV2();
353e5dd7070Spatrick }
354e5dd7070Spatrick 
registerArrayBoundCheckerV2(CheckerManager & mgr)355e5dd7070Spatrick void ento::registerArrayBoundCheckerV2(CheckerManager &mgr) {
356e5dd7070Spatrick   mgr.registerChecker<ArrayBoundCheckerV2>();
357e5dd7070Spatrick }
358e5dd7070Spatrick 
shouldRegisterArrayBoundCheckerV2(const CheckerManager & mgr)359ec727ea7Spatrick bool ento::shouldRegisterArrayBoundCheckerV2(const CheckerManager &mgr) {
360e5dd7070Spatrick   return true;
361e5dd7070Spatrick }
362