Skip to content

Commit 25a54d4

Browse files
committed
Auto merge of #155077 - jhpratt:rollup-6HqPjEt, r=jhpratt
Rollup of 10 pull requests Successful merges: - #154973 (Break a single query cycle in the deadlock handler) - #155034 (Implement `GenericTypeVisitable` for some types) - #151377 (Fix linker error by resolving regions for main return type obligations) - #154677 (hwaddress: automatically add `-Ctarget-feature=+tagged-globals`) - #154774 (Add myself as co-maintainer for hexagon-unknown-linux-musl) - #155015 (Add tests for three fixed issues (an LLVM crash, an ICE and poor codegen)) - #155039 (minor follow up to removing soft mode `#[unstable]`) - #155043 (Fix if branch in op.rs) - #155071 (Deny `#[global_allocator]` + `#[thread_local]`) - #155072 (Set the Fuchsia ABI to the documented minimum)
2 parents 7659cec + 4f606c8 commit 25a54d4

File tree

28 files changed

+268
-198
lines changed

28 files changed

+268
-198
lines changed

compiler/rustc_builtin_macros/src/errors.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,16 @@ pub(crate) struct AllocMustStatics {
158158
pub(crate) span: Span,
159159
}
160160

161+
#[derive(Diagnostic)]
162+
#[diag("allocators cannot be `#[thread_local]`")]
163+
pub(crate) struct AllocCannotThreadLocal {
164+
#[primary_span]
165+
pub(crate) span: Span,
166+
#[label("marked `#[thread_local]` here")]
167+
#[suggestion("remove this attribute", code = "", applicability = "maybe-incorrect")]
168+
pub(crate) attr: Span,
169+
}
170+
161171
pub(crate) use autodiff::*;
162172

