From 3ea1bfce4faf656d0506c194084807f1e498abff Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Wed, 16 Nov 2022 23:06:12 +0100 Subject: [PATCH] jtag: xds110: fix clang error core.StackAddressEscape Clang ignores that xds110_swd_write_reg() is always called with bit SWD_CMD_RNW in 'cmd' set to zero. It then complains that the local variable 'value' gets passed by address to xds110_swd_queue_cmd() and in case of 'read request' such stack address get stored for later use: src/jtag/drivers/xds110.c:1363:1: warning: Address of stack memory associated with local variable 'value' is still referred to by the global variable 'xds110' upon returning to the caller. This will be a dangling reference [core.StackAddressEscape] To both xds110_swd_write_reg() and xds110_swd_read_reg(), add an assert() to inform Clang about the state of bit SWD_CMD_RNW. Change-Id: I7687c055ec71424b642e152f478723a930966e3a Signed-off-by: Antonio Borneo Reviewed-on: https://review.openocd.org/c/openocd/+/7380 Tested-by: jenkins --- src/jtag/drivers/xds110.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/jtag/drivers/xds110.c b/src/jtag/drivers/xds110.c index ecba36bb9..8e5d638db 100644 --- a/src/jtag/drivers/xds110.c +++ b/src/jtag/drivers/xds110.c @@ -1354,11 +1354,13 @@ static void xds110_swd_queue_cmd(uint8_t cmd, uint32_t *value) static void xds110_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk) { + assert(cmd & SWD_CMD_RNW); xds110_swd_queue_cmd(cmd, value); } static void xds110_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk) { + assert(!(cmd & SWD_CMD_RNW)); xds110_swd_queue_cmd(cmd, &value); }