Skip to content

Commit e164200

Browse files
committed
Auto merge of rust-lang#157376 - JonathanBrouwer:rollup-rUrUphg, r=JonathanBrouwer
Rollup of 15 pull requests Successful merges: - rust-lang#155763 (Promotes 5 Thumb-mode bare-metal Arm targets to Tier 2) - rust-lang#156953 (delegation: emit error when there is an infer lifetime in user-specified args) - rust-lang#157248 (delegation: move statements out of the first arg) - rust-lang#157263 (rustc_codegen_ssa: Refactor `ArchiveEntry` to include entry kind) - rust-lang#157311 (Use weak linkage for EII defaults) - rust-lang#156089 (Fix unused_parens for pinned reference patterns) - rust-lang#156928 (Remove -Zemscripten-wasm-eh) - rust-lang#157236 (Reorganize `tests/ui/issues` [3/N]) - rust-lang#157287 (Const generics: remove AliasTerm::kind(), and small fixes) - rust-lang#157294 (Split coroutine layout computation to its own file) - rust-lang#157328 (windows: Elide division-by-zero checks in Instant::now()) - rust-lang#157331 (Rewrite target checking for `#[link]`) - rust-lang#157336 (Enable `clippy::mem_replace_with_default`) - rust-lang#157362 (Fix trivial wf module argument/doc comment name mismatches) - rust-lang#157364 (Rewrite target checking of `rustc_dummy`) Failed merges: - rust-lang#157332 (Rewrite target checking for `#[sanitize]`)
2 parents 042c759 + 49d5453 commit e164200

156 files changed

Lines changed: 2635 additions & 2056 deletions

File tree

Some content is hidden

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

