[clang] [clang][analyzer] Change modeling of 'fileno' in checkers. (PR #81842)
Ben Shi via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 20 17:21:32 PST 2024
=?utf-8?q?Balázs_Kéri?= <balazs.keri at ericsson.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/81842 at github.com>
================
@@ -1404,6 +1486,47 @@ void StreamChecker::evalFeofFerror(const FnDescription *Desc,
}
}
+void StreamChecker::evalFileno(const FnDescription *Desc, const CallEvent &Call,
+ CheckerContext &C) const {
+ // Fileno should fail only if the passed pointer is invalid.
+ // Some of the preconditions are checked already in preDefault.
+ // Here we can assume that the operation does not fail.
+ // An added failure case causes many unexpected warnings because a file number
+ // becomes -1 that is not expected by the program.
+ // The stream error states are not modified by 'fileno', and not the 'errno'.
+ // (To ensure that errno is not changed, this evalCall is needed to not
+ // invalidate 'errno' like in a default case.)
+ ProgramStateRef State = C.getState();
+ SymbolRef StreamSym = getStreamArg(Desc, Call).getAsSymbol();
+ if (!StreamSym)
+ return;
+
+ const CallExpr *CE = dyn_cast_or_null<CallExpr>(Call.getOriginExpr());
----------------
benshi001 wrote:
Shall we change to `StreamOperationEvaluator` which is introduced by your previous simplification patch ?
https://github.com/llvm/llvm-project/pull/81842
More information about the cfe-commits
mailing list