Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add regression test for LLVM 17-rc3 miscompile #115591

Merged
merged 2 commits into from
Sep 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions tests/codegen/issues/issue-115385-llvm-jump-threading.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// compile-flags: -O -Ccodegen-units=1

#![crate_type = "lib"]

#[repr(i64)]
pub enum Boolean {
False = 0,
True = 1,
}

impl Clone for Boolean {
fn clone(&self) -> Self {
*self
}
}

impl Copy for Boolean {}

extern "C" {
fn set_value(foo: *mut i64);
fn bar();
}

pub fn foo(x: bool) {
let mut foo = core::mem::MaybeUninit::<i64>::uninit();
unsafe {
set_value(foo.as_mut_ptr());
}

if x {
let l1 = unsafe { *foo.as_mut_ptr().cast::<Boolean>() };
if matches!(l1, Boolean::False) {
unsafe {
*foo.as_mut_ptr() = 0;
}
}
}

let l2 = unsafe { *foo.as_mut_ptr() };
if l2 == 2 {
// CHECK: call void @bar
unsafe {
bar();
}
}
}