Skip to content

Commit f25d8a6

Browse files
committed
Merge from rustc
2 parents 30e4359 + 23a34c1 commit f25d8a6

File tree

429 files changed

+7531
-3556
lines changed

Some content is hidden

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

429 files changed

+7531
-3556
lines changed

Cargo.lock

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4168,6 +4168,7 @@ dependencies = [
41684168
name = "rustc_parse_format"
41694169
version = "0.0.0"
41704170
dependencies = [
4171+
"rustc_data_structures",
41714172
"rustc_lexer",
41724173
]
41734174

@@ -4342,6 +4343,7 @@ dependencies = [
43424343
"rustc_feature",
43434344
"rustc_fs_util",
43444345
"rustc_hir",
4346+
"rustc_index",
43454347
"rustc_lint_defs",
43464348
"rustc_macros",
43474349
"rustc_serialize",
@@ -4402,6 +4404,7 @@ dependencies = [
44024404
"rustc_span",
44034405
"rustc_target",
44044406
"tracing",
4407+
"twox-hash",
44054408
]
44064409

44074410
[[package]]
@@ -5392,6 +5395,17 @@ dependencies = [
53925395
"tracing-subscriber",
53935396
]
53945397

5398+
[[package]]
5399+
name = "twox-hash"
5400+
version = "1.6.3"
5401+
source = "registry+https://github.com/rust-lang/crates.io-index"
5402+
checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675"
5403+
dependencies = [
5404+
"cfg-if 1.0.0",
5405+
"rand 0.8.5",
5406+
"static_assertions",
5407+
]
5408+
53955409
[[package]]
53965410
name = "type-map"
53975411
version = "0.4.0"

compiler/rustc_borrowck/src/invalidation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
106106
self.check_activations(location);
107107

108108
match &terminator.kind {
109-
TerminatorKind::SwitchInt { discr, switch_ty: _, targets: _ } => {
109+
TerminatorKind::SwitchInt { discr, targets: _ } => {
110110
self.consume_operand(location, discr);
111111
}
112112
TerminatorKind::Drop { place: drop_place, target: _, unwind: _ } => {

compiler/rustc_borrowck/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtx
644644
self.check_activations(loc, span, flow_state);
645645

646646
match &term.kind {
647-
TerminatorKind::SwitchInt { discr, switch_ty: _, targets: _ } => {
647+
TerminatorKind::SwitchInt { discr, targets: _ } => {
648648
self.consume_operand(loc, (discr, span), flow_state);
649649
}
650650
TerminatorKind::Drop { place, target: _, unwind: _ } => {

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,25 +1360,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
13601360
);
13611361
}
13621362
}
1363-
TerminatorKind::SwitchInt { discr, switch_ty, .. } => {
1363+
TerminatorKind::SwitchInt { discr, .. } => {
13641364
self.check_operand(discr, term_location);
13651365

1366-
let discr_ty = discr.ty(body, tcx);
1367-
if let Err(terr) = self.sub_types(
1368-
discr_ty,
1369-
*switch_ty,
1370-
term_location.to_locations(),
1371-
ConstraintCategory::Assignment,
1372-
) {
1373-
span_mirbug!(
1374-
self,
1375-
term,
1376-
"bad SwitchInt ({:?} on {:?}): {:?}",
1377-
switch_ty,
1378-
discr_ty,
1379-
terr
1380-
);
1381-
}
1366+
let switch_ty = discr.ty(body, tcx);
13821367
if !switch_ty.is_integral() && !switch_ty.is_char() && !switch_ty.is_bool() {
13831368
span_mirbug!(self, term, "bad SwitchInt discr ty {:?}", switch_ty);
13841369
}

compiler/rustc_builtin_macros/src/concat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub fn expand_concat(
1111
sp: rustc_span::Span,
1212
tts: TokenStream,
1313
) -> Box<dyn base::MacResult + 'static> {
14-
let Some(es) = base::get_exprs_from_tts(cx, sp, tts) else {
14+
let Some(es) = base::get_exprs_from_tts(cx, tts) else {
1515
return DummyResult::any(sp);
1616
};
1717
let mut accumulator = String::new();

compiler/rustc_builtin_macros/src/concat_bytes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ pub fn expand_concat_bytes(
137137
sp: rustc_span::Span,
138138
tts: TokenStream,
139139
) -> Box<dyn base::MacResult + 'static> {
140-
let Some(es) = base::get_exprs_from_tts(cx, sp, tts) else {
140+
let Some(es) = base::get_exprs_from_tts(cx, tts) else {
141141
return DummyResult::any(sp);
142142
};
143143
let mut accumulator = Vec::new();

compiler/rustc_builtin_macros/src/env.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub fn expand_env<'cx>(
5252
sp: Span,
5353
tts: TokenStream,
5454
) -> Box<dyn base::MacResult + 'cx> {
55-
let mut exprs = match get_exprs_from_tts(cx, sp, tts) {
55+
let mut exprs = match get_exprs_from_tts(cx, tts) {
5656
Some(exprs) if exprs.is_empty() => {
5757
cx.span_err(sp, "env! takes 1 or 2 arguments");
5858
return DummyResult::any(sp);

compiler/rustc_builtin_macros/src/format.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ pub fn make_format_args(
333333
parse::Piece::String(s) => {
334334
unfinished_literal.push_str(s);
335335
}
336-
parse::Piece::NextArgument(parse::Argument { position, position_span, format }) => {
336+
parse::Piece::NextArgument(box parse::Argument { position, position_span, format }) => {
337337
if !unfinished_literal.is_empty() {
338338
template.push(FormatArgsPiece::Literal(Symbol::intern(&unfinished_literal)));
339339
unfinished_literal.clear();

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,10 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
372372
}
373373
}
374374

375-
TerminatorKind::SwitchInt { discr, switch_ty, targets } => {
376-
let discr = codegen_operand(fx, discr).load_scalar(fx);
375+
TerminatorKind::SwitchInt { discr, targets } => {
376+
let discr = codegen_operand(fx, discr);
377+
let switch_ty = discr.layout().ty;
378+
let discr = discr.load_scalar(fx);
377379

378380
let use_bool_opt = switch_ty.kind() == fx.tcx.types.bool.kind()
379381
|| (targets.iter().count() == 1 && targets.iter().next().unwrap().0 == 0);

compiler/rustc_codegen_gcc/src/type_.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,4 +300,8 @@ impl<'gcc, 'tcx> TypeMembershipMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
300300
// Unsupported.
301301
self.context.new_rvalue_from_int(self.int_type, 0)
302302
}
303+
304+
fn set_kcfi_type_metadata(&self, _function: RValue<'gcc>, _kcfi_typeid: u32) {
305+
// Unsupported.
306+
}
303307
}

compiler/rustc_codegen_llvm/src/allocator.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ pub(crate) unsafe fn codegen(
8888
callee,
8989
args.as_ptr(),
9090
args.len() as c_uint,
91-
None,
91+
[].as_ptr(),
92+
0 as c_uint,
9293
);
9394
llvm::LLVMSetTailCall(ret, True);
9495
if output.is_some() {
@@ -132,8 +133,15 @@ pub(crate) unsafe fn codegen(
132133
.enumerate()
133134
.map(|(i, _)| llvm::LLVMGetParam(llfn, i as c_uint))
134135
.collect::<Vec<_>>();
135-
let ret =
136-
llvm::LLVMRustBuildCall(llbuilder, ty, callee, args.as_ptr(), args.len() as c_uint, None);
136+
let ret = llvm::LLVMRustBuildCall(
137+
llbuilder,
138+
ty,
139+
callee,
140+
args.as_ptr(),
141+
args.len() as c_uint,
142+
[].as_ptr(),
143+
0 as c_uint,
144+
);
137145
llvm::LLVMSetTailCall(ret, True);
138146
llvm::LLVMBuildRetVoid(llbuilder);
139147
llvm::LLVMDisposeBuilder(llbuilder);

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use rustc_middle::ty::layout::{
2020
};
2121
use rustc_middle::ty::{self, Ty, TyCtxt};
2222
use rustc_span::Span;
23+
use rustc_symbol_mangling::typeid::kcfi_typeid_for_fnabi;
2324
use rustc_target::abi::{self, call::FnAbi, Align, Size, WrappingRange};
2425
use rustc_target::spec::{HasTargetSpec, Target};
2526
use std::borrow::Cow;
@@ -225,9 +226,25 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
225226
debug!("invoke {:?} with args ({:?})", llfn, args);
226227

227228
let args = self.check_call("invoke", llty, llfn, args);
228-
let bundle = funclet.map(|funclet| funclet.bundle());
229-
let bundle = bundle.as_ref().map(|b| &*b.raw);
229+
let funclet_bundle = funclet.map(|funclet| funclet.bundle());
230+
let funclet_bundle = funclet_bundle.as_ref().map(|b| &*b.raw);
231+
let mut bundles = vec![funclet_bundle];
232+
233+
// Set KCFI operand bundle
234+
let is_indirect_call = unsafe { llvm::LLVMIsAFunction(llfn).is_none() };
235+
let kcfi_bundle =
236+
if self.tcx.sess.is_sanitizer_kcfi_enabled() && fn_abi.is_some() && is_indirect_call {
237+
let kcfi_typeid = kcfi_typeid_for_fnabi(self.tcx, fn_abi.unwrap());
238+
Some(llvm::OperandBundleDef::new("kcfi", &[self.const_u32(kcfi_typeid)]))
239+
} else {
240+
None
241+
};
242+
if kcfi_bundle.is_some() {
243+
let kcfi_bundle = kcfi_bundle.as_ref().map(|b| &*b.raw);
244+
bundles.push(kcfi_bundle);
245+
}
230246

247+
bundles.retain(|bundle| bundle.is_some());
231248
let invoke = unsafe {
232249
llvm::LLVMRustBuildInvoke(
233250
self.llbuilder,
@@ -237,7 +254,8 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
237254
args.len() as c_uint,
238255
then,
239256
catch,
240-
bundle,
257+
bundles.as_ptr(),
258+
bundles.len() as c_uint,
241259
UNNAMED,
242260
)
243261
};
@@ -1143,7 +1161,8 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
11431161
llfn,
11441162
args.as_ptr() as *const &llvm::Value,
11451163
args.len() as c_uint,
1146-
None,
1164+
[].as_ptr(),
1165+
0 as c_uint,
11471166
);
11481167
}
11491168
}
@@ -1159,17 +1178,34 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
11591178
debug!("call {:?} with args ({:?})", llfn, args);
11601179

11611180
let args = self.check_call("call", llty, llfn, args);
1162-
let bundle = funclet.map(|funclet| funclet.bundle());
1163-
let bundle = bundle.as_ref().map(|b| &*b.raw);
1181+
let funclet_bundle = funclet.map(|funclet| funclet.bundle());
1182+
let funclet_bundle = funclet_bundle.as_ref().map(|b| &*b.raw);
1183+
let mut bundles = vec![funclet_bundle];
1184+
1185+
// Set KCFI operand bundle
1186+
let is_indirect_call = unsafe { llvm::LLVMIsAFunction(llfn).is_none() };
1187+
let kcfi_bundle =
1188+
if self.tcx.sess.is_sanitizer_kcfi_enabled() && fn_abi.is_some() && is_indirect_call {
1189+
let kcfi_typeid = kcfi_typeid_for_fnabi(self.tcx, fn_abi.unwrap());
1190+
Some(llvm::OperandBundleDef::new("kcfi", &[self.const_u32(kcfi_typeid)]))
1191+
} else {
1192+
None
1193+
};
1194+
if kcfi_bundle.is_some() {
1195+
let kcfi_bundle = kcfi_bundle.as_ref().map(|b| &*b.raw);
1196+
bundles.push(kcfi_bundle);
1197+
}
11641198

1199+
bundles.retain(|bundle| bundle.is_some());
11651200
let call = unsafe {
11661201
llvm::LLVMRustBuildCall(
11671202
self.llbuilder,
11681203
llty,
11691204
llfn,
11701205
args.as_ptr() as *const &llvm::Value,
11711206
args.len() as c_uint,
1172-
bundle,
1207+
bundles.as_ptr(),
1208+
bundles.len() as c_uint,
11731209
)
11741210
};
11751211
if let Some(fn_abi) = fn_abi {

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,11 @@ pub unsafe fn create_module<'ll>(
250250
);
251251
}
252252

253+
if sess.is_sanitizer_kcfi_enabled() {
254+
let kcfi = "kcfi\0".as_ptr().cast();
255+
llvm::LLVMRustAddModuleFlag(llmod, llvm::LLVMModFlagBehavior::Override, kcfi, 1);
256+
}
257+
253258
// Control Flow Guard is currently only supported by the MSVC linker on Windows.
254259
if sess.target.is_like_msvc {
255260
match sess.opts.cg.control_flow_guard {

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ use rustc_codegen_ssa::traits::*;
2727
use rustc_fs_util::path_to_c_string;
2828
use rustc_hir::def::CtorKind;
2929
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
30-
use rustc_index::vec::{Idx, IndexVec};
3130
use rustc_middle::bug;
32-
use rustc_middle::mir::{self, GeneratorLayout};
3331
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
3432
use rustc_middle::ty::subst::GenericArgKind;
3533
use rustc_middle::ty::{
@@ -1026,33 +1024,6 @@ fn build_struct_type_di_node<'ll, 'tcx>(
10261024
// Tuples
10271025
//=-----------------------------------------------------------------------------
10281026

1029-
/// Returns names of captured upvars for closures and generators.
1030-
///
1031-
/// Here are some examples:
1032-
/// - `name__field1__field2` when the upvar is captured by value.
1033-
/// - `_ref__name__field` when the upvar is captured by reference.
1034-
///
1035-
/// For generators this only contains upvars that are shared by all states.
1036-
fn closure_saved_names_of_captured_variables(tcx: TyCtxt<'_>, def_id: DefId) -> SmallVec<String> {
1037-
let body = tcx.optimized_mir(def_id);
1038-
1039-
body.var_debug_info
1040-
.iter()
1041-
.filter_map(|var| {
1042-
let is_ref = match var.value {
1043-
mir::VarDebugInfoContents::Place(place) if place.local == mir::Local::new(1) => {
1044-
// The projection is either `[.., Field, Deref]` or `[.., Field]`. It
1045-
// implies whether the variable is captured by value or by reference.
1046-
matches!(place.projection.last().unwrap(), mir::ProjectionElem::Deref)
1047-
}
1048-
_ => return None,
1049-
};
1050-
let prefix = if is_ref { "_ref__" } else { "" };
1051-
Some(prefix.to_owned() + var.name.as_str())
1052-
})
1053-
.collect()
1054-
}
1055-
10561027
/// Builds the DW_TAG_member debuginfo nodes for the upvars of a closure or generator.
10571028
/// For a generator, this will handle upvars shared by all states.
10581029
fn build_upvar_field_di_nodes<'ll, 'tcx>(
@@ -1083,7 +1054,7 @@ fn build_upvar_field_di_nodes<'ll, 'tcx>(
10831054
.all(|&t| t == cx.tcx.normalize_erasing_regions(ParamEnv::reveal_all(), t))
10841055
);
10851056

1086-
let capture_names = closure_saved_names_of_captured_variables(cx.tcx, def_id);
1057+
let capture_names = cx.tcx.closure_saved_names_of_captured_variables(def_id);
10871058
let layout = cx.layout_of(closure_or_generator_ty);
10881059

10891060
up_var_tys
@@ -1229,43 +1200,6 @@ fn build_union_type_di_node<'ll, 'tcx>(
12291200
)
12301201
}
12311202

1232-
// FIXME(eddyb) maybe precompute this? Right now it's computed once
1233-
// per generator monomorphization, but it doesn't depend on substs.
1234-
fn generator_layout_and_saved_local_names<'tcx>(
1235-
tcx: TyCtxt<'tcx>,
1236-
def_id: DefId,
1237-
) -> (&'tcx GeneratorLayout<'tcx>, IndexVec<mir::GeneratorSavedLocal, Option<Symbol>>) {
1238-
let body = tcx.optimized_mir(def_id);
1239-
let generator_layout = body.generator_layout().unwrap();
1240-
let mut generator_saved_local_names = IndexVec::from_elem(None, &generator_layout.field_tys);
1241-
1242-
let state_arg = mir::Local::new(1);
1243-
for var in &body.var_debug_info {
1244-
let mir::VarDebugInfoContents::Place(place) = &var.value else { continue };
1245-
if place.local != state_arg {
1246-
continue;
1247-
}
1248-
match place.projection[..] {
1249-
[
1250-
// Deref of the `Pin<&mut Self>` state argument.
1251-
mir::ProjectionElem::Field(..),
1252-
mir::ProjectionElem::Deref,
1253-
// Field of a variant of the state.
1254-
mir::ProjectionElem::Downcast(_, variant),
1255-
mir::ProjectionElem::Field(field, _),
1256-
] => {
1257-
let name = &mut generator_saved_local_names
1258-
[generator_layout.variant_fields[variant][field]];
1259-
if name.is_none() {
1260-
name.replace(var.name);
1261-
}
1262-
}
1263-
_ => {}
1264-
}
1265-
}
1266-
(generator_layout, generator_saved_local_names)
1267-
}
1268-
12691203
/// Computes the type parameters for a type, if any, for the given metadata.
12701204
fn build_generic_type_param_di_nodes<'ll, 'tcx>(
12711205
cx: &CodegenCx<'ll, 'tcx>,

0 commit comments

Comments
 (0)