forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinvalid_const_promotion.rs
60 lines (48 loc) · 1.41 KB
/
invalid_const_promotion.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// run-pass
#![allow(unused_mut)]
// ignore-wasm32
// ignore-emscripten
// ignore-sgx no processes
// compile-flags: -C debug_assertions=yes
#![stable(feature = "rustc", since = "1.0.0")]
#![feature(const_fn, rustc_private, staged_api, rustc_attrs)]
#![allow(const_err)]
extern crate libc;
use std::env;
use std::process::{Command, Stdio};
// this will panic in debug mode and overflow in release mode
//
// NB we give bar an unused argument because otherwise memoization
// of the const fn kicks in, causing a different code path in the
// compiler to be executed (see PR #66294).
#[stable(feature = "rustc", since = "1.0.0")]
#[rustc_promotable]
const fn bar(_: bool) -> usize { 0 - 1 }
fn foo() {
let _: &'static _ = &bar(true);
}
#[cfg(unix)]
fn check_status(status: std::process::ExitStatus)
{
use std::os::unix::process::ExitStatusExt;
assert!(status.signal() == Some(libc::SIGILL)
|| status.signal() == Some(libc::SIGTRAP)
|| status.signal() == Some(libc::SIGABRT));
}
#[cfg(not(unix))]
fn check_status(status: std::process::ExitStatus)
{
assert!(!status.success());
}
fn main() {
let args: Vec<String> = env::args().collect();
if args.len() > 1 && args[1] == "test" {
foo();
return;
}
let mut p = Command::new(&args[0])
.stdout(Stdio::piped())
.stdin(Stdio::piped())
.arg("test").output().unwrap();
check_status(p.status);
}