From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C3229385E00D; Mon, 4 Dec 2023 08:01:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C3229385E00D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701676907; bh=r1EcxA0L3vPifXBIKJeWJibFmzCsC2XS6Q0KLTxO9rU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=GeAEDNbGpsi+Br7dG/yJSNs9lNx9P/+2VZxU9WU51PooDCZIfFBWpNUGZXzCjpqcq KnrhUDDFaKF3nhXfZqx3NbN60nQYDIQNoHp4GS5yvL5NmHdnChjL/+tFe1iuwxneXH aOjBXc0YKV4qieF1hWkeRtF0DssyIZfQizSAGPoQ= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/112795] [C++>=14] ICE pragma GCC unroll (n) cxx_eval_constant_expression Date: Mon, 04 Dec 2023 08:01:43 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 8.1.0 X-Bugzilla-Keywords: ice-on-valid-code X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: jakub at gcc dot gnu.org X-Bugzilla-Target-Milestone: 11.5 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D112795 --- Comment #6 from GCC Commits --- The master branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:b6c78feea08c36e5754818c6a3d7536b3f8913dc commit r14-6107-gb6c78feea08c36e5754818c6a3d7536b3f8913dc Author: Jakub Jelinek Date: Mon Dec 4 08:59:15 2023 +0100 c++: #pragma GCC unroll C++ fixes [PR112795] foo in the unroll-5.C testcase ICEs because cp_parser_pragma_unroll during parsing calls maybe_constant_value unconditionally, which is fine if !processing_template_decl, but can ICE otherwise. While just calling fold_non_dependent_expr there instead could be enough to fix the ICE (and I guess the right thing to do for backports if any), I don't see a reason why we couldn't handle a dependent #pragma GCC unr= oll argument as well, the unrolling isn't done in the FE and all the middle= -end cares about is that ANNOTATE_EXPR has a 1..65534 last operand when it is annot_expr_unroll_kind. So, the following patch changes all the unsigned short unroll arguments to tree unroll (and thus avoids the tree -> unsigned short -> tree conversions), does the type and value checking during parsing only if the argument isn't dependent and repeats it during instantiation. 2023-12-04 Jakub Jelinek PR c++/112795 gcc/cp/ * cp-tree.h (cp_convert_range_for): Change UNROLL type from unsigned short to tree. (finish_while_stmt_cond, finish_do_stmt, finish_for_cond): Likewise. * parser.cc (cp_parser_statement): Pass NULL_TREE rather than 0= to cp_parser_iteration_statement UNROLL argument. (cp_parser_for, cp_parser_c_for): Change UNROLL type from unsigned short to tree. (cp_parser_range_for): Likewise. Set RANGE_FOR_UNROLL to just UNROLL rather than build_int_cst from it. (cp_convert_range_for, cp_parser_iteration_statement): Change UNROLL type from unsigned short to tree. (cp_parser_omp_loop_nest): Pass NULL_TREE rather than 0 to cp_parser_range_for UNROLL argument. (cp_parser_pragma_unroll): Return tree rather than unsigned sho= rt. If parsed expression is type dependent, just return it, don't diagnose issues with value if it is value dependent. (cp_parser_pragma): Change UNROLL type from unsigned short to t= ree. * semantics.cc (finish_while_stmt_cond): Change UNROLL type from unsigned short to tree. Build ANNOTATE_EXPR with UNROLL as its last operand rather than build_int_cst from it. (finish_do_stmt, finish_for_cond): Likewise. * pt.cc (tsubst_stmt) : Change UNROLL type from unsigned short to tree and set it to RECUR on RANGE_FOR_UNROLL = (t). (tsubst_expr) : For annot_expr_unroll_kind repeat checks on UNROLL value from cp_parser_pragma_unroll. gcc/testsuite/ * g++.dg/ext/unroll-5.C: New test. * g++.dg/ext/unroll-6.C: New test.=