From patchwork Sat Jul 16 12:54:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 27 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a98:d5ce:0:b0:178:cc93:bf7d with SMTP id g14csp900998eik; Sat, 16 Jul 2022 05:54:54 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tsDU/QEnFcgl5pSb8TtrVk7S7sjXcLweTEaphqfT3oujRkcxEBqTx94ptA+9cqd/k59WYj X-Received: by 2002:aa7:d3d9:0:b0:43b:4e30:5708 with SMTP id o25-20020aa7d3d9000000b0043b4e305708mr5857799edr.192.1657976094776; Sat, 16 Jul 2022 05:54:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657976094; cv=none; d=google.com; s=arc-20160816; b=wiXpHTwRfNpkkPJOrZSGu1BtE4LK4tbJ4+fFIyGeOIqsyxlAIGaFfTAhmTecNDI0Jf bUB/5HDdXDfxeJti0IHRyS5UeRUILWuidTc9dc4C96ng+FgnMGD/iilYcjFZsXIzZuI3 FZ9ZAxcjOEJrB2gujQztP0N90qsssgUW4sE7VYSnZW8roMoJSGP6WRyBvUhKeBUevGZR xVySe+eL/qjdcieJnmDYFzw+rjONii7BmLE0jv3xoVL7+t8Pu7z8KiGILpGs6om+whM4 SIiFMg/WYxcOX3Kb8jUu1BhIlsEGxU2CFbYX9N73R1PaKAycb5UBH9QIPrFb0KZwAOC/ HHYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-language:thread-index :mime-version:message-id:date:subject:to:from:dkim-signature :dmarc-filter:delivered-to; bh=dD4jthOeHSlPTaXLlKkVpkc/H3i0/e1f2hgzxfy5Z1o=; b=n42RIJosJihPT9cFoJ/qxe4wclsm904cBlNmU0lgfmHY00uXUd26Uvls5yoc76zU89 63TZAOXzwOFFPP0cNrOFgRIf9g4yzBAmGWFNJrphSUr7ep9+D/rFiNYk/Eu2inY8ZZP3 I/LpHc2WGrviOXkgkLYnwznpx+//YP7aaGsGy3ckELB9wTD+Gw4t+vvR7fse6mbo2hOV fDEECA2yE4/rqsvwL+zYZn754JYOCCaWWdAQFHDsH+Upr8epR5UUGfaHO3IWJ4nIub0q 6n8zZBVfJaGUeUniTT9QjF58t6gHcruyDqn2ldD7PGKbbq2eGJS83pc41xhUYzCpZSom 2sJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@nextmovesoftware.com header.s=default header.b=FchV+gXe; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id b9-20020a056402084900b00436f2e1a564si2435918edz.476.2022.07.16.05.54.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Jul 2022 05:54:54 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=fail header.i=@nextmovesoftware.com header.s=default header.b=FchV+gXe; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4F01B384A893 for ; Sat, 16 Jul 2022 12:54:48 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id B512D3858280 for ; Sat, 16 Jul 2022 12:54:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B512D3858280 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nextmovesoftware.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=dD4jthOeHSlPTaXLlKkVpkc/H3i0/e1f2hgzxfy5Z1o=; b=FchV+gXedHuXslsGpnqOIrIjQd gWreDAKkW2ckPx8ZeEqd1CdQdQCEeyGsXoXnWNDfpX+VROX7nf/8BW6+/wlieEPrOWXSde+XLJdQQ j5YmwJOhoJK8UrxtfiW9ewoUwCDsYCc0AWC/3OFYq4e6zv3Yr9MDhU0RHzBWb8LKQKZcU2tP45IhT MhsfF+Yw8WVjMXMNHRlBZVm93bcRLPea8BUjBd6/5Q7QqD52uuh8l0jzy/ceZ0RpIcfDl8UCTEzvv 581S9NzgLIQtOw4VimJX5HwuDPno5JSymUDAG8j9pUVI/WHAEcoX4cx6y5VB3qesTCPD2guG+Cxt5 Pj0C7tqQ==; Received: from host109-154-33-170.range109-154.btcentralplus.com ([109.154.33.170]:51948 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1oChJQ-0002Df-2i for gcc-patches@gcc.gnu.org; Sat, 16 Jul 2022 08:54:24 -0400 From: "Roger Sayle" To: "'GCC Patches'" Subject: [middle-end PATCH] PR c/106264: Silence warnings from __builtin_modf et al. Date: Sat, 16 Jul 2022 13:54:23 +0100 Message-ID: <019501d89913$2d1ccc40$875664c0$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdiZErLNCV3CemaOTaaVybLcsj3ZJg== Content-Language: en-gb X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server.nextmovesoftware.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - nextmovesoftware.com X-Get-Message-Sender-Via: server.nextmovesoftware.com: authenticated_id: roger@nextmovesoftware.com X-Authenticated-Sender: server.nextmovesoftware.com: roger@nextmovesoftware.com X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, SPF_HELO_NONE, SPF_PASS, 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-LABELS: =?utf-8?b?IlxcSW1wb3J0YW50Ig==?= X-GMAIL-THRID: =?utf-8?q?1738513941561469489?= X-GMAIL-MSGID: =?utf-8?q?1738513941561469489?= This middle-end patch resolves PR c/106264 which is a spurious warning regression caused by the tree-level expansion of modf, frexp and remquo producing "expression has no-effect" when the built-in function's result is ignored. When these built-ins were first expanded at tree-level, fold_builtin_n would blindly set TREE_NO_WARNING for all built-ins. Now that we're more discerning, we should precisely set TREE_NO_WARNING selectively on those COMPOUND_EXPRs that need them. This patch has been tested on x86_64-pc-linux-gnu with make bootstrap and make -k check with no new failures. Ok for mainline? 2022-07-16 Roger Sayle gcc/ChangeLog PR c/106264 * builtins.cc (fold_builtin_frexp): Set TREE_NO_WARNING on COMPOUND_EXPR to silence spurious warning if result isn't used. (fold_builtin_modf): Likewise. (do_mpfr_remquo): Likewise. gcc/testsuite/ChangeLog PR c/106264 * gcc.dg/pr106264.c: New test case. Thanks in advance, Roger diff --git a/gcc/builtins.cc b/gcc/builtins.cc index 35b9197..c745777 100644 --- a/gcc/builtins.cc +++ b/gcc/builtins.cc @@ -8625,7 +8625,7 @@ fold_builtin_frexp (location_t loc, tree arg0, tree arg1, tree rettype) if (TYPE_MAIN_VARIANT (TREE_TYPE (arg1)) == integer_type_node) { const REAL_VALUE_TYPE *const value = TREE_REAL_CST_PTR (arg0); - tree frac, exp; + tree frac, exp, res; switch (value->cl) { @@ -8656,7 +8656,9 @@ fold_builtin_frexp (location_t loc, tree arg0, tree arg1, tree rettype) /* Create the COMPOUND_EXPR (*arg1 = trunc, frac). */ arg1 = fold_build2_loc (loc, MODIFY_EXPR, rettype, arg1, exp); TREE_SIDE_EFFECTS (arg1) = 1; - return fold_build2_loc (loc, COMPOUND_EXPR, rettype, arg1, frac); + res = fold_build2_loc (loc, COMPOUND_EXPR, rettype, arg1, frac); + TREE_NO_WARNING (res) = 1; + return res; } return NULL_TREE; @@ -8682,6 +8684,7 @@ fold_builtin_modf (location_t loc, tree arg0, tree arg1, tree rettype) { const REAL_VALUE_TYPE *const value = TREE_REAL_CST_PTR (arg0); REAL_VALUE_TYPE trunc, frac; + tree res; switch (value->cl) { @@ -8711,8 +8714,10 @@ fold_builtin_modf (location_t loc, tree arg0, tree arg1, tree rettype) arg1 = fold_build2_loc (loc, MODIFY_EXPR, rettype, arg1, build_real (rettype, trunc)); TREE_SIDE_EFFECTS (arg1) = 1; - return fold_build2_loc (loc, COMPOUND_EXPR, rettype, arg1, - build_real (rettype, frac)); + res = fold_build2_loc (loc, COMPOUND_EXPR, rettype, arg1, + build_real (rettype, frac)); + TREE_NO_WARNING (res) = 1; + return res; } return NULL_TREE; @@ -10673,8 +10678,10 @@ do_mpfr_remquo (tree arg0, tree arg1, tree arg_quo) integer_quo)); TREE_SIDE_EFFECTS (result_quo) = 1; /* Combine the quo assignment with the rem. */ - result = non_lvalue (fold_build2 (COMPOUND_EXPR, type, - result_quo, result_rem)); + result = fold_build2 (COMPOUND_EXPR, type, + result_quo, result_rem); + TREE_NO_WARNING (result) = 1; + result = non_lvalue (result); } } } diff --git a/gcc/testsuite/gcc.dg/pr106264.c b/gcc/testsuite/gcc.dg/pr106264.c new file mode 100644 index 0000000..6b4af49 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr106264.c @@ -0,0 +1,27 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wall" } */ +double frexp (double, int*); +double modf (double, double*); +double remquo (double, double, int*); + +int f (void) +{ + int y; + frexp (1.0, &y); + return y; +} + +double g (void) +{ + double y; + modf (1.0, &y); + return y; +} + +int h (void) +{ + int y; + remquo (1.0, 1.0, &y); + return y; +} +