Skip to content

Incompatible (u)intptr_t type and PRIxPTR definitions #37718

@stephanosio

Description

@stephanosio

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_t is int, PRIdPTR should be %d.
  • If intptr_t is long, PRIdPTR should 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.

#undef __INTPTR_TYPE__
#undef __UINTPTR_TYPE__
#define __INTPTR_TYPE__ long int
#define __UINTPTR_TYPE__ long unsigned int

See #37712 (comment).
See also #16645.

Metadata

Metadata

Assignees

Labels

area: PortabilityStandard compliant code, toolchain abstractionarea: ToolchainsToolchainsbugThe issue is a bug, or the PR is fixing a bugpriority: mediumMedium impact/importance bug

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions