<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Incorrect code gen related to std::variant"
href="https://bugs.llvm.org/show_bug.cgi?id=50203">50203</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Incorrect code gen related to std::variant
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>CUDA
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>ryan_greenblatt@brown.edu
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>```
#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).</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>