[PATCH] varpool: Restore GENERIC TREE_READONLY automatic var optimization [PR7260]
Joseph Myers
joseph@codesourcery.com
Tue Jan 26 20:48:31 GMT 2021
On Tue, 26 Jan 2021, Richard Biener wrote:
> If it is an initializer from constants we gimplify to a series of
> assigns it might be still useful. OTOH, I'm not sure whether
> a const auto is really readonly in C or if it is safe to assume
> the stack part is writable and thus casting away the const and
> writing to it is fine ...
If an object is defined as const then it's undefined behavior to modify it
(that's different from the case of having a pointer-to-const, where the
original object might be defined as non-const and can be modified through
that pointer after a cast).
Note, however, that for a const object of automatic storage duration with
a non-constant initializer, the initializer gets evaluated and stored in
the object every time the initialization is reached in the order of
execution (while the object is live for the whole block in which it is
declared) - so in that case the object does get modified during execution,
just not by an assignment expression.
--
Joseph S. Myers
joseph@codesourcery.com
More information about the Gcc-patches
mailing list