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

    <tr>
        <th>Summary</th>
        <td>
            Diagnostics for `-Wunsafe-buffer-usage` won't fire unless enabled at *end* of file
        </td>
    </tr>

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

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

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

<pre>
    Like with other diagnostics it's possible to control `-Wunsafe-buffer-usage` with `#pragma clang diagnostic` within a source file. However, there's a weird nonlocal effect: for *any* instances of the warning to fire, it seems the warning must be enabled at the point of occurrence *and* at the end of the file.

This isn't true for other warnings like `-Wsign-compare`.

You can see an example here: https://godbolt.org/z/4eGc5hdzd

Initially there are no `-Wunsafe-buffer-usage` warnings. But if you uncomment the last line of the input (`#pragma clang diagnostic warning "-Wunsafe-buffer-usage"`) then warnings that appear _earlier_ in the file will show up.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8U02v2zYQ_DXUZWFDpj5sH3RwYrgt0GOBoqdgRa6kbSlS4Edc59cXlPwSvyJ4F-lAcmZ2ZhZD4NESdaL5JJprgSlOznfzrD0behS904_ud_6H4M5xAhcn8qAZR-tCZBWAo5DHAIsLgXtDEB0oZ6N3BkRb7v5MNuBAuz4NA_ldCjiSaMsNTbSlkNXicZwRlEE7vkC_3WILCMElrwgGNrSHX92dvpIX8jNkObQKQLgTew3WWeMUGqBhIBVFdYHBeRDygvYh5AXYhohWUQA35PdwR2_Zjln5wBntM3CEQDSHd-dzChF6ArLYG9KAcT1eHNuYsZxSyXuyijY2ndmel8jqN7p1BlFeRXnZvn9MHICDFfIYIfpEq-DN6Sd3AJMjWA3Nee2Umxf02cl3UH-5BAptFg9ogf7FeTEEq0nVBaYYlyCqi5A3IW-j070zce_8KOTtm5C3mn5RzaS_6VfM3yxHRmMem9mAnsC6j8N9qt7DpxSBB3i4BMkqN89kN0MMhgiGLb3ZwnZJEYQ8fViK72EIKX9OL-UKcM6g9od_ccIIuCyEHr4QesPkvwDb75HAnY2BMLk7pGVf6K7S5-qMBXWHY9keqrpqq2Lqmnbo6VQ2qqbTudZSayzLUp_UoanoVJcFd7KUdXmQtZQHWVf7HvF0RDxTq6ilphJ1STOy2Rvzdc7mFxxCou54ro7nwmBPJqzbKKWlO6yHearmWvguv9n1aQyiLg2HGH6gRI6GuuvLaq69_ygmt3Uutx6SNRTCa7mFvNBWYjesFhXJm-5_HeI4pX6v3CzkLUt5_naLd3_n9ZO3dYAg5G0d8L8AAAD__wX8eyU">