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

[OpenMP][libc++] including <iostream> when targeting amdgpu caues error: use of undeclared identifier '__not_found' #67938

Closed
tom91136 opened this issue Oct 1, 2023 · 2 comments · Fixed by #67981
Assignees
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. openmp

Comments

@tom91136
Copy link

tom91136 commented Oct 1, 2023

There seems to be a header inclusion bug in


That header file doesn't seems to have an actual need for <algorithm> but its inclusion cases failures down the line.
For example:

#include <iostream>
int main() {
#pragma omp target
  {}
  return 0;
}

Compiling the program causes a header related error only when targeting amdgpu:

// clang++ -std=c++17 -stdlib=libc++ -fexperimental-library -fopenmp --offload-arch=gfx1036 mp_sample.cpp -O2 # -Xclang -ast-dump
// In file included from mp_sample.cpp:1:
// In file included from /home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/iostream:43:
// In file included from /home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/ios:222:
// In file included from /home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/__locale:16:
// In file included from /home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/__mutex/once_flag.h:21:
// In file included from /home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/tuple:268:
// In file included from /home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/compare:145:
// In file included from /home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/__compare/compare_partial_order_fallback.h:13:
// In file included from /home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/__compare/partial_order.h:14:
// In file included from /home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/__compare/weak_order.h:14:
// In file included from /home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/__compare/strong_order.h:20:
// In file included from /home/tom/software/llvm-ompt/96adadf8f722/lib/clang/18/include/openmp_wrappers/cmath:17:
// In file included from /home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/cmath:319:
// In file included from /home/tom/software/llvm-ompt/96adadf8f722/lib/clang/18/include/openmp_wrappers/math.h:55:
// In file included from /home/tom/software/llvm-ompt/96adadf8f722/lib/clang/18/include/__clang_hip_math.h:18:
// In file included from /home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/algorithm:1977:
// In file included from /home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/iterator:683:
// In file included from /home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/__iterator/common_iterator.h:31:
/// home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/variant:402:21: error: use of undeclared identifier '__not_found'
//  402 |   size_t __result = __not_found;
//      |                     ^
/// home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/variant:405:23: error: use of undeclared identifier '__not_found'
//  405 |       if (__result != __not_found) {
//      |                       ^
/// home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/variant:406:16: error: use of undeclared identifier '__ambiguous'
//  406 |         return __ambiguous;
//      |                ^
/// home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/variant:419:45: error: use of undeclared identifier '__not_found'
//  419 | struct __find_unambiguous_index_sfinae_impl<__not_found> {};
//      |                                             ^
/// home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/variant:422:45: error: use of undeclared identifier '__ambiguous'
//  422 | struct __find_unambiguous_index_sfinae_impl<__ambiguous> {};
//      |                                             ^
//  ... goes on...

Targeting nvptx works as expected.
Manually removing #include <algorithm> in __clang_hip_math.h works, and so does adding #include <algorithm> before #include <iostream> in the reproducer program.

