<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 - clang is not resilient to source files changing length underneath it"
   href="https://bugs.llvm.org/show_bug.cgi?id=35485">35485</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang is not resilient to source files changing length underneath it
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </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>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>caustin@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>At Facebook, engineers have reported that clang will sometimes segfault if the
developer saves a file in the middle of compilation.

While tracking down an unrelated bug, I noticed that this appears to be because
SourceManager has UserFilesAreVolatile set to false which eventually causes
MemoryBuffer::getOpenFile to be called with isVolatile false, which memory maps
it.  When memory mapping a file whose length has changed underneath it,
accessing pages beyond the end of the backing file results in a SIGBUS.  In
addition, I believe line number computation expects a trailing nul byte, which
is implemented by mapping one byte larger than the file (assuming the file is
not exactly on a page boundary).  But if the file has since expanded, that byte
is no longer null, and clang SIGSEGVs while computing line numbers.

It seems like UserFilesAreVolatile should be set true for non-system files.

#35333 looks related. And possibly #20880.</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>