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

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 26 15:18:07 PDT 2024


================
@@ -27702,6 +27702,121 @@ 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 the ubsan specific version of ``@llvm.allow.runtime.check()``.
+
+Arguments:
+""""""""""
+
+An integer describing the kind of ubsan check guarded by the intrinsic.
+
+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 the intrinsic is evaluated as ``true``, program must check ubsan condition,
----------------
MaskRay wrote:

The two paragraphs can be rephrased like the following

When used in a branch condition, it selects one of the two paths:

- true: Executes the UBSan check and reports any issues detected.
- false: Skips the check, assuming its success to potentially remove the check.


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


More information about the llvm-commits mailing list