Fix build errors on GCC. (#42834)
authorhev <wangrui@loongson.cn>
Thu, 1 Oct 2020 05:28:58 +0000 (13:28 +0800)
committerGitHub <noreply@github.com>
Thu, 1 Oct 2020 05:28:58 +0000 (22:28 -0700)
* Fix build errors on GCC.

* Enable PGO on Clang.

* Fix build errors on GCC 10 and later.

eng/native/configurecompiler.cmake
src/coreclr/pgosupport.cmake
src/coreclr/src/CMakeLists.txt
src/libraries/Native/Unix/System.Globalization.Native/CMakeLists.txt

index cb9db28..373cc3d 100644 (file)
@@ -321,6 +321,7 @@ if (CLR_CMAKE_HOST_UNIX)
   add_compile_options(-Wno-unused-variable)
   add_compile_options(-Wno-unused-value)
   add_compile_options(-Wno-unused-function)
+  add_compile_options(-Wno-tautological-compare)
 
   #These seem to indicate real issues
   add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wno-invalid-offsetof>)
@@ -334,8 +335,6 @@ if (CLR_CMAKE_HOST_UNIX)
     add_compile_options(-Wno-unused-private-field)
     # Explicit constructor calls are not supported by clang (this->ClassName::ClassName())
     add_compile_options(-Wno-microsoft)
-    # This warning is caused by comparing 'this' to NULL
-    add_compile_options(-Wno-tautological-compare)
     # There are constants of type BOOL used in a condition. But BOOL is defined as int
     # and so the compiler thinks that there is a mistake.
     add_compile_options(-Wno-constant-logical-operand)
index 04bde2b..1e2be5d 100644 (file)
@@ -47,16 +47,16 @@ function(add_pgo TargetName)
                 set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS_RELWITHDEBINFO " /LTCG /USEPROFILE:PGD=\"${ProfilePath}\"")
             else(CLR_CMAKE_HOST_WIN32)
                 if(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE OR UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELWITHDEBINFO)
-                    if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.6)
+                    if((CMAKE_CXX_COMPILER_ID MATCHES "Clang") AND (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.6))
                         if(HAVE_LTO)
                             target_compile_options(${TargetName} PRIVATE -flto -fprofile-instr-use=${ProfilePath} -Wno-profile-instr-out-of-date -Wno-profile-instr-unprofiled)
                             set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS " -flto -fuse-ld=gold -fprofile-instr-use=${ProfilePath}")
                         else(HAVE_LTO)
                             message(WARNING "LTO is not supported, skipping profile guided optimizations")
                         endif(HAVE_LTO)
-                    else(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.6)
+                    else((CMAKE_CXX_COMPILER_ID MATCHES "Clang") AND (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.6))
                         message(WARNING "PGO is not supported; Clang 3.6 or later is required for profile guided optimizations")
-                    endif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.6)
+                    endif((CMAKE_CXX_COMPILER_ID MATCHES "Clang") AND (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.6))
                 endif(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE OR UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELWITHDEBINFO)
             endif(CLR_CMAKE_HOST_WIN32)
         endif(NOT EXISTS ${ProfilePath})
index 1ee527d..5f74a58 100644 (file)
@@ -60,6 +60,10 @@ if(CLR_CMAKE_HOST_UNIX)
   add_subdirectory(nativeresources)
 endif(CLR_CMAKE_HOST_UNIX)
 
+if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 10.0))
+    add_compile_options(-Wno-error=stringop-overflow=)
+endif()
+
 add_subdirectory(utilcode)
 add_subdirectory(gcinfo)
 add_subdirectory(jit)
index b426252..8995556 100644 (file)
@@ -43,6 +43,10 @@ if(CLR_CMAKE_TARGET_UNIX)
     endif()
 endif()
 
+if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 10.0))
+    add_compile_options(-Wno-error=stringop-truncation)
+endif()
+
 include(configure.cmake)
 
 set(NATIVEGLOBALIZATION_SOURCES