[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 6 08:58:55 PST 2023


================
@@ -1191,6 +1199,49 @@ 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 (State = SP.first)
+    if (State = ensureStreamOpened(StreamVal, C, State))
+      C.addTransition(State);
----------------
balazske wrote:

I think another `addTransition` is needed for `SP.second` if it is non-null.

https://github.com/llvm/llvm-project/pull/74296


More information about the cfe-commits mailing list