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 EBB3E3857404 for ; Fri, 25 Mar 2022 18:45:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EBB3E3857404 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-595-7yOtfbw-NGKS_QjV1KZWIg-1; Fri, 25 Mar 2022 14:45:07 -0400 X-MC-Unique: 7yOtfbw-NGKS_QjV1KZWIg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 88B959219A4; Fri, 25 Mar 2022 18:45:06 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.2.17.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3546D400F8CB; Fri, 25 Mar 2022 18:45:05 +0000 (UTC) From: David Malcolm To: Sebastian Huber , Martin Sebor , gcc-patches@gcc.gnu.org, gcc@gcc.gnu.org Subject: [PATCH v3] Document that the 'access' and 'nonnull' attributes are independent Date: Fri, 25 Mar 2022 14:45:02 -0400 Message-Id: <20220325184502.761115-1-dmalcolm@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.8 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_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Mar 2022 18:45:10 -0000 On Wed, 2022-03-23 at 17:52 +0100, Sebastian Huber wrote: > On 23/03/2022 17:31, Martin Sebor via Gcc-patches wrote: > > > > The concern is that the constraints implied by atttributes access > > and > > nonnull are independent of each other. I would suggest to document > > that without talking about dereferencing because that's not implied > > by either of them. E.g., something like this (feel free to tweak > > it > > as you see fit): > > > > Note that the @code{access} attribute doesn't imply the same > > constraint as attribute @code{nonnull} (@pxref{Attribute > > nonnull}). > > The latter attribute should be used to annotate arguments that > > must > > never be null, regardless of the value of the size argument. > > I would not give an advice on using the nonnull attribute here. This > attribute could have pretty dangerous effects in the function > definition > (removal of null pointer checks). > That's a fair point. Here's a v3 of the patch, which tones down the advice, and mentions that there are caveats when directing the reader to the "nonnull" attribute. How does this look? gcc/ChangeLog: * doc/extend.texi (Common Function Attributes): Document that 'access' does not imply 'nonnull'. Signed-off-by: David Malcolm --- gcc/doc/extend.texi | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index a4a25e86928..539dad7001d 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -2652,6 +2652,14 @@ The mode is intended to be used as a means to help validate the expected object size, for example in functions that call @code{__builtin_object_size}. @xref{Object Size Checking}. +Note that the @code{access} attribute merely specifies how an object +referenced by the pointer argument can be accessed; it does not imply that +an access @strong{will} happen. Also, the @code{access} attribute does not +imply the attribute @code{nonnull}; it may be appropriate to add both attributes +at the declaration of a function that unconditionally manipulates a buffer via +a pointer argument. See the @code{nonnull} attribute for more information and +caveats. + @item alias ("@var{target}") @cindex @code{alias} function attribute The @code{alias} attribute causes the declaration to be emitted as an alias -- 2.26.3