On 10/23/24 3:07 PM, Jakub Jelinek wrote:
On Wed, Oct 23, 2024 at 08:53:36PM +0200, Jakub Jelinek wrote:
save_expr has been doing that at least since 1992, likely before that.
Though, that
4073          /* Array ref is const/volatile if the array elements are
4074             or if the array is..  */
4075          TREE_READONLY (rval)
4076            |= (CP_TYPE_CONST_P (type) | TREE_READONLY (array));
is done in the C++ FE also since 1994-ish.

Setting TREE_READONLY is correct, according to tree.h that just means it means it isn't modifiable.

I'm afraid what will break especially in Ada if we change it.
Though, unsure even to what.

Are the TREE_READONLY flags needed on ARRAY_REFs/COMPONENT_REFs with
ARRAY_REF bases etc.?
If yes, are ARRAY_REFs/ARRAY_RANGE_REFs with non-invariant index (or
possibly also non-invariant 3rd/4th argument or ARRAY_RANGE_REFs with
non-invariant type size) the only problematic cases?
Say TREE_READONLY COMPONENT_REF with VAR_DECL base should be invariant
I'd hope.
So, should we for the (TREE_READONLY (t) && !TREE_SIDE_EFFECTS (t))
case walk the tree, looking for the ARRAY_REFs etc. and checking if that
is really invariant?

Perhaps INDIRECT_REF/MEM_REF are similarly a problem, one could have
TREE_READONLY INDIRECT_REF or say COMPONENT_REF with INDIRECT_REF first
operand etc. and if the pointer which is dereferenced isn't invariant,
then the INDIRECT_REF/MEM_REF isn't invariant either.

Exactly.

Jason

Reply via email to