Skip to content

Commit

Permalink
target/register: use an array of uint8_t for register's value
Browse files Browse the repository at this point in the history
The use of 'void *' makes the pointer arithmetic incompatible with
standard C, even if this is allowed by GCC extensions.
The use of 'void *' can also hide incorrect pointer assignments.

Switch to 'uint8_t *' and add GCC warning flag to track any use of
pointer arithmetic extension.

Change-Id: Ic4d15a232834cd6b374330f70e2473a359b1607f
Signed-off-by: Antonio Borneo <[email protected]>
Reviewed-on: http://openocd.zylin.com/5937
Tested-by: jenkins
Reviewed-by: Andreas Fritiofson <[email protected]>
  • Loading branch information
borneoa authored and erhankur committed Nov 30, 2021
1 parent 1776ef9 commit e6a5e5d
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,7 @@ AS_IF([test "x${gcc_wextra}" = "xyes"], [
GCC_WARNINGS="${GCC_WARNINGS} -Wbad-function-cast"
GCC_WARNINGS="${GCC_WARNINGS} -Wcast-align"
GCC_WARNINGS="${GCC_WARNINGS} -Wredundant-decls"
GCC_WARNINGS="${GCC_WARNINGS} -Wpointer-arith"
])
AS_IF([test "x${gcc_werror}" = "xyes"], [
GCC_WARNINGS="${GCC_WARNINGS} -Werror"
Expand Down
2 changes: 1 addition & 1 deletion src/target/arc.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ static int arc_init_reg(struct target *target, struct reg *reg,
/* Initialize struct reg */
reg->name = reg_desc->name;
reg->size = 32; /* All register in ARC are 32-bit */
reg->value = &reg_desc->reg_value;
reg->value = reg_desc->reg_value;
reg->type = &arc_reg_type;
reg->arch_info = reg_desc;
reg->caller_save = true; /* @todo should be configurable. */
Expand Down
2 changes: 1 addition & 1 deletion src/target/arm7_9_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1393,7 +1393,7 @@ static int arm7_9_full_context(struct target *target)
struct arm *arm = &arm7_9->arm;
struct {
uint32_t value;
void *reg_p;
uint8_t *reg_p;
} read_cache[6 * (16 + 1)];
int read_cache_idx = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/target/etm.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ static void etm_reg_add(unsigned bcd_vers, struct arm_jtag *jtag_info,

reg->name = r->name;
reg->size = r->size;
reg->value = &ereg->value;
reg->value = ereg->value;
reg->arch_info = ereg;
reg->type = &etm_scan6_type;
reg++;
Expand Down
2 changes: 1 addition & 1 deletion src/target/register.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ struct reg {
bool caller_save;
/* Pointer to place where the value is stored, in the format understood by
* the binarybuffer.h functions. */
void *value;
uint8_t *value;
/* The stored value needs to be written to the target. */
bool dirty;
/* When true, value is valid. */
Expand Down
2 changes: 1 addition & 1 deletion src/target/riscv/riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -4556,7 +4556,7 @@ int riscv_init_registers(struct target *target)
reg_name += strlen(reg_name) + 1;
assert(reg_name < info->reg_names + target->reg_cache->num_regs *
max_reg_name_len);
r->value = &info->reg_cache_values[number];
r->value = info->reg_cache_values[number];
}

return ERROR_OK;
Expand Down
4 changes: 2 additions & 2 deletions src/target/riscv/riscv.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ typedef struct {

/* OpenOCD's register cache points into here. This is not per-hart because
* we just invalidate the entire cache when we change which hart is
* selected. */
uint64_t reg_cache_values[RISCV_MAX_REGISTERS];
* selected. Use an array of 8 uint8_t per register. */
uint8_t reg_cache_values[RISCV_MAX_REGISTERS][8];

/* Single buffer that contains all register names, instead of calling
* malloc for each register. Needs to be freed when reg_list is freed. */
Expand Down

0 comments on commit e6a5e5d

Please sign in to comment.