Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warnings with nvc++ as the compiler #3849

Closed
crtrott opened this issue May 23, 2022 · 3 comments · Fixed by #4103 · May be fixed by #4014
Closed

Warnings with nvc++ as the compiler #3849

crtrott opened this issue May 23, 2022 · 3 comments · Fixed by #4103 · May be fixed by #4014

Comments

@crtrott
Copy link

crtrott commented May 23, 2022

Describe the bug

The following warnings were observed when building googletest:
[ 12%] Building CXX object googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o
"/ascldap/users/crtrott/Software/googletest/googletest/src/gtest-internal-inl.h", line 636: warning: unknown attribute "optimize"
        GTEST_NO_INLINE_ GTEST_NO_TAIL_CALL_;
                         ^

"/ascldap/users/crtrott/Software/googletest/googletest/src/gtest.cc", line 6252: warning: unknown attribute "optimize"
  GTEST_NO_INLINE_ GTEST_NO_TAIL_CALL_ std::string
                   ^

[ 25%] Linking CXX static library ../lib/libgtest.a
[ 25%] Built target gtest
Scanning dependencies of target gmock
Scanning dependencies of target gtest_main
[ 37%] Building CXX object googletest/CMakeFiles/gtest_main.dir/src/gtest_main.cc.o
[ 50%] Building CXX object googlemock/CMakeFiles/gmock.dir/src/gmock-all.cc.o
"/ascldap/users/crtrott/Software/googletest/googlemock/src/gmock-spec-builders.cc", line 674: warning: variable "l" was declared but never referenced
    internal::MutexLock l(&internal::g_gmock_mutex);

Steps to reproduce the bug

cmake -DCMAKE_CXX_STANDARD=17 -DCMAKE_CXX_COMPILER=nvc++ ../
-- The C compiler identification is GNU 4.8.5
-- The CXX compiler identification is NVHPC 22.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /ascldap/users/projects/x86-64/nvidia/hpc_sdk/Linux_x86_64/22.3/compilers/bin/nvc++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Python: /usr/bin/python3.6 (found version "3.6.8") found components: Interpreter 
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Configuring done
-- Generating done
-- Build files have been written to: /ascldap/users/crtrott/Software/googletest/build

Does the bug persist in the most recent commit?

This was tested with the latest commit 8d51dc5

What operating system and version are you using?

RedHat 7.x

Linux kokkos-dev-2 3.10.0-1160.36.2.el7.x86_64 #1 SMP Thu Jul 8 02:53:40 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

What compiler and version are you using?

nvc++ --version

nvc++ 22.3-0 64-bit target on x86-64 Linux -tp skylake-avx512 
NVIDIA Compilers and Tools
Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES.  All rights reserved.

What build system are you using?

cmake version 3.21.1

Additional context

The first issue can be resolved by checking for __NVCOMPILER in

#define GTEST_NO_TAIL_CALL_ __attribute__((disable_tail_calls))
#endif
#elif __GNUC__
#define GTEST_NO_TAIL_CALL_ \
__attribute__((optimize("no-optimize-sibling-calls")))
#else
#define GTEST_NO_TAIL_CALL_
#endif

I.e. the rootcause seems to be that __NVCOMPILER does define GNUC, but its not really GCC. So just making sure that the GCC variant is only used when __NVCOMPILER is not defined fixes that warning.

I would issue a PR, but not sure its worth the effort to get the corporate contributor agreement signed ..

The second warning, is likely on nvc++ itself (i mean the lock is clearly used and serves a function), however one could fix it with adding a (void) l in the code.

@crtrott crtrott added the bug label May 23, 2022
@crtrott
Copy link
Author

crtrott commented May 23, 2022

@brycelelbach @mhoemmen not sure if NVIDIA has a contributor agreement, and you guys could issue a PR?

@dinord
Copy link
Collaborator

dinord commented May 23, 2022

We'd be willing to accept a pull request to fix this issue. We do not plan to implement a fix ourselves, since we do not officially support nvc++.

@mhoemmen
Copy link

@crtrott I'm new to NVIDIA, so I'm asking about this.

mhoemmen added a commit to mhoemmen/googletest that referenced this issue Sep 19, 2022
When I build the current stable branch (760060059fb746018a9849234e02dc9bf003861b) of the reference mdspan implementation (https://github.com/kokkos/mdspan) with nvc++ (either 22.7 or a pre-release version), I get a couple build warnings like the following.
```
".../tests/googletest-src/googletest/src/gtest-internal-inl.h", line 636: warning: unknown attribute "optimize" [unrecognized_attribute]
        GTEST_NO_INLINE_ GTEST_NO_TAIL_CALL_;
                         ^
```
Issue google#3849 explains: GTest is using `#elif __GNUC__` to protect use of `__attribute__((optimize("no-optimize-sibling-calls")))`.  Many compilers that are not GCC define `__GNUC__` to express some degree of compatibility with GCC extensions.  This includes nvc++.  nvc++ does not understand this attribute, so it emits a warning.  My fix just disables use of that attribute if `__NVCOMPILER` is defined.

I've tested this fix with a pre-release (post-22.7) version of nvc++.  It prevents the warning, and the reference mdspan implementation's tests build and run correctly.

Fixes google#3849.
kunitoki pushed a commit to kunitoki/googletest that referenced this issue Nov 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants