On Wed, 16 Jun 2021, Martin Jambor wrote:
> Hi,
>
> On Wed, Jun 16 2021, Jakub Jelinek wrote:
> > On Tue, Jun 15, 2021 at 06:11:27PM +0200, Richard Biener wrote:
> >> >--- a/gcc/tree-sra.c
> >> >+++ b/gcc/tree-sra.c
> >> >@@ -915,6 +915,12 @@ create_access (tree expr, gimple *stmt, bool
> >> >write)
> >> >if (!DECL_P (base) || !bitmap_bit_p (candidate_bitmap, DECL_UID
> >> >(base)))
> >> > return NULL;
> >> >
> >> >+ if (write && TREE_READONLY (base))
> >> >+ {
> >> >+ disqualify_candidate (base, "Encountered a store to a read-only
> >> >decl.");
> >
> > Wouldn't this be a useful point to also emit some warning (with
> > some TREE_NO_WARNING prevention) that some particular statement modifies
> > a const decl?
> > I guess it can be warned elsewhere though.
>
> I would prefer it to be elsewhere.
>
> > As testcases one could use
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100994#c4
> > and #c5. Though would be nice if we diagnose that even without those -fno-*
> > options.
> >
>
> My holy grail would be to actually add a condition to the gimple
> verifier that TREE_READONLY decl is never on a LHS of an assignment or a
> call (or generally not seen from the store callback of
> walk_stmt_load_store_addr_ops).
>
> Of course, in order to do that, either the gimplifier or the pass that
> propagated a TREE_READONLY decl into a store would have to drop the flag
> and at that point could emit a warning.
>
> But seeing things like the addition in a0d371a2514 I am afraid that
> getting there might be difficult.
Fixing most easy places would still be a good idea. Eventually
the OMP thing could be worked around by performing the verfication
only after OMP lowering or so (at start).
Richard.