[PATCH] D48325: [analyzer][UninitializedObjectChecker] Support for MemberPointerTypes
Umann Kristóf via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 19 09:05:29 PDT 2018
Szelethus created this revision.
Szelethus added reviewers: NoQ, george.karpenkov, xazax.hun, rnkovacs.
Herald added subscribers: cfe-commits, mikhail.ramalho, a.sidorin, szepet, whisperity.
Repository:
rC Clang
https://reviews.llvm.org/D48325
Files:
lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
Index: test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
===================================================================
--- test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
+++ test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
@@ -416,14 +416,12 @@
#ifdef PEDANTIC
struct PointerToMemberFunctionTest1 {
- // TODO: we'd expect the note {{uninitialized field 'this->f'}}
- void (UsefulFunctions::*f)(void); // no-note
+ void (UsefulFunctions::*f)(void); // expected-note{{uninitialized field 'this->f'}}
PointerToMemberFunctionTest1() {}
};
void fPointerToMemberFunctionTest1() {
- // TODO: we'd expect the warning {{1 uninitialized field}}
- PointerToMemberFunctionTest1(); // no-warning
+ PointerToMemberFunctionTest1(); // expected-warning{{1 uninitialized field}}
}
struct PointerToMemberFunctionTest2 {
@@ -460,14 +458,12 @@
}
struct PointerToMemberDataTest1 {
- // TODO: we'd expect the note {{uninitialized field 'this->f'}}
- int UsefulFunctions::*d; // no-note
+ int UsefulFunctions::*d; // expected-note{{uninitialized field 'this->d'}}
PointerToMemberDataTest1() {}
};
void fPointerToMemberDataTest1() {
- // TODO: we'd expect the warning {{1 uninitialized field}}
- PointerToMemberDataTest1(); // no-warning
+ PointerToMemberDataTest1(); // expected-warning{{1 uninitialized field}}
}
struct PointerToMemberDataTest2 {
Index: lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
===================================================================
--- lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
+++ lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
@@ -389,15 +389,14 @@
continue;
}
- if (T->isMemberPointerType()) {
- if (isMemberPointerUninit(FR, LocalChain))
+ if (T->isPointerType() || T->isReferenceType()) {
+ if (isPointerOrReferenceUninit(FR, LocalChain))
ContainsUninitField = true;
continue;
}
- // If this is a pointer or reference type.
- if (T->isPointerType() || T->isReferenceType()) {
- if (isPointerOrReferenceUninit(FR, LocalChain))
+ if (T->isMemberPointerType()) {
+ if (isMemberPointerUninit(FR, LocalChain))
ContainsUninitField = true;
continue;
}
@@ -521,6 +520,12 @@
}
}
+ if (T->isMemberPointerType()) {
+ if (isMemberPointerUninit(FR, LocalChain))
+ return addFieldToUninits({LocalChain, FR, /*IsDereferenced*/ true});
+ return false;
+ }
+
if (T->isArrayType()) {
IsAnyFieldInitialized = true;
return false;
@@ -543,7 +548,12 @@
FieldChainInfo LocalChain) {
assert(FR->getDecl()->getType()->isMemberPointerType() &&
"This function only checks regions that hold MemberPointerTypes!");
- // TODO: Implement support for MemberPointerTypes.
+
+ SVal V = State->getSVal(FR);
+ if (V.isUndef())
+ return addFieldToUninits({LocalChain, FR});
+
+ IsAnyFieldInitialized = true;
return false;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48325.151928.patch
Type: text/x-patch
Size: 3031 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180619/45f77a24/attachment-0001.bin>
More information about the cfe-commits
mailing list