Skip to content

Commit aafc48b

Browse files
authored
Unrolled build for rust-lang#115654
Rollup merge of rust-lang#115654 - RalfJung:pass-mode-cast, r=compiler-errors improve PassMode docs
2 parents 8ed1d4a + 3ee65c2 commit aafc48b

File tree

12 files changed

+118
-96
lines changed

12 files changed

+118
-96
lines changed

compiler/rustc_codegen_cranelift/src/abi/pass_mode.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
100100
}
101101
_ => unreachable!("{:?}", self.layout.abi),
102102
},
103-
PassMode::Cast(ref cast, pad_i32) => {
103+
PassMode::Cast { ref cast, pad_i32 } => {
104104
assert!(!pad_i32, "padding support not yet implemented");
105105
cast_target_to_abi_params(cast)
106106
}
107-
PassMode::Indirect { attrs, extra_attrs: None, on_stack } => {
107+
PassMode::Indirect { attrs, meta_attrs: None, on_stack } => {
108108
if on_stack {
109109
// Abi requires aligning struct size to pointer size
110110
let size = self.layout.size.align_to(tcx.data_layout.pointer_align.abi);
@@ -117,11 +117,11 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
117117
smallvec![apply_arg_attrs_to_abi_param(AbiParam::new(pointer_ty(tcx)), attrs)]
118118
}
119119
}
120-
PassMode::Indirect { attrs, extra_attrs: Some(extra_attrs), on_stack } => {
120+
PassMode::Indirect { attrs, meta_attrs: Some(meta_attrs), on_stack } => {
121121
assert!(!on_stack);
122122
smallvec![
123123
apply_arg_attrs_to_abi_param(AbiParam::new(pointer_ty(tcx)), attrs),
124-
apply_arg_attrs_to_abi_param(AbiParam::new(pointer_ty(tcx)), extra_attrs),
124+
apply_arg_attrs_to_abi_param(AbiParam::new(pointer_ty(tcx)), meta_attrs),
125125
]
126126
}
127127
}
@@ -148,14 +148,14 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
148148
}
149149
_ => unreachable!("{:?}", self.layout.abi),
150150
},
151-
PassMode::Cast(ref cast, _) => {
151+
PassMode::Cast { ref cast, .. } => {
152152
(None, cast_target_to_abi_params(cast).into_iter().collect())
153153
}
154-
PassMode::Indirect { attrs: _, extra_attrs: None, on_stack } => {
154+
PassMode::Indirect { attrs: _, meta_attrs: None, on_stack } => {
155155
assert!(!on_stack);
156156
(Some(AbiParam::special(pointer_ty(tcx), ArgumentPurpose::StructReturn)), vec![])
157157
}
158-
PassMode::Indirect { attrs: _, extra_attrs: Some(_), on_stack: _ } => {
158+
PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => {
159159
unreachable!("unsized return value")
160160
}
161161
}
@@ -229,7 +229,7 @@ pub(super) fn adjust_arg_for_abi<'tcx>(
229229
let (a, b) = arg.load_scalar_pair(fx);
230230
smallvec![a, b]
231231
}
232-
PassMode::Cast(ref cast, _) => to_casted_value(fx, arg, cast),
232+
PassMode::Cast { ref cast, .. } => to_casted_value(fx, arg, cast),
233233
PassMode::Indirect { .. } => {
234234
if is_owned {
235235
match arg.force_stack(fx) {
@@ -287,14 +287,14 @@ pub(super) fn cvalue_for_param<'tcx>(
287287
assert_eq!(block_params.len(), 2, "{:?}", block_params);
288288
Some(CValue::by_val_pair(block_params[0], block_params[1], arg_abi.layout))
289289
}
290-
PassMode::Cast(ref cast, _) => {
290+
PassMode::Cast { ref cast, .. } => {
291291
Some(from_casted_value(fx, &block_params, arg_abi.layout, cast))
292292
}
293-
PassMode::Indirect { attrs: _, extra_attrs: None, on_stack: _ } => {
293+
PassMode::Indirect { attrs: _, meta_attrs: None, on_stack: _ } => {
294294
assert_eq!(block_params.len(), 1, "{:?}", block_params);
295295
Some(CValue::by_ref(Pointer::new(block_params[0]), arg_abi.layout))
296296
}
297-
PassMode::Indirect { attrs: _, extra_attrs: Some(_), on_stack: _ } => {
297+
PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => {
298298
assert_eq!(block_params.len(), 2, "{:?}", block_params);
299299
Some(CValue::by_ref_unsized(
300300
Pointer::new(block_params[0]),

compiler/rustc_codegen_cranelift/src/abi/returning.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub(super) fn codegen_return_param<'tcx>(
1313
block_params_iter: &mut impl Iterator<Item = Value>,
1414
) -> CPlace<'tcx> {
1515
let (ret_place, ret_param): (_, SmallVec<[_; 2]>) = match fx.fn_abi.as_ref().unwrap().ret.mode {
16-
PassMode::Ignore | PassMode::Direct(_) | PassMode::Pair(_, _) | PassMode::Cast(..) => {
16+
PassMode::Ignore | PassMode::Direct(_) | PassMode::Pair(_, _) | PassMode::Cast { .. } => {
1717
let is_ssa =
1818
ssa_analyzed[RETURN_PLACE].is_ssa(fx, fx.fn_abi.as_ref().unwrap().ret.layout.ty);
1919
(
@@ -26,15 +26,15 @@ pub(super) fn codegen_return_param<'tcx>(
2626
smallvec![],
2727
)
2828
}
29-
PassMode::Indirect { attrs: _, extra_attrs: None, on_stack: _ } => {
29+
PassMode::Indirect { attrs: _, meta_attrs: None, on_stack: _ } => {
3030
let ret_param = block_params_iter.next().unwrap();
3131
assert_eq!(fx.bcx.func.dfg.value_type(ret_param), fx.pointer_type);
3232
(
3333
CPlace::for_ptr(Pointer::new(ret_param), fx.fn_abi.as_ref().unwrap().ret.layout),
3434
smallvec![ret_param],
3535
)
3636
}
37-
PassMode::Indirect { attrs: _, extra_attrs: Some(_), on_stack: _ } => {
37+
PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => {
3838
unreachable!("unsized return value")
3939
}
4040
};
@@ -62,7 +62,7 @@ pub(super) fn codegen_with_call_return_arg<'tcx>(
6262
) {
6363
let (ret_temp_place, return_ptr) = match ret_arg_abi.mode {
6464
PassMode::Ignore => (None, None),
65-
PassMode::Indirect { attrs: _, extra_attrs: None, on_stack: _ } => {
65+
PassMode::Indirect { attrs: _, meta_attrs: None, on_stack: _ } => {
6666
if let Some(ret_ptr) = ret_place.try_to_ptr() {
6767
// This is an optimization to prevent unnecessary copies of the return value when
6868
// the return place is already a memory place as opposed to a register.
@@ -73,10 +73,10 @@ pub(super) fn codegen_with_call_return_arg<'tcx>(
7373
(Some(place), Some(place.to_ptr().get_addr(fx)))
7474
}
7575
}
76-
PassMode::Indirect { attrs: _, extra_attrs: Some(_), on_stack: _ } => {
76+
PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => {
7777
unreachable!("unsized return value")
7878
}
79-
PassMode::Direct(_) | PassMode::Pair(_, _) | PassMode::Cast(..) => (None, None),
79+
PassMode::Direct(_) | PassMode::Pair(_, _) | PassMode::Cast { .. } => (None, None),
8080
};
8181

8282
let call_inst = f(fx, return_ptr);
@@ -93,21 +93,21 @@ pub(super) fn codegen_with_call_return_arg<'tcx>(
9393
ret_place
9494
.write_cvalue(fx, CValue::by_val_pair(ret_val_a, ret_val_b, ret_arg_abi.layout));
9595
}
96-
PassMode::Cast(ref cast, _) => {
96+
PassMode::Cast { ref cast, .. } => {
9797
let results =
9898
fx.bcx.inst_results(call_inst).iter().copied().collect::<SmallVec<[Value; 2]>>();
9999
let result =
100100
super::pass_mode::from_casted_value(fx, &results, ret_place.layout(), cast);
101101
ret_place.write_cvalue(fx, result);
102102
}
103-
PassMode::Indirect { attrs: _, extra_attrs: None, on_stack: _ } => {
103+
PassMode::Indirect { attrs: _, meta_attrs: None, on_stack: _ } => {
104104
if let Some(ret_temp_place) = ret_temp_place {
105105
// If ret_temp_place is None, it is not necessary to copy the return value.
106106
let ret_temp_value = ret_temp_place.to_cvalue(fx);
107107
ret_place.write_cvalue(fx, ret_temp_value);
108108
}
109109
}
110-
PassMode::Indirect { attrs: _, extra_attrs: Some(_), on_stack: _ } => {
110+
PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => {
111111
unreachable!("unsized return value")
112112
}
113113
}
@@ -116,10 +116,10 @@ pub(super) fn codegen_with_call_return_arg<'tcx>(
116116
/// Codegen a return instruction with the right return value(s) if any.
117117
pub(crate) fn codegen_return(fx: &mut FunctionCx<'_, '_, '_>) {
118118
match fx.fn_abi.as_ref().unwrap().ret.mode {
119-
PassMode::Ignore | PassMode::Indirect { attrs: _, extra_attrs: None, on_stack: _ } => {
119+
PassMode::Ignore | PassMode::Indirect { attrs: _, meta_attrs: None, on_stack: _ } => {
120120
fx.bcx.ins().return_(&[]);
121121
}
122-
PassMode::Indirect { attrs: _, extra_attrs: Some(_), on_stack: _ } => {
122+
PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => {
123123
unreachable!("unsized return value")
124124
}
125125
PassMode::Direct(_) => {
@@ -132,7 +132,7 @@ pub(crate) fn codegen_return(fx: &mut FunctionCx<'_, '_, '_>) {
132132
let (ret_val_a, ret_val_b) = place.to_cvalue(fx).load_scalar_pair(fx);
133133
fx.bcx.ins().return_(&[ret_val_a, ret_val_b]);
134134
}
135-
PassMode::Cast(ref cast, _) => {
135+
PassMode::Cast { ref cast, .. } => {
136136
let place = fx.get_local_place(RETURN_PLACE);
137137
let ret_val = place.to_cvalue(fx);
138138
let ret_vals = super::pass_mode::to_casted_value(fx, ret_val, cast);

compiler/rustc_codegen_gcc/src/abi.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
113113
match self.ret.mode {
114114
PassMode::Ignore => cx.type_void(),
115115
PassMode::Direct(_) | PassMode::Pair(..) => self.ret.layout.immediate_gcc_type(cx),
116-
PassMode::Cast(ref cast, _) => cast.gcc_type(cx),
116+
PassMode::Cast { ref cast, .. } => cast.gcc_type(cx),
117117
PassMode::Indirect { .. } => {
118118
argument_tys.push(cx.type_ptr_to(self.ret.memory_ty(cx)));
119119
cx.type_void()
@@ -129,21 +129,21 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
129129
argument_tys.push(arg.layout.scalar_pair_element_gcc_type(cx, 1));
130130
continue;
131131
}
132-
PassMode::Indirect { extra_attrs: Some(_), .. } => {
132+
PassMode::Indirect { meta_attrs: Some(_), .. } => {
133133
unimplemented!();
134134
}
135-
PassMode::Cast(ref cast, pad_i32) => {
135+
PassMode::Cast { ref cast, pad_i32 } => {
136136
// add padding
137137
if pad_i32 {
138138
argument_tys.push(Reg::i32().gcc_type(cx));
139139
}
140140
cast.gcc_type(cx)
141141
}
142-
PassMode::Indirect { extra_attrs: None, on_stack: true, .. } => {
142+
PassMode::Indirect { meta_attrs: None, on_stack: true, .. } => {
143143
on_stack_param_indices.insert(argument_tys.len());
144144
arg.memory_ty(cx)
145145
},
146-
PassMode::Indirect { extra_attrs: None, on_stack: false, .. } => cx.type_ptr_to(arg.memory_ty(cx)),
146+
PassMode::Indirect { meta_attrs: None, on_stack: false, .. } => cx.type_ptr_to(arg.memory_ty(cx)),
147147
};
148148
argument_tys.push(arg_ty);
149149
}

compiler/rustc_codegen_gcc/src/intrinsic/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
144144
sym::volatile_load | sym::unaligned_volatile_load => {
145145
let tp_ty = fn_args.type_at(0);
146146
let mut ptr = args[0].immediate();
147-
if let PassMode::Cast(ty, _) = &fn_abi.ret.mode {
147+
if let PassMode::Cast { cast: ty, .. } = &fn_abi.ret.mode {
148148
ptr = self.pointercast(ptr, self.type_ptr_to(ty.gcc_type(self)));
149149
}
150150
let load = self.volatile_load(ptr.get_type(), ptr);
@@ -353,7 +353,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
353353
};
354354

355355
if !fn_abi.ret.is_ignore() {
356-
if let PassMode::Cast(ty, _) = &fn_abi.ret.mode {
356+
if let PassMode::Cast { cast: ty, .. } = &fn_abi.ret.mode {
357357
let ptr_llty = self.type_ptr_to(ty.gcc_type(self));
358358
let ptr = self.pointercast(result.llval, ptr_llty);
359359
self.store(llval, ptr, result.align);
@@ -449,7 +449,7 @@ impl<'gcc, 'tcx> ArgAbiExt<'gcc, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
449449
else if self.is_unsized_indirect() {
450450
bug!("unsized `ArgAbi` must be handled through `store_fn_arg`");
451451
}
452-
else if let PassMode::Cast(ref cast, _) = self.mode {
452+
else if let PassMode::Cast { ref cast, .. } = self.mode {
453453
// FIXME(eddyb): Figure out when the simpler Store is safe, clang
454454
// uses it for i16 -> {i8, i8}, but not for i24 -> {i8, i8, i8}.
455455
let can_store_through_cast_ptr = false;
@@ -511,10 +511,10 @@ impl<'gcc, 'tcx> ArgAbiExt<'gcc, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
511511
PassMode::Pair(..) => {
512512
OperandValue::Pair(next(), next()).store(bx, dst);
513513
},
514-
PassMode::Indirect { extra_attrs: Some(_), .. } => {
514+
PassMode::Indirect { meta_attrs: Some(_), .. } => {
515515
OperandValue::Ref(next(), Some(next()), self.layout.align.abi).store(bx, dst);
516516
},
517-
PassMode::Direct(_) | PassMode::Indirect { extra_attrs: None, .. } | PassMode::Cast(..) => {
517+
PassMode::Direct(_) | PassMode::Indirect { meta_attrs: None, .. } | PassMode::Cast { .. } => {
518518
let next_arg = next();
519519
self.store(bx, next_arg, dst);
520520
},

0 commit comments

Comments
 (0)