[clang] [analyzer] Refine invalidation caused by `fread` (PR #93408)

Balázs Kéri via cfe-commits cfe-commits at lists.llvm.org
Mon May 27 06:33:52 PDT 2024


================
@@ -937,8 +990,21 @@ void StreamChecker::evalFreadFwrite(const FnDescription *Desc,
 
   // At read, invalidate the buffer in any case of error or success,
   // except if EOF was already present.
-  if (IsFread && !E.isStreamEof())
-    State = escapeArgs(State, C, Call, {0});
+  if (IsFread && !E.isStreamEof()) {
+    // Try to invalidate the individual elements.
+    if (const auto *BufferFirstElem =
+            dyn_cast_or_null<ElementRegion>(Call.getArgSVal(0).getAsRegion())) {
+      const MemRegion *Buffer = BufferFirstElem->getSuperRegion();
+      QualType ElemTy = BufferFirstElem->getElementType();
+      SVal FirstAccessedItem = BufferFirstElem->getIndex();
+      SVal ItemCount = Call.getArgSVal(2);
----------------
balazske wrote:

Here is some redundancy in getting the argument values, `SizeVal` and `NMembVal` are already available and could be used by the function (if it would take `NonLoc`).

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


More information about the cfe-commits mailing list