<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/57712>57712</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            libc++15: Incorrect results from `vector::insert` in ASAN build
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          vogelsgesang
      </td>
    </tr>
</table>

<pre>
    after upgrading to clang-15 and libc++15, `vector::insert` inserts incorrect values when using `clang++ -O2 -fsanitize=address -march=x86-64 -std=c++20` to compile

```
#include <iostream>
#include <vector>
using namespace std;

int main(int /*argc*/, char* /*argv*/[]) {
   uint8_t a[] = {
      1,2,3,4,5,6,7,8,9,
      10,11,12,13,14,15,16,17,18,19,
      20,21,22,23,24,25,26,27,28,29,
      30,31,32,33,34,35,36,37,38,39,
      40,41
   };
   std::vector<uint8_t> vec;
   constexpr int sz = sizeof(a) / sizeof(a[0]);
   vec.insert(vec.end(), a, a + sz);
   for (int i = 0; i != sz; ++i) {
      cerr << static_cast<int>(vec[i]) << ' ';
   }
   cerr << endl;
}
```

This program produces

```
33 34 35 36 37 38 39 40 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 190 190 190 190 190 190 190 190 41
```

on my machine, which is clearly incorrect.
Removing either `-O2` or `-fsanitize=address` or both makes the problem disappear.
`-march=x86-64 -std=c++20` are unnecessary for the repro, I just added them for completeness.

I am still struggling to create a repro on godbolt, will update this issue as soon as I have working repro instructions
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyNVVtvozoQ_jXkZZQI21wfeEibrdSXc6Q9531lwAHvGhzZJt321-8MkDSNqmoRA4xnvvHcGNe2fa3kMSgH06lzstVjB8FCY-TYbVkKcmzB6LqJ-APeLI34I0RZfFZNsC4Se7z16JULuAjLl8d3Y51DFThLMykPL70aYfJkHP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