Undefined behaviour on single element assignment
- Dominant language
- C++
- Stars
- 2.5k
- Forks
- 486
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 295
Description
Here's a minimal example that leads to undefined behaviour sanitizer failures when compiled with all configurations that I checked:
- CUDA toolkit 12.1, thrust 2.0.1, `nvcc thrustIssue.cpp -Xcompiler -fsanitize=undefined`
- CUDA toolkit 12.1, thrust 2.1, `nvcc thrustIssue.cpp -Xcompiler -fsanitize=undefined`
- Clang-16 targeting x86, thrust 2.0.1
```cpp
#define THRUST_DEVICE_SYSTEM THRUST_DEVICE_SYSTEM_CPP
#include
#include
#include
int main() {
thrust::device_vector vec(3);
vec[0] = 1.0;
vec[1] = 0.5;
vec[2] = 1.0;
thrust::host_vector host_vec = vec;
for (size_t i = 0; i < host_vec.size(); ++i) {
std::cout << "host_vec[" << i << "] = " << host_vec[i] << std::endl;
}
return 0;
}
```
Clang's ubsan returns this error at runtime when the code hits `vec[0] = 1.0`:
```traceback
external/thrust/thrust/detail/reference.h:348:44: runtime error: reference binding to null pointer of type 'thrust::execution_policy'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior external/thrust/thrust/detail/reference.h:348:44
```
Contributor guide
Assessment
This issue has not been assessed yet.