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.
|
|
|
|
|
2019-07-02 16:30:28 -05:00
|
|
|
//@ build-pass (FIXME(62277): could be check-pass?)
|
2016-10-31 15:37:13 -05:00
|
|
|
//@ revisions: cfail1 cfail2 cfail3
|
2022-05-27 20:17:39 -05:00
|
|
|
//@ compile-flags: -Z query-dep-graph -C debug-assertions -O
|
2016-10-31 15:37:13 -05:00
|
|
|
|
|
|
|
#![allow(warnings)]
|
|
|
|
#![feature(rustc_attrs)]
|
|
|
|
#![crate_type="rlib"]
|
|
|
|
|
|
|
|
|
2019-08-19 16:31:46 -05:00
|
|
|
// Indexing expression
|
2024-01-25 10:16:38 -06:00
|
|
|
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes,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
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-19 16:31:46 -05:00
|
|
|
// Arithmetic overflow plus
|
2024-01-25 10:16:38 -06:00
|
|
|
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes,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
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-19 16:31:46 -05:00
|
|
|
// Arithmetic overflow minus
|
2024-01-25 10:16:38 -06:00
|
|
|
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes,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
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-19 16:31:46 -05:00
|
|
|
// Arithmetic overflow mult
|
2024-01-25 10:16:38 -06:00
|
|
|
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes,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
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-19 16:31:46 -05:00
|
|
|
// Arithmetic overflow negation
|
2024-01-25 10:16:38 -06:00
|
|
|
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes,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
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-19 16:31:46 -05:00
|
|
|
// Division by zero
|
2024-01-25 10:16:38 -06:00
|
|
|
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes,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
|
|
|
}
|
|
|
|
|
2019-08-19 16:31:46 -05:00
|
|
|
// Division by zero
|
2024-01-25 10:16:38 -06:00
|
|
|
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes,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
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-19 16:31:46 -05:00
|
|
|
// shift left
|
2024-01-25 10:16:38 -06:00
|
|
|
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes,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
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-19 16:31:46 -05:00
|
|
|
// shift right
|
2024-01-25 10:16:38 -06:00
|
|
|
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes,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
|
|
|
}
|