11use rustc_middle:: mir:: BinOp ;
2+ use rustc_middle:: ty:: AtomicOrdering ;
23use rustc_middle:: { mir, ty} ;
34
45use self :: helpers:: check_intrinsic_arg_count;
@@ -19,6 +20,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
1920 fn emulate_atomic_intrinsic (
2021 & mut self ,
2122 intrinsic_name : & str ,
23+ generic_args : ty:: GenericArgsRef < ' tcx > ,
2224 args : & [ OpTy < ' tcx > ] ,
2325 dest : & MPlaceTy < ' tcx > ,
2426 ) -> InterpResult < ' tcx , EmulateItemResult > {
@@ -35,6 +37,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
3537 }
3638 }
3739
40+ fn read_ord_const_generic ( o : AtomicOrdering ) -> AtomicReadOrd {
41+ match o {
42+ AtomicOrdering :: SeqCst => AtomicReadOrd :: SeqCst ,
43+ AtomicOrdering :: Acquire => AtomicReadOrd :: Acquire ,
44+ AtomicOrdering :: Relaxed => AtomicReadOrd :: Relaxed ,
45+ _ => panic ! ( "invalid read ordering `{o:?}`" ) ,
46+ }
47+ }
48+
3849 fn write_ord ( ord : & str ) -> AtomicWriteOrd {
3950 match ord {
4051 "seqcst" => AtomicWriteOrd :: SeqCst ,
@@ -66,7 +77,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
6677 }
6778
6879 match & * intrinsic_structure {
69- [ "load" , ord] => this. atomic_load ( args, dest, read_ord ( ord) ) ?,
80+ // New-style intrinsics that use const generics
81+ [ "load" ] => {
82+ let ordering = generic_args. const_at ( 1 ) . to_value ( ) ;
83+ let ordering =
84+ ordering. valtree . unwrap_branch ( ) [ 0 ] . unwrap_leaf ( ) . to_atomic_ordering ( ) ;
85+ this. atomic_load ( args, dest, read_ord_const_generic ( ordering) ) ?;
86+ }
87+
88+ // Old-style intrinsics that have the ordering in the intrinsic name
7089 [ "store" , ord] => this. atomic_store ( args, write_ord ( ord) ) ?,
7190
7291 [ "fence" , ord] => this. atomic_fence_intrinsic ( args, fence_ord ( ord) ) ?,
0 commit comments