memory: Use QEMU_ALWAYS_INLINE to silence compile-time warning
PATCH 1/1 memory: Use QEMU_ALWAYS_INLINE to silence compile-time warning
Our robot reported the following compile-time warning while compiling Qemu with -fno-inline cflags:
In function 'load_memop',
inlined from 'load_helper' at /qemu/accel/tcg/cputlb.c:1578:20,
inlined from 'full_ldub_mmu' at /qemu/accel/tcg/cputlb.c:1624:12:
/qemu/accel/tcg/cputlb.c:1502:9: error: call to 'qemu_build_not_reached' declared with attribute error: code path is reachable
qemu_build_not_reached();
^~~~~~~~~~~~~~~~~~~~~~~~
[...]It looks like a false-positive because only (MO_UB ^ MO_BSWAP) will hit the default case in load_memop() while need_swap (size > 1) has already ensured that MO_UB is not involved.
Apply QEMU_ALWAYS_INLINE on memop_size() to make sure it will always be inlined while we're using the compile-time assert, so that the compilers won't get confused.
---
Not sure if it's the right fix, but seems works fine to me :)
include/exec/memop.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/exec/memop.h +1 -1
@@ -110,7 +110,7 @@ typedef enum MemOp { } MemOp;/* MemOp to size in bytes. */ -static inline unsigned memop_size (MemOp op) +static inline unsigned QEMU_ALWAYS_INLINE memop_size (MemOp op) {return 1 << (op &MO_SIZE ); }
Signature · 1 line
2.19.1
Quoted 2 lines · Zenghui Yu
Our robot reported the following compile-time warning while compiling Qemu with -fno-inline cflags:
Why are you doing this?
Quoted 8 lines
In function '
load_memop',inlined from 'load_helper' at /qemu/accel/tcg/cputlb.c:1578:20, inlined from 'full_ldub_mmu' at /qemu/accel/tcg/cputlb.c:1624:12: /qemu/accel/tcg/cputlb.c:1502:9: error: call to 'qemu_build_not_reached' declared with attribute error: code path is reachable qemu_build_not_reached(); ^~~~~~~~~~~~~~~~~~~~~~~~ [...]
Of course, the assert is compiled out when optimization is off, which is the only time we expect inlining to be off.
The patch isn't wrong, exactly, but I question whether we want to support completely arbitrary combinations of compile flags.
r~
Quoted 15 lines · Richard Henderson
Quoted 2 lines · Zenghui Yu
Our robot reported the following compile-time warning while compiling Qemu with -fno-inline cflags:
Why are you doing this?
Quoted 8 lines
In function '
load_memop',inlined from 'load_helper' at /qemu/accel/tcg/cputlb.c:1578:20, inlined from 'full_ldub_mmu' at /qemu/accel/tcg/cputlb.c:1624:12: /qemu/accel/tcg/cputlb.c:1502:9: error: call to 'qemu_build_not_reached' declared with attribute error: code path is reachable qemu_build_not_reached(); ^~~~~~~~~~~~~~~~~~~~~~~~ [...]
Quoted 5 lines
Of course, the assert is compiled out when optimization is off, which is the only time we expect inlining to be off.
The patch isn't wrong, exactly, but I question whether we want to support completely arbitrary combinations of compile flags.
To follow up: if you *really* need to support -fno-inline, then perhaps the correct patch is to change
- #ifdef __OPTIMIZE__
+ #if defined(__OPTIMIZE__) && !defined(__NO_INLINE__) extern void QEMU_NORETURN QEMU_ERROR("code path is reachable")
qemu_build_not_reached(void);
#else
#define qemu_build_not_reached() g_assert_not_reached() #endif
within include/qemu/compiler.h.
r~
Hi Richard,
Quoted 6 lines · Richard Henderson
Quoted 5 lines · Richard Henderson
Quoted 2 lines · Zenghui Yu
Our robot reported the following compile-time warning while compiling Qemu with -fno-inline cflags:
Why are you doing this?
I'm not sure why it was added in the building test. As you said, there's just a arbitrary combination of compile flags.
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
In function '
load_memop',inlined from 'load_helper' at /qemu/accel/tcg/cputlb.c:1578:20, inlined from 'full_ldub_mmu' at /qemu/accel/tcg/cputlb.c:1624:12: /qemu/accel/tcg/cputlb.c:1502:9: error: call to 'qemu_build_not_reached' declared with attribute error: code path is reachable qemu_build_not_reached(); ^~~~~~~~~~~~~~~~~~~~~~~~ [...]
Quoted 5 lines
Quoted 5 lines
Of course, the assert is compiled out when optimization is off, which is the only time we expect inlining to be off.
The patch isn't wrong, exactly, but I question whether we want to support completely arbitrary combinations of compile flags.
It doesn't hurt to do the right thing, and you already have the good approach :)
Quoted 7 lines
To follow up: if you *really* need to support -fno-inline, then perhaps the correct patch is to change
- #ifdef
__OPTIMIZE__
+ #ifdefined(__OPTIMIZE__)&& !defined(__NO_INLINE__) extern voidQEMU_NORETURNQEMU_ERROR("code path is reachable")
Quoted 6 lines
qemu_build_not_reached(void); #else #define qemu_build_not_reached() g_assert_not_reached() #endifwithin
include/qemu/compiler.h.
Thanks for this. I've tested it with -fno-inlie and it indeed works. I will send it as v2.
Thanks,
Zenghui