From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1734) id B356D3858C2D; Mon, 12 Feb 2024 19:56:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B356D3858C2D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1707767785; bh=slL1UvBkcng0IwrjxbzmU8VdQc7FovPCBwolrDRqmqQ=; h=From:To:Subject:Date:From; b=AiAl2i/vdPq6iuSvL8z7BipX0MsDV+xz+gsG+s22E0VDvHO6mQ/sy5OQeN/9C76pe d1/NCuwrztS+1iZDbW7Xl6RnJHkctJ6YU6L49rOv34LHUFn+cRplL3HbCL74RsfMtg eafJLhwbz/90Y0eNqVZr3ZyqRv99IsDvwPGKrFQo= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Marek Polacek To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-8942] c++: ICE with reinterpret_cast and switch [PR113545] X-Act-Checkin: gcc X-Git-Author: Marek Polacek X-Git-Refname: refs/heads/trunk X-Git-Oldrev: 9511b91c56f08b319b4a407608f85c96029ce7ce X-Git-Newrev: 39d989022dd0eacf1a7b95b7b20621acbe717d70 Message-Id: <20240212195625.B356D3858C2D@sourceware.org> Date: Mon, 12 Feb 2024 19:56:24 +0000 (GMT) List-Id: https://gcc.gnu.org/g:39d989022dd0eacf1a7b95b7b20621acbe717d70 commit r14-8942-g39d989022dd0eacf1a7b95b7b20621acbe717d70 Author: Marek Polacek Date: Mon Feb 12 14:53:24 2024 -0500 c++: ICE with reinterpret_cast and switch [PR113545] Jason, this is the patch you proposed for PR113545. It looks very safe so I'm posting it here so that it's not forgotten. PR c++/113545 gcc/cp/ChangeLog: * constexpr.cc (cxx_eval_switch_expr): If the condition doesn't reduce to an INTEGER_CST, consider it non-constant. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/constexpr-reinterpret3.C: Remove dg-ice. Diff: --- gcc/cp/constexpr.cc | 10 ++++++++++ gcc/testsuite/g++.dg/cpp1y/constexpr-reinterpret3.C | 4 +--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index 2ebb1470dd5e..fa346fe01c9c 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -7106,6 +7106,16 @@ cxx_eval_switch_expr (const constexpr_ctx *ctx, tree t, cond = cxx_eval_constant_expression (ctx, cond, vc_prvalue, non_constant_p, overflow_p); VERIFY_CONSTANT (cond); + if (TREE_CODE (cond) != INTEGER_CST) + { + /* If the condition doesn't reduce to an INTEGER_CST it isn't a usable + switch condition even if it's constant enough for other things + (c++/113545). */ + gcc_checking_assert (ctx->quiet); + *non_constant_p = true; + return t; + } + *jump_target = cond; tree body diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-reinterpret3.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-reinterpret3.C index 51feb2e558e7..adc0b418df91 100644 --- a/gcc/testsuite/g++.dg/cpp1y/constexpr-reinterpret3.C +++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-reinterpret3.C @@ -1,7 +1,5 @@ // PR c++/113545 -// { dg-do compile { target c++14 } } -// Please change the above "dg-do compile" to "dg-do run" when the ICE is resolved. -// { dg-ice "PR112545 - constexpr function with switch called for reinterpret_cast" } +// { dg-do run { target c++14 } } char foo;