Skip to content

Commit 7b49840

Browse files
authored
Merge pull request #36628 from nikomatsakis/backport-issue-36496
Backport #36496
2 parents 0b458c1 + 3264a86 commit 7b49840

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

src/librustc_trans/adt.rs

+21-5
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ use syntax::attr;
5555
use syntax::attr::IntType;
5656
use _match;
5757
use abi::FAT_PTR_ADDR;
58-
use base::InitAlloca;
58+
use base::{self, InitAlloca};
5959
use build::*;
6060
use cleanup;
6161
use cleanup::CleanupMethods;
@@ -1023,16 +1023,32 @@ pub fn trans_set_discr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, r: &Repr<'tcx>,
10231023
Store(bcx, C_null(llptrty), val);
10241024
}
10251025
}
1026-
StructWrappedNullablePointer { nndiscr, ref discrfield, .. } => {
1026+
StructWrappedNullablePointer { nndiscr, ref discrfield, ref nonnull, .. } => {
10271027
if discr != nndiscr {
1028-
let llptrptr = GEPi(bcx, val, &discrfield[..]);
1029-
let llptrty = val_ty(llptrptr).element_type();
1030-
Store(bcx, C_null(llptrty), llptrptr);
1028+
if target_sets_discr_via_memset(bcx) {
1029+
// Issue #34427: As workaround for LLVM bug on
1030+
// ARM, use memset of 0 on whole struct rather
1031+
// than storing null to single target field.
1032+
let b = B(bcx);
1033+
let llptr = b.pointercast(val, Type::i8(b.ccx).ptr_to());
1034+
let fill_byte = C_u8(b.ccx, 0);
1035+
let size = C_uint(b.ccx, nonnull.size);
1036+
let align = C_i32(b.ccx, nonnull.align as i32);
1037+
base::call_memset(&b, llptr, fill_byte, size, align, false);
1038+
} else {
1039+
let llptrptr = GEPi(bcx, val, &discrfield[..]);
1040+
let llptrty = val_ty(llptrptr).element_type();
1041+
Store(bcx, C_null(llptrty), llptrptr);
1042+
}
10311043
}
10321044
}
10331045
}
10341046
}
10351047

1048+
fn target_sets_discr_via_memset<'blk, 'tcx>(bcx: Block<'blk, 'tcx>) -> bool {
1049+
bcx.sess().target.target.arch == "arm" || bcx.sess().target.target.arch == "aarch64"
1050+
}
1051+
10361052
fn assert_discr_in_range(ity: IntType, min: Disr, max: Disr, discr: Disr) {
10371053
match ity {
10381054
attr::UnsignedInt(_) => {

src/test/run-pass/issue-34427.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2016 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+
// Issue #34427: On ARM, the code in `foo` at one time was generating
12+
// a machine code instruction of the form: `str r0, [r0, rN]!` (for
13+
// some N), which is not legal because the source register and base
14+
// register cannot be identical in the preindexed form signalled by
15+
// the `!`.
16+
//
17+
// See LLVM bug: https://llvm.org/bugs/show_bug.cgi?id=28809
18+
19+
#[inline(never)]
20+
fn foo(n: usize) -> Vec<Option<(*mut (), &'static ())>> {
21+
(0..n).map(|_| None).collect()
22+
}
23+
24+
fn main() {
25+
let _ = (foo(10), foo(32));
26+
}

0 commit comments

Comments
 (0)