Skip to content

Commit aa52cbf

Browse files
committed
Support read_via_copy intrinsic
1 parent c26259b commit aa52cbf

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

crates/hir-ty/src/consteval/tests/intrinsics.rs

+18
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,24 @@ fn transmute() {
163163
);
164164
}
165165

166+
#[test]
167+
fn read_via_copy() {
168+
check_number(
169+
r#"
170+
extern "rust-intrinsic" {
171+
pub fn read_via_copy<T>(e: *const T) -> T;
172+
pub fn volatile_load<T>(e: *const T) -> T;
173+
}
174+
175+
const GOAL: i32 = {
176+
let x = 2;
177+
read_via_copy(&x) + volatile_load(&x)
178+
};
179+
"#,
180+
4,
181+
);
182+
}
183+
166184
#[test]
167185
fn const_eval_select() {
168186
check_number(

crates/hir-ty/src/mir/eval/shim.rs

+7
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,13 @@ impl Evaluator<'_> {
888888
}
889889
not_supported!("FnOnce was not available for executing const_eval_select");
890890
}
891+
"read_via_copy" | "volatile_load" => {
892+
let [arg] = args else {
893+
return Err(MirEvalError::TypeError("read_via_copy args are not provided"));
894+
};
895+
let addr = Address::from_bytes(arg.interval.get(self)?)?;
896+
destination.write_from_interval(self, Interval { addr, size: destination.size })
897+
}
891898
_ => not_supported!("unknown intrinsic {name}"),
892899
}
893900
}

0 commit comments

Comments
 (0)