[clang] [clang][analyzer] Improve modeling of `fileno` in the StreamChecker (PR #76207)

Balázs Kéri via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 22 01:59:00 PST 2023


balazske wrote:

I do not see much benefit of adding `fileno` to the checker in the current state. If the `StdLibraryFunctionsChecker` is turned on it will anyway do a similar modeling of `fileno` (this applied to `ftell` too). The `fileno` and `ftell` are semantically different and `fileno` can be more complicated if we want to ensure that the returned file numbers are different from each other, and special values for `stdin`, `stdout`, `stderr` should be taken into account.
Adding `fileno` in the current way makes a small improvement for the case when `StdLibraryFunctionsChecker` is not used. A combined function for `fileno` and `ftell` can be used, but in a way that works with any function that returns -1 on error and >=0 value on success. The type of the return value can be get from the declaration of the function or from the `CallEvent` in some way, a type parameter to the function is not needed.
Adding the standard streams to the checker has some difficulties and requires more work (at least there must be a checker parameter to assume that standard streams are not changed by the program, otherwise no modeling can be done because these are global variables).

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


More information about the cfe-commits mailing list