Skip to content

Commit c18da3c

Browse files
author
David Koloski
committed
Add regression test for LLVM 17-rc3 miscompile
See #115385 for more details.
1 parent ab45885 commit c18da3c

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

tests/codegen/issues/issue-115385.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// compile-flags: -O -Ccodegen-units=1
2+
// only-x86_64-unknown-linux-gnu
3+
4+
#![crate_type = "lib"]
5+
6+
#[repr(i64)]
7+
pub enum Boolean {
8+
False = 0,
9+
True = 1,
10+
}
11+
12+
impl Clone for Boolean {
13+
fn clone(&self) -> Self {
14+
*self
15+
}
16+
}
17+
18+
impl Copy for Boolean {}
19+
20+
extern "C" {
21+
fn set_value(foo: *mut i64);
22+
}
23+
24+
pub fn foo(x: bool) {
25+
let mut foo = core::mem::MaybeUninit::<i64>::uninit();
26+
unsafe {
27+
set_value(foo.as_mut_ptr());
28+
}
29+
30+
if x {
31+
let l1 = unsafe { *foo.as_mut_ptr().cast::<Boolean>() };
32+
if matches!(l1, Boolean::False) {
33+
unsafe {
34+
*foo.as_mut_ptr() = 0;
35+
}
36+
}
37+
}
38+
39+
let l2 = unsafe { *foo.as_mut_ptr() };
40+
if l2 == 2 {
41+
// CHECK: call void @bar
42+
bar();
43+
}
44+
}
45+
46+
#[no_mangle]
47+
#[inline(never)]
48+
pub fn bar() {
49+
println!("Working correctly!");
50+
}

0 commit comments

Comments
 (0)