From 5b2ecaa64ef286f70a5d4d6914e1b170c69d5b2d Mon Sep 17 00:00:00 2001 From: makise-homura Date: Thu, 22 Aug 2024 21:12:11 +0300 Subject: [PATCH 1/4] Treat LCC as compiler different from GCC LCC (eLbrus C/C++ compiler) is an EDG-based compiler that in most cases is similar in behavior to GNU, but it has different warning options supported and enabled by default. It seems to have sense to treat LCC and GNU differently, as CMake supports it from 3.23. For it to be done, CMake policy CMP0129 should be set to NEW, and then CMAKE_${LANG}_COMPILER_ID may be checked to be STREQUAL "LCC". This commit does this, and introduces warning arguments in call to compiler that are slightly different from GNU to let googletest be buildable without unexpected warnings. --- CMakeLists.txt | 1 + googlemock/CMakeLists.txt | 1 + googletest/CMakeLists.txt | 1 + googletest/cmake/internal_utils.cmake | 13 ++++++++++--- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 512e5c3d48..56eab5dade 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.13) +cmake_policy(SET CMP0129 NEW) project(googletest-distribution) set(GOOGLETEST_VERSION 1.15.2) diff --git a/googlemock/CMakeLists.txt b/googlemock/CMakeLists.txt index 99b2411f36..c4d1a7506e 100644 --- a/googlemock/CMakeLists.txt +++ b/googlemock/CMakeLists.txt @@ -37,6 +37,7 @@ endif() # ${gmock_BINARY_DIR}. # Language "C" is required for find_package(Threads). cmake_minimum_required(VERSION 3.13) +cmake_policy(SET CMP0129 NEW) project(gmock VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C) if (COMMAND set_up_hermetic_build) diff --git a/googletest/CMakeLists.txt b/googletest/CMakeLists.txt index dce6a7c9ee..00009ec30a 100644 --- a/googletest/CMakeLists.txt +++ b/googletest/CMakeLists.txt @@ -47,6 +47,7 @@ endif() # Project version. cmake_minimum_required(VERSION 3.13) +cmake_policy(SET CMP0129 NEW) project(gtest VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C) if (COMMAND set_up_hermetic_build) diff --git a/googletest/cmake/internal_utils.cmake b/googletest/cmake/internal_utils.cmake index 580ac1cbc3..9d8b79de05 100644 --- a/googletest/cmake/internal_utils.cmake +++ b/googletest/cmake/internal_utils.cmake @@ -102,9 +102,11 @@ macro(config_compiler_and_linker) if (CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM") set(cxx_base_flags "${cxx_base_flags} -Wno-implicit-float-size-conversion -ffp-model=precise") endif() - elseif (CMAKE_COMPILER_IS_GNUCXX) - set(cxx_base_flags "-Wall -Wshadow -Wundef") - if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0.0) + elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR + CMAKE_CXX_COMPILER_ID STREQUAL "LCC") + set(cxx_base_flags "-Wall -Wundef") + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND + NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0.0) set(cxx_base_flags "${cxx_base_flags} -Wno-error=dangling-else") endif() set(cxx_exception_flags "-fexceptions") @@ -115,6 +117,11 @@ macro(config_compiler_and_linker) set(cxx_no_rtti_flags "-fno-rtti -DGTEST_HAS_RTTI=0") set(cxx_strict_flags "-Wextra -Wno-unused-parameter -Wno-missing-field-initializers") + if (CMAKE_CXX_COMPILER_ID STREQUAL "LCC") + set(cxx_base_flags "${cxx_base_flags} -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unused-function") + else() + set(cxx_base_flags "${cxx_base_flags} -Wshadow") + endif() elseif (CMAKE_CXX_COMPILER_ID STREQUAL "SunPro") set(cxx_exception_flags "-features=except") # Sun Pro doesn't provide macros to indicate whether exceptions and From df6fa41e1b3b75513cce52e95fecc99b130f26c0 Mon Sep 17 00:00:00 2001 From: makise-homura Date: Thu, 22 Aug 2024 21:19:18 +0300 Subject: [PATCH 2/4] Eliminate -Wreturn-type (at least on LCC) There are four GetName() functions that are expected to have a limited set of possible types. But compiler does not know about that, and may complain (and in LCC case, does) about no return operator in the end of these functions. This commit adds dummy return to each of these functions to eliminate this warning. --- googletest/test/googletest-output-test_.cc | 2 ++ googletest/test/gtest-typed-test_test.cc | 2 ++ 2 files changed, 4 insertions(+) diff --git a/googletest/test/googletest-output-test_.cc b/googletest/test/googletest-output-test_.cc index e3560c0182..e30b69bbec 100644 --- a/googletest/test/googletest-output-test_.cc +++ b/googletest/test/googletest-output-test_.cc @@ -720,6 +720,7 @@ class TypedTestNames { return std::string("char") + ::testing::PrintToString(i); if (std::is_same::value) return std::string("int") + ::testing::PrintToString(i); + return std::string("unknown"); } }; @@ -755,6 +756,7 @@ class TypedTestPNames { if (std::is_same::value) { return std::string("unsignedInt") + ::testing::PrintToString(i); } + return std::string("unknown"); } }; diff --git a/googletest/test/gtest-typed-test_test.cc b/googletest/test/gtest-typed-test_test.cc index 0cc8b21145..6b90ee4a0b 100644 --- a/googletest/test/gtest-typed-test_test.cc +++ b/googletest/test/gtest-typed-test_test.cc @@ -172,6 +172,7 @@ class TypedTestNames { if (std::is_same::value) { return std::string("int") + ::testing::PrintToString(i); } + return std::string("unknown"); } }; @@ -320,6 +321,7 @@ class TypeParametrizedTestNames { if (std::is_same::value) { return std::string("parInt") + ::testing::PrintToString(i); } + return std::string("unknown"); } }; From 24699b4926072b07e3b4e01c865f1913e382f5ec Mon Sep 17 00:00:00 2001 From: makise-homura Date: Thu, 22 Aug 2024 21:24:31 +0300 Subject: [PATCH 3/4] Extend NVC workaround for no-optimize-sibling-calls __attribute__((optimize("no-optimize-sibling-calls"))) is not supported for at least some versions of NVC (nVidia HPC compiler), and this case has a workaround in gtest-port.h. Actually, this is true not just for NVC (that defines __NVCOMPILER), but for other EDG-based compilers as well, for example, LCC. So the correct check here would be not just for __NVCOMPILER, but for __EDG__ (NVC defines this too, because it is based on EDG). This commit does this. --- googletest/include/gtest/internal/gtest-port.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 8d27c2c4f7..59ab39bfed 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -897,7 +897,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // Ask the compiler not to perform tail call optimization inside // the marked function. #define GTEST_NO_TAIL_CALL_ __attribute__((disable_tail_calls)) -#elif defined(__GNUC__) && !defined(__NVCOMPILER) +#elif defined(__GNUC__) && !defined(__EDG__) #define GTEST_NO_TAIL_CALL_ \ __attribute__((optimize("no-optimize-sibling-calls"))) #else From 2aa1e7cc67feb634cc25d6d32e2cb32f0988a886 Mon Sep 17 00:00:00 2001 From: makise-homura Date: Thu, 22 Aug 2024 22:41:22 +0300 Subject: [PATCH 4/4] Correctly deal with abi::__cxa_demangle() on LCC abi::__cxa_demangle("7MyArrayIbLi42EE", nullptr, nullptr, nullptr) returns "MyArray" on GCC/x86_64, but "MyArray" on LCC/e2k. This behavior causes googletest-list-tests-unittest test to fail. This commit fixes that by slightly modifying the regex to match this behavior of abi::__cxa_demangle(). --- googletest/test/googletest-list-tests-unittest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/googletest/test/googletest-list-tests-unittest.py b/googletest/test/googletest-list-tests-unittest.py index 977e57f087..2283eb91b8 100755 --- a/googletest/test/googletest-list-tests-unittest.py +++ b/googletest/test/googletest-list-tests-unittest.py @@ -74,7 +74,7 @@ TypedTest/1\. # TypeParam = int\s*\*( __ptr64)? TestA TestB -TypedTest/2\. # TypeParam = .*MyArray +TypedTest/2\. # TypeParam = .*MyArray TestA TestB My/TypeParamTest/0\. # TypeParam = (VeryLo{245}|class VeryLo{239})\.\.\. @@ -83,7 +83,7 @@ My/TypeParamTest/1\. # TypeParam = int\s*\*( __ptr64)? TestA TestB -My/TypeParamTest/2\. # TypeParam = .*MyArray +My/TypeParamTest/2\. # TypeParam = .*MyArray TestA TestB MyInstantiation/ValueParamTest\.