Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subtree sync for rustc_codegen_cranelift #124286

Merged
merged 32 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e243f8d
Merge commit '89f54caacf90e99fc8ba0d60a28bdadea3cfdf1e' into sync_cg_…
bjorn3 Apr 11, 2024
bf02a87
Merge branch 'sync_from_rust'
bjorn3 Apr 11, 2024
71e7414
Allow MaybeUninit in input and output of inline assembly
taiki-e Apr 14, 2024
49ad3ae
Merge pull request #1481 from taiki-e/asm-maybe-uninit
bjorn3 Apr 14, 2024
5075386
Rustup to rustc 1.79.0-nightly (0d8b3346a 2024-04-14)
bjorn3 Apr 15, 2024
9e4e444
static_mut_refs: use raw pointers to remove the remaining FIXME
RalfJung Apr 15, 2024
fbac8ef
Cranelift: Revert raw-dylib for Windows futex APIs
ChrisDenton Apr 16, 2024
f532309
ScalarInt: add methods to assert being a (u)int of given size
RalfJung Apr 18, 2024
a2a949b
Auto merge of #124113 - RalfJung:interpret-scalar-ops, r=oli-obk
bors Apr 19, 2024
4027a52
Sync from rust f9b16149208c8a8a349c32813312716f6603eb6f
bjorn3 Apr 20, 2024
82dd93f
Rustup to rustc 1.79.0-nightly (f9b161492 2024-04-19)
bjorn3 Apr 20, 2024
9ad9620
Don't create data object for zero sized allocations
bjorn3 Apr 20, 2024
be9d7ca
Rollup merge of #123967 - RalfJung:static_mut_refs, r=Nilstrieb
jieyouxu Apr 20, 2024
72e6f0c
Remove a couple of items from the crate prelude
bjorn3 Apr 21, 2024
e654877
Also handle AggregateKind::RawPtr in cg_cranelift
scottmcm Apr 12, 2024
a74d6c2
Only apply --cap-lints to the extended_sysroot test suite
bjorn3 Apr 22, 2024
8bc15fb
Sync from rust fb898629a26e4acec59c928ce3ec00a62675d1cc
bjorn3 Apr 22, 2024
d0c5141
Rustup to rustc 1.79.0-nightly (fb898629a 2024-04-21)
bjorn3 Apr 22, 2024
8bf1687
Fix neon test on non arm64 targets
bjorn3 Apr 22, 2024
569df1d
Inline CValue::pointer_from_data_and_meta
bjorn3 Apr 22, 2024
498dbbd
Fix warning in alloc_system.rs
bjorn3 Apr 22, 2024
d569c84
Update libloading
bjorn3 Apr 22, 2024
c02f6c5
Update windows-trgets to 0.52.5
bjorn3 Apr 22, 2024
cea3e7d
Update syn, quote and proc-macro2
bjorn3 Apr 22, 2024
966e269
Update data structure crates
bjorn3 Apr 22, 2024
2c6ef5a
Update a couple of crates
bjorn3 Apr 22, 2024
6ec27fe
Update to Cranelift 0.107
bjorn3 Mar 31, 2024
041666a
Update abi-cafe ui128 test expectations
bjorn3 Apr 1, 2024
de5d652
Rustup to rustc 1.79.0-nightly (7f2fc33da 2024-04-22)
bjorn3 Apr 23, 2024
3d682cf
Merge commit 'de5d6523738fd44a0521b6abf3e73ae1df210741' into sync_cg_…
bjorn3 Apr 23, 2024
7c968a2
Update allowed cg_clif deps
bjorn3 Apr 23, 2024
96152c7
Fix broken subtree sync
bjorn3 Apr 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
239 changes: 90 additions & 149 deletions compiler/rustc_codegen_cranelift/Cargo.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions compiler/rustc_codegen_cranelift/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ crate-type = ["dylib"]

