On Tue, Apr 01, 2025 at 09:19:08AM +0200, Richard Biener via Gcc wrote:
> On Tue, Apr 1, 2025 at 12:04 AM Thomas Schwinge <tschwi...@baylibre.com> 
> wrote:
> > In Nvidia PTX, "A state space is a storage area with particular
> > characteristics.  All variables reside in some state space.  [...]".
> > These include:
> >
> >     .const  Shared, read-only memory.
> >     .global  Global memory, shared by all threads.
> >
> > Implemented via 'TARGET_ENCODE_SECTION_INFO', GCC/nvptx then uses
> > special-cased instructions for accessing the respective memory regions.
> >
> > Now, given a 'const' array (with whatever element type; not interesting
> > here), like:
> >
> >     extern int * const arr[];
> >
> > ..., for GCC/C compilation, we access this as '.const' memory: GCC/nvptx
> > 'DATA_AREA_CONST', but for GCC/C++ compilation, we access it as
> > 'DATA_AREA_GLOBAL', and then fault at run time due to mismatch with the
> > definition, which actually is '.const' for both C and C++ compilation.
> >
> > The difference is, when we get to 'TARGET_ENCODE_SECTION_INFO', that for
> > C we've got 'TREE_READONLY(decl)', but for C++ we don't.
> 
> In C++ there could be runtime initializers for a const qualified
> object.  I think all
> you need to do is make sure the logic that places the object in .const
> vs. .global
> is consistent with the logic deciding how to access it.

If it is extern, then for C++ you really don't know if it will be
TREE_READONLY or not, that depends on whether it has runtime initialization
or not and only the TU which defines it knows that.
And deriving something from TYPE_READONLY of the ARRAY_TYPE or even
from strip_array_types of the type does not work, that reflects whether it
is const or not, I think it will still be set even if it has mutable members
and doesn't say anything about runtime initialization.

        Jakub

Reply via email to