[LLVMbugs] [Bug 20091] New: Invalid assembly code generated by clang-cl from the inline assembly

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Jun 20 15:22:00 PDT 2014


            Bug ID: 20091
           Summary: Invalid assembly code generated by clang-cl from the
                    inline assembly
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: ehsan at mozilla.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Here's the source code:

extern "C" __declspec(dllexport) nsresult __stdcall
NS_InvokeByIndex(nsISupports* that, uint32_t methodIndex,
                 uint32_t paramCount, nsXPTCVariant* params)
    __asm {
        mov     edx,paramCount      // Save paramCount for later
        test    edx,edx             // maybe we don't have any params to copy
        jz      noparams
        mov     eax,edx             
        shl     eax,3               // *= 8 (max possible param size)
        sub     esp,eax             // make space for params
        mov     ecx,esp
        push    params
        call    invoke_copy_to_stack // fastcall, ecx = d, edx = paramCount,
params is on the stack
        mov     ecx,that            // instance in ecx
        push    ecx                 // push this
        mov     edx,[ecx]           // vtable in edx
        mov     eax,methodIndex
        call    [edx][eax*4]        // stdcall, i.e. callee cleans up stack.
        mov     esp,ebp

Here is the code generated by cl:

       0:       55                                              push    ebp     
       1:       8b ec                                           mov     ebp,
       3:       8b 55 10                                        mov     edx,
dword ptr [ebp + 16]         
       6:       85 d2                                           test    edx,
       8:       74 11                                           je      17      
       a:       8b c2                                           mov     eax,
       c:       c1 e0 03                                        shl     eax, 3  
       f:       2b e0                                           sub     esp,
      11:       8b cc                                           mov     ecx,
      13:       ff 75 14                                        push    dword
ptr [ebp + 20]              
      16:       e8 00 00 00 00                                  call    0       

      1b:       8b 4d 08                                        mov     ecx,
dword ptr [ebp + 8]          
      1e:       51                                              push    ecx     
      1f:       8b 11                                           mov     edx,
dword ptr [ecx]              
      21:       8b 45 0c                                        mov     eax,
dword ptr [ebp + 12]         
      24:       ff 14 82                                        call    dword
ptr [edx + 4*eax]           
      27:       8b e5                                           mov     esp,
      29:       5d                                              pop     ebp     
      2a:       c3                                              ret             

Here is the code generated by clang-cl:

55BD89A0  push        ebp  
55BD89A1  mov         ebp,esp  
55BD89A3  push        esi  
55BD89A4  sub         esp,18h  
55BD89A7  mov         eax,dword ptr [ebp+14h]  
55BD89AA  mov         ecx,dword ptr [ebp+10h]  
55BD89AD  mov         edx,dword ptr [ebp+0Ch]  
55BD89B0  mov         esi,dword ptr [ebp+8]  
55BD89B3  mov         dword ptr [ebp-0Ch],eax  
55BD89B6  mov         dword ptr [ebp-10h],ecx  
55BD89B9  mov         dword ptr [ebp-14h],edx  
55BD89BC  mov         dword ptr [ebp-18h],esi  
55BD89BF  mov         eax,55BD8A10h  
55BD89C4  mov         dword ptr [ebp-1Ch],eax  
55BD89C7  mov         esi,dword ptr [ebp-1Ch]  
55BD89CA  mov         edx,dword ptr [ebp-10h]  
55BD89CD  test        edx,edx  
55BD89CF  je          _NS_InvokeByIndex+43h (55BD89E3h)  
55BD89D5  mov         eax,edx  
55BD89D7  shl         eax,3  
55BD89DA  sub         esp,eax  
55BD89DC  mov         ecx,esp  
55BD89DE  push        dword ptr [ebp-0Ch]  
55BD89E1  call        esi  
55BD89E3  mov         ecx,dword ptr [ebp-18h]  
55BD89E6  push        ecx  
55BD89E7  mov         edx,dword ptr [ecx]  
55BD89E9  mov         eax,dword ptr [ebp-14h]  
55BD89EC  call        word ptr [edx+eax*4]  
55BD89F0  mov         esp,ebp  
55BD89F2  ud2  

Note the incorrect short dereference above (at 55BD89EC) and the invalid
instruction at 55BD89F2.

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140620/8a3ec1c0/attachment.html>

More information about the llvm-bugs mailing list