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.
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.

        Jakub

Reply via email to