]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_codegen_llvm/intrinsic.rs
Change const eval to return `ConstValue`, instead of `Const` as the type inside it...
[rust.git] / src / librustc_codegen_llvm / intrinsic.rs
index 5adff0d1f9233a081ee4f1bb36eca4d4e2bbb614..341a4a77c3c0a343129296885afda4c828db8eb3 100644 (file)
@@ -193,7 +193,8 @@ fn codegen_intrinsic_call(
                     .tcx
                     .const_eval_instance(ty::ParamEnv::reveal_all(), instance, None)
                     .unwrap();
-                OperandRef::from_const(self, ty_name).immediate_or_packed_pair(self)
+                let const_ = ty::Const { val: ty::ConstKind::Value(ty_name), ty: ret_ty };
+                OperandRef::from_const(self, &const_).immediate_or_packed_pair(self)
             }
             "init" => {
                 let ty = substs.type_at(0);
@@ -952,11 +953,17 @@ fn codegen_msvc_try(
         let cs = catchswitch.catch_switch(None, None, 1);
         catchswitch.add_handler(cs, catchpad.llbb());
 
+        // The flag value of 8 indicates that we are catching the exception by
+        // reference instead of by value. We can't use catch by value because
+        // that requires copying the exception object, which we don't support
+        // since our exception object effectively contains a Box.
+        //
+        // Source: MicrosoftCXXABI::getAddrOfCXXCatchHandlerType in clang
+        let flags = bx.const_i32(8);
         let tydesc = match bx.tcx().lang_items().eh_catch_typeinfo() {
             Some(did) => bx.get_static(did),
             None => bug!("eh_catch_typeinfo not defined, but needed for SEH unwinding"),
         };
-        let flags = bx.const_i32(8); // Catch by reference
         let funclet = catchpad.catch_pad(cs, &[tydesc, flags, slot]);
 
         let i64_align = bx.tcx().data_layout.i64_align.abi;
@@ -966,6 +973,8 @@ fn codegen_msvc_try(
         catchpad.store(payload, local_ptr, i64_align);
 
         // Clear the first word of the exception so avoid double-dropping it.
+        // This will be read by the destructor which is implicitly called at the
+        // end of the catch block by the runtime.
         let payload_0_ptr = catchpad.inbounds_gep(payload_ptr, &[bx.const_i32(0), bx.const_i32(0)]);
         catchpad.store(bx.const_u64(0), payload_0_ptr, i64_align);