163173
mod autodiff {

compiler/rustc_builtin_macros/src/global_allocator.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ pub(crate) fn expand(
3838
return vec![orig_item];
3939
};
4040

41+
// Forbid `#[thread_local]` attributes on the item
42+
if let Some(attr) = item.attrs.iter().find(|x| x.has_name(sym::thread_local)) {
43+
ecx.dcx().emit_err(errors::AllocCannotThreadLocal { span: item.span, attr: attr.span });
44+
return vec![orig_item];
45+
}
46+
4147
// Generate a bunch of new items using the AllocFnFactory
4248
let span = ecx.with_def_site_ctxt(item.span);
4349
let f = AllocFnFactory { span, ty_span, global: ident, cx: ecx };

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,7 @@ fn llvm_features_by_flags(sess: &Session, features: &mut Vec<String>) {
630630
}
631631

632632
target_features::retpoline_features_by_flags(sess, features);
633+
target_features::sanitizer_features_by_flags(sess, features);
633634

634635
// -Zfixed-x18
635636
if sess.opts.unstable_opts.fixed_x18 {

compiler/rustc_codegen_ssa/src/target_features.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_session::Session;
1010
use rustc_session::lint::builtin::AARCH64_SOFTFLOAT_NEON;
1111
use rustc_session::parse::feature_err;
1212
use rustc_span::{Span, Symbol, edit_distance, sym};
13-
use rustc_target::spec::Arch;
13+
use rustc_target::spec::{Arch, SanitizerSet};
1414
use rustc_target::target_features::{RUSTC_SPECIFIC_FEATURES, Stability};
1515
use smallvec::SmallVec;
1616

@@ -460,6 +460,15 @@ pub fn retpoline_features_by_flags(sess: &Session, features: &mut Vec<String>) {
460460
}
461461
}
462462

463+
/// Computes the backend target features to be added to account for sanitizer flags.
464+
pub fn sanitizer_features_by_flags(sess: &Session, features: &mut Vec<String>) {
465+
// It's intentional that this is done only for non-kernel version of hwaddress. This matches
466+
// clang behavior.
467+
if sess.sanitizers().contains(SanitizerSet::HWADDRESS) {
468+
features.push("+tagged-globals".into());
469+
}
470+
}
471+
463472
pub(crate) fn provide(providers: &mut Providers) {
464473
*providers = Providers {
465474
rust_target_features: |tcx, cnum| {

compiler/rustc_hir_analysis/src/check/entry.rs

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,23 @@ use rustc_infer::infer::TyCtxtInferExt;
77
use rustc_middle::span_bug;
88
use rustc_middle::ty::{self, TyCtxt, TypingMode};
99
use rustc_session::config::EntryFnType;
10-
use rustc_span::Span;
1110
use rustc_span::def_id::{CRATE_DEF_ID, DefId, LocalDefId};
11+
use rustc_span::{ErrorGuaranteed, Span};
1212
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
13+
use rustc_trait_selection::regions::InferCtxtRegionExt;
1314
use rustc_trait_selection::traits::{self, ObligationCause, ObligationCauseCode};
1415

1516
use super::check_function_signature;
1617
use crate::errors;
1718

18-
pub(crate) fn check_for_entry_fn(tcx: TyCtxt<'_>) {
19+
pub(crate) fn check_for_entry_fn(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
1920
match tcx.entry_fn(()) {
2021
Some((def_id, EntryFnType::Main { .. })) => check_main_fn_ty(tcx, def_id),
21-
_ => {}
22+
_ => Ok(()),
2223
}
2324
}
2425

25-
fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
26+
fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) -> Result<(), ErrorGuaranteed> {
2627
let main_fnsig = tcx.fn_sig(main_def_id).instantiate_identity();
2728
let main_span = tcx.def_span(main_def_id);
2829

@@ -87,33 +88,28 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
8788
}
8889
}
8990

90-
let mut error = false;
9191
let main_diagnostics_def_id = main_fn_diagnostics_def_id(tcx, main_def_id, main_span);
9292

9393
let main_asyncness = tcx.asyncness(main_def_id);
9494
if main_asyncness.is_async() {
9595
let asyncness_span = main_fn_asyncness_span(tcx, main_def_id);
96-
tcx.dcx()
97-
.emit_err(errors::MainFunctionAsync { span: main_span, asyncness: asyncness_span });
98-
error = true;
96+
return Err(tcx
97+
.dcx()
98+
.emit_err(errors::MainFunctionAsync { span: main_span, asyncness: asyncness_span }));
9999
}
100100

101101
if let Some(attr_span) = find_attr!(tcx, main_def_id, TrackCaller(span) => *span) {
102-
tcx.dcx().emit_err(errors::TrackCallerOnMain { span: attr_span, annotated: main_span });
103-
error = true;
102+
return Err(tcx
103+
.dcx()
104+
.emit_err(errors::TrackCallerOnMain { span: attr_span, annotated: main_span }));
104105
}
105106

106107
if !tcx.codegen_fn_attrs(main_def_id).target_features.is_empty()
107108
// Calling functions with `#[target_feature]` is not unsafe on WASM, see #84988
108109
&& !tcx.sess.target.is_like_wasm
109110
&& !tcx.sess.opts.actually_rustdoc
110111
{
111-
tcx.dcx().emit_err(errors::TargetFeatureOnMain { main: main_span });
112-
error = true;
113-
}
114-
115-
if error {
116-
return;
112+
return Err(tcx.dcx().emit_err(errors::TargetFeatureOnMain { main: main_span }));
117113
}
118114

119115
// Main should have no WC, so empty param env is OK here.
@@ -123,8 +119,9 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
123119
let return_ty = main_fnsig.output();
124120
let return_ty_span = main_fn_return_type_span(tcx, main_def_id).unwrap_or(main_span);
125121
let Some(return_ty) = return_ty.no_bound_vars() else {
126-
tcx.dcx().emit_err(errors::MainFunctionReturnTypeGeneric { span: return_ty_span });
127-
return;
122+
return Err(tcx
123+
.dcx()
124+
.emit_err(errors::MainFunctionReturnTypeGeneric { span: return_ty_span }));
128125
};
129126
let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
130127
let cause = traits::ObligationCause::new(
@@ -137,8 +134,16 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
137134
ocx.register_bound(cause, param_env, norm_return_ty, term_did);
138135
let errors = ocx.evaluate_obligations_error_on_ambiguity();
139136
if !errors.is_empty() {
140-
infcx.err_ctxt().report_fulfillment_errors(errors);
141-
error = true;
137+
return Err(infcx.err_ctxt().report_fulfillment_errors(errors));
138+
}
139+
140+
let region_errors =
141+
infcx.resolve_regions(main_diagnostics_def_id, param_env, ty::List::empty());
142+
143+
if !region_errors.is_empty() {
144+
return Err(infcx
145+
.err_ctxt()
146+
.report_region_errors(main_diagnostics_def_id, &region_errors));
142147
}
143148
// now we can take the return type of the given main function
144149
expected_return_type = norm_return_ty;
@@ -147,10 +152,6 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
147152
expected_return_type = tcx.types.unit;
148153
}
149154

150-
if error {
151-
return;
152-
}
153-
154155
let expected_sig = ty::Binder::dummy(tcx.mk_fn_sig(
155156
[],
156157
expected_return_type,
@@ -159,7 +160,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
159160
ExternAbi::Rust,
160161
));
161162

162-
if check_function_signature(
163+
check_function_signature(
163164
tcx,
164165
ObligationCause::new(
165166
main_span,
@@ -168,26 +169,24 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
168169
),
169170
main_def_id,
170171
expected_sig,
171-
)
172-
.is_err()
173-
{
174-
return;
175-
}
172+
)?;
176173

177174
let main_fn_generics = tcx.generics_of(main_def_id);
178175
let main_fn_predicates = tcx.predicates_of(main_def_id);
179176
if main_fn_generics.count() != 0 || !main_fnsig.bound_vars().is_empty() {
180177
let generics_param_span = main_fn_generics_params_span(tcx, main_def_id);
181-
tcx.dcx().emit_err(errors::MainFunctionGenericParameters {
178+
return Err(tcx.dcx().emit_err(errors::MainFunctionGenericParameters {
182179
span: generics_param_span.unwrap_or(main_span),
183180
label_span: generics_param_span,
184-
});
181+
}));
185182
} else if !main_fn_predicates.predicates.is_empty() {
186183
// generics may bring in implicit predicates, so we skip this check if generics is present.
187184
let generics_where_clauses_span = main_fn_where_clauses_span(tcx, main_def_id);
188-
tcx.dcx().emit_err(errors::WhereClauseOnMain {
185+
return Err(tcx.dcx().emit_err(errors::WhereClauseOnMain {
189186
span: generics_where_clauses_span.unwrap_or(main_span),
190187
generics_span: generics_where_clauses_span,
191-
});
188+
}));
192189
}
190+
191+
Ok(())
193192
}

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2372,7 +2372,8 @@ pub(super) fn check_type_wf(tcx: TyCtxt<'_>, (): ()) -> Result<(), ErrorGuarante
23722372
}))
23732373
.and(items.par_nested_bodies(|item| tcx.ensure_result().check_well_formed(item)))
23742374
.and(items.par_opaques(|item| tcx.ensure_result().check_well_formed(item)));
2375-
super::entry::check_for_entry_fn(tcx);
2375+
2376+
super::entry::check_for_entry_fn(tcx)?;
23762377

