Skip to content

Commit e05da87

Browse files
committed
Add regression test for option initialization
1 parent 1f81f90 commit e05da87

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

tests/codegen/repeat-init.rs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
//@ compile-flags: -O -Z randomize-layout=no
2+
//@ only-x86_64
3+
#![crate_type = "lib"]
4+
5+
extern crate core;
6+
7+
use core::num::NonZero;
8+
use core::option::Option;
9+
10+
const N: usize = 100;
11+
12+
// CHECK-LABEL: @u8_init
13+
#[no_mangle]
14+
pub fn u8_init() -> [u8; N] {
15+
// CHECK-NOT: select
16+
// CHECK-NOT: br
17+
// CHECK-NOT: switch
18+
// CHECK-NOT: icmp
19+
// CHECK: llvm.memset.p0
20+
[0; N]
21+
}
22+
23+
// CHECK-LABEL: @u8_init_ones
24+
#[no_mangle]
25+
pub fn u8_init_ones() -> [u8; N] {
26+
// CHECK-NOT: select
27+
// CHECK-NOT: br
28+
// CHECK-NOT: switch
29+
// CHECK-NOT: icmp
30+
// CHECK: llvm.memset.p0
31+
[1; N]
32+
}
33+
34+
// CHECK-LABEL: @u16_init
35+
#[no_mangle]
36+
pub fn u16_init() -> [u16; N] {
37+
// CHECK-NOT: select
38+
// CHECK-NOT: br
39+
// CHECK-NOT: switch
40+
// CHECK-NOT: icmp
41+
// CHECK: llvm.memset.p0
42+
[0; N]
43+
}
44+
45+
// This can't be helped
46+
// CHECK-LABEL: @u16_init_ones
47+
#[no_mangle]
48+
pub fn u16_init_ones() -> [u16; N] {
49+
// CHECK-NOT: select
50+
// CHECK-NOT: br
51+
// CHECK-NOT: switch
52+
// CHECK: getelementptr
53+
// CHECK-NOT: llvm.memset.p0
54+
[1; N]
55+
}
56+
57+
// FIXME: The two bytes of the u16 are the same, so we should
58+
// just use memset, too.
59+
// CHECK-LABEL: @u16_init_one_bytes
60+
#[no_mangle]
61+
pub fn u16_init_one_bytes() -> [u16; N] {
62+
// CHECK-NOT: select
63+
// CHECK-NOT: br
64+
// CHECK-NOT: switch
65+
// CHECK-NOT: icmp
66+
// CHECK: llvm.memset.p0
67+
[u16::from_be_bytes([1, 1]); N]
68+
}
69+
70+
// FIXME: undef bytes can just be initialized with the same value as the
71+
// defined bytes, if the defines bytes are all the same.
72+
// CHECK-LABEL: @option_none_init
73+
#[no_mangle]
74+
pub fn option_none_init() -> [Option<u8>; N] {
75+
// CHECK-NOT: select
76+
// CHECK: br
77+
// CHECK-NOT: switch
78+
// CHECK: icmp
79+
[None; N]
80+
}

0 commit comments

Comments
 (0)