<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 - Structured Bindings Miscompilation(?) on Windows x64."
   href="https://bugs.llvm.org/show_bug.cgi?id=50731">50731</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Structured Bindings Miscompilation(?) on Windows x64.
          </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>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, <a href="https://godbolt.org/z/P6d3Pn1Gh">https://godbolt.org/z/P6d3Pn1Gh</a>

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.</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>