zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
9.74k stars 6k forks source link

toolchain/llvm: Fix integer macros implementation #72163

Open duda-patryk opened 2 weeks ago

duda-patryk commented 2 weeks ago

Currently __INT64_C() doesn't add any suffix to provided constant which causes the constant to have 'int' type. On the other side, __UINT64_C() adds ULL suffix which makes the constant 'unsigned long long'.

Of course, __INT64_C() is wrong here because int type, in most cases, has 32 bit width.

According to the C standard, these macros are for minimum-width integer constants. For example, it means that using INT16_C() macro will give you constant with type the same as int_least16_t type.

Clang doesn't provide defines like __INT_LEAST16_C_SUFFIX__, which makes implementation difficult, because we need to determine appropriate type first.

This PR also removes the integer constant macros (these not prefixed with __) from llvm.h, since we use definitions from stdint.h (more details can be found in commit message).

duda-patryk commented 1 week ago

Friendly ping!