Skip to content

Commit 9c62193

Browse files
committed
Do not put noalias annotations by default
This will be re-enabled sooner or later depending on results of further investigation. Fixes #54462
1 parent 80e6e3e commit 9c62193

File tree

3 files changed

+48
-10
lines changed

3 files changed

+48
-10
lines changed

src/librustc_codegen_llvm/type_of.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@
1010

1111
use abi::{FnType, FnTypeExt};
1212
use common::*;
13-
use llvm;
1413
use rustc::hir;
1514
use rustc::ty::{self, Ty, TypeFoldable};
1615
use rustc::ty::layout::{self, Align, LayoutOf, Size, TyLayout};
17-
use rustc_target::spec::PanicStrategy;
1816
use rustc_target::abi::FloatTy;
1917
use rustc_mir::monomorphize::item::DefPathBasedNames;
2018
use type_::Type;
@@ -433,12 +431,19 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyLayout<'tcx> {
433431
PointerKind::Shared
434432
},
435433
hir::MutMutable => {
436-
// Only emit noalias annotations for LLVM >= 6 or in panic=abort
437-
// mode, as prior versions had many bugs in conjunction with
438-
// unwinding. See also issue #31681.
434+
// Previously we would only emit noalias annotations for LLVM >= 6 or in
435+
// panic=abort mode. That was deemed right, as prior versions had many bugs
436+
// in conjunction with unwinding, but later versions didn’t seem to have
437+
// said issues. See issue #31681.
438+
//
439+
// Alas, later on we encountered a case where noalias would generate wrong
440+
// code altogether even with recent versions of LLVM in *safe* code with no
441+
// unwinding involved. See #54462.
442+
//
443+
// For now, do not enable mutable_noalias by default at all, while the
444+
// issue is being figured out.
439445
let mutable_noalias = cx.tcx.sess.opts.debugging_opts.mutable_noalias
440-
.unwrap_or(unsafe { llvm::LLVMRustVersionMajor() >= 6 }
441-
|| cx.tcx.sess.panic_strategy() == PanicStrategy::Abort);
446+
.unwrap_or(false);
442447
if mutable_noalias {
443448
PointerKind::UniqueBorrowed
444449
} else {

src/test/codegen/function-arguments.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ pub fn named_borrow<'r>(_: &'r i32) {
5353
pub fn unsafe_borrow(_: &UnsafeInner) {
5454
}
5555

56-
// CHECK: @mutable_unsafe_borrow(i16* noalias dereferenceable(2) %arg0)
56+
// CHECK: @mutable_unsafe_borrow(i16* dereferenceable(2) %arg0)
5757
// ... unless this is a mutable borrow, those never alias
5858
#[no_mangle]
5959
pub fn mutable_unsafe_borrow(_: &mut UnsafeInner) {
6060
}
6161

62-
// CHECK: @mutable_borrow(i32* noalias dereferenceable(4) %arg0)
62+
// CHECK: @mutable_borrow(i32* dereferenceable(4) %arg0)
6363
// FIXME #25759 This should also have `nocapture`
6464
#[no_mangle]
6565
pub fn mutable_borrow(_: &mut i32) {
@@ -102,7 +102,7 @@ pub fn helper(_: usize) {
102102
pub fn slice(_: &[u8]) {
103103
}
104104

105-
// CHECK: @mutable_slice([0 x i8]* noalias nonnull %arg0.0, [[USIZE]] %arg0.1)
105+
// CHECK: @mutable_slice([0 x i8]* nonnull %arg0.0, [[USIZE]] %arg0.1)
106106
// FIXME #25759 This should also have `nocapture`
107107
#[no_mangle]
108108
pub fn mutable_slice(_: &mut [u8]) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
//
11+
// compile-flags: -Ccodegen-units=1 -O
12+
13+
fn linidx(row: usize, col: usize) -> usize {
14+
row * 1 + col * 3
15+
}
16+
17+
fn main() {
18+
let mut mat = [1.0f32, 5.0, 9.0, 2.0, 6.0, 10.0, 3.0, 7.0, 11.0, 4.0, 8.0, 12.0];
19+
20+
for i in 0..2 {
21+
for j in i+1..3 {
22+
if mat[linidx(j, 3)] > mat[linidx(i, 3)] {
23+
for k in 0..4 {
24+
let (x, rest) = mat.split_at_mut(linidx(i, k) + 1);
25+
let a = x.last_mut().unwrap();
26+
let b = rest.get_mut(linidx(j, k) - linidx(i, k) - 1).unwrap();
27+
::std::mem::swap(a, b);
28+
}
29+
}
30+
}
31+
}
32+
assert_eq!([9.0, 5.0, 1.0, 10.0, 6.0, 2.0, 11.0, 7.0, 3.0, 12.0, 8.0, 4.0], mat);
33+
}

0 commit comments

Comments
 (0)