On Wed, 2022-07-20 at 23:29 +0530, Immad Mir wrote:
> This patch adds three new function attributes to GCC that > are used for static analysis of usage of file descriptors: Thanks for the updated patch. Some very minor spelling/grammar/whitespace nits... > > 1) __attribute__ ((fd_arg(N))): The attributes may be applied to a function > that > takes on open file descriptor at refrenced argument N. "on open" -> "an open" "refrenced" -> "referenced" [...snip...] > diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi > index d5ff1018372..9234275ca6d 100644 > --- a/gcc/doc/invoke.texi > +++ b/gcc/doc/invoke.texi > @@ -9843,7 +9843,12 @@ This warning requires @option{-fanalyzer}, which > enables it; use > to disable it. > > This diagnostic warns for paths through code in which a > -@code{read} on a write-only file descriptor is attempted, or vice versa > +@code{read} on a write-only file descriptor is attempted, or vice versa. > + > +This diagnostic also warns for code paths in a which a function with > attribute > +@code{fd_arg_read (N)} is called with a file descriptor opened with > @code{O_WRONLY} > +at refrenced argument @code{N} or a function with attribute > @code{fd_arg_write (N)} "refrenced" -> "referenced" > +is called with a file descriptor opened with @code{O_RDONLY} at refrenced > argument @var{N}, "refrenced" -> "referenced". Please wrap these lines to avoid going over 80 columns. > > @item -Wno-analyzer-fd-double-close > @opindex Wanalyzer-fd-double-close > @@ -9875,6 +9880,11 @@ to disable it. > This diagnostic warns for paths through code in which a > read or write is called on a closed file descriptor. > > +This diagnostic also warns for paths through code in which > +a function with attribute @code{fd_arg (N)} or @code{fd_arg_read (N)} > +or @code{fd_arg_write (N)} is called with a closed file descriptor at > +refrenced argument @code{N}. "refrenced" -> "referenced". > + > @item -Wno-analyzer-fd-use-without-check > @opindex Wanalyzer-fd-use-without-check > @opindex Wno-analyzer-fd-use-without-check > @@ -9885,6 +9895,11 @@ to disable it. > This diagnostic warns for paths through code in which a > file descriptor is used without being checked for validity. > > +This diagnostic also warns for paths through code in which > +a function with attribute @code{fd_arg (N)} or @code{fd_arg_read (N)} > +or @code{fd_arg_write (N)} is called with a file descriptor, at refrenced > +argument @code{N}, without being checked for validity. "refrenced" -> "referenced". > + > @item -Wno-analyzer-file-leak > @opindex Wanalyzer-file-leak > @opindex Wno-analyzer-file-leak [...snip...] ...but with those fixed, this patch is OK for trunk, assuming it bootstraps and passes regression tests. Thanks! Dave