<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=http://email.email.llvm.org/c/eJylVd9v4zYM_mucF8KBLSV28pCH9HIdiuE64G7DHgvZlh2tihRIstvsrx-puM2P5bo7DBAciaQ-kh9JpbLNYfVV7p1t-lq6hK-TbJNk66TIxnU8Mq5MrftGQsI_-eCU6abbhH--rW6U_UirVXWujt-nJxEQtuqDfHpK2AKXscpoZWTClrhgsKqB1tpKOFTWW_pZQ9jtE_YJ_Na6AIK2ygSoTrKa7ibl3dENwE7u6v0BEcabCSviNa_-lrZFuTj6S_j7FbREs7uEb66s-Eeo1QVq9UOo1X-i1heo9RVqUm5-jlSiEZBR5BWVt1ikzesVh_EWxTS_WyTzzVnEI-dAWWVn8ve6jZlEHxG_vkzZydA7M4K_IjhBEdqMfS9LinAnlEF02grXRZLGDqEmQdFwlcJgtQhKy_fO4f9WHTk4KVQLVKM3tk45kEuM8zPk-L0HEawiPXmd3-XEEDnna6TkWK8REGCPkxTaWBpW4VAhbo7b2zW9msn4HSfXf39yZ1BrYToI0odpDelvDNLWC6MCdhEyi01m3eFMlh4laXCifk6tU50yHtKO2g8XTBN2L6a2DzAbfcQK5fMiYwt-PPy5_vr48PgL5fwlon0bwemJgd7L1LZpbxQJhUZ5kw5C9_LEDL4aGWSvMzETTYGliCUek0AMho7W5TkTAH-c40HEgxfhoXZSBJRUBxAGhNa2xgJbA5YKWsaWLMlF2GI_BMwaWid2kvRtb-poiyZvlS9vRVkWGUEcbU5x5vyD4v2-VR5wvThrOmokDMBJbCcJxsKRHqhU8KgQOFYWY2qd3QHiUNRFNoW11jGPN0nM2A7SvTgVgjSUtSVcaEQQ01vu5SuVmhiK4AJ-_fJt_Qit0F7C3nrkdJDU-sI08ICxKPMMD8gDSr1EF7teB7WnYVI7pfFtsAY7ki0vvK21t2ROnPFiPp8BwcXDbFHAy1bV25i6IENRUYPh_4Z1TtYBxja8QExmGZYJ4xMm7bRqMEcUDSoIfaj6Z0En2XfSKD9pVrxZ8qWYiD7gxK-a4dA_22HSO73ahrCPA8TucXUqbPtqimTjQevh7SfFUfsLQ8Gj8r6nBO_nbFnkk-1qVs54VvGCM9Ys5YKXvBBNWzTFciGZKOcTLSqp_QqfA5xuI18gQtCkzzeT_x-BWrGMsSzPeM6QWz7lRcuXrGkW-ZKVkufEBA6QnhLO1Lpu4lYRsuo7j0qtfPAnpfBedUbKGDBGGFTQcrXDF4LG97oq0OCgBWpYHD281gD1nvSTGOUqhvgPyot9Uw>52961</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            msan: incorrect origin due to unaligned writes
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    Reproducer:
```
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

__attribute__((noinline)) void foobar(char* tmp, short a, int b, short c) {
  memcpy(tmp, &a, sizeof(a));
  tmp += sizeof(a);
  memcpy(tmp, &b, sizeof(b));
  tmp += sizeof(b);
  memcpy(tmp, &c, sizeof(c));
}

__attribute__((noinline)) char barfoo(short a, int b, int x) {
  char tmp[8];
  short c = 0;
  foobar(tmp, a, b, c);
  return tmp[x] == 42;
}

int main(int argc, char** argv) {
  volatile short a;
  volatile int b;
  if (barfoo(a, b, argc > 1 ? atoi(argv[1]) : 0))
    printf("bingo!");
}
```

produces:
```
$ clang test.c -O2 -fsanitize=memory -fsanitize-memory-track-origins -g && ./a.out 4
==1560283==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x4a4ad6 in main test.c:23:7

  Uninitialized value was created by an allocation of 'tmp' in the stack frame of function 'barfoo'
    #0 0x4a4760 in barfoo test.c:13
```

This is wrong, there are no uninit bits that come from `tmp`. All of `tmp` was overwritten by other data.

This is extracted from a KMSAN false positive (and I think I've seen multiple similar ones).

Also see #36554 and #36486 which are also about incorrect origins.

@ramosian-glider @vitalybuka @eugenis
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVVU1v4zYQ_TXyZSBBoizZPujgrDdFUGwK7HbRY0BJlMyGJg2SUuL--s7QSvxRb3YLELI4Q72ZefOGrk17qL6KvTXt0Agb5eso3UTpOirTaR23LJe6UUMrIMo_OW-l7pNtlH--7W6l-cirZH3uDs-nJ-4Rth68eHqK2BKXNlIrqUXEVrhgNLKFzpiaW3Q2W_pZg9_tI_YJ3NZYD5xepfZQn2wNfRst7o5hAHZi1-wPiDB9GbEyfObkP8J0aOfHeFH-_gmexGN3Ub65OpV_hFpfoNa_hFr_FLW5QG2uUKPF5v-RSjQCMoq8ovMWi_TyesVh-IpyKu6WUbE5y3jiHKiq9Mz-3repkhAj4DeXJVvhB6sn8FcEJyhCm7MfVUkZ7rjUiE6v3PaBpEkhJBI0jVcljEZxL5V4V07-X9eRg5NDdkA9emPrVAOFxDw_Q4bPe-DeSPJT1OIuI4YoeL5GSo79mgAB9jhJvgutYTUOFeJm-Hq7p1czGZ7T5LofT-4cGsV1D144nzQQ_8Eg7hzX0qOKkFkUmbGHM1t8tMTe8uY5Nlb2UjuIe5IfLkgids8TM3iYTzFCh7KiTNkyP27-Wn99fHj8jWr-EtC-TeB0xcDgRGy6eNCSjFyhvY1HrgZxYgZvjRTS1zmf87bEVoQWT0UgBsNA68U5EwDfz_Eg4MELd9BYwT1a6gNwDVwp02CDjQZDDV0ESS4ohN-iHjxWDZ3lO0H-btBNOItH3jq_uJXlokwJ4njmlGeWf9C8P7fSAa4Xa3RPQsIErEA5CdAGjvRALb1DB8exMphTZ80OEIeyLtME1kqFOt4soWIzCvtipfdCU9WGcKHlnie3wotXajUxFMA5_P7l2_oROq6cgL1xyOkoSPpct_CAuUj9DA_IA1qdwBC7QXm5p2GSO6nwbjAaFclWF9HWyhk6TpzlZVHMgeDCZr4s4WUrm20ondNBXpPA8H_DWCsaD5MMLxCjeYptwvy4jnslW6wRTaP0XB3q4ZnTTgy90NLN2ipvV_mKz7z0SlQ7FDsp8ToAtKgZT9yjinqNlBCNws0Gq6qt9_swaOweVy_9dqgTbApulBrffmIcyb8REbfSuYGIuC_Yqsxm2ypdpEVZpDxdpvNVvWK8Y1lWNvOy40tRpPVM8VooV-G1gbeAFi8QIOhGKDYzWbGUsTRL84whg3mSl12-Ym27zFZsIfKM6sUxUQnlkRjbz2wVUqqH3qFTSefdycmdoxpFCIf4fPB4GVbteBiezTgLoauQ-r8woWe_">