Skip to content

Fix RegionStore assertion failure after #127602 #129224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions clang/lib/StaticAnalyzer/Core/RegionStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2570,6 +2570,9 @@ RegionStoreManager::bind(LimitedRegionBindingsConstRef B, Loc L, SVal V) {
LimitedRegionBindingsRef
RegionStoreManager::setImplicitDefaultValue(LimitedRegionBindingsConstRef B,
const MemRegion *R, QualType T) {
if (B.hasExhaustedBindingLimit())
return B;

SVal V;

if (Loc::isLocType(T))
Expand All @@ -2596,6 +2599,8 @@ RegionStoreManager::setImplicitDefaultValue(LimitedRegionBindingsConstRef B,
std::optional<LimitedRegionBindingsRef> RegionStoreManager::tryBindSmallArray(
LimitedRegionBindingsConstRef B, const TypedValueRegion *R,
const ArrayType *AT, nonloc::LazyCompoundVal LCV) {
if (B.hasExhaustedBindingLimit())
return B.withValuesEscaped(LCV);

auto CAT = dyn_cast<ConstantArrayType>(AT);

Expand Down Expand Up @@ -2632,6 +2637,8 @@ RegionStoreManager::bindArray(LimitedRegionBindingsConstRef B,
const TypedValueRegion *R, SVal Init) {
llvm::TimeTraceScope TimeScope("RegionStoreManager::bindArray",
[R]() { return R->getDescriptiveName(); });
if (B.hasExhaustedBindingLimit())
return B.withValuesEscaped(Init);

const ArrayType *AT =cast<ArrayType>(Ctx.getCanonicalType(R->getValueType()));
QualType ElementTy = AT->getElementType();
Expand Down Expand Up @@ -2698,6 +2705,9 @@ RegionStoreManager::bindVector(LimitedRegionBindingsConstRef B,
const TypedValueRegion *R, SVal V) {
llvm::TimeTraceScope TimeScope("RegionStoreManager::bindVector",
[R]() { return R->getDescriptiveName(); });
if (B.hasExhaustedBindingLimit())
return B.withValuesEscaped(V);

QualType T = R->getValueType();
const VectorType *VT = T->castAs<VectorType>(); // Use castAs for typedefs.

Expand All @@ -2722,6 +2732,9 @@ RegionStoreManager::bindVector(LimitedRegionBindingsConstRef B,
if (VI == VE)
break;

if (NewB.hasExhaustedBindingLimit())
return NewB.withValuesEscaped(VI, VE);

NonLoc Idx = svalBuilder.makeArrayIndex(index);
const ElementRegion *ER = MRMgr.getElementRegion(ElemType, Idx, R, Ctx);

Expand Down Expand Up @@ -2758,6 +2771,9 @@ RegionStoreManager::getUniqueDefaultBinding(nonloc::LazyCompoundVal LCV) const {
std::optional<LimitedRegionBindingsRef> RegionStoreManager::tryBindSmallStruct(
LimitedRegionBindingsConstRef B, const TypedValueRegion *R,
const RecordDecl *RD, nonloc::LazyCompoundVal LCV) {
if (B.hasExhaustedBindingLimit())
return B.withValuesEscaped(LCV);

// If we try to copy a Conjured value representing the value of the whole
// struct, don't try to element-wise copy each field.
// That would unnecessarily bind Derived symbols slicing off the subregion for
Expand Down Expand Up @@ -2822,6 +2838,9 @@ RegionStoreManager::bindStruct(LimitedRegionBindingsConstRef B,
const TypedValueRegion *R, SVal V) {
llvm::TimeTraceScope TimeScope("RegionStoreManager::bindStruct",
[R]() { return R->getDescriptiveName(); });
if (B.hasExhaustedBindingLimit())
return B.withValuesEscaped(V);

QualType T = R->getValueType();
assert(T->isStructureOrClassType());

Expand Down Expand Up @@ -2931,6 +2950,9 @@ RegionStoreManager::bindStruct(LimitedRegionBindingsConstRef B,
++VI;
}

if (NewB.hasExhaustedBindingLimit())
return NewB.withValuesEscaped(VI, VE);

// There may be fewer values in the initialize list than the fields of struct.
if (FI != FE) {
NewB = NewB.addBinding(R, BindingKey::Default,
Expand All @@ -2945,6 +2967,9 @@ RegionStoreManager::bindAggregate(LimitedRegionBindingsConstRef B,
const TypedRegion *R, SVal Val) {
llvm::TimeTraceScope TimeScope("RegionStoreManager::bindAggregate",
[R]() { return R->getDescriptiveName(); });
if (B.hasExhaustedBindingLimit())
return B.withValuesEscaped(Val);

// Remove the old bindings, using 'R' as the root of all regions
// we will invalidate. Then add the new binding.
return removeSubRegionBindings(B, R).addBinding(R, BindingKey::Default, Val);
Expand Down
29 changes: 29 additions & 0 deletions clang/test/Analysis/region-store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,3 +386,32 @@ void tooManyFnArgumentsWhenInlining() {
10,11,12,13,14,15,16,17,18,19,
});
}

void gh129211_assertion() {
struct Clazz {
int b;
int : 0;
};

Clazz d[][5][5] = {
{
{{}, {}, {}, {}, {}},
{{}, {}, {}, {}, {}},
{{}, {}, {}, {}, {}},
{{}, {}, {}, {}, {}},
{{}, {}, {}, {}, {}}
},
{
{{}, {}, {}, {}, {}},
{{}, {}, {}, {}, {}},
{{}, {}, {}, {}, {}},
{{}, {}, {}, {}, {}},
{{}, {}, {}, {}, {}},
},
{
{{}, {}, {}, {}, {}},
{{}, {}, {}, {}, {}},
{{}, {}, {}, {}},
}
}; // no-crash
}
Loading