Skip to content

Commit 5367df5

Browse files
Auto merge of #142616 - workingjubilee:rollup-0t8naf1, r=<try>
Rollup of 7 pull requests Successful merges: - #141061 (Change __rust_no_alloc_shim_is_unstable to be a function) - #142585 (Update books) - #142586 (Fold unnecessary `visit_struct_field_def` in AstValidator) - #142587 (Make sure to propagate result from `visit_expr_fields`) - #142595 (Revert overeager warning for misuse of `--print native-static-libs`) - #142598 (Set elf e_flags on ppc64 targets according to abi) - #142601 (Add a comment to `FORMAT_VERSION`.) r? `@ghost` `@rustbot` modify labels: rollup <!-- homu-ignore:start --> [Create a similar rollup](https://bors.rust-lang.org/queue/rust?prs=141061,142585,142586,142587,142595,142598,142601) <!-- homu-ignore:end --> try-job: x86_64-gnu-aux
2 parents 55d4364 + 669d06d commit 5367df5

Some content is hidden

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

41 files changed

+217
-194
lines changed

compiler/rustc_ast/src/expand/allocator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub fn alloc_error_handler_name(alloc_error_handler_kind: AllocatorKind) -> &'st
2222
}
2323
}
2424

25-
pub const NO_ALLOC_SHIM_IS_UNSTABLE: &str = "__rust_no_alloc_shim_is_unstable";
25+
pub const NO_ALLOC_SHIM_IS_UNSTABLE: &str = "__rust_no_alloc_shim_is_unstable_v2";
2626

2727
pub enum AllocatorTy {
2828
Layout,

compiler/rustc_ast/src/visit.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ macro_rules! common_visitor_and_walkers {
884884
TyKind::BareFn(function_declaration) => {
885885
let BareFnTy { safety, ext: _, generic_params, decl, decl_span } =
886886
&$($mut)? **function_declaration;
887-
visit_safety(vis, safety);
887+
try_visit!(visit_safety(vis, safety));
888888
try_visit!(visit_generic_params(vis, generic_params));
889889
try_visit!(vis.visit_fn_decl(decl));
890890
try_visit!(visit_span(vis, decl_span));
@@ -1235,7 +1235,7 @@ macro_rules! common_visitor_and_walkers {
12351235
bounds,
12361236
bound_generic_params,
12371237
}) => {
1238-
visit_generic_params(vis, bound_generic_params);
1238+
try_visit!(visit_generic_params(vis, bound_generic_params));
12391239
try_visit!(vis.visit_ty(bounded_ty));
12401240
walk_list!(vis, visit_param_bound, bounds, BoundKind::Bound);
12411241
}
@@ -1420,7 +1420,7 @@ macro_rules! common_visitor_and_walkers {
14201420
let StructExpr { qself, path, fields, rest } = &$($mut)?**se;
14211421
try_visit!(vis.visit_qself(qself));
14221422
try_visit!(vis.visit_path(path));
1423-
visit_expr_fields(vis, fields);
1423+
try_visit!(visit_expr_fields(vis, fields));
14241424
match rest {
14251425
StructRest::Base(expr) => try_visit!(vis.visit_expr(expr)),
14261426
StructRest::Rest(_span) => {}

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -224,20 +224,6 @@ impl<'a> AstValidator<'a> {
224224
}
225225
}
226226

227-
fn visit_struct_field_def(&mut self, field: &'a FieldDef) {
228-
if let Some(ref ident) = field.ident
229-
&& ident.name == kw::Underscore
230-
{
231-
self.visit_vis(&field.vis);
232-
self.visit_ident(ident);
233-
self.visit_ty_common(&field.ty);
234-
self.walk_ty(&field.ty);
235-
walk_list!(self, visit_attribute, &field.attrs);
236-
} else {
237-
self.visit_field_def(field);
238-
}
239-
}
240-
241227
fn dcx(&self) -> DiagCtxtHandle<'a> {
242228
self.sess.dcx()
243229
}
@@ -1135,8 +1121,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11351121
VariantData::Struct { fields, .. } => {
11361122
self.visit_attrs_vis_ident(&item.attrs, &item.vis, ident);
11371123
self.visit_generics(generics);
1138-
// Permit `Anon{Struct,Union}` as field type.
1139-
walk_list!(self, visit_struct_field_def, fields);
1124+
walk_list!(self, visit_field_def, fields);
11401125
}
11411126
_ => visit::walk_item(self, item),
11421127
},
@@ -1148,8 +1133,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11481133
VariantData::Struct { fields, .. } => {
11491134
self.visit_attrs_vis_ident(&item.attrs, &item.vis, ident);
11501135
self.visit_generics(generics);
1151-
// Permit `Anon{Struct,Union}` as field type.
1152-
walk_list!(self, visit_struct_field_def, fields);
1136+
walk_list!(self, visit_field_def, fields);
11531137
}
11541138
_ => visit::walk_item(self, item),
11551139
}

