<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 - [MC][Thumb2] #-0 assembled as #INT_MIN instead"
   href="https://bugs.llvm.org/show_bug.cgi?id=50763">50763</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[MC][Thumb2] #-0 assembled as #INT_MIN instead
          </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>Linux
          </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>Backend: ARM
          </td>
        </tr>

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

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

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, smithp352@googlemail.com, Ties.Stuij@arm.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The LLVM and GNU ARM assemblers recognize a special "negative zero" immediate
operand. The intent seems to have been to select an instruction encoding that
uses non-positive address offsets instead of non-negative offsets.

AFAICT they both use the same syntax: an immediate of value 0 whose first token
is a '-'. So #-(0) and #-(1-1) are treated specially, but #(-0) is not, because
its first token is '(' instead of '-'.

LLVM represents these offsets internally using INT_MIN. It uses the same
immediate parsing for non-address-offset immediates, and in that case, a #-0
operand is sometimes converted into an #INT_MIN operand. This seems wrong and
doesn't match the GNU assembler:

cat >test.s <<EOF
  .syntax unified
  .arch armv7-a
  .text
  .thumb
func:
  mov r2, #-0
  mov r2, #0x80000000
  orn r2, r2, #-0
  orn r2, r2, #0x80000000
  add r2, #-0
  add r2, #0x80000000
  mvn r0, #-0
  mvn r0, #0x80000000
EOF
llvm-mc --triple armv7a-linux test.s --filetype=obj -o test.o
llvm-objdump -d test.o
arm-linux-gnueabi-as test.s -c -o test.o
llvm-objdump -d test.o

LLVM output:

       0: 4f f0 00 42   mov.w r2, #2147483648
       4: 4f f0 00 42   mov.w r2, #2147483648
       8: 62 f0 00 42   orn r2, r2, #2147483648
       c: 62 f0 00 42   orn r2, r2, #2147483648
      10: 02 f1 00 42   add.w r2, r2, #2147483648
      14: 02 f1 00 42   add.w r2, r2, #2147483648
      18: 6f f0 00 40   mvn r0, #2147483648
      1c: 6f f0 00 40   mvn r0, #2147483648

GAS output:

       0: 4f f0 00 02   mov.w r2, #0
       4: 4f f0 00 42   mov.w r2, #2147483648
       8: 62 f0 00 02   orn r2, r2, #0
       c: 62 f0 00 42   orn r2, r2, #2147483648
      10: 02 f1 00 02   add.w r2, r2, #0
      14: 02 f1 00 42   add.w r2, r2, #2147483648
      18: 6f f0 00 00   mvn r0, #0
      1c: 6f f0 00 40   mvn r0, #2147483648</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>