Skip to content

Commit ff8e264

Browse files
committed
Auto merge of #45012 - Gankro:noalias, r=arielb1
Add -Zmutable-noalias flag We disabled noalias on mutable references a long time ago when it was clear that llvm was incorrectly handling this in relation to unwinding edges. Since then, a few things have happened: * llvm has cleaned up a bunch of the issues (I'm told) * we've added a nounwind codegen option As such, I would like to add this -Z flag so that we can evaluate if the codegen bugs still exist, and if this significantly affects the codegen of different projects, with an eye towards permanently re-enabling it (or at least making it a stable option).
2 parents 108706f + a6dea41 commit ff8e264

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/librustc/session/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
10511051
"print the result of the translation item collection pass"),
10521052
mir_opt_level: usize = (1, parse_uint, [TRACKED],
10531053
"set the MIR optimization level (0-3, default: 1)"),
1054+
mutable_noalias: bool = (false, parse_bool, [UNTRACKED],
1055+
"emit noalias metadata for mutable references"),
10541056
dump_mir: Option<String> = (None, parse_opt_string, [UNTRACKED],
10551057
"dump MIR state at various points in translation"),
10561058
dump_mir_dir: Option<String> = (None, parse_opt_string, [UNTRACKED],

src/librustc_trans/abi.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use type_of;
3737
use rustc::hir;
3838
use rustc::ty::{self, Ty};
3939
use rustc::ty::layout::{self, Layout, LayoutTyper, TyLayout, Size};
40+
use rustc_back::PanicStrategy;
4041

4142
use libc::c_uint;
4243
use std::cmp;
@@ -760,7 +761,17 @@ impl<'a, 'tcx> FnType<'tcx> {
760761
// on memory dependencies rather than pointer equality
761762
let is_freeze = ccx.shared().type_is_freeze(mt.ty);
762763

763-
if mt.mutbl != hir::MutMutable && is_freeze {
764+
let no_alias_is_safe =
765+
if ccx.shared().tcx().sess.opts.debugging_opts.mutable_noalias ||
766+
ccx.shared().tcx().sess.panic_strategy() == PanicStrategy::Abort {
767+
// Mutable refrences or immutable shared references
768+
mt.mutbl == hir::MutMutable || is_freeze
769+
} else {
770+
// Only immutable shared references
771+
mt.mutbl != hir::MutMutable && is_freeze
772+
};
773+
774+
if no_alias_is_safe {
764775
arg.attrs.set(ArgAttribute::NoAlias);
765776
}
766777

0 commit comments

Comments
 (0)