forked from OSchip/llvm-project
[analyzer][UninitializedObjectChecker] Refactoring p5.: Handle pedantic mode in the checker class only
Differential Revision: https://reviews.llvm.org/D50508 llvm-svn: 339601
This commit is contained in:
parent
35213793bc
commit
23ca9660bf
|
@ -111,9 +111,7 @@ class FindUninitializedFields {
|
|||
ProgramStateRef State;
|
||||
const TypedValueRegion *const ObjectR;
|
||||
|
||||
const bool IsPedantic;
|
||||
const bool CheckPointeeInitialization;
|
||||
|
||||
bool IsAnyFieldInitialized = false;
|
||||
|
||||
FieldChainInfo::FieldChain::Factory ChainFactory;
|
||||
|
@ -131,10 +129,17 @@ class FindUninitializedFields {
|
|||
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
|
||||
|
|
|
@ -136,7 +136,7 @@ void UninitializedObjectChecker::checkEndFunction(
|
|||
if (!Object)
|
||||
return;
|
||||
|
||||
FindUninitializedFields F(Context.getState(), Object->getRegion(), IsPedantic,
|
||||
FindUninitializedFields F(Context.getState(), Object->getRegion(),
|
||||
CheckPointeeInitialization);
|
||||
|
||||
const UninitFieldMap &UninitFields = F.getUninitFields();
|
||||
|
@ -144,6 +144,12 @@ void UninitializedObjectChecker::checkEndFunction(
|
|||
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 @@ void UninitializedObjectChecker::checkEndFunction(
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
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) {
|
||||
|
|
Loading…
Reference in New Issue