[PATCH] D50508: [analyzer][UninitializedObjectChecker] Refactoring p5.: Handle pedantic mode in the checker class only
Umann Kristóf via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 13 11:49:18 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rC339601: [analyzer][UninitializedObjectChecker] Refactoring p5.: Handle pedantic mode in… (authored by Szelethus, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D50508?vs=159901&id=160420#toc
Repository:
rC Clang
https://reviews.llvm.org/D50508
Files:
lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
Index: lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
===================================================================
--- lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
+++ lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
@@ -136,14 +136,20 @@
if (!Object)
return;
- FindUninitializedFields F(Context.getState(), Object->getRegion(), IsPedantic,
+ FindUninitializedFields F(Context.getState(), Object->getRegion(),
CheckPointeeInitialization);
const UninitFieldMap &UninitFields = F.getUninitFields();
if (UninitFields.empty())
return;
+ // In non-pedantic mode, if Object's region doesn't contain a single
+ // initialized field, we'll assume that Object was intentionally left
+ // uninitialized.
+ if (!IsPedantic && !F.isAnyFieldInitialized())
+ return;
+
// There are uninitialized fields in the record.
ExplodedNode *Node = Context.generateNonFatalErrorNode(Context.getState());
@@ -192,18 +198,12 @@
//===----------------------------------------------------------------------===//
FindUninitializedFields::FindUninitializedFields(
- ProgramStateRef State, const TypedValueRegion *const R, bool IsPedantic,
+ ProgramStateRef State, const TypedValueRegion *const R,
bool CheckPointeeInitialization)
- : State(State), ObjectR(R), IsPedantic(IsPedantic),
- CheckPointeeInitialization(CheckPointeeInitialization) {}
+ : State(State), ObjectR(R),
+ CheckPointeeInitialization(CheckPointeeInitialization) {
-const UninitFieldMap &FindUninitializedFields::getUninitFields() {
isNonUnionUninit(ObjectR, FieldChainInfo(ChainFactory));
-
- if (!IsPedantic && !IsAnyFieldInitialized)
- UninitFields.clear();
-
- return UninitFields;
}
bool FindUninitializedFields::addFieldToUninits(FieldChainInfo Chain) {
Index: lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
===================================================================
--- lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
+++ lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
@@ -111,9 +111,7 @@
ProgramStateRef State;
const TypedValueRegion *const ObjectR;
- const bool IsPedantic;
const bool CheckPointeeInitialization;
-
bool IsAnyFieldInitialized = false;
FieldChainInfo::FieldChain::Factory ChainFactory;
@@ -131,10 +129,17 @@
UninitFieldMap UninitFields;
public:
+ /// Constructs the FindUninitializedField object, searches for and stores
+ /// uninitialized fields in R.
FindUninitializedFields(ProgramStateRef State,
- const TypedValueRegion *const R, bool IsPedantic,
+ const TypedValueRegion *const R,
bool CheckPointeeInitialization);
- const UninitFieldMap &getUninitFields();
+
+ const UninitFieldMap &getUninitFields() { return UninitFields; }
+
+ /// Returns whether the analyzed region contains at least one initialized
+ /// field.
+ bool isAnyFieldInitialized() { return IsAnyFieldInitialized; }
private:
// For the purposes of this checker, we'll regard the object under checking as
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50508.160420.patch
Type: text/x-patch
Size: 3256 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180813/348b1ae5/attachment.bin>
More information about the cfe-commits
mailing list