about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <bjorn3@users.noreply.github.com>2022-01-30 18:23:01 +0100
committerbjorn3 <bjorn3@users.noreply.github.com>2022-01-30 18:23:01 +0100
commitbb1b5cdde26cc5055fb6b3f1a5ff22a1e16db72b (patch)
tree87a9eb57a10678324cd5ddd393bbd3d23dbeee89
parent5efd7782b33e396a8206fb7c919bede2a3a03a75 (diff)
downloadrust-bb1b5cdde26cc5055fb6b3f1a5ff22a1e16db72b.tar.gz
rust-bb1b5cdde26cc5055fb6b3f1a5ff22a1e16db72b.zip
Remove validate_atomic_type
By expanding it in place. Also extract a common
report_atomic_type_validation_error function to reduce code duplication.
-rw-r--r--src/intrinsics/mod.rs144
1 files changed, 114 insertions, 30 deletions
diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs
index 3429a7a03aa..a93887a7605 100644
--- a/src/intrinsics/mod.rs
+++ b/src/intrinsics/mod.rs
@@ -62,22 +62,21 @@ macro intrinsic_match {
     }
 }
 
-macro validate_atomic_type($fx:ident, $intrinsic:ident, $span:ident, $ty:expr) {
-    match $ty.kind() {
-        ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
-        _ => {
-            $fx.tcx.sess.span_err(
-                $span,
-                &format!(
-                    "`{}` intrinsic: expected basic integer or raw pointer type, found `{:?}`",
-                    $intrinsic, $ty
-                ),
-            );
-            // Prevent verifier error
-            crate::trap::trap_unreachable($fx, "compilation should not have succeeded");
-            return;
-        }
-    }
+fn report_atomic_type_validation_error<'tcx>(
+    fx: &mut FunctionCx<'_, '_, 'tcx>,
+    intrinsic: Symbol,
+    span: Span,
+    ty: Ty<'tcx>,
+) {
+    fx.tcx.sess.span_err(
+        span,
+        &format!(
+            "`{}` intrinsic: expected basic integer or raw pointer type, found `{:?}`",
+            intrinsic, ty
+        ),
+    );
+    // Prevent verifier error
+    crate::trap::trap_unreachable(fx, "compilation should not have succeeded");
 }
 
 pub(crate) fn clif_vector_type<'tcx>(tcx: TyCtxt<'tcx>, layout: TyAndLayout<'tcx>) -> Option<Type> {
