2016-10-31 15:37:13 -05:00
|
|
|
// This test case tests the incremental compilation hash (ICH) implementation
|
2018-11-26 20:59:49 -06:00
|
|
|
// for exprs that can panic at runtime (e.g., because of bounds checking). For
|
2016-10-31 15:37:13 -05:00
|
|
|
// these expressions an error message containing their source location is
|
|
|
|
// generated, so their hash must always depend on their location in the source
|
|
|
|
// code, not just when debuginfo is enabled.
|
|
|
|
|
|
|
|
// The general pattern followed here is: Change one thing between rev1 and rev2
|
|
|
|
// and make sure that the hash has changed, then change nothing between rev2 and
|
|
|
|
// rev3 and make sure that the hash has not changed.
|
|
|
|
|
2018-04-02 06:20:06 -05:00
|
|
|
// compile-pass
|
2016-10-31 15:37:13 -05:00
|
|
|
// revisions: cfail1 cfail2 cfail3
|
|
|
|
// compile-flags: -Z query-dep-graph -C debug-assertions
|
|
|
|
|
|
|
|
#![allow(warnings)]
|
|
|
|
#![feature(rustc_attrs)]
|
|
|
|
#![crate_type="rlib"]
|
|
|
|
|
|
|
|
|
|
|
|
// Indexing expression ---------------------------------------------------------
|
2019-03-20 10:06:09 -05:00
|
|
|
#[rustc_clean(cfg="cfail2", except="HirBody,mir_built,optimized_mir")]
|
2017-11-12 16:57:43 -06:00
|
|
|
#[rustc_clean(cfg="cfail3")]
|
2016-10-31 15:37:13 -05:00
|
|
|
pub fn indexing(slice: &[u8]) -> u8 {
|
2017-12-04 05:47:16 -06:00
|
|
|
#[cfg(cfail1)]
|
|
|
|
{
|
|
|
|
slice[100]
|
|
|
|
}
|
|
|
|
#[cfg(not(cfail1))]
|
|
|
|
{
|
|
|
|
slice[100]
|
|
|
|
}
|
2016-10-31 15:37:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Arithmetic overflow plus ----------------------------------------------------
|
2019-03-20 10:06:09 -05:00
|
|
|
#[rustc_clean(cfg="cfail2", except="HirBody,mir_built,optimized_mir")]
|
2017-11-12 16:57:43 -06:00
|
|
|
#[rustc_clean(cfg="cfail3")]
|
2016-10-31 15:37:13 -05:00
|
|
|
pub fn arithmetic_overflow_plus(val: i32) -> i32 {
|
2017-12-04 05:47:16 -06:00
|
|
|
#[cfg(cfail1)]
|
|
|
|
{
|
|
|
|
val + 1
|
|
|
|
}
|
|
|
|
#[cfg(not(cfail1))]
|
|
|
|
{
|
|
|
|
val + 1
|
|
|
|
}
|
2016-10-31 15:37:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Arithmetic overflow minus ----------------------------------------------------
|
2019-03-20 10:06:09 -05:00
|
|
|
#[rustc_clean(cfg="cfail2", except="HirBody,mir_built,optimized_mir")]
|
2017-11-12 16:57:43 -06:00
|
|
|
#[rustc_clean(cfg="cfail3")]
|
2016-10-31 15:37:13 -05:00
|
|
|
pub fn arithmetic_overflow_minus(val: i32) -> i32 {
|
2017-12-04 05:47:16 -06:00
|
|
|
#[cfg(cfail1)]
|
|
|
|
{
|
|
|
|
val - 1
|
|
|
|
}
|
|
|
|
#[cfg(not(cfail1))]
|
|
|
|
{
|
|
|
|
val - 1
|
|
|
|
}
|
2016-10-31 15:37:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Arithmetic overflow mult ----------------------------------------------------
|
2019-03-20 10:06:09 -05:00
|
|
|
#[rustc_clean(cfg="cfail2", except="HirBody,mir_built,optimized_mir")]
|
2017-11-12 16:57:43 -06:00
|
|
|
#[rustc_clean(cfg="cfail3")]
|
2016-10-31 15:37:13 -05:00
|
|
|
pub fn arithmetic_overflow_mult(val: i32) -> i32 {
|
2017-12-04 05:47:16 -06:00
|
|
|
#[cfg(cfail1)]
|
|
|
|
{
|
|
|
|
val * 2
|
|
|
|
}
|
|
|
|
#[cfg(not(cfail1))]
|
|
|
|
{
|
|
|
|
val * 2
|
|
|
|
}
|
2016-10-31 15:37:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Arithmetic overflow negation ------------------------------------------------
|
2019-03-20 10:06:09 -05:00
|
|
|
#[rustc_clean(cfg="cfail2", except="HirBody,mir_built,optimized_mir")]
|
2017-11-12 16:57:43 -06:00
|
|
|
#[rustc_clean(cfg="cfail3")]
|
2016-10-31 15:37:13 -05:00
|
|
|
pub fn arithmetic_overflow_negation(val: i32) -> i32 {
|
2017-12-04 05:47:16 -06:00
|
|
|
#[cfg(cfail1)]
|
|
|
|
{
|
|
|
|
-val
|
|
|
|
}
|
|
|
|
#[cfg(not(cfail1))]
|
|
|
|
{
|
|
|
|
-val
|
|
|
|
}
|
2016-10-31 15:37:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Division by zero ------------------------------------------------------------
|
2019-03-20 10:06:09 -05:00
|
|
|
#[rustc_clean(cfg="cfail2", except="HirBody,mir_built,optimized_mir")]
|
2017-11-12 16:57:43 -06:00
|
|
|
#[rustc_clean(cfg="cfail3")]
|
2016-10-31 15:37:13 -05:00
|
|
|
pub fn division_by_zero(val: i32) -> i32 {
|
2017-12-04 05:47:16 -06:00
|
|
|
#[cfg(cfail1)]
|
|
|
|
{
|
|
|
|
2 / val
|
|
|
|
}
|
|
|
|
#[cfg(not(cfail1))]
|
|
|
|
{
|
|
|
|
2 / val
|
|
|
|
}
|
2016-10-31 15:37:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Division by zero ------------------------------------------------------------
|
2019-03-20 10:06:09 -05:00
|
|
|
#[rustc_clean(cfg="cfail2", except="HirBody,mir_built,optimized_mir")]
|
2017-11-12 16:57:43 -06:00
|
|
|
#[rustc_clean(cfg="cfail3")]
|
2016-10-31 15:37:13 -05:00
|
|
|
pub fn mod_by_zero(val: i32) -> i32 {
|
2017-12-04 05:47:16 -06:00
|
|
|
#[cfg(cfail1)]
|
|
|
|
{
|
|
|
|
2 % val
|
|
|
|
}
|
|
|
|
#[cfg(not(cfail1))]
|
|
|
|
{
|
|
|
|
2 % val
|
|
|
|
}
|
2016-10-31 15:37:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-07 08:49:51 -06:00
|
|
|
// shift left ------------------------------------------------------------------
|
2019-03-20 10:06:09 -05:00
|
|
|
#[rustc_clean(cfg="cfail2", except="HirBody,mir_built,optimized_mir")]
|
2017-11-12 16:57:43 -06:00
|
|
|
#[rustc_clean(cfg="cfail3")]
|
2017-11-07 08:49:51 -06:00
|
|
|
pub fn shift_left(val: i32, shift: usize) -> i32 {
|
2017-12-04 05:47:16 -06:00
|
|
|
#[cfg(cfail1)]
|
|
|
|
{
|
|
|
|
val << shift
|
|
|
|
}
|
|
|
|
#[cfg(not(cfail1))]
|
|
|
|
{
|
|
|
|
val << shift
|
|
|
|
}
|
2017-11-07 08:49:51 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// shift right ------------------------------------------------------------------
|
2019-03-20 10:06:09 -05:00
|
|
|
#[rustc_clean(cfg="cfail2", except="HirBody,mir_built,optimized_mir")]
|
2017-11-12 16:57:43 -06:00
|
|
|
#[rustc_clean(cfg="cfail3")]
|
2017-11-07 08:49:51 -06:00
|
|
|
pub fn shift_right(val: i32, shift: usize) -> i32 {
|
2017-12-04 05:47:16 -06:00
|
|
|
#[cfg(cfail1)]
|
|
|
|
{
|
|
|
|
val >> shift
|
|
|
|
}
|
|
|
|
#[cfg(not(cfail1))]
|
|
|
|
{
|
|
|
|
val >> shift
|
|
|
|
}
|
2016-10-31 15:37:13 -05:00
|
|
|
}
|