- Notifications
You must be signed in to change notification settings - Fork 15.3k
Closed
Labels
libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.openmp
Description
There seems to be a header inclusion bug in
| #include <algorithm> |
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.30202Metadata
Metadata
Assignees
Labels
libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.openmp