Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,15 @@ class CallEvent {
getExtraInvalidatedValues(ValueList &Values,
RegionAndSymbolInvalidationTraits *ETraits) const {}

/// A state for looking up relevant Environment entries (arguments, return
/// value), dynamic type information and similar "stable" things.
/// WARNING: During the evaluation of a function call, several state
/// transitions happen, so this state can become partially obsolete!
///
/// TODO: Instead of storing a complete state object in the CallEvent, only
/// store the relevant parts (argument/return SVals, dynamic type etc.).
ProgramStateRef getState() const { return State; }

public:
CallEvent &operator=(const CallEvent &) = delete;
virtual ~CallEvent() = default;
Expand All @@ -231,8 +240,11 @@ class CallEvent {
}
void setForeign(bool B) const { Foreign = B; }

/// The state in which the call is being evaluated.
const ProgramStateRef &getState() const { return State; }
/// NOTE: There are plans for refactoring that would eliminate this method.
/// Prefer to use CheckerContext::getASTContext if possible!
ASTContext &getASTContext() const {
return getState()->getStateManager().getContext();
}

/// The context in which the call is being evaluated.
const LocationContext *getLocationContext() const { return LCtx; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class RAIIMutexDescriptor {
// this function is called instead of early returning it. To avoid this, a
// bool variable (IdentifierInfoInitialized) is used and the function will
// be run only once.
const auto &ASTCtx = Call.getState()->getStateManager().getContext();
const auto &ASTCtx = Call.getASTContext();
Guard = &ASTCtx.Idents.get(GuardName);
}
}
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ ObjCDeallocChecker::getValueReleasedByNillingOut(const ObjCMethodCall &M,
SVal Arg = M.getArgSVal(0);
ProgramStateRef notNilState, nilState;
std::tie(notNilState, nilState) =
M.getState()->assume(Arg.castAs<DefinedOrUnknownSVal>());
C.getState()->assume(Arg.castAs<DefinedOrUnknownSVal>());
if (!(nilState && !notNilState))
return nullptr;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ ObjCSuperDeallocChecker::isSuperDeallocMessage(const ObjCMethodCall &M) const {
if (M.getOriginExpr()->getReceiverKind() != ObjCMessageExpr::SuperInstance)
return false;

ASTContext &Ctx = M.getState()->getStateManager().getContext();
ASTContext &Ctx = M.getASTContext();
initIdentifierInfoAndSelectors(Ctx);

return M.getSelector() == SELdealloc;
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/StaticAnalyzer/Checkers/StdVariantChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,13 @@ class StdVariantChecker : public Checker<eval::Call, check::RegionChanges> {
if (!DefaultType)
return;

ProgramStateRef State = ConstructorCall->getState();
ProgramStateRef State = C.getState();
State = State->set<VariantHeldTypeMap>(ThisMemRegion, *DefaultType);
C.addTransition(State);
}

bool handleStdGetCall(const CallEvent &Call, CheckerContext &C) const {
ProgramStateRef State = Call.getState();
ProgramStateRef State = C.getState();

const auto &ArgType = Call.getArgSVal(0)
.getType(C.getASTContext())
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/StaticAnalyzer/Checkers/TaggedUnionModeling.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ removeInformationStoredForDeadInstances(const CallEvent &Call,
template <class TypeMap>
void handleConstructorAndAssignment(const CallEvent &Call, CheckerContext &C,
SVal ThisSVal) {
ProgramStateRef State = Call.getState();
ProgramStateRef State = C.getState();

if (!State)
return;
Expand Down
Loading