summaryrefslogtreecommitdiffstats
path: root/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
diff options
context:
space:
mode:
authorKristof Umann <dkszelethus@gmail.com>2018-08-13 18:43:08 +0000
committerKristof Umann <dkszelethus@gmail.com>2018-08-13 18:43:08 +0000
commit015b059569eef883e9313035cd98c72f947477ab (patch)
tree850c472d40251407a22ed90feca61c38c213227d /clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
parente33062369e67ab95949ab8f5f52dbc1027332199 (diff)
downloadbcm5719-llvm-015b059569eef883e9313035cd98c72f947477ab.tar.gz
bcm5719-llvm-015b059569eef883e9313035cd98c72f947477ab.zip
[analyzer][UninitializedObjectChecker] Refactoring p4.: Wrap FieldRegions and reduce weight on FieldChainInfo
Before this patch, FieldChainInfo used a spaghetti: it took care of way too many cases, even though it was always meant as a lightweight wrapper around ImmutableList<const FieldRegion *>. This problem is solved by introducing a lightweight polymorphic wrapper around const FieldRegion *, FieldNode. It is an interface that abstracts away special cases like pointers/references, objects that need to be casted to another type for a proper note messages. Changes to FieldChainInfo: * Now wraps ImmutableList<const FieldNode &>. * Any pointer/reference related fields and methods were removed * Got a new add method. This replaces it's former constructors as a way to create a new FieldChainInfo objects with a new element. Changes to FindUninitializedField: * In order not to deal with dynamic memory management, when an uninitialized field is found, the note message for it is constructed and is stored instead of a FieldChainInfo object. (see doc around addFieldToUninits). Some of the test files are changed too, from now on uninitialized pointees of references always print "uninitialized pointee" instead of "uninitialized field" (which should've really been like this from the beginning). I also updated every comment according to these changes. Differential Revision: https://reviews.llvm.org/D50506 llvm-svn: 339599
Diffstat (limited to 'clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp')
-rw-r--r--clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp43
1 files changed, 39 insertions, 4 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
index 90d2ff00510..61e96ef9ae7 100644
--- a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
@@ -28,6 +28,40 @@
using namespace clang;
using namespace clang::ento;
+namespace {
+
+/// Represents a pointer or a reference field.
+class LocField : public FieldNode {
+ /// We'll store whether the pointee or the pointer itself is uninitialited.
+ const bool IsDereferenced;
+
+public:
+ LocField(const FieldRegion *FR, const bool IsDereferenced = true)
+ : FieldNode(FR), IsDereferenced(IsDereferenced) {}
+
+ virtual void printNoteMsg(llvm::raw_ostream &Out) const override {
+ if (IsDereferenced)
+ Out << "uninitialized pointee ";
+ else
+ Out << "uninitialized pointer ";
+ }
+
+ virtual void printPrefix(llvm::raw_ostream &Out) const override {}
+
+ virtual void printNode(llvm::raw_ostream &Out) const override {
+ Out << getVariableName(getDecl());
+ }
+
+ virtual void printSeparator(llvm::raw_ostream &Out) const override {
+ if (getDecl()->getType()->isPointerType())
+ Out << "->";
+ else
+ Out << '.';
+ }
+};
+
+} // end of anonymous namespace
+
// Utility function declarations.
/// Returns whether T can be (transitively) dereferenced to a void pointer type
@@ -57,7 +91,8 @@ bool FindUninitializedFields::isPointerOrReferenceUninit(
}
if (V.isUndef()) {
- return addFieldToUninits({LocalChain, FR});
+ return addFieldToUninits(
+ LocalChain.add(LocField(FR, /*IsDereferenced*/ false)));
}
if (!CheckPointeeInitialization) {
@@ -126,11 +161,11 @@ bool FindUninitializedFields::isPointerOrReferenceUninit(
const TypedValueRegion *R = RecordV->getRegion();
if (DynT->getPointeeType()->isStructureOrClassType())
- return isNonUnionUninit(R, {LocalChain, FR});
+ return isNonUnionUninit(R, LocalChain.add(LocField(FR)));
if (DynT->getPointeeType()->isUnionType()) {
if (isUnionUninit(R)) {
- return addFieldToUninits({LocalChain, FR, /*IsDereferenced*/ true});
+ return addFieldToUninits(LocalChain.add(LocField(FR)));
} else {
IsAnyFieldInitialized = true;
return false;
@@ -151,7 +186,7 @@ bool FindUninitializedFields::isPointerOrReferenceUninit(
"must be a null, undefined, unknown or concrete pointer!");
if (isPrimitiveUninit(DerefdV))
- return addFieldToUninits({LocalChain, FR, /*IsDereferenced*/ true});
+ return addFieldToUninits(LocalChain.add(LocField(FR)));
IsAnyFieldInitialized = true;
return false;
OpenPOWER on IntegriCloud