diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h index d265d864228ca..baa5fb5c6b97b 100644 --- a/llvm/include/llvm/Support/Compiler.h +++ b/llvm/include/llvm/Support/Compiler.h @@ -197,17 +197,32 @@ #define LLVM_EXPORT_TEMPLATE #endif #define LLVM_ABI_EXPORT __declspec(dllexport) -#elif defined(__ELF__) || defined(__MINGW32__) || defined(_AIX) || \ - defined(__MVS__) -#define LLVM_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT -#define LLVM_TEMPLATE_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT +#elif (defined(__ELF__) || defined(__MINGW32__) || defined(_AIX) || \ + defined(__MVS__)) && \ + __has_attribute(visibililty) +// Use __attribute__((visibility(""))) syntax for visibility rather than +// [[gnu::visibility("")]] because compilers are more permissive with its +// placement. +#define LLVM_ABI __attribute__((visibility("default"))) +#if defined(__GNUC__) && !defined(__clang__) +// GCC produces warnings on visibility attributes applied to some templates. +#define LLVM_TEMPLATE_ABI +#else +#define LLVM_TEMPLATE_ABI __attribute__((visibility("default"))) +#endif +#define LLVM_EXPORT_TEMPLATE +#define LLVM_ABI_EXPORT __attribute__((visibility("default"))) +#elif (defined(__MACH__) || defined(__WASM__) || defined(__EMSCRIPTEN__)) && \ + __has_attribute(visibility) +#define LLVM_ABI __attribute__((visibility("default"))) +#define LLVM_TEMPLATE_ABI #define LLVM_EXPORT_TEMPLATE -#define LLVM_ABI_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT -#elif defined(__MACH__) || defined(__WASM__) || defined(__EMSCRIPTEN__) -#define LLVM_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT +#define LLVM_ABI_EXPORT __attribute__((visibility("default"))) +#else +#define LLVM_ABI #define LLVM_TEMPLATE_ABI #define LLVM_EXPORT_TEMPLATE -#define LLVM_ABI_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT +#define LLVM_ABI_EXPORT #endif #else #define LLVM_ABI