Skip to content

Commit cd2003f

Browse files
committed
Added clarification regarding rust_try_inner.
1 parent cb55279 commit cd2003f

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

Diff for: src/librustrt/unwind.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,19 @@ fn rust_exception_class() -> uw::_Unwind_Exception_Class {
220220
//
221221
// This is pretty close to Rust's exception handling approach, except that Rust
222222
// does have a single "catch-all" handler at the bottom of each task's stack.
223-
// So we have two versions:
223+
// So we have two versions of the personality routine:
224224
// - rust_eh_personality, used by all cleanup landing pads, which never catches,
225225
// so the behavior of __gcc_personality_v0 is perfectly adequate there, and
226226
// - rust_eh_personality_catch, used only by rust_try(), which always catches.
227-
// This is achieved by overriding the return value in search phase to always
228-
// say "catch!".
227+
//
228+
// Note, however, that for implementation simplicity, rust_eh_personality_catch
229+
// lacks code to install a landing pad, so in order to obtain exception object
230+
// pointer (which it needs to return upstream), rust_try() employs another trick:
231+
// it calls into the nested rust_try_inner(), whose landing pad does not resume
232+
// unwinds. Instead, it extracts the exception pointer and performs a "normal"
233+
// return.
234+
//
235+
// See also: rt/rust_try.ll
229236

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

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

386394
#[cfg(windows, target_arch = "x86_64", not(test))]
395+
#[doc(hidden)]
387396
#[allow(visible_private_types)]
388397
#[allow(non_camel_case_types)]
389-
#[allow(unused_variable)]
390-
#[allow(uppercase_variables)]
391398
pub mod eabi {
392399
use uw = libunwind;
393400
use libc::{c_void, c_int};

Diff for: src/rt/rust_try.ll

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
; Rust's try-catch
1212
; When f(...) returns normally, the return value is null.
1313
; When f(...) throws, the return value is a pointer to the caught exception object.
14+
1415
; See also: librustrt/unwind.rs
1516

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

Diff for: src/rustllvm/llvm-auto-clean-trigger

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# If this file is modified, then llvm will be forcibly cleaned and then rebuilt.
22
# The actual contents of this file do not matter, but to trigger a change on the
33
# build bots then the contents should be changed so git updates the mtime.
4-
2014-08-24
4+
2014-08-05

0 commit comments

Comments
 (0)