compiler/rustc_codegen_cranelift/src/allocator.rs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Allocator shim
22
// Adapted from rustc
33

4+
use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
45
use rustc_ast::expand::allocator::{
56
ALLOCATOR_METHODS, AllocatorKind, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE,
67
alloc_error_handler_name, default_fn_name, global_fn_name,
@@ -97,16 +98,31 @@ fn codegen_inner(
9798
data.define(Box::new([val]));
9899
module.define_data(data_id, &data).unwrap();
99100

100-
let data_id = module
101-
.declare_data(
102-
&mangle_internal_symbol(tcx, NO_ALLOC_SHIM_IS_UNSTABLE),
103-
Linkage::Export,
104-
false,
105-
false,
106-
)
107-
.unwrap();
108-
let mut data = DataDescription::new();
109-
data.set_align(1);
110-
data.define(Box::new([0]));
111-
module.define_data(data_id, &data).unwrap();
101+
{
102+
let sig = Signature {
103+
call_conv: module.target_config().default_call_conv,
104+
params: vec![],
105+
returns: vec![],
106+
};
107+
let func_id = module
108+
.declare_function(
109+
&mangle_internal_symbol(tcx, NO_ALLOC_SHIM_IS_UNSTABLE),
110+
Linkage::Export,
111+
&sig,
112+
)
113+
.unwrap();
114+
115+
let mut ctx = Context::new();
116+
ctx.func.signature = sig;
117+
let mut func_ctx = FunctionBuilderContext::new();
118+
let mut bcx = FunctionBuilder::new(&mut ctx.func, &mut func_ctx);
119+
120+
let block = bcx.create_block();
121+
bcx.switch_to_block(block);
122+
bcx.ins().return_(&[]);
123+
bcx.seal_all_blocks();
124+
bcx.finalize();
125+
126+
module.define_function(func_id, &mut ctx).unwrap();
127+
}
112128
}

compiler/rustc_codegen_gcc/src/allocator.rs

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub(crate) unsafe fn codegen(
5757
let from_name = mangle_internal_symbol(tcx, &global_fn_name(method.name));
5858
let to_name = mangle_internal_symbol(tcx, &default_fn_name(method.name));
5959

60-
create_wrapper_function(tcx, context, &from_name, &to_name, &types, output);
60+
create_wrapper_function(tcx, context, &from_name, Some(&to_name), &types, output);
6161
}
6262
}
6363

@@ -66,7 +66,7 @@ pub(crate) unsafe fn codegen(
6666
tcx,
6767
context,
6868
&mangle_internal_symbol(tcx, "__rust_alloc_error_handler"),
69-
&mangle_internal_symbol(tcx, alloc_error_handler_name(alloc_error_handler_kind)),
69+
Some(&mangle_internal_symbol(tcx, alloc_error_handler_name(alloc_error_handler_kind))),
7070
&[usize, usize],
7171
None,
7272
);
@@ -81,21 +81,21 @@ pub(crate) unsafe fn codegen(
8181
let value = context.new_rvalue_from_int(i8, value as i32);
8282
global.global_set_initializer_rvalue(value);
8383

84-
let name = mangle_internal_symbol(tcx, NO_ALLOC_SHIM_IS_UNSTABLE);
85-
let global = context.new_global(None, GlobalKind::Exported, i8, name);
86-
#[cfg(feature = "master")]
87-
global.add_attribute(VarAttribute::Visibility(symbol_visibility_to_gcc(
88-
tcx.sess.default_visibility(),
89-
)));
90-
let value = context.new_rvalue_from_int(i8, 0);
91-
global.global_set_initializer_rvalue(value);
84+
create_wrapper_function(
85+
tcx,
86+
context,
87+
&mangle_internal_symbol(tcx, NO_ALLOC_SHIM_IS_UNSTABLE),
88+
None,
89+
&[],
90+
None,
91+
);
9292
}
9393

