<div dir="ltr">Would you mind trying the following patch (on top of the "broken" patch) and then running SupportTests --gtest_filter=NativeFormatTest.*?<div><br></div><div>Then paste the output back here?  Here's my output for reference:</div><div><br></div><div><div>calling write_signed() with N == -10, sizeof(N) == 4</div><div>Unsigned value = 10</div><div>Using 32-bit codepath</div><div>write_unsigned_impl.  N = 10, IsNegative = 1</div><div>Prec = 1</div><div>format_to_buffer(10), BufferSize = 128</div><div>Wrote character 0</div><div>Wrote character 1</div><div>formatted value to buffer, Len = 2</div><div>LeadingZeros = 0</div><div>Writing negative sign</div><div>Writing 2 characters "10"</div><div>finished</div></div><div><br></div><div>If it is indeed an optimizer bug then perhaps the addition of this code will cause it to start working.  Hopefully it yields a clue though.</div><div><br></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Oct 18, 2016 at 4:05 PM Zachary Turner <<a href="mailto:zturner@google.com">zturner@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg">If this doesn't turn anything up, we can add some print statements to NativeFormatTest.cpp since debugging doesn't work well in an optimized build.<div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">For example, make a global variable in NativeFormatTest.cpp called g_print, initialize it to false, in write_signed when N == -10, set it to true, and when it's true you write a bunch of logging to stderr to trace the value through the various functions.</div></div><br class="gmail_msg"><div class="gmail_quote gmail_msg"><div dir="ltr" class="gmail_msg">On Tue, Oct 18, 2016 at 3:50 PM Zachary Turner <<a href="mailto:zturner@google.com" class="gmail_msg" target="_blank">zturner@google.com</a>> wrote:<br class="gmail_msg"></div><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg">To get it to run under ubsan, I did the following.<div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">1. clone compiler-rt into llvm/projects.</div><div class="gmail_msg">2. Build a stage 1 clang into A using -DCMAKE_BUILD_TYPE=Release</div><div class="gmail_msg">3. Build a stage 2 clang into B using -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=A/bin/clang -DCMAKE_CXX_COMPILER=/A/bin/clang++ -DLLVM_USE_SANITIZER=Undefined</div><div class="gmail_msg">4. ninja SupportTests </div><div class="gmail_msg">5. unittests/Support/SupportTests --gtest_filter=NativeFormatTest.*</div></div><br class="gmail_msg"><div class="gmail_quote gmail_msg"><div dir="ltr" class="gmail_msg">On Tue, Oct 18, 2016 at 3:46 PM Zachary Turner <<a href="mailto:zturner@google.com" class="gmail_msg" target="_blank">zturner@google.com</a>> wrote:<br class="gmail_msg"></div><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg">I'm leaning towards bug in clang's optimizer.  I've scanned this code multiple times and I really don't see any UB.  I ran it under ubsan on Linux and it did not report any problems.  <div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">I guess maybe you could run it under ubsan on aarch64 as well?</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Assuming that passes, where do we go from here?  I know 0 about the optimizer or how to fix a bug in it, especially one that only occurs in a backend I have no access to :-/</div></div><br class="gmail_msg"><div class="gmail_quote gmail_msg"><div dir="ltr" class="gmail_msg">On Tue, Oct 18, 2016 at 2:40 AM Renato Golin <<a href="mailto:renato.golin@linaro.org" class="gmail_msg" target="_blank">renato.golin@linaro.org</a>> wrote:<br class="gmail_msg"></div><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 18 October 2016 at 00:08, Zachary Turner via llvm-commits<br class="gmail_msg">
<<a href="mailto:llvm-commits@lists.llvm.org" class="gmail_msg" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br class="gmail_msg">
> Author: zturner<br class="gmail_msg">
> Date: Mon Oct 17 18:08:47 2016<br class="gmail_msg">
> New Revision: 284437<br class="gmail_msg">
><br class="gmail_msg">
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=284437&view=rev" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project?rev=284437&view=rev</a><br class="gmail_msg">
> Log:<br class="gmail_msg">
> Rename HexStyle -> HexFormatStyle, and remove a constexpr.<br class="gmail_msg">
><br class="gmail_msg">
> This should fix the remaining broken builds.<br class="gmail_msg">
<br class="gmail_msg">
Hi Zach,<br class="gmail_msg">
<br class="gmail_msg">
Didn't quite fix all problems, but we're getting there... :)<br class="gmail_msg">
<br class="gmail_msg">
<a href="http://lab.llvm.org:8011/builders/clang-cmake-aarch64-full/builds/3344" rel="noreferrer" class="gmail_msg" target="_blank">http://lab.llvm.org:8011/builders/clang-cmake-aarch64-full/builds/3344</a><br class="gmail_msg">
<br class="gmail_msg">
[ RUN      ] NativeFormatTest.IntegerTests<br class="gmail_msg">
/home/buildslave/buildslave/clang-cmake-aarch64-full/llvm/unittests/Support/NativeFormatTests.cpp:249:<br class="gmail_msg">
Failure<br class="gmail_msg">
Value of: format_number(-10, IntegerStyle::Integer, 1)<br class="gmail_msg">
  Actual: "-0"<br class="gmail_msg">
Expected: "-10"<br class="gmail_msg">
[  FAILED  ] NativeFormatTest.IntegerTests (0 ms)<br class="gmail_msg">
<br class="gmail_msg">
I have reverted on r284462. Let me know if you need help testing.<br class="gmail_msg">
<br class="gmail_msg">
cheers,<br class="gmail_msg">
--renato<br class="gmail_msg">
</blockquote></div></blockquote></div></blockquote></div></blockquote></div></div>