Skip to content

Commit

Permalink
Add -Zmutable-noalias flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Gankra committed Oct 3, 2017
1 parent 4502e2a commit 3647129
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/librustc/session/config.rs
Expand Up @@ -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],
Expand Down
11 changes: 10 additions & 1 deletion src/librustc_trans/abi.rs
Expand Up @@ -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);
}

Expand Down

0 comments on commit 3647129

Please sign in to comment.