compiler/rustc_ast_lowering/src/delegation.rs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -408,11 +408,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
408408
let block_id = self.lower_body(|this| {
409409
let mut parameters: Vec<hir::Param<'_>> = Vec::with_capacity(param_count);
410410
let mut args: Vec<hir::Expr<'_>> = Vec::with_capacity(param_count);
411+
let mut stmts: &[hir::Stmt<'hir>] = &[];
411412

412413
for idx in 0..param_count {
413414
let (param, pat_node_id) = this.generate_param(is_method, idx, span);
414415
parameters.push(param);
415416

417+
let generate_arg =
418+
|this: &mut Self| this.generate_arg(is_method, idx, param.pat.hir_id, span);
419+
416420
let arg = if let Some(block) = block
417421
&& idx == 0
418422
{
@@ -424,10 +428,24 @@ impl<'hir> LoweringContext<'_, 'hir> {
424428
self_resolver.visit_block(block);
425429
// Target expr needs to lower `self` path.
426430
this.ident_and_label_to_local_id.insert(pat_node_id, param.pat.hir_id.local_id);
427-
this.lower_target_expr(&block)
431+
432+
// Lower with `HirId::INVALID` as we will use only expr and stmts.
433+
// FIXME(fn_delegation): Alternatives for target expression lowering:
434+
// https://github.com/rust-lang/rfcs/pull/3530#issuecomment-2197170600.
435+
let block = this.lower_block_noalloc(HirId::INVALID, block, false);
436+
437+
stmts = block.stmts;
438+
439+
// The behavior of the delegation's target expression differs from the
440+
// behavior of the usual block, where if there is no final expression
441+
// the `()` is returned. In case of the similar situation in delegation
442+
// (no final expression) we propagate first argument instead of replacing
443+
// it with `()`.
444+
if let Some(&expr) = block.expr { expr } else { generate_arg(this) }
428445
} else {
429-
this.generate_arg(is_method, idx, param.pat.hir_id, span)
446+
generate_arg(this)
430447
};
448+
431449
args.push(arg);
432450
}
433451

@@ -439,11 +457,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
439457
if param_count == 0
440458
&& let Some(block) = block
441459
{
442-
args.push(this.lower_target_expr(&block));
460+
args.push(this.lower_block_expr(&block));
443461
}
444462

445463
let (final_expr, hir_id) =
446-
this.finalize_body_lowering(delegation, args, generics, span);
464+
this.finalize_body_lowering(delegation, stmts, args, generics, span);
447465

448466
call_expr_id = hir_id;
449467

@@ -455,22 +473,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
455473
(block_id, call_expr_id)
456474
}
457475

458-
// FIXME(fn_delegation): Alternatives for target expression lowering:
459-
// https://github.com/rust-lang/rfcs/pull/3530#issuecomment-2197170600.
460-
fn lower_target_expr(&mut self, block: &Block) -> hir::Expr<'hir> {
461-
if let [stmt] = block.stmts.as_slice()
462-
&& let StmtKind::Expr(expr) = &stmt.kind
463-
{
464-
return self.lower_expr_mut(expr);
465-
}
466-
467-
let block = self.lower_block(block, false);
468-
self.mk_expr(hir::ExprKind::Block(block, None), block.span)
469-
}
470-
471476
fn finalize_body_lowering(
472477
&mut self,
473478
delegation: &Delegation,
479+
stmts: &'hir [hir::Stmt<'hir>],
474480
args: Vec<hir::Expr<'hir>>,
475481
generics: &mut GenericsGenerationResults<'hir>,
476482
span: Span,
@@ -522,7 +528,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
522528
let call = self.arena.alloc(self.mk_expr(hir::ExprKind::Call(callee_path, args), span));
523529

524530
let block = self.arena.alloc(hir::Block {
525-
stmts: &[],
531+
stmts,
526532
expr: Some(call),
527533
hir_id: self.next_id(),
528534
rules: hir::BlockCheckMode::DefaultBlock,
@@ -587,7 +593,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
587593

588594
let callee_path = this.arena.alloc(this.mk_expr(hir::ExprKind::Path(path), span));
589595
let args = if let Some(block) = delegation.body.as_ref() {
590-
this.arena.alloc_slice(&[this.lower_target_expr(block)])
596+
this.arena.alloc_slice(&[this.lower_block_expr(block)])
591597
} else {
592598
&mut []
593599
};

compiler/rustc_attr_parsing/src/attributes/dummy.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@ use rustc_span::{Symbol, sym};
55
use crate::attributes::{OnDuplicate, SingleAttributeParser};
66
use crate::context::AcceptContext;
77
use crate::parser::ArgParser;
8-
use crate::target_checking::{ALL_TARGETS, AllowedTargets};
8+
use crate::target_checking::AllowedTargets;
99
use crate::unstable;
1010

1111
pub(crate) struct RustcDummyParser;
1212
impl SingleAttributeParser for RustcDummyParser {
1313
const PATH: &[Symbol] = &[sym::rustc_dummy];
1414
const ON_DUPLICATE: OnDuplicate = OnDuplicate::Ignore;
15-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS);
15+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::ManuallyChecked;
1616
const TEMPLATE: AttributeTemplate = template!(Word); // Anything, really
1717
const STABILITY: AttributeStability =
1818
unstable!(rustc_attrs, "the `#[rustc_dummy]` attribute is used for rustc unit tests");
1919

20-
fn convert(_: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
20+
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
2121
args.ignore_args();
22+
cx.ignore_target_checks();
2223
Some(AttributeKind::RustcDummy)
2324
}
2425
}

compiler/rustc_attr_parsing/src/attributes/link_attrs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ impl CombineAttributeParser for LinkParser {
7070
r#"name = "...", import_name_type = "decorated|noprefix|undecorated""#,
7171
r#"name = "...", kind = "dylib|static|...", wasm_import_module = "...", import_name_type = "decorated|noprefix|undecorated""#,
7272
], "https://doc.rust-lang.org/reference/items/external-blocks.html#the-link-attribute");
73-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS); //FIXME Still checked fully in `check_attr.rs`
73+
const ALLOWED_TARGETS: AllowedTargets =
74+
AllowedTargets::AllowListWarnRest(&[Allow(Target::ForeignMod)]);
7475
const STABILITY: AttributeStability = AttributeStability::Stable;
7576

