From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 44E023858C41; Tue, 23 Jan 2024 18:59:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 44E023858C41 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1706036381; bh=3PEXzippQnWbDa+qMTnzbQiQoUb5VMSaeSHnUX/DKck=; h=From:To:Subject:Date:From; b=v2GPLlnCYyLoz0vWX/mrr+MK/RwOn85gXzAJxavyZrgbcHPFeyKSv2lkA3up43Pf5 xvEMj3u+ClPzG6Zy1AQ3o8Eq8CeFh536/UUH7PVbaTecITDaNw7qEakKfIpWo/Ccwc e2JsTiC2CnpkM68eeSrtqLXiW3Qn7tiwdfWGfp68= 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 r14-8373] c: Call c_fully_fold on __atomic_* operands in atomic_bitint_fetch_using_cas_loop [PR113518] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: 06ee648e9bb8c121fbd93659f81d3380dba8be09 X-Git-Newrev: dbc5f1f523b3cfa539d72fdd60b9479b3cd5a45d Message-Id: <20240123185941.44E023858C41@sourceware.org> Date: Tue, 23 Jan 2024 18:59:40 +0000 (GMT) List-Id: https://gcc.gnu.org/g:dbc5f1f523b3cfa539d72fdd60b9479b3cd5a45d commit r14-8373-gdbc5f1f523b3cfa539d72fdd60b9479b3cd5a45d Author: Jakub Jelinek Date: Tue Jan 23 19:59:00 2024 +0100 c: Call c_fully_fold on __atomic_* operands in atomic_bitint_fetch_using_cas_loop [PR113518] As the following testcase shows, I forgot to call c_fully_fold on the __atomic_*/__sync_* operands called on _BitInt address, the expressions are then used inside of TARGET_EXPR initializers etc. and are never fully folded later, which means we can ICE e.g. on C_MAYBE_CONST_EXPR trees inside of those. The following patch fixes it, while the function currently is only called in the C FE because C++ doesn't support BITINT_TYPE, I think guarding the calls on !c_dialect_cxx () is safer. 2024-01-23 Jakub Jelinek PR c/113518 * c-common.cc (atomic_bitint_fetch_using_cas_loop): Call c_fully_fold on lhs_addr, val and model for C. * gcc.dg/bitint-77.c: New test. Diff: --- gcc/c-family/c-common.cc | 6 ++++++ gcc/testsuite/gcc.dg/bitint-77.c | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc index dc67562ce92..e15eff698df 100644 --- a/gcc/c-family/c-common.cc +++ b/gcc/c-family/c-common.cc @@ -8082,6 +8082,12 @@ atomic_bitint_fetch_using_cas_loop (location_t loc, tree lhs_addr = (*orig_params)[0]; tree val = convert (nonatomic_lhs_type, (*orig_params)[1]); tree model = convert (integer_type_node, (*orig_params)[2]); + if (!c_dialect_cxx ()) + { + lhs_addr = c_fully_fold (lhs_addr, false, NULL); + val = c_fully_fold (val, false, NULL); + model = c_fully_fold (model, false, NULL); + } if (TREE_SIDE_EFFECTS (lhs_addr)) { tree var = create_tmp_var_raw (TREE_TYPE (lhs_addr)); diff --git a/gcc/testsuite/gcc.dg/bitint-77.c b/gcc/testsuite/gcc.dg/bitint-77.c new file mode 100644 index 00000000000..0125f1e9fb3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/bitint-77.c @@ -0,0 +1,25 @@ +/* PR c/113518 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-O2 -std=c23" } */ + +#if __BITINT_MAXWIDTH__ >= 607 +_BitInt(607) v; +#else +_BitInt(63) v; +#endif + +void +foo (void) +{ + __atomic_fetch_or (&v, 1 << 31, __ATOMIC_RELAXED); +} + +#if __BITINT_MAXWIDTH__ >= 16321 +_BitInt(16321) w; + +void +bar (void) +{ + __atomic_fetch_add (&w, 1 << 31, __ATOMIC_SEQ_CST); +} +#endif