@@ -49,9 +49,15 @@ impl<'c> Translation<'c> {
4949 fn atomic_intrinsic_expr_edition_2024 (
5050 & self ,
5151 base_name : & str ,
52- num_ty_params : usize ,
5352 orders : & [ Ordering ] ,
5453 ) -> Box < Expr > {
54+ let num_ty_params = match base_name {
55+ "fence" => 0 ,
56+ "load" | "store" | "xchg" | "cxchg" | "cxchgweak" => 1 ,
57+ "xadd" | "xsub" | "or" | "xor" | "nand" | "and" => 2 ,
58+ _ => unimplemented ! ( "unknown atomic intrinsic: {base_name}" ) ,
59+ } ;
60+
5561 let args = repeat_n ( "_" . to_owned ( ) , num_ty_params)
5662 . chain ( orders. iter ( ) . map ( |& order| {
5763 let order = order_ty_name ( order) ;
@@ -66,12 +72,7 @@ impl<'c> Translation<'c> {
6672 Box :: new ( expr)
6773 }
6874
69- pub fn atomic_intrinsic_expr (
70- & self ,
71- base_name : & str ,
72- num_ty_params : usize ,
73- orders : & [ Ordering ] ,
74- ) -> Box < Expr > {
75+ pub fn atomic_intrinsic_expr ( & self , base_name : & str , orders : & [ Ordering ] ) -> Box < Expr > {
7576 assert ! ( matches!(
7677 orders,
7778 & [ _ /* order */ ] | & [ _ /* order_succ */ , _ /* order_fail */ ]
@@ -81,7 +82,7 @@ impl<'c> Translation<'c> {
8182 if self . tcfg . edition < Edition2024 {
8283 self . atomic_intrinsic_expr_edition_2021 ( base_name, orders)
8384 } else {
84- self . atomic_intrinsic_expr_edition_2024 ( base_name, num_ty_params , orders)
85+ self . atomic_intrinsic_expr_edition_2024 ( base_name, orders)
8586 }
8687 }
8788
@@ -92,7 +93,7 @@ impl<'c> Translation<'c> {
9293 order_fail : Ordering ,
9394 ) -> Box < Expr > {
9495 let base = if weak { "cxchgweak" } else { "cxchg" } ;
95- self . atomic_intrinsic_expr ( base, 1 , & [ order_succ, order_fail] )
96+ self . atomic_intrinsic_expr ( base, & [ order_succ, order_fail] )
9697 }
9798
9899 fn convert_constant_bool ( & self , expr : CExprId ) -> Option < bool > {
@@ -165,7 +166,7 @@ impl<'c> Translation<'c> {
165166 "__atomic_load" | "__atomic_load_n" | "__c11_atomic_load" => ptr. and_then ( |ptr| {
166167 let order = static_order ( order) ;
167168
168- let atomic_load = self . atomic_intrinsic_expr ( "load" , 1 , & [ order] ) ;
169+ let atomic_load = self . atomic_intrinsic_expr ( "load" , & [ order] ) ;
169170 let call = mk ( ) . call_expr ( atomic_load, vec ! [ ptr] ) ;
170171 if name == "__atomic_load" {
171172 let ret = val1. expect ( "__atomic_load should have a ret argument" ) ;
@@ -194,7 +195,7 @@ impl<'c> Translation<'c> {
194195 let val = val1. expect ( "__atomic_store must have a val argument" ) ;
195196 ptr. and_then ( |ptr| {
196197 val. and_then ( |val| {
197- let atomic_store = self . atomic_intrinsic_expr ( "store" , 1 , & [ order] ) ;
198+ let atomic_store = self . atomic_intrinsic_expr ( "store" , & [ order] ) ;
198199 let val = if name == "__atomic_store" {
199200 mk ( ) . unary_expr ( UnOp :: Deref ( Default :: default ( ) ) , val)
200201 } else {
@@ -233,7 +234,7 @@ impl<'c> Translation<'c> {
233234 let val = val1. expect ( "__atomic_store must have a val argument" ) ;
234235 ptr. and_then ( |ptr| {
235236 val. and_then ( |val| {
236- let fn_path = self . atomic_intrinsic_expr ( "xchg" , 1 , & [ order] ) ;
237+ let fn_path = self . atomic_intrinsic_expr ( "xchg" , & [ order] ) ;
237238 let val = if name == "__atomic_exchange" {
238239 mk ( ) . unary_expr ( UnOp :: Deref ( Default :: default ( ) ) , val)
239240 } else {
@@ -425,7 +426,7 @@ impl<'c> Translation<'c> {
425426 fetch_first : bool ,
426427 ) -> TranslationResult < WithStmts < Box < Expr > > > {
427428 // Emit `atomic_func(a0, a1) (op a1)?`
428- let atomic_func = self . atomic_intrinsic_expr ( base_name, 2 , & [ order] ) ;
429+ let atomic_func = self . atomic_intrinsic_expr ( base_name, & [ order] ) ;
429430
430431 if fetch_first {
431432 let call_expr = mk ( ) . call_expr ( atomic_func, vec ! [ dst, src] ) ;
0 commit comments