hexagon: GETPC() and shadowing fixes
v2 cover hexagon: GETPC() and shadowing fixes
In v2: reworked with suggestions from Philippe and added a new patch to cover -Wshadow=global.
Brian Cain (2):
target/hexagon: fix some occurrences of -Wshadow=local target/hexagon: avoid shadowing globals
Matheus Tavares Bernardino (1):
target/hexagon: move GETPC() calls to top level helpers
target/hexagon/genptr.c | 56 ++++++++--------- target/hexagon/genptr.h | 18 +++--- target/hexagon/imported/alu.idef | 6 +- target/hexagon/macros.h | 19 +++--- target/hexagon/mmvec/macros.h | 6 +- target/hexagon/mmvec/system_ext_mmvec.c | 4 +- target/hexagon/mmvec/system_ext_mmvec.h | 2 +- target/hexagon/op_helper.c | 84 ++++++++++--------------- target/hexagon/op_helper.h | 9 --- target/hexagon/translate.c | 9 ++- 10 files changed, 91 insertions(+), 122 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/3 target/hexagon: move GETPC() calls to top level helpers
From: Matheus Tavares Bernardino <[email protected]>
As docs/devel/loads-stores.rst states:
``GETPC()`` should be used with great care: calling it in other functions that are *not* the top level ``HELPER(foo)`` will cause unexpected behavior. Instead, the value of ``GETPC()`` should be read from the helper and passed if needed to the functions that the helper calls.
Let's fix the GETPC() usage in Hexagon, making sure it's always called from top level helpers and passed down to the places where it's needed. There are a few snippets where that is not currently the case:
- probe_store(), which is only called from two helpers, so it's easy to move GETPC() up.
- mem_load*() functions, which are also called directly from helpers, but through the MEM_LOAD*() set of macros. Note that this are only used when compiling with --disable-hexagon-idef-parser.
In this case, we also take this opportunity to simplify the code, unifying the mem_load*() functions.
- HELPER(probe_hvx_stores), when called from another helper, ends up using its own GETPC() expansion instead of the top level caller.
Message-Id: <2c74c3696946edba7cc5b2942cf296a5af532052.1689070412.git.quic_mathbern@quicinc.com>-ne
--- target/hexagon/macros.h | 19 +++++----- target/hexagon/op_helper.c | 75 +++++++++++++++----------------------- target/hexagon/op_helper.h | 9 ----- 3 files changed, 38 insertions(+), 65 deletions(-)
target/hexagon/macros.h +9 -10
@@ -173,15 +173,6 @@#define MEM_STORE8 (VA ,DATA ,SLOT ) \ MEM_STORE8_FUNC(DATA)(cpu_env, VA, DATA, SLOT)#else -#define MEM_LOAD1s (VA ) ((int8_t)mem_load1(env, pkt_has_store_s1, slot, VA)) -#define MEM_LOAD1u (VA ) ((uint8_t)mem_load1(env, pkt_has_store_s1, slot, VA)) -#define MEM_LOAD2s (VA ) ((int16_t)mem_load2(env, pkt_has_store_s1, slot, VA)) -#define MEM_LOAD2u (VA ) ((uint16_t)mem_load2(env, pkt_has_store_s1, slot, VA)) -#define MEM_LOAD4s (VA ) ((int32_t)mem_load4(env, pkt_has_store_s1, slot, VA)) -#define MEM_LOAD4u (VA ) ((uint32_t)mem_load4(env, pkt_has_store_s1, slot, VA)) -#define MEM_LOAD8s (VA ) ((int64_t)mem_load8(env, pkt_has_store_s1, slot, VA)) -#define MEM_LOAD8u (VA ) ((uint64_t)mem_load8(env, pkt_has_store_s1, slot, VA)) -#define MEM_STORE1 (VA ,DATA ,SLOT ) log_store32(env, VA, DATA, 1, SLOT)#define MEM_STORE2 (VA ,DATA ,SLOT ) log_store32(env, VA, DATA, 2, SLOT)#define MEM_STORE4 (VA ,DATA ,SLOT ) log_store32(env, VA, DATA, 4, SLOT)
@@ -530,8 +521,16 @@ static inline TCGv gen_read_ireg(TCGv result, TCGv val, int shift)#ifdef QEMU_GENERATE #define fLOAD (NUM ,SIZE ,SIGN ,EA ,DST ) MEM_LOAD##SIZE##SIGN(DST, EA)#else +#define MEM_LOAD1 cpu_ldub_data_ra +#define MEM_LOAD2 cpu_lduw_data_ra +#define MEM_LOAD4 cpu_ldl_data_ra +#define MEM_LOAD8 cpu_ldq_data_ra +#define fLOAD (NUM ,SIZE ,SIGN ,EA ,DST ) \ - DST = (size##SIZE##SIGN##_t)MEM_LOAD##SIZE##SIGN(EA) + do { \ + check_noshuf(env, pkt_has_store_s1, slot, EA, SIZE, GETPC()); \ + DST = (size##SIZE##SIGN##_t)MEM_LOAD##SIZE(env, EA, GETPC()); \ + } while (0)#endif #define fMEMOP (NUM ,SIZE ,SIGN ,EA ,FNTYPE ,VALUE )
target/hexagon/op_helper.c +29 -46
139 lines not on this page · raw message
target/hexagon/op_helper.h +0 -9
@@ -19,15 +19,6 @@#define HEXAGON_OP_HELPER_H /* Misc functions */ -uint8_t mem_load1 (CPUHexagonState *env,bool pkt_has_store_s1, -uint32_t slot,target_ulong vaddr); -uint16_t mem_load2 (CPUHexagonState *env,bool pkt_has_store_s1, -uint32_t slot,target_ulong vaddr); -uint32_t mem_load4 (CPUHexagonState *env,bool pkt_has_store_s1, -uint32_t slot,target_ulong vaddr); -uint64_t mem_load8 (CPUHexagonState *env,bool pkt_has_store_s1, -uint32_t slot,target_ulong vaddr); -void log_store64 (CPUHexagonState *env,target_ulong addr,int64_t val,int width,int slot); void log_store32(CPUHexagonState *env, target_ulong addr,
Signature · 1 line
2.25.1
PATCH v2 2/3 target/hexagon: fix some occurrences of -Wshadow=local
In reply to Brian CainOf the changes in this commit, the changes in HELPER(commit_hvx_stores)() are less obvious. They are required because of some macro invocations like SCATTER_OP_WRITE_TO_MEM().
e.g.:
In file included from ../target/hexagon/op_helper.c:31:
../target/hexagon/mmvec/macros.h:205:18: error: declaration of ‘i’ shadows a previous local [-Werror=shadow=compatible-local]
205 | for (int i = 0; i < sizeof(MMVector); i += sizeof(TYPE)) { \
| ^
../target/hexagon/op_helper.c:157:17: note: in expansion of macro ‘SCATTER_OP_WRITE_TO_MEM’
157 | SCATTER_OP_WRITE_TO_MEM(uint16_t);
| ^~~~~~~~~~~~~~~~~~~~~~~
../target/hexagon/op_helper.c:135:9: note: shadowed declaration is here
135 | int i;
| ^
In file included from ../target/hexagon/op_helper.c:31:
../target/hexagon/mmvec/macros.h:204:19: error: declaration of ‘ra’ shadows a previous local [-Werror=shadow=compatible-local]
204 | uintptr_t ra = GETPC(); \
| ^~
../target/hexagon/op_helper.c:160:17: note: in expansion of macro ‘SCATTER_OP_WRITE_TO_MEM’
160 | SCATTER_OP_WRITE_TO_MEM(uint32_t);
| ^~~~~~~~~~~~~~~~~~~~~~~
../target/hexagon/op_helper.c:134:15: note: shadowed declaration is here
134 | uintptr_t ra = GETPC();
| ^~
--- target/hexagon/imported/alu.idef | 6 +++--- target/hexagon/mmvec/macros.h | 6 +++--- target/hexagon/op_helper.c | 9 +++------ target/hexagon/translate.c | 9 ++++----- 4 files changed, 13 insertions(+), 17 deletions(-)
target/hexagon/imported/alu.idef +3 -3
@@ -1142,9 +1142,9 @@ Q6INSN(A4_cround_rr,"Rd32=cround(Rs32,Rt32)",ATTRIBS(),"Convergent Round", {RdV tmp128 = fSHIFTR128(tmp128, SHIFT);\ DST = fCAST16S_8S(tmp128);\ } else {\ - size16s_t rndbit_128 = fCAST8S_16S((1LL << (SHIFT - 1))); \ - size16s_t src_128 = fCAST8S_16S(SRC); \ - size16s_t tmp128 = fADD128(src_128, rndbit_128);\ + rndbit_128 = fCAST8S_16S((1LL << (SHIFT - 1))); \ + src_128 = fCAST8S_16S(SRC); \ + tmp128 = fADD128(src_128, rndbit_128);\ tmp128 = fSHIFTR128(tmp128, SHIFT);\ DST = fCAST16S_8S(tmp128);\ }
target/hexagon/mmvec/macros.h +3 -3
@@ -201,14 +201,14 @@ } while (0)#define SCATTER_OP_WRITE_TO_MEM (TYPE ) \ do { \ - uintptr_t ra = GETPC(); \ + uintptr_t ra_ = GETPC(); \ for (int i = 0; i < sizeof(MMVector); i += sizeof(TYPE)) { \ if (test_bit(i, env->vtcm_log.mask)) { \ TYPE dst = 0; \ TYPE inc = 0; \ for (int j = 0; j < sizeof(TYPE); j++) { \ uint8_t val; \ - val = cpu_ldub_data_ra(env, env->vtcm_log.va[i + j], ra); \ + val = cpu_ldub_data_ra(env, env->vtcm_log.va[i + j], ra_); \ dst |= val << (8 * j); \ inc |= env->vtcm_log.data.ub[j + i] << (8 * j); \ clear_bit(j + i, env->vtcm_log.mask); \
@@ -217,7 +217,7 @@ dst += inc; \for (int j =0 ; j <sizeof (TYPE ); j++) { \cpu_stb_data_ra (env, env->vtcm_log.va[i + j], \ - (dst >> (8 * j)) &0xFF , ra); \ + (dst >> (8 * j)) &0xFF , ra_); \ } \ } \ } \
target/hexagon/op_helper.c +3 -6
@@ -132,10 +132,9 @@ void HELPER(gather_store)(CPUHexagonState *env, uint32_t addr, int slot)void HELPER (commit_hvx_stores )(CPUHexagonState *env) {uintptr_t ra =GETPC (); -int i;/* Normal (possibly masked) vector store */ -for (i =0 ; i <VSTORES_MAX ; i++) { +for (int i =0 ; i <VSTORES_MAX ; i++) {if (env->vstore_pending[i]) { env->vstore_pending[i] =0 ;target_ulong va = env->vstore[i].va;
@@ -162,7 +161,7 @@ void HELPER(commit_hvx_stores)(CPUHexagonState *env)g_assert_not_reached (); } }else { -for (i =0 ; i <sizeof (MMVector); i++) { +for (int i =0 ; i <sizeof (MMVector); i++) {if (test_bit (i, env->vtcm_log.mask)) {cpu_stb_data_ra (env, env->vtcm_log.va[i], env->vtcm_log.data.ub[i], ra);
@@ -505,10 +504,8 @@ void HELPER(probe_pkt_scalar_store_s0)(CPUHexagonState *env, int args)static void probe_hvx_stores (CPUHexagonState *env,int mmu_idx,uintptr_t retaddr) { -int i; -/* Normal (possibly masked) vector store */ -for (i =0 ; i <VSTORES_MAX ; i++) { +for (int i =0 ; i <VSTORES_MAX ; i++) {if (env->vstore_pending[i]) {target_ulong va = env->vstore[i].va;int size = env->vstore[i].size;
target/hexagon/translate.c +4 -5
@@ -484,7 +484,6 @@ static void gen_start_packet(DisasContext *ctx) {Packet *pkt = ctx->pkt;target_ulong next_PC = ctx->base.pc_next + pkt->encod_pkt_size_in_bytes; -int i;/* Clear out the disassembly context */ ctx->next_PC = next_PC;
@@ -506,15 +505,15 @@ static void gen_start_packet(DisasContext *ctx)bitmap_zero (ctx->vregs_read,NUM_VREGS );bitmap_zero (ctx->qregs_read,NUM_QREGS ); ctx->qreg_log_idx =0 ; -for (i =0 ; i <STORES_MAX ; i++) { +for (int i =0 ; i <STORES_MAX ; i++) { ctx->store_width[i] =0 ; } ctx->s1_store_processed = false; ctx->pre_commit = true; -for (i =0 ; i <TOTAL_PER_THREAD_REGS ; i++) { +for (int i =0 ; i <TOTAL_PER_THREAD_REGS ; i++) { ctx->new_value[i] =NULL ; } -for (i =0 ; i <NUM_PREGS ; i++) { +for (int i =0 ; i <NUM_PREGS ; i++) { ctx->new_pred_value[i] =NULL ; }
@@ -1228,7 +1227,7 @@ void hexagon_translate_init(void) offsetof(CPUHexagonState, mem_log_stores[i].data64), store_val64_names[i]); } -for (int i =0 ; i <VSTORES_MAX ; i++) { +for (i =0 ; i <VSTORES_MAX ; i++) {snprintf (vstore_addr_names[i],NAME_LEN ,"vstore_addr_%d" , i); hex_vstore_addr[i] =tcg_global_mem_new (cpu_env, offsetof(CPUHexagonState, vstore[i].va),
Signature · 1 line
2.25.1
Re: [PATCH v2 2/3] target/hexagon: fix some occurrences of -Wshadow=local
Quoted 27 lines · Brian Cain
Of the changes in this commit, the changes in
HELPER(commit_hvx_stores)()are less obvious. They are required because of some macro invocations likeSCATTER_OP_WRITE_TO_MEM().e.g.:
In file included from
../target/hexagon/op_helper.c:31:
../target/hexagon/mmvec/macros.h:205:18: error: declaration of ‘i’ shadows a previous local [-Werror=shadow=compatible-local]
205 | for (int i = 0; i < sizeof(MMVector); i += sizeof(TYPE)) { \
| ^
../target/hexagon/op_helper.c:157:17: note: in expansion of macro ‘SCATTER_OP_WRITE_TO_MEM’
157 |SCATTER_OP_WRITE_TO_MEM(uint16_t);
| ^~~~~~~~~~~~~~~~~~~~~~~
../target/hexagon/op_helper.c:135:9: note: shadowed declaration is here
135 | int i;
| ^
In file included from../target/hexagon/op_helper.c:31:
../target/hexagon/mmvec/macros.h:204:19: error: declaration of ‘ra’ shadows a previous local [-Werror=shadow=compatible-local]
204 |uintptr_tra =GETPC(); \
| ^~
../target/hexagon/op_helper.c:160:17: note: in expansion of macro ‘SCATTER_OP_WRITE_TO_MEM’
160 |SCATTER_OP_WRITE_TO_MEM(uint32_t);
| ^~~~~~~~~~~~~~~~~~~~~~~
../target/hexagon/op_helper.c:134:15: note: shadowed declaration is here
134 |uintptr_tra =GETPC();
| ^~
Quoted 8 lines
Reviewed-by Matheus Tavares Bernardino <[email protected]>Signed-off-by Brian Cain <[email protected]>--- target/hexagon/imported/alu.idef | 6 +++--- target/hexagon/mmvec/macros.h | 6 +++--- target/hexagon/op_helper.c | 9 +++------ target/hexagon/translate.c | 9 ++++----- 4 files changed, 13 insertions(+), 17 deletions(-)
RE: [PATCH v2 2/3] target/hexagon: fix some occurrences of -Wshadow=local
In reply to Brian CainQuoted 44 lines
-----Original Message-----
From: Brian Cain <[email protected]>
Sent: Thursday, October 5, 2023 4:22 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH v2 2/3] target/hexagon: fix some occurrences of - Wshadow=localOf the changes in this commit, the changes in
HELPER(commit_hvx_stores)()are less obvious. They are required because of some macro invocations likeSCATTER_OP_WRITE_TO_MEM().e.g.:
In file included from
../target/hexagon/op_helper.c:31:
../target/hexagon/mmvec/macros.h:205:18: error: declaration of ‘i’
shadows a previous local [-Werror=shadow=compatible-local]
205 | for (int i = 0; i < sizeof(MMVector); i += sizeof(TYPE)) { \
| ^
../target/hexagon/op_helper.c:157:17: note: in expansion of macro
‘SCATTER_OP_WRITE_TO_MEM’157 | SCATTER_OP_WRITE_TO_MEM(uint16_t); | ^~~~~~~~~~~~~~~~~~~~~~~
../target/hexagon/op_helper.c:135:9: note: shadowed declaration is here
135 | int i;
| ^
In file included from../target/hexagon/op_helper.c:31:
../target/hexagon/mmvec/macros.h:204:19: error: declaration of ‘ra’
shadows a previous local [-Werror=shadow=compatible-local]
204 |uintptr_tra =GETPC(); \
| ^~
../target/hexagon/op_helper.c:160:17: note: in expansion of macro
‘SCATTER_OP_WRITE_TO_MEM’160 | SCATTER_OP_WRITE_TO_MEM(uint32_t); | ^~~~~~~~~~~~~~~~~~~~~~~
../target/hexagon/op_helper.c:134:15: note: shadowed declaration is here
134 |uintptr_tra =GETPC();
| ^~
Quoted 8 lines
Reviewed-by Matheus Tavares Bernardino <[email protected]>Signed-off-by Brian Cain <[email protected]>--- target/hexagon/imported/alu.idef | 6 +++--- target/hexagon/mmvec/macros.h | 6 +++--- target/hexagon/op_helper.c | 9 +++------ target/hexagon/translate.c | 9 ++++----- 4 files changed, 13 insertions(+), 17 deletions(-)
PATCH v2 3/3 target/hexagon: avoid shadowing globals
In reply to Brian CainThe typedef vaddr is shadowed by vaddr identifiers, so we rename the identifiers to avoid shadowing the type name.
The global cpu_env is shadowed by local cpu_env arguments, so we rename the function arguments to avoid shadowing the global.
--- target/hexagon/genptr.c | 56 ++++++++++++------------- target/hexagon/genptr.h | 18 ++++---- target/hexagon/mmvec/system_ext_mmvec.c | 4 +- target/hexagon/mmvec/system_ext_mmvec.h | 2 +- target/hexagon/op_helper.c | 4 +- 5 files changed, 42 insertions(+), 42 deletions(-)
target/hexagon/genptr.c +28 -28
@@ -334,28 +334,28 @@ void gen_set_byte_i64(int N, TCGv_i64 result, TCGv src)tcg_gen_deposit_i64 (result, result, src64,N *8 ,8 ); } -static inline void gen_load_locked4u (TCGv dest,TCGv vaddr,int mem_index) +static inline void gen_load_locked4u (TCGv dest,TCGv v_addr,int mem_index) { -tcg_gen_qemu_ld_tl (dest, vaddr, mem_index,MO_TEUL ); -tcg_gen_mov_tl (hex_llsc_addr, vaddr); +tcg_gen_qemu_ld_tl (dest, v_addr, mem_index,MO_TEUL ); +tcg_gen_mov_tl (hex_llsc_addr, v_addr);tcg_gen_mov_tl (hex_llsc_val, dest); } -static inline void gen_load_locked8u (TCGv_i64 dest,TCGv vaddr,int mem_index) +static inline void gen_load_locked8u (TCGv_i64 dest,TCGv v_addr,int mem_index) { -tcg_gen_qemu_ld_i64 (dest, vaddr, mem_index,MO_TEUQ ); -tcg_gen_mov_tl (hex_llsc_addr, vaddr); +tcg_gen_qemu_ld_i64 (dest, v_addr, mem_index,MO_TEUQ ); +tcg_gen_mov_tl (hex_llsc_addr, v_addr);tcg_gen_mov_i64 (hex_llsc_val_i64, dest); }static inline void gen_store_conditional4 (DisasContext *ctx, -TCGv pred,TCGv vaddr,TCGv src) +TCGv pred,TCGv v_addr,TCGv src) {TCGLabel *fail =gen_new_label ();TCGLabel *done =gen_new_label ();TCGv one, zero, tmp; -tcg_gen_brcond_tl (TCG_COND_NE , vaddr, hex_llsc_addr, fail); +tcg_gen_brcond_tl (TCG_COND_NE , v_addr, hex_llsc_addr, fail); one =tcg_constant_tl (0xff ); zero =tcg_constant_tl (0 );
@@ -374,13 +374,13 @@ static inline void gen_store_conditional4(DisasContext *ctx, }static inline void gen_store_conditional8 (DisasContext *ctx, -TCGv pred,TCGv vaddr,TCGv_i64 src) +TCGv pred,TCGv v_addr,TCGv_i64 src) {TCGLabel *fail =gen_new_label ();TCGLabel *done =gen_new_label ();TCGv_i64 one, zero, tmp; -tcg_gen_brcond_tl (TCG_COND_NE , vaddr, hex_llsc_addr, fail); +tcg_gen_brcond_tl (TCG_COND_NE , v_addr, hex_llsc_addr, fail); one =tcg_constant_i64 (0xff ); zero =tcg_constant_i64 (0 );
@@ -407,57 +407,57 @@ static TCGv gen_slotval(DisasContext *ctx) }#endif -void gen_store32 (TCGv vaddr,TCGv src,int width,uint32_t slot) +void gen_store32 (TCGv v_addr,TCGv src,int width,uint32_t slot) { -tcg_gen_mov_tl (hex_store_addr[slot], vaddr); +tcg_gen_mov_tl (hex_store_addr[slot], v_addr);tcg_gen_movi_tl (hex_store_width[slot], width);tcg_gen_mov_tl (hex_store_val32[slot], src); } -void gen_store1 (TCGv_env cpu_env,TCGv vaddr,TCGv src,uint32_t slot) +void gen_store1 (TCGv_env cpu_env_,TCGv v_addr,TCGv src,uint32_t slot) { -gen_store32 (vaddr, src,1 , slot); +gen_store32 (v_addr, src,1 , slot); } -void gen_store1i (TCGv_env cpu_env,TCGv vaddr,int32_t src,uint32_t slot) +void gen_store1i (TCGv_env cpu_env_,TCGv v_addr,int32_t src,uint32_t slot) {TCGv tmp =tcg_constant_tl (src); -gen_store1 (cpu_env, vaddr, tmp, slot); +gen_store1 (cpu_env_, v_addr, tmp, slot); } -void gen_store2 (TCGv_env cpu_env,TCGv vaddr,TCGv src,uint32_t slot) +void gen_store2 (TCGv_env cpu_env_,TCGv v_addr,TCGv src,uint32_t slot) { -gen_store32 (vaddr, src,2 , slot); +gen_store32 (v_addr, src,2 , slot); } -void gen_store2i (TCGv_env cpu_env,TCGv vaddr,int32_t src,uint32_t slot) +void gen_store2i (TCGv_env cpu_env_,TCGv v_addr,int32_t src,uint32_t slot) {TCGv tmp =tcg_constant_tl (src); -gen_store2 (cpu_env, vaddr, tmp, slot); +gen_store2 (cpu_env_, v_addr, tmp, slot); } -void gen_store4 (TCGv_env cpu_env,TCGv vaddr,TCGv src,uint32_t slot) +void gen_store4 (TCGv_env cpu_env_,TCGv v_addr,TCGv src,uint32_t slot) { -gen_store32 (vaddr, src,4 , slot); +gen_store32 (v_addr, src,4 , slot); } -void gen_store4i (TCGv_env cpu_env,TCGv vaddr,int32_t src,uint32_t slot) +void gen_store4i (TCGv_env cpu_env_,TCGv v_addr,int32_t src,uint32_t slot) {TCGv tmp =tcg_constant_tl (src); -gen_store4 (cpu_env, vaddr, tmp, slot); +gen_store4 (cpu_env_, v_addr, tmp, slot); } -void gen_store8 (TCGv_env cpu_env,TCGv vaddr,TCGv_i64 src,uint32_t slot) +void gen_store8 (TCGv_env cpu_env_,TCGv v_addr,TCGv_i64 src,uint32_t slot) { -tcg_gen_mov_tl (hex_store_addr[slot], vaddr); +tcg_gen_mov_tl (hex_store_addr[slot], v_addr);tcg_gen_movi_tl (hex_store_width[slot],8 );tcg_gen_mov_i64 (hex_store_val64[slot], src); } -void gen_store8i (TCGv_env cpu_env,TCGv vaddr,int64_t src,uint32_t slot) +void gen_store8i (TCGv_env cpu_env_,TCGv v_addr,int64_t src,uint32_t slot) {TCGv_i64 tmp =tcg_constant_i64 (src); -gen_store8 (cpu_env, vaddr, tmp, slot); +gen_store8 (cpu_env_, v_addr, tmp, slot); }TCGv gen_8bitsof (TCGv result,TCGv value)
target/hexagon/genptr.h +9 -9
@@ -24,15 +24,15 @@extern const SemanticInsn opcode_genptr[]; -void gen_store32 (TCGv vaddr,TCGv src,int width,uint32_t slot); -void gen_store1 (TCGv_env cpu_env,TCGv vaddr,TCGv src,uint32_t slot); -void gen_store2 (TCGv_env cpu_env,TCGv vaddr,TCGv src,uint32_t slot); -void gen_store4 (TCGv_env cpu_env,TCGv vaddr,TCGv src,uint32_t slot); -void gen_store8 (TCGv_env cpu_env,TCGv vaddr,TCGv_i64 src,uint32_t slot); -void gen_store1i (TCGv_env cpu_env,TCGv vaddr,int32_t src,uint32_t slot); -void gen_store2i (TCGv_env cpu_env,TCGv vaddr,int32_t src,uint32_t slot); -void gen_store4i (TCGv_env cpu_env,TCGv vaddr,int32_t src,uint32_t slot); -void gen_store8i (TCGv_env cpu_env,TCGv vaddr,int64_t src,uint32_t slot); +void gen_store32 (TCGv v_addr,TCGv src,int width,uint32_t slot); +void gen_store1 (TCGv_env cpu_env_,TCGv v_addr,TCGv src,uint32_t slot); +void gen_store2 (TCGv_env cpu_env_,TCGv v_addr,TCGv src,uint32_t slot); +void gen_store4 (TCGv_env cpu_env_,TCGv v_addr,TCGv src,uint32_t slot); +void gen_store8 (TCGv_env cpu_env_,TCGv v_addr,TCGv_i64 src,uint32_t slot); +void gen_store1i (TCGv_env cpu_env_,TCGv v_addr,int32_t src,uint32_t slot); +void gen_store2i (TCGv_env cpu_env_,TCGv v_addr,int32_t src,uint32_t slot); +void gen_store4i (TCGv_env cpu_env_,TCGv v_addr,int32_t src,uint32_t slot); +void gen_store8i (TCGv_env cpu_env_,TCGv v_addr,int64_t src,uint32_t slot);TCGv gen_read_reg (TCGv result,int num);TCGv gen_read_preg (TCGv pred,uint8_t num);TCGv get_result_gpr (DisasContext *ctx,int rnum);
target/hexagon/mmvec/system_ext_mmvec.c +2 -2
@@ -19,12 +19,12 @@#include "cpu.h" #include "mmvec/system_ext_mmvec.h" -void mem_gather_store (CPUHexagonState *env,target_ulong vaddr,int slot) +void mem_gather_store (CPUHexagonState *env,target_ulong v_addr,int slot) {size_t size =sizeof (MMVector); env->vstore_pending[slot] =1 ; - env->vstore[slot].va = vaddr; + env->vstore[slot].va = v_addr; env->vstore[slot].size = size;memcpy (&env->vstore[slot].data.ub[0 ], &env->tmp_VRegs[0 ], size);
target/hexagon/mmvec/system_ext_mmvec.h +1 -1
@@ -18,7 +18,7 @@#ifndef HEXAGON_SYSTEM_EXT_MMVEC_H #define HEXAGON_SYSTEM_EXT_MMVEC_H -void mem_gather_store (CPUHexagonState *env,target_ulong vaddr,int slot); +void mem_gather_store (CPUHexagonState *env,target_ulong v_addr,int slot);void mem_vector_scatter_init (CPUHexagonState *env);void mem_vector_gather_init (CPUHexagonState *env);
target/hexagon/op_helper.c +2 -2
@@ -577,12 +577,12 @@ void HELPER(probe_pkt_scalar_hvx_stores)(CPUHexagonState *env, int mask)* wasn't cancelled), we have to do the store first. */ static void check_noshuf (CPUHexagonState *env,bool pkt_has_store_s1, -uint32_t slot,target_ulong vaddr,int size, +uint32_t slot,target_ulong v_addr,int size,uintptr_t ra) {if (slot ==0 && pkt_has_store_s1 && ((env->slot_cancelled & (1 <<1 )) ==0 )) { -probe_read (env, vaddr, size,MMU_USER_IDX , ra); +probe_read (env, v_addr, size,MMU_USER_IDX , ra);commit_store (env,1 , ra); } }
Signature · 1 line
2.25.1
RE: [PATCH v2 3/3] target/hexagon: avoid shadowing globals
Quoted 32 lines
-----Original Message-----
From: Brian Cain <[email protected]>
Sent: Thursday, October 5, 2023 4:22 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH v2 3/3] target/hexagon: avoid shadowing globalsThe typedef
vaddris shadowed byvaddridentifiers, so we rename the identifiers to avoid shadowing the type name.The global
cpu_envis shadowed by localcpu_envarguments, so we rename the function arguments to avoid shadowing the global.Signed-off-by Brian Cain <[email protected]>--- target/hexagon/genptr.c | 56 ++++++++++++------------- target/hexagon/genptr.h | 18 ++++---- target/hexagon/mmvec/system_ext_mmvec.c | 4 +- target/hexagon/mmvec/system_ext_mmvec.h | 2 +- target/hexagon/op_helper.c | 4 +- 5 files changed, 42 insertions(+), 42 deletions(-)target/hexagon/genptr.c index renamed from target/hexagon/genptr.c +0
-0
217bc7bb5a..11377ac92b100644
target/hexagon/genptr.c void gen_set_byte_i64(int N, TCGv_i64 result, TCGv · line 339
Quoted 7 lines
target/hexagon/genptr.c +2
-1@@ -334,28 +334,28 @@ void gen_set_byte_i64(int N, TCGv_i64 result, TCGv src) tcg_gen_deposit_i64(result, result, src64, N * 8, 8); } -static inline void gen_load_locked4u (TCGv dest,TCGv vaddr,int mem_index) +static inline void gen_load_locked4u(TCGv dest, TCGv v_addr, int +mem_index)
I'd recommend moving both the type and the arg name to the new line, also indent the new line. static inline void gen_load_locked4u(TCGv dest, TCGv v_addr,
int mem_index)
target/hexagon/genptr.c void gen_set_byte_i64(int N, TCGv_i64 result, TCGv · line 342
Quoted 5 lines
target/hexagon/genptr.c +2
-1-static inline void gen_load_locked8u (TCGv_i64 dest,TCGv vaddr,int mem_index) +static inline void gen_load_locked8u(TCGv_i64 dest, TCGv v_addr, int +mem_index)
Ditto
target/hexagon/genptr.c void gen_set_byte_i64(int N, TCGv_i64 result, TCGv src)
Quoted 4 lines
target/hexagon/genptr.c +2
-1static inline void gen_store_conditional4 (DisasContext *ctx, -TCGv pred,TCGv vaddr,TCGv src) +TCGv pred,TCGv v_addr,TCGv + src)
Ditto
target/hexagon/genptr.c static inline void · line 378
Quoted 8 lines
target/hexagon/genptr.c +2
-1zero =tcg_constant_tl (0 );@@ -374,13 +374,13 @@ static inline void gen_store_conditional4(DisasContext *ctx, }static inline void gen_store_conditional8 (DisasContext *ctx, -TCGv pred,TCGv vaddr,TCGv_i64 src) +TCGv pred,TCGv v_addr, +TCGv_i64 src)
Indent
target/hexagon/genptr.c static inline void · line 381
Quoted 4 lines
target/hexagon/genptr.c +2
-1-void mem_gather_store (CPUHexagonState *env,target_ulong vaddr,int slot) +void mem_gather_store (CPUHexagonState *env,target_ulong v_addr,int +slot)
Ditto
target/hexagon/genptr.c static inline void · line 384
Quoted 4 lines
target/hexagon/genptr.c +2
-1-void mem_gather_store (CPUHexagonState *env,target_ulong vaddr,int slot); +void mem_gather_store (CPUHexagonState *env,target_ulong v_addr,int +slot);
Ditto
Otherwise,
RE: [PATCH v2 3/3] target/hexagon: avoid shadowing globals
Quoted 93 lines
-----Original Message-----
From: [email protected] <[email protected]>
Sent: Friday, October 6, 2023 11:01 AM
To: Brian Cain <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Matheus Bernardino (QUIC) <[email protected]>; [email protected]; [email protected]; [email protected]; Marco Liebel (QUIC) <[email protected]>
Subject: RE: [PATCH v2 3/3] target/hexagon: avoid shadowing globalsWARNING: This email originated from outside of Qualcomm. Please be wary of any links or attachments, and do not enable macros.
target/hexagon/genptr.c void gen_set_byte_i64(int N, TCGv_i64 result,
Quoted 30 lines
-----Original Message-----
From: Brian Cain <[email protected]>
Sent: Thursday, October 5, 2023 4:22 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH v2 3/3] target/hexagon: avoid shadowing globalsThe typedef
vaddris shadowed byvaddridentifiers, so we rename the identifiers to avoid shadowing the type name.The global
cpu_envis shadowed by localcpu_envarguments, so we rename the function arguments to avoid shadowing the global.Signed-off-by Brian Cain <[email protected]>--- target/hexagon/genptr.c | 56 ++++++++++++------------- target/hexagon/genptr.h | 18 ++++---- target/hexagon/mmvec/system_ext_mmvec.c | 4 +- target/hexagon/mmvec/system_ext_mmvec.h | 2 +- target/hexagon/op_helper.c | 4 +- 5 files changed, 42 insertions(+), 42 deletions(-)target/hexagon/genptr.c index renamed from target/hexagon/genptr.c +0
-0
217bc7bb5a..11377ac92b100644target/hexagon/genptr.c +0
-0@@ -334,28 +334,28 @@ void gen_set_byte_i64(int N, TCGv_i64 result,TCGv
target/hexagon/genptr.c void gen_set_byte_i64(int N, TCGv_i64 result, · line 339
Quoted 7 lines
target/hexagon/genptr.c +2
-1src) tcg_gen_deposit_i64(result, result, src64, N * 8, 8); } -static inline void gen_load_locked4u (TCGv dest,TCGv vaddr,int mem_index) +static inline void gen_load_locked4u(TCGv dest, TCGv v_addr, int +mem_index)I'd recommend moving both the type and the arg name to the new line, also indent the new line.
static inline void gen_load_locked4u(TCGv dest, TCGvv_addr,
intmem_index)target/hexagon/genptr.c void gen_set_byte_i64(int N, TCGv_i64 result, · line 342
Quoted 5 lines
target/hexagon/genptr.c +2
-1-static inline void gen_load_locked8u (TCGv_i64 dest,TCGv vaddr,int mem_index) +static inline void gen_load_locked8u(TCGv_i64 dest, TCGv v_addr, int +mem_index)Ditto
target/hexagon/genptr.c void gen_set_byte_i64(int N, TCGv_i64 result, TCGv src)
Quoted 4 lines
target/hexagon/genptr.c +2
-1static inline void gen_store_conditional4 (DisasContext *ctx, -TCGv pred,TCGv vaddr,TCGv src) +TCGv pred,TCGv v_addr,TCGv + src)Ditto
target/hexagon/genptr.c static inline void · line 378
Quoted 8 lines
target/hexagon/genptr.c +2
-1zero =tcg_constant_tl (0 );@@ -374,13 +374,13 @@ static inline void gen_store_conditional4(DisasContext *ctx, }static inline void gen_store_conditional8 (DisasContext *ctx, -TCGv pred,TCGv vaddr,TCGv_i64 src) +TCGv pred,TCGv v_addr, +TCGv_i64 src)Indent
target/hexagon/genptr.c static inline void · line 381
Quoted 4 lines
target/hexagon/genptr.c +2
-1-void mem_gather_store (CPUHexagonState *env,target_ulong vaddr,int slot) +void mem_gather_store (CPUHexagonState *env,target_ulong v_addr,int +slot)Ditto
Quoted 6 lines
target/hexagon/genptr.c static inline void · line 384
Quoted 4 lines
target/hexagon/genptr.c +2
-1-void mem_gather_store (CPUHexagonState *env,target_ulong vaddr,int slot); +void mem_gather_store (CPUHexagonState *env,target_ulong v_addr,int +slot);Ditto
I could be mistaken but AFAICT none of these lines are wrapped in the way they're quoted above in my patch (nor the baseline). I don't think any of these lines exceed 80 columns, so they shouldn't need wrapping, either.
I double checked how it's displayed at the archive https://lists.gnu.org/archive/html/qemu-devel/2023-10/msg01667.html to make sure that it wasn't a misconfiguration of my mailer. For another perspective - refer to the commit used to create this patch: https://github.com/quic/qemu/commit/7f20565d403d16337ab6d69ee663121a3eef71e6
Is your review comment that "these lines should be wrapped and when you do, make sure you do it like this"? Or "if you are going to wrap them, wrap them like this"? Or something else?
Quoted 3 lines
Otherwise,
Reviewed-by Taylor Simpson <[email protected]>
RE: [PATCH v2 3/3] target/hexagon: avoid shadowing globals
Quoted 85 lines
-----Original Message-----
From: Brian Cain <[email protected]>
Sent: Sunday, October 8, 2023 7:50 AM
To: [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Matheus Bernardino (QUIC) <[email protected]>; [email protected]; [email protected]; [email protected]; Marco Liebel (QUIC) <[email protected]>
Subject: RE: [PATCH v2 3/3] target/hexagon: avoid shadowing globalsQuoted 48 lines
-----Original Message-----
From: [email protected] <[email protected]>
Sent: Friday, October 6, 2023 11:01 AM
To: Brian Cain <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Matheus Bernardino (QUIC) <[email protected]>; [email protected]; [email protected]; [email protected]; Marco Liebel (QUIC) <[email protected]>
Subject: RE: [PATCH v2 3/3] target/hexagon: avoid shadowing globalsWARNING: This email originated from outside of Qualcomm. Please be wary of any links or attachments, and do not enable macros.
target/hexagon/genptr.c void gen_set_byte_i64(int N, TCGv_i64 result,
Quoted 31 lines
-----Original Message-----
From: Brian Cain <[email protected]>
Sent: Thursday, October 5, 2023 4:22 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH v2 3/3] target/hexagon: avoid shadowing globalsThe typedef
vaddris shadowed byvaddridentifiers, so we rename the identifiers to avoid shadowing the type name.The global
cpu_envis shadowed by localcpu_envarguments, so we rename the function arguments to avoid shadowing the global.Signed-off-by Brian Cain <[email protected]>--- target/hexagon/genptr.c | 56 ++++++++++++------------- target/hexagon/genptr.h | 18 ++++---- target/hexagon/mmvec/system_ext_mmvec.c | 4 +- target/hexagon/mmvec/system_ext_mmvec.h | 2 +- target/hexagon/op_helper.c | 4 +- 5 files changed, 42 insertions(+), 42 deletions(-)target/hexagon/genptr.c index renamed from target/hexagon/genptr.c +0
-0
217bc7bb5a..11377ac92b100644target/hexagon/genptr.c +0
-0@@ -334,28 +334,28 @@ void gen_set_byte_i64(int N, TCGv_i64 result,TCGv
Quoted 3 lines
target/hexagon/genptr.c +0
-0src) tcg_gen_deposit_i64(result, result, src64, N * 8, 8); }Quoted 12 lines
target/hexagon/genptr.c void gen_set_byte_i64(int N, TCGv_i64 result, · line 339
Quoted 4 lines
target/hexagon/genptr.c +2
-1-static inline void gen_load_locked4u (TCGv dest,TCGv vaddr,int mem_index) +static inline void gen_load_locked4u(TCGv dest, TCGv v_addr, int +mem_index)I'd recommend moving both the type and the arg name to the new line, also indent the new line.
static inline void gen_load_locked4u(TCGv dest, TCGvv_addr,
intmem_index)I could be mistaken but AFAICT none of these lines are wrapped in the way they're quoted above in my patch (nor the baseline). I don't think any of these lines exceed 80 columns, so they shouldn't need wrapping, either.
I double checked how it's displayed at the archive
https://lists.gnu.org/archive/html/qemu-devel/2023-10/msg01667.html to make sure that it wasn't a misconfiguration of my mailer. For another perspective - refer to the commit used to create this patch:
https://github.com/quic/qemu/commit/7f20565d403d16337ab6d69ee663121a3eef71e6
Quoted 3 lines
Is your review comment that "these lines should be wrapped and when you do, make sure you do it like this"? Or "if you are going to wrap them, wrap them like this"? Or something else?
Yes. It looked like some adding the v_ would sometimes put the line over the 80 character size. If so, wrap them as described. If not, no wrapping is needed.
Quoted 4 lines
Quoted 4 lines
Otherwise,
Reviewed-by Taylor Simpson <[email protected]>
Re: [PATCH v2 3/3] target/hexagon: avoid shadowing globals
In reply to Brian CainHi Brian,
Quoted 2 lines · Brian Cain
The typedef
vaddris shadowed byvaddridentifiers, so we rename the identifiers to avoid shadowing the type name.
This one surprises me, since we have other occurences:
include/exec/memory.h:751:bool memory_get_xlat_addr(IOMMUTLBEntry *iotlb, void **vaddr,
include/qemu/plugin.h:199:void qemu_plugin_vcpu_mem_cb(CPUState *cpu,uint64_t vaddr,
target/arm/internals.h:643:G_NORETURN void arm_cpu_do_unaligned_access(CPUState *cs, vaddr vaddr, target/i386/tcg/helper-tcg.h:70:G_NORETURN void handle_unaligned_access(CPUX86State *env, vaddr vaddr,
...
$ git grep -w vaddr, | wc -l
207What is the error/warning like?
Quoted 29 lines
The global
cpu_envis shadowed by localcpu_envarguments, so we rename the function arguments to avoid shadowing the global.Signed-off-by Brian Cain <[email protected]>--- target/hexagon/genptr.c | 56 ++++++++++++------------- target/hexagon/genptr.h | 18 ++++---- target/hexagon/mmvec/system_ext_mmvec.c | 4 +- target/hexagon/mmvec/system_ext_mmvec.h | 2 +- target/hexagon/op_helper.c | 4 +- 5 files changed, 42 insertions(+), 42 deletions(-)target/hexagon/genptr.c +3
-3@@ -334,28 +334,28 @@ void gen_set_byte_i64(int N, TCGv_i64 result, TCGv src)tcg_gen_deposit_i64 (result, result, src64,N *8 ,8 ); } -static inline void gen_load_locked4u (TCGv dest,TCGv vaddr,int mem_index) +static inline void gen_load_locked4u (TCGv dest,TCGv v_addr,int mem_index) { -tcg_gen_qemu_ld_tl (dest, vaddr, mem_index,MO_TEUL ); -tcg_gen_mov_tl (hex_llsc_addr, vaddr); +tcg_gen_qemu_ld_tl (dest, v_addr, mem_index,MO_TEUL ); +tcg_gen_mov_tl (hex_llsc_addr, v_addr);tcg_gen_mov_tl (hex_llsc_val, dest); }
Re: [PATCH v2 3/3] target/hexagon: avoid shadowing globals
Quoted 15 lines · Philippe Mathieu-Daudé
Hi Brian,
Quoted 2 lines · Brian Cain
The typedef
vaddris shadowed byvaddridentifiers, so we rename the identifiers to avoid shadowing the type name.This one surprises me, since we have other occurences:
include/exec/memory.h:751:bool memory_get_xlat_addr(IOMMUTLBEntry *iotlb, void **vaddr,
include/qemu/plugin.h:199:void qemu_plugin_vcpu_mem_cb(CPUState
*cpu,uint64_tvaddr,
target/arm/internals.h:643:G_NORETURN void arm_cpu_do_unaligned_access(CPUState *cs, vaddr vaddr, target/i386/tcg/helper-tcg.h:70:G_NORETURN void handle_unaligned_access(CPUX86State *env, vaddr vaddr,
...
Quoted 4 lines
$ git grep -w vaddr, | wc -l 207What is the error/warning like?
OK I could reproduce, I suppose you are building with Clang which doesn't support shadow-local so you get global warnings too (as mentioned in this patch subject...):
In file included from ../../gdbstub/trace.h:1,
from ../../gdbstub/softmmu.c:30:
trace/trace-gdbstub.h: In function '_nocheck__trace_gdbstub_hit_watchpoint':trace/trace-gdbstub.h:903:106: error: declaration of 'vaddr' shadows a global declaration [-Werror=shadow]
903 | static inline void _nocheck__trace_gdbstub_hit_watchpoint(const
char * type, int cpu_gdb_index, uint64_t vaddr)
|
~~~~~~~~~^~~~~
In file included from include/sysemu/accel-ops.h:13,
from include/sysemu/cpus.h:4,
from ../../gdbstub/softmmu.c:21:include/exec/cpu-common.h:21:18: note: shadowed declaration is here
21 | typedef uint64_t vaddr;
| ^~~~~trace/trace-gdbstub.h: In function 'trace_gdbstub_hit_watchpoint':trace/trace-gdbstub.h:923:96: error: declaration of 'vaddr' shadows a global declaration [-Werror=shadow]
923 | static inline void trace_gdbstub_hit_watchpoint(const char *
type, int cpu_gdb_index, uint64_t vaddr)
|
~~~~~~~~~^~~~~include/exec/cpu-common.h:21:18: note: shadowed declaration is here
21 | typedef uint64_t vaddr;
| ^~~~~
Clang users got confused by this, IIUC Markus and Thomas idea is to only enable these warnings for GCC, enforcing them for Clang users via CI (until Clang get this option supported). Personally I'd rather enable the warning once for all, waiting for Clang support (or clean/enable global shadowing for GCC too).
See this thread:
https://lore.kernel.org/qemu-devel/[email protected]/
Regards,
Phil.
RE: [PATCH v2 3/3] target/hexagon: avoid shadowing globals
Quoted 36 lines
-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: Monday, October 9, 2023 1:43 AM
To: Brian Cain <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; Matheus Bernardino (QUIC) <[email protected]>; [email protected]; [email protected]; [email protected]; Marco Liebel (QUIC) <[email protected]>; [email protected]; Thomas Huth <[email protected]>; Daniel P. Berrangé <[email protected]>
Subject: Re: [PATCH v2 3/3] target/hexagon: avoid shadowing globalsWARNING: This email originated from outside of Qualcomm. Please be wary of any links or attachments, and do not enable macros.
Quoted 18 lines · Philippe Mathieu-Daudé
Hi Brian,
Quoted 2 lines · Brian Cain
The typedef
vaddris shadowed byvaddridentifiers, so we rename the identifiers to avoid shadowing the type name.This one surprises me, since we have other occurences:
include/exec/memory.h:751:bool memory_get_xlat_addr(IOMMUTLBEntry *iotlb, void **vaddr,
include/qemu/plugin.h:199:void qemu_plugin_vcpu_mem_cb(CPUState
*cpu,uint64_tvaddr, target/arm/internals.h:643:G_NORETURN void arm_cpu_do_unaligned_access(CPUState *cs, vaddr vaddr, target/i386/tcg/helper-tcg.h:70:G_NORETURN void handle_unaligned_access(CPUX86State *env, vaddr vaddr,
...
Quoted 8 lines
Quoted 4 lines
$ git grep -w vaddr, | wc -l 207What is the error/warning like?
OK I could reproduce, I suppose you are building with Clang which doesn't support shadow-local so you get global warnings too (as mentioned in this patch subject...):
No -- I generally build with gcc and only double-check the clang results to make sure I don't see any new failures there.
But I've not tested "-Wshadow" with clang yet. I found these by adding "-Wshadow=global" to "-Wshadow=local". I thought it might be useful to address these too while we're here.
Quoted 26 lines
In file included from
../../gdbstub/trace.h:1,from ../../gdbstub/softmmu.c:30:
trace/trace-gdbstub.h: In function '_nocheck__trace_gdbstub_hit_watchpoint':trace/trace-gdbstub.h:903:106: error: declaration of 'vaddr' shadows a global declaration [-Werror=shadow]
903 | static inline void _nocheck__trace_gdbstub_hit_watchpoint(const
char * type, intcpu_gdb_index,uint64_tvaddr)| ~~~~~~~~~^~~~~ In file included from include/sysemu/accel-ops.h:13, from include/sysemu/cpus.h:4, from ../../gdbstub/softmmu.c:21: include/exec/cpu-common.h:21:18: note: shadowed declaration is here 21 | typedef uint64_t vaddr; | ^~~~~
trace/trace-gdbstub.h: In function 'trace_gdbstub_hit_watchpoint':trace/trace-gdbstub.h:923:96: error: declaration of 'vaddr' shadows a global declaration [-Werror=shadow]
923 | static inline void trace_gdbstub_hit_watchpoint(const char *
type, intcpu_gdb_index,uint64_tvaddr)| ~~~~~~~~~^~~~~ include/exec/cpu-common.h:21:18: note: shadowed declaration is here 21 | typedef uint64_t vaddr; | ^~~~~
Quoted 5 lines
Clang users got confused by this, IIUC Markus and Thomas idea is to only enable these warnings for GCC, enforcing them for Clang users via CI (until Clang get this option supported). Personally I'd rather enable the warning once for all, waiting for Clang support (or clean/enable global shadowing for GCC too).
Hopefully it's helpful or at least benign if we address the shadowed globals under target/hexagon/ for now, even if "-Wshadow=global" is not enabled.
Quoted 7 lines
See this thread:
https://lore.kernel.org/qemu-devel/11abc551-188e-85c0-fe55-
[email protected]/Regards,
Phil.
Re: [PATCH v2 3/3] target/hexagon: avoid shadowing globals
Quoted 22 lines · Brian Cain
Quoted 22 lines · Philippe Mathieu-Daudé
Quoted 20 lines · Brian Cain
Quoted 2 lines
The typedef
vaddris shadowed byvaddridentifiers, so we rename the identifiers to avoid shadowing the type name.This one surprises me, since we have other occurences:
include/exec/memory.h:751:bool memory_get_xlat_addr(IOMMUTLBEntry *iotlb, void **vaddr,
include/qemu/plugin.h:199:void qemu_plugin_vcpu_mem_cb(CPUState
*cpu,uint64_tvaddr, target/arm/internals.h:643:G_NORETURN void arm_cpu_do_unaligned_access(CPUState *cs, vaddr vaddr, target/i386/tcg/helper-tcg.h:70:G_NORETURN void handle_unaligned_access(CPUX86State *env, vaddr vaddr,
...$ git grep -w vaddr, | wc -l 207What is the error/warning like?
Quoted 33 lines
Quoted 3 lines
OK I could reproduce, I suppose you are building with Clang which doesn't support shadow-local so you get global warnings too (as mentioned in this patch subject...):
No -- I generally build with gcc and only double-check the clang results to make sure I don't see any new failures there.
But I've not tested "-Wshadow" with clang yet. I found these by adding "-Wshadow=global" to "-Wshadow=local". I thought it might be useful to address these too while we're here.
Quoted 25 lines
In file included from
../../gdbstub/trace.h:1,from ../../gdbstub/softmmu.c:30:
trace/trace-gdbstub.h: In function '_nocheck__trace_gdbstub_hit_watchpoint':trace/trace-gdbstub.h:903:106: error: declaration of 'vaddr' shadows a global declaration [-Werror=shadow]
903 | static inline void _nocheck__trace_gdbstub_hit_watchpoint(const
char * type, intcpu_gdb_index,uint64_tvaddr)| ~~~~~~~~~^~~~~ In file included from include/sysemu/accel-ops.h:13, from include/sysemu/cpus.h:4, from ../../gdbstub/softmmu.c:21: include/exec/cpu-common.h:21:18: note: shadowed declaration is here 21 | typedef uint64_t vaddr; | ^~~~~
trace/trace-gdbstub.h: In function 'trace_gdbstub_hit_watchpoint':trace/trace-gdbstub.h:923:96: error: declaration of 'vaddr' shadows a global declaration [-Werror=shadow]
923 | static inline void trace_gdbstub_hit_watchpoint(const char *
type, intcpu_gdb_index,uint64_tvaddr)| ~~~~~~~~~^~~~~ include/exec/cpu-common.h:21:18: note: shadowed declaration is here 21 | typedef uint64_t vaddr; | ^~~~~
If we have to clean that for -Wshadow=global, I'm tempted to rename the typedef as 'vaddr_t' and keep the 'vaddr' variable names.
Richard, Anton, what do you think?
Quoted 15 lines
Quoted 5 lines
Clang users got confused by this, IIUC Markus and Thomas idea is to only enable these warnings for GCC, enforcing them for Clang users via CI (until Clang get this option supported). Personally I'd rather enable the warning once for all, waiting for Clang support (or clean/enable global shadowing for GCC too).
Hopefully it's helpful or at least benign if we address the shadowed globals under target/hexagon/ for now, even if "-Wshadow=global" is not enabled.
Quoted 7 lines
See this thread:
https://lore.kernel.org/qemu-devel/11abc551-188e-85c0-fe55-
[email protected]/Regards,
Phil.
Re: [PATCH v2 3/3] target/hexagon: avoid shadowing globals
Philippe Mathieu-Daudé <[email protected]> writes:
[...]
Quoted 2 lines
If we have to clean that for -Wshadow=global, I'm tempted to rename the typedef as '
vaddr_t' and keep the 'vaddr' variable names.
POSIX reserves suffix _t, see
https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_02_02
Do we care?
Quoted 1 line
Richard, Anton, what do you think?
[...]
Re: [PATCH v2 3/3] target/hexagon: avoid shadowing globals
Quoted 9 lines · Markus Armbruster
Philippe Mathieu-Daudé <[email protected]> writes:
[...]
Quoted 2 lines
If we have to clean that for -Wshadow=global, I'm tempted to rename the typedef as '
vaddr_t' and keep the 'vaddr' variable names.POSIX reserves suffix _t, see
https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_02_02
Alternatives: tvaddr, VAddr, TargetVirtualAddress.
Naming is hard.
Quoted 6 lines
Do we care?
Quoted 1 line
Richard, Anton, what do you think?
[...]
Re: [PATCH v2 3/3] target/hexagon: avoid shadowing globals
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Markus Armbruster
Philippe Mathieu-Daudé <[email protected]> writes:
[...]
Quoted 2 lines
If we have to clean that for -Wshadow=global, I'm tempted to rename the typedef as '
vaddr_t' and keep the 'vaddr' variable names.
Quoted 8 lines
Quoted 2 lines
POSIX reserves suffix _t, see
https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_02_02Alternatives: tvaddr, VAddr, TargetVirtualAddress.
Naming is hard.
Quoted 1 line
Do we care?
According to our docs/devel/style.rst :
"Scalar type
names are lower_case_with_underscores_ending_with_a_t, like the POSIX uint64_t and family. Note that this last convention contradicts POSIX and is therefore likely to be changed."
Maybe this would be a good point in time now to revisit our coding style, update it and then to change the "vaddr" type accordingly?
My 0.02 €: If enum types should already be in CamelCase, why not also use that for scalar types? So I'd vote for VirtAddr or VAddr here.
Thomas
RE: [PATCH v2 3/3] target/hexagon: avoid shadowing globals
In reply to Philippe Mathieu-DaudéQuoted 78 lines
-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: Tuesday, October 10, 2023 12:23 AM
To: Brian Cain <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]; Matheus Bernardino (QUIC) <[email protected]>; [email protected]; [email protected]; Marco Liebel (QUIC) <[email protected]>; [email protected]; Thomas Huth <[email protected]>; Daniel P. Berrangé <[email protected]>; [email protected]
Subject: Re: [PATCH v2 3/3] target/hexagon: avoid shadowing globalsWARNING: This email originated from outside of Qualcomm. Please be wary of any links or attachments, and do not enable macros.
Quoted 20 lines · Brian Cain
Quoted 20 lines · Philippe Mathieu-Daudé
Quoted 19 lines · Brian Cain
Quoted 2 lines
The typedef
vaddris shadowed byvaddridentifiers, so we rename the identifiers to avoid shadowing the type name.This one surprises me, since we have other occurences:
include/exec/memory.h:751:bool memory_get_xlat_addr(IOMMUTLBEntry *iotlb, void **vaddr,
include/qemu/plugin.h:199:void qemu_plugin_vcpu_mem_cb(CPUState
*cpu,uint64_tvaddr, target/arm/internals.h:643:G_NORETURN void arm_cpu_do_unaligned_access(CPUState *cs, vaddr vaddr, target/i386/tcg/helper-tcg.h:70:G_NORETURN void handle_unaligned_access(CPUX86State *env, vaddr vaddr,
...$ git grep -w vaddr, | wc -l 207Quoted 7 lines
Quoted 5 lines
Quoted 1 line
What is the error/warning like?
OK I could reproduce, I suppose you are building with Clang which doesn't support shadow-local so you get global warnings too (as mentioned in this patch subject...):
No -- I generally build with gcc and only double-check the clang results to
make sure I don't see any new failures there.
Quoted 2 lines
But I've not tested "-Wshadow" with clang yet. I found these by adding "-
Wshadow=global" to "-Wshadow=local". I thought it might be useful to address these too while we're here.
Quoted 4 lines
Quoted 4 lines
In file included from
../../gdbstub/trace.h:1,from ../../gdbstub/softmmu.c:30:
trace/trace-gdbstub.h: In function'
_nocheck__trace_gdbstub_hit_watchpoint':Quoted 14 lines
Quoted 14 lines
trace/trace-gdbstub.h:903:106: error: declaration of 'vaddr' shadows a global declaration [-Werror=shadow]
903 | static inline void _nocheck__trace_gdbstub_hit_watchpoint(const
char * type, intcpu_gdb_index,uint64_tvaddr)| ~~~~~~~~~^~~~~ In file included from include/sysemu/accel-ops.h:13, from include/sysemu/cpus.h:4, from ../../gdbstub/softmmu.c:21: include/exec/cpu-common.h:21:18: note: shadowed declaration is here 21 | typedef uint64_t vaddr; | ^~~~~
trace/trace-gdbstub.h: In function 'trace_gdbstub_hit_watchpoint':trace/trace-gdbstub.h:923:96: error: declaration of 'vaddr' shadows aQuoted 8 lines
Quoted 8 lines
global declaration [-Werror=shadow]
923 | static inline void trace_gdbstub_hit_watchpoint(const char *
type, intcpu_gdb_index,uint64_tvaddr)| ~~~~~~~~~^~~~~ include/exec/cpu-common.h:21:18: note: shadowed declaration is here 21 | typedef uint64_t vaddr; | ^~~~~
Quoted 4 lines
If we have to clean that for -Wshadow=global, I'm tempted to rename the typedef as '
vaddr_t' and keep the 'vaddr' variable names.Richard, Anton, what do you think?
Feels like I may have strolled into uncharted territory. I'll just drop the patch that is intended to address -Wshadow=global and resurrect it if/when we decide to take that on in general.
Quoted 16 lines
Quoted 7 lines
Quoted 5 lines
Clang users got confused by this, IIUC Markus and Thomas idea is to only enable these warnings for GCC, enforcing them for Clang users via CI (until Clang get this option supported). Personally I'd rather enable the warning once for all, waiting for Clang support (or clean/enable global shadowing for GCC too).
Hopefully it's helpful or at least benign if we address the shadowed globals
under target/hexagon/ for now, even if "-Wshadow=global" is not enabled.
Quoted 8 lines
Quoted 8 lines
See this thread:
https://lore.kernel.org/qemu-devel/11abc551-188e-85c0-fe55-
[email protected]/Regards,
Phil.
Re: [PATCH v2 3/3] target/hexagon: avoid shadowing globals
In reply to Philippe Mathieu-DaudéQuoted 39 lines · Philippe Mathieu-Daudé
Quoted 10 lines · Philippe Mathieu-Daudé
Hi Brian,
Quoted 2 lines · Brian Cain
The typedef
vaddris shadowed byvaddridentifiers, so we rename the identifiers to avoid shadowing the type name.This one surprises me, since we have other occurences:
include/exec/memory.h:751:bool memory_get_xlat_addr(IOMMUTLBEntry *iotlb, void **vaddr,
include/qemu/plugin.h:199:void qemu_plugin_vcpu_mem_cb(CPUState *cpu,uint64_tvaddr,
target/arm/internals.h:643:G_NORETURN void arm_cpu_do_unaligned_access(CPUState *cs, vaddr vaddr, target/i386/tcg/helper-tcg.h:70:G_NORETURN void handle_unaligned_access(CPUX86State *env, vaddr vaddr,
...Quoted 3 lines
$ git grep -w vaddr, | wc -l 207 What is the error/warning like?OK I could reproduce, I suppose you are building with Clang which doesn't support shadow-local so you get global warnings too (as mentioned in this patch subject...):
In file included from
../../gdbstub/trace.h:1,from ../../gdbstub/softmmu.c:30: trace/trace-gdbstub.h: In function '_nocheck__trace_gdbstub_hit_watchpoint': trace/trace-gdbstub.h:903:106: error: declaration of 'vaddr' shadows a global declaration [-Werror=shadow] 903 | static inline void _nocheck__trace_gdbstub_hit_watchpoint(const char * type, int cpu_gdb_index, uint64_t vaddr) | ~~~~~~~~~^~~~~ In file included from include/sysemu/accel-ops.h:13, from include/sysemu/cpus.h:4, from ../../gdbstub/softmmu.c:21:
include/exec/cpu-common.h:21:18: note: shadowed declaration is here
21 | typedefuint64_tvaddr;
| ^~~~~trace/trace-gdbstub.h: In function 'trace_gdbstub_hit_watchpoint':trace/trace-gdbstub.h:923:96: error: declaration of 'vaddr' shadows a global declaration [-Werror=shadow]
923 | static inline voidtrace_gdbstub_hit_watchpoint(const char * type, int cpu_gdb_index, uint64_t vaddr)| ~~~~~~~~~^~~~~
include/exec/cpu-common.h:21:18: note: shadowed declaration is here
21 | typedefuint64_tvaddr;
| ^~~~~
Quoted 8 lines
Clang users got confused by this, IIUC Markus and Thomas idea is to only enable these warnings for GCC, enforcing them for Clang users via CI (until Clang get this option supported). Personally I'd rather enable the warning once for all, waiting for Clang support (or clean/enable global shadowing for GCC too).
See this thread:
https://lore.kernel.org/qemu-devel/[email protected]/
The idea to enable some variation of -Wshadow goes back to this thread:
Subject: Re: [RFC PATCH] docs/style: permit inline loop variables
Date: Thu, 24 Aug 2023 14:18:53 +0100
Message-ID: <CAFEAcA8wobO5F16vYhbQCjeadfN5Zwx5CQ7L4vQ3fh8c_6ngJg@mail.gmail.com>
https://lore.kernel.org/qemu-devel/CAFEAcA8wobO5F16vYhbQCjeadfN5Zwx5CQ7L4vQ3fh8c_6ngJg@mail.gmail.com/
I've been aiming at -Wshadow=local because (1) it seemed more practical (a lot less cleanup needed before we can enable the warning), and (2) local shadowing is basically always foolish and fully our own fault.
No objection to additional -Wshadow work as long as I'm not the one doing it :)
Conflicts with recent commit ad75a51e84a (tcg: Rename cpu_env to tcg_env). Please rebase.