]> git.lizzy.rs Git - rust.git/blobdiff - src/base.rs
Rustup to rustc 1.46.0-nightly (7750c3d46 2020-06-26)
[rust.git] / src / base.rs
index b3751a02029434fd948965780108d025944002d0..8d2087b352831897b376811f3933f01eac027b0e 100644 (file)
@@ -3,8 +3,8 @@
 
 use crate::prelude::*;
 
-pub(crate) fn trans_fn<'clif, 'tcx, B: Backend + 'static>(
-    cx: &mut crate::CodegenCx<'clif, 'tcx, B>,
+pub(crate) fn trans_fn<'tcx, B: Backend + 'static>(
+    cx: &mut crate::CodegenCx<'tcx, B>,
     instance: Instance<'tcx>,
     linkage: Linkage,
 ) {
@@ -15,10 +15,6 @@ pub(crate) fn trans_fn<'clif, 'tcx, B: Backend + 'static>(
     // Declare function
     let (name, sig) = get_function_name_and_sig(tcx, cx.module.isa().triple(), instance, false);
     let func_id = cx.module.declare_function(&name, linkage, &sig).unwrap();
-    let mut debug_context = cx
-        .debug_context
-        .as_mut()
-        .map(|debug_context| FunctionDebugContext::new(debug_context, instance, func_id, &name));
 
     // Make FunctionBuilder
     let context = &mut cx.cached_context;
@@ -39,7 +35,7 @@ pub(crate) fn trans_fn<'clif, 'tcx, B: Backend + 'static>(
 
     let mut fx = FunctionCx {
         tcx,
-        module: cx.module,
+        module: &mut cx.module,
         pointer_type,
 
         instance,
@@ -65,7 +61,7 @@ pub(crate) fn trans_fn<'clif, 'tcx, B: Backend + 'static>(
         crate::trap::trap_unreachable(&mut fx, "function has uninhabited argument");
     } else {
         tcx.sess.time("codegen clif ir", || {
-            tcx.sess.time("codegen prelude", || crate::abi::codegen_fn_prelude(&mut fx, start_block, true));
+            tcx.sess.time("codegen prelude", || crate::abi::codegen_fn_prelude(&mut fx, start_block));
             codegen_fn_content(&mut fx);
         });
     }
@@ -77,8 +73,14 @@ pub(crate) fn trans_fn<'clif, 'tcx, B: Backend + 'static>(
     let local_map = fx.local_map;
     let cold_blocks = fx.cold_blocks;
 
-    #[cfg(debug_assertions)]
-    crate::pretty_clif::write_clif_file(cx.tcx, "unopt", instance, &context.func, &clif_comments, None);
+    crate::pretty_clif::write_clif_file(
+        cx.tcx,
+        "unopt",
+        None,
+        instance,
+        &context,
+        &clif_comments,
+    );
 
     // Verify function
     verify_func(tcx, &clif_comments, &context.func);
@@ -106,29 +108,23 @@ pub(crate) fn trans_fn<'clif, 'tcx, B: Backend + 'static>(
     );
 
     // Write optimized function to file for debugging
-    #[cfg(debug_assertions)]
-    {
-        let value_ranges = context
-            .build_value_labels_ranges(cx.module.isa())
-            .expect("value location ranges");
-
-        crate::pretty_clif::write_clif_file(
-            cx.tcx,
-            "opt",
-            instance,
-            &context.func,
-            &clif_comments,
-            Some(&value_ranges),
-        );
-    }
+    crate::pretty_clif::write_clif_file(
+        cx.tcx,
+        "opt",
+        Some(cx.module.isa()),
+        instance,
+        &context,
+        &clif_comments,
+    );
 
     // Define debuginfo for function
     let isa = cx.module.isa();
+    let debug_context = &mut cx.debug_context;
     let unwind_context = &mut cx.unwind_context;
     tcx.sess.time("generate debug info", || {
-        debug_context
-            .as_mut()
-            .map(|x| x.define(context, isa, &source_info_set, local_map));
+        if let Some(debug_context) = debug_context {
+            debug_context.define_function(instance, func_id, &name, isa, context, &source_info_set, local_map);
+        }
         unwind_context.add_function(func_id, &context, isa);
     });
 
