add rustc_abi debugging attribute

This commit is contained in:
Ralf Jung 2023-08-25 23:01:06 +02:00
parent b60f7b51a2
commit abe2148aee
12 changed files with 422 additions and 29 deletions

23
tests/ui/abi/debug.rs Normal file
View file

@ -0,0 +1,23 @@
// normalize-stderr-test "(abi|pref|unadjusted_abi_align): Align\([1-8] bytes\)" -> "$1: $$SOME_ALIGN"
// normalize-stderr-test "(size): Size\([48] bytes\)" -> "$1: $$SOME_SIZE"
// normalize-stderr-test "(can_unwind): (true|false)" -> "$1: $$SOME_BOOL"
// normalize-stderr-test "(valid_range): 0\.\.=(4294967295|18446744073709551615)" -> "$1: $$FULL"
// This pattern is prepared for when we account for alignment in the niche.
// normalize-stderr-test "(valid_range): [1-9]\.\.=(429496729[0-9]|1844674407370955161[0-9])" -> "$1: $$NON_NULL"
// Some attributes are only computed for release builds:
// compile-flags: -O
#![feature(rustc_attrs)]
#![crate_type = "lib"]
#[rustc_abi(debug)]
fn test(_x: u8) -> bool { true } //~ ERROR: fn_abi
#[rustc_abi(debug)]
fn test_generic<T>(_x: *const T) { } //~ ERROR: fn_abi
struct S(u16);
impl S {
#[rustc_abi(debug)]
fn assoc_test(&self) { } //~ ERROR: fn_abi
}

260
tests/ui/abi/debug.stderr Normal file
View file

