Issue 134515
Summary [msan] Runtime false positives with iostream, msan, and -O0
Labels new issue
Assignees
Reporter steveWang
    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
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to