Skip to content

Commit 3ef3dd7

Browse files
committedSep 14, 2018
[analyzer][UninitializedObjectChecker] Correct dynamic type is acquired for record pointees
Differential Revision: https://reviews.llvm.org/D50892 llvm-svn: 342217
1 parent 5c3457d commit 3ef3dd7

File tree

2 files changed

+51
-11
lines changed

2 files changed

+51
-11
lines changed
 

‎clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -234,5 +234,13 @@ static llvm::Optional<DereferenceInfo> dereference(ProgramStateRef State,
234234
break;
235235
}
236236

237+
while (R->getAs<CXXBaseObjectRegion>()) {
238+
NeedsCastBack = true;
239+
240+
if (!isa<TypedValueRegion>(R->getSuperRegion()))
241+
break;
242+
R = R->getSuperRegion()->getAs<TypedValueRegion>();
243+
}
244+
237245
return std::make_pair(R, NeedsCastBack);
238246
}

‎clang/test/Analysis/cxx-uninitialized-object-inheritance.cpp

+43-11
Original file line numberDiff line numberDiff line change
@@ -781,21 +781,53 @@ void fVirtualDiamondInheritanceTest3() {
781781
// Dynamic type test.
782782
//===----------------------------------------------------------------------===//
783783

784-
struct DynTBase {};
785-
struct DynTDerived : DynTBase {
786-
// TODO: we'd expect the note: {{uninitialized field 'this->x'}}
787-
int x; // no-note
784+
struct DynTBase1 {};
785+
struct DynTDerived1 : DynTBase1 {
786+
int y; // expected-note{{uninitialized field 'static_cast<struct DynTDerived1 *>(this->bptr)->y'}}
788787
};
789788

790-
struct DynamicTypeTest {
791-
DynTBase *bptr;
789+
struct DynamicTypeTest1 {
790+
DynTBase1 *bptr;
792791
int i = 0;
793792

794-
// TODO: we'd expect the warning: {{1 uninitialized field}}
795-
DynamicTypeTest(DynTBase *bptr) : bptr(bptr) {} // no-warning
793+
DynamicTypeTest1(DynTBase1 *bptr) : bptr(bptr) {} // expected-warning{{1 uninitialized field}}
796794
};
797795

798-
void f() {
799-
DynTDerived d;
800-
DynamicTypeTest t(&d);
796+
void fDynamicTypeTest1() {
797+
DynTDerived1 d;
798+
DynamicTypeTest1 t(&d);
801799
};
800+
801+
struct DynTBase2 {
802+
int x; // expected-note{{uninitialized field 'static_cast<struct DynTDerived2 *>(this->bptr)->DynTBase2::x'}}
803+
};
804+
struct DynTDerived2 : DynTBase2 {
805+
int y; // expected-note{{uninitialized field 'static_cast<struct DynTDerived2 *>(this->bptr)->y'}}
806+
};
807+
808+
struct DynamicTypeTest2 {
809+
DynTBase2 *bptr;
810+
int i = 0;
811+
812+
DynamicTypeTest2(DynTBase2 *bptr) : bptr(bptr) {} // expected-warning{{2 uninitialized fields}}
813+
};
814+
815+
void fDynamicTypeTest2() {
816+
DynTDerived2 d;
817+
DynamicTypeTest2 t(&d);
818+
}
819+
820+
struct SymbolicSuperRegionBase {
821+
SymbolicSuperRegionBase() {}
822+
};
823+
824+
struct SymbolicSuperRegionDerived : SymbolicSuperRegionBase {
825+
SymbolicSuperRegionBase *bptr; // no-crash
826+
SymbolicSuperRegionDerived(SymbolicSuperRegionBase *bptr) : bptr(bptr) {}
827+
};
828+
829+
SymbolicSuperRegionDerived *getSymbolicRegion();
830+
831+
void fSymbolicSuperRegionTest() {
832+
SymbolicSuperRegionDerived test(getSymbolicRegion());
833+
}

0 commit comments

Comments
 (0)
Please sign in to comment.