Skip to content

Commit

Permalink
Auto merge of #45012 - Gankro:noalias, r=arielb1
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
bors committed Oct 8, 2017
2 parents 108706f + a6dea41 commit ff8e264
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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
13 changes: 12 additions & 1 deletion src/librustc_trans/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit ff8e264

Please sign in to comment.