This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Questions about a constant array reference in the C++ frontend


> Kazu Hirata writes:
>
>> Nathan writes:
>> this is untrue. the elements hold the qualification.
>
> Then how do I know that an array is declared with const (or static
> const)?  When I looked at the CONSTRUCTOR stored in the DECL_INITIAL
> of an array, I saw it with the TREE_STATIC flag set regardless of
> whether the array is declared with const, so that's not useful to
> determine whether the array is declared with const.
> 
> All I need is a sufficient condition that works with C, C++, and any
> other language that GCC supports to determine whether it's safe to
> fold array[CST] into a constant.

My basic understanding based on GCC's documentation, is that only memory
references to "static const" values (and presumably non-in-lined literals)
are warranted to have MEM_READONLY_P (mem-ref) true (which I understand is
designated by the unchanging attribute at the tree/rtx level); as these
are the only references which may physically be read-only and traditionally
warranted not to change (as as memory references to "const" only objects are
more a semantic restriction, not necessarily a literal one, as non-"const"
objects may be cast as being "const" and visa versa, therefore can't be
reliably presumed to be READONLY/unchanging).

However do note that something does appear to be broken with respect to
literal string constants, as MEM_READONLY_P memory references to them are
not reliably true as they should be, although char array literals do seem
to be reliably designated (at least for the C FE).




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]