<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 - `llvm.experimental.stackmap` is erroneously marked `Throws`?"
   href="https://bugs.llvm.org/show_bug.cgi?id=37788">37788</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>`llvm.experimental.stackmap` is erroneously marked `Throws`?
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </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>new bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>vext01@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Over the last few days I have been experimenting with inserting stackmaps from
the Rust compiler.

After inserting some `call`s (not `invoke`s) to llvm.experimental.stackmap into
rustc's llvm
codegen, and then allowing the compiler to build itself using this change, I
was surprised to see:

```
Cannot invoke an intrinsic other than donothing, patchpoint, statepoint,
coro_resume or coro_destroy
invoke void (i64, i32, ...%) @llvm.experimental.stackmap(i64 1, i32 0)
          to label 13
```

As I understand, this is LLVM's way of saying, you can't `invoke` (expecting a
possible exception) an intrinsic which cannot raise an exception.

Having spoke to one of the Rust developers about this, and after trying
a few things, it seems that LLVM's inlining pass is itself allowing `call`s to
the stackmap intrinsic to be translated to `invoke`s. Then the verifier rejects
the resulting code.

We suspect that the fix is as follows:

```
diff --git a/include/llvm/IR/Intrinsics.td b/include/llvm/IR/Intrinsics.td
index a2a1f26292c..9bbe22645ac 100644
--- a/include/llvm/IR/Intrinsics.td
+++ b/include/llvm/IR/Intrinsics.td
@@ -720,8 +720,7 @@ def int_invariant_group_barrier :
Intrinsic<[llvm_anyptr_ty],
 //===------------------------ Stackmap Intrinsics
-------------------------===//
 //
 def int_experimental_stackmap : Intrinsic<[],
-                                  [llvm_i64_ty, llvm_i32_ty, llvm_vararg_ty],
-                                  [Throws]>;
+                                  [llvm_i64_ty, llvm_i32_ty, llvm_vararg_ty],
[]>;
 def int_experimental_patchpoint_void : Intrinsic<[],
                                                  [llvm_i64_ty, llvm_i32_ty,
                                                   llvm_ptr_ty, llvm_i32_ty,
```

In other words, remove `Throws` from the signature of
`int_experimental_stackmap`.

With this patch applied, I managed to run a stage 2 rustc build without the
verifier getting upset.</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>