https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128477
Bug ID: 128477
Summary: type attribute on __typeof__ of an array drops the
named address space from the element type
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: c
Assignee: vineetg at gcc dot gnu.org
Reporter: vineetg at gcc dot gnu.org
CC: dfaust at gcc dot gnu.org, jemarch at gcc dot gnu.org
Target Milestone: ---
A type attribute applied to a __typeof__ of an array strips the named
address space from the element type, so &arr[0] no longer has the address
space and a valid program is rejected.
extern __seg_gs __attribute__((may_alias)) __typeof__(int [4]) arr;
int __seg_gs *p = &arr[0];
$ gcc -c t.c
t.c:2:19: error: initialization from pointer to non-enclosed address space
2 | int __seg_gs *p = &arr[0];
| ^
t.c:2:19: note: expected '__seg_gs int *' but pointer is of type 'int *'
All three the attribute, the array and the __typeof__ are needed to trigger the
failure. Any type attribute that forms a variant has the same effect.
Only the address space is lost. A const or a volatile survives, because
an element access takes those from the array node, which does keep them.
An address space is read from the element type instead.
This shows up with a GCC with btf tags to build the Linux kernel.