qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] compiler.h: Don't use compile-time assert when __NO_INLINE__ is defined
@ 2020-02-05 14:15 Zenghui Yu
  2020-02-16  3:21 ` Richard Henderson
  0 siblings, 1 reply; 2+ messages in thread
From: Zenghui Yu @ 2020-02-05 14:15 UTC (permalink / raw)
  To: pbonzini, richard.henderson, tony.nguyen
  Cc: Zenghui Yu, wanghaibin.wang, qemu-devel, Euler Robot

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.

Reported-by: Euler Robot <euler.robot@huawei.com>
Suggested-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Zenghui Yu <yuzenghui@huawei.com>
---

v2 is actually written by Richard Henderson.

v1: https://lore.kernel.org/r/20200205081703.631-1-yuzenghui@huawei.com

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

diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
index 85c02c16d3..c76281f354 100644
--- a/include/qemu/compiler.h
+++ b/include/qemu/compiler.h
@@ -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
-- 
2.19.1




^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] compiler.h: Don't use compile-time assert when __NO_INLINE__ is defined
  2020-02-05 14:15 [PATCH v2] compiler.h: Don't use compile-time assert when __NO_INLINE__ is defined Zenghui Yu
@ 2020-02-16  3:21 ` Richard Henderson
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Henderson @ 2020-02-16  3:21 UTC (permalink / raw)
  To: Zenghui Yu, pbonzini, tony.nguyen
  Cc: wanghaibin.wang, qemu-devel, Euler Robot

On 2/5/20 6:15 AM, Zenghui Yu wrote:
> 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.
> 
> Reported-by: Euler Robot <euler.robot@huawei.com>
> Suggested-by: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: Zenghui Yu <yuzenghui@huawei.com>
> ---
> 
> v2 is actually written by Richard Henderson.
> 
> v1: https://lore.kernel.org/r/20200205081703.631-1-yuzenghui@huawei.com
> 
>  include/qemu/compiler.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Queued to tcg-next.


r~


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-02-16  3:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-05 14:15 [PATCH v2] compiler.h: Don't use compile-time assert when __NO_INLINE__ is defined Zenghui Yu
2020-02-16  3:21 ` Richard Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).