From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 8A9483858D1E; Fri, 30 Sep 2022 19:55:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8A9483858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664567751; bh=z5YKE8LvrL6nJFdl1AbdtxhDQ61ZlF7ktSQkFtW4Auo=; h=From:To:Subject:Date:From; b=fx1uJel66YbMRAwyOhY6QEMo9o3e0fKJxU/LM1Xzo2VgHmn55h8kwSXLCCN17OG33 Cud8lC83ApeeLC+KjHD/mbKzQvGA+XwmBuUFg8QjIxVzdK2q5xdu2R1IbTAxHfYSgU FyoV5vzhqFb+0qTt6/TgLzPoVJV6zXaIx8Lz/6M8= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-2995] arm, csky: Fix C++ ICEs with _Float16 and __fp16 [PR107080] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: b52b99b62df8fc9b3a3010cb0a8cf49bc35037f0 X-Git-Newrev: 61786edf7a82ffb4979207b43a8204ebc2a7671d Message-Id: <20220930195551.8A9483858D1E@sourceware.org> Date: Fri, 30 Sep 2022 19:55:51 +0000 (GMT) List-Id: https://gcc.gnu.org/g:61786edf7a82ffb4979207b43a8204ebc2a7671d commit r13-2995-g61786edf7a82ffb4979207b43a8204ebc2a7671d Author: Jakub Jelinek Date: Fri Sep 30 21:54:08 2022 +0200 arm, csky: Fix C++ ICEs with _Float16 and __fp16 [PR107080] On Fri, Sep 30, 2022 at 09:54:49AM -0400, Jason Merrill wrote: > > 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_ ? > > You argued for keeping __float128 separate from _Float128, does the same > argument not apply to this case? Actually, they already were distinct types that just mangled the same. So the same issue that had to be solved on i?86, ia64 and rs6000 for _Float64x vs. long double is a problem on arm and aarch64 with _Float16 vs. __fp16. The following patch fixes it for arm after aarch64 has been changed already before. > > 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? And seems even on csky __fp16 is distinct type from _Float16 (which is a good thing for consistency, these 3 targets are the only ones that have __fp16 type), so instead the patch handles it the same as on arm/aarch64, Dh mangling for __fp16 and DF16_ for _Float16. 2022-09-30 Jakub Jelinek PR c++/107080 * config/arm/arm.cc (arm_mangle_type): Mangle just __fp16 as Dh and _Float16 as DF16_. * config/csky/csky.cc (csky_init_builtins): Fix a comment typo. (csky_mangle_type): Mangle __fp16 as Dh and _Float16 as DF16_ rather than mangling __fp16 as __fp16. * g++.target/arm/pr107080.C: New test. Diff: --- gcc/config/arm/arm.cc | 2 ++ gcc/config/csky/csky.cc | 10 +++++----- gcc/testsuite/g++.target/arm/pr107080.C | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc index 1a375367ac7..ee8f1babf8a 100644 --- a/gcc/config/arm/arm.cc +++ b/gcc/config/arm/arm.cc @@ -30359,6 +30359,8 @@ arm_mangle_type (const_tree type) /* Half-precision floating point types. */ if (TREE_CODE (type) == REAL_TYPE && TYPE_PRECISION (type) == 16) { + if (TYPE_MAIN_VARIANT (type) == float16_type_node) + return NULL; if (TYPE_MODE (type) == BFmode) return "u6__bf16"; else diff --git a/gcc/config/csky/csky.cc b/gcc/config/csky/csky.cc index 4dc74d8924f..f7b2bf8e7c1 100644 --- a/gcc/config/csky/csky.cc +++ b/gcc/config/csky/csky.cc @@ -7300,7 +7300,7 @@ csky_init_cumulative_args (CUMULATIVE_ARGS *pcum, tree fntype, void csky_init_builtins (void) { - /* Inint fp16. */ + /* Init fp16. */ static tree csky_floatHF_type_node = make_node (REAL_TYPE); TYPE_PRECISION (csky_floatHF_type_node) = GET_MODE_PRECISION (HFmode); layout_type (csky_floatHF_type_node); @@ -7313,10 +7313,10 @@ csky_init_builtins (void) static const char * csky_mangle_type (const_tree type) { - if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL - && DECL_NAME (TYPE_NAME (type)) - && !strcmp (IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))), "__fp16")) - return "__fp16"; + if (TREE_CODE (type) == REAL_TYPE + && TYPE_PRECISION (type) == 16 + && TYPE_MAIN_VARIANT (type) != float16_type_node) + return "Dh"; /* Use the default mangling. */ return NULL; diff --git a/gcc/testsuite/g++.target/arm/pr107080.C b/gcc/testsuite/g++.target/arm/pr107080.C new file mode 100644 index 00000000000..89a5746d5fb --- /dev/null +++ b/gcc/testsuite/g++.target/arm/pr107080.C @@ -0,0 +1,19 @@ +// PR c++/107080 +// { dg-do compile } +// { dg-options "-mfp16-format=ieee" } + +template +int +foo (T x, T1 y) +{ + return 3; +} + +int +main () +{ + return (foo (0.0f16, 0.0f16) + foo (0.0f16, (__fp16) 0.0)) != 6; +} + +// { dg-final { scan-assembler "_Z3fooIDF16_DF16_EiT_T0_" } } +// { dg-final { scan-assembler "_Z3fooIDF16_DhEiT_T0_" } }