about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMark-Simulacrum <mark.simulacrum@gmail.com>2016-12-14 09:26:27 -0700
committerMark Simulacrum <mark.simulacrum@gmail.com>2016-12-20 20:02:50 -0700
commitcd57bbe27abac8ece0b927f9ab830ef98f7927e3 (patch)
tree4cad899771a5a992fc098e322cfa935e0f34dde9 /src
parent28d00e781bbe111d3c9f7a864e6ecdd3d29bcfa9 (diff)
downloadrust-cd57bbe27abac8ece0b927f9ab830ef98f7927e3.tar.gz
rust-cd57bbe27abac8ece0b927f9ab830ef98f7927e3.zip
Refactor get_landing_pad to take a CleanupScope
It unwrapped the Option anyway, so this more closely resembles the
reality of what's happening.
Diffstat (limited to 'src')
-rw-r--r--src/librustc_trans/callee.rs2
-rw-r--r--src/librustc_trans/cleanup.rs50
-rw-r--r--src/librustc_trans/glue.rs2
3 files changed, 24 insertions, 30 deletions
diff --git a/src/librustc_trans/callee.rs b/src/librustc_trans/callee.rs
index 1a4afb4b02e..982a8e9514c 100644
--- a/src/librustc_trans/callee.rs
+++ b/src/librustc_trans/callee.rs
@@ -743,7 +743,7 @@ fn trans_call_fn_once_adapter_shim<'a, 'blk, 'tcx>(
     let _icx = push_ctxt("invoke_");
     let (llret, bcx) = if cleanup_scope.is_some() && !bcx.sess().no_landing_pads() {
         let normal_bcx = bcx.fcx().build_new_block("normal-return");
-        let landing_pad = bcx.fcx().get_landing_pad(cleanup_scope);
+        let landing_pad = bcx.fcx().get_landing_pad(cleanup_scope.as_mut().unwrap());
 
         let llresult = bcx.invoke(llfn, &llargs[..], normal_bcx.llbb(), landing_pad, None);
         (llresult, normal_bcx)
diff --git a/src/librustc_trans/cleanup.rs b/src/librustc_trans/cleanup.rs
index d9e8b795cb1..f1ca228035a 100644
--- a/src/librustc_trans/cleanup.rs
+++ b/src/librustc_trans/cleanup.rs
@@ -207,14 +207,10 @@ impl<'blk, 'tcx> FunctionContext<'blk, 'tcx> {
     ///
     /// (The cleanups and resume instruction are created by
     /// `trans_cleanups_to_exit_scope()`, not in this function itself.)
-    pub fn get_landing_pad(&'blk self, scope: &mut Option<CleanupScope<'tcx>>) -> BasicBlockRef {
-        // TODO: Factor out and take a CleanupScope.
-        assert!(scope.is_some());
-
+    pub fn get_landing_pad(&'blk self, scope: &mut CleanupScope<'tcx>) -> BasicBlockRef {
         debug!("get_landing_pad");
 
         // Check if a landing pad block exists; if not, create one.
-        let mut scope = scope.as_mut().unwrap();
         let mut pad_bcx = match scope.cached_landing_pad {
             Some(llbb) => return llbb,
             None => {
@@ -270,28 +266,6 @@ impl<'blk, 'tcx> FunctionContext<'blk, 'tcx> {
         return pad_bcx.llbb();
     }
 
-    fn generate_resume_block(&self, label: UnwindKind) -> BasicBlockRef {
-        // Generate a block that will resume unwinding to the calling function
-        let bcx = self.build_new_block("resume");
-        match label {
-            UnwindKind::LandingPad => {
-                let addr = self.landingpad_alloca.get().unwrap();
-                let lp = bcx.load(addr);
-                Lifetime::End.call(&bcx, addr);
-                if !bcx.sess().target.target.options.custom_unwind_resume {
-                    bcx.resume(lp);
-                } else {
-                    let exc_ptr = bcx.extract_value(lp, 0);
-                    bcx.call(bcx.fcx().eh_unwind_resume().reify(bcx.ccx()), &[exc_ptr], None);
-                }
-            }
-            UnwindKind::CleanupPad(_) => {
-                bcx.cleanup_ret(bcx.cleanup_pad(None, &[]), None);
-            }
-        }
-        bcx.llbb()
-    }
-
     /// Used when the caller wishes to jump to an early exit, such as a return,
     /// break, continue, or unwind. This function will generate all cleanups
     /// between the top of the stack and the exit `label` and return a basic
@@ -306,7 +280,27 @@ impl<'blk, 'tcx> FunctionContext<'blk, 'tcx> {
 
         // Check if we have already cached the unwinding of this
         // scope for this label. If so, we can just branch to the cached block.
-        let exit_llbb = cached_exit.unwrap_or_else(|| self.generate_resume_block(label));
+        let exit_llbb = cached_exit.unwrap_or_else(|| {
+            // Generate a block that will resume unwinding to the calling function
+            let bcx = self.build_new_block("resume");
+            match label {
+                UnwindKind::LandingPad => {
+                    let addr = self.landingpad_alloca.get().unwrap();
+                    let lp = bcx.load(addr);
+                    Lifetime::End.call(&bcx, addr);
+                    if !bcx.sess().target.target.options.custom_unwind_resume {
+                        bcx.resume(lp);
+                    } else {
+                        let exc_ptr = bcx.extract_value(lp, 0);
+                        bcx.call(bcx.fcx().eh_unwind_resume().reify(bcx.ccx()), &[exc_ptr], None);
+                    }
+                }
+                UnwindKind::CleanupPad(_) => {
+                    bcx.cleanup_ret(bcx.cleanup_pad(None, &[]), None);
+                }
+            }
+            bcx.llbb()
+        });
 
         let name = scope.block_name("clean");
         debug!("generating cleanup for {}", name);
diff --git a/src/librustc_trans/glue.rs b/src/librustc_trans/glue.rs
index dc3f75d52b9..549f1db22e7 100644
--- a/src/librustc_trans/glue.rs
+++ b/src/librustc_trans/glue.rs
@@ -312,7 +312,7 @@ fn trans_call_custom_dtor<'a, 'blk, 'tcx>(
     let _icx = push_ctxt("invoke_");
     let (llret, bcx) = if cleanup_scope.is_some() && !bcx.sess().no_landing_pads() {
         let normal_bcx = bcx.fcx().build_new_block("normal-return");
-        let landing_pad = bcx.fcx().get_landing_pad(cleanup_scope);
+        let landing_pad = bcx.fcx().get_landing_pad(cleanup_scope.as_mut().unwrap());
 
         let llresult = bcx.invoke(llfn, &llargs[..], normal_bcx.llbb(), landing_pad, None);
         (llresult, normal_bcx)