[llvm-bugs] [Bug 50962] New: Clang 11.0 and 12.0 errorneous codegen on Windows x64 when using Visual Studio 2019 STL.

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jul 1 18:53:48 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=50962

            Bug ID: 50962
           Summary: Clang 11.0 and 12.0 errorneous codegen on Windows x64
                    when using Visual Studio 2019 STL.
           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

Rephrased title to better match the problem, originally from [Structured
Bindings Miscompilation(?) on Windows
x64](https://bugs.llvm.org/show_bug.cgi?id=50731). 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](https://developercommunity.visualstudio.com/t/Clang-110-and-120-generates-erroneous/1464106).

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});
}
```

-- 
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/20210702/2a3c2827/attachment.html>


More information about the llvm-bugs mailing list