Skip to content

Commit 6741f33

Browse files
committed
Avoid FCA loads and extractvalue when copying fat pointers
Since fat pointers do not qualify as structural types, they got copied using load_ty and store_ty, which means that we load an FCA and use extractvalue to get the components of the fat pointer. This breaks certain optimizations in LLVM. Found via apasel422/ref_count#13
1 parent f8827f5 commit 6741f33

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/librustc_trans/trans/base.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,9 @@ pub fn memcpy_ty<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, dst: ValueRef, src: ValueRe
12231223
let llsz = llsize_of(ccx, llty);
12241224
let llalign = type_of::align_of(ccx, t);
12251225
call_memcpy(bcx, dst, src, llsz, llalign as u32);
1226+
} else if common::type_is_fat_ptr(bcx.tcx(), t) {
1227+
let (data, extra) = load_fat_ptr(bcx, src, t);
1228+
store_fat_ptr(bcx, data, extra, dst, t);
12261229
} else {
12271230
store_ty(bcx, load_ty(bcx, src, t), dst, t);
12281231
}

src/test/codegen/fatptr.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2015 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: -C no-prepopulate-passes
12+
13+
#![crate_type = "lib"]
14+
15+
pub trait T {}
16+
17+
// CHECK-LABEL: @copy_fat_ptr
18+
#[no_mangle]
19+
pub fn copy_fat_ptr(x: &T) {
20+
// CHECK-NOT: extractvalue
21+
let x2 = x;
22+
}

0 commit comments

Comments
 (0)