[PATCH v2] tcg: Silence ubsan error on tcg_splitwx_diff causing overflow

Fabiano Rosas posted 1 patch 2 days, 7 hours ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260605132539.2775364-1-farosas@suse.de
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>
include/tcg/tcg.h | 2 +-
tcg/tcg.c         | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
[PATCH v2] tcg: Silence ubsan error on tcg_splitwx_diff causing overflow
Posted by Fabiano Rosas 2 days, 7 hours ago
UBSAN complains:
runtime error: addition of unsigned offset to 0x7bc06e1f5000
overflowed to 0x7bc02e1f5000

Change tcg_splitwx_diff to ptrdiff_t and silence the error.

Signed-off-by: Fabiano Rosas <farosas@suse.de>
---
 include/tcg/tcg.h | 2 +-
 tcg/tcg.c         | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h
index 45c7e118c3..7669dc1c2d 100644
--- a/include/tcg/tcg.h
+++ b/include/tcg/tcg.h
@@ -447,7 +447,7 @@ static inline bool temp_readonly(TCGTemp *ts)
 
 extern __thread TCGContext *tcg_ctx;
 extern const void *tcg_code_gen_epilogue;
-extern uintptr_t tcg_splitwx_diff;
+extern ptrdiff_t tcg_splitwx_diff;
 extern TCGv_env tcg_env;
 
 bool in_code_gen_buffer(const void *p);
diff --git a/tcg/tcg.c b/tcg/tcg.c
index 2ca44766f6..1e77f2365a 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -244,7 +244,7 @@ unsigned int tcg_cur_ctxs;
 unsigned int tcg_max_ctxs;
 TCGv_env tcg_env;
 const void *tcg_code_gen_epilogue;
-uintptr_t tcg_splitwx_diff;
+ptrdiff_t tcg_splitwx_diff;
 
 #ifndef CONFIG_TCG_INTERPRETER
 tcg_prologue_fn *tcg_qemu_tb_exec;
-- 
2.53.0
Re: [PATCH v2] tcg: Silence ubsan error on tcg_splitwx_diff causing overflow
Posted by Richard Henderson 2 days, 5 hours ago
On 6/5/26 06:25, Fabiano Rosas wrote:
> UBSAN complains:
> runtime error: addition of unsigned offset to 0x7bc06e1f5000
> overflowed to 0x7bc02e1f5000
> 
> Change tcg_splitwx_diff to ptrdiff_t and silence the error.
> 
> Signed-off-by: Fabiano Rosas <farosas@suse.de>
> ---
>   include/tcg/tcg.h | 2 +-
>   tcg/tcg.c         | 2 +-
>   2 files changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~

> 
> diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h
> index 45c7e118c3..7669dc1c2d 100644
> --- a/include/tcg/tcg.h
> +++ b/include/tcg/tcg.h
> @@ -447,7 +447,7 @@ static inline bool temp_readonly(TCGTemp *ts)
>   
>   extern __thread TCGContext *tcg_ctx;
>   extern const void *tcg_code_gen_epilogue;
> -extern uintptr_t tcg_splitwx_diff;
> +extern ptrdiff_t tcg_splitwx_diff;
>   extern TCGv_env tcg_env;
>   
>   bool in_code_gen_buffer(const void *p);
> diff --git a/tcg/tcg.c b/tcg/tcg.c
> index 2ca44766f6..1e77f2365a 100644
> --- a/tcg/tcg.c
> +++ b/tcg/tcg.c
> @@ -244,7 +244,7 @@ unsigned int tcg_cur_ctxs;
>   unsigned int tcg_max_ctxs;
>   TCGv_env tcg_env;
>   const void *tcg_code_gen_epilogue;
> -uintptr_t tcg_splitwx_diff;
> +ptrdiff_t tcg_splitwx_diff;
>   
>   #ifndef CONFIG_TCG_INTERPRETER
>   tcg_prologue_fn *tcg_qemu_tb_exec;