[llvm] [IR] Introduce `llvm.allow.{runtime, ubsan}.check()` (PR #84850)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 20 00:21:40 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
+ %cond = or i1 %ubcheck, %not.allow
+ br i1 %cond, label %cont, label %trap
+
+ %cont:
+ ; Proceed
+
+ %trap:
+ call void @llvm.ubsantrap(i8 5)
+ unreachable
+
+
+'``llvm.allow.runtime.check``' Intrinsic
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Syntax:
+"""""""
+
+::
+
+ declare i1 @llvm.allow.runtime.check(metadata %kind)
+
+Overview:
+"""""""""
+
+This intrinsic returns ``true`` if and only if the compiler opted to enable
+runtime checks in the current basic block.
+
+Rules to allow runtime checks are not part of the intrinsic declaration, and
+controlled by compiler options.
+
+This intrinsic is non-ubsan specific version of ``@llvm.allow.ubsan.check()``.
+
+Arguments:
+""""""""""
+
+A string identifying the kind of runtime check guarded by the intrinsic. The
+string can be used to control rules to allow checks.
+
+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 should execute a guarded checks.
+If intrunsic is evaluated as ``false``, the program shoud avoid any unnececary
----------------
arsenm wrote:
```suggestion
If intrinsic is evaluated as ``true``, program should execute a guarded checks.
If intrinsic is evaluated as ``false``, the program shoud avoid any unnececary
```
https://github.com/llvm/llvm-project/pull/84850
More information about the llvm-commits
mailing list