Verifier: an unbound legacy memory intrinsic call is one operand short of its declaration

Decode upgrades a call of the older LLVM's llvm.memcpy, llvm.memmove or llvm.memset (an i32
alignment before the volatile flag) by removing the alignment operand. Where the volatile flag is
not a constant in the function that makes the call, decode keeps the upgraded call
Callee::Unbound with its template, as it keeps a current-form call (bitcode/function.rs). The
verifier's legacy arm took only Callee::Llvm, so such a call failed Verify(OperandType) in the
Module::new that decode runs (bitcode/decoded.rs), refusing the whole module. The arm now also
takes Callee::Unbound { template: Template::Llvm(Memset | Memcpy | Memmove) }, under the same
conditions: not variadic, one operand short, and a five-parameter declaration whose fourth
parameter is i32 and fifth i1.

What such a call then meets, read on the current form's path (not run): canonicalization's SCCP
binds an Unbound call with Template::bind over its four operands and the current signature
(canon/sccp.rs), so where inlining makes the flag a constant the call becomes Callee::Llvm, the
form the PR already verifies and translates; where the flag stays a kernel parameter or a value
the run computes, the post-check refuses it at the call in the inlined entry as
InvalidInput(Intrinsic(ImmediateNotConstant)) (canon/mod.rs), the refusal a current-form call
with that flag meets (docs/API.md, OpenCL C kernels).

Makes a_legacy_memory_intrinsic_with_an_unbound_volatile_flag_verifies pass (expected; not run:
the brief holds every build and test until PR 30 merges). No SEMANTICS_VERSION bump here: PR 30's
2391 covers its decode change, of which this is part. Checked: cargo fmt clean.
This commit is contained in:
Anees Iqbal committed 2026-12-04 21:17:50 -08:00
1 parent a5a4c0f839
commit 3e311ec8ac
1 file changed
+13 -2
+13 -2
View File
@@ -38,7 +38,7 @@ use crate::budget::Meter;
use crate::error::Error;
use crate::error::{DiagName, InputError, InputErrorKind, Location, VerifyError};
use crate::graph::{Cfg, DomTree};
use crate::intrinsics::LlvmIntrinsic;
use crate::intrinsics::{LlvmIntrinsic, Template};
/// A verified AIR module. Immutable: passes consume it with [`Module::into_parts`] and build a
/// new one through [`Module::new`].
@@ -919,7 +919,9 @@ impl<'a> Verifier<'a> {
};
// A memory intrinsic declared with an alignment operand (an older LLVM's form,
// its `i32` alignment before the `i1` volatile flag) is called without it: decode
// moved its value to the pointers' `align`.
// moved its value to the pointers' `align`. So is one whose volatile flag is not
// yet a constant (`Callee::Unbound`), which specialization binds as it binds the
// current form's.
let upgraded: Vec<TypeId>;
let legacy = |params: &[TypeId]| match params {
[.., align, flag] if params.len() == 5 => {
@@ -934,6 +936,15 @@ impl<'a> Verifier<'a> {
| LlvmIntrinsic::Memcpy { .. }
| LlvmIntrinsic::Memmove { .. },
..
}
| Callee::Unbound {
template:
Template::Llvm(
LlvmIntrinsic::Memset { .. }
| LlvmIntrinsic::Memcpy { .. }
| LlvmIntrinsic::Memmove { .. },
),
..
} if !vararg && call.args.len() + 1 == params.len() && legacy(params) => {
upgraded = params
.iter()