From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 507643857C43; Fri, 11 Feb 2022 12:53:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 507643857C43 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 r12-7197] c++: Fix up constant expression __builtin_convertvector folding [PR104472] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: fb76c0ad35f96505ecd9213849ebc3df6163a0f7 X-Git-Newrev: 84993d94e13ad2ab3aee151bb5a5e767cf75d51e Message-Id: <20220211125335.507643857C43@sourceware.org> Date: Fri, 11 Feb 2022 12:53:35 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Feb 2022 12:53:35 -0000 https://gcc.gnu.org/g:84993d94e13ad2ab3aee151bb5a5e767cf75d51e commit r12-7197-g84993d94e13ad2ab3aee151bb5a5e767cf75d51e Author: Jakub Jelinek Date: Fri Feb 11 13:52:44 2022 +0100 c++: Fix up constant expression __builtin_convertvector folding [PR104472] The following testcase ICEs, because due to the -frounding-math fold_const_call fails, which is it returns NULL, and returning NULL from cxx_eval* is wrong, all the callers rely on them to either return folded value or original with *non_constant_p = true. The following patch does that, and additionally falls through into the default case where there is diagnostics for the !ctx->quiet case too. 2022-02-11 Jakub Jelinek PR c++/104472 * constexpr.cc (cxx_eval_internal_function) : Only return fold_const_call result if it is non-NULL. Otherwise fall through into the default: case to return t, set *non_constant_p and emit diagnostics if needed. * g++.dg/cpp0x/constexpr-104472.C: New test. Diff: --- gcc/cp/constexpr.cc | 9 +++------ gcc/testsuite/g++.dg/cpp0x/constexpr-104472.C | 9 +++++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index 9b8e0eced4b..87f3a7bb7a3 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -1840,13 +1840,10 @@ cxx_eval_internal_function (const constexpr_ctx *ctx, tree t, false, non_constant_p, overflow_p); if (TREE_CODE (arg) == VECTOR_CST) - return fold_const_call (CFN_VEC_CONVERT, TREE_TYPE (t), arg); - else - { - *non_constant_p = true; - return t; - } + if (tree r = fold_const_call (CFN_VEC_CONVERT, TREE_TYPE (t), arg)) + return r; } + /* FALLTHRU */ default: if (!ctx->quiet) diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-104472.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-104472.C new file mode 100644 index 00000000000..c9c8bf414fe --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-104472.C @@ -0,0 +1,9 @@ +// PR c++/104472 +// { dg-options "-O2 -frounding-math" } +// { dg-add-options float16 } +// { dg-require-effective-target float16 } + +typedef short __attribute__((__vector_size__ (16))) V; +typedef _Float16 __attribute__((__vector_size__ (16))) F; + +V v = __builtin_convertvector (__builtin_convertvector ((V){5534}, F), V) < 8;