<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 - [WinEH] Inline assembly corrupts catch handler"
   href="https://bugs.llvm.org/show_bug.cgi?id=36247">36247</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[WinEH] Inline assembly corrupts catch handler
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </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>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Backend: X86
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>smeenai@fb.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>compnerd@compnerd.org, david.majnemer@gmail.com, llvm-bugs@lists.llvm.org, rnk@google.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=19814" name="attach_19814" title="IR">attachment 19814</a> <a href="attachment.cgi?id=19814&action=edit" title="IR">[details]</a></span>
IR

% cat exc.cpp
void f();
int main() {
    try {
        f();
    } catch (int) {
        __asm__ ("nop");
        return 0;
    }
    return 1;
}

% clang -target i686-windows-msvc -S -o - exc.cpp
...
"?catch$1@?0?main@4HA":
LBB0_1:                                 # %catch
        pushl   %ebp
        addl    $12, %ebp
        movl    %esp, -28(%ebp)
Lfunc_end0:
        .section        .xdata,"dr"
        .p2align        2
L__ehtable$main:
        .long   429065506               # MagicNumber
...

Note that the EH table is emitted in the middle of the catch handler's code
(right after its prologue), which is obviously bogus. Slightly cleaned up IR
generated from the C++ source above is attached for convenience. Removing the
`call void asm` from the IR makes llc generate sane assembly for the catch
handler.

The same occurs for x86-64, but MS doesn't officially support inline assembly
for x86-64, so I presume we don't care too much. To be perfectly honest, I
don't care very much about the x86 case either, since I have a trivial local
workaround; I'm just reporting it for completeness.</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>