Skip to content

Commit

Permalink
Support read_via_copy intrinsic
Browse files Browse the repository at this point in the history
  • Loading branch information
HKalbasi committed Jul 9, 2023
1 parent c26259b commit aa52cbf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
18 changes: 18 additions & 0 deletions crates/hir-ty/src/consteval/tests/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,24 @@ fn transmute() {
);
}

#[test]
fn read_via_copy() {
check_number(
r#"
extern "rust-intrinsic" {
pub fn read_via_copy<T>(e: *const T) -> T;
pub fn volatile_load<T>(e: *const T) -> T;
}
const GOAL: i32 = {
let x = 2;
read_via_copy(&x) + volatile_load(&x)
};
"#,
4,
);
}

#[test]
fn const_eval_select() {
check_number(
Expand Down
7 changes: 7 additions & 0 deletions crates/hir-ty/src/mir/eval/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,13 @@ impl Evaluator<'_> {
}
not_supported!("FnOnce was not available for executing const_eval_select");
}
"read_via_copy" | "volatile_load" => {
let [arg] = args else {
return Err(MirEvalError::TypeError("read_via_copy args are not provided"));
};
let addr = Address::from_bytes(arg.interval.get(self)?)?;
destination.write_from_interval(self, Interval { addr, size: destination.size })
}
_ => not_supported!("unknown intrinsic {name}"),
}
}
Expand Down

0 comments on commit aa52cbf

Please sign in to comment.