Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -409,7 +403,7 @@ if(CONFIG_COMPILER_FREESTANDING)
zephyr_compile_options($<$<COMPILE_LANGUAGE:ASM>:$<TARGET_PROPERTY:compiler,freestanding>>)
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($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,no_printf_return_value>>)
endif()
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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.
Expand Down
35 changes: 1 addition & 34 deletions Kconfig.zephyr
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
Expand Down
6 changes: 0 additions & 6 deletions arch/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 4 additions & 7 deletions cmake/compiler/compiler_features.cmake
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to drop these compiler feature flags? This will require all out-of-tree dependencies to drop this (even if they do support an older C standard version?).

I think this can remain, as newer standards should support older flags.

Original file line number Diff line number Diff line change
@@ -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})
Expand Down
18 changes: 6 additions & 12 deletions doc/develop/languages/c/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,21 @@ 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 ``<stdbool.h>``)
* fixed-width integer types (``[u]intN_t`` in ``<stdint.h>``)
* 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
Expand Down
6 changes: 2 additions & 4 deletions doc/services/formatted_output.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions doc/services/logging/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``
Expand Down
14 changes: 0 additions & 14 deletions include/zephyr/sys/cbprintf.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,6 @@
#include <stdio.h>
#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
Expand Down Expand Up @@ -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 <zephyr/sys/cbprintf_internal.h>

#ifdef __cplusplus
Expand Down
17 changes: 0 additions & 17 deletions include/zephyr/sys/cbprintf_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) { \
Expand All @@ -544,9 +543,6 @@ extern "C" {
} \
_rv; \
})
#else
#define Z_CBPRINTF_MUST_RUNTIME_PACKAGE(flags, ...) 1
#endif

/** @brief Get storage size for given argument.
*
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 0 additions & 6 deletions lib/os/cbprintf_packaged.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@
#include <zephyr/logging/log.h>
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.
*
Expand Down
2 changes: 0 additions & 2 deletions modules/nanopb/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
14 changes: 0 additions & 14 deletions tests/lib/cbprintf_package/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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); \
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down
Loading
Loading