<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 - Clang 11.0 and 12.0 errorneous codegen on Windows x64 when using Visual Studio 2019 STL."
href="https://bugs.llvm.org/show_bug.cgi?id=50962">50962</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Clang 11.0 and 12.0 errorneous codegen on Windows x64 when using Visual Studio 2019 STL.
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>12.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>release blocker
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++17
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>choon-ho.choe@vitrox.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>Rephrased title to better match the problem, originally from [Structured
Bindings Miscompilation(?) on Windows
x64](<a class="bz_bug_link
bz_status_NEW "
title="NEW - Structured Bindings Miscompilation(?) on Windows x64."
href="show_bug.cgi?id=50731">https://bugs.llvm.org/show_bug.cgi?id=50731</a>). As the problem is not
limited to structured bindings but operator[] and std::get.
Microsoft also doesn't seem to find anything wrong with their STL, for more
info, see [Clang 11.0 and 12.0 generates erroneous code when using
STL](<a href="https://developercommunity.visualstudio.com/t/Clang-110-and-120-generates-erroneous/1464106">https://developercommunity.visualstudio.com/t/Clang-110-and-120-generates-erroneous/1464106</a>).
The code in question,
```
#include <immintrin.h>
#include <array>
namespace my {
template <class T, size_t N>
struct array {
T data_[N];
};
template <size_t I, class T, size_t N>
constexpr typename std::enable_if<(I < N), T&>::type get(
my::array<T, N>& a) noexcept {
return a.data_[I];
}
template <size_t I, class T, size_t N>
constexpr typename std::enable_if<(I < N), T const&>::type get(
my::array<T, N> const& a) noexcept {
return a.data_[I];
}
template <size_t I, class T, size_t N>
constexpr typename std::enable_if<(I < N), T&&>::type get(
my::array<T, N>&& a) noexcept {
return std::move(a.data_[I]);
}
} // namespace my
namespace std {
template <class T, size_t N>
struct tuple_size<my::array<T, N>> {
static constexpr auto value = N;
};
template <size_t I, class T, size_t N>
struct tuple_element<I, my::array<T, N>> {
static_assert(I < N);
using type = T;
};
} // namespace std
#if 0
using std::array; // Results in memory violation in x64 Debug.
#else
using my::array; // Fine.
#endif
int main() {
auto lambda = [](std::array<__m256i, 2> in) noexcept {
auto [in0, in1] = in;
return _mm256_add_epi8(in0, in1);
};
const __m256i a = _mm256_set1_epi8(1);
const __m256i b = _mm256_set1_epi8(2);
(void)lambda({a, b});
}
```</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>