Skip to content

Commit a53c6ee

Browse files
committed
also ensure that size and alignment are the same
1 parent f6ef555 commit a53c6ee

File tree

3 files changed

+161
-6
lines changed

3 files changed

+161
-6
lines changed

compiler/rustc_passes/src/abi_test.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,13 @@ fn test_arg_abi_eq<'tcx>(
119119
abi2: &'tcx ArgAbi<'tcx, Ty<'tcx>>,
120120
) -> bool {
121121
// Ideally we'd just compare the `mode`, but that is not enough -- for some modes LLVM will look
122-
// at the type. Comparing the `mode` and `layout.abi` should catch basically everything though
123-
// (except for tricky cases around unized types).
124-
abi1.mode.eq_abi(&abi2.mode) && abi1.layout.abi.eq_up_to_validity(&abi2.layout.abi)
122+
// at the type. Comparing the `mode` and `layout.abi` as well as size and alignment should catch
123+
// basically everything though (except for tricky cases around unized types).
124+
abi1.mode.eq_abi(&abi2.mode)
125+
&& abi1.layout.abi.eq_up_to_validity(&abi2.layout.abi)
126+
&& abi1.layout.size == abi2.layout.size
127+
&& abi1.layout.align.abi == abi2.layout.align.abi
128+
&& abi1.layout.is_sized() == abi2.layout.is_sized()
125129
}
126130

127131
fn test_abi_eq<'tcx>(abi1: &'tcx FnAbi<'tcx, Ty<'tcx>>, abi2: &'tcx FnAbi<'tcx, Ty<'tcx>>) -> bool {

tests/ui/abi/debug.rs

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ type TestAbiEq = (fn(bool), fn(bool));
3939
#[rustc_abi(assert_eq)]
4040
type TestAbiNe = (fn(u8), fn(u32)); //~ ERROR: ABIs are not compatible
4141

42+
#[rustc_abi(assert_eq)]
43+
type TestAbiNeLarger = (fn([u8; 32]), fn([u32; 32])); //~ ERROR: ABIs are not compatible
44+
4245
#[rustc_abi(assert_eq)]
4346
type TestAbiNeFloat = (fn(f32), fn(u32)); //~ ERROR: ABIs are not compatible
4447

tests/ui/abi/debug.stderr

+151-3
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,154 @@ error: ABIs are not compatible
508508
LL | type TestAbiNe = (fn(u8), fn(u32));
509509
| ^^^^^^^^^^^^^^
510510