The actual cause seems to be an ordering issue, as __not_found is defined in <tuple> but that header's include chain eventually leads to __iterator/common_iterator.h which depends on <variant> in OpenMP target's amdgpu case, and <variant> expects some of the symbols from <tuple> (which isn't defined just yet).

In case it matters:

> clang++
clang version 18.0.0 (git@github.com:tom91136/llvm-project.git 96adadf8f7227f6543537056f27f98cb18bbe8ce)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/tom/software/llvm-ompt/96adadf8f722/bin
Found candidate GCC installation: /usr/lib/gcc/i686-redhat-linux/12
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/12
Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/12
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
Found HIP installation: /opt/rocm, version 5.5.30202
@github-actions github-actions bot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Oct 1, 2023
@tom91136 tom91136 changed the title [OpenMP][libc++] including <iostream> when targeting amdgpu cases error: use of undeclared identifier '__not_found' [OpenMP][libc++] including <iostream> when targeting amdgpu caues error: use of undeclared identifier '__not_found' Oct 1, 2023
@jdoerfert
Copy link
Member

@jhuber6 We should get rid of these headers ... for now, can you check out the proposed solutions?

@llvmbot
Copy link
Collaborator

llvmbot commented Oct 2, 2023

@llvm/issue-subscribers-openmp

There seems to be a header inclusion bug in https://github.com/llvm/llvm-project/blob/a7517e12caab0750d3dfd7c0c6faec9acc7e5a2b/clang/lib/Headers/__clang_hip_math.h#L18 That header file doesn't seems to have an actual need for `<algorithm>` but its inclusion cases failures down the line. For example: ``` #include <iostream> int main() { #pragma omp target {} return 0; } ``` Compiling the program causes a header related error only when targeting amdgpu: ``` // clang++ -std=c++17 -stdlib=libc++ -fexperimental-library -fopenmp --offload-arch=gfx1036 mp_sample.cpp -O2 # -Xclang -ast-dump // In file included from mp_sample.cpp:1: // In file included from /home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/iostream:43: // In file included from /home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/ios:222: // In file included from /home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/__locale:16: // In file included from /home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/__mutex/once_flag.h:21: // In file included from /home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/tuple:268: // In file included from /home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/compare:145: // In file included from /home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/__compare/compare_partial_order_fallback.h:13: // In file included from /home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/__compare/partial_order.h:14: // In file included from /home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/__compare/weak_order.h:14: // In file included from /home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/__compare/strong_order.h:20: // In file included from /home/tom/software/llvm-ompt/96adadf8f722/lib/clang/18/include/openmp_wrappers/cmath:17: // In file included from /home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/cmath:319: // In file included from /home/tom/software/llvm-ompt/96adadf8f722/lib/clang/18/include/openmp_wrappers/math.h:55: // In file included from /home/tom/software/llvm-ompt/96adadf8f722/lib/clang/18/include/__clang_hip_math.h:18: // In file included from /home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/algorithm:1977: // In file included from /home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/iterator:683: // In file included from /home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/__iterator/common_iterator.h:31: /// home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/variant:402:21: error: use of undeclared identifier '__not_found' // 402 | size_t __result = __not_found; // | ^ /// home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/variant:405:23: error: use of undeclared identifier '__not_found' // 405 | if (__result != __not_found) { // | ^ /// home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/variant:406:16: error: use of undeclared identifier '__ambiguous' // 406 | return __ambiguous; // | ^ /// home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/variant:419:45: error: use of undeclared identifier '__not_found' // 419 | struct __find_unambiguous_index_sfinae_impl<__not_found> {}; // | ^ /// home/tom/software/llvm-ompt/96adadf8f722/bin/../include/c++/v1/variant:422:45: error: use of undeclared identifier '__ambiguous' // 422 | struct __find_unambiguous_index_sfinae_impl<__ambiguous> {}; // | ^ // ... goes on... ``` Targeting nvptx works as expected. Manually removing `#include <algorithm>` in `__clang_hip_math.h` works, and so does adding `#include <algorithm>` before `#include <iostream>` in the reproducer program.

The actual cause seems to be an ordering issue, as __not_found is defined in &lt;tuple&gt; but that header's include chain eventually leads to __iterator/common_iterator.h which depends on &lt;variant&gt; in OpenMP target's amdgpu case, and &lt;variant&gt; expects some of the symbols from &lt;tuple&gt; (which isn't defined just yet).

In case it matters:

&gt; clang++
clang version 18.0.0 (git@<!-- -->github.com:tom91136/llvm-project.git 96adadf8f7227f6543537056f27f98cb18bbe8ce)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/tom/software/llvm-ompt/96adadf8f722/bin
Found candidate GCC installation: /usr/lib/gcc/i686-redhat-linux/12
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/12
Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/12
Candidate multilib: .;@<!-- -->m64
Candidate multilib: 32;@<!-- -->m32
Selected multilib: .;@<!-- -->m64
Found HIP installation: /opt/rocm, version 5.5.30202

@jhuber6 jhuber6 self-assigned this Oct 2, 2023
jhuber6 added a commit to jhuber6/llvm-project that referenced this issue Oct 2, 2023
Summary:
The `algorithm` header included here sometimes caused issues when using
`libc++` over `libstdc++`. This was primarily because  of the order they
were included in. This patch just gets rid of this dependency as it was
only used for min and max which are trivial to reimplement.

Fixes: llvm#67938
jhuber6 added a commit that referenced this issue Oct 2, 2023
…67981)

Summary:
The `algorithm` header included here sometimes caused issues when using
`libc++` over `libstdc++`. This was primarily because  of the order they
were included in. This patch just gets rid of this dependency as it was
only used for min and max which are trivial to reimplement.

Fixes: #67938
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. openmp
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants