Re: [PATCH v3 02/15] cpus: Add const-qualified CPU environment accessors
Richard Henderson <[email protected]>
| Newsgroups | org.nongnu.qemu-devel,org.nongnu.qemu-arm,org.nongnu.qemu-riscv |
|---|---|
| Message-ID | <[email protected]> |
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)))
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~