Enable mutable noalias by default for LLVM 12
We don't have any known noalias bugs for LLVM 12 ... yet.
This commit is contained in:
parent
c3f9403f59
commit
39ed64399e
3 changed files with 14 additions and 16 deletions
|
@ -1,6 +1,7 @@
|
||||||
use crate::builder::Builder;
|
use crate::builder::Builder;
|
||||||
use crate::context::CodegenCx;
|
use crate::context::CodegenCx;
|
||||||
use crate::llvm::{self, AttributePlace};
|
use crate::llvm::{self, AttributePlace};
|
||||||
|
use crate::llvm_util;
|
||||||
use crate::type_::Type;
|
use crate::type_::Type;
|
||||||
use crate::type_of::LayoutLlvmExt;
|
use crate::type_of::LayoutLlvmExt;
|
||||||
use crate::value::Value;
|
use crate::value::Value;
|
||||||
|
@ -51,18 +52,15 @@ pub trait ArgAttributesExt {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn should_use_mutable_noalias(cx: &CodegenCx<'_, '_>) -> bool {
|
fn should_use_mutable_noalias(cx: &CodegenCx<'_, '_>) -> bool {
|
||||||
// Previously we would only emit noalias annotations for LLVM >= 6 or in
|
// LLVM prior to version 12 has known miscompiles in the presence of
|
||||||
// panic=abort mode. That was deemed right, as prior versions had many bugs
|
// noalias attributes (see #54878). Only enable mutable noalias by
|
||||||
// in conjunction with unwinding, but later versions didn’t seem to have
|
// default for versions we believe to be safe.
|
||||||
// said issues. See issue #31681.
|
cx.tcx
|
||||||
//
|
.sess
|
||||||
// Alas, later on we encountered a case where noalias would generate wrong
|
.opts
|
||||||
// code altogether even with recent versions of LLVM in *safe* code with no
|
.debugging_opts
|
||||||
// unwinding involved. See #54462.
|
.mutable_noalias
|
||||||
//
|
.unwrap_or_else(|| llvm_util::get_version() >= (12, 0, 0))
|
||||||
// For now, do not enable mutable_noalias by default at all, while the
|
|
||||||
// issue is being figured out.
|
|
||||||
cx.tcx.sess.opts.debugging_opts.mutable_noalias.unwrap_or(false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ArgAttributesExt for ArgAttributes {
|
impl ArgAttributesExt for ArgAttributes {
|
||||||
|
|
|
@ -998,7 +998,7 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
|
||||||
mir_opt_level: Option<usize> = (None, parse_opt_uint, [TRACKED],
|
mir_opt_level: Option<usize> = (None, parse_opt_uint, [TRACKED],
|
||||||
"MIR optimization level (0-4; default: 1 in non optimized builds and 2 in optimized builds)"),
|
"MIR optimization level (0-4; default: 1 in non optimized builds and 2 in optimized builds)"),
|
||||||
mutable_noalias: Option<bool> = (None, parse_opt_bool, [TRACKED],
|
mutable_noalias: Option<bool> = (None, parse_opt_bool, [TRACKED],
|
||||||
"emit noalias metadata for mutable references (default: no)"),
|
"emit noalias metadata for mutable references (default: yes for LLVM >= 12, otherwise no)"),
|
||||||
new_llvm_pass_manager: bool = (false, parse_bool, [TRACKED],
|
new_llvm_pass_manager: bool = (false, parse_bool, [TRACKED],
|
||||||
"use new LLVM pass manager (default: no)"),
|
"use new LLVM pass manager (default: no)"),
|
||||||
nll_facts: bool = (false, parse_bool, [UNTRACKED],
|
nll_facts: bool = (false, parse_bool, [UNTRACKED],
|
||||||
|
|
|
@ -43,13 +43,13 @@ pub fn named_borrow<'r>(_: &'r i32) {
|
||||||
pub fn unsafe_borrow(_: &UnsafeInner) {
|
pub fn unsafe_borrow(_: &UnsafeInner) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK: @mutable_unsafe_borrow(i16* align 2 dereferenceable(2) %_1)
|
// CHECK: @mutable_unsafe_borrow(i16* noalias align 2 dereferenceable(2) %_1)
|
||||||
// ... unless this is a mutable borrow, those never alias
|
// ... unless this is a mutable borrow, those never alias
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn mutable_unsafe_borrow(_: &mut UnsafeInner) {
|
pub fn mutable_unsafe_borrow(_: &mut UnsafeInner) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK: @mutable_borrow(i32* align 4 dereferenceable(4) %_1)
|
// CHECK: @mutable_borrow(i32* noalias align 4 dereferenceable(4) %_1)
|
||||||
// FIXME #25759 This should also have `nocapture`
|
// FIXME #25759 This should also have `nocapture`
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn mutable_borrow(_: &mut i32) {
|
pub fn mutable_borrow(_: &mut i32) {
|
||||||
|
@ -94,7 +94,7 @@ pub fn helper(_: usize) {
|
||||||
pub fn slice(_: &[u8]) {
|
pub fn slice(_: &[u8]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK: @mutable_slice([0 x i8]* nonnull align 1 %_1.0, [[USIZE]] %_1.1)
|
// CHECK: @mutable_slice([0 x i8]* noalias nonnull align 1 %_1.0, [[USIZE]] %_1.1)
|
||||||
// FIXME #25759 This should also have `nocapture`
|
// FIXME #25759 This should also have `nocapture`
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn mutable_slice(_: &mut [u8]) {
|
pub fn mutable_slice(_: &mut [u8]) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue