diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake --- a/llvm/cmake/modules/HandleLLVMOptions.cmake +++ b/llvm/cmake/modules/HandleLLVMOptions.cmake @@ -351,8 +351,11 @@ endif() endif() -if(NOT WIN32 AND NOT CYGWIN AND NOT (${CMAKE_SYSTEM_NAME} MATCHES "AIX")) - # MinGW warns if -fvisibility-inlines-hidden is used. +if((NOT (${CMAKE_SYSTEM_NAME} MATCHES "AIX")) AND + (NOT (WIN32 OR CYGWIN) OR (MINGW AND CMAKE_CXX_COMPILER_ID MATCHES "Clang"))) + # GCC for MinGW does nothing about -fvisibility-inlines-hidden, but warns + # about use of the attributes. As long as we don't use the attributes (to + # override the default) we shouldn't set the command line options either. # GCC on AIX warns if -fvisibility-inlines-hidden is used and Clang on AIX doesn't currently support visibility. check_cxx_compiler_flag("-fvisibility-inlines-hidden" SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG) append_if(SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG "-fvisibility-inlines-hidden" CMAKE_CXX_FLAGS) diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h --- a/llvm/include/llvm/Support/Compiler.h +++ b/llvm/include/llvm/Support/Compiler.h @@ -113,8 +113,9 @@ /// LLVM_EXTERNAL_VISIBILITY - classes, functions, and variables marked with /// this attribute will be made public and visible outside of any shared library /// they are linked in to. -#if __has_attribute(visibility) && !defined(__MINGW32__) && \ - !defined(__CYGWIN__) && !defined(_WIN32) +#if __has_attribute(visibility) && \ + (!(defined(_WIN32) || defined(__CYGWIN__)) || \ + (defined(__MINGW32__) && defined(__clang__))) #define LLVM_LIBRARY_VISIBILITY __attribute__ ((visibility("hidden"))) #if defined(LLVM_BUILD_LLVM_DYLIB) || defined(LLVM_BUILD_SHARED_LIBS) #define LLVM_EXTERNAL_VISIBILITY __attribute__((visibility("default"))) diff --git a/llvm/lib/Target/CMakeLists.txt b/llvm/lib/Target/CMakeLists.txt --- a/llvm/lib/Target/CMakeLists.txt +++ b/llvm/lib/Target/CMakeLists.txt @@ -22,7 +22,7 @@ # When building shared objects for each target there are some internal APIs # that are used across shared objects which we can't hide. if (NOT BUILD_SHARED_LIBS AND NOT APPLE AND - NOT MINGW AND + (NOT (WIN32 OR CYGWIN) OR (MINGW AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")) AND NOT (${CMAKE_SYSTEM_NAME} MATCHES "AIX") AND NOT DEFINED CMAKE_CXX_VISIBILITY_PRESET) # Set default visibility to hidden, so we don't export all the Target classes