https://bugs.llvm.org/show_bug.cgi?id=44272

            Bug ID: 44272
           Summary: [CLANG-CL] 64x inline assembler function call/jump
                    miscompiled
           Product: new-bugs
           Version: 9.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedb...@nondot.org
          Reporter: zegzmanz...@gmail.com
                CC: htmldevelo...@gmail.com, llvm-bugs@lists.llvm.org

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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to