[PATCH] D50892: [analyzer][UninitializedObjectChecker] Correct dynamic type is acquired for record pointees
Umann Kristóf via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 27 04:53:36 PDT 2018
Szelethus updated this revision to Diff 162658.
Szelethus marked 5 inline comments as done.
Szelethus added a comment.
Actually, the note messages were incorrect as in this case the static and dynamic type of the object differs.
https://reviews.llvm.org/D50892
Files:
lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
test/Analysis/cxx-uninitialized-object-inheritance.cpp
Index: test/Analysis/cxx-uninitialized-object-inheritance.cpp
===================================================================
--- test/Analysis/cxx-uninitialized-object-inheritance.cpp
+++ test/Analysis/cxx-uninitialized-object-inheritance.cpp
@@ -781,21 +781,38 @@
// Dynamic type test.
//===----------------------------------------------------------------------===//
-struct DynTBase {};
-struct DynTDerived : DynTBase {
- // TODO: we'd expect the note: {{uninitialized field 'this->x'}}
- int x; // no-note
+struct DynTBase1 {};
+struct DynTDerived1 : DynTBase1 {
+ int y; // expected-note{{uninitialized field 'static_cast<struct DynTDerived1 *>(this->bptr)->y'}}
};
-struct DynamicTypeTest {
- DynTBase *bptr;
+struct DynamicTypeTest1 {
+ DynTBase1 *bptr;
int i = 0;
- // TODO: we'd expect the warning: {{1 uninitialized field}}
- DynamicTypeTest(DynTBase *bptr) : bptr(bptr) {} // no-warning
+ DynamicTypeTest1(DynTBase1 *bptr) : bptr(bptr) {} // expected-warning{{1 uninitialized field}}
};
-void f() {
- DynTDerived d;
- DynamicTypeTest t(&d);
+void fDynamicTypeTest1() {
+ DynTDerived1 d;
+ DynamicTypeTest1 t(&d);
};
+
+struct DynTBase2 {
+ int x; // expected-note{{uninitialized field 'static_cast<struct DynTDerived2 *>(this->bptr)->DynTBase2::x'}}
+};
+struct DynTDerived2 : DynTBase2 {
+ int y; // expected-note{{uninitialized field 'static_cast<struct DynTDerived2 *>(this->bptr)->y'}}
+};
+
+struct DynamicTypeTest2 {
+ DynTBase2 *bptr;
+ int i = 0;
+
+ DynamicTypeTest2(DynTBase2 *bptr) : bptr(bptr) {} // expected-warning{{2 uninitialized fields}}
+};
+
+void fDynamicTypeTest2() {
+ DynTDerived2 d;
+ DynamicTypeTest2 t(&d);
+}
Index: lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
===================================================================
--- lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
+++ lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
@@ -240,5 +240,10 @@
break;
}
+ while (R->getAs<CXXBaseObjectRegion>()) {
+ NeedsCastBack = true;
+ R = R->getSuperRegion()->getAs<TypedValueRegion>();
+ }
+
return std::make_pair(R, NeedsCastBack);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50892.162658.patch
Type: text/x-patch
Size: 2213 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180827/b40c06f1/attachment.bin>
More information about the cfe-commits
mailing list