[llvm-bugs] [Bug 50203] New: Incorrect code gen related to std::variant
via llvm-bugs
llvm-bugs at lists.llvm.org
Sun May 2 18:21:35 PDT 2021
https://bugs.llvm.org/show_bug.cgi?id=50203
Bug ID: 50203
Summary: Incorrect code gen related to std::variant
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: CUDA
Assignee: unassignedclangbugs at nondot.org
Reporter: ryan_greenblatt at brown.edu
CC: llvm-bugs at lists.llvm.org
```
#include <thrust/execution_policy.h>
#include <thrust/for_each.h>
#include <thrust/iterator/counting_iterator.h>
#include <variant>
struct Items {
bool needed;
std::array<unsigned, 2> also_needed;
};
struct Value {
std::variant<unsigned, Items> item;
template <typename F> constexpr void get_first(F &&f) {
return f(*std::get_if<0>(&item));
}
};
constexpr Value get_variant() { return {.item = 0u}; }
int main() {
auto it = thrust::make_counting_iterator(0u);
thrust::for_each(thrust::device, it, it + 1, [](auto) {
get_variant().get_first(
[](const auto &v) { printf("should be zero: %u\n", v); });
});
}
```
When built with `clang++ -O0 --cuda-gpu-arch=sm_75 --cuda-path=/opt/cuda
-std=c++17 -pthread -lcudart_static -ldl -lrt -L/opt/cuda/lib64` (modify path
as needed), this program prints out (seemingly) random values instead of always
printing zero.
This only happens when building with O0.
I tried reducing the test case further, but I was unable to do so (launching
the kernel without using thrust seems to remove the issue).
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210503/d67bf616/attachment.html>
More information about the llvm-bugs
mailing list