Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit bd8a11e

Browse files
committed
Provide stop-gap solution to crash reported in PR 14436.
This was also covered by <rdar://problem/12753384>. The static analyzer evaluates a CXXConstructExpr within an initializer expression and RegionStore doesn't know how to handle the resulting CXXTempObjectRegion that gets created. We need a better solution than just dropping the value, but we need to better understand how to implement the right semantics here. Thanks to Jordan for his help diagnosing the behavior here. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@168741 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 82c458e commit bd8a11e

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

lib/StaticAnalyzer/Core/RegionStore.cpp

+10-8
Original file line numberDiff line numberDiff line change
@@ -1581,14 +1581,16 @@ StoreRef RegionStoreManager::BindArray(Store store, const TypedValueRegion* R,
15811581
Size = CAT->getSize().getZExtValue();
15821582

15831583
// Check if the init expr is a string literal.
1584-
if (loc::MemRegionVal *MRV = dyn_cast<loc::MemRegionVal>(&Init)) {
1585-
const StringRegion *S = cast<StringRegion>(MRV->getRegion());
1586-
1587-
// Treat the string as a lazy compound value.
1588-
nonloc::LazyCompoundVal LCV =
1589-
cast<nonloc::LazyCompoundVal>(svalBuilder.
1590-
makeLazyCompoundVal(StoreRef(store, *this), S));
1591-
return BindAggregate(store, R, LCV);
1584+
if (const MemRegion *Reg = Init.getAsRegion()) {
1585+
if (const StringRegion *S = dyn_cast<StringRegion>(Reg)) {
1586+
// Treat the string as a lazy compound value.
1587+
NonLoc V = svalBuilder.makeLazyCompoundVal(StoreRef(store, *this), S);
1588+
return BindAggregate(store, R, V);
1589+
}
1590+
// FIXME: Handle CXXTempObjectRegion, which can occur in cases
1591+
// where a struct contains an array of structs in C++.
1592+
assert(isa<CXXTempObjectRegion>(Reg));
1593+
return BindAggregate(store, R, UnknownVal());
15921594
}
15931595

15941596
// Handle lazy compound values.

test/Analysis/misc-ps-region-store.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -633,3 +633,26 @@ void test_alloca_in_a_recursive_function(int p1) {
633633
test_alloca_in_a_recursive_function(1);
634634
test_alloca_in_a_recursive_function(2);
635635
}
636+
637+
//===---------------------------------------------------------------------===//
638+
// Random tests.
639+
//===---------------------------------------------------------------------===//
640+
641+
// Tests assigning using a C-style initializer to a struct
642+
// variable whose sub-field is also a struct. This currently
643+
// results in a CXXTempObjectRegion being created, but not
644+
// properly handled. For now, we just ignore that value
645+
// to avoid a crash (<rdar://problem/12753384>).
646+
struct RDar12753384_ClassA {
647+
unsigned z;
648+
};
649+
struct RDar12753384_ClassB {
650+
unsigned x;
651+
RDar12753384_ClassA y[ 8 ] ;
652+
};
653+
unsigned RDar12753384() {
654+
RDar12753384_ClassB w = { 0x00 };
655+
RDar12753384_ClassA y[8];
656+
return w.x;
657+
}
658+

0 commit comments

Comments
 (0)