tcg: If DEBUG_TCGV, distinguish TCGv_ptr from TCGv_i32/TCGv_i64
cover tcg: If DEBUG_TCGV, distinguish TCGv_ptr from TCGv_i32/TCGv_i64
This patch series enhances the type checking of TCG values done when compiling with debugging enabled, so that it can detect confusion of TCGv_ptr values with whichever of TCGv_i32 and TCGv_i64 corresponds to the pointer-width type on the compile host. This means that such errors will always be compile failures, rather than only failing on one of the two kinds of compile host.
In particular, this would have caught the recent compile error I introduced...
I've tested this on both 32 and 64 bit hosts, with a full compile for all targets. Note that to get a clean debug compile for both hosts (whether with or without this patchset) you'll need to have applied the following recent patches which all fix compile problems:
* http://patchwork.ozlabs.org/patch/97559/
(target-arm: Fix compilation failure for 64 bit hosts)
* http://patchwork.ozlabs.org/patch/97418/
(target-s390x: Fix wrong argument in call of tcg_gen_shl_i64())
* http://patchwork.ozlabs.org/patch/96665/
(ppc: Fix compilation for ppc64-softmmu)
Peter Maydell (2):
tcg/tcg-op.h: Fix prototypes for ld/st functions on 64 bit hosts
tcg: If DEBUG_TCGV, distinguish TCGv_ptr from TCGv_i32/TCGv_i64
tcg/tcg-op.h | 48 +++++++++++++++++++++++++++--------------------- tcg/tcg.h | 52 ++++++++++++++++++++++++++++++++++------------------ 2 files changed, 61 insertions(+), 39 deletions(-)
PATCH 1/2 tcg/tcg-op.h: Fix prototypes for ld/st functions on 64 bit hosts
The prototypes for the ld/st functions on a 64 bit host declared the address parameter as a TCGv_i64 rather than a TCGv_ptr. This worked OK (since the two are aliases), but needs to be fixed to allow extension of TCG type debugging to i64/i32/ptr mismatches.
--- tcg/tcg-op.h | 22 +++++++++++----------- 1 files changed, 11 insertions(+), 11 deletions(-)
tcg/tcg-op.h +11 -11
@@ -1063,66 +1063,66 @@ static inline void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)tcg_gen_op2i_i64 (INDEX_op_movi_i64, ret, arg); } -static inline void tcg_gen_ld8u_i64 (TCGv_i64 ret,TCGv_i64 arg2, +static inline void tcg_gen_ld8u_i64 (TCGv_i64 ret,TCGv_ptr arg2,tcg_target_long offset) {tcg_gen_ldst_op_i64 (INDEX_op_ld8u_i64, ret, arg2, offset); } -static inline void tcg_gen_ld8s_i64 (TCGv_i64 ret,TCGv_i64 arg2, +static inline void tcg_gen_ld8s_i64 (TCGv_i64 ret,TCGv_ptr arg2,tcg_target_long offset) {tcg_gen_ldst_op_i64 (INDEX_op_ld8s_i64, ret, arg2, offset); } -static inline void tcg_gen_ld16u_i64 (TCGv_i64 ret,TCGv_i64 arg2, +static inline void tcg_gen_ld16u_i64 (TCGv_i64 ret,TCGv_ptr arg2,tcg_target_long offset) {tcg_gen_ldst_op_i64 (INDEX_op_ld16u_i64, ret, arg2, offset); } -static inline void tcg_gen_ld16s_i64 (TCGv_i64 ret,TCGv_i64 arg2, +static inline void tcg_gen_ld16s_i64 (TCGv_i64 ret,TCGv_ptr arg2,tcg_target_long offset) {tcg_gen_ldst_op_i64 (INDEX_op_ld16s_i64, ret, arg2, offset); } -static inline void tcg_gen_ld32u_i64 (TCGv_i64 ret,TCGv_i64 arg2, +static inline void tcg_gen_ld32u_i64 (TCGv_i64 ret,TCGv_ptr arg2,tcg_target_long offset) {tcg_gen_ldst_op_i64 (INDEX_op_ld32u_i64, ret, arg2, offset); } -static inline void tcg_gen_ld32s_i64 (TCGv_i64 ret,TCGv_i64 arg2, +static inline void tcg_gen_ld32s_i64 (TCGv_i64 ret,TCGv_ptr arg2,tcg_target_long offset) {tcg_gen_ldst_op_i64 (INDEX_op_ld32s_i64, ret, arg2, offset); } -static inline void tcg_gen_ld_i64 (TCGv_i64 ret,TCGv_i64 arg2,tcg_target_long offset) +static inline void tcg_gen_ld_i64 (TCGv_i64 ret,TCGv_ptr arg2,tcg_target_long offset) {tcg_gen_ldst_op_i64 (INDEX_op_ld_i64, ret, arg2, offset); } -static inline void tcg_gen_st8_i64 (TCGv_i64 arg1,TCGv_i64 arg2, +static inline void tcg_gen_st8_i64 (TCGv_i64 arg1,TCGv_ptr arg2,tcg_target_long offset) {tcg_gen_ldst_op_i64 (INDEX_op_st8_i64, arg1, arg2, offset); } -static inline void tcg_gen_st16_i64 (TCGv_i64 arg1,TCGv_i64 arg2, +static inline void tcg_gen_st16_i64 (TCGv_i64 arg1,TCGv_ptr arg2,tcg_target_long offset) {tcg_gen_ldst_op_i64 (INDEX_op_st16_i64, arg1, arg2, offset); } -static inline void tcg_gen_st32_i64 (TCGv_i64 arg1,TCGv_i64 arg2, +static inline void tcg_gen_st32_i64 (TCGv_i64 arg1,TCGv_ptr arg2,tcg_target_long offset) {tcg_gen_ldst_op_i64 (INDEX_op_st32_i64, arg1, arg2, offset); } -static inline void tcg_gen_st_i64 (TCGv_i64 arg1,TCGv_i64 arg2,tcg_target_long offset) +static inline void tcg_gen_st_i64 (TCGv_i64 arg1,TCGv_ptr arg2,tcg_target_long offset) {tcg_gen_ldst_op_i64 (INDEX_op_st_i64, arg1, arg2, offset); }
Signature · 1 line
1.7.1
PATCH 2/2 tcg: If DEBUG_TCGV, distinguish TCGv_ptr from TCGv_i32/TCGv_i64
In reply to Peter MaydellWhen compiling with DEBUG_TCGV enabled, make the TCGv_ptr type distinct from TCGv_i32/TCGv_i64. This means that using an i32 or i64 TCG op to manipulate a TCGv_ptr will always be detected at compile time, rather than only if compiling on a host system with the other word size.
NB: the tcg_add_ptr and tcg_sub_ptr macros have been removed as they were not used anywhere.
--- tcg/tcg-op.h | 26 ++++++++++++++++---------- tcg/tcg.h | 52 ++++++++++++++++++++++++++++++++++------------------ 2 files changed, 50 insertions(+), 28 deletions(-)
tcg/tcg-op.h +16 -10
@@ -2304,8 +2304,8 @@ static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)#endif } -#define tcg_gen_ld_ptr tcg_gen_ld_i32 -#define tcg_gen_discard_ptr tcg_gen_discard_i32 +#define tcg_gen_ld_ptr (R ,A ,O ) tcg_gen_ld_i32(TCGV_PTR_TO_NAT(R), (A), (O)) +#define tcg_gen_discard_ptr (A ) tcg_gen_discard_i32(TCGV_PTR_TO_NAT(A))#else /* TCG_TARGET_REG_BITS == 32 */
@@ -2372,8 +2372,8 @@ static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index) tcg_gen_qemu_ldst_op_i64(INDEX_op_qemu_st64, arg, addr, mem_index); } -#define tcg_gen_ld_ptr tcg_gen_ld_i64 -#define tcg_gen_discard_ptr tcg_gen_discard_i64 +#define tcg_gen_ld_ptr (R ,A ,O ) tcg_gen_ld_i64(TCGV_PTR_TO_NAT(R), (A), (O)) +#define tcg_gen_discard_ptr (A ) tcg_gen_discard_i64(TCGV_PTR_TO_NAT(A))#endif /* TCG_TARGET_REG_BITS != 32 */
@@ -2523,11 +2523,17 @@ static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)#endif #if TCG_TARGET_REG_BITS ==32 -#define tcg_gen_add_ptr tcg_gen_add_i32 -#define tcg_gen_addi_ptr tcg_gen_addi_i32 -#define tcg_gen_ext_i32_ptr tcg_gen_mov_i32 +#define tcg_gen_add_ptr (R ,A ,B ) tcg_gen_add_i32(TCGV_PTR_TO_NAT(R), \ + TCGV_PTR_TO_NAT(A), \ + TCGV_PTR_TO_NAT(B)) +#define tcg_gen_addi_ptr (R ,A ,B ) tcg_gen_addi_i32(TCGV_PTR_TO_NAT(R), \ + TCGV_PTR_TO_NAT(A), (B)) +#define tcg_gen_ext_i32_ptr (R ,A ) tcg_gen_mov_i32(TCGV_PTR_TO_NAT(R), (A))#else /* TCG_TARGET_REG_BITS == 32 */ -#define tcg_gen_add_ptr tcg_gen_add_i64 -#define tcg_gen_addi_ptr tcg_gen_addi_i64 -#define tcg_gen_ext_i32_ptr tcg_gen_ext_i32_i64 +#define tcg_gen_add_ptr (R ,A ,B ) tcg_gen_add_i64(TCGV_PTR_TO_NAT(R), \ + TCGV_PTR_TO_NAT(A), \ + TCGV_PTR_TO_NAT(B)) +#define tcg_gen_addi_ptr (R ,A ,B ) tcg_gen_addi_i64(TCGV_PTR_TO_NAT(R), \ + TCGV_PTR_TO_NAT(A), (B)) +#define tcg_gen_ext_i32_ptr (R ,A ) tcg_gen_ext_i32_i64(TCGV_PTR_TO_NAT(R), (A))#endif /* TCG_TARGET_REG_BITS != 32 */
tcg/tcg.h +34 -18
81 lines not on this page · raw message
Signature · 1 line
1.7.1
Quoted 22 lines · Peter Maydell
This patch series enhances the type checking of TCG values done when compiling with debugging enabled, so that it can detect confusion of
TCGv_ptrvalues with whichever ofTCGv_i32andTCGv_i64corresponds to the pointer-width type on the compile host. This means that such errors will always be compile failures, rather than only failing on one of the two kinds of compile host.In particular, this would have caught the recent compile error I introduced...
I've tested this on both 32 and 64 bit hosts, with a full compile for all targets. Note that to get a clean debug compile for both hosts (whether with or without this patchset) you'll need to have applied the following recent patches which all fix compile problems:
* http://patchwork.ozlabs.org/patch/97559/
(target-arm: Fix compilation failure for 64 bit hosts)
* http://patchwork.ozlabs.org/patch/97418/
(target-s390x: Fix wrong argument in call oftcg_gen_shl_i64())
* http://patchwork.ozlabs.org/patch/96665/
(ppc: Fix compilation for ppc64-softmmu)
Quoted 8 lines
Peter Maydell (2):
tcg/tcg-op.h: Fix prototypes for ld/st functions on 64 bit hosts
tcg: IfDEBUG_TCGV, distinguishTCGv_ptrfrom TCGv_i32/TCGv_i64tcg/tcg-op.h | 48 +++++++++++++++++++++++++++--------------------- tcg/tcg.h | 52 ++++++++++++++++++++++++++++++++++------------------ 2 files changed, 61 insertions(+), 39 deletions(-)
Thanks, both applied.
Signature · 2 lines
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net