[llvm] [IR] Introduce `llvm.allow.{runtime, ubsan}.check()` (PR #84850)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 20 08:44:05 PDT 2024


================
@@ -27696,6 +27696,125 @@ constant `true`. However it is always correct to replace
 it with any other `i1` value. Any pass can
 freely do it if it can benefit from non-default lowering.
 
+'``llvm.allow.ubsan.check``' Intrinsic
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Syntax:
+"""""""
+
+::
+
+      declare i1 @llvm.allow.ubsan.check(i8 immarg %kind)
+
+Overview:
+"""""""""
+
+This intrinsic returns ``true`` if and only if the compiler opted to enable the
+ubsan check in the current basic block.
+
+Rules to allow ubsan checks are not part of the intrinsic declaration, and
+controlled by compiler options.
+
+This intrinsic is ubsan specific version of ``@llvm.allow.runtime.check()``.
+
+Arguments:
+""""""""""
+
+An integer describing the kind of ubsan check guarded by the intrinsic.
+
+None.
+
+Semantics:
+""""""""""
+
+The intrinsic ``@llvm.allow.ubsan.check()`` returns either ``true`` or
+``false``, depending on compiler options. 
+
+For each evaluation of a call to this intrinsic, the program must be valid and
+correct both if it returns ``true`` and if it returns ``false``.
+
+When used in a branch condition, it allows us to choose between
+two alternative correct solutions for the same problem. 
+
+If intrunsic is evaluated as ``true``, program must check ubsan condition, and
+report if needed. If intrunsic is evaluated as ``false``, program must 
+avoid checking ubsan condition and assume it passed.
+
+Example:
+
+.. code-block:: text
+
+    %allow = call i1 @llvm.allow.ubsan.check(i8 5)
+    %not.allow = not i1 %allow
----------------
nikic wrote:

```suggestion
    %not.allow = xor i1 %allow, true
```

https://github.com/llvm/llvm-project/pull/84850


More information about the llvm-commits mailing list