@ -0,0 +1,260 @@
error: fn_abi_of_instance(test) = FnAbi {
args: [
ArgAbi {
layout: TyAndLayout {
ty: u8,
layout: Layout {
size: Size(1 bytes),
align: AbiAndPrefAlign {
abi: $SOME_ALIGN,
pref: $SOME_ALIGN,
},
abi: Scalar(
Initialized {
value: Int(
I8,
false,
),
valid_range: 0..=255,
},
),
fields: Primitive,
largest_niche: None,
variants: Single {
index: 0,
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
},
},
mode: Direct(
ArgAttributes {
regular: NoUndef,
arg_ext: None,
pointee_size: Size(0 bytes),
pointee_align: None,
},
),
},
],
ret: ArgAbi {
layout: TyAndLayout {
ty: bool,
layout: Layout {
size: Size(1 bytes),
align: AbiAndPrefAlign {
abi: $SOME_ALIGN,
pref: $SOME_ALIGN,
},
abi: Scalar(
Initialized {
value: Int(
I8,
false,
),
valid_range: 0..=1,
},
),
fields: Primitive,
largest_niche: Some(
Niche {
offset: Size(0 bytes),
value: Int(
I8,
false,
),
valid_range: 0..=1,
},
),
variants: Single {
index: 0,
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
},
},
mode: Direct(
ArgAttributes {
regular: NoUndef,
arg_ext: Zext,
pointee_size: Size(0 bytes),
pointee_align: None,
},
),
},
c_variadic: false,
fixed_count: 1,
conv: Rust,
can_unwind: $SOME_BOOL,
}
--> $DIR/debug.rs:13:1
|
LL | fn test(_x: u8) -> bool { true }
| ^^^^^^^^^^^^^^^^^^^^^^^
error: fn_abi_of_instance(test_generic) = FnAbi {
args: [
ArgAbi {
layout: TyAndLayout {
ty: *const T,
layout: Layout {
size: $SOME_SIZE,
align: AbiAndPrefAlign {
abi: $SOME_ALIGN,
pref: $SOME_ALIGN,
},
abi: Scalar(
Initialized {
value: Pointer(
AddressSpace(
0,
),
),
valid_range: $FULL,
},
),
fields: Primitive,
largest_niche: None,
variants: Single {
index: 0,
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
},
},
mode: Direct(
ArgAttributes {
regular: NoUndef,
arg_ext: None,
pointee_size: Size(0 bytes),
pointee_align: None,
},
),
},
],
ret: ArgAbi {
layout: TyAndLayout {
ty: (),
layout: Layout {
size: Size(0 bytes),
align: AbiAndPrefAlign {
abi: $SOME_ALIGN,
pref: $SOME_ALIGN,
},
abi: Aggregate {
sized: true,
},
fields: Arbitrary {
offsets: [],
memory_index: [],
},
largest_niche: None,
variants: Single {
index: 0,
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
},
},
mode: Ignore,
},
c_variadic: false,
fixed_count: 1,
conv: Rust,
can_unwind: $SOME_BOOL,
}
--> $DIR/debug.rs:17:1
|
LL | fn test_generic<T>(_x: *const T) { }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: fn_abi_of_instance(assoc_test) = FnAbi {
args: [
ArgAbi {
layout: TyAndLayout {
ty: &S,
layout: Layout {
size: $SOME_SIZE,
align: AbiAndPrefAlign {
abi: $SOME_ALIGN,
pref: $SOME_ALIGN,
},
abi: Scalar(
Initialized {
value: Pointer(
AddressSpace(
0,
),
),
valid_range: $NON_NULL,
},
),
fields: Primitive,
largest_niche: Some(
Niche {
offset: Size(0 bytes),
value: Pointer(
AddressSpace(
0,
),
),
valid_range: $NON_NULL,
},
),
variants: Single {
index: 0,
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
},
},
mode: Direct(
ArgAttributes {
regular: NoAlias | NonNull | ReadOnly | NoUndef,
arg_ext: None,
pointee_size: Size(2 bytes),
pointee_align: Some(
Align(2 bytes),
),
},
),
},
],
ret: ArgAbi {
layout: TyAndLayout {
ty: (),
layout: Layout {
size: Size(0 bytes),
align: AbiAndPrefAlign {
abi: $SOME_ALIGN,
pref: $SOME_ALIGN,
},
abi: Aggregate {
sized: true,
},
fields: Arbitrary {
offsets: [],
memory_index: [],
},
largest_niche: None,
variants: Single {
index: 0,
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
},
},
mode: Ignore,
},
c_variadic: false,
fixed_count: 1,
conv: Rust,
can_unwind: $SOME_BOOL,
}
--> $DIR/debug.rs:22:5
|
LL | fn assoc_test(&self) { }
| ^^^^^^^^^^^^^^^^^^^^
error: aborting due to 3 previous errors

View file

@ -1,4 +1,4 @@
// normalize-stderr-test "pref: Align\([1-8] bytes\)" -> "pref: $$PREF_ALIGN"
// normalize-stderr-test "pref: Align\([1-8] bytes\)" -> "pref: $$SOME_ALIGN"
#![feature(never_type, rustc_attrs, type_alias_impl_trait, repr_simd)]
#![crate_type = "lib"]

View file

@ -2,7 +2,7 @@ error: layout_of(E) = Layout {
size: Size(12 bytes),
align: AbiAndPrefAlign {
abi: Align(4 bytes),
pref: $PREF_ALIGN,
pref: $SOME_ALIGN,
},
abi: Aggregate {
sized: true,
@ -40,7 +40,7 @@ error: layout_of(E) = Layout {
size: Size(4 bytes),
align: AbiAndPrefAlign {
abi: Align(1 bytes),
pref: $PREF_ALIGN,
pref: $SOME_ALIGN,
},
abi: Aggregate {
sized: true,
@ -60,7 +60,7 @@ error: layout_of(E) = Layout {
size: Size(12 bytes),
align: AbiAndPrefAlign {
abi: Align(4 bytes),
pref: $PREF_ALIGN,
pref: $SOME_ALIGN,
},
abi: Uninhabited,
fields: Arbitrary {
@ -96,7 +96,7 @@ error: layout_of(S) = Layout {
size: Size(8 bytes),
align: AbiAndPrefAlign {
abi: Align(4 bytes),
pref: $PREF_ALIGN,
pref: $SOME_ALIGN,
},
abi: ScalarPair(
Initialized {
@ -142,7 +142,7 @@ error: layout_of(U) = Layout {
size: Size(8 bytes),
align: AbiAndPrefAlign {
abi: Align(4 bytes),
pref: $PREF_ALIGN,
pref: $SOME_ALIGN,
},
abi: Aggregate {
sized: true,
@ -166,7 +166,7 @@ error: layout_of(std::result::Result<i32, i32>) = Layout {
size: Size(8 bytes),
align: AbiAndPrefAlign {
abi: Align(4 bytes),
pref: $PREF_ALIGN,
pref: $SOME_ALIGN,
},
abi: ScalarPair(
Initialized {
@ -217,7 +217,7 @@ error: layout_of(std::result::Result<i32, i32>) = Layout {
size: Size(8 bytes),
align: AbiAndPrefAlign {
abi: Align(4 bytes),
pref: $PREF_ALIGN,
pref: $SOME_ALIGN,
},
abi: ScalarPair(
Initialized {
@ -254,7 +254,7 @@ error: layout_of(std::result::Result<i32, i32>) = Layout {
size: Size(8 bytes),
align: AbiAndPrefAlign {
abi: Align(4 bytes),
pref: $PREF_ALIGN,
pref: $SOME_ALIGN,
},
abi: ScalarPair(
Initialized {
@ -301,7 +301,7 @@ error: layout_of(i32) = Layout {
size: Size(4 bytes),
align: AbiAndPrefAlign {
abi: Align(4 bytes),
pref: $PREF_ALIGN,
pref: $SOME_ALIGN,
},
abi: Scalar(
Initialized {
@ -329,7 +329,7 @@ error: layout_of(V) = Layout {
size: Size(2 bytes),
align: AbiAndPrefAlign {
abi: Align(2 bytes),
pref: $PREF_ALIGN,
pref: $SOME_ALIGN,
},
abi: Aggregate {
sized: true,
@ -353,7 +353,7 @@ error: layout_of(W) = Layout {
size: Size(2 bytes),
align: AbiAndPrefAlign {
abi: Align(2 bytes),
pref: $PREF_ALIGN,
pref: $SOME_ALIGN,
},
abi: Aggregate {
sized: true,
@ -377,7 +377,7 @@ error: layout_of(Y) = Layout {
size: Size(0 bytes),
align: AbiAndPrefAlign {
abi: Align(2 bytes),
pref: $PREF_ALIGN,
pref: $SOME_ALIGN,
},
abi: Aggregate {
sized: true,
@ -401,7 +401,7 @@ error: layout_of(P1) = Layout {
size: Size(4 bytes),
align: AbiAndPrefAlign {
abi: Align(1 bytes),
pref: $PREF_ALIGN,
pref: $SOME_ALIGN,
},
abi: Aggregate {
sized: true,
@ -425,7 +425,7 @@ error: layout_of(P2) = Layout {
size: Size(8 bytes),
align: AbiAndPrefAlign {
abi: Align(1 bytes),
pref: $PREF_ALIGN,
pref: $SOME_ALIGN,
},
abi: Aggregate {
sized: true,
@ -449,7 +449,7 @@ error: layout_of(P3) = Layout {
size: Size(16 bytes),
align: AbiAndPrefAlign {
abi: Align(1 bytes),
pref: $PREF_ALIGN,
pref: $SOME_ALIGN,
},
abi: Aggregate {
sized: true,
@ -473,7 +473,7 @@ error: layout_of(P4) = Layout {
size: Size(12 bytes),
align: AbiAndPrefAlign {
abi: Align(1 bytes),
pref: $PREF_ALIGN,
pref: $SOME_ALIGN,
},
abi: Aggregate {
sized: true,
@ -497,7 +497,7 @@ error: layout_of(P5) = Layout {
size: Size(1 bytes),
align: AbiAndPrefAlign {
abi: Align(1 bytes),
pref: $PREF_ALIGN,
pref: $SOME_ALIGN,
},
abi: Scalar(
Union {
@ -526,7 +526,7 @@ error: layout_of(std::mem::MaybeUninit<u8>) = Layout {
size: Size(1 bytes),
align: AbiAndPrefAlign {
abi: Align(1 bytes),
pref: $PREF_ALIGN,
pref: $SOME_ALIGN,
},
abi: Scalar(
Union {