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

Bump LLVM for DeadArgElim fix #78253

Merged
merged 1 commit into from
Oct 25, 2020
Merged
Show file tree
Hide file tree
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
29 changes: 29 additions & 0 deletions src/test/ui/auxiliary/issue-76387.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// compile-flags: -C opt-level=3

pub struct FatPtr {
ptr: *mut u8,
len: usize,
}

impl FatPtr {
pub fn new(len: usize) -> FatPtr {
let ptr = Box::into_raw(vec![42u8; len].into_boxed_slice()) as *mut u8;

FatPtr { ptr, len }
}
}

impl std::ops::Deref for FatPtr {
type Target = [u8];

#[inline]
fn deref(&self) -> &[u8] {
unsafe { std::slice::from_raw_parts(self.ptr, self.len) }
}
}

impl std::ops::Drop for FatPtr {
fn drop(&mut self) {
println!("Drop");
}
}
22 changes: 22 additions & 0 deletions src/test/ui/issue-76387-llvm-miscompile.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// no-system-llvm
// compile-flags: -C opt-level=3
// aux-build: issue-76387.rs
// run-pass

// Regression test for issue #76387
// Tests that LLVM doesn't miscompile this

extern crate issue_76387;

use issue_76387::FatPtr;

fn print(data: &[u8]) {
println!("{:#?}", data);
}

fn main() {
let ptr = FatPtr::new(20);
let data = unsafe { std::slice::from_raw_parts(ptr.as_ptr(), ptr.len()) };

print(data);
}