From patchwork Thu Sep 29 10:01:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1523 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f2ce:0:0:0:0:0 with SMTP id d14csp601089wrp; Thu, 29 Sep 2022 03:02:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5qGcpLtbN9Hyrcu+gXIUbk7IHE/jZ/l34qr/hI2c1Mh7o0UcE72y8yan9SY2VCwjOS+XrX X-Received: by 2002:a17:906:9b91:b0:783:12ec:2724 with SMTP id dd17-20020a1709069b9100b0078312ec2724mr2068488ejc.198.1664445768168; Thu, 29 Sep 2022 03:02:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664445768; cv=none; d=google.com; s=arc-20160816; b=t0VgJAD5GmznPPnfAN2BDkC5ZFQ1oFBtOVUNOlWhLZUaebRZ1vEDELqduDBpm+SKig BjQkUnofXkiJympJXxYuH/tjGDdcYqK9+h50AyzyvY+KSR8S/XUTVVpssOrJ4QBgUoFC 9kUOTXODZhubZgruYqPuJbqATmy6riX49xZYN/78mjcbFvPMZESV5kWAoBfQRjCKGCvg z1wYP2/K413HMXwILL+pTANqkC4yhQzqJZfByQpZ7uicEn0sx4M+fVU6TwzFBRXR6ICk 25of3pNDnwmzigDinErx7zt6KBHPzVePAfNEJLateaqBtfcNNTuwP6deln77UaBs+yk+ wkiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=rDsUmTPbyUuSIYL5pxh1hKnacPI5FS7Q3M9FI7r92Js=; b=KssVQN/f668qoWpD9XO8fQPjHdDSRqCn85XkjmWJEq6TvajSeXIf/7aU8LK4CcrEU/ +fxokVEv7FUkOg2twYvrI5DR7jIZeU2p3fmgEYmgPQJILfGoJ5avbzvIV7pSKqm3EbIY uqzNfDd1cXTWorh5ATOGbizSROiNdct2oMlYgiZcm7H8uxvdgel3c6UAzvNJ4WUEbhha s6bdHnzqg3bBj99Q+GUpsHqU87zpOFwsVJ9IWcSAti4fel1HeNt7t2eOTGjbeQlp3pUJ AamU7l6gXCIo7wEgcL1I7/ciYjuEvkkUzmA4dWweiuQwlU249xhUmuCeNRiruztrIGz4 gTKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=IIFzjue2; 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 nc2-20020a1709071c0200b00781e52406cbsi8039883ejc.677.2022.09.29.03.02.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Sep 2022 03:02:48 -0700 (PDT) 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=IIFzjue2; 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 D28093858435 for ; Thu, 29 Sep 2022 10:02:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D28093858435 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664445766; bh=rDsUmTPbyUuSIYL5pxh1hKnacPI5FS7Q3M9FI7r92Js=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=IIFzjue2umTxKnpYuFcMSp1Es/J918EPnm2Urjiy888i40J/GcLKTMH0ojhGcRerx qo6gBIz6Zt/AVe2WIh63cZwcp0YndmlNfcVRwGhpbQunBUsh+Sc9pPHrjTkDz2vo22 wtaMCvitvHQItUihzKJ0NrykxFYIK46a5Q7kVyyQ= 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 AD992385829A for ; Thu, 29 Sep 2022 10:01:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AD992385829A Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-534-dbqK9fquOPOimoOEIJZmOg-1; Thu, 29 Sep 2022 06:01:49 -0400 X-MC-Unique: dbqK9fquOPOimoOEIJZmOg-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 BAF50855421; Thu, 29 Sep 2022 10:01:48 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.194]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 554BB2166B26; Thu, 29 Sep 2022 10:01:48 +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 28TA1iZ53913151 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 29 Sep 2022 12:01:45 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 28TA1h7X3913150; Thu, 29 Sep 2022 12:01:43 +0200 Date: Thu, 29 Sep 2022 12:01:43 +0200 To: Jason Merrill , "Joseph S. Myers" Subject: [PATCH] i386, rs6000, ia64, s390: Fix C++ ICEs with _Float64x or _Float128 [PR107080] 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.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, 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 Cc: richard.sandiford@arm.com, Richard Earnshaw , gcc-patches@gcc.gnu.org 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?1745297885415576172?= X-GMAIL-MSGID: =?utf-8?q?1745297885415576172?= Hi! The following testcase ICEs on x86 as well as ppc64le (the latter with -mabi=ieeelongdouble), because _Float64x there isn't mangled as DF64x but e or u9__ieee128 instead. Those are the mangling that should be used for the non-standard types with the same mode or for long double, but not for _Float64x. All the 4 mangle_type targhook implementations start with type = TYPE_MAIN_VARIANT (type); so I think it is cleanest to handle it the same in all and return NULL before the switches on mode or whatever other tests. s390 doesn't actually have a bug, but while I was there, having type = TYPE_MAIN_VARIANT (type); if (TYPE_MAIN_VARIANT (type) == long_double_type_node) looked useless to me. Tested on x86_64, i686 and powerpc64le, ok for trunk? Note, there is one further problem on aarch64/arm, types with HFmode (_Float16 and __fp16) are there mangled as Dh (which is standard Itanium mangling: ::= Dh # IEEE 754r half-precision floating point (16 bits) ::= DF _ # ISO/IEC TS 18661 binary floating point type _FloatN (N bits) so in theory is also ok, but DF16_ is more specific. Should we just change Dh to DF16_ in those backends, or should __fp16 there be distinct type from _Float16 where __fp16 would mangle Dh and _Float16 DF16_ ? And there is csky, which mangles __fp16 (but only if type's name is __fp16, not _Float16) as __fp16, that looks clearly invalid to me as it isn't valid in the mangling grammar. So perhaps just nuke csky's mangle_type and have it mangled as DF16_ by the generic code? 2022-09-29 Jakub Jelinek PR c++/107080 * config/i386/i386.cc (ix86_mangle_type): Always return NULL for float128_type_node or float64x_type_node, don't check float128t_type_node later on. * config/ia64/ia64.cc (ia64_mangle_type): Always return NULL for float128_type_node or float64x_type_node. * config/rs6000/rs6000.cc (rs6000_mangle_type): Likewise. Don't check float128_type_node later on. * config/s390/s390.cc (s390_mangle_type): Don't use TYPE_MAIN_VARIANT on type which was set to TYPE_MAIN_VARIANT a few lines earlier. * g++.dg/cpp23/ext-floating11.C: New test. Jakub --- gcc/config/i386/i386.cc.jj 2022-09-29 09:13:25.713718513 +0200 +++ gcc/config/i386/i386.cc 2022-09-29 11:29:20.828358152 +0200 @@ -22725,6 +22725,9 @@ ix86_mangle_type (const_tree type) && TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE) return NULL; + if (type == float128_type_node || type == float64x_type_node) + return NULL; + switch (TYPE_MODE (type)) { case E_BFmode: @@ -22735,10 +22738,7 @@ ix86_mangle_type (const_tree type) return "DF16_"; case E_TFmode: /* __float128 is "g". */ - if (type == float128t_type_node) - return "g"; - /* _Float128 should mangle as "DF128_" done in generic code. */ - return NULL; + return "g"; case E_XFmode: /* "long double" or __float80 is "e". */ return "e"; --- gcc/config/ia64/ia64.cc.jj 2022-09-27 08:03:26.977984661 +0200 +++ gcc/config/ia64/ia64.cc 2022-09-29 11:29:44.071037677 +0200 @@ -11225,6 +11225,9 @@ ia64_mangle_type (const_tree type) && TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE) return NULL; + if (type == float128_type_node || type == float64x_type_node) + return NULL; + /* On HP-UX, "long double" is mangled as "e" so __float128 is mangled as "e". */ if (!TARGET_HPUX && TYPE_MODE (type) == TFmode) --- gcc/config/rs6000/rs6000.cc.jj 2022-09-27 08:03:26.999984363 +0200 +++ gcc/config/rs6000/rs6000.cc 2022-09-29 11:26:10.290985331 +0200 @@ -20270,13 +20270,12 @@ rs6000_mangle_type (const_tree type) if (type == bool_int_type_node) return "U6__booli"; if (type == bool_long_long_type_node) return "U6__boolx"; + if (type == float128_type_node || type == float64x_type_node) + return NULL; + if (SCALAR_FLOAT_TYPE_P (type) && FLOAT128_IBM_P (TYPE_MODE (type))) return "g"; - if (SCALAR_FLOAT_TYPE_P (type) - && FLOAT128_IEEE_P (TYPE_MODE (type)) - /* _Float128 should mangle as DF128_ (done in generic code) - rather than u9__ieee128 (used for __ieee128 and __float128). */ - && type != float128_type_node) + if (SCALAR_FLOAT_TYPE_P (type) && FLOAT128_IEEE_P (TYPE_MODE (type))) return "u9__ieee128"; if (type == vector_pair_type_node) --- gcc/config/s390/s390.cc.jj 2022-09-26 18:47:26.950349802 +0200 +++ gcc/config/s390/s390.cc 2022-09-29 11:26:51.180421534 +0200 @@ -7642,8 +7642,7 @@ s390_mangle_type (const_tree type) if (type == s390_builtin_types[BT_BV4SI]) return "U6__booli"; if (type == s390_builtin_types[BT_BV2DI]) return "U6__booll"; - if (TYPE_MAIN_VARIANT (type) == long_double_type_node - && TARGET_LONG_DOUBLE_128) + if (type == long_double_type_node && TARGET_LONG_DOUBLE_128) return "g"; /* For all other types, use normal C++ mangling. */ --- gcc/testsuite/g++.dg/cpp23/ext-floating11.C.jj 2022-09-29 11:33:46.331697320 +0200 +++ gcc/testsuite/g++.dg/cpp23/ext-floating11.C 2022-09-29 11:40:30.610123406 +0200 @@ -0,0 +1,79 @@ +// P1467R9 - Extended floating-point types and standard names. +// { dg-do compile { target c++23 } } +// { dg-options "" } + +#include "ext-floating.h" + +#ifdef __STRICT_ANSI__ +#undef __SIZEOF_FLOAT128__ +#endif + +extern "C" void abort (); + +using namespace std; + +template +int +foo (T x, U y) noexcept +{ + return 3; +} + +int +main () +{ + if (foo (0.0f, 0.0f) != 3) + abort (); + if (foo (0.0, 0.0) != 3) + abort (); + if (foo (0.0L, 0.0L) != 3) + abort (); +#ifdef __STDCPP_FLOAT16_T__ + if (foo (0.0f16, 0.0f16) != 3) + abort (); + if (foo (0.0f, 0.0f16) != 3) + abort (); +#endif +#ifdef __STDCPP_FLOAT32_T__ + if (foo (0.0f32, 0.0f32) != 3) + abort (); + if (foo (0.0f, 0.0f32) != 3) + abort (); +#endif +#ifdef __STDCPP_FLOAT64_T__ + if (foo (0.0f64, 0.0f64) != 3) + abort (); + if (foo (0.0, 0.0f64) != 3) + abort (); +#endif +#ifdef __STDCPP_FLOAT128_T__ + if (foo (0.0f128, 0.0f128) != 3) + abort (); + if (foo (0.0L, 0.0f128) != 3) + abort (); +#endif +#ifdef __STDCPP_BFLOAT16_T__ + if (foo (0.0bf16, 0.0bf16) != 3) + abort (); + if (foo (0.0f, 0.0bf16) != 3) + abort (); +#endif +#ifdef __FLT32X_MANT_DIG__ + if (foo (0.0f32x, 0.0f32x) != 3) + abort (); + if (foo (0.0, 0.0f32x) != 3) + abort (); +#endif +#ifdef __FLT64X_MANT_DIG__ + if (foo (0.0f64x, 0.0f64x) != 3) + abort (); + if (foo (0.0L, 0.0f64x) != 3) + abort (); +#endif +#ifdef __FLT128X_MANT_DIG__ + if (foo (0.0f128x, 0.0f128x) != 3) + abort (); + if (foo (0.0L, 0.0f128x) != 3) + abort (); +#endif +}