From aaceff81f064107537c7706dc19ca6ff80ca12c8 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Mon, 2 Feb 2026 14:52:45 +0100 Subject: [PATCH] configure: silent MacOS clang warning gnu-folding-constant On the specific fork of clang for MacOS, the compiler gets more strict on the use of GNU folding constants, generating warnings that halts the build of OpenOCD. The GNU folding constants are highlighted by upstream clang only for global variables. E.g.: const int len = 10; int array[len]; generates the warning on: clang -c x.c x.c:2:5: warning: variable length array folded to constant array as an extension [-Wgnu-folding-constant] int array[len]; ^ Apparently only the MacOS fork generates warning for folded constants inside a function. E.g.: int a(int *x); int b(void) { const int len = 10; int array[len]; return a*array); } does not return error even forcing -Wgnu-folding-constant on clang upstream. Current code triggers warning on the following lines due to the size of the array being computed from a const variable: jtag/drivers/xds110.c:354 unsigned char data[max_data + 1]; flash/nor/dw-spi.c:950 uint8_t buffer[buffer_size]; flash/nor/dw-spi.c:980 uint8_t buffer[buffer_size]; flash/nor/dw-spi.c:1034 uint8_t buffer[buffer_size]; flash/nor/dw-spi.c:1065 uint8_t buffer[buffer_size]; flash/nor/jtagspi.c:364 uint8_t ..., write_buffer[max], ...; flash/nor/stmqspi.c:778 char ..., output[(2 + max + 256) * 3 + 8]; flash/nor/xcf.c:392 uint8_t reference[L]; target/target.c:3303 char output[line_bytecnt * 4 + 1]; target/semihosting_common.c:1787 char buf[buf_len]; target/smp.c:59 char hex_buffer[len * 2 + 1]; target/smp.c:60 uint8_t buffer[len]; target/cortex_m.c:296 uint32_t r_vals[n_r32]; target/cortex_m.c:297 uint32_t dhcsr[n_r32]; target/x86_32_common.c:1337 char output[line_bytecnt * 4 + 1]; target/riscv/riscv.c:2377 uint8_t buffer[length]; target/xtensa/xtensa.c:536 uint8_t ops_padded[max_oplen]; While some of the const variable above could be replaced by macros, for the majority of them I don't see such need, and the use of const looks to me correct. Silent the warning adding the clang flag -Wno-gnu-folding-constant. The flag is not recognized by GCC, but it's silently ignored. Change-Id: I1d452af115355bc4949b1616648fe6544cc48318 Reported-by: Frank Zeyda Signed-off-by: Antonio Borneo Reviewed-on: https://review.openocd.org/c/openocd/+/9431 Tested-by: jenkins Reviewed-by: Marc Schink --- configure.ac | 1 + 1 file changed, 1 insertion(+) diff --git a/configure.ac b/configure.ac index c452cf5d3..5bb76fe00 100644 --- a/configure.ac +++ b/configure.ac @@ -763,6 +763,7 @@ AC_DEFINE([_GNU_SOURCE],[1],[Use GNU C library extensions (e.g. stdndup).]) GCC_WARNINGS="-Wall -Wstrict-prototypes -Wformat-security -Wshadow" AS_IF([test "x${gcc_wextra}" = "xyes"], [ GCC_WARNINGS="${GCC_WARNINGS} -Wextra -Wno-unused-parameter" + GCC_WARNINGS="${GCC_WARNINGS} -Wno-gnu-folding-constant" GCC_WARNINGS="${GCC_WARNINGS} -Wbad-function-cast" GCC_WARNINGS="${GCC_WARNINGS} -Wcast-align" GCC_WARNINGS="${GCC_WARNINGS} -Wredundant-decls"