Skip to content

Commit

Permalink
Add tests for issues #82833 and #82859
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Mar 11, 2021
1 parent d9be71a commit ef269ac
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/test/ui/issues/issue-82833-slice-miscompile.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// run-pass
// compile-flags: -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Copt-level=0 -Cdebuginfo=2
// ignore-tidy-linelength

// Make sure LLVM does not miscompile this.

fn make_string(ch: char) -> String {
let mut bytes = [0u8; 4];
ch.encode_utf8(&mut bytes).into()
}

fn main() {
let ch = '😃';
dbg!(ch);
let string = make_string(ch);
dbg!(string);
}
19 changes: 19 additions & 0 deletions src/test/ui/issues/issue-82859-slice-miscompile.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// run-pass
// compile-flags: -Copt-level=0 -Cdebuginfo=2

// Make sure LLVM does not miscompile this.

fn indirect_get_slice() -> &'static [usize] {
&[]
}

#[inline(always)]
fn get_slice() -> &'static [usize] {
let ret = indirect_get_slice();
ret
}

fn main() {
let output = get_slice().len();
assert_eq!(output, 0);
}

0 comments on commit ef269ac

Please sign in to comment.