/src/test/run-make-fulldeps/intrinsic-unreachable/exit-unreachable.rs

https://gitlab.com/jianglu/rust · Rust · 27 lines · 11 code · 3 blank · 13 comment · 0 complexity · 94ae176b2a8fd9d1cbe3b689ed0eaad4 MD5 · raw file

  1. // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
  2. // file at the top-level directory of this distribution and at
  3. // http://rust-lang.org/COPYRIGHT.
  4. //
  5. // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
  6. // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
  7. // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
  8. // option. This file may not be copied, modified, or distributed
  9. // except according to those terms.
  10. #![feature(asm, core_intrinsics)]
  11. #![crate_type="lib"]
  12. use std::intrinsics;
  13. #[allow(unreachable_code)]
  14. pub fn exit(n: usize) -> i32 {
  15. unsafe {
  16. // Pretend this asm is an exit() syscall.
  17. asm!("" :: "r"(n) :: "volatile");
  18. intrinsics::unreachable()
  19. }
  20. // This return value is just here to generate some extra code for a return
  21. // value, making it easier for the test script to detect whether the
  22. // compiler deleted it.
  23. 42
  24. }