File: uninhabited-transparent-return-abi.rs

package info (click to toggle)
rustc 1.88.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 934,128 kB
  • sloc: xml: 158,127; python: 36,062; javascript: 19,855; sh: 19,700; cpp: 18,947; ansic: 12,993; asm: 4,792; makefile: 690; lisp: 29; perl: 29; ruby: 19; sql: 11
file content (44 lines) | stat: -rw-r--r-- 1,278 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//@ compile-flags: -Copt-level=3

// See https://github.com/rust-lang/rust/issues/135802

#![crate_type = "lib"]

enum Void {}

// Should be ABI-compatible with T, but wasn't prior to the PR adding this test.
#[repr(transparent)]
struct NoReturn<T>(T, Void);

// Returned by invisible reference (in most ABIs)
#[allow(dead_code)]
struct Large(u64, u64, u64);

extern "Rust" {
    fn opaque() -> NoReturn<Large>;
    fn opaque_with_arg(rsi: u32) -> NoReturn<Large>;
}

// CHECK-LABEL: @test_uninhabited_ret_by_ref
#[no_mangle]
pub fn test_uninhabited_ret_by_ref() {
    // CHECK: %_1 = alloca [24 x i8], align {{8|4}}
    // CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %_1)
    // CHECK-NEXT: call void @opaque({{.*}} sret([24 x i8]) {{.*}} %_1) #2
    // CHECK-NEXT: unreachable
    unsafe {
        opaque();
    }
}

// CHECK-LABEL: @test_uninhabited_ret_by_ref_with_arg
#[no_mangle]
pub fn test_uninhabited_ret_by_ref_with_arg(rsi: u32) {
    // CHECK: %_2 = alloca [24 x i8], align {{8|4}}
    // CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %_2)
    // CHECK-NEXT: call void @opaque_with_arg({{.*}} sret([24 x i8]) {{.*}} %_2, i32 noundef %rsi) #2
    // CHECK-NEXT: unreachable
    unsafe {
        opaque_with_arg(rsi);
    }
}