diff --git a/CMakeLists.txt b/CMakeLists.txt index 2cc5be9d62734..f53d3d31a2a2c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -319,12 +319,6 @@ if(CONFIG_STD_C23) set(CSTD c2x) elseif(CONFIG_STD_C17) set(CSTD c17) -elseif(CONFIG_STD_C11) - set(CSTD c11) -elseif(CONFIG_STD_C99) - set(CSTD c99) -elseif(CONFIG_STD_C90) - set(CSTD c90) else() message(FATAL_ERROR "Unreachable code. Expected C standard to have been chosen.") endif() @@ -409,7 +403,7 @@ if(CONFIG_COMPILER_FREESTANDING) zephyr_compile_options($<$:$>) endif() -if (CONFIG_PICOLIBC AND NOT CONFIG_PICOLIBC_IO_FLOAT) +if(CONFIG_PICOLIBC AND NOT CONFIG_PICOLIBC_IO_FLOAT) # @Intent: Set compiler specific flag to disable printf-related optimizations zephyr_compile_options($<$:$>) endif() @@ -1157,7 +1151,7 @@ endif() get_property(OUTPUT_FORMAT GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT) -if (CONFIG_CODE_DATA_RELOCATION) +if(CONFIG_CODE_DATA_RELOCATION) set(CODE_RELOCATION_DEP code_relocation_source_lib) endif() # CONFIG_CODE_DATA_RELOCATION @@ -2134,7 +2128,7 @@ if(CONFIG_BUILD_OUTPUT_INFO_HEADER) ) endif() -if (CONFIG_LLEXT AND CONFIG_LLEXT_EXPORT_BUILTINS_BY_SLID) +if(CONFIG_LLEXT AND CONFIG_LLEXT_EXPORT_BUILTINS_BY_SLID) #slidgen must be the first post-build command to be executed #on the Zephyr ELF to ensure that all other commands, such as #binary file generation, are operating on a preparated ELF. @@ -2200,7 +2194,7 @@ if(signing_script) endif() # Generate USB-C VIF policies in XML format -if (CONFIG_BUILD_OUTPUT_VIF) +if(CONFIG_BUILD_OUTPUT_VIF) include(${CMAKE_CURRENT_LIST_DIR}/cmake/vif.cmake) endif() @@ -2251,7 +2245,7 @@ if(LOG_DICT_DB_NAME_ARG) --build-header ${PROJECT_BINARY_DIR}/include/generated/zephyr/version.h ) - if (NOT CONFIG_LOG_DICTIONARY_DB_TARGET) + if(NOT CONFIG_LOG_DICTIONARY_DB_TARGET) # If not using a separate target for generating logging dictionary # database, add the generation to post build command to make sure # the database is actually being generated. diff --git a/Kconfig.zephyr b/Kconfig.zephyr index d758a03baff44..a654293abd6a0 100644 --- a/Kconfig.zephyr +++ b/Kconfig.zephyr @@ -355,20 +355,8 @@ endmenu menu "Compiler Options" -config REQUIRES_STD_C99 - bool - help - Hidden option to select compiler support C99 standard or higher. - -config REQUIRES_STD_C11 - bool - select REQUIRES_STD_C99 - help - Hidden option to select compiler support C11 standard or higher. - config REQUIRES_STD_C17 bool - select REQUIRES_STD_C11 help Hidden option to select compiler support C17 standard or higher. @@ -381,31 +369,10 @@ config REQUIRES_STD_C23 choice STD_C prompt "C Standard" default STD_C23 if REQUIRES_STD_C23 - default STD_C17 if REQUIRES_STD_C17 - default STD_C11 if REQUIRES_STD_C11 - default STD_C99 + default STD_C17 help C Standards. -config STD_C90 - bool "C90" - depends on !REQUIRES_STD_C99 - help - 1989 C standard as completed in 1989 and ratified by ISO/IEC - as ISO/IEC 9899:1990. This version is known as "ANSI C". - -config STD_C99 - bool "C99" - depends on !REQUIRES_STD_C11 - help - 1999 C standard. - -config STD_C11 - bool "C11" - depends on !REQUIRES_STD_C17 - help - 2011 C standard. - config STD_C17 bool "C17" depends on !REQUIRES_STD_C23 diff --git a/arch/Kconfig b/arch/Kconfig index 7bcfb4d3ffd8d..1a7d9d418c5a4 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -152,12 +152,6 @@ config ARCH_POSIX select BARRIER_OPERATIONS_BUILTIN # POSIX arch based targets get their memory cleared on entry by the host OS select SKIP_BSS_CLEAR - # Override the C standard used for compilation to C 2011 - # This is due to some tests using _Static_assert which is a 2011 feature, but - # otherwise relying on compilers supporting it also when set to C99. - # This was in general ok, but with some host compilers and C library versions - # it led to problems. So we override it to 2011 for the native targets. - select REQUIRES_STD_C11 help POSIX (native) architecture diff --git a/cmake/compiler/compiler_features.cmake b/cmake/compiler/compiler_features.cmake index 6b4b6ce70ba75..e2cad220d6bac 100644 --- a/cmake/compiler/compiler_features.cmake +++ b/cmake/compiler/compiler_features.cmake @@ -1,18 +1,15 @@ -set(c23id c2x gnu2x) +set(c23id c2x gnu2x "iso9899:2023" "iso9899:2024") set(c17id c17 c18 gnu17 gnu18 "iso9899:2017" "iso9899:2018") -set(c11id c11 gnu11 "iso9899:2011") -set(c99id c99 gnu99 "iso9899:1999") -set(c90id c89 c90 gnu89 gnu90 "iso9899:1990" "iso9899:199409") set(compile_features_list) # For each id value above a compile_features_${idval} with a list of supported # `c_std_XX` values are created for easy lookup. # For example, the settings -# - `compile_feature_c99` will contain `c_std_90;c_std_99` -# - `compile_feature_iso9899:2011` will contain `c_std_90;c_std_99;c_std_11` +# - `compile_feature_c23` will contain `c_std_17;c_std_23` +# - `compile_feature_iso9899:2023` will contain `c_std_17;c_std_23` # that can then be used to set CMAKE_C_COMPILE_FEATURES accordingly. -foreach(standard 90 99 11 17 23) +foreach(standard 17 23) list(APPEND compile_features_list c_std_${standard}) foreach(id ${c${standard}id}) set(compile_features_${id} ${compile_features_list}) diff --git a/doc/develop/languages/c/index.rst b/doc/develop/languages/c/index.rst index 8cd19737ba833..e2dd534210895 100644 --- a/doc/develop/languages/c/index.rst +++ b/doc/develop/languages/c/index.rst @@ -24,9 +24,9 @@ Language Standards Zephyr does not target a specific version of the C standards; however, the Zephyr codebase makes extensive use of the features newly introduced in the -1999 release of the ISO C standard (ISO/IEC 9899:1999, hereinafter referred to -as C99) such as those listed below, effectively requiring the use of a compiler -toolchain that supports the C99 standard and above: +2017 release of the ISO C standard (ISO/IEC 9899:2017, hereinafter referred to +as C17) such as those listed below, effectively requiring the use of a compiler +toolchain that supports the C17 standard and above: * inline functions * standard boolean types (``bool`` in ````) @@ -34,17 +34,11 @@ toolchain that supports the C99 standard and above: * designated initializers * variadic macros * ``restrict`` qualification - -Some Zephyr components make use of the features newly introduced in the 2011 -release of the ISO C standard (ISO/IEC 9899:2011, hereinafter referred to as -C11) such as the type-generic expressions using the ``_Generic`` keyword. For -example, the :c:func:`cbprintf` component, used as the default formatted output -processor for Zephyr, makes use of the C11 type-generic expressions, and this -effectively requires most Zephyr applications to be compiled using a compiler -toolchain that supports the C11 standard and above. +* _Generic keyword +* _Static_assert keyword In summary, it is recommended to use a compiler toolchain that supports at -least the C11 standard for developing with Zephyr. It is, however, important to +least the C17 standard for developing with Zephyr. It is, however, important to note that some optional Zephyr components and external modules may make use of the C language features that have been introduced in more recent versions of the standards, in which case it will be necessary to use a more up-to-date diff --git a/doc/services/formatted_output.rst b/doc/services/formatted_output.rst index 5f6616795a98d..6ec480048f462 100644 --- a/doc/services/formatted_output.rst +++ b/doc/services/formatted_output.rst @@ -81,9 +81,8 @@ Package can be created using two methods: package. * static - types of arguments are detected at compile time by the preprocessor and package is created as simple assignments to a provided memory. This method - is significantly faster than runtime (more than 15 times) but has following - limitations: requires ``_Generic`` keyword (C11 feature) to be supported by - the compiler and cannot distinguish between ``%p`` and ``%s`` if char pointer + is significantly faster than runtime (more than 15 times) but has a + significant limitation: it cannot distinguish between ``%p`` and ``%s`` if char pointer is used. It treats all (unsigned) char pointers as ``%s`` thus it will attempt to append string to a package. It can be handled correctly during conversion from **transient** package to **self-contained** package using @@ -174,7 +173,6 @@ formatting since address changes whenever package is copied. Limitations and recommendations =============================== -* C11 ``_Generic`` support is required by the compiler to use static (fast) packaging. * It is recommended to cast any character pointer used with ``%p`` format specifier to other pointer type (e.g. ``void *``). If format string is not accessible then only static packaging is possible and it will append all detected strings. Character pointer diff --git a/doc/services/logging/index.rst b/doc/services/logging/index.rst index 0830f78730699..5bd939aca66b3 100644 --- a/doc/services/logging/index.rst +++ b/doc/services/logging/index.rst @@ -869,8 +869,6 @@ The are following recommendations: * Enable :kconfig:option:`CONFIG_LOG_SPEED` to slightly speed up deferred logging at the cost of slight increase in memory footprint. -* Compiler with C11 ``_Generic`` keyword support is recommended. Logging - performance is significantly degraded without it. See :ref:`cbprintf_packaging`. * It is recommended to cast pointer to ``const char *`` when it is used with ``%s`` format specifier and it points to a constant string. * It is recommended to cast pointer to ``char *`` when it is used with ``%s`` diff --git a/include/zephyr/sys/cbprintf.h b/include/zephyr/sys/cbprintf.h index 414e950946527..2da57dcf3317f 100644 --- a/include/zephyr/sys/cbprintf.h +++ b/include/zephyr/sys/cbprintf.h @@ -17,19 +17,6 @@ #include #endif /* CONFIG_CBPRINTF_LIBC_SUBSTS */ -/* Determine if _Generic is supported using macro from toolchain.h. - * - * @note Z_C_GENERIC is also set for C++ where functionality is implemented - * using overloading and templates. - */ -#ifndef Z_C_GENERIC -#if defined(__cplusplus) || TOOLCHAIN_HAS_C_GENERIC -#define Z_C_GENERIC 1 -#else -#define Z_C_GENERIC 0 -#endif -#endif - #ifdef __xtensa__ #define Z_PKG_HDR_EXT_XTENSA_ALIGNMENT 8 #ifdef CONFIG_CBPRINTF_PACKAGE_HEADER_STORE_CREATION_FLAGS @@ -120,7 +107,6 @@ BUILD_ASSERT(sizeof(struct cbprintf_package_hdr_ext) % Z_PKG_HDR_EXT_XTENSA_ALIG * @endcond */ -/* Z_C_GENERIC is used there */ #include #ifdef __cplusplus diff --git a/include/zephyr/sys/cbprintf_internal.h b/include/zephyr/sys/cbprintf_internal.h index 19ed82f6b53a8..13bda1695abd3 100644 --- a/include/zephyr/sys/cbprintf_internal.h +++ b/include/zephyr/sys/cbprintf_internal.h @@ -534,7 +534,6 @@ extern "C" { * @retval 1 if string must be packaged at runtime. * @retval 0 if string can be statically packaged. */ -#if Z_C_GENERIC #define Z_CBPRINTF_MUST_RUNTIME_PACKAGE(flags, ...) ({\ int _rv; \ if ((flags) & CBPRINTF_PACKAGE_ADD_RW_STR_POS) { \ @@ -544,9 +543,6 @@ extern "C" { } \ _rv; \ }) -#else -#define Z_CBPRINTF_MUST_RUNTIME_PACKAGE(flags, ...) 1 -#endif /** @brief Get storage size for given argument. * @@ -864,23 +860,10 @@ do { \ } \ } while (false) -#if Z_C_GENERIC #define Z_CBPRINTF_STATIC_PACKAGE(packaged, inlen, outlen, align_offset, flags, \ ... /* fmt, ... */) \ Z_CBPRINTF_STATIC_PACKAGE_GENERIC(packaged, inlen, outlen, \ align_offset, flags, __VA_ARGS__) -#else -#define Z_CBPRINTF_STATIC_PACKAGE(packaged, inlen, outlen, align_offset, flags, \ - ... /* fmt, ... */) \ -do { \ - /* Small trick needed to avoid warning on always true */ \ - if (((uintptr_t)packaged + 1) != 1) { \ - outlen = cbprintf_package(packaged, inlen, flags, __VA_ARGS__); \ - } else { \ - outlen = cbprintf_package(NULL, align_offset, flags, __VA_ARGS__); \ - } \ -} while (false) -#endif /* Z_C_GENERIC */ #ifdef __cplusplus } diff --git a/lib/os/cbprintf_packaged.c b/lib/os/cbprintf_packaged.c index d5add5ecf3780..64289dc23edd0 100644 --- a/lib/os/cbprintf_packaged.c +++ b/lib/os/cbprintf_packaged.c @@ -17,12 +17,6 @@ #include LOG_MODULE_REGISTER(cbprintf_package, CONFIG_CBPRINTF_PACKAGE_LOG_LEVEL); -#if defined(CONFIG_CBPRINTF_PACKAGE_SUPPORT_TAGGED_ARGUMENTS) && \ - !Z_C_GENERIC -#error "CONFIG_CBPRINTF_PACKAGE_SUPPORT_TAGGED_ARGUMENTS " \ - "requires toolchain to support _Generic!" -#endif - /** * @brief Check if address is in read only section. * diff --git a/modules/nanopb/Kconfig b/modules/nanopb/Kconfig index 85c6ede9782ef..41030eac6b3e7 100644 --- a/modules/nanopb/Kconfig +++ b/modules/nanopb/Kconfig @@ -6,8 +6,6 @@ config ZEPHYR_NANOPB_MODULE menuconfig NANOPB bool "Nanopb Support" - # Nanopb requires c_std_11 compiler features like _Static_assert - select REQUIRES_STD_C11 help This option enables the Nanopb library and generator. diff --git a/tests/lib/cbprintf_package/src/main.c b/tests/lib/cbprintf_package/src/main.c index 35deba58013f3..21f43b3daf970 100644 --- a/tests/lib/cbprintf_package/src/main.c +++ b/tests/lib/cbprintf_package/src/main.c @@ -59,7 +59,6 @@ static void unpack(const char *desc, struct out_buffer *buf, #define TEST_PACKAGING(flags, fmt, ...) do { \ int must_runtime = CBPRINTF_MUST_RUNTIME_PACKAGE(flags, fmt, __VA_ARGS__); \ - zassert_equal(must_runtime, !Z_C_GENERIC); \ snprintfcb(compare_buf, sizeof(compare_buf), fmt, __VA_ARGS__); \ printk("-----------------------------------------\n"); \ printk("%s\n", compare_buf); \ @@ -683,14 +682,6 @@ ZTEST(cbprintf_package, test_cbprintf_ro_rw_loc_const_char_ptr) static void cbprintf_rw_loc_const_char_ptr(bool keep_ro_str) { - /* Test requires that static packaging is applied. Runtime packaging - * cannot be tricked because it checks pointers against read only - * section. - */ - if (Z_C_GENERIC == 0) { - ztest_test_skip(); - } - int slen, slen2; int clen, clen2; static const char test_str[] = "test %s %d %s"; @@ -778,10 +769,6 @@ ZTEST(cbprintf_package, test_cbprintf_must_runtime_package) { int rv; - if (Z_C_GENERIC == 0) { - ztest_test_skip(); - } - rv = CBPRINTF_MUST_RUNTIME_PACKAGE(0, "test"); zassert_equal(rv, 0); @@ -1006,7 +993,6 @@ static void *print_size_and_alignment_info(void) printk("alignof: int=%zu long=%zu ptr=%zu long long=%zu double=%zu long double=%zu\n", __alignof__(int), __alignof__(long), __alignof__(void *), __alignof__(long long), __alignof__(double), __alignof__(long double)); - printk("%s C11 _Generic\n", Z_C_GENERIC ? "With" : "Without"); #endif return NULL; diff --git a/tests/lib/cbprintf_package/testcase.yaml b/tests/lib/cbprintf_package/testcase.yaml index f1761003c8a73..fb5780eb2843a 100644 --- a/tests/lib/cbprintf_package/testcase.yaml +++ b/tests/lib/cbprintf_package/testcase.yaml @@ -11,13 +11,6 @@ tests: integration_platforms: - native_sim - libraries.cbprintf.package_no_generic: - extra_configs: - - CONFIG_CBPRINTF_COMPLETE=y - - CONFIG_COMPILER_OPT="-DZ_C_GENERIC=0" - integration_platforms: - - native_sim - libraries.cbprintf.package_fp: filter: CONFIG_CPU_HAS_FPU extra_configs: @@ -76,14 +69,6 @@ tests: integration_platforms: - native_sim - libraries.cbprintf.package_no_generic_cpp: - extra_configs: - - CONFIG_CPP=y - - CONFIG_CBPRINTF_COMPLETE=y - - CONFIG_COMPILER_OPT="-DZ_C_GENERIC=0" - integration_platforms: - - native_sim - libraries.cbprintf.package_fp_cpp: filter: CONFIG_CPU_HAS_FPU extra_configs: @@ -148,16 +133,6 @@ tests: integration_platforms: - qemu_x86 - libraries.cbprintf.package_no_generic.picolibc: - filter: CONFIG_PICOLIBC_SUPPORTED - tags: picolibc - extra_configs: - - CONFIG_CBPRINTF_COMPLETE=y - - CONFIG_COMPILER_OPT="-DZ_C_GENERIC=0" - - CONFIG_PICOLIBC=y - integration_platforms: - - qemu_x86 - libraries.cbprintf.package_fp.picolibc: filter: CONFIG_CPU_HAS_FPU and CONFIG_PICOLIBC_SUPPORTED tags: picolibc @@ -180,17 +155,6 @@ tests: integration_platforms: - qemu_x86 - libraries.cbprintf.package_no_generic_cpp.picolibc: - filter: CONFIG_PICOLIBC_SUPPORTED - tags: picolibc - extra_configs: - - CONFIG_CPP=y - - CONFIG_CBPRINTF_COMPLETE=y - - CONFIG_COMPILER_OPT="-DZ_C_GENERIC=0" - - CONFIG_PICOLIBC=y - integration_platforms: - - qemu_x86 - libraries.cbprintf.package_fp_cpp.picolibc: filter: CONFIG_CPU_HAS_FPU and CONFIG_PICOLIBC_SUPPORTED tags: picolibc diff --git a/tests/subsys/bindesc/definition/testcase.yaml b/tests/subsys/bindesc/definition/testcase.yaml index 3e92b2982f253..72f62c0b1f107 100644 --- a/tests/subsys/bindesc/definition/testcase.yaml +++ b/tests/subsys/bindesc/definition/testcase.yaml @@ -19,23 +19,9 @@ tests: - qemu_riscv32 - qemu_riscv32e - qemu_riscv64 - bindesc.define.c99: - extra_configs: - - CONFIG_STD_C99=y - bindesc.define.c11: - extra_configs: - - CONFIG_STD_C11=y bindesc.define.c17: extra_configs: - CONFIG_STD_C17=y - bindesc.define.gnu99: - extra_configs: - - CONFIG_STD_C99=y - - CONFIG_GNU_C_EXTENSIONS=y - bindesc.define.gnu11: - extra_configs: - - CONFIG_STD_C11=y - - CONFIG_GNU_C_EXTENSIONS=y bindesc.define.gnu17: extra_configs: - CONFIG_STD_C17=y diff --git a/tests/subsys/bindesc/reading/testcase.yaml b/tests/subsys/bindesc/reading/testcase.yaml index 94a00642d2fd7..827644089d242 100644 --- a/tests/subsys/bindesc/reading/testcase.yaml +++ b/tests/subsys/bindesc/reading/testcase.yaml @@ -8,23 +8,9 @@ tests: bindesc.read: platform_allow: - native_sim - bindesc.read.c99: - extra_configs: - - CONFIG_STD_C99=y - bindesc.read.c11: - extra_configs: - - CONFIG_STD_C11=y bindesc.read.c17: extra_configs: - CONFIG_STD_C17=y - bindesc.read.gnu99: - extra_configs: - - CONFIG_STD_C99=y - - CONFIG_GNU_C_EXTENSIONS=y - bindesc.read.gnu11: - extra_configs: - - CONFIG_STD_C11=y - - CONFIG_GNU_C_EXTENSIONS=y bindesc.read.gnu17: extra_configs: - CONFIG_STD_C17=y diff --git a/tests/unit/cbprintf/main.c b/tests/unit/cbprintf/main.c index fa6a2d2a4ebe9..321a52708ac3b 100644 --- a/tests/unit/cbprintf/main.c +++ b/tests/unit/cbprintf/main.c @@ -35,9 +35,6 @@ #else #define USE_PACKAGED 0 #endif -#if (VIA_TWISTER & 0x800) != 0 -#define AVOID_C_GENERIC 1 -#endif #if (VIA_TWISTER & 0x1000) != 0 #define PKG_ALIGN_OFFSET sizeof(void *) #endif @@ -63,10 +60,6 @@ #define ENABLED_USE_PACKAGED false #endif -#if AVOID_C_GENERIC -#define Z_C_GENERIC 0 -#endif - #ifndef PACKAGE_FLAGS #define PACKAGE_FLAGS 0 #endif @@ -1181,11 +1174,6 @@ ZTEST(prf, test_cbprintf_package_rw_string_indexes) return; } - if (!Z_C_GENERIC) { - /* runtime packaging will not detect ro strings. */ - return; - } - int len0, len1; static const char *test_str = "test %d %s"; static const char *test_str1 = "lorem ipsum"; @@ -1249,10 +1237,6 @@ ZTEST(prf, test_cbprintf_fsc_package) return; } - if (!Z_C_GENERIC) { - /* runtime packaging will not detect ro strings. */ - return; - } char test_str[] = "test %d %s"; const char *test_str1 = "lorem ipsum"; @@ -1449,8 +1433,7 @@ static void *cbprintf_setup(void) TC_PRINT(" NANO\n"); } if (ENABLED_USE_PACKAGED) { - TC_PRINT(" PACKAGED %s C11 _Generic\n", - Z_C_GENERIC ? "with" : "without"); + TC_PRINT(" PACKAGED\n"); } else { TC_PRINT(" VA_LIST\n"); }