Skip to content

Commit

Permalink
Added clarification regarding rust_try_inner.
Browse files Browse the repository at this point in the history
  • Loading branch information
vadimcn committed Aug 6, 2014
1 parent cb55279 commit cd2003f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
19 changes: 13 additions & 6 deletions src/librustrt/unwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,19 @@ fn rust_exception_class() -> uw::_Unwind_Exception_Class {
//
// This is pretty close to Rust's exception handling approach, except that Rust
// does have a single "catch-all" handler at the bottom of each task's stack.
// So we have two versions:
// So we have two versions of the personality routine:
// - rust_eh_personality, used by all cleanup landing pads, which never catches,
// so the behavior of __gcc_personality_v0 is perfectly adequate there, and
// - rust_eh_personality_catch, used only by rust_try(), which always catches.
// This is achieved by overriding the return value in search phase to always
// say "catch!".
//
// Note, however, that for implementation simplicity, rust_eh_personality_catch
// lacks code to install a landing pad, so in order to obtain exception object
// pointer (which it needs to return upstream), rust_try() employs another trick:
// it calls into the nested rust_try_inner(), whose landing pad does not resume
// unwinds. Instead, it extracts the exception pointer and performs a "normal"
// return.
//
// See also: rt/rust_try.ll

#[cfg(not(target_arch = "arm"), not(windows, target_arch = "x86_64"), not(test))]
#[doc(hidden)]
Expand Down Expand Up @@ -334,7 +341,8 @@ pub mod eabi {

// ARM EHABI uses a slightly different personality routine signature,
// but otherwise works the same.
#[cfg(target_arch = "arm", not(target_os = "ios", not(test)))]
#[cfg(target_arch = "arm", not(target_os = "ios"), not(test))]
#[doc(hidden)]
#[allow(visible_private_types)]
pub mod eabi {
use uw = libunwind;
Expand Down Expand Up @@ -384,10 +392,9 @@ pub mod eabi {
// with an "API translator" layer (_GCC_specific_handler).

#[cfg(windows, target_arch = "x86_64", not(test))]
#[doc(hidden)]
#[allow(visible_private_types)]
#[allow(non_camel_case_types)]
#[allow(unused_variable)]
#[allow(uppercase_variables)]
pub mod eabi {
use uw = libunwind;
use libc::{c_void, c_int};
Expand Down
3 changes: 2 additions & 1 deletion src/rt/rust_try.ll
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
; Rust's try-catch
; When f(...) returns normally, the return value is null.
; When f(...) throws, the return value is a pointer to the caught exception object.

; See also: librustrt/unwind.rs

define i8* @rust_try(void (i8*,i8*)* %f, i8* %fptr, i8* %env) {
Expand All @@ -25,7 +26,7 @@ normal:
catch:
landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @rust_eh_personality_catch to i8*)
catch i8* null
; execution will never reach here because rust_try_inner's landing pad does not resume unwinds
; rust_try_inner's landing pad does not resume unwinds, so execution will never reach here
ret i8* null
}

Expand Down
2 changes: 1 addition & 1 deletion src/rustllvm/llvm-auto-clean-trigger
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# If this file is modified, then llvm will be forcibly cleaned and then rebuilt.
# The actual contents of this file do not matter, but to trigger a change on the
# build bots then the contents should be changed so git updates the mtime.
2014-08-24
2014-08-05

0 comments on commit cd2003f

Please sign in to comment.