llvm: stdint: Don't define integer constant macros in llvm.h

Zephyr minimal libc implements integer constant macros using internal
headers provided by GCC, for example INT64_C(x) is just a __INT64_C(x)
which is implemented by the GCC.

Clang compiler doesn't provide these definitions, so we define them
(__INT64_C() and INT64_C()) in zephyr/toolchain/llvm.h, but it looks
like INT64_C() definition doesn't come from llvm.h, but from stdlib.h
despite of checking if __GNUC__ is defined.

This is because Clang sometimes pretends to be GNU compiler:
$ x86_64-pc-linux-gnu-clang -dM -E - < /dev/null | grep "GNU"
 #define __GNUC_MINOR__ 2
 #define __GNUC_PATCHLEVEL__ 1
 #define __GNUC_STDC_INLINE__ 1
 #define __GNUC__ 4

Let's keep the integer constant macros in stdlib.h and their
actual implementation in llvm.h. Also define these macros if __clang__
is defined, just in case.

Signed-off-by: Patryk Duda <patrykd@google.com>
This commit is contained in:
Patryk Duda 2024-04-30 14:41:09 +02:00 committed by Carles Cufí
commit 759dcfe18f
2 changed files with 2 additions and 40 deletions

View file

@ -34,80 +34,42 @@
#define __INT8_C(x) x
#endif
#ifndef INT8_C
#define INT8_C(x) __INT8_C(x)
#endif
#ifndef __UINT8_C
#define __UINT8_C(x) x ## U
#endif
#ifndef UINT8_C
#define UINT8_C(x) __UINT8_C(x)
#endif
#ifndef __INT16_C
#define __INT16_C(x) x
#endif
#ifndef INT16_C
#define INT16_C(x) __INT16_C(x)
#endif
#ifndef __UINT16_C
#define __UINT16_C(x) x ## U
#endif
#ifndef UINT16_C
#define UINT16_C(x) __UINT16_C(x)
#endif
#ifndef __INT32_C
#define __INT32_C(x) x
#endif
#ifndef INT32_C
#define INT32_C(x) __INT32_C(x)
#endif
#ifndef __UINT32_C
#define __UINT32_C(x) x ## U
#endif
#ifndef UINT32_C
#define UINT32_C(x) __UINT32_C(x)
#endif
#ifndef __INT64_C
#define __INT64_C(x) x
#endif
#ifndef INT64_C
#define INT64_C(x) __INT64_C(x)
#endif
#ifndef __UINT64_C
#define __UINT64_C(x) x ## ULL
#endif
#ifndef UINT64_C
#define UINT64_C(x) __UINT64_C(x)
#endif
#ifndef __INTMAX_C
#define __INTMAX_C(x) x
#endif
#ifndef INTMAX_C
#define INTMAX_C(x) __INTMAX_C(x)
#endif
#ifndef __UINTMAX_C
#define __UINTMAX_C(x) x ## ULL
#endif
#ifndef UINTMAX_C
#define UINTMAX_C(x) __UINTMAX_C(x)
#endif
#endif /* ZEPHYR_INCLUDE_TOOLCHAIN_LLVM_H_ */

View file

@ -104,7 +104,7 @@ typedef __UINT_LEAST64_TYPE__ uint_least64_t;
typedef __INTPTR_TYPE__ intptr_t;
typedef __UINTPTR_TYPE__ uintptr_t;
#ifdef __GNUC__
#if defined(__GNUC__) || defined(__clang__)
/* These macros must produce constant integer expressions, which can't
* be done in the preprocessor (casts aren't allowed). Defer to the
* GCC internal functions where they're available.
@ -120,7 +120,7 @@ typedef __UINTPTR_TYPE__ uintptr_t;
#define UINT32_C(_v) __UINT32_C(_v)
#define UINT64_C(_v) __UINT64_C(_v)
#define UINTMAX_C(_v) __UINTMAX_C(_v)
#endif /* __GNUC__ */
#endif /* defined(__GNUC__) || defined(__clang__) */
#ifdef __CCAC__
#ifndef __INT8_C