diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 36b74cbcb4f..9ff52496dab 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1051,6 +1051,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, "print the result of the translation item collection pass"), mir_opt_level: usize = (1, parse_uint, [TRACKED], "set the MIR optimization level (0-3, default: 1)"), + mutable_noalias: bool = (false, parse_bool, [UNTRACKED], + "emit noalias metadata for mutable references"), dump_mir: Option = (None, parse_opt_string, [UNTRACKED], "dump MIR state at various points in translation"), dump_mir_dir: Option = (None, parse_opt_string, [UNTRACKED], diff --git a/src/librustc_trans/abi.rs b/src/librustc_trans/abi.rs index 2aecc016a5c..ee295bdf0b4 100644 --- a/src/librustc_trans/abi.rs +++ b/src/librustc_trans/abi.rs @@ -37,6 +37,7 @@ use type_of; use rustc::hir; use rustc::ty::{self, Ty}; use rustc::ty::layout::{self, Layout, LayoutTyper, TyLayout, Size}; +use rustc_back::PanicStrategy; use libc::c_uint; use std::cmp; @@ -760,7 +761,17 @@ impl<'a, 'tcx> FnType<'tcx> { // on memory dependencies rather than pointer equality let is_freeze = ccx.shared().type_is_freeze(mt.ty); - if mt.mutbl != hir::MutMutable && is_freeze { + let no_alias_is_safe = + if ccx.shared().tcx().sess.opts.debugging_opts.mutable_noalias || + ccx.shared().tcx().sess.panic_strategy() == PanicStrategy::Abort { + // Mutable refrences or immutable shared references + mt.mutbl == hir::MutMutable || is_freeze + } else { + // Only immutable shared references + mt.mutbl != hir::MutMutable && is_freeze + }; + + if no_alias_is_safe { arg.attrs.set(ArgAttribute::NoAlias); }