]> git.proxmox.com Git - rustc.git/blobdiff - src/librustc_trans/mir/block.rs
New upstream version 1.23.0+dfsg1
[rustc.git] / src / librustc_trans / mir / block.rs
index 591aa974666cce89dbff36feafed0bebb0424d6f..bd26c961bb28b59558f7b85ce5e130d56f9dedca 100644 (file)
@@ -524,7 +524,16 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
                         }
                     }
 
-                    let op = self.trans_operand(&bcx, arg);
+                    let mut op = self.trans_operand(&bcx, arg);
+
+                    // The callee needs to own the argument memory if we pass it
+                    // by-ref, so make a local copy of non-immediate constants.
+                    if let (&mir::Operand::Constant(_), Ref(..)) = (arg, op.val) {
+                        let tmp = LvalueRef::alloca(&bcx, op.ty, "const");
+                        self.store_operand(&bcx, tmp.llval, tmp.alignment.to_align(), op);
+                        op.val = Ref(tmp.llval, tmp.alignment);
+                    }
+
                     self.trans_argument(&bcx, op, &mut llargs, &fn_ty,
                                         &mut idx, &mut llfn, &def);
                 }
@@ -583,7 +592,8 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
                         cleanup);
             }
             mir::TerminatorKind::GeneratorDrop |
-            mir::TerminatorKind::Yield { .. } => bug!("generator ops in trans"),
+            mir::TerminatorKind::Yield { .. } |
+            mir::TerminatorKind::FalseEdges { .. } => bug!("generator ops in trans"),
         }
     }