Skip to content

Commit d1c8f66

Browse files
committed
clarify PassMode::Indirect as well
1 parent 6570039 commit d1c8f66

File tree

8 files changed

+60
-54
lines changed

8 files changed

+60
-54
lines changed

compiler/rustc_codegen_cranelift/src/abi/pass_mode.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
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
}
@@ -151,11 +151,11 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
151151
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
}
@@ -290,11 +290,11 @@ pub(super) fn cvalue_for_param<'tcx>(
290290
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

+8-8
Original file line numberDiff line numberDiff line change
@@ -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,7 +73,7 @@ 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
}
7979
PassMode::Direct(_) | PassMode::Pair(_, _) | PassMode::Cast(..) => (None, None),
@@ -100,14 +100,14 @@ pub(super) fn codegen_with_call_return_arg<'tcx>(
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(_) => {

compiler/rustc_codegen_gcc/src/abi.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ 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
}
135135
PassMode::Cast(ref cast, pad_i32) => {
@@ -139,11 +139,11 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
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

+2-2
Original file line numberDiff line numberDiff line change
@@ -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
},

compiler/rustc_codegen_llvm/src/abi.rs

+20-15
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,11 @@ impl<'ll, 'tcx> ArgAbiExt<'ll, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
274274
PassMode::Pair(..) => {
275275
OperandValue::Pair(next(), next()).store(bx, dst);
276276
}
277-
PassMode::Indirect { attrs: _, extra_attrs: Some(_), on_stack: _ } => {
277+
PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => {
278278
OperandValue::Ref(next(), Some(next()), self.layout.align.abi).store(bx, dst);
279279
}
280280
PassMode::Direct(_)
281-
| PassMode::Indirect { attrs: _, extra_attrs: None, on_stack: _ }
281+
| PassMode::Indirect { attrs: _, meta_attrs: None, on_stack: _ }
282282
| PassMode::Cast { .. } => {
283283
let next_arg = next();
284284
self.store(bx, next_arg, dst);
@@ -378,8 +378,10 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
378378
llargument_tys.push(arg.layout.scalar_pair_element_llvm_type(cx, 1, true));
379379
continue;
380380
}
381-
PassMode::Indirect { attrs: _, extra_attrs: Some(_), on_stack: _ } => {
382-
assert!(arg.layout.is_unsized());
381+
PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack } => {
382+
// `Indirect` with metadata is only for unsized types, and doesn't work with
383+
// on-stack passing.
384+
assert!(arg.layout.is_unsized() && !on_stack);
383385
// Construct the type of a (wide) pointer to `ty`, and pass its two fields.
384386
// Any two ABI-compatible unsized types have the same metadata type and
385387
// moreover the same metadata value leads to the same dynamic size and
@@ -390,6 +392,10 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
390392
llargument_tys.push(ptr_layout.scalar_pair_element_llvm_type(cx, 1, true));
391393
continue;
392394
}
395+
PassMode::Indirect { attrs: _, meta_attrs: None, on_stack: _ } => {
396+
assert!(arg.layout.is_sized());
397+
cx.type_ptr()
398+
}
393399
PassMode::Cast { cast, pad_i32 } => {
394400
// `Cast` means "transmute to `CastType`"; that only makes sense for sized types.
395401
assert!(arg.layout.is_sized());
@@ -401,7 +407,6 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
401407
// We assume here that ABI-compatible Rust types have the same cast type.
402408
cast.llvm_type(cx)
403409
}
404-
PassMode::Indirect { attrs: _, extra_attrs: None, on_stack: _ } => cx.type_ptr(),
405410
};
406411
llargument_tys.push(llarg_ty);
407412
}
@@ -444,7 +449,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
444449
PassMode::Direct(attrs) => {
445450
attrs.apply_attrs_to_llfn(llvm::AttributePlace::ReturnValue, cx, llfn);
446451
}
447-
PassMode::Indirect { attrs, extra_attrs: _, on_stack } => {
452+
PassMode::Indirect { attrs, meta_attrs: _, on_stack } => {
448453
assert!(!on_stack);
449454
let i = apply(attrs);
450455
let sret = llvm::CreateStructRetAttr(cx.llcx, self.ret.layout.llvm_type(cx));
@@ -458,19 +463,19 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
458463
for arg in self.args.iter() {
459464
match &arg.mode {
460465
PassMode::Ignore => {}
461-
PassMode::Indirect { attrs, extra_attrs: None, on_stack: true } => {
466+
PassMode::Indirect { attrs, meta_attrs: None, on_stack: true } => {
462467
let i = apply(attrs);
463468
let byval = llvm::CreateByValAttr(cx.llcx, arg.layout.llvm_type(cx));
464469
attributes::apply_to_llfn(llfn, llvm::AttributePlace::Argument(i), &[byval]);
465470
}
466471
PassMode::Direct(attrs)
467-
| PassMode::Indirect { attrs, extra_attrs: None, on_stack: false } => {
472+
| PassMode::Indirect { attrs, meta_attrs: None, on_stack: false } => {
468473
apply(attrs);
469474
}
470-
PassMode::Indirect { attrs, extra_attrs: Some(extra_attrs), on_stack } => {
475+
PassMode::Indirect { attrs, meta_attrs: Some(meta_attrs), on_stack } => {
471476
assert!(!on_stack);
472477
apply(attrs);
473-
apply(extra_attrs);
478+
apply(meta_attrs);
474479
}
475480
PassMode::Pair(a, b) => {
476481
apply(a);
@@ -506,7 +511,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
506511
PassMode::Direct(attrs) => {
507512
attrs.apply_attrs_to_callsite(llvm::AttributePlace::ReturnValue, bx.cx, callsite);
508513
}
509-
PassMode::Indirect { attrs, extra_attrs: _, on_stack } => {
514+
PassMode::Indirect { attrs, meta_attrs: _, on_stack } => {
510515
assert!(!on_stack);
511516
let i = apply(bx.cx, attrs);
512517
let sret = llvm::CreateStructRetAttr(bx.cx.llcx, self.ret.layout.llvm_type(bx));
@@ -534,7 +539,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
534539
for arg in self.args.iter() {
535540
match &arg.mode {
536541
PassMode::Ignore => {}
537-
PassMode::Indirect { attrs, extra_attrs: None, on_stack: true } => {
542+
PassMode::Indirect { attrs, meta_attrs: None, on_stack: true } => {
538543
let i = apply(bx.cx, attrs);
539544
let byval = llvm::CreateByValAttr(bx.cx.llcx, arg.layout.llvm_type(bx));
540545
attributes::apply_to_callsite(
@@ -544,12 +549,12 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
544549
);
545550
}
546551
PassMode::Direct(attrs)
547-
| PassMode::Indirect { attrs, extra_attrs: None, on_stack: false } => {
552+
| PassMode::Indirect { attrs, meta_attrs: None, on_stack: false } => {
548553
apply(bx.cx, attrs);
549554
}
550-
PassMode::Indirect { attrs, extra_attrs: Some(extra_attrs), on_stack: _ } => {
555+
PassMode::Indirect { attrs, meta_attrs: Some(meta_attrs), on_stack: _ } => {
551556
apply(bx.cx, attrs);
552-
apply(bx.cx, extra_attrs);
557+
apply(bx.cx, meta_attrs);
553558
}
554559
PassMode::Pair(a, b) => {
555560
apply(bx.cx, a);

compiler/rustc_codegen_ssa/src/mir/block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
13431343
}
13441344
_ => bug!("codegen_argument: {:?} invalid for pair argument", op),
13451345
},
1346-
PassMode::Indirect { attrs: _, extra_attrs: Some(_), on_stack: _ } => match op.val {
1346+
PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => match op.val {
13471347
Ref(a, Some(b), _) => {
13481348
llargs.push(a);
13491349
llargs.push(b);

compiler/rustc_target/src/abi/call/mod.rs

+17-16
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@ pub enum PassMode {
4949
/// indicates if a `Reg::i32()` dummy argument is emitted before the real argument.
5050
Cast { pad_i32: bool, cast: Box<CastTarget> },
5151
/// Pass the argument indirectly via a hidden pointer.
52-
/// The `extra_attrs` value, if any, is for the extra data (vtable or length)
53-
/// which indicates that it refers to an unsized rvalue.
54-
/// `on_stack` defines that the value should be passed at a fixed
55-
/// stack offset in accordance to the ABI rather than passed using a
56-
/// pointer. This corresponds to the `byval` LLVM argument attribute.
57-
Indirect { attrs: ArgAttributes, extra_attrs: Option<ArgAttributes>, on_stack: bool },
52+
/// The `meta_attrs` value, if any, is for the metadata (vtable or length) of an unsized
53+
/// argument.
54+
/// `on_stack` defines that the value should be passed at a fixed stack offset in accordance to
55+
/// the ABI rather than passed using a pointer. This corresponds to the `byval` LLVM argument
56+
/// attribute (using the Rust type of this argument). `on_stack` cannot be true for unsized
57+
/// arguments, i.e., when `meta_attrs` is `Some`.
58+
Indirect { attrs: ArgAttributes, meta_attrs: Option<ArgAttributes>, on_stack: bool },
5859
}
5960

6061
impl PassMode {
@@ -71,12 +72,12 @@ impl PassMode {
7172
PassMode::Cast { cast: c2, pad_i32: pad2 },
7273
) => c1.eq_abi(c2) && pad1 == pad2,
7374
(
74-
PassMode::Indirect { attrs: a1, extra_attrs: None, on_stack: s1 },
75-
PassMode::Indirect { attrs: a2, extra_attrs: None, on_stack: s2 },
75+
PassMode::Indirect { attrs: a1, meta_attrs: None, on_stack: s1 },
76+
PassMode::Indirect { attrs: a2, meta_attrs: None, on_stack: s2 },
7677
) => a1.eq_abi(a2) && s1 == s2,
7778
(
78-
PassMode::Indirect { attrs: a1, extra_attrs: Some(e1), on_stack: s1 },
79-
PassMode::Indirect { attrs: a2, extra_attrs: Some(e2), on_stack: s2 },
79+
PassMode::Indirect { attrs: a1, meta_attrs: Some(e1), on_stack: s1 },
80+
PassMode::Indirect { attrs: a2, meta_attrs: Some(e2), on_stack: s2 },
8081
) => a1.eq_abi(a2) && e1.eq_abi(e2) && s1 == s2,
8182
_ => false,
8283
}
@@ -560,15 +561,15 @@ impl<'a, Ty> ArgAbi<'a, Ty> {
560561
attrs.pointee_size = layout.size;
561562
attrs.pointee_align = Some(layout.align.abi);
562563

563-
let extra_attrs = layout.is_unsized().then_some(ArgAttributes::new());
564+
let meta_attrs = layout.is_unsized().then_some(ArgAttributes::new());
564565

565-
PassMode::Indirect { attrs, extra_attrs, on_stack: false }
566+
PassMode::Indirect { attrs, meta_attrs, on_stack: false }
566567
}
567568

568569
pub fn make_indirect(&mut self) {
569570
match self.mode {
570571
PassMode::Direct(_) | PassMode::Pair(_, _) => {}
571-
PassMode::Indirect { attrs: _, extra_attrs: None, on_stack: false } => return,
572+
PassMode::Indirect { attrs: _, meta_attrs: None, on_stack: false } => return,
572573
_ => panic!("Tried to make {:?} indirect", self.mode),
573574
}
574575

@@ -578,7 +579,7 @@ impl<'a, Ty> ArgAbi<'a, Ty> {
578579
pub fn make_indirect_byval(&mut self, byval_align: Option<Align>) {
579580
self.make_indirect();
580581
match self.mode {
581-
PassMode::Indirect { ref mut attrs, extra_attrs: _, ref mut on_stack } => {
582+
PassMode::Indirect { ref mut attrs, meta_attrs: _, ref mut on_stack } => {
582583
*on_stack = true;
583584

584585
// Some platforms, like 32-bit x86, change the alignment of the type when passing
@@ -623,11 +624,11 @@ impl<'a, Ty> ArgAbi<'a, Ty> {
623624
}
624625

625626
pub fn is_sized_indirect(&self) -> bool {
626-
matches!(self.mode, PassMode::Indirect { attrs: _, extra_attrs: None, on_stack: _ })
627+
matches!(self.mode, PassMode::Indirect { attrs: _, meta_attrs: None, on_stack: _ })
627628
}
628629

629630
pub fn is_unsized_indirect(&self) -> bool {
630-
matches!(self.mode, PassMode::Indirect { attrs: _, extra_attrs: Some(_), on_stack: _ })
631+
matches!(self.mode, PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ })
631632
}
632633

633634
pub fn is_ignore(&self) -> bool {

0 commit comments

Comments
 (0)