Skip to content

Commit 39ed643

Browse files
committed
Enable mutable noalias by default for LLVM 12
We don't have any known noalias bugs for LLVM 12 ... yet.
1 parent c3f9403 commit 39ed643

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

compiler/rustc_codegen_llvm/src/abi.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::builder::Builder;
22
use crate::context::CodegenCx;
33
use crate::llvm::{self, AttributePlace};
4+
use crate::llvm_util;
45
use crate::type_::Type;
56
use crate::type_of::LayoutLlvmExt;
67
use crate::value::Value;
@@ -51,18 +52,15 @@ pub trait ArgAttributesExt {
5152
}
5253

5354
fn should_use_mutable_noalias(cx: &CodegenCx<'_, '_>) -> bool {
54-
// Previously we would only emit noalias annotations for LLVM >= 6 or in
55-
// panic=abort mode. That was deemed right, as prior versions had many bugs
56-
// in conjunction with unwinding, but later versions didn’t seem to have
57-
// said issues. See issue #31681.
58-
//
59-
// Alas, later on we encountered a case where noalias would generate wrong
60-
// code altogether even with recent versions of LLVM in *safe* code with no
61-
// unwinding involved. See #54462.
62-
//
63-
// For now, do not enable mutable_noalias by default at all, while the
64-
// issue is being figured out.
65-
cx.tcx.sess.opts.debugging_opts.mutable_noalias.unwrap_or(false)
55+
// LLVM prior to version 12 has known miscompiles in the presence of
56+
// noalias attributes (see #54878). Only enable mutable noalias by
57+
// default for versions we believe to be safe.
58+
cx.tcx
59+
.sess
60+
.opts
61+
.debugging_opts
62+
.mutable_noalias
63+
.unwrap_or_else(|| llvm_util::get_version() >= (12, 0, 0))
6664
}
6765

6866
impl ArgAttributesExt for ArgAttributes {

compiler/rustc_session/src/options.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
998998
mir_opt_level: Option<usize> = (None, parse_opt_uint, [TRACKED],
999999
"MIR optimization level (0-4; default: 1 in non optimized builds and 2 in optimized builds)"),
10001000
mutable_noalias: Option<bool> = (None, parse_opt_bool, [TRACKED],
1001-
"emit noalias metadata for mutable references (default: no)"),
1001+
"emit noalias metadata for mutable references (default: yes for LLVM >= 12, otherwise no)"),
10021002
new_llvm_pass_manager: bool = (false, parse_bool, [TRACKED],
10031003
"use new LLVM pass manager (default: no)"),
10041004
nll_facts: bool = (false, parse_bool, [UNTRACKED],

src/test/codegen/function-arguments.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ pub fn named_borrow<'r>(_: &'r i32) {
4343
pub fn unsafe_borrow(_: &UnsafeInner) {
4444
}
4545

46-
// CHECK: @mutable_unsafe_borrow(i16* align 2 dereferenceable(2) %_1)
46+
// CHECK: @mutable_unsafe_borrow(i16* noalias align 2 dereferenceable(2) %_1)
4747
// ... unless this is a mutable borrow, those never alias
4848
#[no_mangle]
4949
pub fn mutable_unsafe_borrow(_: &mut UnsafeInner) {
5050
}
5151

52-
// CHECK: @mutable_borrow(i32* align 4 dereferenceable(4) %_1)
52+
// CHECK: @mutable_borrow(i32* noalias align 4 dereferenceable(4) %_1)
5353
// FIXME #25759 This should also have `nocapture`
5454
#[no_mangle]
5555
pub fn mutable_borrow(_: &mut i32) {
@@ -94,7 +94,7 @@ pub fn helper(_: usize) {
9494
pub fn slice(_: &[u8]) {
9595
}
9696

97-
// CHECK: @mutable_slice([0 x i8]* nonnull align 1 %_1.0, [[USIZE]] %_1.1)
97+
// CHECK: @mutable_slice([0 x i8]* noalias nonnull align 1 %_1.0, [[USIZE]] %_1.1)
9898
// FIXME #25759 This should also have `nocapture`
9999
#[no_mangle]
100100
pub fn mutable_slice(_: &mut [u8]) {

0 commit comments

Comments
 (0)