Add -Zmutable-noalias flag

This commit is contained in:
Alexis Beingessner 2017-10-03 19:49:45 -04:00
parent 4502e2aa9c
commit 36471293e6
2 changed files with 12 additions and 1 deletions

View file

@ -1060,6 +1060,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<String> = (None, parse_opt_string, [UNTRACKED],
"dump MIR state at various points in translation"),
dump_mir_dir: Option<String> = (None, parse_opt_string, [UNTRACKED],

View file

@ -760,7 +760,16 @@ 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 {
// 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);
}