Am 23.06.26 um 13:14 schrieb Arsen Arsenović:
Georg-Johann Lay <[email protected]> writes:
But the rest of the compiler would probably need similar changes, as,
AFAICT, it all assumes that TREE_ADDR_SPACE (array) is set to
TREE_ADDR_SPACE (TREE_TYPE (array)) prior to using it.
Alternatively, of course, we could make such a EXPR_OR_DECL_ADDR_SPACE
and replace all (applicable) usages of TYPE_ADDR_SPACE with it.
I think it'd be semantically sound to make GENERIC semantics match C++
when dealing with address spaces on array types (i.e. define that the
the address space of an array type is the address space of the element
type; nothing else really makes sense after all), so it may be best to
make TYPE_ADDR_SPACE strip arrays.

I am not sure if that's a good idea.  For example the outcome of
strip_array_types() might be error_mark_node.

Moreover, while convenient in many places, it would be confusing.

It's not just convenience, it's also semantically more sound, IMO.

Such a change would make it impossible to have the (nonsensical)
scenario where an array has its elements in some other address space
(which is the confusion that lead to the bug you found).

The outcome of strip_array_types() can be error_mark_node iff the array
passed into it is an array of error types (or, of course, if the error
mark was passed into it).  But, if it is such an array, then we need to
invent an address space to place on the array type anyway (in
build_min_array_type).  Ergo, it seems to me equivalent to treat that
case as if it were the generic address space anyway, in the
TYPE_ADDR_SPACE accessor.

Indeed, ISTM that at least varasm.cc already deals with the error mark
in that way, and other places probably do too.

Though to find out readonlyness, you's have to peel arrays by hand,
while to get an AS you don't need peel.

Maybe leave TYPE_ADDR_SPACE (and TYPE_QUALS, TYPE_QUALS_NO_ADDR_SPACE,
TYPE_READONLY, TYPE_VOLATILE and what not for that matter) consistently
operating on the very node, and add a new function like
decl_addr_space() to tree.h?  In avr.cc, I am currently using this one:

/* Return the address space of a DECL_P or TYPE_P.  This doesn't follow
   pointer types and can be used to find the section for a decl.  */

static addr_space_t
avr_node_addr_space (tree node)
{
  if (DECL_P (node))
    node = TREE_TYPE (node);

  if (TYPE_P (node))
    node = strip_array_types (node);

  return TYPE_P (node) ? TYPE_ADDR_SPACE (node) : ADDR_SPACE_GENERIC;
}

Johann

Reply via email to