<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - Silent miscompile of integer to string conversion in stage 2 build"
   href="https://llvm.org/bugs/show_bug.cgi?id=30748">30748</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Silent miscompile of integer to string conversion in stage 2 build
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Other
          </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>LLVM Codegen
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>t.p.northover@gmail.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>zturner@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, renato.golin@linaro.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I submitted r284425 which adds some functions for formatting numbers.  This
broke the AArch64 build
[<a href="http://lab.llvm.org:8011/builders/clang-cmake-aarch64-full/builds/3344">http://lab.llvm.org:8011/builders/clang-cmake-aarch64-full/builds/3344</a>] with
one failing unit tests which tries to print -10 and instead prints "-0".  This
was reverted in r284462.

We suspect a latent clang bug, as there is no apparent UB in my patch, as well
as the fact that it only happens with optimizations on.

One particular quirk.  It only happens on a stage 2 build, and only when BOTH
stage 1 and stage 2 are compiled without O0.  If either stage 1 or stage 2 is
built at -O0, the problem does not happen.

Attached are 3 patches which might help to diagnose the issue.  Short
description as follows:

moretest - Adds unit tests for all numbers from -1000 to 1000.  Is there a
pattern that causes it to fail?  Certainly -10 can't be the only value.

rewrite - Simplifies the code a little.  If this is an optimizer bug, maybe we
can just remove whatever is tickling the optimizer so I can submit this and
unblock myself.

logging - Adds some print statements which might help identify where the bad CG
is.  Here is the output when it works:

calling write_signed() with N == -10, sizeof(N) == 4
Unsigned value = 10
Using 32-bit codepath
write_unsigned_impl.  N = 10, IsNegative = 1
Prec = 1
format_to_buffer(10), BufferSize = 128
Wrote character 0
Wrote character 1
formatted value to buffer, Len = 2
LeadingZeros = 0
Writing negative sign
Writing 2 characters "10"
finished


All 3 patches are independent of each other and should be applied directly on
top of the bad commit.</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>