From patchwork Wed Jan 11 09:52:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 41870 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3226915wrt; Wed, 11 Jan 2023 01:53:49 -0800 (PST) X-Google-Smtp-Source: AMrXdXulz1Cz8xlnn4kfZSdi3ZsQb05lIQ7PYBSFX6L97gfKD4YitHZ9gD0WGHhJlxU4/eIJscij X-Received: by 2002:a17:907:cca7:b0:84d:ed5:a406 with SMTP id up39-20020a170907cca700b0084d0ed5a406mr16172744ejc.14.1673430829535; Wed, 11 Jan 2023 01:53:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673430829; cv=none; d=google.com; s=arc-20160816; b=Gu2/ezMdLTgAt6e3IT7xxMrU88PEHvT5GLKSeoQ5FXot3P5inia79pMUHpvQ999W84 mO2vWzAhSFcDPp2HobZgzWyRoENbox7pDh5Q/yH+BeZ/q2r0orWBku2FM7rKVL388pKC u1UAEhN459mguCW7p4BgY3UDOS6DLXooHZTIK2fo4h8+GS1yp0v3FXEFWlvobRFXWmuL spWFdDNoOKNAsH8m7paF/pjAB6uZ3Ft0xEDX9HBXq8jm0XCGqQQ9i3AUTYIdpdlR1PJQ NF837hrLOGDhmpenVRh+FiZ1o9mooF9cMFScm5ybDlc5c5Y+uPovr3+B4YI+6oDnl8Cr JovA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=3zhW3FdEivzAGKWc8STxivbY1eCFKqWUsD0ZbP67SGE=; b=iLTn9LyW87Jyp82S3TI7qAlEN8TeLDJmSGh62KMvIz7cJMRfzjD4/CrctvclHvm0tE 5NXEXDlvwpMYzRO65eEKLE1O4EALZEwpa5W+avmmMWEiRfE2/XspNlr7w0RU7WgnsVAW 1+nsPQ52x+MxxjMwBwb2r7gCB0uhNU1t1q5jxfcKG0Wid/cm9EP1OnOWFd1argy8CVW4 4s1OrJ2hyTQNfbj3AW0c6SiOQYxLpQu9Xmn69MUd8CKE3KT2agA+XYSBE9mhRSkoZQye WyuaeHbeJNq4159Ly230dNBZzkBcuXYSOgDHlmjZtX+zRdQ7JNOqBflgaMNug5hss6gg ObOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=md6JjWaE; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id dm8-20020a170907948800b007c08000a65esi16179493ejc.756.2023.01.11.01.53.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jan 2023 01:53:49 -0800 (PST) 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=pass header.i=@gcc.gnu.org header.s=default header.b=md6JjWaE; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6DD7B3858005 for ; Wed, 11 Jan 2023 09:53:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6DD7B3858005 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673430828; bh=3zhW3FdEivzAGKWc8STxivbY1eCFKqWUsD0ZbP67SGE=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=md6JjWaEyB4ZAVgQFFtVXnEzmGVew5GozuhbupDKd8Y0AqQ/l54qanewUK+ylWi4R rERZvfWzpbn59p/nSHWL29sVYfqJIgl0IG5JIo/iIzW4qTHd33QgB6aKDsoPcf9xKG 6tcUh4ZH05Z1f2qnduvPmP6CaMz7pVYl/GXNTRIo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 495E83858CDA for ; Wed, 11 Jan 2023 09:53:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 495E83858CDA Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-158-4krz-jHdPMaoTHz8GAs_GA-1; Wed, 11 Jan 2023 04:53:01 -0500 X-MC-Unique: 4krz-jHdPMaoTHz8GAs_GA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E16F02807D63 for ; Wed, 11 Jan 2023 09:53:00 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 98D71140EBF4; Wed, 11 Jan 2023 09:53:00 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 30B9qvpO1300668 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 11 Jan 2023 10:52:58 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 30B9qvEA1300665; Wed, 11 Jan 2023 10:52:57 +0100 Date: Wed, 11 Jan 2023 10:52:52 +0100 To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Avoid some false positive -Wfloat-conversion warnings with extended precision [PR108285] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek 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-THRID: =?utf-8?q?1754719405508769447?= X-GMAIL-MSGID: =?utf-8?q?1754719405508769447?= Hi! On the following testcase trunk emits a false positive warning on ia32. convert_like_internal is there called with type of double and expr EXCESS_PRECISION_EXPR with float type with long double operand 2.L * (long double) x. Now, for the code generation we do the right thing, cp_convert to double from that 2.L * (long double) x, but we call even cp_convert_and_check with that and that emits the -Wfloat-conversion warning. Looking at what the C FE does in this case, it calls convert_and_check with the EXCESS_PRECISION_EXPR expression rather than its operand, and essentially uses the operand for code generation and EXCESS_PRECISION_EXPR itself for warnings. The following patch does that too for the C++ FE. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-01-11 Jakub Jelinek PR c++/108285 * cvt.cc (cp_convert_and_check): For EXCESS_PRECISION_EXPR use its operand except that for warning purposes use the original EXCESS_PRECISION_EXPR. * call.cc (convert_like_internal): Only look through EXCESS_PRECISION_EXPR when calling cp_convert, not when calling cp_convert_and_check. * g++.dg/warn/pr108285.C: New test. Jakub --- gcc/cp/cvt.cc.jj 2022-10-14 09:32:32.403797521 +0200 +++ gcc/cp/cvt.cc 2023-01-10 13:53:00.639130717 +0100 @@ -652,8 +652,10 @@ cp_convert (tree type, tree expr, tsubst tree cp_convert_and_check (tree type, tree expr, tsubst_flags_t complain) { - tree result; + tree result, expr_for_warning = expr; + if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR) + expr = TREE_OPERAND (expr, 0); if (TREE_TYPE (expr) == type) return expr; if (expr == error_mark_node) @@ -663,7 +665,7 @@ cp_convert_and_check (tree type, tree ex if ((complain & tf_warning) && c_inhibit_evaluation_warnings == 0) { - tree folded = cp_fully_fold (expr); + tree folded = cp_fully_fold (expr_for_warning); tree folded_result; if (folded == expr) folded_result = result; --- gcc/cp/call.cc.jj 2023-01-09 23:41:11.135159084 +0100 +++ gcc/cp/call.cc 2023-01-10 13:50:09.277640628 +0100 @@ -8863,12 +8863,14 @@ convert_like_internal (conversion *convs return error_mark_node; warning_sentinel w (warn_zero_as_null_pointer_constant); - if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR) - expr = TREE_OPERAND (expr, 0); if (issue_conversion_warnings) expr = cp_convert_and_check (totype, expr, complain); else - expr = cp_convert (totype, expr, complain); + { + if (TREE_CODE (expr) == EXCESS_PRECISION_EXPR) + expr = TREE_OPERAND (expr, 0); + expr = cp_convert (totype, expr, complain); + } return expr; } --- gcc/testsuite/g++.dg/warn/pr108285.C.jj 2023-01-10 16:52:06.115345345 +0100 +++ gcc/testsuite/g++.dg/warn/pr108285.C 2023-01-10 16:39:26.646532929 +0100 @@ -0,0 +1,11 @@ +// PR c++/108285 +// { dg-do compile } +// { dg-options "-fexcess-precision=standard -Wfloat-conversion" } + +void bar (double); + +void +foo (float x) +{ + bar (2 * x); // { dg-bogus "conversion from '\[^\n\r]\*' to 'double' may change value" } +}