From 9aa3bf46812108ed07e4584e70b4d2b44310bfc5 Mon Sep 17 00:00:00 2001 From: Dave Date: Fri, 2 Sep 2022 00:00:55 -0500 Subject: [PATCH] Fix compiler warning for GCC >= 11.3 - GCC version 12 generates a warnings for certain pointer references. Apparently this is to decect invalid offsets. To properly compiler, the recommended remedy is to add the compiler option "--param=min-pagesize=0" to the flags. This option was introduced in version 11.3, so we need to check the compiler version and only add for >11.3. - Moved setting of compiler flags to a new function c_toolchain_flags in the toolchain file "generic-gcc-avr.cmake". This function is now called from the CMakeLists.txt file in the src directory. This allows the test for the compiler version to be specified in the toolchain file, but not executed until called by the src subdir CMakeLists.txt. Delaying evaluation of the function ensures that the CMAKE_C_VERSION variable is properly set when the function is called. - Moving the compiler flags out of the source dir CMakeLists.txt file also improves portability by moving architecture-specific compiler details from the source tree to the toolchain file. --- firmware/asdf/cmake/generic-gcc-avr.cmake | 39 +++++++++++++++++++++++ firmware/asdf/src/CMakeLists.txt | 27 +--------------- 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/firmware/asdf/cmake/generic-gcc-avr.cmake b/firmware/asdf/cmake/generic-gcc-avr.cmake index 03a3e1b..c27c638 100644 --- a/firmware/asdf/cmake/generic-gcc-avr.cmake +++ b/firmware/asdf/cmake/generic-gcc-avr.cmake @@ -151,6 +151,45 @@ else(WITH_MCU) set(MCU_TYPE_FOR_FILENAME "") endif(WITH_MCU) +function(c_toolchain_flags) + # fix array base indexing beginning in AVR-GCC 12: + + list(APPEND TOOLCHAIN_FLAGS + -std=c99 + # -Wa,-adhln + -Wall + -funsigned-char + -funsigned-bitfields + -ffunction-sections + -fdata-sections + -fpack-struct + -fshort-enums + -O2 + -Wall + -Wextra + -Wpointer-arith + -Wcast-align + -Wwrite-strings + -Wswitch-default + -Wunreachable-code + -Winit-self + -Wmissing-field-initializers + -Wno-unknown-pragmas + -Wstrict-prototypes + -Wundef + -Wold-style-definition + ) + + if(CMAKE_C_COMPILER_VERSION GREATER_EQUAL "11.3") + message(STATUS "Appending page size fix for GCC >= 11.3") + list(APPEND TOOLCHAIN_FLAGS --param=min-pagesize=0) + endif() + + set(CFLAGS ${TOOLCHAIN_FLAGS} PARENT_SCOPE) +endfunction(c_toolchain_flags) + + + ########################################################################## # add_avr_executable # - IN_VAR: EXECUTABLE_NAME diff --git a/firmware/asdf/src/CMakeLists.txt b/firmware/asdf/src/CMakeLists.txt index d3428b2..f639fb3 100644 --- a/firmware/asdf/src/CMakeLists.txt +++ b/firmware/asdf/src/CMakeLists.txt @@ -52,32 +52,7 @@ configure_file(${ASDF_SRC_DIR}/asdf_keymap_setup.c.in ${CMAKE_CURRENT_BINARY_DI configure_file(${ASDF_SRC_DIR}/asdf_keymap_setup.h.in ${CMAKE_CURRENT_BINARY_DIR}/asdf_keymap_setup.h) - -list(APPEND CFLAGS - -std=c99 -# -Wa,-adhln - -Wall - -funsigned-char - -funsigned-bitfields - -ffunction-sections - -fdata-sections - -fpack-struct - -fshort-enums - -O2 - -Wall - -Wextra - -Wpointer-arith - -Wcast-align - -Wwrite-strings - -Wswitch-default - -Wunreachable-code - -Winit-self - -Wmissing-field-initializers - -Wno-unknown-pragmas - -Wstrict-prototypes - -Wundef - -Wold-style-definition -) +c_toolchain_flags() list (APPEND SOURCES asdf.c