29 const MemRegion *MR, SValBuilder &SVB) {
30 MR = MR->StripCasts();
32 if (
const DefinedOrUnknownSVal *Size = State->get<DynamicExtentMap>(MR))
34 SVB.convertToArrayIndex(*Size).getAs<DefinedOrUnknownSVal>())
37 return MR->getMemRegionManager().getStaticSize(MR, SVB);
41 return SVB.makeIntVal(SVB.getContext().getTypeSizeInChars(Ty).getQuantity(),
42 SVB.getArrayIndexType());
45static DefinedOrUnknownSVal getConstantArrayElementCount(SValBuilder &SVB,
46 const MemRegion *MR) {
47 MR = MR->StripCasts();
49 const auto *TVR = MR->
getAs<TypedValueRegion>();
53 if (
const ConstantArrayType *CAT =
54 SVB.getContext().getAsConstantArrayType(TVR->getValueType()))
55 return SVB.makeIntVal(CAT->getSize(),
false);
60static DefinedOrUnknownSVal
62 DefinedOrUnknownSVal ElementSize) {
63 SValBuilder &SVB = State->getStateManager().getSValBuilder();
66 SVB.evalBinOp(State, BO_Div, Size, ElementSize, SVB.getArrayIndexType())
67 .getAs<DefinedOrUnknownSVal>();
68 return ElementCount.value_or(UnknownVal());
75 assert(MR !=
nullptr &&
"Not-null region expected");
76 MR = MR->StripCasts();
79 if (ElementSize.isZeroConstant())
80 return getConstantArrayElementCount(SVB, MR);
87 SValBuilder &SVB = State->getStateManager().getSValBuilder();
88 const MemRegion *MRegion = BufV.getAsRegion();
91 RegionOffset Offset = MRegion->getAsOffset();
92 if (Offset.hasSymbolicOffset())
94 const MemRegion *BaseRegion = MRegion->getBaseRegion();
98 NonLoc OffsetInChars =
99 SVB.makeArrayIndex(Offset.getOffset() / SVB.getContext().getCharWidth());
100 DefinedOrUnknownSVal ExtentInBytes =
getDynamicExtent(State, BaseRegion, SVB);
102 return SVB.evalBinOp(State, BinaryOperator::Opcode::BO_Sub, ExtentInBytes,
103 OffsetInChars, SVB.getArrayIndexType());
108 QualType ElementTy) {
113 SValBuilder &SVB = State->getStateManager().getSValBuilder();
115 if (ElementSize.isZeroConstant())
116 return getConstantArrayElementCount(SVB, MR);
123 DefinedOrUnknownSVal Size, SValBuilder &SVB) {
124 MR = MR->StripCasts();
126 if (Size.isUnknown())
129 return State->set<DynamicExtentMap>(MR->StripCasts(), Size);
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
#define REGISTER_MAP_WITH_PROGRAMSTATE(Name, Key, Value)
Declares an immutable map of type NameTy, suitable for placement into the ProgramState.
MemRegion - The root abstract class for all memory regions.
std::optional< T > getAs() const
Convert to the specified SVal type, returning std::nullopt if this SVal is not of the desired type.
const MemRegion * getAsRegion() const
DefinedOrUnknownSVal getDynamicElementCount(ProgramStateRef State, const MemRegion *MR, SValBuilder &SVB, QualType Ty)
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
SVal getDynamicExtentWithOffset(ProgramStateRef State, SVal BufV)
Get the dynamic extent for a symbolic value that represents a buffer.
DefinedOrUnknownSVal getDynamicExtent(ProgramStateRef State, const MemRegion *MR, SValBuilder &SVB)
DefinedOrUnknownSVal getElementExtent(QualType Ty, SValBuilder &SVB)
ProgramStateRef setDynamicExtent(ProgramStateRef State, const MemRegion *MR, DefinedOrUnknownSVal Extent, SValBuilder &SVB)
Set the dynamic extent Extent of the region MR.
DefinedOrUnknownSVal getDynamicElementCountWithOffset(ProgramStateRef State, SVal BufV, QualType Ty)
The JSON file list parser is used to communicate input to InstallAPI.