https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99287

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Patrick Palka from comment #3)
> IIUC, those two types are actually the same, it's just that one of them was
> 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.
> 
> It seems the issue ultimately is in cxx_eval_increment_expression: during
> evaluation of ++__first with __first = &"mystr"[n] + m and with lval=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.
> 
> I'm testing the following which updates 'mod' with the result of evaluation
> of the MODIFY_EXPR:
> 
> --- 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 = 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 = 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 store)
or can return NULL_TREE.
And store is then ggc_freed, so shouldn't be really used afterwards.
So perhaps
  tree new_mod = cxx_eval_constant_expression (ctx, store, false,
non_constant_p, overflow_p);
  if (new_mod && new_mod != store)
    mod = new_mod;

  ggc_free (store);
?

Reply via email to