<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 - [CLANG-CL] 64x inline assembler function call/jump miscompiled"
   href="https://bugs.llvm.org/show_bug.cgi?id=44272">44272</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[CLANG-CL] 64x inline assembler function call/jump miscompiled
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>9.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </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>unassignedbugs@nondot.org
          </td>
        </tr>

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

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I've recently starting using Clang-CL in Visual Studio 2019 and I've discovered
a fatal bug within the compiler, when attempting to call a function within
inline assembly the function pointer is dereferenced, causing to crash due to
memory access violation, the same issue exists by attempting to "jmp" to a
function directly, I've tried to fix this in various ways, but I only found a
way to get around the problem, this happens only with 64bit inline assembler
and the fatal bug is clearly visible within assembly output.

The problem is replicated by doing something like this:

int main() {
      __asm {
           xor rcx, rcx
           call exit
      }
      printf("The application didn't quit!");
      return 0;
}

The generated inline assembly looks like this:

xor rcx, rcx
call qword ptr [exit]

The way I get around the problem is by using "lea" instruction to retrieve the
function pointer, which looks like this:

__asm {
     xor rcx, rcx
     lea rax, exit
     call rax 
}

Results in generated inline assembly that looks like this:

xor rcx, rcx
lea rax, [exit]
call rax

This no longer results in a crash.

My Clang-CL installation (--version):

CLang Version: 9.0.0 (release-final)
Target: x86_64-pc-windows-msvc
InstalledDir: C:\Program Files (x86)\Microsoft Visual
Studio\2019\Community\VC\Tools\Llvm\bin

The Clang-CL compiler is downloaded via visual studio 2019 installer, selecting
the "C++ Clang tools for Windows (9.0.0 - x64/x86)"

I hope this problem can be addressed soon, this is my first time reporting a
bug. Thank you.</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>