Skip to content

Commit 7b62e09

Browse files
committed
Allow disabling TrapUnreachable via -Ztrap-unreachable=no
This is useful for embedded targets where small code size is desired. For example, on my project (thumbv7em-none-eabi) this yields a 0.6% code size reduction.
1 parent d9a105f commit 7b62e09

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

compiler/rustc_codegen_llvm/src/back/write.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ pub fn target_machine_factory(
152152
let features = features.join(",");
153153
let features = CString::new(features).unwrap();
154154
let abi = SmallCStr::new(&sess.target.llvm_abiname);
155-
let trap_unreachable = sess.target.trap_unreachable;
155+
let trap_unreachable =
156+
sess.opts.debugging_opts.trap_unreachable.unwrap_or(sess.target.trap_unreachable);
156157
let emit_stack_size_section = sess.opts.debugging_opts.emit_stack_sizes;
157158

158159
let asm_comments = sess.asm_comments();

compiler/rustc_interface/src/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@ fn test_debugging_options_tracking_hash() {
592592
tracked!(thinlto, Some(true));
593593
tracked!(tune_cpu, Some(String::from("abc")));
594594
tracked!(tls_model, Some(TlsModel::GeneralDynamic));
595+
tracked!(trap_unreachable, Some(false));
595596
tracked!(treat_err_as_bug, Some(1));
596597
tracked!(unleash_the_miri_inside_of_you, true);
597598
tracked!(use_ctors_section, Some(true));

compiler/rustc_session/src/options.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
11131113
"choose the TLS model to use (`rustc --print tls-models` for details)"),
11141114
trace_macros: bool = (false, parse_bool, [UNTRACKED],
11151115
"for every macro invocation, print its name and arguments (default: no)"),
1116+
trap_unreachable: Option<bool> = (None, parse_opt_bool, [TRACKED],
1117+
"generate trap instructions for unreachable intrinsics (default: use target setting, usually yes)"),
11161118
treat_err_as_bug: Option<usize> = (None, parse_treat_err_as_bug, [TRACKED],
11171119
"treat error number `val` that occurs as bug"),
11181120
trim_diagnostic_paths: bool = (true, parse_bool, [UNTRACKED],

0 commit comments

Comments
 (0)