On 5/30/23 04:23, Jakub Jelinek wrote:
On Tue, May 30, 2023 at 10:03:05AM +0200, Eric Botcazou wrote:
We want to be able to treat such things as invariant somehow even if we
can't do that for references to user data that might be changed by
intervening code.

That is, indicate that we know that the _REF actually refers to a const
variable or is otherwise known to be unchanging.

Perhaps that should be a new flag that tree_invariant_p can check
instead of TREE_READONLY.

Richard earlier suggested a langhook; given that Ada will be the main (sole?)
user of it, this would probably be better.

Are the DECL_INVARIANT_P FIELD_DECLs in Ada really invariant no matter how
exactly they are accessed?  Or can Ada suffer from the same problem as
C/C++, where the FIELD_DECL is TREE_READONLY, but could go out of scope or
a pointer to it could change.
I mean the p->fld cases in C/C++, where there could be free (p); or p++
etc. in between the place where save_expr is first evaluated and later
uses?

Note that it is fine to treat p->fld as invariant in C++ if fld is TREE_READONLY and p is itself invariant. The implementation is allowed to assume that other code didn't destroy *p and create a new object with a different value of p in the same location under https://eel.is/c++draft/basic.memobj#basic.life-8.3

Are the Ada references to VLA bounds represented that way?

Jason

Reply via email to