typeof() preserves address space information
Uros Bizjak <[email protected]>
| Newsgroups | org.kernel.vger.linux-sparse |
|---|---|
| Message-ID | <CAFULd4ZV6OiDZF8zknddrxPRTD5vhSQE6nEux4dr+2p1A7N6uA@mail.gmail.com> |
The following testcase:
--cut here--
#ifdef __CHECKER__
# define __seg_gs __attribute__((address_space(__seg_gs)))
# define __seg_fs __attribute__((address_space(__seg_fs)))
#endif
#define __read(var) (*(volatile typeof(var) *)&(var))
extern int __seg_gs m;
int foo (void);
int foo (void)
{
return __read (m);
}
--cut here--
compiles with GCC (15+) without warnings, but sparse warns:
_.c:13:10: warning: cast removes address space '__seg_gs' of expression
typeof () operator should preserve all qualifiers (const, volatile,
__seg_gs, etc). OTOH, typeof_unqual () operator strips all qualifiers
and returns unqualified type of what typeof () returns. Please see
notes of [1].
[1] https://en.cppreference.com/w/c/language/typeof.html
Uros.