<html>
    <head>
      <base href="http://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 --- - Inline assembly handling of adding negative numbers not as smart as gcc's"
   href="http://llvm.org/bugs/show_bug.cgi?id=20978">20978</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Inline assembly handling of adding negative numbers not as smart as gcc's
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Other
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </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>-New Bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>bero@lindev.ch
          </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>Created <span class=""><a href="attachment.cgi?id=13047" name="attach_13047" title="test case">attachment 13047</a> <a href="attachment.cgi?id=13047&action=edit" title="test case">[details]</a></span>
test case

Compiling the attached test case with clang -target aarch64-linux-android -O2
-c test.c -o test.o results in

test.c:5:3: error: expected compatible register, symbol or integer in range
      [0, 4095]
                "add %w[result], %w[result], %w[num]    \n\t"
                ^
<inline asm>:1:14: note: instantiated into assembly here
        add w0, w0, #4294967295 
                    ^
1 error generated.


This is not unreasonable, given add doesn't take a negative number and the
constraint is set to IJr (J --> valid for sub --> doesn't catch the -1).

However, gcc (tested Linaro 4.9-2014.09, but it's probably the same for older
gcc, the code has compiled with gcc forever) compiles the code just fine,
recognizes what it meant to do, and generates
        sub w0, w0, #1

It would be nice if clang could match - better compatibility and the generated
code is better than what could be achieved by the workarounds (changing the
constraint to Ir or adding an if clause for add vs. sub).</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>