<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </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 --- - Invalid assembly code generated by clang-cl from the inline assembly"
   href="http://llvm.org/bugs/show_bug.cgi?id=20091">20091</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Invalid assembly code generated by clang-cl from the inline assembly
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>All
          </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>ehsan@mozilla.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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
noparams:
        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:

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

$noparams$4:                                                                    
      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,
ebp                          
      29:       5d                                              pop     ebp     
      2a:       c3                                              ret             


Here is the code generated by clang-cl:

_NS_InvokeByIndex:
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.</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>