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: 56107 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E3DAD385416F for ; Sat, 16 Jul 2022 12:54:40 +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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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; +} +