Skip to content

Commit 9d1aeae

Browse files
committed
Auto merge of #94214 - nikic:rust-opaque-pointers, r=cuviper
Prepare Rust for opaque pointers Fix one codegen bug with opaque pointers, and update our IR tests to accept both typed pointer and opaque pointer IR. This is a bit annoying, but unavoidable if we want decent test coverage on both LLVM 14 and LLVM 15. This prepares Rust for when LLVM will enable opaque pointers by default.
2 parents abc7681 + 1ff051a commit 9d1aeae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+265
-289
lines changed

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,15 +509,20 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
509509
OperandValue::Ref(place.llval, Some(llextra), place.align)
510510
} else if place.layout.is_llvm_immediate() {
511511
let mut const_llval = None;
512+
let llty = place.layout.llvm_type(self);
512513
unsafe {
513514
if let Some(global) = llvm::LLVMIsAGlobalVariable(place.llval) {
514515
if llvm::LLVMIsGlobalConstant(global) == llvm::True {
515-
const_llval = llvm::LLVMGetInitializer(global);
516+
if let Some(init) = llvm::LLVMGetInitializer(global) {
517+
if self.val_ty(init) == llty {
518+
const_llval = Some(init);
519+
}
520+
}
516521
}
517522
}
518523
}
519524
let llval = const_llval.unwrap_or_else(|| {
520-
let load = self.load(place.layout.llvm_type(self), place.llval, place.align);
525+
let load = self.load(llty, place.llval, place.align);
521526
if let abi::Abi::Scalar(scalar) = place.layout.abi {
522527
scalar_load_metadata(self, load, scalar, place.layout, Size::ZERO);
523528
}

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,8 @@ impl CodegenBackend for LlvmCodegenBackend {
304304
local stack variable in the ABI.)
305305
306306
basic
307-
Generate stack canaries in functions with:
308-
- local variables of `[T; N]` type, where `T` is byte-sized and `N` > 8.
307+
Generate stack canaries in functions with local variables of `[T; N]`
308+
type, where `T` is byte-sized and `N` >= 8.
309309
310310
none
311311
Do not generate stack canaries.

src/bootstrap/native.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,10 @@ impl Step for Lld {
738738
.define("LLVM_CONFIG_PATH", llvm_config_shim)
739739
.define("LLVM_INCLUDE_TESTS", "OFF");
740740

741+
if builder.config.llvm_allow_old_toolchain {
742+
cfg.define("LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN", "YES");
743+
}
744+
741745
// While we're using this horrible workaround to shim the execution of
742746
// llvm-config, let's just pile on more. I can't seem to figure out how
743747
// to build LLD as a standalone project and also cross-compile it at the

src/test/assembly/stack-protector/stack-protector-heuristics-effect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub fn array_u8_1(f: fn(*const u8)) {
7878
#[no_mangle]
7979
pub fn array_u8_small(f: fn(*const u8)) {
8080
let a = [0u8; 2];
81-
let b = [0u8; 8];
81+
let b = [0u8; 7];
8282
f(&a as *const _);
8383
f(&b as *const _);
8484

src/test/codegen/abi-main-signature-32bit-c-int.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
fn main() {
88
}
99

10-
// CHECK: define i32 @main(i32{{( %0)?}}, i8**{{( %1)?}})
10+
// CHECK: define i32 @main(i32{{( %0)?}}, {{i8\*\*|ptr}}{{( %1)?}})

src/test/codegen/adjustments.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ pub fn helper(_: usize) {
1313
pub fn no_op_slice_adjustment(x: &[u8]) -> &[u8] {
1414
// We used to generate an extra alloca and memcpy for the block's trailing expression value, so
1515
// check that we copy directly to the return value slot
16-
// CHECK: %0 = insertvalue { [0 x i8]*, [[USIZE]] } undef, [0 x i8]* %x.0, 0
17-
// CHECK: %1 = insertvalue { [0 x i8]*, [[USIZE]] } %0, [[USIZE]] %x.1, 1
18-
// CHECK: ret { [0 x i8]*, [[USIZE]] } %1
16+
// CHECK: %0 = insertvalue { {{\[0 x i8\]\*|ptr}}, [[USIZE]] } undef, {{\[0 x i8\]\*|ptr}} %x.0, 0
17+
// CHECK: %1 = insertvalue { {{\[0 x i8\]\*|ptr}}, [[USIZE]] } %0, [[USIZE]] %x.1, 1
18+
// CHECK: ret { {{\[0 x i8\]\*|ptr}}, [[USIZE]] } %1
1919
{ x }
2020
}
2121

src/test/codegen/align-enum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub struct Nested64 {
2020
#[no_mangle]
2121
pub fn align64(a: u32) -> Align64 {
2222
// CHECK: %a64 = alloca %Align64, align 64
23-
// CHECK: call void @llvm.memcpy.{{.*}}(i8* align 64 %{{.*}}, i8* align 64 %{{.*}}, i{{[0-9]+}} 64, i1 false)
23+
// CHECK: call void @llvm.memcpy.{{.*}}({{i8\*|ptr}} align 64 %{{.*}}, {{i8\*|ptr}} align 64 %{{.*}}, i{{[0-9]+}} 64, i1 false)
2424
let a64 = Align64::A(a);
2525
a64
2626
}

src/test/codegen/align-struct.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub enum Enum64 {
3232
#[no_mangle]
3333
pub fn align64(i : i32) -> Align64 {
3434
// CHECK: %a64 = alloca %Align64, align 64
35-
// CHECK: call void @llvm.memcpy.{{.*}}(i8* align 64 %{{.*}}, i8* align 64 %{{.*}}, i{{[0-9]+}} 64, i1 false)
35+
// CHECK: call void @llvm.memcpy.{{.*}}({{i8\*|ptr}} align 64 %{{.*}}, {{i8\*|ptr}} align 64 %{{.*}}, i{{[0-9]+}} 64, i1 false)
3636
let a64 = Align64(i);
3737
a64
3838
}
@@ -42,8 +42,7 @@ pub fn align64(i : i32) -> Align64 {
4242
// CHECK-LABEL: @align64_load
4343
#[no_mangle]
4444
pub fn align64_load(a: Align64) -> i32 {
45-
// CHECK: [[FIELD:%.*]] = bitcast %Align64* %{{.*}} to i32*
46-
// CHECK: {{%.*}} = load i32, i32* [[FIELD]], align 64
45+
// CHECK: {{%.*}} = load i32, {{i32\*|ptr}} {{%.*}}, align 64
4746
a.0
4847
}
4948

src/test/codegen/array-equality.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ pub fn array_eq_value(a: [u16; 3], b: [u16; 3]) -> bool {
1616
#[no_mangle]
1717
pub fn array_eq_ref(a: &[u16; 3], b: &[u16; 3]) -> bool {
1818
// CHECK: start:
19-
// CHECK: load i48, i48* %{{.+}}, align 2
20-
// CHECK: load i48, i48* %{{.+}}, align 2
19+
// CHECK: load i48, {{i48\*|ptr}} %{{.+}}, align 2
20+
// CHECK: load i48, {{i48\*|ptr}} %{{.+}}, align 2
2121
// CHECK: icmp eq i48
2222
// CHECK-NEXT: ret
2323
a == b
@@ -27,9 +27,7 @@ pub fn array_eq_ref(a: &[u16; 3], b: &[u16; 3]) -> bool {
2727
#[no_mangle]
2828
pub fn array_eq_value_still_passed_by_pointer(a: [u16; 9], b: [u16; 9]) -> bool {
2929
// CHECK-NEXT: start:
30-
// CHECK-NEXT: bitcast
31-
// CHECK-NEXT: bitcast
32-
// CHECK-NEXT: %[[CMP:.+]] = tail call i32 @{{bcmp|memcmp}}(i8* {{.*}} dereferenceable(18) %{{.+}}, i8* {{.*}} dereferenceable(18) %{{.+}}, i64 18)
30+
// CHECK: %[[CMP:.+]] = tail call i32 @{{bcmp|memcmp}}({{i8\*|ptr}} {{.*}} dereferenceable(18) %{{.+}}, {{i8\*|ptr}} {{.*}} dereferenceable(18) %{{.+}}, i64 18)
3331
// CHECK-NEXT: %[[EQ:.+]] = icmp eq i32 %[[CMP]], 0
3432
// CHECK-NEXT: ret i1 %[[EQ]]
3533
a == b
@@ -39,9 +37,7 @@ pub fn array_eq_value_still_passed_by_pointer(a: [u16; 9], b: [u16; 9]) -> bool
3937
#[no_mangle]
4038
pub fn array_eq_long(a: &[u16; 1234], b: &[u16; 1234]) -> bool {
4139
// CHECK-NEXT: start:
42-
// CHECK-NEXT: bitcast
43-
// CHECK-NEXT: bitcast
44-
// CHECK-NEXT: %[[CMP:.+]] = tail call i32 @{{bcmp|memcmp}}(i8* {{.*}} dereferenceable(2468) %{{.+}}, i8* {{.*}} dereferenceable(2468) %{{.+}}, i64 2468)
40+
// CHECK: %[[CMP:.+]] = tail call i32 @{{bcmp|memcmp}}({{i8\*|ptr}} {{.*}} dereferenceable(2468) %{{.+}}, {{i8\*|ptr}} {{.*}} dereferenceable(2468) %{{.+}}, i64 2468)
4541
// CHECK-NEXT: %[[EQ:.+]] = icmp eq i32 %[[CMP]], 0
4642
// CHECK-NEXT: ret i1 %[[EQ]]
4743
a == b
@@ -56,18 +52,17 @@ pub fn array_eq_zero_short(x: [u16; 3]) -> bool {
5652
x == [0; 3]
5753
}
5854

59-
// CHECK-LABEL: @array_eq_zero_mid([8 x i16]*
55+
// CHECK-LABEL: @array_eq_zero_mid(
6056
#[no_mangle]
6157
pub fn array_eq_zero_mid(x: [u16; 8]) -> bool {
6258
// CHECK-NEXT: start:
63-
// CHECK-NEXT: bitcast
64-
// CHECK-NEXT: %[[LOAD:.+]] = load i128,
59+
// CHECK: %[[LOAD:.+]] = load i128,
6560
// CHECK-NEXT: %[[EQ:.+]] = icmp eq i128 %[[LOAD]], 0
6661
// CHECK-NEXT: ret i1 %[[EQ]]
6762
x == [0; 8]
6863
}
6964

70-
// CHECK-LABEL: @array_eq_zero_long([1234 x i16]*
65+
// CHECK-LABEL: @array_eq_zero_long(
7166
#[no_mangle]
7267
pub fn array_eq_zero_long(x: [u16; 1234]) -> bool {
7368
// CHECK-NEXT: start:

src/test/codegen/atomic-operations.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@ use std::sync::atomic::{AtomicI32, Ordering::*};
88
// CHECK-LABEL: @compare_exchange
99
#[no_mangle]
1010
pub fn compare_exchange(a: &AtomicI32) {
11-
// CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 10 monotonic monotonic
11+
// CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 10 monotonic monotonic
1212
let _ = a.compare_exchange(0, 10, Relaxed, Relaxed);
1313

14-
// CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 20 release monotonic
14+
// CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 20 release monotonic
1515
let _ = a.compare_exchange(0, 20, Release, Relaxed);
1616

17-
// CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 30 acquire monotonic
18-
// CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 31 acquire acquire
17+
// CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 30 acquire monotonic
18+
// CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 31 acquire acquire
1919
let _ = a.compare_exchange(0, 30, Acquire, Relaxed);
2020
let _ = a.compare_exchange(0, 31, Acquire, Acquire);
2121

22-
// CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 40 acq_rel monotonic
23-
// CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 41 acq_rel acquire
22+
// CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 40 acq_rel monotonic
23+
// CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 41 acq_rel acquire
2424
let _ = a.compare_exchange(0, 40, AcqRel, Relaxed);
2525
let _ = a.compare_exchange(0, 41, AcqRel, Acquire);
2626

27-
// CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 50 seq_cst monotonic
28-
// CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 51 seq_cst acquire
29-
// CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 52 seq_cst seq_cst
27+
// CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 50 seq_cst monotonic
28+
// CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 51 seq_cst acquire
29+
// CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 52 seq_cst seq_cst
3030
let _ = a.compare_exchange(0, 50, SeqCst, Relaxed);
3131
let _ = a.compare_exchange(0, 51, SeqCst, Acquire);
3232
let _ = a.compare_exchange(0, 52, SeqCst, SeqCst);
@@ -35,25 +35,25 @@ pub fn compare_exchange(a: &AtomicI32) {
3535
// CHECK-LABEL: @compare_exchange_weak
3636
#[no_mangle]
3737
pub fn compare_exchange_weak(w: &AtomicI32) {
38-
// CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 10 monotonic monotonic
38+
// CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 10 monotonic monotonic
3939
let _ = w.compare_exchange_weak(1, 10, Relaxed, Relaxed);
4040

41-
// CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 20 release monotonic
41+
// CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 20 release monotonic
4242
let _ = w.compare_exchange_weak(1, 20, Release, Relaxed);
4343

44-
// CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 30 acquire monotonic
45-
// CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 31 acquire acquire
44+
// CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 30 acquire monotonic
45+
// CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 31 acquire acquire
4646
let _ = w.compare_exchange_weak(1, 30, Acquire, Relaxed);
4747
let _ = w.compare_exchange_weak(1, 31, Acquire, Acquire);
4848

49-
// CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 40 acq_rel monotonic
50-
// CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 41 acq_rel acquire
49+
// CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 40 acq_rel monotonic
50+
// CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 41 acq_rel acquire
5151
let _ = w.compare_exchange_weak(1, 40, AcqRel, Relaxed);
5252
let _ = w.compare_exchange_weak(1, 41, AcqRel, Acquire);
5353

54-
// CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 50 seq_cst monotonic
55-
// CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 51 seq_cst acquire
56-
// CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 52 seq_cst seq_cst
54+
// CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 50 seq_cst monotonic
55+
// CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 51 seq_cst acquire
56+
// CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 52 seq_cst seq_cst
5757
let _ = w.compare_exchange_weak(1, 50, SeqCst, Relaxed);
5858
let _ = w.compare_exchange_weak(1, 51, SeqCst, Acquire);
5959
let _ = w.compare_exchange_weak(1, 52, SeqCst, SeqCst);

0 commit comments

Comments
 (0)