23772378
res
23782379
}

compiler/rustc_hir_typeck/src/op.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -294,24 +294,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
294294
self.apply_adjustments(lhs_expr, vec![autoref]);
295295
}
296296

297-
if let ty::Ref(_, _, mutbl) = method.sig.inputs()[1].kind() {
298-
// Allow two-phase borrows for binops in initial deployment
299-
// since they desugar to methods
300-
let mutbl = AutoBorrowMutability::new(*mutbl, AllowTwoPhase::Yes);
301-
let autoref = Adjustment {
302-
kind: Adjust::Borrow(AutoBorrow::Ref(mutbl)),
303-
target: method.sig.inputs()[1],
304-
};
305-
// HACK(eddyb) Bypass checks due to reborrows being in
306-
// some cases applied on the RHS, on top of which we need
307-
// to autoref, which is not allowed by apply_adjustments.
308-
// self.apply_adjustments(rhs_expr, vec![autoref]);
309-
self.typeck_results
310-
.borrow_mut()
311-
.adjustments_mut()
312-
.entry(rhs_expr.hir_id)
313-
.or_default()
314-
.push(autoref);
297+
if by_ref_binop {
298+
if let ty::Ref(_, _, mutbl) = method.sig.inputs()[1].kind() {
299+
// Allow two-phase borrows for binops in initial deployment
300+
// since they desugar to methods
301+
let mutbl = AutoBorrowMutability::new(*mutbl, AllowTwoPhase::Yes);
302+
let autoref = Adjustment {
303+
kind: Adjust::Borrow(AutoBorrow::Ref(mutbl)),
304+
target: method.sig.inputs()[1],
305+
};
306+
// HACK(eddyb) Bypass checks due to reborrows being in
307+
// some cases applied on the RHS, on top of which we need
308+
// to autoref, which is not allowed by apply_adjustments.
309+
// self.apply_adjustments(rhs_expr, vec![autoref]);
310+
self.typeck_results
311+
.borrow_mut()
312+
.adjustments_mut()
313+
.entry(rhs_expr.hir_id)
314+
.or_default()
315+
.push(autoref);
316+
}
315317
}
316318
}
317319

compiler/rustc_interface/src/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ pub(crate) fn run_in_thread_pool_with_globals<
184184

185185
use rustc_data_structures::defer;
186186
use rustc_middle::ty::tls;
187-
use rustc_query_impl::break_query_cycles;
187+
use rustc_query_impl::break_query_cycle;
188188

189189
let thread_stack_size = init_stack_size(thread_builder_diag);
190190

@@ -260,7 +260,7 @@ internal compiler error: query cycle handler thread panicked, aborting process";
260260
)
261261
},
262262
);
263-
break_query_cycles(job_map, &registry);
263+
break_query_cycle(job_map, &registry);
264264
})
265265
})
266266
});

0 commit comments

Comments
 (0)