diff --git a/libc/src/__support/common.h b/libc/src/__support/common.h --- a/libc/src/__support/common.h +++ b/libc/src/__support/common.h @@ -15,6 +15,18 @@ #define unlikely(x) __builtin_expect(x, 0) #define UNUSED __attribute__((unused)) +#ifdef __has_attribute +#define LIBC_HAVE_ATTRIBUTE(x) __has_attribute(x) +#else +#define LIBC_HAVE_ATTRIBUTE(x) 0 +#endif + +#if LIBC_HAVE_ATTRIBUTE(aligned) || (defined(__GNUC__) && !defined(__clang__)) +#define LIBC_ATTRIBUTE_FUNC_ALIGN(bytes) __attribute__((aligned(bytes))) +#else +#define LIBC_ATTRIBUTE_FUNC_ALIGN(bytes) +#endif + #ifndef LLVM_LIBC_FUNCTION_ATTR #define LLVM_LIBC_FUNCTION_ATTR #endif @@ -25,9 +37,10 @@ LLVM_LIBC_FUNCTION_ATTR decltype(__llvm_libc::name) \ __##name##_impl__ __asm__(#name); \ decltype(__llvm_libc::name) name [[gnu::alias(#name)]]; \ - type __##name##_impl__ arglist + type LIBC_ATTRIBUTE_FUNC_ALIGN(64) __##name##_impl__ arglist #else -#define LLVM_LIBC_FUNCTION(type, name, arglist) type name arglist +#define LLVM_LIBC_FUNCTION(type, name, arglist) \ + type LIBC_ATTRIBUTE_FUNC_ALIGN(64) name arglist #endif namespace __llvm_libc {