Skip to contentSkip to conversation

compiler.h: Don't use compile-time assert when __NO_INLINE__ is defined

PATCH Applied Zenghui Yu 2 participants 2 messages Feb 5, 2020 – Feb 16, 2020

lore
Share & tools
lore

Zenghui Yu

author
#0 lore raw

PATCH v2 1/1 compiler.h: Don't use compile-time assert when __NO_INLINE__ is defined

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.

So the thing is that compilers get confused by the -fno-inline and just can't accurately evaluate memop_size(op) at compile time, and then the qemu_build_not_reached() is wrongly triggered by (MO_UB ^ MO_BSWAP). Let's carefully don't use the compile-time assert when no functions will be inlined into their callers.

---

v2 is actually written by Richard Henderson.

v1: https://lore.kernel.org/r/[email protected]

 include/qemu/compiler.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/qemu/compiler.h +1 -1
index 85c02c16d3..c76281f354 100644
@@ -236,7 +236,7 @@
  * supports QEMU_ERROR, this will be reported at compile time; otherwise
  * this will be reported at link time due to the missing symbol.
  */
-#ifdef __OPTIMIZE__
+#if defined(__OPTIMIZE__) && !defined(__NO_INLINE__)
 extern void QEMU_NORETURN QEMU_ERROR("code path is reachable")
     qemu_build_not_reached(void);
 #else
Signature · 1 line
2.19.1
#1 lore raw
Quoted 24 lines · Zenghui Yu

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.

So the thing is that compilers get confused by the -fno-inline and just can't accurately evaluate memop_size(op) at compile time, and then the qemu_build_not_reached() is wrongly triggered by (MO_UB ^ MO_BSWAP). Let's carefully don't use the compile-time assert when no functions will be inlined into their callers.

Quoted 8 lines

---

v2 is actually written by Richard Henderson.

v1: https://lore.kernel.org/r/[email protected]

 include/qemu/compiler.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Queued to tcg-next.

r~