Re: [PATCH v3 02/15] cpus: Add const-qualified CPU environment accessors

Philippe Mathieu-Daudé <[email protected]>
Newsgroups org.nongnu.qemu-riscv,org.nongnu.qemu-arm,org.nongnu.qemu-devel
Message-ID <[email protected]>
On 21/8/26 19:07, Richard Henderson wrote:
> On 8/21/26 08:51, Philippe Mathieu-Daudé wrote:
>> No, this now fails distinctly on Ubuntu 24.04:
>>
>> In file included from ../accel/tcg/tcg-runtime.c:26:
>> ../accel/tcg/tcg-runtime.c: In function ‘helper_exit_atomic’:
>> /home/runner/work/qemu/qemu/include/exec/cpu-common.h:100:31: error: 
>> expected expression before ‘typeof’
>>    100 | #define env_cpu(env) _Generic(typeof(*env), \
>>        |                               ^~~~~~
>> ../accel/tcg/tcg-runtime.c:135:26: note: in expansion of macro ‘env_cpu’
>>    135 |     cpu_loop_exit_atomic(env_cpu(env), GETPC());
>>        |                          ^~~~~~~
> 
> Yeah, this of course fails because _Generic wants an expression and 
> typeof() is a type not an expression.
> 
> However, in this case less is more -- just don't dereference env:
> 
> #define env_cpu(env) _Generic(env, \
>              CPUArchState *: \
>                  (CPUState *)((void *)(env) - sizeof(CPUState)), \
>              const CPUArchState *: \
>                  (const CPUState *)((const void *)(env) - 
> sizeof(CPUState)))

Indeed :) The simpler the better. Thanks for the help!
> 
> etc.  It's only top-level qualifiers that are stripped (so const int -> 
> const), but qualified pointers aren't top level (so const int * and int 
> * do not match).
> 
> 
> r~
>
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.