<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - MemorySanitizer: use-of-uninitialized-value in std::string s = "x"; std::replace(s.begin(), s.end(), 'a', 'b'); on -O0"
   href="https://bugs.llvm.org/show_bug.cgi?id=50112">50112</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>MemorySanitizer: use-of-uninitialized-value in std::string s = "x"; std::replace(s.begin(), s.end(), 'a', 'b'); on -O0
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>10.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>nok.raven@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>#include <string>

int main()
{
    std::string s = "x";
    std::replace(s.begin(), s.end(), 'a', 'b');
}

clang++-11 -fsanitize=memory -stdlib=libc++ -g z.cpp -o z && ./z

==62635==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x49a95b in std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char> >::__get_pointer()
/usr/lib/llvm-11/bin/../include/c++/v1/string:1514:17
    #1 0x49a461 in std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char> >::begin()
/usr/lib/llvm-11/bin/../include/c++/v1/string:909:26
    #2 0x499d79 in main /home/user/z.cpp:6:20
    #3 0x7fcd8bd35cb1 in __libc_start_main csu/../csu/libc-start.c:314:16
    #4 0x41d26d in _start (/home/user/z+0x41d26d)

SUMMARY: MemorySanitizer: use-of-uninitialized-value
/usr/lib/llvm-11/bin/../include/c++/v1/string:1514:17 in
std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char> >::__get_pointer()
Exiting

Clang/libc++ 10+ are affected

<a href="https://godbolt.org/z/6E9aeWjjP">https://godbolt.org/z/6E9aeWjjP</a></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>