<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 --- - Possible miscompile with arm64"
   href="https://llvm.org/bugs/show_bug.cgi?id=23437">23437</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Possible miscompile with arm64
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </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>Backend: AArch64
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>nicolasweber@gmx.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>This assert fails when building with trunk clang when targeting arm64:

$ cat test.cc
#include <assert.h>

int main(int argc, char **argv) {
  const struct {
    const char* to_escape;
    const char* escaped;
  } cases[] = {
    {"\xe5\xc4\x4f\x05\xb6\xfd\0", "\\u00E5\\u00C4O\\u0005\\u00B6\\u00FD"},
  };

  assert((unsigned char)cases[0].to_escape[0] == 0xe5);
  return 0;
}
$ Release+Asserts/bin/clang++ -isysroot
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.2.sdk
-O0 -gdwarf-2 -fvisibility=hidden -miphoneos-version-min=7.0 -arch arm64
-std=c++11 -stdlib=libc++ -fno-rtti -fno-exceptions -fvisibility-inlines-hidden
-fno-threadsafe-statics  -fcolor-diagnostics -fstack-protector-all  -c test.cc
-o test.o
$ Release+Asserts/bin/clang++ -Wl,-search_paths_first -Wl,-ObjC
-miphoneos-version-min=7.0 -isysroot
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.2.sdk
-arch arm64 -L. -stdlib=libc++ -o foo test.o



Here's the disassembly of the relevant bits of main:

0000000100007e60         stp        x29, x30, [sp, #0xfffffff0]!               
; XREF=0x1000000d0
0000000100007e64         mov        x29, sp
0000000100007e68         sub        sp, sp, #0x20
0000000100007e6c         adrp       x8, #0x100008000                           
; imp___got____stack_chk_guard
0000000100007e70         add        x8, x8, #0x28                              
; __ZZ4mainE5cases

0000000100007e74         adrp       x10, #0x100008000                          
 ; imp___got____stack_chk_guard
0000000100007e78         ldr        x10, [x10]
0000000100007e7c         ldr        x10, [x10]
0000000100007e80         mov        x2, x10
0000000100007e84         stur       x10, [x29, #0xfffffff8]
0000000100007e88         stur       wzr, [x29, #0xfffffff4]
0000000100007e8c         str        w0, [sp, #0x10]
0000000100007e90         str        x1, [sp, #0x8]
0000000100007e94         ldr        x8, [x8]
0000000100007e98         ldrb       w0, [x8]

0000000100007e9c         cmp        w0, #0xe5
0000000100007ea0         cset       w0, eq


0000000100007ea4         eor        w0, w0, #0x1


0000000100007ea8         cmp        w0, #0x0
0000000100007eac         str        x2, [sp]
0000000100007eb0         b.eq       0x100007ed4

0000000100007eb4         adrp       x8, #0x100007000                           
; 0x100007000 (__mh_execute_header + 0x7000)
0000000100007eb8         add        x0, x8, #0xf78                             
; "main"
0000000100007ebc         adrp       x8, #0x100007000                           
; 0x100007000 (__mh_execute_header + 0x7000)
0000000100007ec0         add        x1, x8, #0xf7d                             
; "test.cc"
0000000100007ec4         orr        w2, wzr, #0x10
0000000100007ec8         adrp       x8, #0x100007000                           
; 0x100007000 (__mh_execute_header + 0x7000), argument #1 for method
imp___stubs____assert_rtn
0000000100007ecc         add        x3, x8, #0xf85                             
; "(unsigned char)cases[0].to_escape[0] == 0xe5"
0000000100007ed0         bl         imp___stubs____assert_rtn


I can't read arm64 well enough to say if that makes sense.


The assert doesn't fire with xcode's clang, so maybe it's a somewhat recent
regression?</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>