diff mbox series

Make TARGET_PAGE_MASK typed as target_ulong

Message ID 20240614192938.1690188-1-rkir@google.com
State New
Headers show
Series Make TARGET_PAGE_MASK typed as target_ulong | expand

Commit Message

Roman Kiryanov June 14, 2024, 7:29 p.m. UTC
this fixes the build warnings like

accel/tcg/cputlb.c:416:13: warning: shifting a negative signed value is undefined [-Wshift-negative-value]
    mask &= TARGET_PAGE_MASK | TLB_INVALID_MASK;
            ^~~~~~~~~~~~~~~~
include/exec/cpu-all.h:169:45: note: expanded from macro 'TARGET_PAGE_MASK'
                            ~~~~~~~~~~~~~~~ ^

also this fixes the inconsitency in the return
type of qemu_target_page_mask (int could be
shorter than target_long).

Signed-off-by: Roman Kiryanov <rkir@google.com>
---
 include/exec/cpu-all.h     | 4 ++--
 include/exec/target_page.h | 2 +-
 page-target.c              | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

Comments

Richard Henderson June 15, 2024, 11:59 p.m. UTC | #1
On 6/14/24 12:29, Roman Kiryanov wrote:
> this fixes the build warnings like
> 
> accel/tcg/cputlb.c:416:13: warning: shifting a negative signed value is undefined [-Wshift-negative-value]
>      mask &= TARGET_PAGE_MASK | TLB_INVALID_MASK;
>              ^~~~~~~~~~~~~~~~
> include/exec/cpu-all.h:169:45: note: expanded from macro 'TARGET_PAGE_MASK'
>                              ~~~~~~~~~~~~~~~ ^
> 
> also this fixes the inconsitency in the return
> type of qemu_target_page_mask (int could be
> shorter than target_long).
> 
> Signed-off-by: Roman Kiryanov <rkir@google.com>

No, this will cause failures, because we need this value to sign-extend to when the 
context includes {u}int64_t, and target_ulong is uint32_t.

What options are you using, because this warning should not be generated with -fwrapv.


r~
Roman Kiryanov June 16, 2024, 5:40 p.m. UTC | #2
Hi Richard,

thank you for looking into this.

> No, this will cause failures, because we need this value to sign-extend to when the
> context includes {u}int64_t, and target_ulong is uint32_t.

I did not expect this, good catch. I see QEMU uses size_t as the
return type in qemu_target_page_size which returns TARGET_PAGE_SIZE.
Maybe use size_t for TARGET_PAGE_MASK everywhere (including
qemu_target_page_mask) as well?

> What options are you using, because this warning should not be generated with -fwrapv.

Good point, I think we missed this option.

Regards,
Roman.
Richard Henderson June 16, 2024, 6:10 p.m. UTC | #3
On 6/16/24 10:40, Roman Kiryanov wrote:
> Hi Richard,
> 
> thank you for looking into this.
> 
>> No, this will cause failures, because we need this value to sign-extend to when the
>> context includes {u}int64_t, and target_ulong is uint32_t.
> 
> I did not expect this, good catch. I see QEMU uses size_t as the
> return type in qemu_target_page_size which returns TARGET_PAGE_SIZE.
> Maybe use size_t for TARGET_PAGE_MASK everywhere (including
> qemu_target_page_mask) as well?

No, because size_t != uint64_t.
We still support 32-bit hosts.


r~
diff mbox series

Patch

diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
index 6f09b86e7f..238a847eca 100644
--- a/include/exec/cpu-all.h
+++ b/include/exec/cpu-all.h
@@ -152,8 +152,8 @@  extern const TargetPageBits target_page;
 # define TARGET_PAGE_SIZE    (-(int)TARGET_PAGE_MASK)
 #else
 # define TARGET_PAGE_BITS_MIN TARGET_PAGE_BITS
-# define TARGET_PAGE_SIZE    (1 << TARGET_PAGE_BITS)
-# define TARGET_PAGE_MASK    ((target_long)-1 << TARGET_PAGE_BITS)
+# define TARGET_PAGE_SIZE    ((target_ulong)1 << TARGET_PAGE_BITS)
+# define TARGET_PAGE_MASK    ((target_ulong)-1 << TARGET_PAGE_BITS)
 #endif
 
 #define TARGET_PAGE_ALIGN(addr) ROUND_UP((addr), TARGET_PAGE_SIZE)
diff --git a/include/exec/target_page.h b/include/exec/target_page.h
index 98ffbb5c23..57d60f2b06 100644
--- a/include/exec/target_page.h
+++ b/include/exec/target_page.h
@@ -15,7 +15,7 @@ 
 #define EXEC_TARGET_PAGE_H
 
 size_t qemu_target_page_size(void);
-int qemu_target_page_mask(void);
+target_ulong qemu_target_page_mask(void);
 int qemu_target_page_bits(void);
 int qemu_target_page_bits_min(void);
 
diff --git a/page-target.c b/page-target.c
index 82211c8593..7176c29555 100644
--- a/page-target.c
+++ b/page-target.c
@@ -17,7 +17,7 @@  size_t qemu_target_page_size(void)
     return TARGET_PAGE_SIZE;
 }
 
-int qemu_target_page_mask(void)
+target_ulong qemu_target_page_mask(void)
 {
     return TARGET_PAGE_MASK;
 }