9494
fn create_wrapper_function(
9595
tcx: TyCtxt<'_>,
9696
context: &Context<'_>,
9797
from_name: &str,
98-
to_name: &str,
98+
to_name: Option<&str>,
9999
types: &[Type<'_>],
100100
output: Option<Type<'_>>,
101101
) {
@@ -124,34 +124,40 @@ fn create_wrapper_function(
124124
// TODO(antoyo): emit unwind tables.
125125
}
126126

127-
let args: Vec<_> = types
128-
.iter()
129-
.enumerate()
130-
.map(|(index, typ)| context.new_parameter(None, *typ, format!("param{}", index)))
131-
.collect();
132-
let callee = context.new_function(
133-
None,
134-
FunctionType::Extern,
135-
output.unwrap_or(void),
136-
&args,
137-
to_name,
138-
false,
139-
);
140-
#[cfg(feature = "master")]
141-
callee.add_attribute(FnAttribute::Visibility(gccjit::Visibility::Hidden));
142-
143127
let block = func.new_block("entry");
144128

145-
let args = args
146-
.iter()
147-
.enumerate()
148-
.map(|(i, _)| func.get_param(i as i32).to_rvalue())
149-
.collect::<Vec<_>>();
150-
let ret = context.new_call(None, callee, &args);
151-
//llvm::LLVMSetTailCall(ret, True);
152-
if output.is_some() {
153-
block.end_with_return(None, ret);
129+
if let Some(to_name) = to_name {
130+
let args: Vec<_> = types
131+
.iter()
132+
.enumerate()
133+
.map(|(index, typ)| context.new_parameter(None, *typ, format!("param{}", index)))
134+
.collect();
135+
let callee = context.new_function(
136+
None,
137+
FunctionType::Extern,
138+
output.unwrap_or(void),
139+
&args,
140+
to_name,
141+
false,
142+
);
143+
#[cfg(feature = "master")]
144+
callee.add_attribute(FnAttribute::Visibility(gccjit::Visibility::Hidden));
145+
146+
let args = args
147+
.iter()
148+
.enumerate()
149+
.map(|(i, _)| func.get_param(i as i32).to_rvalue())
150+
.collect::<Vec<_>>();
151+
let ret = context.new_call(None, callee, &args);
152+
//llvm::LLVMSetTailCall(ret, True);
153+
if output.is_some() {
154+
block.end_with_return(None, ret);
155+
} else {
156+
block.add_eval(None, ret);
157+
block.end_with_void_return(None);
158+
}
154159
} else {
160+
assert!(output.is_none());
155161
block.end_with_void_return(None);
156162
}
157163

compiler/rustc_codegen_llvm/src/allocator.rs

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub(crate) unsafe fn codegen(
5757
let from_name = mangle_internal_symbol(tcx, &global_fn_name(method.name));
5858
let to_name = mangle_internal_symbol(tcx, &default_fn_name(method.name));
5959

60-
create_wrapper_function(tcx, &cx, &from_name, &to_name, &args, output, false);
60+
create_wrapper_function(tcx, &cx, &from_name, Some(&to_name), &args, output, false);
6161
}
6262
}
6363

@@ -66,7 +66,7 @@ pub(crate) unsafe fn codegen(
6666
tcx,
6767
&cx,
6868
&mangle_internal_symbol(tcx, "__rust_alloc_error_handler"),
69-
&mangle_internal_symbol(tcx, alloc_error_handler_name(alloc_error_handler_kind)),
69+
Some(&mangle_internal_symbol(tcx, alloc_error_handler_name(alloc_error_handler_kind))),
7070
&[usize, usize], // size, align
7171
None,
7272
true,
@@ -81,11 +81,16 @@ pub(crate) unsafe fn codegen(
8181
let llval = llvm::LLVMConstInt(i8, val as u64, False);
8282
llvm::set_initializer(ll_g, llval);
8383

84-
let name = mangle_internal_symbol(tcx, NO_ALLOC_SHIM_IS_UNSTABLE);
85-
let ll_g = cx.declare_global(&name, i8);
86-
llvm::set_visibility(ll_g, llvm::Visibility::from_generic(tcx.sess.default_visibility()));
87-
let llval = llvm::LLVMConstInt(i8, 0, False);
88-
llvm::set_initializer(ll_g, llval);
84+
// __rust_no_alloc_shim_is_unstable_v2
85+
create_wrapper_function(
86+
tcx,
87+
&cx,
88+
&mangle_internal_symbol(tcx, NO_ALLOC_SHIM_IS_UNSTABLE),
89+
None,
90+
&[],
91+
None,
92+
false,
93+
);
8994
}
9095

9196
if tcx.sess.opts.debuginfo != DebugInfo::None {
@@ -99,7 +104,7 @@ fn create_wrapper_function(
99104
tcx: TyCtxt<'_>,
100105
cx: &SimpleCx<'_>,
101106
from_name: &str,
102-
to_name: &str,
107+
to_name: Option<&str>,
103108
args: &[&Type],
104109
output: Option<&Type>,
105110
no_return: bool,
@@ -128,33 +133,38 @@ fn create_wrapper_function(
128133
attributes::apply_to_llfn(llfn, llvm::AttributePlace::Function, &[uwtable]);
129134
}
130135

131-
let callee = declare_simple_fn(
132-
&cx,
133-
to_name,
134-
llvm::CallConv::CCallConv,
135-
llvm::UnnamedAddr::Global,
136-
llvm::Visibility::Hidden,
137-
ty,
138-
);
139-
if let Some(no_return) = no_return {
140-
// -> ! DIFlagNoReturn
141-
attributes::apply_to_llfn(callee, llvm::AttributePlace::Function, &[no_return]);
142-
}
143-
llvm::set_visibility(callee, llvm::Visibility::Hidden);
144-
145136
let llbb = unsafe { llvm::LLVMAppendBasicBlockInContext(cx.llcx, llfn, c"entry".as_ptr()) };
146-
147137
let mut bx = SBuilder::build(&cx, llbb);
148-
let args = args
149-
.iter()
150-
.enumerate()
151-
.map(|(i, _)| llvm::get_param(llfn, i as c_uint))
152-
.collect::<Vec<_>>();
153-
let ret = bx.call(ty, callee, &args, None);
154-
llvm::LLVMSetTailCall(ret, True);
155-
if output.is_some() {
156-
bx.ret(ret);
138+
139+
if let Some(to_name) = to_name {
140+
let callee = declare_simple_fn(
141+
&cx,
142+
to_name,
143+
llvm::CallConv::CCallConv,
144+
llvm::UnnamedAddr::Global,
145+
llvm::Visibility::Hidden,
146+
ty,
147+
);
148+
if let Some(no_return) = no_return {
149+
// -> ! DIFlagNoReturn
150+
attributes::apply_to_llfn(callee, llvm::AttributePlace::Function, &[no_return]);
151+
}
152+
llvm::set_visibility(callee, llvm::Visibility::Hidden);
153+
154+
let args = args
155+
.iter()
156+
.enumerate()
157+
.map(|(i, _)| llvm::get_param(llfn, i as c_uint))
158+
.collect::<Vec<_>>();
159+
let ret = bx.call(ty, callee, &args, None);
160+
llvm::LLVMSetTailCall(ret, True);
161+
if output.is_some() {
162+
bx.ret(ret);
163+
} else {
164+
bx.ret_void()
165+
}
157166
} else {
167+
assert!(output.is_none());
158168
bx.ret_void()
159169
}
160170
}

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -69,23 +69,6 @@ pub fn ensure_removed(dcx: DiagCtxtHandle<'_>, path: &Path) {
6969
}
7070
}
7171

72-
fn check_link_info_print_request(sess: &Session, crate_types: &[CrateType]) {
73-
let print_native_static_libs =
74-
sess.opts.prints.iter().any(|p| p.kind == PrintKind::NativeStaticLibs);
75-
let has_staticlib = crate_types.iter().any(|ct| *ct == CrateType::Staticlib);
76-
if print_native_static_libs {
77-
if !has_staticlib {
78-
sess.dcx()
79-
.warn(format!("cannot output linkage information without staticlib crate-type"));
80-
sess.dcx()
81-
.note(format!("consider `--crate-type staticlib` to print linkage information"));
82-
} else if !sess.opts.output_types.should_link() {
83-
sess.dcx()
84-
.warn(format!("cannot output linkage information when --emit link is not passed"));
85-
}
86-
}
87-
}
88-
8972
/// Performs the linkage portion of the compilation phase. This will generate all
9073
/// of the requested outputs for this compilation session.
9174
pub fn link_binary(
@@ -208,8 +191,6 @@ pub fn link_binary(
208191
}
209192
}
210193

211-
check_link_info_print_request(sess, &codegen_results.crate_info.crate_types);
212-
213194
// Remove the temporary object file and metadata if we aren't saving temps.
214195
sess.time("link_binary_remove_temps", || {
215196
// If the user requests that temporaries are saved, don't delete any.

0 commit comments

Comments
 (0)