Description
Describe the bug
The Zephyr RTOS has its own C standard integer type definitions (zephyr_stdint.h
) that override the toolchain defaults.
The __INT{32,64}_C
internal constant macros, which are defined by the toolchain, are not overridden by the zephyr_stdint.h
of the toolchain abstraction layer, and this causes the C library stdint.h
header to infer incorrect types (i.e. those that are native to the toolchain rather than those that are specified by the toolchain abstraction layer) for the INT{32,64}_C
constant macros, leading to type mismatches between the constant macros and the rest.
Affected macros:
INT32_C
UINT32_C
INT64_C
UINT64_C
To Reproduce
Check out and run #44193
Expected behavior
The integer constants generated by the stdint (U)INT{32,64}_C
macros should correspond to the types specified by stdint.h
and inttypes.h
.
Impact
INT{32,64}_C
macros cannot be used.
Logs and console output
Building #44193 for qemu_cortex_m3
:
/home/stephanos/Dev/zephyrproject/zephyr/tests/misc/print_format/src/main.c: In function 'main':
/home/stephanos/Dev/zephyrproject/zephyr/tests/misc/print_format/src/main.c:13:9: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long int' [-Wformat=]
13 | printk("d%" PRId32 "\n", INT32_C(32));
| ^~~~
In file included from /home/stephanos/Dev/zephyrproject/zephyr/include/sys/printk.h:14,
from /home/stephanos/Dev/zephyrproject/zephyr/include/kernel_includes.h:32,
from /home/stephanos/Dev/zephyrproject/zephyr/include/kernel.h:17,
from /home/stephanos/Dev/zephyrproject/zephyr/include/zephyr.h:18,
from /home/stephanos/Dev/zephyrproject/zephyr/tests/misc/print_format/src/main.c:7:
/home/stephanos/Dev/zephyrproject/zephyr/lib/libc/minimal/include/inttypes.h:15:19: note: format string is defined here
15 | #define PRId32 "d" /* int32_t */
/home/stephanos/Dev/zephyrproject/zephyr/tests/misc/print_format/src/main.c:18:9: warning: format '%i' expects argument of type 'int', but argument 2 has type 'long int' [-Wformat=]
18 | printk("i%" PRIi32 "\n", INT32_C(32));
| ^~~~
In file included from /home/stephanos/Dev/zephyrproject/zephyr/include/sys/printk.h:14,
from /home/stephanos/Dev/zephyrproject/zephyr/include/kernel_includes.h:32,
from /home/stephanos/Dev/zephyrproject/zephyr/include/kernel.h:17,
from /home/stephanos/Dev/zephyrproject/zephyr/include/zephyr.h:18,
from /home/stephanos/Dev/zephyrproject/zephyr/tests/misc/print_format/src/main.c:7:
/home/stephanos/Dev/zephyrproject/zephyr/lib/libc/minimal/include/inttypes.h:21:19: note: format string is defined here
21 | #define PRIi32 "i" /* int32_t */
/home/stephanos/Dev/zephyrproject/zephyr/tests/misc/print_format/src/main.c:23:9: warning: format '%o' expects argument of type 'unsigned int', but argument 2 has type 'long int' [-Wformat=]
23 | printk("o%" PRIo32 "\n", INT32_C(32));
| ^~~~
In file included from /home/stephanos/Dev/zephyrproject/zephyr/include/sys/printk.h:14,
from /home/stephanos/Dev/zephyrproject/zephyr/include/kernel_includes.h:32,
from /home/stephanos/Dev/zephyrproject/zephyr/include/kernel.h:17,
from /home/stephanos/Dev/zephyrproject/zephyr/include/zephyr.h:18,
from /home/stephanos/Dev/zephyrproject/zephyr/tests/misc/print_format/src/main.c:7:
/home/stephanos/Dev/zephyrproject/zephyr/lib/libc/minimal/include/inttypes.h:27:19: note: format string is defined here
27 | #define PRIo32 "o" /* int32_t */
/home/stephanos/Dev/zephyrproject/zephyr/tests/misc/print_format/src/main.c:28:9: warning: format '%u' expects argument of type 'unsigned int', but argument 2 has type 'long unsigned int' [-Wformat=]
28 | printk("u%" PRIu32 "\n", UINT32_C(32));
| ^~~~
In file included from /home/stephanos/Dev/zephyrproject/zephyr/include/sys/printk.h:14,
from /home/stephanos/Dev/zephyrproject/zephyr/include/kernel_includes.h:32,
from /home/stephanos/Dev/zephyrproject/zephyr/include/kernel.h:17,
from /home/stephanos/Dev/zephyrproject/zephyr/include/zephyr.h:18,
from /home/stephanos/Dev/zephyrproject/zephyr/tests/misc/print_format/src/main.c:7:
/home/stephanos/Dev/zephyrproject/zephyr/lib/libc/minimal/include/inttypes.h:33:19: note: format string is defined here
33 | #define PRIu32 "u" /* uint32_t */
/home/stephanos/Dev/zephyrproject/zephyr/tests/misc/print_format/src/main.c:33:9: warning: format '%x' expects argument of type 'unsigned int', but argument 2 has type 'long unsigned int' [-Wformat=]
33 | printk("x%" PRIx32 "\n", UINT32_C(32));
| ^~~~
In file included from /home/stephanos/Dev/zephyrproject/zephyr/include/sys/printk.h:14,
from /home/stephanos/Dev/zephyrproject/zephyr/include/kernel_includes.h:32,
from /home/stephanos/Dev/zephyrproject/zephyr/include/kernel.h:17,
from /home/stephanos/Dev/zephyrproject/zephyr/include/zephyr.h:18,
from /home/stephanos/Dev/zephyrproject/zephyr/tests/misc/print_format/src/main.c:7:
/home/stephanos/Dev/zephyrproject/zephyr/lib/libc/minimal/include/inttypes.h:39:19: note: format string is defined here
39 | #define PRIx32 "x" /* uint32_t */
/home/stephanos/Dev/zephyrproject/zephyr/tests/misc/print_format/src/main.c:38:9: warning: format '%X' expects argument of type 'unsigned int', but argument 2 has type 'long unsigned int' [-Wformat=]
38 | printk("X%" PRIX32 "\n", UINT32_C(32));
| ^~~~
In file included from /home/stephanos/Dev/zephyrproject/zephyr/include/sys/printk.h:14,
from /home/stephanos/Dev/zephyrproject/zephyr/include/kernel_includes.h:32,
from /home/stephanos/Dev/zephyrproject/zephyr/include/kernel.h:17,
from /home/stephanos/Dev/zephyrproject/zephyr/include/zephyr.h:18,
from /home/stephanos/Dev/zephyrproject/zephyr/tests/misc/print_format/src/main.c:7:
/home/stephanos/Dev/zephyrproject/zephyr/lib/libc/minimal/include/inttypes.h:45:19: note: format string is defined here
45 | #define PRIX32 "X" /* uint32_t */
Building #44193 for qemu_cortex_a53
:
/home/stephanos/Dev/zephyrproject/zephyr/tests/misc/print_format/src/main.c: In function 'main':
/home/stephanos/Dev/zephyrproject/zephyr/tests/misc/print_format/src/main.c:14:9: warning: format '%lld' expects argument of type 'long long int', but argument 2 has type 'long int' [-Wformat=]
14 | printk("d%" PRId64 "\n", INT64_C(64));
| ^~~~
In file included from /home/stephanos/Dev/zephyrproject/zephyr/include/sys/printk.h:14,
from /home/stephanos/Dev/zephyrproject/zephyr/include/kernel_includes.h:32,
from /home/stephanos/Dev/zephyrproject/zephyr/include/kernel.h:17,
from /home/stephanos/Dev/zephyrproject/zephyr/include/zephyr.h:18,
from /home/stephanos/Dev/zephyrproject/zephyr/tests/misc/print_format/src/main.c:7:
/home/stephanos/Dev/zephyrproject/zephyr/lib/libc/minimal/include/inttypes.h:16:21: note: format string is defined here
16 | #define PRId64 "lld" /* int64_t */
/home/stephanos/Dev/zephyrproject/zephyr/tests/misc/print_format/src/main.c:19:9: warning: format '%lli' expects argument of type 'long long int', but argument 2 has type 'long int' [-Wformat=]
19 | printk("i%" PRIi64 "\n", INT64_C(64));
| ^~~~
In file included from /home/stephanos/Dev/zephyrproject/zephyr/include/sys/printk.h:14,
from /home/stephanos/Dev/zephyrproject/zephyr/include/kernel_includes.h:32,
from /home/stephanos/Dev/zephyrproject/zephyr/include/kernel.h:17,
from /home/stephanos/Dev/zephyrproject/zephyr/include/zephyr.h:18,
from /home/stephanos/Dev/zephyrproject/zephyr/tests/misc/print_format/src/main.c:7:
/home/stephanos/Dev/zephyrproject/zephyr/lib/libc/minimal/include/inttypes.h:22:21: note: format string is defined here
22 | #define PRIi64 "lli" /* int64_t */
/home/stephanos/Dev/zephyrproject/zephyr/tests/misc/print_format/src/main.c:24:9: warning: format '%llo' expects argument of type 'long long unsigned int', but argument 2 has type 'long int' [-Wformat=]
24 | printk("o%" PRIo64 "\n", INT64_C(64));
| ^~~~
In file included from /home/stephanos/Dev/zephyrproject/zephyr/include/sys/printk.h:14,
from /home/stephanos/Dev/zephyrproject/zephyr/include/kernel_includes.h:32,
from /home/stephanos/Dev/zephyrproject/zephyr/include/kernel.h:17,
from /home/stephanos/Dev/zephyrproject/zephyr/include/zephyr.h:18,
from /home/stephanos/Dev/zephyrproject/zephyr/tests/misc/print_format/src/main.c:7:
/home/stephanos/Dev/zephyrproject/zephyr/lib/libc/minimal/include/inttypes.h:28:21: note: format string is defined here
28 | #define PRIo64 "llo" /* int64_t */
/home/stephanos/Dev/zephyrproject/zephyr/tests/misc/print_format/src/main.c:29:9: warning: format '%llu' expects argument of type 'long long unsigned int', but argument 2 has type 'long unsigned int' [-Wformat=]
29 | printk("u%" PRIu64 "\n", UINT64_C(64));
| ^~~~
In file included from /home/stephanos/Dev/zephyrproject/zephyr/include/sys/printk.h:14,
from /home/stephanos/Dev/zephyrproject/zephyr/include/kernel_includes.h:32,
from /home/stephanos/Dev/zephyrproject/zephyr/include/kernel.h:17,
from /home/stephanos/Dev/zephyrproject/zephyr/include/zephyr.h:18,
from /home/stephanos/Dev/zephyrproject/zephyr/tests/misc/print_format/src/main.c:7:
/home/stephanos/Dev/zephyrproject/zephyr/lib/libc/minimal/include/inttypes.h:34:21: note: format string is defined here
34 | #define PRIu64 "llu" /* uint64_t */
/home/stephanos/Dev/zephyrproject/zephyr/tests/misc/print_format/src/main.c:34:9: warning: format '%llx' expects argument of type 'long long unsigned int', but argument 2 has type 'long unsigned int' [-Wformat=]
34 | printk("x%" PRIx64 "\n", UINT64_C(64));
| ^~~~
In file included from /home/stephanos/Dev/zephyrproject/zephyr/include/sys/printk.h:14,
from /home/stephanos/Dev/zephyrproject/zephyr/include/kernel_includes.h:32,
from /home/stephanos/Dev/zephyrproject/zephyr/include/kernel.h:17,
from /home/stephanos/Dev/zephyrproject/zephyr/include/zephyr.h:18,
from /home/stephanos/Dev/zephyrproject/zephyr/tests/misc/print_format/src/main.c:7:
/home/stephanos/Dev/zephyrproject/zephyr/lib/libc/minimal/include/inttypes.h:40:21: note: format string is defined here
40 | #define PRIx64 "llx" /* uint64_t */
/home/stephanos/Dev/zephyrproject/zephyr/tests/misc/print_format/src/main.c:39:9: warning: format '%llX' expects argument of type 'long long unsigned int', but argument 2 has type 'long unsigned int' [-Wformat=]
39 | printk("X%" PRIX64 "\n", UINT64_C(64));
| ^~~~
In file included from /home/stephanos/Dev/zephyrproject/zephyr/include/sys/printk.h:14,
from /home/stephanos/Dev/zephyrproject/zephyr/include/kernel_includes.h:32,
from /home/stephanos/Dev/zephyrproject/zephyr/include/kernel.h:17,
from /home/stephanos/Dev/zephyrproject/zephyr/include/zephyr.h:18,
from /home/stephanos/Dev/zephyrproject/zephyr/tests/misc/print_format/src/main.c:7:
/home/stephanos/Dev/zephyrproject/zephyr/lib/libc/minimal/include/inttypes.h:46:21: note: format string is defined here
46 | #define PRIX64 "llX" /* uint64_t */
Environment (please complete the following information):
- OS: Ubuntu 20.04
- Toolchain: Zephyr SDK 0.14.0
- Commit SHA: 0521aa0 (with printk: Add tests for print format #44193)
Additional context
- This problem affects almost all architectures.
- Toolchain version is not an issue here.
- This affects both the minimal libc and the newlib (the problem lies within the toolchain abstraction layer, and not in the libc itself).