From 759dcfe18fcb2b5989fa73a07fa58da1c698dbff Mon Sep 17 00:00:00 2001 From: Patryk Duda Date: Tue, 30 Apr 2024 14:41:09 +0200 Subject: [PATCH] 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 --- include/zephyr/toolchain/llvm.h | 38 ------------------------------- lib/libc/minimal/include/stdint.h | 4 ++-- 2 files changed, 2 insertions(+), 40 deletions(-) diff --git a/include/zephyr/toolchain/llvm.h b/include/zephyr/toolchain/llvm.h index 8a78d4e8404..a77e82a45e2 100644 --- a/include/zephyr/toolchain/llvm.h +++ b/include/zephyr/toolchain/llvm.h @@ -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_ */ diff --git a/lib/libc/minimal/include/stdint.h b/lib/libc/minimal/include/stdint.h index 904f0b49b25..80a2ff1ab29 100644 --- a/lib/libc/minimal/include/stdint.h +++ b/lib/libc/minimal/include/stdint.h @@ -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