LLVM Discussion Forums

clang_Cursor_getReceiverType - Illegal Instruction

Hello there ! :slight_smile:

Currently I’m working on my own, complex libclang API test application.
I will test all of libclang functions and i have a small problem with one of them : clang_Cursor_getReceiverType.

At first my configuration :

  1. I’m using the latest LLVM 10.0 for Windows x64 that I downloaded from https://releases.llvm.org/download.html#10.0.0
  2. The IDE (with compiler) is Visual Studio Community 2019
  3. For my code : build switch is set to Debug and architecture switch is set to x64

Ok, so where is the problem ?
For CXCursor with enum CXCursorKind kind < CXCursor_FirstExpr && > CXCursor_LastExpr compiler throw Invalid Instruction exception for call clang_Cursor_getReceiverType function - assembler ud2 instruction.

Here is the full exception description : Unhandled exception at 0x000007FEAF30D249 (libclang.dll) in libclang.exe: 0xC000001D: Illegal Instruction.

In disassembler window (inside clang_Cursor_getReceiverType function) :

1.  000007FEB1CBD130  push        rsi  
2.  000007FEB1CBD131  push        rdi  
3.  000007FEB1CBD132  push        rbx  
4.  000007FEB1CBD133  sub         rsp,40h  
5.  000007FEB1CBD137  mov         rbx,rdx  
6.  000007FEB1CBD13A  mov         rsi,rcx  
7.  000007FEB1CBD13D  mov         rax,qword ptr [7FEB6240550h]  
8.  000007FEB1CBD144  xor         rax,rsp  
9.  000007FEB1CBD147  mov         qword ptr [rsp+38h],rax  
10. 000007FEB1CBD14C  mov         rdi,qword ptr [rdx+18h]  
11. 000007FEB1CBD150  mov         ecx,dword ptr [rdx]  
12. 000007FEB1CBD152  call        000007FEB1C85580  
13. 000007FEB1CBD157  test        eax,eax  
14. 000007FEB1CBD159  je          000007FEB1CBD249

ecx register (line 11) is CXCursor.kind.
Function from line 12 is (i think) https://github.com/llvm/llvm-project/blob/master/clang/tools/libclang/CXCursor.cpp#L1671

000007FEB1C85580  add         ecx,0FFFFFF9Ch  
000007FEB1C85583  xor         eax,eax  
000007FEB1C85585  cmp         ecx,32h  
000007FEB1C85588  setb        al  
000007FEB1C8558B  ret 

And finally :
When CXCursor.kind is Expression everything is OK,
When CXCursor.kind is NOT Expression assembler je instruction (line 14) goes to ud2 and I don’t know why.

000007FEB1CBD249  ud2

This behavior is similar to ASSERT function, but in source code is if statement.
Is it probably that is the rest of library debugging ?