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

[BUG]: UB in thrust tests caused by out-of range conversion from FP types to integers. #3021

Closed
1 task done
Artem-B opened this issue Dec 3, 2024 · 0 comments · Fixed by #3022
Closed
1 task done
Labels
bug Something isn't working right.

Comments

@Artem-B
Copy link
Contributor

Artem-B commented Dec 3, 2024

Is this a duplicate?

Type of Bug

Something else

Component

Thrust

Describe the bug

random_integers<fp-type>() may generate values not representable as an integer type, which results in undefined behavior when we attempt to cast them to integer type later on.

E.g.:

thrust::host_vector<T> h_input = unittest::random_integers<T>(n);
for (size_t i = 0; i < n; i++)
{
h_input[i] = ((size_t) h_input[i]) % output_size;

UBsan reported an error on (size_t)h_input[i]:

third_party/gpus/cccl/v2_6_0/thrust/testing/for_each.cu.cc:205:28: runtime error: 2.35321e+38 is outside the range of representable values of type 'unsigned long'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior third_party/gpus/cccl/v2_6_0/thrust/testing/for_each.cu.cc:205:28

How to Reproduce

Stock thrust tests with clang, UBsan, and disabled optimizations.

Expected behavior

Avoiding undefined behavior is a good idea in general.

Reproduction link

No response

Operating System

No response

nvidia-smi output

No response

NVCC version

No response

@Artem-B Artem-B added the bug Something isn't working right. label Dec 3, 2024
@github-project-automation github-project-automation bot moved this to Todo in CCCL Dec 3, 2024
@cccl-authenticator-app cccl-authenticator-app bot moved this from Todo to In Review in CCCL Dec 3, 2024
@github-project-automation github-project-automation bot moved this from In Review to Done in CCCL Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working right.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant