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

    <tr>
        <th>Summary</th>
        <td>
            False negatives in MemorySanitizer
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          shao-hua-li
      </td>
    </tr>
</table>

<pre>
    MemorySanitizer missed some uninitialized variable reports.

a.c
```c
struct a {
  int b;
  int c

d(struct a *g) {
  struct a f = *g;
  if (f.b)
    printf("f.b\n");
  if (f.c)
    printf("f.c\n");
}
main() {
  struct a e;
  d(&e);
}
```

I tested with clang trunk. You can find that -O1,-O2,-O3 report nothing and have divergent outputs.
```
$ clang -fsanitize=memory -w -O0 a.c; ./a.out
==1533603==WARNING: MemorySanitizer: use-of-uninitialized-value
...
$
$ clang -fsanitize=memory -w -O1 a.c; ./a.out
f.b
$
$ clang -fsanitize=memory -w -O2 a.c; ./a.out
f.b
f.c
$
$ clang -fsanitize=memory -w -O3 a.c; ./a.out
f.b
f.c
$
$ clang -fsanitize=memory -w -Os a.c; ./a.out
==1533603==WARNING: MemorySanitizer: use-of-uninitialized-value
...
$
``` 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzFVE1vnDAQ_TXmMgIZe3HgwGGTVaocmkjtoerRGANuvbDC9kbpr-8Au5vNJv3IoapkgefrzZPn2dVQP5Uf9XYYnz7L3njzQ4-wNc7pGtyw1RB6M7mlxUgNezkaWVkNo94No3cJoRtC18tXJupgCrqsg-38GJQHCeTqevEAmN5DRfgL-1h-tYFlVxOWPxezdUtYcQ5yijVA-GbJOINEL8ubpMKqow9gN2KrBgOEsSmW3fS4m1JeV6rfVKo3KpH5stlK08-Jb9PVZ73qOU_oN3FOJ3l-znfgtfM4jUfjO1BW9i0gcv89ga9DACV7aExfg--kh_ghJewmfmDzlx8GB_3gO4N1EvM6uddQm70eW41TGILfhefRXjBgq0PHuHEHweDRb2cFQfyI_ShMQuDXkBB2KxOEO5TyDa4041xQvhhf1p_u7-4_EL6GCw1OruB0PDTxCwXGe2mDXgCTJDmR-mt26S_YTVJ4Nxj7E1hzuhLvQOX_BNX9x7EcNQRRXfK64IWMvPFWl7fSOg29bqVH_Tl8BS47RmG0Zef9zmFvZI6rRdmHKlHDFg1r98dfvBuHb1p5NPEBC9rhJluJlEddWcs65flK5JnICyEqRWlaiFUuFFUiVU1kZaWtK0l2TbJNZEpGGaOcFSmjxapIhMoFp1kl2FWtVZOTFdV4yW0yNU6GsY3GcuZQhdZh0BqHV-gUlM6Zttf6iC-D74axdJ0c4i7I2JpoplzOfH8CLGqZtQ">