<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 - Error: unknown token in expression using inline asm"
   href="https://bugs.llvm.org/show_bug.cgi?id=39895">39895</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Error: unknown token in expression using inline asm
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>7.0
          </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>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Frontend
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>noloader@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>We have about 8K lines of inline assembly written to accommodate GCC and MSVC.
Clang is currently disabled but we would like to enable it.

The inline assembly in the production code is hidden behind macros. The body is
Intel and the assembler template is AT&T. GCC sees both while MSVC only sees
the Intel body without the other adornments.

Clang is having trouble with it. It looks like Clang handles the noprefix OK
because "xor rsi, rsi" does not cause an error. However, the positional
arguments are giving it trouble.

$ cat TestPrograms/test_mixed_asm.cxx
#include <cstddef>
int main(int argc, char* argv[])
{
        size_t ret = 1, N = 0;
        asm __volatile__
        (
                ".intel_syntax   noprefix ;\n"
                "xor rsi, rsi    ;\n"
                "neg %1          ;\n"
                "inc %1          ;\n"
                "push %1         ;\n"
                "pop rax         ;\n"
                ".att_syntax     prefix ;\n"
                : "=a" (ret) : "c" (N) : "%rsi"
        );
        return (int)ret;
}

Compiling with GCC on Linux is OK:

$ g++ TestPrograms/test_mixed_asm.cxx

But Clang on Linux is having trouble:

$ clang++ TestPrograms/test_mixed_asm.cxx
TestPrograms/test_mixed_asm.cxx:11:4: error: unknown token in expression
                "neg %1          ;\n"
                 ^
<inline asm>:3:5: note: instantiated into assembly here
neg %rcx          ;
    ^
TestPrograms/test_mixed_asm.cxx:12:4: error: unknown token in expression
                "inc %1          ;\n"
                 ^
<inline asm>:4:5: note: instantiated into assembly here
inc %rcx          ;
    ^
TestPrograms/test_mixed_asm.cxx:13:4: error: unknown token in expression
                "push %1         ;\n"
                 ^
<inline asm>:5:6: note: instantiated into assembly here
push %rcx         ;
     ^
3 errors generated.

And:

$ clang++ --version
clang version 6.0.1 (tags/RELEASE_601/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /bin

Jumping over to MacPorts for Clang 7:

$ /opt/local/bin/clang++-mp-7.0 TestPrograms/test_mixed_asm.cxx
TestPrograms/test_mixed_asm.cxx:11:4: error: unknown token in expression
                "neg %1          ;\n"
                 ^
<inline asm>:3:5: note: instantiated into assembly here
neg %rcx          ;
    ^
TestPrograms/test_mixed_asm.cxx:12:4: error: unknown token in expression
                "inc %1          ;\n"
                 ^
<inline asm>:4:5: note: instantiated into assembly here
inc %rcx          ;
    ^
TestPrograms/test_mixed_asm.cxx:13:4: error: unknown token in expression
                "push %1         ;\n"
                 ^
<inline asm>:5:6: note: instantiated into assembly here
push %rcx         ;
     ^
3 errors generated.</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>