Skip to content

Commit

Permalink
Update the "[run-make] run-make/intrinsic-unreachable" test.
Browse files Browse the repository at this point in the history
With rustc now emitting "ud2" on unreachable code, a "return nothing"
sequence may take the same number of lines as an "unreachable" sequence
in assembly code. This test is testing that intrinsics::unreachable()
works by testing that it reduces the number of lines in the assembly
code. Fix it by adding a return value, which requires an extra
instruction in the reachable case, which provides the test what it's
looking for.
  • Loading branch information
sunfishcode committed Nov 10, 2017
1 parent 89652d6 commit 626d93b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/test/run-make/intrinsic-unreachable/exit-ret.rs
Expand Up @@ -11,10 +11,12 @@
#![feature(asm)]
#![crate_type="lib"]

pub fn exit(n: usize) {
#[deny(unreachable_code)]
pub fn exit(n: usize) -> i32 {
unsafe {
// Pretend this asm is an exit() syscall.
asm!("" :: "r"(n) :: "volatile");
// Can't actually reach this point, but rustc doesn't know that.
}
42
}
4 changes: 3 additions & 1 deletion src/test/run-make/intrinsic-unreachable/exit-unreachable.rs
Expand Up @@ -13,10 +13,12 @@

use std::intrinsics;

pub fn exit(n: usize) -> ! {
#[allow(unreachable_code)]
pub fn exit(n: usize) -> i32 {
unsafe {
// Pretend this asm is an exit() syscall.
asm!("" :: "r"(n) :: "volatile");
intrinsics::unreachable()
}
42
}

0 comments on commit 626d93b

Please sign in to comment.