Skip to content

Commit 3647129

Browse files
committed
Add -Zmutable-noalias flag
1 parent 4502e2a commit 3647129

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/librustc/session/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
10601060
"print the result of the translation item collection pass"),
10611061
mir_opt_level: usize = (1, parse_uint, [TRACKED],
10621062
"set the MIR optimization level (0-3, default: 1)"),
1063+
mutable_noalias: bool = (false, parse_bool, [UNTRACKED],
1064+
"emit noalias metadata for mutable references"),
10631065
dump_mir: Option<String> = (None, parse_opt_string, [UNTRACKED],
10641066
"dump MIR state at various points in translation"),
10651067
dump_mir_dir: Option<String> = (None, parse_opt_string, [UNTRACKED],

src/librustc_trans/abi.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,16 @@ impl<'a, 'tcx> FnType<'tcx> {
760760
// on memory dependencies rather than pointer equality
761761
let is_freeze = ccx.shared().type_is_freeze(mt.ty);
762762

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

0 commit comments

Comments
 (0)