|  | 
|  | 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. | 
|  | 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 | + | 
|  | 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. | 
|  | 16 | + | 
|  | 17 | +// As opposed to the panic_exprs.rs test case, this test case checks that things | 
|  | 18 | +// behave as expected when overflow checks are off: | 
|  | 19 | +// | 
|  | 20 | +// - Addition, subtraction, and multiplication do not change the ICH, unless | 
|  | 21 | +//   the function containing them is marked with rustc_inherit_overflow_checks. | 
|  | 22 | +// - Division by zero and bounds checks always influence the ICH | 
|  | 23 | + | 
|  | 24 | +// The general pattern followed here is: Change one thing between rev1 and rev2 | 
|  | 25 | +// and make sure that the hash has changed, then change nothing between rev2 and | 
|  | 26 | +// rev3 and make sure that the hash has not changed. | 
|  | 27 | + | 
|  | 28 | +// must-compile-successfully | 
|  | 29 | +// revisions: cfail1 cfail2 cfail3 | 
|  | 30 | +// compile-flags: -Z query-dep-graph -Z force-overflow-checks=off | 
|  | 31 | + | 
|  | 32 | +#![allow(warnings)] | 
|  | 33 | +#![feature(rustc_attrs)] | 
|  | 34 | +#![crate_type="rlib"] | 
|  | 35 | + | 
|  | 36 | + | 
|  | 37 | +// Indexing expression --------------------------------------------------------- | 
|  | 38 | +#[cfg(cfail1)] | 
|  | 39 | +pub fn indexing(slice: &[u8]) -> u8 { | 
|  | 40 | +    slice[100] | 
|  | 41 | +} | 
|  | 42 | + | 
|  | 43 | +#[cfg(not(cfail1))] | 
|  | 44 | +#[rustc_dirty(label="Hir", cfg="cfail2")] | 
|  | 45 | +#[rustc_clean(label="Hir", cfg="cfail3")] | 
|  | 46 | +#[rustc_metadata_dirty(cfg="cfail2")] | 
|  | 47 | +#[rustc_metadata_clean(cfg="cfail3")] | 
|  | 48 | +pub fn indexing(slice: &[u8]) -> u8 { | 
|  | 49 | +    slice[100] | 
|  | 50 | +} | 
|  | 51 | + | 
|  | 52 | + | 
|  | 53 | +// Arithmetic overflow plus ---------------------------------------------------- | 
|  | 54 | +#[cfg(cfail1)] | 
|  | 55 | +#[rustc_inherit_overflow_checks] | 
|  | 56 | +pub fn arithmetic_overflow_plus_inherit(val: i32) -> i32 { | 
|  | 57 | +    val + 1 | 
|  | 58 | +} | 
|  | 59 | + | 
|  | 60 | +#[cfg(not(cfail1))] | 
|  | 61 | +#[rustc_dirty(label="Hir", cfg="cfail2")] | 
|  | 62 | +#[rustc_clean(label="Hir", cfg="cfail3")] | 
|  | 63 | +#[rustc_metadata_dirty(cfg="cfail2")] | 
|  | 64 | +#[rustc_metadata_clean(cfg="cfail3")] | 
|  | 65 | +#[rustc_inherit_overflow_checks] | 
|  | 66 | +pub fn arithmetic_overflow_plus_inherit(val: i32) -> i32 { | 
|  | 67 | +    val + 1 | 
|  | 68 | +} | 
|  | 69 | + | 
|  | 70 | + | 
|  | 71 | +// Arithmetic overflow minus ---------------------------------------------------- | 
|  | 72 | +#[cfg(cfail1)] | 
|  | 73 | +#[rustc_inherit_overflow_checks] | 
|  | 74 | +pub fn arithmetic_overflow_minus_inherit(val: i32) -> i32 { | 
|  | 75 | +    val - 1 | 
|  | 76 | +} | 
|  | 77 | + | 
|  | 78 | +#[cfg(not(cfail1))] | 
|  | 79 | +#[rustc_dirty(label="Hir", cfg="cfail2")] | 
|  | 80 | +#[rustc_clean(label="Hir", cfg="cfail3")] | 
|  | 81 | +#[rustc_metadata_dirty(cfg="cfail2")] | 
|  | 82 | +#[rustc_metadata_clean(cfg="cfail3")] | 
|  | 83 | +#[rustc_inherit_overflow_checks] | 
|  | 84 | +pub fn arithmetic_overflow_minus_inherit(val: i32) -> i32 { | 
|  | 85 | +    val - 1 | 
|  | 86 | +} | 
|  | 87 | + | 
|  | 88 | + | 
|  | 89 | +// Arithmetic overflow mult ---------------------------------------------------- | 
|  | 90 | +#[cfg(cfail1)] | 
|  | 91 | +#[rustc_inherit_overflow_checks] | 
|  | 92 | +pub fn arithmetic_overflow_mult_inherit(val: i32) -> i32 { | 
|  | 93 | +    val * 2 | 
|  | 94 | +} | 
|  | 95 | + | 
|  | 96 | +#[cfg(not(cfail1))] | 
|  | 97 | +#[rustc_dirty(label="Hir", cfg="cfail2")] | 
|  | 98 | +#[rustc_clean(label="Hir", cfg="cfail3")] | 
|  | 99 | +#[rustc_metadata_dirty(cfg="cfail2")] | 
|  | 100 | +#[rustc_metadata_clean(cfg="cfail3")] | 
|  | 101 | +#[rustc_inherit_overflow_checks] | 
|  | 102 | +pub fn arithmetic_overflow_mult_inherit(val: i32) -> i32 { | 
|  | 103 | +    val * 2 | 
|  | 104 | +} | 
|  | 105 | + | 
|  | 106 | + | 
|  | 107 | +// Arithmetic overflow negation ------------------------------------------------ | 
|  | 108 | +#[cfg(cfail1)] | 
|  | 109 | +#[rustc_inherit_overflow_checks] | 
|  | 110 | +pub fn arithmetic_overflow_negation_inherit(val: i32) -> i32 { | 
|  | 111 | +    -val | 
|  | 112 | +} | 
|  | 113 | + | 
|  | 114 | +#[cfg(not(cfail1))] | 
|  | 115 | +#[rustc_dirty(label="Hir", cfg="cfail2")] | 
|  | 116 | +#[rustc_clean(label="Hir", cfg="cfail3")] | 
|  | 117 | +#[rustc_metadata_dirty(cfg="cfail2")] | 
|  | 118 | +#[rustc_metadata_clean(cfg="cfail3")] | 
|  | 119 | +#[rustc_inherit_overflow_checks] | 
|  | 120 | +pub fn arithmetic_overflow_negation_inherit(val: i32) -> i32 { | 
|  | 121 | +    -val | 
|  | 122 | +} | 
|  | 123 | + | 
|  | 124 | + | 
|  | 125 | +// Division by zero ------------------------------------------------------------ | 
|  | 126 | +#[cfg(cfail1)] | 
|  | 127 | +pub fn division_by_zero(val: i32) -> i32 { | 
|  | 128 | +    2 / val | 
|  | 129 | +} | 
|  | 130 | + | 
|  | 131 | +#[cfg(not(cfail1))] | 
|  | 132 | +#[rustc_dirty(label="Hir", cfg="cfail2")] | 
|  | 133 | +#[rustc_clean(label="Hir", cfg="cfail3")] | 
|  | 134 | +#[rustc_metadata_dirty(cfg="cfail2")] | 
|  | 135 | +#[rustc_metadata_clean(cfg="cfail3")] | 
|  | 136 | +pub fn division_by_zero(val: i32) -> i32 { | 
|  | 137 | +    2 / val | 
|  | 138 | +} | 
|  | 139 | + | 
|  | 140 | +// Division by zero ------------------------------------------------------------ | 
|  | 141 | +#[cfg(cfail1)] | 
|  | 142 | +pub fn mod_by_zero(val: i32) -> i32 { | 
|  | 143 | +    2 % val | 
|  | 144 | +} | 
|  | 145 | + | 
|  | 146 | +#[cfg(not(cfail1))] | 
|  | 147 | +#[rustc_dirty(label="Hir", cfg="cfail2")] | 
|  | 148 | +#[rustc_clean(label="Hir", cfg="cfail3")] | 
|  | 149 | +#[rustc_metadata_dirty(cfg="cfail2")] | 
|  | 150 | +#[rustc_metadata_clean(cfg="cfail3")] | 
|  | 151 | +pub fn mod_by_zero(val: i32) -> i32 { | 
|  | 152 | +    2 % val | 
|  | 153 | +} | 
|  | 154 | + | 
|  | 155 | + | 
|  | 156 | + | 
|  | 157 | +// THE FOLLOWING ITEMS SHOULD NOT BE INFLUENCED BY THEIR SOURCE LOCATION | 
|  | 158 | + | 
|  | 159 | +// bitwise --------------------------------------------------------------------- | 
|  | 160 | +#[cfg(cfail1)] | 
|  | 161 | +pub fn bitwise(val: i32) -> i32 { | 
|  | 162 | +    !val & 0x101010101 | 0x45689 ^ 0x2372382 << 1 >> 1 | 
|  | 163 | +} | 
|  | 164 | + | 
|  | 165 | +#[cfg(not(cfail1))] | 
|  | 166 | +#[rustc_clean(label="Hir", cfg="cfail2")] | 
|  | 167 | +#[rustc_clean(label="Hir", cfg="cfail3")] | 
|  | 168 | +#[rustc_metadata_clean(cfg="cfail2")] | 
|  | 169 | +#[rustc_metadata_clean(cfg="cfail3")] | 
|  | 170 | +pub fn bitwise(val: i32) -> i32 { | 
|  | 171 | +    !val & 0x101010101 | 0x45689 ^ 0x2372382 << 1 >> 1 | 
|  | 172 | +} | 
|  | 173 | + | 
|  | 174 | + | 
|  | 175 | +// logical --------------------------------------------------------------------- | 
|  | 176 | +#[cfg(cfail1)] | 
|  | 177 | +pub fn logical(val1: bool, val2: bool, val3: bool) -> bool { | 
|  | 178 | +    val1 && val2 || val3 | 
|  | 179 | +} | 
|  | 180 | + | 
|  | 181 | +#[cfg(not(cfail1))] | 
|  | 182 | +#[rustc_clean(label="Hir", cfg="cfail2")] | 
|  | 183 | +#[rustc_clean(label="Hir", cfg="cfail3")] | 
|  | 184 | +#[rustc_metadata_clean(cfg="cfail2")] | 
|  | 185 | +#[rustc_metadata_clean(cfg="cfail3")] | 
|  | 186 | +pub fn logical(val1: bool, val2: bool, val3: bool) -> bool { | 
|  | 187 | +    val1 && val2 || val3 | 
|  | 188 | +} | 
|  | 189 | + | 
|  | 190 | +// Arithmetic overflow plus ---------------------------------------------------- | 
|  | 191 | +#[cfg(cfail1)] | 
|  | 192 | +pub fn arithmetic_overflow_plus(val: i32) -> i32 { | 
|  | 193 | +    val + 1 | 
|  | 194 | +} | 
|  | 195 | + | 
|  | 196 | +#[cfg(not(cfail1))] | 
|  | 197 | +#[rustc_clean(label="Hir", cfg="cfail2")] | 
|  | 198 | +#[rustc_clean(label="Hir", cfg="cfail3")] | 
|  | 199 | +#[rustc_metadata_clean(cfg="cfail2")] | 
|  | 200 | +#[rustc_metadata_clean(cfg="cfail3")] | 
|  | 201 | +pub fn arithmetic_overflow_plus(val: i32) -> i32 { | 
|  | 202 | +    val + 1 | 
|  | 203 | +} | 
|  | 204 | + | 
|  | 205 | + | 
|  | 206 | +// Arithmetic overflow minus ---------------------------------------------------- | 
|  | 207 | +#[cfg(cfail1)] | 
|  | 208 | +pub fn arithmetic_overflow_minus(val: i32) -> i32 { | 
|  | 209 | +    val - 1 | 
|  | 210 | +} | 
|  | 211 | + | 
|  | 212 | +#[cfg(not(cfail1))] | 
|  | 213 | +#[rustc_clean(label="Hir", cfg="cfail2")] | 
|  | 214 | +#[rustc_clean(label="Hir", cfg="cfail3")] | 
|  | 215 | +#[rustc_metadata_clean(cfg="cfail2")] | 
|  | 216 | +#[rustc_metadata_clean(cfg="cfail3")] | 
|  | 217 | +pub fn arithmetic_overflow_minus(val: i32) -> i32 { | 
|  | 218 | +    val - 1 | 
|  | 219 | +} | 
|  | 220 | + | 
|  | 221 | + | 
|  | 222 | +// Arithmetic overflow mult ---------------------------------------------------- | 
|  | 223 | +#[cfg(cfail1)] | 
|  | 224 | +pub fn arithmetic_overflow_mult(val: i32) -> i32 { | 
|  | 225 | +    val * 2 | 
|  | 226 | +} | 
|  | 227 | + | 
|  | 228 | +#[cfg(not(cfail1))] | 
|  | 229 | +#[rustc_clean(label="Hir", cfg="cfail2")] | 
|  | 230 | +#[rustc_clean(label="Hir", cfg="cfail3")] | 
|  | 231 | +#[rustc_metadata_clean(cfg="cfail2")] | 
|  | 232 | +#[rustc_metadata_clean(cfg="cfail3")] | 
|  | 233 | +pub fn arithmetic_overflow_mult(val: i32) -> i32 { | 
|  | 234 | +    val * 2 | 
|  | 235 | +} | 
|  | 236 | + | 
|  | 237 | + | 
|  | 238 | +// Arithmetic overflow negation ------------------------------------------------ | 
|  | 239 | +#[cfg(cfail1)] | 
|  | 240 | +pub fn arithmetic_overflow_negation(val: i32) -> i32 { | 
|  | 241 | +    -val | 
|  | 242 | +} | 
|  | 243 | + | 
|  | 244 | +#[cfg(not(cfail1))] | 
|  | 245 | +#[rustc_clean(label="Hir", cfg="cfail2")] | 
|  | 246 | +#[rustc_clean(label="Hir", cfg="cfail3")] | 
|  | 247 | +#[rustc_metadata_clean(cfg="cfail2")] | 
|  | 248 | +#[rustc_metadata_clean(cfg="cfail3")] | 
|  | 249 | +pub fn arithmetic_overflow_negation(val: i32) -> i32 { | 
|  | 250 | +    -val | 
|  | 251 | +} | 
0 commit comments