about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-10-08 10:43:45 +0000
committerbors <bors@rust-lang.org>2017-10-08 10:43:45 +0000
commitff8e264950b070578c8c8187241f4ca55ebf28fe (patch)
tree272142ab47edf6097f2544b9ad23f0f0091b1138
parent108706f13a7e5e530ba4bbddf776d8ce71aec01f (diff)
parenta6dea41d64a244c8f7671dd0eeb498b015c3a712 (diff)
downloadrust-ff8e264950b070578c8c8187241f4ca55ebf28fe.tar.gz
rust-ff8e264950b070578c8c8187241f4ca55ebf28fe.zip
Auto merge of #45012 - Gankro:noalias, r=arielb1
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).
-rw-r--r--src/librustc/session/config.rs2
-rw-r--r--src/librustc_trans/abi.rs13
2 files changed, 14 insertions, 1 deletions
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<String> = (None, parse_opt_string, [UNTRACKED],
           "dump MIR state at various points in translation"),
     dump_mir_dir: Option<String> = (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);
                 }