From patchwork Sun Oct 15 13:34:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 23577 Received: (qmail 21042 invoked by alias); 15 Oct 2017 13:35:00 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 21023 invoked by uid 89); 15 Oct 2017 13:34:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.9 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=silence, silences X-HELO: mail-oi0-f47.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=qdcPgotwm1tGYhgv8PJnLjM74pgU92IjZOezgLku+ss=; b=MhafT+2QixbT4BdC2ADfocnetDUdOzXwoViI3GLjAf+YWF1uc0F/QKxsre1DF8eLXe 4zJsVba6pptfmpn1/W7Ua7T3y4gGnU5m0Mp/77z4ksAEdSqS1qhYb26x1MSG+SEDF4Uq Xs+fMzxKF8z64dyngP2l32fXqUNSsKBuMazORbVIesv5RstcyOuTzBGocnlCTjswJeXu B3qJmrlVqtiG/UL3xemztOZEF9tGV8hT2rg9/R0pA6vG9ONnsy98tBkUax1DavyD3M0c pz/kF3QrahdHPEig9VFqNebGKkVJqPhIF4lk84fZyccf/3jfUKf6PEOaXhsL5/o4v27j 2Ucg== X-Gm-Message-State: AMCzsaXs6220H0sey8IM4QyD0slO+2sDr8XWfhuLYbPFHNGaQL507zeH 7RqvrfLUPsiviAUprRsnqteSa0Ye2tDRo8QOf4w= X-Google-Smtp-Source: AOwi7QDT8W2qQh30J9pEySry2U+1uYt0UImwfwC0gfQ5XYT0Q0ux9drsmczPboIxTcn+pAyz/hi+AsxstGz+5enfG1s= X-Received: by 10.157.43.104 with SMTP id f37mr3950703otd.491.1508074496426; Sun, 15 Oct 2017 06:34:56 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: "H.J. Lu" Date: Sun, 15 Oct 2017 06:34:55 -0700 Message-ID: Subject: Re: [PATCH] Silence -O3 -Wall warning in malloc/hooks.c with GCC 7 [BZ #22052] To: Florian Weimer Cc: "Carlos O'Donell" , GNU C Library On Mon, Sep 18, 2017 at 7:02 AM, Florian Weimer wrote: > On 09/04/2017 10:29 PM, H.J. Lu wrote: >> >> On Mon, Sep 4, 2017 at 1:33 AM, Florian Weimer wrote: >>> >>> On 09/03/2017 05:48 PM, H.J. Lu wrote: >>>> >>>> + unsigned char *magic_p = NULL; >>> >>> >>> I think the current practice is to use to suppress the >>> warning. >> >> >> Is there a usage example for this warning? > > > Search for DIAG_PUSH_NEEDS_COMMENT in the sources. > Here is a patch. Tested on x86-64. I am going to check it in. Thanks. From aca3e9b42f9c172af368f2fc54d2c7299b231cc0 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Sun, 3 Sep 2017 08:39:55 -0700 Subject: [PATCH] Silence -O3 -Wall warning in malloc/hooks.c with GCC 7 [BZ #22052] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit realloc_check has unsigned char *magic_p; ... __libc_lock_lock (main_arena.mutex); const mchunkptr oldp = mem2chunk_check (oldmem, &magic_p); __libc_lock_unlock (main_arena.mutex); if (!oldp) malloc_printerr ("realloc(): invalid pointer"); ... if (newmem == NULL) *magic_p ^= 0xFF; with static void malloc_printerr(const char *str) __attribute__ ((noreturn)); GCC 7 -O3 warns hooks.c: In function ‘realloc_check’: hooks.c:352:14: error: ‘magic_p’ may be used uninitialized in this function [-Werror=maybe-uninitialized] *magic_p ^= 0xFF; This patch silences GCC 7 by using DIAG_IGNORE_NEEDS_COMMENT. [BZ #22052] * malloc/hooks.c (realloc_check): Use DIAG_IGNORE_NEEDS_COMMENT to silence -O3 -Wall warning GCC 7. --- malloc/hooks.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/malloc/hooks.c b/malloc/hooks.c index 01be076f5e..17d8907727 100644 --- a/malloc/hooks.c +++ b/malloc/hooks.c @@ -345,11 +345,18 @@ realloc_check (void *oldmem, size_t bytes, const void *caller) newmem = _int_realloc (&main_arena, oldp, oldsize, nb); } + DIAG_PUSH_NEEDS_COMMENT; +#if __GNUC_PREREQ (7, 0) + /* GCC 7 warns about magic_p may be used uninitialized. But we never + reach here if magic_p is uninitialized. */ + DIAG_IGNORE_NEEDS_COMMENT (7, "-Wmaybe-uninitialized"); +#endif /* mem2chunk_check changed the magic byte in the old chunk. If newmem is NULL, then the old chunk will still be used though, so we need to invert that change here. */ if (newmem == NULL) *magic_p ^= 0xFF; + DIAG_POP_NEEDS_COMMENT; __libc_lock_unlock (main_arena.mutex); -- 2.13.5