[dependencies]
# These have to be in sync with each other
cranelift-codegen = { version = "0.106.0", default-features = false, features = ["std", "unwind", "all-arch"] }
cranelift-frontend = { version = "0.106.0" }
cranelift-module = { version = "0.106.0" }
cranelift-native = { version = "0.106.0" }
cranelift-jit = { version = "0.106.0", optional = true }
cranelift-object = { version = "0.106.0" }
cranelift-codegen = { version = "0.107.0", default-features = false, features = ["std", "unwind", "all-arch"] }
cranelift-frontend = { version = "0.107.0" }
cranelift-module = { version = "0.107.0" }
cranelift-native = { version = "0.107.0" }
cranelift-jit = { version = "0.107.0", optional = true }
cranelift-object = { version = "0.107.0" }
target-lexicon = "0.12.0"
gimli = { version = "0.28", default-features = false, features = ["write"]}
object = { version = "0.32", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] }
object = { version = "0.33", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] }

indexmap = "2.0.0"
libloading = { version = "0.8.0", optional = true }
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_codegen_cranelift/build_system/abi_cafe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ pub(crate) fn run(
let mut cmd = ABI_CAFE.run(bootstrap_host_compiler, dirs);
cmd.arg("--");
cmd.arg("--pairs");
cmd.args(pairs);
cmd.args(
if cfg!(not(any(target_os = "macos", all(target_os = "windows", target_env = "msvc")))) {
&pairs[..]
} else {
&pairs[..2]
},
);
cmd.arg("--add-rustc-codegen-backend");
match cg_clif_dylib {
CodegenBackend::Local(path) => {
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_codegen_cranelift/build_system/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ pub(crate) fn run_tests(
&& !skip_tests.contains(&"testsuite.extended_sysroot");

if run_base_sysroot || run_extended_sysroot {
let mut target_compiler = build_sysroot::build_sysroot(
let target_compiler = build_sysroot::build_sysroot(
dirs,
channel,
sysroot_kind,
Expand All @@ -299,11 +299,8 @@ pub(crate) fn run_tests(
rustup_toolchain_name,
target_triple.clone(),
);
// Rust's build system denies a couple of lints that trigger on several of the test
// projects. Changing the code to fix them is not worth it, so just silence all lints.
target_compiler.rustflags.push("--cap-lints=allow".to_owned());

let runner = TestRunner::new(
let mut runner = TestRunner::new(
dirs.clone(),
target_compiler,
use_unstable_features,
Expand All @@ -319,6 +316,9 @@ pub(crate) fn run_tests(
}

if run_extended_sysroot {
// Rust's build system denies a couple of lints that trigger on several of the test
// projects. Changing the code to fix them is not worth it, so just silence all lints.
runner.target_compiler.rustflags.push("--cap-lints=allow".to_owned());
runner.run_testsuite(EXTENDED_SYSROOT_SUITE);
} else {
eprintln!("[SKIP] extended_sysroot tests");
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_cranelift/example/alloc_example.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![feature(start, core_intrinsics, alloc_error_handler, lang_items)]
#![allow(internal_features)]
#![no_std]

extern crate alloc;
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_codegen_cranelift/example/alloc_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ mod platform {
extern "system" {
fn GetProcessHeap() -> HANDLE;
fn HeapAlloc(hHeap: HANDLE, dwFlags: DWORD, dwBytes: SIZE_T) -> LPVOID;
fn HeapReAlloc(hHeap: HANDLE, dwFlags: DWORD, lpMem: LPVOID, dwBytes: SIZE_T) -> LPVOID;
fn HeapFree(hHeap: HANDLE, dwFlags: DWORD, lpMem: LPVOID) -> BOOL;
fn GetLastError() -> DWORD;
}
Expand Down Expand Up @@ -111,7 +110,7 @@ mod platform {
allocate_with_flags(layout, HEAP_ZERO_MEMORY)
}
#[inline]
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
let header = get_header(ptr);
let err = HeapFree(GetProcessHeap(), 0, header.0 as LPVOID);
debug_assert!(err != 0, "Failed to free heap memory: {}", GetLastError());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Test that the simd_f{min,max} intrinsics produce the correct results.

#![feature(repr_simd, core_intrinsics)]
#![allow(non_camel_case_types)]
#![allow(internal_features, non_camel_case_types)]

#[repr(simd)]
#[derive(Copy, Clone, PartialEq, Debug)]
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_cranelift/example/mod_bench.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![feature(start, core_intrinsics, lang_items)]
#![allow(internal_features)]
#![no_std]

#[cfg_attr(unix, link(name = "c"))]
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_codegen_cranelift/example/neon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

#[cfg(target_arch = "aarch64")]
use std::arch::aarch64::*;
#[cfg(target_arch = "aarch64")]
use std::mem::transmute;
#[cfg(target_arch = "aarch64")]
use std::simd::*;

#[cfg(target_arch = "aarch64")]
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_cranelift/example/std_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
tuple_trait,
unboxed_closures
)]
#![allow(internal_features)]

#[cfg(target_arch = "x86_64")]
use std::arch::x86_64::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ diff --git a/src/report.rs b/src/report.rs
index eeec614..f582867 100644
--- a/src/report.rs
+++ b/src/report.rs
@@ -48,6 +48,12 @@ pub fn get_test_rules(test: &TestKey, caller: &dyn AbiImpl, callee: &dyn AbiImpl
@@ -48,6 +48,15 @@ pub fn get_test_rules(test: &TestKey, caller: &dyn AbiImpl, callee: &dyn AbiImpl
//
// THIS AREA RESERVED FOR VENDORS TO APPLY PATCHES

+ // x86_64-pc-windows-gnu has some broken i128 tests that aren't disabled by default
+ if cfg!(all(target_os = "windows", target_env = "gnu")) && test.test_name == "ui128" {
+ result.run = Link;
+ result.check = Pass(Link);
+ } else if test.test_name == "ui128" {
+ result.run == Check;
+ result.check = Pass(Check);
+ }
+
// END OF VENDOR RESERVED AREA
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2024-04-11"
channel = "nightly-2024-04-23"
components = ["rust-src", "rustc-dev", "llvm-tools"]
2 changes: 2 additions & 0 deletions compiler/rustc_codegen_cranelift/src/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ mod returning;
use std::borrow::Cow;

use cranelift_codegen::ir::SigRef;
use cranelift_codegen::isa::CallConv;
use cranelift_module::ModuleError;
use rustc_codegen_ssa::errors::CompilerBuiltinsCannotCall;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::ty::layout::FnAbiOf;
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::TypeVisitableExt;
use rustc_monomorphize::is_call_from_compiler_builtins_to_upstream_monomorphization;
use rustc_session::Session;
use rustc_span::source_map::Spanned;
Expand Down
10 changes: 9 additions & 1 deletion compiler/rustc_codegen_cranelift/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

use cranelift_codegen::ir::UserFuncName;
use cranelift_codegen::CodegenError;
use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
use cranelift_module::ModuleError;
use rustc_ast::InlineAsmOptions;
use rustc_index::IndexVec;
use rustc_middle::ty::adjustment::PointerCoercion;
use rustc_middle::ty::layout::FnAbiOf;
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::TypeVisitableExt;
use rustc_monomorphize::is_call_from_compiler_builtins_to_upstream_monomorphization;

use crate::constant::ConstantCx;
Expand Down Expand Up @@ -823,7 +825,13 @@ fn codegen_stmt<'tcx>(
};
let data = codegen_operand(fx, data);
let meta = codegen_operand(fx, meta);
let ptr_val = CValue::pointer_from_data_and_meta(data, meta, layout);
assert!(data.layout().ty.is_unsafe_ptr());
assert!(layout.ty.is_unsafe_ptr());
let ptr_val = if meta.layout().is_zst() {
data.cast_pointer_to(layout)
} else {
CValue::by_val_pair(data.load_scalar(fx), meta.load_scalar(fx), layout)
};
lval.write_cvalue(fx, ptr_val);
}
Rvalue::Aggregate(ref kind, ref operands) => {
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_codegen_cranelift/src/common.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use cranelift_codegen::isa::TargetFrontendConfig;
use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
use rustc_index::IndexVec;
use rustc_middle::ty::layout::{
FnAbiError, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOfHelpers,
self, FnAbiError, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOfHelpers,
};
use rustc_middle::ty::TypeFoldable;
use rustc_span::source_map::Spanned;
use rustc_target::abi::call::FnAbi;
use rustc_target::abi::{Integer, Primitive};
Expand Down
27 changes: 16 additions & 11 deletions compiler/rustc_codegen_cranelift/src/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,23 @@ pub(crate) fn codegen_const_value<'tcx>(
let alloc_id = prov.alloc_id();
let base_addr = match fx.tcx.global_alloc(alloc_id) {
GlobalAlloc::Memory(alloc) => {
let data_id = data_id_for_alloc_id(
&mut fx.constants_cx,
fx.module,
alloc_id,
alloc.inner().mutability,
);
let local_data_id =
fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
if fx.clif_comments.enabled() {
fx.add_comment(local_data_id, format!("{:?}", alloc_id));
if alloc.inner().len() == 0 {
assert_eq!(offset, Size::ZERO);
fx.bcx.ins().iconst(fx.pointer_type, alloc.inner().align.bytes() as i64)
} else {
let data_id = data_id_for_alloc_id(
&mut fx.constants_cx,
fx.module,
alloc_id,
alloc.inner().mutability,
);
let local_data_id =
fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
if fx.clif_comments.enabled() {
fx.add_comment(local_data_id, format!("{:?}", alloc_id));
}
fx.bcx.ins().global_value(fx.pointer_type, local_data_id)
}
fx.bcx.ins().global_value(fx.pointer_type, local_data_id)
}
GlobalAlloc::Function(instance) => {
let func_id = crate::abi::import_function(fx.tcx, fx.module, instance);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use rustc_codegen_ssa::debuginfo::type_names;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::DefIdMap;
use rustc_session::Session;
use rustc_span::{SourceFileHash, StableSourceFileId};
use rustc_span::{FileNameDisplayPreference, SourceFileHash, StableSourceFileId};
use rustc_target::abi::call::FnAbi;

pub(crate) use self::emit::{DebugReloc, DebugRelocName};
Expand Down
10 changes: 6 additions & 4 deletions compiler/rustc_codegen_cranelift/src/debuginfo/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use cranelift_module::{DataId, FuncId};
use cranelift_object::ObjectProduct;
use gimli::SectionId;
use object::write::{Relocation, StandardSegment};
use object::{RelocationEncoding, SectionKind};
use object::{RelocationEncoding, RelocationFlags, SectionKind};
use rustc_data_structures::fx::FxHashMap;

use crate::debuginfo::{DebugReloc, DebugRelocName};
Expand Down Expand Up @@ -72,9 +72,11 @@ impl WriteDebugInfo for ObjectProduct {
Relocation {
offset: u64::from(reloc.offset),
symbol,
kind: reloc.kind,
encoding: RelocationEncoding::Generic,
size: reloc.size * 8,
flags: RelocationFlags::Generic {
kind: reloc.kind,
encoding: RelocationEncoding::Generic,
size: reloc.size * 8,
},
addend: i64::try_from(symbol_offset).unwrap() + reloc.addend,
},
)
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_cranelift/src/driver/jit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::ffi::CString;
use std::os::raw::{c_char, c_int};
use std::sync::{mpsc, Mutex, OnceLock};

use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
use cranelift_jit::{JITBuilder, JITModule};
use rustc_codegen_ssa::CrateInfo;
use rustc_middle::mir::mono::MonoItem;
Expand Down
26 changes: 24 additions & 2 deletions compiler/rustc_codegen_cranelift/src/inline_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use std::fmt::Write;

use cranelift_codegen::isa::CallConv;
use rustc_ast::ast::{InlineAsmOptions, InlineAsmTemplatePiece};
use rustc_span::sym;
use rustc_target::asm::*;
Expand Down Expand Up @@ -785,9 +786,9 @@ fn call_inline_asm<'tcx>(
for (offset, place) in outputs {
let ty = if place.layout().ty.is_simd() {
let (lane_count, lane_type) = place.layout().ty.simd_size_and_type(fx.tcx);
fx.clif_type(lane_type).unwrap().by(lane_count.try_into().unwrap()).unwrap()
asm_clif_type(fx, lane_type).unwrap().by(lane_count.try_into().unwrap()).unwrap()
} else {
fx.clif_type(place.layout().ty).unwrap()
asm_clif_type(fx, place.layout().ty).unwrap()
};
let value = stack_slot.offset(fx, i32::try_from(offset.bytes()).unwrap().into()).load(
fx,
Expand All @@ -797,3 +798,24 @@ fn call_inline_asm<'tcx>(
place.write_cvalue(fx, CValue::by_val(value, place.layout()));
}
}

fn asm_clif_type<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> Option<types::Type> {
match ty.kind() {
// Adapted from https://github.com/rust-lang/rust/blob/f3c66088610c1b80110297c2d9a8b5f9265b013f/compiler/rustc_hir_analysis/src/check/intrinsicck.rs#L136-L151
ty::Adt(adt, args) if Some(adt.did()) == fx.tcx.lang_items().maybe_uninit() => {
let fields = &adt.non_enum_variant().fields;
let ty = fields[FieldIdx::from_u32(1)].ty(fx.tcx, args);
let ty::Adt(ty, args) = ty.kind() else {
unreachable!("expected first field of `MaybeUninit` to be an ADT")
};
assert!(
ty.is_manually_drop(),
"expected first field of `MaybeUninit` to be `ManuallyDrop`"
);
let fields = &ty.non_enum_variant().fields;
let ty = fields[FieldIdx::ZERO].ty(fx.tcx, args);
fx.clif_type(ty)
}
_ => fx.clif_type(ty),
}
}
12 changes: 4 additions & 8 deletions compiler/rustc_codegen_cranelift/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,17 @@ mod prelude {
AbiParam, Block, FuncRef, Inst, InstBuilder, MemFlags, Signature, SourceLoc, StackSlot,
StackSlotData, StackSlotKind, TrapCode, Type, Value,
};
pub(crate) use cranelift_codegen::isa::{self, CallConv};
pub(crate) use cranelift_codegen::Context;
pub(crate) use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext, Variable};
pub(crate) use cranelift_module::{self, DataDescription, FuncId, Linkage, Module};
pub(crate) use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
pub(crate) use rustc_hir::def_id::{DefId, LOCAL_CRATE};
pub(crate) use rustc_index::Idx;
pub(crate) use rustc_middle::bug;
pub(crate) use rustc_middle::mir::{self, *};
pub(crate) use rustc_middle::ty::layout::{self, LayoutOf, TyAndLayout};
pub(crate) use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
pub(crate) use rustc_middle::ty::{
self, FloatTy, Instance, InstanceDef, IntTy, ParamEnv, Ty, TyCtxt, TypeAndMut,
TypeFoldable, TypeVisitableExt, UintTy,
self, FloatTy, Instance, InstanceDef, IntTy, ParamEnv, Ty, TyCtxt, TypeAndMut, UintTy,
};
pub(crate) use rustc_span::{FileNameDisplayPreference, Span};
pub(crate) use rustc_span::Span;
pub(crate) use rustc_target::abi::{Abi, FieldIdx, Scalar, Size, VariantIdx, FIRST_VARIANT};

pub(crate) use crate::abi::*;
Expand Down Expand Up @@ -261,7 +257,7 @@ fn target_triple(sess: &Session) -> target_lexicon::Triple {
}
}

fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Arc<dyn isa::TargetIsa + 'static> {
fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Arc<dyn TargetIsa + 'static> {
use target_lexicon::BinaryFormat;

let target_triple = crate::target_triple(sess);
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_cranelift/src/main_shim.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
use rustc_hir::LangItem;
use rustc_middle::ty::AssocKind;
use rustc_middle::ty::GenericArg;
Expand Down
18 changes: 1 addition & 17 deletions compiler/rustc_codegen_cranelift/src/value_and_place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use cranelift_codegen::entity::EntityRef;
use cranelift_codegen::ir::immediates::Offset32;
use cranelift_frontend::Variable;
use rustc_middle::ty::FnSig;

use crate::prelude::*;
Expand Down Expand Up @@ -94,23 +95,6 @@ impl<'tcx> CValue<'tcx> {
CValue(CValueInner::ByValPair(value, extra), layout)
}

/// For `AggregateKind::RawPtr`, create a pointer from its parts.
///
/// Panics if the `layout` is not a raw pointer.
pub(crate) fn pointer_from_data_and_meta(
data: CValue<'tcx>,
meta: CValue<'tcx>,
layout: TyAndLayout<'tcx>,
) -> CValue<'tcx> {
assert!(layout.ty.is_unsafe_ptr());
let inner = match (data.0, meta.0) {
(CValueInner::ByVal(p), CValueInner::ByVal(m)) => CValueInner::ByValPair(p, m),
(p @ CValueInner::ByVal(_), CValueInner::ByRef(..)) if meta.1.is_zst() => p,
_ => bug!("RawPtr operands {data:?} {meta:?}"),
};
CValue(inner, layout)
}

pub(crate) fn layout(&self) -> TyAndLayout<'tcx> {
self.1
}
Expand Down
Loading
Loading