Skip to content

Commit 5429ed2

Browse files
committed
Test missing miri::intrinsic_fallback_checks_ub attribute
1 parent e0ee8f7 commit 5429ed2

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

src/tools/miri/src/shims/intrinsics/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
6868
throw_unsup_format!("unimplemented intrinsic: `{intrinsic_name}`")
6969
}
7070
let intrinsic_fallback_checks_ub = Symbol::intern("intrinsic_fallback_checks_ub");
71-
if !this.tcx.item_attrs(instance.def_id()).iter().any(|attr| attr.path_matches(&[sym::miri, intrinsic_fallback_checks_ub])) {
72-
throw_unsup_format!("miri can only use intrinsics that preserve UB. After verifying that `{intrinsic_name}` does so, add the `#[miri::intrinsic_fallback_checks_ub]` attribute to it");
71+
if this.tcx.get_attrs_by_path(instance.def_id(), &[sym::miri, intrinsic_fallback_checks_ub]).next().is_none() {
72+
throw_unsup_format!("miri can only use intrinsic fallback bodies that preserve UB. After verifying that `{intrinsic_name}` does so, add the `#[miri::intrinsic_fallback_checks_ub]` attribute to it");
7373
}
7474
return Ok(Some(ty::Instance {
7575
def: ty::InstanceDef::Item(instance.def_id()),
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![feature(rustc_attrs, effects)]
2+
3+
#[rustc_intrinsic]
4+
#[rustc_nounwind]
5+
#[rustc_do_not_const_check]
6+
#[inline]
7+
pub const fn ptr_guaranteed_cmp<T>(ptr: *const T, other: *const T) -> u8 {
8+
(ptr == other) as u8
9+
}
10+
11+
fn main() {
12+
ptr_guaranteed_cmp::<()>(std::ptr::null(), std::ptr::null());
13+
//~^ ERROR: can only use intrinsic fallback bodies that preserve UB
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: unsupported operation: miri can only use intrinsic fallback bodies that preserve UB. After verifying that `ptr_guaranteed_cmp` does so, add the `#[miri::intrinsic_fallback_checks_ub]` attribute to it
2+
--> $DIR/intrinsic_fallback_checks_ub.rs:LL:CC
3+
|
4+
LL | ptr_guaranteed_cmp::<()>(std::ptr::null(), std::ptr::null());
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ miri can only use intrinsic fallback bodies that preserve UB. After verifying that `ptr_guaranteed_cmp` does so, add the `#[miri::intrinsic_fallback_checks_ub]` attribute to it
6+
|
7+
= help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support
8+
= note: BACKTRACE:
9+
= note: inside `main` at $DIR/intrinsic_fallback_checks_ub.rs:LL:CC
10+
11+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
12+
13+
error: aborting due to 1 previous error
14+

0 commit comments

Comments
 (0)