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 9B4DE3858405 for ; Fri, 22 Jul 2022 18:27:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9B4DE3858405 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-159-UHX4mt4YNdmePWRCY_QyAQ-1; Fri, 22 Jul 2022 14:27:42 -0400 X-MC-Unique: UHX4mt4YNdmePWRCY_QyAQ-1 Received: by mail-qk1-f199.google.com with SMTP id o13-20020a05620a2a0d00b006b46c5414b0so4334694qkp.23 for ; Fri, 22 Jul 2022 11:27:42 -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=4y1//ceUuTdbNV67sT05nrUo2XcP9nP+No6tz6v+G7c=; b=2AjKgtRD80ewA269f+HvbMRmIgJUO5PZfeuEjC/bDDux4lbIPq34d0I5e+kGj6GaX5 a0TxXrapPTfjgqEmXTzRhtOiNgMj+FNF42gwXY3zYpvnEOzr5tlwwEIlTtrWqX1jv3oQ 7IkDgl3dDaD6jwlzLKA1yaSpzDmLQD5bfL94ucIJs8SHAvnCAOhYenPcuTgl+Tx70rv3 AiyECawisXvEyGRo4Jm5hCiXto04MIKn9pTtehB4muxkdlfZTInDSL2pAl1I9soJs7mL gW7kKepD7o89V7rLgIOq4RLOxhwtjunz/MBL0uOBxmvzfhujL3YMr0S0xHAgEBEg0W/f LUJA== X-Gm-Message-State: AJIora8/27xvaz9DbPmqR7JyN6yfEUrqtEVBj4J4RlKkBtckgnXsDhmK ll23sDQ3tQghPE+LaqOfYnk5xQFfZPxhjSfSGDPjF/x4cERgwuLVpjB8cZUEt8II/smzy8qeUfK hpnDbCp/phwHkLZr7kw== X-Received: by 2002:a05:620a:4891:b0:6b5:e281:afdf with SMTP id ea17-20020a05620a489100b006b5e281afdfmr951329qkb.249.1658514461540; Fri, 22 Jul 2022 11:27:41 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sDfXGIYA4HxK1bCfn8EzrlncLpvtz9xrskKaQEHRRgksUeOsDS6OrwH/hYdZu/Yv4ovITJgw== X-Received: by 2002:a05:620a:4891:b0:6b5:e281:afdf with SMTP id ea17-20020a05620a489100b006b5e281afdfmr951316qkb.249.1658514461297; Fri, 22 Jul 2022 11:27:41 -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 k7-20020a05620a414700b006b5e5ebfff8sm4272612qko.62.2022.07.22.11.27.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 11:27:40 -0700 (PDT) Message-ID: <1f26d57a28c70da7bd2bdec0182816ebdaaede6f.camel@redhat.com> 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: Fri, 22 Jul 2022 14:27:39 -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=-6.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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: Fri, 22 Jul 2022 18:27:46 -0000 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