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: 62930 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 78F033858C83 for ; Wed, 11 Jan 2023 09:53:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 78F033858C83 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673430813; bh=3zhW3FdEivzAGKWc8STxivbY1eCFKqWUsD0ZbP67SGE=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=cs+3A2WHq/rWyS6sDuxoYOZi//Y2oQOH63bOekp8wtfdN1eS+IajHuin+szqyj09c LSMHx/U9qm2g/DYjXFgNLNwOwDY7/8PLZnqZlHwMFG7C/b+D1P3YFplLZNw2pwKftN QOZev9ajhgRW9tZeN1SJxputjC9xdCj87G7/8Y70= 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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" } +}