1 // Copyright 2016 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.
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.
11 // This test case tests the incremental compilation hash (ICH) implementation
12 // for exprs that can panic at runtime (e.g. because of bounds checking). For
13 // these expressions an error message containing their source location is
14 // generated, so their hash must always depend on their location in the source
15 // code, not just when debuginfo is enabled.
17 // The general pattern followed here is: Change one thing between rev1 and rev2
18 // and make sure that the hash has changed, then change nothing between rev2 and
19 // rev3 and make sure that the hash has not changed.
21 // must-compile-successfully
22 // revisions: cfail1 cfail2 cfail3
23 // compile-flags: -Z query-dep-graph -C debug-assertions
26 #![feature(rustc_attrs)]
30 // Indexing expression ---------------------------------------------------------
32 pub fn indexing(slice: &[u8]) -> u8 {
37 #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized")]
38 #[rustc_clean(cfg="cfail3")]
39 pub fn indexing(slice: &[u8]) -> u8 {
44 // Arithmetic overflow plus ----------------------------------------------------
46 pub fn arithmetic_overflow_plus(val: i32) -> i32 {
51 #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized")]
52 #[rustc_clean(cfg="cfail3")]
53 pub fn arithmetic_overflow_plus(val: i32) -> i32 {
58 // Arithmetic overflow minus ----------------------------------------------------
60 pub fn arithmetic_overflow_minus(val: i32) -> i32 {
65 #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized")]
66 #[rustc_clean(cfg="cfail3")]
67 pub fn arithmetic_overflow_minus(val: i32) -> i32 {
72 // Arithmetic overflow mult ----------------------------------------------------
74 pub fn arithmetic_overflow_mult(val: i32) -> i32 {
79 #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized")]
80 #[rustc_clean(cfg="cfail3")]
81 pub fn arithmetic_overflow_mult(val: i32) -> i32 {
86 // Arithmetic overflow negation ------------------------------------------------
88 pub fn arithmetic_overflow_negation(val: i32) -> i32 {
93 #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized")]
94 #[rustc_clean(cfg="cfail3")]
95 pub fn arithmetic_overflow_negation(val: i32) -> i32 {
100 // Division by zero ------------------------------------------------------------
102 pub fn division_by_zero(val: i32) -> i32 {
107 #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized")]
108 #[rustc_clean(cfg="cfail3")]
109 pub fn division_by_zero(val: i32) -> i32 {
113 // Division by zero ------------------------------------------------------------
115 pub fn mod_by_zero(val: i32) -> i32 {
120 #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized")]
121 #[rustc_clean(cfg="cfail3")]
122 pub fn mod_by_zero(val: i32) -> i32 {
127 // shift left ------------------------------------------------------------------
129 pub fn shift_left(val: i32, shift: usize) -> i32 {
134 #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized")]
135 #[rustc_clean(cfg="cfail3")]
136 pub fn shift_left(val: i32, shift: usize) -> i32 {
141 // shift right ------------------------------------------------------------------
143 pub fn shift_right(val: i32, shift: usize) -> i32 {
148 #[rustc_clean(cfg="cfail2", except="HirBody,MirValidated,MirOptimized")]
149 #[rustc_clean(cfg="cfail3")]
150 pub fn shift_right(val: i32, shift: usize) -> i32 {
155 // THE FOLLOWING ITEMS SHOULD NOT BE INFLUENCED BY THEIR SOURCE LOCATION
157 // bitwise ---------------------------------------------------------------------
159 pub fn bitwise(val: i32) -> i32 {
160 !val & 0x101010101 | 0x45689 ^ 0x2372382
164 #[rustc_clean(cfg="cfail2")]
165 #[rustc_clean(cfg="cfail3")]
166 pub fn bitwise(val: i32) -> i32 {
167 !val & 0x101010101 | 0x45689 ^ 0x2372382
171 // logical ---------------------------------------------------------------------
173 pub fn logical(val1: bool, val2: bool, val3: bool) -> bool {
178 #[rustc_clean(cfg="cfail2")]
179 #[rustc_clean(cfg="cfail3")]
180 pub fn logical(val1: bool, val2: bool, val3: bool) -> bool {