From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 35D033858CDA for ; Wed, 20 Jul 2022 18:24:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 35D033858CDA Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-473-GzCsnrj1NpiLO6weEZAq_g-1; Wed, 20 Jul 2022 14:24:00 -0400 X-MC-Unique: GzCsnrj1NpiLO6weEZAq_g-1 Received: by mail-qk1-f197.google.com with SMTP id l189-20020a37bbc6000000b006af2596c5e8so14891035qkf.14 for ; Wed, 20 Jul 2022 11:24:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=QvP6TDETEVqxpSC4lk4x3ge77qkylxVX9iJT2YL0nRw=; b=3E7zrCmGzyHR9dVzEadBimbDDUgj69V7aY8/q9IyoPoRBK8DoUuE+NK2097IJd490p zFb9ZAcRCvYR+umPyhQkOILgHIXrCwHA7AcWBT70Wql3UuAsVtTGdfuoCjA0k3b8EW8F ttx/nQ/zfvMQ37eCz5EML4Med834Lk4Ysaykc1YdshhmaRr19tA8o1wAdYuj5wxs7efn WwDAxvQlF9JOHJSdXLcUmde2Kf8Y2rQ29mIEEHQIhVWERRD+ZwBOJhOwCBkNYwpgE8v0 fwwNZmKCeGXHsxhELOqMnoFtQJXpelfsStxZeGa34Frs7R3PM8AZZW9fr+lmvlROiVfp t67g== X-Gm-Message-State: AJIora/w8wH5WxYq5v1udywfD/tQ9WvZwTnBZx+nxx+HXn3Rjt++ueje zss53R7zVu6rC1rkw2K+9tCRdjELKX7RWKzYOKo2mOHhBtJEGRszcEQuUuFaFlxfFhqRVDOhgrQ XEZyFdZQK6xYvKQapoA== X-Received: by 2002:a05:620a:29c8:b0:6b5:ea23:afc8 with SMTP id s8-20020a05620a29c800b006b5ea23afc8mr11410609qkp.105.1658341439881; Wed, 20 Jul 2022 11:23:59 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uJzxbBUUzdLENvVuY3fMKuHbw090V244BOiZ3cHYLqNoTWtqgmynmkPQAmQ4mvPjWmuFPGQQ== X-Received: by 2002:a05:620a:29c8:b0:6b5:ea23:afc8 with SMTP id s8-20020a05620a29c800b006b5ea23afc8mr11410601qkp.105.1658341439660; Wed, 20 Jul 2022 11:23:59 -0700 (PDT) Received: from t14s.localdomain (c-73-69-212-193.hsd1.ma.comcast.net. [73.69.212.193]) by smtp.gmail.com with ESMTPSA id bj30-20020a05620a191e00b006b59f02224asm8478846qkb.60.2022.07.20.11.23.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 11:23:58 -0700 (PDT) Message-ID: Subject: Re: [PATCH] Adding three new function attributes for static analysis of file descriptors From: David Malcolm To: mirimnan017@gmail.com, gcc-patches@gcc.gnu.org Cc: Immad Mir Date: Wed, 20 Jul 2022 14:23:57 -0400 In-Reply-To: References: User-Agent: Evolution 3.38.4 (3.38.4-1.fc33) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Jul 2022 18:24:05 -0000 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