From patchwork Thu Feb 21 23:00:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 1046494 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-496842-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="tsrYs35C"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="HtA7A9yE"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44591g5Cn4z9s9L for ; Fri, 22 Feb 2019 10:00:55 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=jK5eNi4fRJ14jtB+I5o7ivx+Fv1kroJvnZmIoAfL+QN+pLOF6W C0ocedx55YnY7PYsMj8cIVGYJidQylHHGWXWpaCKBsCOiusMDRH2Azr8xUGt/X9W Wdtxsc2vo+m5Y3VeVWjzliyobOPj0E9sI1ZqJfX2wBFQL8LazedQ01cvQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=86yo6UAROkaPqc7+VtJs2HYOi1c=; b=tsrYs35C+hZJuTRZMJ4z dvPsoP7gNe/yWNgrg4juw5sB8K0Out0eMnKA4aGhtUcOV6nILVg3KoEktZ3+STaz 46uGGVEx2WDlKOrUfYvaGdHIeSsHp0GhilyKzDL9ZBNNWAwnl/5FRvNzA4Z67vtB fKB+/Ox6d2ZRzzgvPAAwUzU= Received: (qmail 72365 invoked by alias); 21 Feb 2019 23:00:44 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 67648 invoked by uid 89); 21 Feb 2019 23:00:36 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=unavailable version=3.3.2 spammy=c-parser.c, cparserc, UD:c-parser.c, 269041 X-HELO: mail-qt1-f173.google.com Received: from mail-qt1-f173.google.com (HELO mail-qt1-f173.google.com) (209.85.160.173) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 21 Feb 2019 23:00:14 +0000 Received: by mail-qt1-f173.google.com with SMTP id o6so390989qtk.6 for ; Thu, 21 Feb 2019 15:00:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=q17rqakwkyqlRHV5Jzy9ZgxUIpy6v5Ud7rS4LacNcL8=; b=HtA7A9yEpmImKp2BfT+/Gr+J4yH0WMmTLbrCdASKUi83oq5cQu3YuVP9QhtdW5Ot4S 2xIXue7WZ4qHBB6eyy8eLb0k9M4S1sKZK9I9Dt8UYgVKZjS/qnQelJyzTCxqNmzBbt08 S2tQABntqPDqaP5sXUu55KedaUdnjufn0hbHbD2ifSxEePjh/CpSLNwmR67ISbXD0sUg YOSnva+3mVbg/2uq2bUOigbrIjVHWJXenWEdWaLpOmzu8Lb0rdNJ9MIhknf4xCbpvv+H k8ViLnxxGMfxck5KPEYhe6rXOrZD5u2jobfBoLyl+SoUQuGHaYifIkTJOEsz45v7CFRl Vj0Q== Received: from [192.168.0.106] (174-16-104-92.hlrn.qwest.net. [174.16.104.92]) by smtp.gmail.com with ESMTPSA id g49sm163657qtg.24.2019.02.21.15.00.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Feb 2019 15:00:03 -0800 (PST) To: "gcc-patches@gcc.gnu.org" From: Martin Sebor Subject: [PATCH] avoid -Wabsolute-value in dead subexpressions (PR 89425) Message-ID: Date: Thu, 21 Feb 2019 16:00:02 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 MIME-Version: 1.0 X-IsSubscribed: yes Joseph noticed the -Wabsolute-value warning newly introduced in GCC 9 and included in -Wextra triggers on some unreachable subexpressions in Glibc code that the C front end otherwise makes an effort to avoid diagnosing. The attached trivial patch guards the warning to avoid these spurious instances. Tested on x86_64-linux. Similarly to other warnings like it, -Wabsolute-value still triggers in unreachable statements but the only way to deal with those instances would be to move all such warnings into the middle-end. Martin PR c/89425 - -Wabsolute-value warns in dead subexpressions gcc/c/ChangeLog: PR c/89425 * c-parser.c (sizeof_ptr_memacc_comptypes): Avoid warning in unreachable subexpressions. gcc/testsuite/ChangeLog: PR c/89425 * gcc.dg/Wabsolute-value.c: New test. Index: gcc/c/c-parser.c =================================================================== --- gcc/c/c-parser.c (revision 269041) +++ gcc/c/c-parser.c (working copy) @@ -9374,6 +9374,10 @@ sizeof_ptr_memacc_comptypes (tree type1, tree type static void warn_for_abs (location_t loc, tree fndecl, tree arg) { + /* Avoid warning in unreachable subexpressions. */ + if (c_inhibit_evaluation_warnings) + return; + tree atype = TREE_TYPE (arg); /* Casts from pointers (and thus arrays and fndecls) will generate Index: gcc/testsuite/gcc.dg/Wabsolute-value.c =================================================================== --- gcc/testsuite/gcc.dg/Wabsolute-value.c (nonexistent) +++ gcc/testsuite/gcc.dg/Wabsolute-value.c (working copy) @@ -0,0 +1,57 @@ +/* PR c/89425 - -Wabsolute-value warns in dead subexpressions + { dg-do compile } + { dg-options "-Wabsolute-value -ftrack-macro-expansion=0" } */ + +struct Vals +{ + signed char sc; + signed short ss; + signed int si; + signed long sl; + signed long long sll; + + unsigned char uc; + unsigned short us; + unsigned int ui; + unsigned long ul; + unsigned long long ull; + + float f; + double d; + long double ld; +}; + +#define abs(x) __builtin_abs (x) +#define labs(x) __builtin_labs (x) +#define llabs(x) __builtin_llabs (x) + +#define fabsf(x) __builtin_fabsf (x) +#define fabs(x) __builtin_fabs (x) + + +void tst_warn (struct Vals *p) +{ + /* Verify that "-Wabsolute-value is issued for subexpressions + that are evaluated. */ + + p->uc = 0 ? abs (p->sc) : abs (p->uc); /* { dg-warning "\\\[-Wabsolute-value]" } */ + p->us = 0 ? abs (p->ss) : abs (p->us); /* { dg-warning "\\\[-Wabsolute-value]" } */ + p->ui = 0 ? abs (p->si) : abs (p->ui); /* { dg-warning "\\\[-Wabsolute-value]" } */ + p->ul = 0 ? labs (p->sl) : labs (p->ul); /* { dg-warning "\\\[-Wabsolute-value]" } */ + p->ull = 0 ? llabs (p->sll) : llabs (p->ull); /* { dg-warning "\\\[-Wabsolute-value]" } */ + + p->d = 0 ? fabs (p->d) : fabsf (p->d); /* { dg-warning "\\\[-Wabsolute-value]" } */ +} + +void tst_no_warn (struct Vals *p) +{ + /* Verify that "-Wabsolute-value is not issued for subexpressions + that are not evaluated. */ + + p->uc = 0 ? abs (p->uc) : abs (p->sc); + p->us = 0 ? abs (p->us) : abs (p->ss); + p->ui = 0 ? abs (p->ui) : abs (p->si); + p->ul = 0 ? labs (p->ul) : labs (p->sl); + p->ull = 0 ? llabs (p->ull) : llabs (p->sll); + p->d = 0 ? fabsf (p->d) : fabs (p->d); +}