From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 27ECE3840C27; Fri, 5 Mar 2021 15:39:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 27ECE3840C27 From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/99287] std::source_location::function_name breaks constexpr Date: Fri, 05 Mar 2021 15:39:55 +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: 11.0 X-Bugzilla-Keywords: rejects-valid X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: ppalka at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Mar 2021 15:39:55 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99287 --- Comment #4 from Jakub Jelinek --- (In reply to Patrick Palka from comment #3) > IIUC, those two types are actually the same, it's just that one of them w= as > obtained through the char_type alias, and it seems debug_tree prefers to > show the name of the alias when the type came from one. >=20 > It seems the issue ultimately is in cxx_eval_increment_expression: during > evaluation of ++__first with __first =3D &"mystr"[n] + m and with lval=3D= false, > since cxx_fold_pointer_plus_expression and not fold_build2 is responsible > for simplifying this POINTER_PLUS_EXPR to &"mystr"[n+m], returning 'mod' > actually returns the unreduced &"mystr"[n] + m rather than the reduced > &"mystr"[n+m] that we obtain as part of constexpr evaluation of the > temporary MODIFY_EXPR. This unreduced return value of cxx_eval_increment > interfers with later constexpr evaluation, e.g. folding of the > POINTER_DIFF_EXPR. >=20 > I'm testing the following which updates 'mod' with the result of evaluati= on > of the MODIFY_EXPR: >=20 > --- a/gcc/cp/constexpr.c > +++ b/gcc/cp/constexpr.c > @@ -5582,20 +5582,14 @@ cxx_eval_increment_expression (const constexpr_ctx > *ctx, tree t, > /* Storing the modified value. */ > tree store =3D build2_loc (cp_expr_loc_or_loc (t, input_location), > MODIFY_EXPR, type, op, mod); > - cxx_eval_constant_expression (ctx, store, > - true, non_constant_p, overflow_p); > + mod =3D cxx_eval_constant_expression (ctx, store, false, > + non_constant_p, overflow_p); > ggc_free (store); Maybe; I'm a little bit worried here though because cxx_eval_constant_expression can in various cases return the tree passed to it on failure (i.e. the stor= e) or can return NULL_TREE. And store is then ggc_freed, so shouldn't be really used afterwards. So perhaps tree new_mod =3D cxx_eval_constant_expression (ctx, store, false, non_constant_p, overflow_p); if (new_mod && new_mod !=3D store) mod =3D new_mod; ggc_free (store); ?=