1
1
use rustc_middle:: mir:: BinOp ;
2
+ use rustc_middle:: ty:: AtomicOrdering ;
2
3
use rustc_middle:: { mir, ty} ;
3
4
4
5
use self :: helpers:: check_intrinsic_arg_count;
@@ -19,6 +20,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
19
20
fn emulate_atomic_intrinsic (
20
21
& mut self ,
21
22
intrinsic_name : & str ,
23
+ generic_args : ty:: GenericArgsRef < ' tcx > ,
22
24
args : & [ OpTy < ' tcx > ] ,
23
25
dest : & MPlaceTy < ' tcx > ,
24
26
) -> InterpResult < ' tcx , EmulateItemResult > {
@@ -35,6 +37,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
35
37
}
36
38
}
37
39
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
+
38
49
fn write_ord ( ord : & str ) -> AtomicWriteOrd {
39
50
match ord {
40
51
"seqcst" => AtomicWriteOrd :: SeqCst ,
@@ -66,7 +77,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
66
77
}
67
78
68
79
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
70
89
[ "store" , ord] => this. atomic_store ( args, write_ord ( ord) ) ?,
71
90
72
91
[ "fence" , ord] => this. atomic_fence_intrinsic ( args, fence_ord ( ord) ) ?,
0 commit comments