use vyre::ir::{BufferDecl, DataType, Expr, Node, Program};
use vyre_conform::{reference::interp, spec::value::Value};
/// ADVERSARIAL: uniform_checks not cleared across barrier iterations — vector: a loop whose
/// If-condition changes between iterations falsely reports a uniform-control-flow violation
/// even though every live invocation reached the barrier with the same condition on each
/// iteration.
#[test]
fn loop_barrier_uniformity_resets_across_iterations() {
let program = Program {
entry_op_id: None,
buffers: vec![BufferDecl::read_write("out", 0, DataType::U32)],
workgroup_size: [1, 1, 1],
entry: vec![
Node::loop_for(
"i",
Expr::u32(0),
Expr::u32(2),
vec![Node::if_then(
Expr::eq(Expr::var("i"), Expr::u32(0)),
vec![Node::Barrier],
)],
),
Node::store("out", Expr::u32(0), Expr::u32(42)),
],
};
// Iteration 0: condition=true, barrier reached uniformly.
// Iteration 1: condition=false, barrier reached uniformly.
// Per spec this is valid because on each barrier all live invocations have the same condition.
let outputs = interp::run(&program, &[Value::Bytes(vec![0; 4])])
.expect("uniform barrier across loop iterations must not error");
assert_eq!(outputs, vec![Value::Bytes(vec![42, 0, 0, 0])]);
}