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

    <tr>
        <th>Summary</th>
        <td>
            [msan] Runtime false positives with iostream, msan, and -O0
        </td>
    </tr>

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

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

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

<pre>
    Running clang version 19.1.7 obtained from Arch Linux repositories, with libc++ 19.1.7-1 and libstdc++ 14.2.1, although this also reproduces on Compiler Explorer with newer versions of clang.

I was exploring the conditions in which MSAN / ASAN / hardened builds detect buffer overruns (initially exploring with std::array which stores its data inline), and ran into the following issues with printing argc:

```c++
// $ clang++ -fsanitize=memory
#include <iostream>
#include <vector>

int main(int argc, char** argv) {
  std::vector<int> vec = {1, 2, 3, 4};
  std::cout << argc << std::endl;
  return 0;
}
```

https://godbolt.org/z/ovxsG8e9d

(I was initially modifying vec[argc], but removed that when constructing a reproducer to make sure that wasn't a confounding factor.)

In short: with libc++, this fails when trying to format argc, while with libstdc++, this fails when printing _any_ string.

In the latter case, I've gotten this down to the following minimum reproducer on Compiler Explorer, but it doesn't reproduce locally:
```c++
// $ clang++ -stdlib=libc++ -fsanitize=memory 
#include <iostream>

int main(int argc, char** argv) {
  std::cout << "hello world\n";
  return 0;
}
```

https://godbolt.org/z/3Ea9coP3E
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVU9v47YT_TT0ZRBDJq1YPvig2PEPC_z6B9tDjwtKHFlsKY5BjuR4P31BSbaDbIAWaIFAkSm-mTePb4Y6RnvyiDuRv4j8sNA9txR2kXHA37U_LSoy193X3nvrT1A77U8wYIiWPKy2y9VyA1Sxth4NNIE6KEPdwv-t798g4JmiZQoWo5B7uFhuwdmqFvJFyJcZ_7QC7U1aj2zun9ZLuVwlkHbcUn9qgVsbQbt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