Skip to content

Commit 57ec426

Browse files
committed
Auto merge of #147692 - matthiaskrgr:rollup-bqhlwyw, r=matthiaskrgr
Rollup of 12 pull requests Successful merges: - rust-lang/rust#146187 (Unstably constify `ptr::drop_in_place` and related methods) - rust-lang/rust#146503 (std: improve handling of timed condition variable waits on macOS) - rust-lang/rust#147526 (Move computation of allocator shim contents to cg_ssa) - rust-lang/rust#147630 (Bitset cleanups) - rust-lang/rust#147638 (bpf: return results larger than one register indirectly) - rust-lang/rust#147666 (Replace manual implementation with `carrying_mul_add`) - rust-lang/rust#147669 (fix missing link to `std::char` in `std` docs) - rust-lang/rust#147673 (pretty print u128 with display) - rust-lang/rust#147677 (Fewer exceptions in `span()` on parsed attributes) - rust-lang/rust#147680 (Fix ICE caused by associated_item_def_ids on wrong type in resolve diag) - rust-lang/rust#147682 (convert `rustc_main` to the new attribute parsing infrastructure) - rust-lang/rust#147683 (only check duplicates on old/unparsed attributes) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f6f2c21 + cb9c32a commit 57ec426

File tree

2 files changed

+29
-42
lines changed

2 files changed

+29
-42
lines changed

src/allocator.rs

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
use gccjit::FnAttribute;
33
use gccjit::{Context, FunctionType, RValue, ToRValue, Type};
44
use rustc_ast::expand::allocator::{
5-
ALLOCATOR_METHODS, AllocatorKind, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE,
6-
alloc_error_handler_name, default_fn_name, global_fn_name,
5+
AllocatorMethod, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE, default_fn_name, global_fn_name,
76
};
87
use rustc_middle::bug;
98
use rustc_middle::ty::TyCtxt;
@@ -18,8 +17,7 @@ pub(crate) unsafe fn codegen(
1817
tcx: TyCtxt<'_>,
1918
mods: &mut GccContext,
2019
_module_name: &str,
21-
kind: AllocatorKind,
22-
alloc_error_handler_kind: AllocatorKind,
20+
methods: &[AllocatorMethod],
2321
) {
2422
let context = &mods.context;
2523
let usize = match tcx.sess.target.pointer_width {
@@ -31,45 +29,35 @@ pub(crate) unsafe fn codegen(
3129
let i8 = context.new_type::<i8>();
3230
let i8p = i8.make_pointer();
3331

34-
if kind == AllocatorKind::Default {
35-
for method in ALLOCATOR_METHODS {
36-
let mut types = Vec::with_capacity(method.inputs.len());
37-
for input in method.inputs.iter() {
38-
match input.ty {
39-
AllocatorTy::Layout => {
40-
types.push(usize);
41-
types.push(usize);
42-
}
43-
AllocatorTy::Ptr => types.push(i8p),
44-
AllocatorTy::Usize => types.push(usize),
45-
46-
AllocatorTy::ResultPtr | AllocatorTy::Unit => panic!("invalid allocator arg"),
32+
for method in methods {
33+
let mut types = Vec::with_capacity(method.inputs.len());
34+
for input in method.inputs.iter() {
35+
match input.ty {
36+
AllocatorTy::Layout => {
37+
types.push(usize);
38+
types.push(usize);
4739
}
48-
}
49-
let output = match method.output {
50-
AllocatorTy::ResultPtr => Some(i8p),
51-
AllocatorTy::Unit => None,
40+
AllocatorTy::Ptr => types.push(i8p),
41+
AllocatorTy::Usize => types.push(usize),
5242

53-
AllocatorTy::Layout | AllocatorTy::Usize | AllocatorTy::Ptr => {
54-
panic!("invalid allocator output")
43+
AllocatorTy::Never | AllocatorTy::ResultPtr | AllocatorTy::Unit => {
44+
panic!("invalid allocator arg")
5545
}
56-
};
57-
let from_name = mangle_internal_symbol(tcx, &global_fn_name(method.name));
58-
let to_name = mangle_internal_symbol(tcx, &default_fn_name(method.name));
59-
60-
create_wrapper_function(tcx, context, &from_name, Some(&to_name), &types, output);
46+
}
6147
}
62-
}
48+
let output = match method.output {
49+
AllocatorTy::ResultPtr => Some(i8p),
50+
AllocatorTy::Never | AllocatorTy::Unit => None,
6351

64-
// FIXME(bjorn3): Add noreturn attribute
65-
create_wrapper_function(
66-
tcx,
67-
context,
68-
&mangle_internal_symbol(tcx, "__rust_alloc_error_handler"),
69-
Some(&mangle_internal_symbol(tcx, alloc_error_handler_name(alloc_error_handler_kind))),
70-
&[usize, usize],
71-
None,
72-
);
52+
AllocatorTy::Layout | AllocatorTy::Usize | AllocatorTy::Ptr => {
53+
panic!("invalid allocator output")
54+
}
55+
};
56+
let from_name = mangle_internal_symbol(tcx, &global_fn_name(method.name));
57+
let to_name = mangle_internal_symbol(tcx, &default_fn_name(method.name));
58+
59+
create_wrapper_function(tcx, context, &from_name, Some(&to_name), &types, output);
60+
}
7361

7462
create_const_value_function(
7563
tcx,

src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ use back::lto::{ThinBuffer, ThinData};
9292
use gccjit::{CType, Context, OptimizationLevel};
9393
#[cfg(feature = "master")]
9494
use gccjit::{TargetInfo, Version};
95-
use rustc_ast::expand::allocator::AllocatorKind;
95+
use rustc_ast::expand::allocator::AllocatorMethod;
9696
use rustc_codegen_ssa::back::lto::{SerializedModule, ThinModule};
9797
use rustc_codegen_ssa::back::write::{
9898
CodegenContext, FatLtoInput, ModuleConfig, TargetMachineFactoryFn,
@@ -284,8 +284,7 @@ impl ExtraBackendMethods for GccCodegenBackend {
284284
&self,
285285
tcx: TyCtxt<'_>,
286286
module_name: &str,
287-
kind: AllocatorKind,
288-
alloc_error_handler_kind: AllocatorKind,
287+
methods: &[AllocatorMethod],
289288
) -> Self::Module {
290289
let mut mods = GccContext {
291290
context: Arc::new(SyncContext::new(new_context(tcx))),
@@ -295,7 +294,7 @@ impl ExtraBackendMethods for GccCodegenBackend {
295294
};
296295

297296
unsafe {
298-
allocator::codegen(tcx, &mut mods, module_name, kind, alloc_error_handler_kind);
297+
allocator::codegen(tcx, &mut mods, module_name, methods);
299298
}
300299
mods
301300
}

0 commit comments

Comments
 (0)