From patchwork Wed Feb 8 08:59:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 54262 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp3342577wrn; Wed, 8 Feb 2023 01:00:15 -0800 (PST) X-Google-Smtp-Source: AK7set/+CPKDl/bS48UAB8E2/V3VCLu8autGadgVrFAjZ9eQJFvQa4OEo8LgwnuOzcG+OyP98QZm X-Received: by 2002:a17:906:3896:b0:87b:db53:3829 with SMTP id q22-20020a170906389600b0087bdb533829mr6351467ejd.46.1675846815256; Wed, 08 Feb 2023 01:00:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675846815; cv=none; d=google.com; s=arc-20160816; b=Ti7D2Y6oeLrp54wW+sBj3tt4SIAQ6OXQ8xSafXcKe1i0VG0WEBnFGbjnFWM3/6wISi FYcTP9laB8cOk6N2Tt+r06kq8eIWOdmsOXyDMm4Py/vIsHIY1b8KgWjininpC6GG+QO+ vMlat/qNJlAUgM0XOzHGgSKYb1qHzpr3fwxHa+HbSrXH7ZkOfCF0E5oKFUL7Omsep44J rI2rK2xA5WwuMOlVR/fgXQIwyVTKrBv4bw59kLO1ZxjMcMPkLQ+osPYIPt4H70iDp/NC 2WtpjjSQKMXk4AljP6HYqgw2PjZtCjdni4WtnJJ48t6uB8mpgGjZ/1XKfuWwREeF7hK5 UMNg== 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=Nfkb9JYOEXxJI/wC5ZFd1cRwC5740heOH+dyOO9b+UI=; b=OokqPS+8xFldrHvvuwMZcs6qopri0JwDFEQWUGVI0oecvBBZYOkUKJLJYKzFijbA01 ix18b4A0Hzq2c1UDpvmpsV4ywrSmgb7IdzbsNCq5KZ8ejyCq4gz3Ou0UJE4SOC6n7xX2 zyC7aHYdbiWRKaEaHcl7prxyN4yXGPkq9YbuPNpyqW+zHThQ4brH3v9BZHWfZvXLlPT0 vTdfP9Cgqd5x37DwbaA3wMusN9fOE/IreVKO20hP4qSxYM6FbBna2KFLKj7jOj+ios7v MLEpFQujrV8fYB6pLLnn69hCVzb6MBwBoABd0Oxje00+1mLzwDsg/2kNcgFS55BDC4Ed LCEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="A7sJTM/q"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id n21-20020a17090673d500b008aabe163627si3421593ejl.699.2023.02.08.01.00.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Feb 2023 01:00:15 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="A7sJTM/q"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 C68CC385B50C for ; Wed, 8 Feb 2023 09:00:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C68CC385B50C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675846810; bh=Nfkb9JYOEXxJI/wC5ZFd1cRwC5740heOH+dyOO9b+UI=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=A7sJTM/qAQs/sY5rpqWOZkjVKAl1jTyK6OEmFTMJrSnOQV0l7DJnbWNPiEPd15vhY pGpC0eWSxcOzC8l+c6NiSShInVxPmCimFdR3jfXc3+8MgRzJt3HSwooe1GSeLzNTEi 2L3j8gdlPlxKnks7HoePE+GtU079eqSPEV+dN/uY= 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 0BE8E385800C for ; Wed, 8 Feb 2023 08:59:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0BE8E385800C 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-574-6q5ib3eoNVWJaMLK0iTLkg-1; Wed, 08 Feb 2023 03:59:21 -0500 X-MC-Unique: 6q5ib3eoNVWJaMLK0iTLkg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 52ACC2A5954D for ; Wed, 8 Feb 2023 08:59:21 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 10E4C2166B29; Wed, 8 Feb 2023 08:59:20 +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 3188xImK3943129 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 8 Feb 2023 09:59:19 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3188xIaE3943128; Wed, 8 Feb 2023 09:59:18 +0100 Date: Wed, 8 Feb 2023 09:59:17 +0100 To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Mangle EXCESS_PRECISION_EXPR as fold_convert REAL_CST [PR108698] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.8 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?1757252750301208605?= X-GMAIL-MSGID: =?utf-8?q?1757252750301208605?= Hi! For standard excess precision, like the C FE we parse floating point constants as EXCESS_PRECISION_EXPR of promoted REAL_CST rather than the nominal REAL_CST, and as the following testcase shows the constants might need mangling. The following patch mangles those as fold_convert of the REAL_CST to EXCESS_PRECISION_EXPR type, i.e. how they were mangled before. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? I'm not really sure EXCESS_PRECISION_EXPR can appear elsewhere in expressions that would need mangling, tried various testcases but haven't managed to come up with one. If that is possible, we'd keep ICEing on it without/with this patch, and the big question is how to mangle those; they could be mangled as casts from the promoted type back to nominal, but then in the mangled expressions one could see the effects of excess precision. Until we have a reproducer, that is just theoretical though. 2023-02-08 Jakub Jelinek PR c++/108698 * mangle.cc (write_expression, write_template_arg): Handle EXCESS_PRECISION_EXPR with REAL_CST operand as write_template_arg_literal on fold_convert of the REAL_CST to EXCESS_PRECISION_EXPR type. * g++.dg/cpp0x/pr108698.C: New test. Jakub --- gcc/cp/mangle.cc.jj 2023-01-25 15:13:23.220649480 +0100 +++ gcc/cp/mangle.cc 2023-02-07 19:27:35.949588461 +0100 @@ -3107,6 +3107,10 @@ write_expression (tree expr) else if (TREE_CODE_CLASS (code) == tcc_constant || code == CONST_DECL) write_template_arg_literal (expr); + else if (code == EXCESS_PRECISION_EXPR + && TREE_CODE (TREE_OPERAND (expr, 0)) == REAL_CST) + write_template_arg_literal (fold_convert (TREE_TYPE (expr), + TREE_OPERAND (expr, 0))); else if (code == PARM_DECL && DECL_ARTIFICIAL (expr)) { gcc_assert (id_equal (DECL_NAME (expr), "this")); @@ -3815,6 +3819,10 @@ write_template_arg (tree node) || code == CONST_DECL || null_member_pointer_value_p (node)) write_template_arg_literal (node); + else if (code == EXCESS_PRECISION_EXPR + && TREE_CODE (TREE_OPERAND (node, 0)) == REAL_CST) + write_template_arg_literal (fold_convert (TREE_TYPE (node), + TREE_OPERAND (node, 0))); else if (DECL_P (node)) { write_char ('L'); --- gcc/testsuite/g++.dg/cpp0x/pr108698.C.jj 2023-02-07 20:33:45.365125556 +0100 +++ gcc/testsuite/g++.dg/cpp0x/pr108698.C 2023-02-07 19:55:57.459493456 +0100 @@ -0,0 +1,16 @@ +// PR c++/108698 +// { dg-do compile { target c++11 } } + +template +decltype (T () * T () + 1.0) foo () +{ + return T () * T () + 1.0; +} + +void +bar () +{ + foo (); + foo (); + foo (); +}