[clang] [clang][analyzer] Support `fflush` in the StreamChecker (PR #74296)
Balázs Kéri via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 20 07:31:59 PST 2023
================
@@ -1191,6 +1199,82 @@ void StreamChecker::evalSetFeofFerror(const FnDescription *Desc,
C.addTransition(State);
}
+void StreamChecker::preFflush(const FnDescription *Desc, const CallEvent &Call,
+ CheckerContext &C) const {
+ ProgramStateRef State = C.getState();
+ SVal StreamVal = getStreamArg(Desc, Call);
+ std::optional<DefinedSVal> Stream = StreamVal.getAs<DefinedSVal>();
+ if (!Stream)
+ return;
+
+ ConstraintManager::ProgramStatePair SP =
+ C.getConstraintManager().assumeDual(State, *Stream);
+ if (SP.first)
----------------
balazske wrote:
It is better to check for `SP.first && !SP.second`. If a stream pointer is unknown (`SP.first` and `SP.second` is not null) there should be no `StreamState` for it, so the `ensureStreamOpened` does nothing useful.
https://github.com/llvm/llvm-project/pull/74296
More information about the cfe-commits
mailing list