[llvm-bugs] [Bug 50731] New: Structured Bindings Miscompilation(?) on Windows x64.
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Jun 15 19:29:51 PDT 2021
https://bugs.llvm.org/show_bug.cgi?id=50731
Bug ID: 50731
Summary: Structured Bindings Miscompilation(?) on Windows x64.
Product: clang
Version: 12.0
Hardware: PC
OS: Windows NT
Status: NEW
Severity: release blocker
Priority: P
Component: C++17
Assignee: unassignedclangbugs at nondot.org
Reporter: choon-ho.choe at vitrox.com
CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk
Clang 11.0 and Clang 12.0 generates code that causes memory access violation
(attempting to read address 0xffff...) on Windows x64 with -O0 or -O1 for the
following code, https://godbolt.org/z/P6d3Pn1Gh
Note:
- Clang 10.0 doesn't cause this violation.
- Clang 12.0 with -O2 or -O3 doesn't cause this violation.
- Clang 12.0 doesn't cause this violation on Windows x86 regardless of
optimization level.
Same as godbolt link:
```
#include <immintrin.h>
#include <array>
#include <cassert>
#include <cstdint>
#include <vector>
template <class F>
void f(uint8_t const* a_ptr, uint8_t const* b_ptr, uint8_t const* c_ptr,
uint8_t* d_ptr, size_t size, F f) noexcept {
assert(size / 32 * 32 == size);
for (auto x = static_cast<size_t>(0); x < size; x += 32) {
auto a = _mm256_loadu_si256(reinterpret_cast<__m256i const*>(a_ptr + x));
auto b = _mm256_loadu_si256(reinterpret_cast<__m256i const*>(b_ptr + x));
auto c = _mm256_loadu_si256(reinterpret_cast<__m256i const*>(c_ptr + x));
auto d = f({a, b, c});
_mm256_storeu_si256(reinterpret_cast<__m256i*>(d_ptr + x), d);
}
}
int main() {
auto size = 32 * 32;
auto a = std::vector<uint8_t>(size, 1);
auto b = std::vector<uint8_t>(size, 2);
auto c = std::vector<uint8_t>(size, 4);
auto d = std::vector<uint8_t>(size);
f(a.data(), b.data(), c.data(), d.data(), size, [](std::array<__m256i, 3> in)
noexcept {
auto [in0, in1, in2] = in;
return _mm256_add_epi8(_mm256_add_epi8(in0, in1), in2);
});
return 0;
}
```
Changing,
```auto [in0, in1, in2] = in;```
to,
```
auto in0 = in[0];
auto in1 = in[1];
auto in2 = in[2];
```
seems to fix the problem for this example.
Also, Visual Studio (16.10.2) STL implementation of ```std::array```,
```std::get```, ```std::tuple_size``` seems to be implemented correctly.
--
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/20210616/19be1ff0/attachment.html>
More information about the llvm-bugs
mailing list