On Fri, 2022-07-22 at 21:25 +0530, Immad Mir wrote: > This patch adds three new function attributes to GCC that > are used for static analysis of usage of file descriptors: > > 1) __attribute__ ((fd_arg(N))): The attributes may be applied to a > function that > takes an open file descriptor at refrenced argument N. > > It indicates that the passed filedescriptor must not have been > closed. > Therefore, when the analyzer is enabled with -fanalyzer, the > analyzer may emit a -Wanalyzer-fd-use-after-close diagnostic > if it detects a code path in which a function with this attribute is > called with a closed file descriptor. > > The attribute also indicates that the file descriptor must have been > checked for > validity before usage. Therefore, analyzer may emit > -Wanalyzer-fd-use-without-check diagnostic if it detects a code path > in > which a function with this attribute is called with a file descriptor > that has > not been checked for validity. > > 2) __attribute__((fd_arg_read(N))): The attribute is identical to > fd_arg, but with the additional requirement that it might read from > the file descriptor, and thus, the file descriptor must not have been > opened > as write-only. > > The analyzer may emit a -Wanalyzer-access-mode-mismatch > diagnostic if it detects a code path in which a function with this > attribute is called on a file descriptor opened with O_WRONLY. > > 3) __attribute__((fd_arg_write(N))): The attribute is identical to > fd_arg_read > except that the analyzer may emit a -Wanalyzer-access-mode-mismatch > diagnostic if > it detects a code path in which a function with this attribute is > called on a > file descriptor opened with O_RDONLY.
[...snip...] Thanks for the updated patch. This version looks good for trunk. You indicated (in an off-list email) that you've tested this, so please go ahead and push this. Thanks Dave