2024-03-09 13:54:35 -06:00
|
|
|
// Tests the correct handling of unnamed fields within structs and unions marked with #[repr(C)].
|
2024-03-01 12:03:24 -06:00
|
|
|
|
2024-01-04 07:45:06 -06:00
|
|
|
// EMIT_MIR field_access.foo.SimplifyCfg-initial.after.mir
|
|
|
|
// EMIT_MIR field_access.bar.SimplifyCfg-initial.after.mir
|
|
|
|
|
|
|
|
#![allow(incomplete_features)]
|
|
|
|
#![feature(unnamed_fields)]
|
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
|
struct Foo {
|
|
|
|
a: u8,
|
|
|
|
_: struct {
|
|
|
|
b: i8,
|
|
|
|
c: bool,
|
|
|
|
},
|
|
|
|
_: struct {
|
|
|
|
_: struct {
|
|
|
|
d: [u8; 1],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
|
union Bar {
|
|
|
|
a: u8,
|
|
|
|
_: union {
|
|
|
|
b: i8,
|
|
|
|
c: bool,
|
|
|
|
},
|
|
|
|
_: union {
|
|
|
|
_: union {
|
|
|
|
d: [u8; 1],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn access<T>(_: T) {}
|
|
|
|
|
2024-03-01 12:03:24 -06:00
|
|
|
// CHECK-LABEL: fn foo(
|
2024-01-04 07:45:06 -06:00
|
|
|
fn foo(foo: Foo) {
|
2024-03-11 15:21:52 -05:00
|
|
|
// CHECK [[a:_.*]] = (_1.0: u8);
|
|
|
|
// CHECK _.* = access::<u8>(move [[a]]) -> [return: bb1, unwind: bb5];
|
2024-01-04 07:45:06 -06:00
|
|
|
access(foo.a);
|
2024-03-11 15:21:52 -05:00
|
|
|
// CHECK [[b:_.*]] = ((_1.1: Foo::{anon_adt#0}).0: i8);
|
|
|
|
// CHECK _.* = access::<i8>(move [[b]]) -> [return: bb2, unwind: bb5];
|
2024-01-04 07:45:06 -06:00
|
|
|
access(foo.b);
|
2024-03-11 15:21:52 -05:00
|
|
|
// CHECK [[c:_.*]] = ((_1.1: Foo::{anon_adt#0}).1: bool);
|
|
|
|
// CHECK _.* = access::<bool>(move [[c]]) -> [return: bb3, unwind: bb5];
|
2024-01-04 07:45:06 -06:00
|
|
|
access(foo.c);
|
2024-03-11 15:21:52 -05:00
|
|
|
// CHECK [[d:_.*]] = (((_1.2: Foo::{anon_adt#1}).0: Foo::{anon_adt#1}::{anon_adt#0}).0: [u8; 1]);
|
|
|
|
// CHECK _.* = access::<[u8; 1]>(move [[d]]) -> [return: bb4, unwind: bb5];
|
2024-01-04 07:45:06 -06:00
|
|
|
access(foo.d);
|
|
|
|
}
|
|
|
|
|
2024-03-01 12:03:24 -06:00
|
|
|
// CHECK-LABEL: fn bar(
|
2024-01-04 07:45:06 -06:00
|
|
|
fn bar(bar: Bar) {
|
|
|
|
unsafe {
|
2024-03-11 15:21:52 -05:00
|
|
|
// CHECK [[a:_.*]] = (_1.0: u8);
|
|
|
|
// CHECK _.* = access::<u8>(move [[a]]) -> [return: bb1, unwind: bb5];
|
2024-01-04 07:45:06 -06:00
|
|
|
access(bar.a);
|
2024-03-11 15:21:52 -05:00
|
|
|
// CHECK [[b:_.*]] = ((_1.1: Bar::{anon_adt#0}).0: i8);
|
|
|
|
// CHECK _.* = access::<i8>(move [[b]]) -> [return: bb2, unwind: bb5];
|
2024-01-04 07:45:06 -06:00
|
|
|
access(bar.b);
|
2024-03-11 15:21:52 -05:00
|
|
|
// CHECK [[c:_.*]] = ((_1.1: Bar::{anon_adt#0}).1: bool);
|
|
|
|
// CHECK _.* = access::<bool>(move [[c]]) -> [return: bb3, unwind: bb5];
|
2024-01-04 07:45:06 -06:00
|
|
|
access(bar.c);
|
2024-03-11 15:21:52 -05:00
|
|
|
// CHECK [[d:_.*]] = (((_1.2: Bar::{anon_adt#1}).0: Bar::{anon_adt#1}::{anon_adt#0}).0: [u8; 1]);
|
|
|
|
// CHECK _.* = access::<[u8; 1]>(move [[d]]) -> [return: bb4, unwind: bb5];
|
2024-01-04 07:45:06 -06:00
|
|
|
access(bar.d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn main() {}
|