-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Description
Describe the bug
For some platforms, the intptr_t and uintptr_t types do not match the PRIxPTR types.
To Reproduce
On an x86-64 host, build the following code for native_posix board using LLVM (ZEPHYR_TOOLCHAIN_VARIANT=llvm).
uintptr_t val = 1234;
printk("%" PRIuPTR "\n", val);
See the following error:
error: format specifies type 'unsigned int' but the argument has type 'uintptr_t' (aka 'unsigned long') [-Werror,-Wformat]
Expected behavior
The types of intptr_t and uintptr_t and the PRIxPTR match.
For instance:
- If
intptr_tisint,PRIdPTRshould be%d. - If
intptr_tislong,PRIdPTRshould be%ld.
Impact
Makes PRIxPTR useless on the affected platforms (in particular, native_posix on x86-64 with Clang/LLVM).
Environment (please complete the following information):
- OS: Ubuntu 20.04 x86-64
- Toolchain: Clang 10.0 (also tested on Clang 12 and the problem persists)
- Commit SHA: feb0e9f
Additional context
This happens because zephyr_stdint.h re-defines __INTPTR_TYPE__ and __UINTPTR_TYPE__ as long int and long unsigned int, respectively, while the PRIxPTR definitions stay %x with no size prefix.
zephyr/include/toolchain/zephyr_stdint.h
Lines 47 to 50 in feb0e9f
| #undef __INTPTR_TYPE__ | |
| #undef __UINTPTR_TYPE__ | |
| #define __INTPTR_TYPE__ long int | |
| #define __UINTPTR_TYPE__ long unsigned int |
See #37712 (comment).
See also #16645.