7677
fn extend(

compiler/rustc_attr_parsing/src/target_checking.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,11 +422,15 @@ impl<'f, 'sess> AcceptContext<'f, 'sess> {
422422
attribute_args: &'static str,
423423
allowed_targets: &AllowedTargets,
424424
) {
425+
self.ignore_target_checks();
426+
AttributeParser::check_target(allowed_targets, attribute_args, self);
427+
}
428+
429+
pub(crate) fn ignore_target_checks(&mut self) {
425430
#[cfg(debug_assertions)]
426431
{
427432
self.has_target_been_checked = true;
428433
}
429-
AttributeParser::check_target(allowed_targets, attribute_args, self);
430434
}
431435
}
432436

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use rustc_session::config::{
2626
BranchProtection, CFGuard, CFProtection, CrateType, DebugInfo, FunctionReturn, PAuthKey, PacRet,
2727
};
2828
use rustc_span::{DUMMY_SP, Span, Spanned, Symbol, sym};
29-
use rustc_symbol_mangling::mangle_internal_symbol;
3029
use rustc_target::spec::{
3130
Arch, CfgAbi, Env, FramePointer, HasTargetSpec, Os, RelocModel, SmallDataThresholdSupport,
3231
Target, TlsModel,
@@ -136,7 +135,6 @@ pub(crate) struct FullCx<'ll, 'tcx> {
136135
pub dbg_cx: Option<debuginfo::CodegenUnitDebugContext<'ll, 'tcx>>,
137136

138137
eh_personality: Cell<Option<&'ll Value>>,
139-
eh_catch_typeinfo: Cell<Option<&'ll Value>>,
140138
pub rust_try_fn: Cell<Option<(&'ll Type, &'ll Value)>>,
141139

142140
intrinsics:
@@ -672,7 +670,6 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
672670
coverage_cx,
673671
dbg_cx,
674672
eh_personality: Cell::new(None),
675-
eh_catch_typeinfo: Cell::new(None),
676673
rust_try_fn: Cell::new(None),
677674
intrinsics: Default::default(),
678675
local_gen_sym_counter: Cell::new(0),
@@ -1042,23 +1039,6 @@ impl<'ll> CodegenCx<'ll, '_> {
10421039
}
10431040
}
10441041
}
1045-
1046-
pub(crate) fn eh_catch_typeinfo(&self) -> &'ll Value {
1047-
if let Some(eh_catch_typeinfo) = self.eh_catch_typeinfo.get() {
1048-
return eh_catch_typeinfo;
1049-
}
1050-
let tcx = self.tcx;
1051-
assert!(self.sess().target.os == Os::Emscripten);
1052-
let eh_catch_typeinfo = match tcx.lang_items().eh_catch_typeinfo() {
1053-
Some(def_id) => self.get_static(def_id),
1054-
_ => {
1055-
let ty = self.type_struct(&[self.type_ptr(), self.type_ptr()], false);
1056-
self.declare_global(&mangle_internal_symbol(self.tcx, "rust_eh_catch_typeinfo"), ty)
1057-
}
1058-
};
1059-
self.eh_catch_typeinfo.set(Some(eh_catch_typeinfo));
1060-
eh_catch_typeinfo
1061-
}
10621042
}
10631043