@@ -743,7 +742,13 @@ fn codegen_regular_intrinsic_call<'tcx>(
         };
         _ if intrinsic.as_str().starts_with("atomic_load"), (v ptr) {
             let ty = substs.type_at(0);
-            validate_atomic_type!(fx, intrinsic, span, ty);
+            match ty.kind() {
+                ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
+                _ => {
+                    report_atomic_type_validation_error(fx, intrinsic, span, ty);
+                    return;
+                }
+            }
             let clif_ty = fx.clif_type(ty).unwrap();
 
             let val = fx.bcx.ins().atomic_load(clif_ty, MemFlags::trusted(), ptr);
@@ -752,7 +757,14 @@ fn codegen_regular_intrinsic_call<'tcx>(
             ret.write_cvalue(fx, val);
         };
         _ if intrinsic.as_str().starts_with("atomic_store"), (v ptr, c val) {
-            validate_atomic_type!(fx, intrinsic, span, val.layout().ty);
+            let ty = substs.type_at(0);
+            match ty.kind() {
+                ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
+                _ => {
+                    report_atomic_type_validation_error(fx, intrinsic, span, ty);
+                    return;
+                }
+            }
 
             let val = val.load_scalar(fx);
 
@@ -760,7 +772,13 @@ fn codegen_regular_intrinsic_call<'tcx>(
         };
         _ if intrinsic.as_str().starts_with("atomic_xchg"), (v ptr, c new) {
             let layout = new.layout();
-            validate_atomic_type!(fx, intrinsic, span, layout.ty);
+            match layout.ty.kind() {
+                ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
+                _ => {
+                    report_atomic_type_validation_error(fx, intrinsic, span, layout.ty);
+                    return;
+                }
+            }
             let ty = fx.clif_type(layout.ty).unwrap();
 
             let new = new.load_scalar(fx);
@@ -772,7 +790,13 @@ fn codegen_regular_intrinsic_call<'tcx>(
         };
         _ if intrinsic.as_str().starts_with("atomic_cxchg"), (v ptr, c test_old, c new) { // both atomic_cxchg_* and atomic_cxchgweak_*
             let layout = new.layout();
-            validate_atomic_type!(fx, intrinsic, span, layout.ty);
+            match layout.ty.kind() {
+                ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
+                _ => {
+                    report_atomic_type_validation_error(fx, intrinsic, span, layout.ty);
+                    return;
+                }
+            }
 
             let test_old = test_old.load_scalar(fx);
             let new = new.load_scalar(fx);
@@ -786,7 +810,13 @@ fn codegen_regular_intrinsic_call<'tcx>(
 
         _ if intrinsic.as_str().starts_with("atomic_xadd"), (v ptr, c amount) {
             let layout = amount.layout();
-            validate_atomic_type!(fx, intrinsic, span, layout.ty);
+            match layout.ty.kind() {
+                ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
+                _ => {
+                    report_atomic_type_validation_error(fx, intrinsic, span, layout.ty);
+                    return;
+                }
+            }
             let ty = fx.clif_type(layout.ty).unwrap();
 
             let amount = amount.load_scalar(fx);
@@ -798,7 +828,13 @@ fn codegen_regular_intrinsic_call<'tcx>(
         };
         _ if intrinsic.as_str().starts_with("atomic_xsub"), (v ptr, c amount) {
             let layout = amount.layout();
-            validate_atomic_type!(fx, intrinsic, span, layout.ty);
+            match layout.ty.kind() {
+                ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
+                _ => {
+                    report_atomic_type_validation_error(fx, intrinsic, span, layout.ty);
+                    return;
+                }
+            }
             let ty = fx.clif_type(layout.ty).unwrap();
 
             let amount = amount.load_scalar(fx);
@@ -810,7 +846,13 @@ fn codegen_regular_intrinsic_call<'tcx>(
         };
         _ if intrinsic.as_str().starts_with("atomic_and"), (v ptr, c src) {
             let layout = src.layout();
-            validate_atomic_type!(fx, intrinsic, span, layout.ty);
+            match layout.ty.kind() {
+                ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
+                _ => {
+                    report_atomic_type_validation_error(fx, intrinsic, span, layout.ty);
+                    return;
+                }
+            }
             let ty = fx.clif_type(layout.ty).unwrap();
 
             let src = src.load_scalar(fx);
@@ -822,7 +864,13 @@ fn codegen_regular_intrinsic_call<'tcx>(
         };
         _ if intrinsic.as_str().starts_with("atomic_or"), (v ptr, c src) {
             let layout = src.layout();
-            validate_atomic_type!(fx, intrinsic, span, layout.ty);
+            match layout.ty.kind() {
+                ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
+                _ => {
+                    report_atomic_type_validation_error(fx, intrinsic, span, layout.ty);
+                    return;
+                }
+            }
             let ty = fx.clif_type(layout.ty).unwrap();
 
             let src = src.load_scalar(fx);
@@ -834,7 +882,13 @@ fn codegen_regular_intrinsic_call<'tcx>(
         };
         _ if intrinsic.as_str().starts_with("atomic_xor"), (v ptr, c src) {
             let layout = src.layout();
-            validate_atomic_type!(fx, intrinsic, span, layout.ty);
+            match layout.ty.kind() {
+                ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
+                _ => {
+                    report_atomic_type_validation_error(fx, intrinsic, span, layout.ty);
+                    return;
+                }
+            }
             let ty = fx.clif_type(layout.ty).unwrap();
 
             let src = src.load_scalar(fx);
@@ -846,7 +900,13 @@ fn codegen_regular_intrinsic_call<'tcx>(
         };
         _ if intrinsic.as_str().starts_with("atomic_nand"), (v ptr, c src) {
             let layout = src.layout();
-            validate_atomic_type!(fx, intrinsic, span, layout.ty);
+            match layout.ty.kind() {
+                ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
+                _ => {
+                    report_atomic_type_validation_error(fx, intrinsic, span, layout.ty);
+                    return;
+                }
+            }
             let ty = fx.clif_type(layout.ty).unwrap();
 
             let src = src.load_scalar(fx);
@@ -858,7 +918,13 @@ fn codegen_regular_intrinsic_call<'tcx>(
         };
         _ if intrinsic.as_str().starts_with("atomic_max"), (v ptr, c src) {
             let layout = src.layout();
-            validate_atomic_type!(fx, intrinsic, span, layout.ty);
+            match layout.ty.kind() {
+                ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
+                _ => {
+                    report_atomic_type_validation_error(fx, intrinsic, span, layout.ty);
+                    return;
+                }
+            }
             let ty = fx.clif_type(layout.ty).unwrap();
 
             let src = src.load_scalar(fx);
@@ -870,7 +936,13 @@ fn codegen_regular_intrinsic_call<'tcx>(
         };
         _ if intrinsic.as_str().starts_with("atomic_umax"), (v ptr, c src) {
             let layout = src.layout();
-            validate_atomic_type!(fx, intrinsic, span, layout.ty);
+            match layout.ty.kind() {
+                ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
+                _ => {
+                    report_atomic_type_validation_error(fx, intrinsic, span, layout.ty);
+                    return;
+                }
+            }
             let ty = fx.clif_type(layout.ty).unwrap();
 
             let src = src.load_scalar(fx);
@@ -882,7 +954,13 @@ fn codegen_regular_intrinsic_call<'tcx>(
         };
         _ if intrinsic.as_str().starts_with("atomic_min"), (v ptr, c src) {
             let layout = src.layout();
-            validate_atomic_type!(fx, intrinsic, span, layout.ty);
+            match layout.ty.kind() {
+                ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
+                _ => {
+                    report_atomic_type_validation_error(fx, intrinsic, span, layout.ty);
+                    return;
+                }
+            }
             let ty = fx.clif_type(layout.ty).unwrap();
 
             let src = src.load_scalar(fx);
@@ -894,7 +972,13 @@ fn codegen_regular_intrinsic_call<'tcx>(
         };
         _ if intrinsic.as_str().starts_with("atomic_umin"), (v ptr, c src) {
             let layout = src.layout();
-            validate_atomic_type!(fx, intrinsic, span, layout.ty);
+            match layout.ty.kind() {
+                ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
+                _ => {
+                    report_atomic_type_validation_error(fx, intrinsic, span, layout.ty);
+                    return;
+                }
+            }
             let ty = fx.clif_type(layout.ty).unwrap();
 
             let src = src.load_scalar(fx);