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

--- Comment #15 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #14)
> C++ FE's constexpr.c has bool lval argument to many recursive functions, so
> it can differentiate between cases where you don't want to fold "str"[0] to
> 's' and cases where you can do that.  It is among other cases set when
> processing ADDR_EXPR's operand.  But c_fully_fold_internal doesn't have
> anything like that, so that would need to be introduced there.

>From the related PR66618, it seems that if we had such an argument properly
propagated, we could as well use decl_constant_value_for_optimization during
c_fully_fold_internal (if not pedantic?) centrally for VAR_DECLs, rather then
just using it on selected operands where we basically know for sure we don't
need an lvalue.

Without such changes, a hack could be to add the ARRAY_REF of STRING_CST with
constant index folding into decl_constant_value_for_optimization.

Reply via email to