From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 62851 invoked by alias); 29 Sep 2019 17:36:34 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 62829 invoked by uid 89); 29 Sep 2019 17:36:32 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=have, up, rely, reflected X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 29 Sep 2019 17:36:30 +0000 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E815130821AE; Sun, 29 Sep 2019 17:36:28 +0000 (UTC) Received: from localhost.localdomain (ovpn-112-6.rdu2.redhat.com [10.10.112.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id A1BFB1001B12; Sun, 29 Sep 2019 17:36:26 +0000 (UTC) Subject: Re: [PATCH] declare bcmp, bcopy, and bzero nonnull (PR 80936) To: Martin Sebor , gcc-patches References: <834b10eb-95e1-c84e-1c9f-57fbe9228328@gmail.com> From: Jeff Law Openpgp: preference=signencrypt Message-ID: <1101626c-0149-945d-9cbd-9e94ab1a378d@redhat.com> Date: Sun, 29 Sep 2019 17:36:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <834b10eb-95e1-c84e-1c9f-57fbe9228328@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2019-09/txt/msg01688.txt.bz2 On 9/27/19 1:06 PM, Martin Sebor wrote: > GCC declares bcmp, bcopy, and bzero without the nonnull attribute. > This was a deliberate decision as is reflected in the comment in > builtins.def: > > /* bcmp, bcopy and bzero have traditionally accepted NULL pointers >    when the length parameter is zero, so don't apply attribute > "nonnull".  */ > > But the SUSv3, Issue 6 marks the functions as legacy and recommends > portable applications to replace calls to the functions with the C > standard equivalents as follows: > >   #define bcmp(b1,b2,len) memcmp((b1), (b2), (size_t)(len)) > > (The legacy functions have been removed from POSIX in Issue 7.) > > The C standard functions do require their arguments to be nonnull. > > Some libcs (e.g., Glibc) implement the legacy functions in terms > of the C standard equivalents.  Others (e.g., libiberty) rely on > strictly undefined behavior in their implementation of these > function (null pointer arithmetic). > > Finally, GCC has been transforming calls to the legacy functions > to the C standard equivalents for a few releases, and making > the same assumptions about their arguments (i.e., eliminating > tests for their pointer arguments being null subsequent to > the calls). > > To help detect some of the same mistakes in calls to the legacy > functions as in the standard ones the attached adds the nonnull > attribute to all three of them. > > Tested on x86_64-linux.  Compiling Binutils/GDB and Glibc with > the patch doesn't turn up any -Wnonnull instances. > > Martin > > gcc-80936.diff > > PR tree-optimization/80936 - bcmp, bcopy, and bzero not declared nonnull > > gcc/testsuite/ChangeLog: > > PR tree-optimization/80936 > * gcc.dg/Wnonnull-2.c: New test. > * gcc.dg/Wnonnull-3.c: New test. > * gcc.dg/nonnull-3.c: Expect more warnings. > > gcc/ChangeLog: > > PR tree-optimization/80936 > * builtins.def (bcmp, bcopy, bzero): Declare nonnull. OK. I'll be doing another Fedora rebuild relatively soon, so we'll have a chance to see if there's fallout on a wider codebase. I don't expect significant issues. jeff