Re: typeof() preserves address space information

Chris Li <[email protected]>
Newsgroups org.kernel.vger.linux-sparse
Message-ID <CACePvbU_NNkQVP9tMuu5vzcBsCApKV9+viWCEO6drwg3WhzVJg@mail.gmail.com>
On Thu, Oct 16, 2025 at 8:31 AM Uros Bizjak <[email protected]> wrote:
>
> 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].

Hi Uros, thanks for the detailed report.

Anyone interested in turning the above test case into a  validation
check? We can mark that test case as "known to fail" right now. We can
then give it to some sparse new comers as warm up projects to make
some failure test cases pass.

Chris
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.