@@ -138,12 +134,12 @@ pub(crate) fn trans_fn<'clif, 'tcx, B: Backend + 'static>(
 
 pub(crate) fn verify_func(tcx: TyCtxt<'_>, writer: &crate::pretty_clif::CommentWriter, func: &Function) {
     tcx.sess.time("verify clif ir", || {
-        let flags = settings::Flags::new(settings::builder());
-        match ::cranelift_codegen::verify_function(&func, &flags) {
+        let flags = cranelift_codegen::settings::Flags::new(cranelift_codegen::settings::builder());
+        match cranelift_codegen::verify_function(&func, &flags) {
             Ok(_) => {}
             Err(err) => {
                 tcx.sess.err(&format!("{:?}", err));
-                let pretty_error = ::cranelift_codegen::print_errors::pretty_verifier_error(
+                let pretty_error = cranelift_codegen::print_errors::pretty_verifier_error(
                     &func,
                     None,
                     Some(Box::new(writer)),
@@ -223,7 +219,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Backend>) {
                 cleanup: _,
             } => {
                 if !fx.tcx.sess.overflow_checks() {
-                    if let mir::AssertKind::OverflowNeg = *msg {
+                    if let mir::AssertKind::OverflowNeg(_) = *msg {
                         let target = fx.get_block(*target);
                         fx.bcx.ins().jump(target, &[]);
                         continue;
@@ -294,12 +290,14 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Backend>) {
                 func,
                 args,
                 destination,
+                fn_span,
                 cleanup: _,
                 from_hir_call: _,
             } => {
                 fx.tcx.sess.time("codegen call", || crate::abi::codegen_terminator_call(
                     fx,
-                    bb_data.terminator().source_info.span,
+                    *fn_span,
+                    block,
                     func,
                     args,
                     *destination,
@@ -310,6 +308,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Backend>) {
                 operands,
                 options: _,
                 destination,
+                line_spans: _,
             } => {
                 match template {
                     &[] => {
@@ -324,7 +323,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Backend>) {
 
                         // Black box
                     }
-                    _ => unimpl_fatal!(fx.tcx, bb_data.terminator().source_info.span, "Inline assembly is not supported"),
+                    _ => fx.tcx.sess.span_fatal(bb_data.terminator().source_info.span, "Inline assembly is not supported"),
                 }
             }
             TerminatorKind::Resume | TerminatorKind::Abort => {
@@ -334,18 +333,18 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Backend>) {
                 trap_unreachable(fx, "[corruption] Hit unreachable code.");
             }
             TerminatorKind::Yield { .. }
-            | TerminatorKind::FalseEdges { .. }
+            | TerminatorKind::FalseEdge { .. }
             | TerminatorKind::FalseUnwind { .. }
             | TerminatorKind::DropAndReplace { .. }
             | TerminatorKind::GeneratorDrop => {
                 bug!("shouldn't exist at trans {:?}", bb_data.terminator());
             }
             TerminatorKind::Drop {
-                location,
+                place,
                 target,
                 unwind: _,
             } => {
-                let drop_place = trans_place(fx, *location);
+                let drop_place = trans_place(fx, *place);
                 crate::abi::codegen_drop(fx, bb_data.terminator().source_info.span, drop_place);
 
                 let target_block = fx.get_block(*target);
@@ -364,7 +363,7 @@ fn trans_stmt<'tcx>(
     cur_block: Block,
     stmt: &Statement<'tcx>,
 ) {
-    let _print_guard = PrintOnPanic(|| format!("stmt {:?}", stmt));
+    let _print_guard = crate::PrintOnPanic(|| format!("stmt {:?}", stmt));
 
     fx.set_debug_loc(stmt.source_info);
 
@@ -397,6 +396,10 @@ fn trans_stmt<'tcx>(
                     let place = trans_place(fx, *place);
                     place.write_place_ref(fx, lval);
                 }
+                Rvalue::ThreadLocalRef(def_id) => {
+                    let val = crate::constant::codegen_tls_ref(fx, *def_id, lval.layout());
+                    lval.write_cvalue(fx, val);
+                }
                 Rvalue::BinaryOp(bin_op, lhs, rhs) => {
                     let lhs = trans_operand(fx, lhs);
                     let rhs = trans_operand(fx, rhs);
@@ -677,7 +680,18 @@ fn is_fat_ptr<'tcx>(
 
                     crate::trap::trap_unimplemented(fx, "_xgetbv arch intrinsic is not supported");
                 }
-                _ => unimpl_fatal!(fx.tcx, stmt.source_info.span, "Inline assembly is not supported"),
+                // ___chkstk, ___chkstk_ms and __alloca are only used on Windows
+                _ if fx.tcx.symbol_name(fx.instance).name.as_str().starts_with("___chkstk") => {
+                    crate::trap::trap_unimplemented(fx, "Stack probes are not supported");
+                }
+                _ if fx.tcx.symbol_name(fx.instance).name.as_str() == "__alloca" => {
+                    crate::trap::trap_unimplemented(fx, "Alloca is not supported");
+                }
+                // Used in sys::windows::abort_internal
+                "int $$0x29" => {
+                    crate::trap::trap_unimplemented(fx, "Windows abort");
+                }
+                _ => fx.tcx.sess.span_fatal(stmt.source_info.span, "Inline assembly is not supported"),
             }
         }
     }
@@ -709,7 +723,7 @@ pub(crate) fn trans_place<'tcx>(
     let mut cplace = fx.get_local_place(place.local);
 
     for elem in place.projection {
-        match *elem {
+        match elem {
             PlaceElem::Deref => {
                 cplace = cplace.place_deref(fx);
             }