NVIDIA / NVIDIA/cccl

[BUG]: cuda::std::allocator_traits fails to compile with clang and libc++

Open
#2,721 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
2.5k
Forks
486
Avg merge
2d 6h
Merged PRs (30d)
295

Description

### Is this a duplicate?

- [x] I confirmed there appear to be no [duplicate issues](https://github.com/NVIDIA/cccl/issues) for this bug and that I agree to the [Code of Conduct](CODE_OF_CONDUCT.md)

### Type of Bug

Compile-time Error

### Component

libcu++

### Describe the bug

Attempt to use `cuda::std::allocator_traits::allocate(alloc, 1);` fails to compile.

### How to Reproduce

third_party/gpus/cccl/v2_6_0/libcudacxx/test/libcudacxx/std/utilities/memory/allocator.traits/allocator.traits.members/destroy.pass.cpp fails if compiled w/ clang and libc++

Reduced example: https://godbolt.org/z/Yz3ajozr6

```
In file included from /opt/compiler-explorer/cuda/12.6.1//include/cuda/std/__memory_:26:
In file included from /opt/compiler-explorer/cuda/12.6.1//include/cuda/std/detail/libcxx/include/memory:26:
In file included from /opt/compiler-explorer/cuda/12.6.1//include/cuda/std/__memory/allocate_at_least.h:25:
In file included from /opt/compiler-explorer/cuda/12.6.1//include/cuda/std/__memory/allocator_traits.h:25:
In file included from /opt/compiler-explorer/cuda/12.6.1//include/cuda/std/__memory/construct_at.h:47:
In file included from /opt/compiler-explorer/clang-trunk-20241106/bin/../include/c++/v1/memory:940:
/opt/compiler-explorer/clang-trunk-20241106/bin/../include/c++/v1/__memory/allocator.h:99:7: error: reference to __host__ function '__throw_bad_array_new_length' in __host__ __device__ function
99 | __throw_bad_array_new_length();
| ^
/opt/compiler-explorer/cuda/12.6.1//include/cuda/std/__memory/allocator.h:135:38: note: called by 'allocate'
135 | return ::std::allocator<_Tp>{}.allocate(__n);
| ^
:13:38: note: called by 'allocate'
13 | return cuda::std::allocator().allocate(n);
| ^
/opt/compiler-explorer/cuda/12.6.1//include/cuda/std/__memory/allocator_traits.h:375:16: note: called by 'allocate'
375 | return __a.allocate(__n);
| ^
:81:65: note: called by 'test'
81 | CountDestructor* pool = cuda::std::allocator_traits::allocate(alloc, 1);
| ^
/opt/compiler-explorer/clang-trunk-20241106/bin/../include/c++/v1/new:176:52: note: '__throw_bad_array_new_length' declared here
176 | [[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_bad_array_new_length() {
| ^

```

### Expected behavior

Allocator should work regardless of the version of the *host* standard c++ library.

### Reproduction link

https://godbolt.org/z/Yz3ajozr6

### Operating System

_No response_

### nvidia-smi output

_No response_

### NVCC version

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.