511+
error: ABIs are not compatible
512+
left ABI = FnAbi {
513+
args: [
514+
ArgAbi {
515+
layout: TyAndLayout {
516+
ty: [u8; 32],
517+
layout: Layout {
518+
size: Size(32 bytes),
519+
align: AbiAndPrefAlign {
520+
abi: $SOME_ALIGN,
521+
pref: $SOME_ALIGN,
522+
},
523+
abi: Aggregate {
524+
sized: true,
525+
},
526+
fields: Array {
527+
stride: Size(1 bytes),
528+
count: 32,
529+
},
530+
largest_niche: None,
531+
variants: Single {
532+
index: 0,
533+
},
534+
max_repr_align: None,
535+
unadjusted_abi_align: $SOME_ALIGN,
536+
},
537+
},
538+
mode: Indirect {
539+
attrs: ArgAttributes {
540+
regular: NoAlias | NoCapture | NonNull | NoUndef,
541+
arg_ext: None,
542+
pointee_size: Size(32 bytes),
543+
pointee_align: Some(
544+
Align(1 bytes),
545+
),
546+
},
547+
extra_attrs: None,
548+
on_stack: false,
549+
},
550+
},
551+
],
552+
ret: ArgAbi {
553+
layout: TyAndLayout {
554+
ty: (),
555+
layout: Layout {
556+
size: Size(0 bytes),
557+
align: AbiAndPrefAlign {
558+
abi: $SOME_ALIGN,
559+
pref: $SOME_ALIGN,
560+
},
561+
abi: Aggregate {
562+
sized: true,
563+
},
564+
fields: Arbitrary {
565+
offsets: [],
566+
memory_index: [],
567+
},
568+
largest_niche: None,
569+
variants: Single {
570+
index: 0,
571+
},
572+
max_repr_align: None,
573+
unadjusted_abi_align: $SOME_ALIGN,
574+
},
575+
},
576+
mode: Ignore,
577+
},
578+
c_variadic: false,
579+
fixed_count: 1,
580+
conv: Rust,
581+
can_unwind: $SOME_BOOL,
582+
}
583+
right ABI = FnAbi {
584+
args: [
585+
ArgAbi {
586+
layout: TyAndLayout {
587+
ty: [u32; 32],
588+
layout: Layout {
589+
size: Size(128 bytes),
590+
align: AbiAndPrefAlign {
591+
abi: $SOME_ALIGN,
592+
pref: $SOME_ALIGN,
593+
},
594+
abi: Aggregate {
595+
sized: true,
596+
},
597+
fields: Array {
598+
stride: Size(4 bytes),
599+
count: 32,
600+
},
601+
largest_niche: None,
602+
variants: Single {
603+
index: 0,
604+
},
605+
max_repr_align: None,
606+
unadjusted_abi_align: $SOME_ALIGN,
607+
},
608+
},
609+
mode: Indirect {
610+
attrs: ArgAttributes {
611+
regular: NoAlias | NoCapture | NonNull | NoUndef,
612+
arg_ext: None,
613+
pointee_size: Size(128 bytes),
614+
pointee_align: Some(
615+
Align(4 bytes),
616+
),
617+
},
618+
extra_attrs: None,
619+
on_stack: false,
620+
},
621+
},
622+
],
623+
ret: ArgAbi {
624+
layout: TyAndLayout {
625+
ty: (),
626+
layout: Layout {
627+
size: Size(0 bytes),
628+
align: AbiAndPrefAlign {
629+
abi: $SOME_ALIGN,
630+
pref: $SOME_ALIGN,
631+
},
632+
abi: Aggregate {
633+
sized: true,
634+
},
635+
fields: Arbitrary {
636+
offsets: [],
637+
memory_index: [],
638+
},
639+
largest_niche: None,
640+
variants: Single {
641+
index: 0,
642+
},
643+
max_repr_align: None,
644+
unadjusted_abi_align: $SOME_ALIGN,
645+
},
646+
},
647+
mode: Ignore,
648+
},
649+
c_variadic: false,
650+
fixed_count: 1,
651+
conv: Rust,
652+
can_unwind: $SOME_BOOL,
653+
}
654+
--> $DIR/debug.rs:43:1
655+
|
656+
LL | type TestAbiNeLarger = (fn([u8; 32]), fn([u32; 32]));
657+
| ^^^^^^^^^^^^^^^^^^^^
658+
511659
error: ABIs are not compatible
512660
left ABI = FnAbi {
513661
args: [
@@ -646,7 +794,7 @@ error: ABIs are not compatible
646794
conv: Rust,
647795
can_unwind: $SOME_BOOL,
648796
}
649-
--> $DIR/debug.rs:43:1
797+
--> $DIR/debug.rs:46:1
650798
|
651799
LL | type TestAbiNeFloat = (fn(f32), fn(u32));
652800
| ^^^^^^^^^^^^^^^^^^^
@@ -792,10 +940,10 @@ error: ABIs are not compatible
792940
conv: Rust,
793941
can_unwind: $SOME_BOOL,
794942
}
795-
--> $DIR/debug.rs:47:1
943+
--> $DIR/debug.rs:50:1
796944
|
797945
LL | type TestAbiNeSign = (fn(i32), fn(u32));
798946
| ^^^^^^^^^^^^^^^^^^
799947

800-
error: aborting due to 9 previous errors
948+
error: aborting due to 10 previous errors
801949

0 commit comments

Comments
 (0)