10641044
impl CodegenCx<'_, '_> {

compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,8 @@ fn build_coroutine_variant_struct_type_di_node<'ll, 'tcx>(
328328
.map(|field_index| {
329329
let coroutine_saved_local = coroutine_layout.variant_fields[variant_index]
330330
[FieldIdx::from_usize(field_index)];
331-
let field_name_maybe = coroutine_layout.field_names[coroutine_saved_local];
331+
let field_name_maybe =
332+
coroutine_layout.field_tys[coroutine_saved_local].debuginfo_name;
332333
let field_name = field_name_maybe
333334
.as_ref()
334335
.map(|s| Cow::from(s.as_str()))

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 1 addition & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use rustc_session::lint::builtin::DEPRECATED_LLVM_INTRINSIC;
2828
use rustc_span::{ErrorGuaranteed, Span, Symbol, sym};
2929
use rustc_symbol_mangling::{mangle_internal_symbol, symbol_name_for_instance_in_crate};
3030
use rustc_target::callconv::PassMode;
31-
use rustc_target::spec::{Arch, Os};
31+
use rustc_target::spec::Arch;
3232
use tracing::debug;
3333

3434
use crate::abi::FnAbiLlvmExt;
@@ -1356,8 +1356,6 @@ fn catch_unwind_intrinsic<'ll, 'tcx>(
13561356
codegen_msvc_try(bx, try_func, data, catch_func)
13571357
} else if wants_wasm_eh(bx.sess()) {
13581358
codegen_wasm_try(bx, try_func, data, catch_func)
1359-
} else if bx.sess().target.os == Os::Emscripten {
1360-
codegen_emcc_try(bx, try_func, data, catch_func)
13611359
} else {
13621360
codegen_gnu_try(bx, try_func, data, catch_func)
13631361
}
@@ -1654,87 +1652,6 @@ fn codegen_gnu_try<'ll, 'tcx>(
16541652
ret
16551653
}
16561654

1657-
// Variant of codegen_gnu_try used for emscripten where Rust panics are
1658-
// implemented using C++ exceptions. Here we use exceptions of a specific type
1659-
// (`struct rust_panic`) to represent Rust panics.
1660-
fn codegen_emcc_try<'ll, 'tcx>(
1661-
bx: &mut Builder<'_, 'll, 'tcx>,
1662-
try_func: &'ll Value,
1663-
data: &'ll Value,
1664-
catch_func: &'ll Value,
1665-
) -> &'ll Value {
1666-
let (llty, llfn) = get_rust_try_fn(bx, &mut |mut bx| {
1667-
// Codegens the shims described above:
1668-
//
1669-
// bx:
1670-
// invoke %try_func(%data) normal %normal unwind %catch
1671-
//
1672-
// normal:
1673-
// ret 0
1674-
//
1675-
// catch:
1676-
// (%ptr, %selector) = landingpad
1677-
// %rust_typeid = @llvm.eh.typeid.for(@_ZTI10rust_panic)
1678-
// %is_rust_panic = %selector == %rust_typeid
1679-
// %catch_data = alloca { i8*, i8 }
1680-
// %catch_data[0] = %ptr
1681-
// %catch_data[1] = %is_rust_panic
1682-
// call %catch_func(%data, %catch_data)
1683-
// ret 1
1684-
let then = bx.append_sibling_block("then");
1685-
let catch = bx.append_sibling_block("catch");
1686-
1687-
let try_func = llvm::get_param(bx.llfn(), 0);
1688-
let data = llvm::get_param(bx.llfn(), 1);
1689-
let catch_func = llvm::get_param(bx.llfn(), 2);
1690-
let try_func_ty = bx.type_func(&[bx.type_ptr()], bx.type_void());
1691-
bx.invoke(try_func_ty, None, None, try_func, &[data], then, catch, None, None);
1692-
1693-
bx.switch_to_block(then);
1694-
bx.ret(bx.const_bool(false));
1695-
1696-
// Type indicator for the exception being thrown.
1697-
//
1698-
// The first value in this tuple is a pointer to the exception object
1699-
// being thrown. The second value is a "selector" indicating which of
1700-
// the landing pad clauses the exception's type had been matched to.
1701-
bx.switch_to_block(catch);
1702-
let tydesc = bx.eh_catch_typeinfo();
1703-
let lpad_ty = bx.type_struct(&[bx.type_ptr(), bx.type_i32()], false);
1704-
let vals = bx.landing_pad(lpad_ty, bx.eh_personality(), 2);
1705-
bx.add_clause(vals, tydesc);
1706-
bx.add_clause(vals, bx.const_null(bx.type_ptr()));
1707-
let ptr = bx.extract_value(vals, 0);
1708-
let selector = bx.extract_value(vals, 1);
1709-
1710-
// Check if the typeid we got is the one for a Rust panic.
1711-
let rust_typeid = bx.call_intrinsic("llvm.eh.typeid.for", &[bx.val_ty(tydesc)], &[tydesc]);
1712-
let is_rust_panic = bx.icmp(IntPredicate::IntEQ, selector, rust_typeid);
1713-
let is_rust_panic = bx.zext(is_rust_panic, bx.type_bool());
1714-
1715-
// We need to pass two values to catch_func (ptr and is_rust_panic), so
1716-
// create an alloca and pass a pointer to that.
1717-
let ptr_size = bx.tcx().data_layout.pointer_size();
1718-
let ptr_align = bx.tcx().data_layout.pointer_align().abi;
1719-
let i8_align = bx.tcx().data_layout.i8_align;
1720-
// Required in order for there to be no padding between the fields.
1721-
assert!(i8_align <= ptr_align);
1722-
let catch_data = bx.alloca(2 * ptr_size, ptr_align);
1723-
bx.store(ptr, catch_data, ptr_align);
1724-
let catch_data_1 = bx.inbounds_ptradd(catch_data, bx.const_usize(ptr_size.bytes()));
1725-
bx.store(is_rust_panic, catch_data_1, i8_align);
1726-
1727-
let catch_ty = bx.type_func(&[bx.type_ptr(), bx.type_ptr()], bx.type_void());
1728-
bx.call(catch_ty, None, None, catch_func, &[data, catch_data], None, None);
1729-
bx.ret(bx.const_bool(true));
1730-
});
1731-
1732-
// Note that no invoke is used here because by definition this function
1733-
// can't panic (that's what it's catching).
1734-
let ret = bx.call(llty, None, None, llfn, &[try_func, data, catch_func], None, None);
1735-
ret
1736-
}
1737-
17381655
// Helper function to give a Block to a closure to codegen a shim function.
17391656
// This is currently primarily used for the `try` intrinsic functions above.
17401657
fn gen_fn<'a, 'll, 'tcx>(

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,6 @@ unsafe fn configure_llvm(sess: &Session) {
109109
add("-wasm-enable-eh", false);
110110
}
111111

112-
if sess.target.os == Os::Emscripten
113-
&& !sess.opts.unstable_opts.emscripten_wasm_eh
114-
&& sess.panic_strategy().unwinds()
115-
{
116-
add("-enable-emscripten-cxx-exceptions", false);
117-
}
118-
119112
// HACK(eddyb) LLVM inserts `llvm.assume` calls to preserve align attributes
120113
// during inlining. Unfortunately these may block other optimizations.
121114
add("-preserve-alignment-assumptions-during-inlining=false", false);

compiler/rustc_codegen_llvm/src/mono_item.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,10 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
169169
) {
170170
for (alias, linkage, visibility) in aliases {
171171
let symbol_name = self.tcx.symbol_name(Instance::mono(self.tcx, *alias));
172-
tracing::debug!("FUNCTION ALIAS: {alias:?} {linkage:?} {visibility:?}");
172+
tracing::debug!(
173+
"FUNCTION ALIAS: generating fn {} that calls {aliasee_instance:?} ({alias:?} {linkage:?} {visibility:?})",
174+
symbol_name.name
175+
);
173176

174177
// predefine another copy of the original instance
175178
// with a new symbol name

compiler/rustc_codegen_llvm/src/type_.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,6 @@ impl<'ll, CX: Borrow<SCx<'ll>>> GenericCx<'ll, CX> {
106106
}
107107
}
108108
impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
109-
pub(crate) fn type_bool(&self) -> &'ll Type {
110-
self.type_i8()
111-
}
112-
113109
pub(crate) fn type_int_from_ty(&self, t: ty::IntTy) -> &'ll Type {
114110
match t {
115111
ty::IntTy::Isize => self.type_isize(),

0 commit comments

Comments
 (0)