Address warnings on NVIDIA nvc++ (#1573) * Address warnings on NVIDIA nvc++ Types of warnings were being generated: 1. Deprecated warnings - solved by defining the relevant BENCHMARK_* macros for nvc++ and adding pragma suppress on a couple of .cc files 2. Setup/TearDown const vs non-const partial override - solved by adding non-const version 3. Static but not referenced - added diagnostic suppress for that file * Modified manually to comply with CD/CI * Revert partial override * Suppress warnings from tests if compiler is NVHPC --------- Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
diff --git a/include/benchmark/benchmark.h b/include/benchmark/benchmark.h index 3e7e1dc..153cbba 100644 --- a/include/benchmark/benchmark.h +++ b/include/benchmark/benchmark.h
@@ -243,13 +243,20 @@ #define BENCHMARK_INTERNAL_TOSTRING(x) BENCHMARK_INTERNAL_TOSTRING2(x) // clang-format off -#if defined(__GNUC__) && !defined(__NVCC__) || defined(__clang__) +#if (defined(__GNUC__) && !defined(__NVCC__) && !defined(__NVCOMPILER)) || defined(__clang__) #define BENCHMARK_BUILTIN_EXPECT(x, y) __builtin_expect(x, y) #define BENCHMARK_DEPRECATED_MSG(msg) __attribute__((deprecated(msg))) #define BENCHMARK_DISABLE_DEPRECATED_WARNING \ _Pragma("GCC diagnostic push") \ _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") #define BENCHMARK_RESTORE_DEPRECATED_WARNING _Pragma("GCC diagnostic pop") +#elif defined(__NVCOMPILER) +#define BENCHMARK_BUILTIN_EXPECT(x, y) __builtin_expect(x, y) +#define BENCHMARK_DEPRECATED_MSG(msg) __attribute__((deprecated(msg))) +#define BENCHMARK_DISABLE_DEPRECATED_WARNING \ + _Pragma("diagnostic push") \ + _Pragma("diag_suppress deprecated_entity_with_custom_message") +#define BENCHMARK_RESTORE_DEPRECATED_WARNING _Pragma("diagnostic pop") #else #define BENCHMARK_BUILTIN_EXPECT(x, y) x #define BENCHMARK_DEPRECATED_MSG(msg)
diff --git a/src/benchmark.cc b/src/benchmark.cc index 1937eea..1408840 100644 --- a/src/benchmark.cc +++ b/src/benchmark.cc
@@ -196,6 +196,10 @@ #pragma nv_diagnostic push #pragma nv_diag_suppress 1427 #endif +#if defined(__NVCOMPILER) +#pragma diagnostic push +#pragma diag_suppress offset_in_non_POD_nonstandard +#endif // Offset tests to ensure commonly accessed data is on the first cache line. const int cache_line_size = 64; static_assert( @@ -208,6 +212,9 @@ #if defined(__NVCC__) #pragma nv_diagnostic pop #endif +#if defined(__NVCOMPILER) +#pragma diagnostic pop +#endif } void State::PauseTiming() {
diff --git a/src/timers.cc b/src/timers.cc index 89ddbfb..b23feea 100644 --- a/src/timers.cc +++ b/src/timers.cc
@@ -67,6 +67,9 @@ #if defined(__GNUC__) #pragma GCC diagnostic ignored "-Wunused-function" #endif +#if defined(__NVCOMPILER) +#pragma diag_suppress declared_but_not_referenced +#endif namespace { #if defined(BENCHMARK_OS_WINDOWS)
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index cfef13b..212cfd2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt
@@ -46,6 +46,9 @@ macro(compile_benchmark_test name) add_executable(${name} "${name}.cc") target_link_libraries(${name} benchmark::benchmark_main ${CMAKE_THREAD_LIBS_INIT}) + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "NVHPC") + target_compile_options( ${name} PRIVATE --diag_suppress partial_override ) + endif() endmacro(compile_benchmark_test) macro(compile_benchmark_test_with_main name)
diff --git a/test/clobber_memory_assembly_test.cc b/test/clobber_memory_assembly_test.cc index ab26913..54e26cc 100644 --- a/test/clobber_memory_assembly_test.cc +++ b/test/clobber_memory_assembly_test.cc
@@ -3,6 +3,7 @@ #ifdef __clang__ #pragma clang diagnostic ignored "-Wreturn-type" #endif +BENCHMARK_DISABLE_DEPRECATED_WARNING extern "C" {
diff --git a/test/donotoptimize_assembly_test.cc b/test/donotoptimize_assembly_test.cc index 70e780a..dc286f5 100644 --- a/test/donotoptimize_assembly_test.cc +++ b/test/donotoptimize_assembly_test.cc
@@ -3,6 +3,7 @@ #ifdef __clang__ #pragma clang diagnostic ignored "-Wreturn-type" #endif +BENCHMARK_DISABLE_DEPRECATED_WARNING extern "C" {