Skip to content

Commit 3dc8ebc

Browse files
committed
Correctly account for different address spaces in LLVM intrinsic invocations
1 parent 9415f3d commit 3dc8ebc

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,7 +1394,7 @@ impl<'ll> StaticBuilderMethods for Builder<'_, 'll, '_> {
13941394
let global = self.cx().get_static(def_id);
13951395
if self.cx().tcx.is_thread_local_static(def_id) {
13961396
let pointer =
1397-
self.call_intrinsic("llvm.threadlocal.address", &[self.type_ptr()], &[global]);
1397+
self.call_intrinsic("llvm.threadlocal.address", &[self.val_ty(global)], &[global]);
13981398
// Cast to default address space if globals are in a different addrspace
13991399
self.pointercast(pointer, self.type_ptr())
14001400
} else {
@@ -1609,7 +1609,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
16091609
return;
16101610
}
16111611

1612-
self.call_intrinsic(intrinsic, &[self.type_ptr()], &[self.cx.const_u64(size), ptr]);
1612+
self.call_intrinsic(intrinsic, &[self.val_ty(ptr)], &[self.cx.const_u64(size), ptr]);
16131613
}
16141614
}
16151615
impl<'a, 'll, CX: Borrow<SCx<'ll>>> GenericBuilder<'a, 'll, CX> {

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@ fn call_simple_intrinsic<'ll, 'tcx>(
154154
sym::roundf64 => ("llvm.round", &[bx.type_f64()]),
155155
sym::roundf128 => ("llvm.round", &[bx.type_f128()]),
156156

157-
sym::ptr_mask => ("llvm.ptrmask", &[bx.type_ptr(), bx.type_isize()]),
158-
159157
_ => return None,
160158
};
161159
Some(bx.call_intrinsic(
@@ -181,6 +179,14 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
181179
let simple = call_simple_intrinsic(self, name, args);
182180
let llval = match name {
183181
_ if simple.is_some() => simple.unwrap(),
182+
sym::ptr_mask => {
183+
let ptr = args[0].immediate();
184+
self.call_intrinsic(
185+
"llvm.ptrmask",
186+
&[self.val_ty(ptr), self.type_isize()],
187+
&[ptr, args[1].immediate()],
188+
)
189+
}
184190
sym::is_val_statically_known => {
185191
if let OperandValue::Immediate(imm) = args[0].val {
186192
self.call_intrinsic(
@@ -309,15 +315,11 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
309315
sym::prefetch_write_instruction => (1, 0),
310316
_ => bug!(),
311317
};
318+
let ptr = args[0].immediate();
312319
self.call_intrinsic(
313320
"llvm.prefetch",
314-
&[self.type_ptr()],
315-
&[
316-
args[0].immediate(),
317-
self.const_i32(rw),
318-
args[1].immediate(),
319-
self.const_i32(cache_type),
320-
],
321+
&[self.val_ty(ptr)],
322+
&[ptr, self.const_i32(rw), args[1].immediate(), self.const_i32(cache_type)],
321323
)
322324
}
323325
sym::carrying_mul_add => {
@@ -637,11 +639,11 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
637639
}
638640

639641
fn va_start(&mut self, va_list: &'ll Value) -> &'ll Value {
640-
self.call_intrinsic("llvm.va_start", &[self.type_ptr()], &[va_list])
642+
self.call_intrinsic("llvm.va_start", &[self.val_ty(va_list)], &[va_list])
641643
}
642644

643645
fn va_end(&mut self, va_list: &'ll Value) -> &'ll Value {
644-
self.call_intrinsic("llvm.va_end", &[self.type_ptr()], &[va_list])
646+
self.call_intrinsic("llvm.va_end", &[self.val_ty(va_list)], &[va_list])
645647
}
646648
}
647649

@@ -1018,7 +1020,7 @@ fn codegen_emcc_try<'ll, 'tcx>(
10181020
let selector = bx.extract_value(vals, 1);
10191021

10201022
// Check if the typeid we got is the one for a Rust panic.
1021-
let rust_typeid = bx.call_intrinsic("llvm.eh.typeid.for", &[bx.type_ptr()], &[tydesc]);
1023+
let rust_typeid = bx.call_intrinsic("llvm.eh.typeid.for", &[bx.val_ty(tydesc)], &[tydesc]);
10221024
let is_rust_panic = bx.icmp(IntPredicate::IntEQ, selector, rust_typeid);
10231025
let is_rust_panic = bx.zext(is_rust_panic, bx.type_bool());
10241026

0 commit comments

Comments
 (0)