From 4cd76e510132581a01fa42ca799d0e5789390373 Mon Sep 17 00:00:00 2001 From: Vadim Fedorenko Date: Tue, 17 Feb 2026 16:09:42 -0800 Subject: [PATCH] cmake: add -fzero-init-padding-bits=unions to fix tests Starting from GCC 15.1 union initializers is not guaranteed to zero-initialize all field, but only specified. It means that UBLOXCFG_KEYVAL_ANY(CFG_UBLOXCFGTEST_U1, 42) will initialize 5 bytes only and keep stack garbage in the rest 11 bytes of the UBLOXCFG_KEYVAL_t union. It broke just 1 test, but apparently any initializer in the code can now have garbage. Confirmation can be found in the Caveats section of the link provided. Fix it by reverting GCC to old behavior. Link: https://gcc.gnu.org/gcc-15/changes.html Signed-off-by: Vadim Fedorenko --- ff/CMakeLists.txt | 5 +++++ ubloxcfg/CMakeLists.txt | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/ff/CMakeLists.txt b/ff/CMakeLists.txt index f4a1194..857a8fd 100644 --- a/ff/CMakeLists.txt +++ b/ff/CMakeLists.txt @@ -35,6 +35,11 @@ set(CMAKE_C_EXTENSIONS ON) set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror \ -Wshadow -Wunused-parameter -Wformat -Wpointer-arith -Wundef") +include(CheckCCompilerFlag) +check_c_compiler_flag(-fzero-init-padding-bits HAS_ZERO_INIT_PADDING_BITS) +if (HAS_ZERO_INIT_PADDING_BITS) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fzero-init-padding-bits=unions") +endif() set(CMAKE_C_FLAGS_RELEASE "-O3") set(CMAKE_EXPORT_COMPILE_COMMANDS ON) if(NOT CMAKE_BUILD_TYPE) diff --git a/ubloxcfg/CMakeLists.txt b/ubloxcfg/CMakeLists.txt index 74b5c83..4ac77d7 100644 --- a/ubloxcfg/CMakeLists.txt +++ b/ubloxcfg/CMakeLists.txt @@ -35,6 +35,11 @@ set(CMAKE_C_EXTENSIONS OFF) set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wpedantic -Werror \ -Wshadow -Wunused-parameter -Wformat -Wpointer-arith -Wundef") +include(CheckCCompilerFlag) +check_c_compiler_flag(-fzero-init-padding-bits HAS_ZERO_INIT_PADDING_BITS) +if (HAS_ZERO_INIT_PADDING_BITS) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fzero-init-padding-bits=unions") +endif() set(CMAKE_C_FLAGS_RELEASE "-O3") set(CMAKE_EXPORT_COMPILE_COMMANDS ON) if(NOT CMAKE_BUILD_TYPE)