]> git.proxmox.com Git - rustc.git/blame - src/test/incremental/hashes/panic_exprs.rs
New upstream version 1.34.2+dfsg1
[rustc.git] / src / test / incremental / hashes / panic_exprs.rs
CommitLineData
c30ab7b3 1// This test case tests the incremental compilation hash (ICH) implementation
0731742a 2// for exprs that can panic at runtime (e.g., because of bounds checking). For
c30ab7b3
SL
3// these expressions an error message containing their source location is
4// generated, so their hash must always depend on their location in the source
5// code, not just when debuginfo is enabled.
6
7// The general pattern followed here is: Change one thing between rev1 and rev2
8// and make sure that the hash has changed, then change nothing between rev2 and
9// rev3 and make sure that the hash has not changed.
10
83c7162d 11// compile-pass
c30ab7b3
SL
12// revisions: cfail1 cfail2 cfail3
13// compile-flags: -Z query-dep-graph -C debug-assertions
14
15#![allow(warnings)]
16#![feature(rustc_attrs)]
17#![crate_type="rlib"]
18
19
20// Indexing expression ---------------------------------------------------------
9fa01778 21#[rustc_clean(cfg="cfail2", except="HirBody,MirBuilt,MirOptimized")]
abe05a73 22#[rustc_clean(cfg="cfail3")]
c30ab7b3 23pub fn indexing(slice: &[u8]) -> u8 {
ff7c6d11
XL
24 #[cfg(cfail1)]
25 {
26 slice[100]
27 }
28 #[cfg(not(cfail1))]
29 {
30 slice[100]
31 }
c30ab7b3
SL
32}
33
34
35// Arithmetic overflow plus ----------------------------------------------------
9fa01778 36#[rustc_clean(cfg="cfail2", except="HirBody,MirBuilt,MirOptimized")]
abe05a73 37#[rustc_clean(cfg="cfail3")]
c30ab7b3 38pub fn arithmetic_overflow_plus(val: i32) -> i32 {
ff7c6d11
XL
39 #[cfg(cfail1)]
40 {
41 val + 1
42 }
43 #[cfg(not(cfail1))]
44 {
45 val + 1
46 }
c30ab7b3
SL
47}
48
49
50// Arithmetic overflow minus ----------------------------------------------------
9fa01778 51#[rustc_clean(cfg="cfail2", except="HirBody,MirBuilt,MirOptimized")]
abe05a73 52#[rustc_clean(cfg="cfail3")]
c30ab7b3 53pub fn arithmetic_overflow_minus(val: i32) -> i32 {
ff7c6d11
XL
54 #[cfg(cfail1)]
55 {
56 val - 1
57 }
58 #[cfg(not(cfail1))]
59 {
60 val - 1
61 }
c30ab7b3
SL
62}
63
64
65// Arithmetic overflow mult ----------------------------------------------------
9fa01778 66#[rustc_clean(cfg="cfail2", except="HirBody,MirBuilt,MirOptimized")]
abe05a73 67#[rustc_clean(cfg="cfail3")]
c30ab7b3 68pub fn arithmetic_overflow_mult(val: i32) -> i32 {
ff7c6d11
XL
69 #[cfg(cfail1)]
70 {
71 val * 2
72 }
73 #[cfg(not(cfail1))]
74 {
75 val * 2
76 }
c30ab7b3
SL
77}
78
79
80// Arithmetic overflow negation ------------------------------------------------
9fa01778 81#[rustc_clean(cfg="cfail2", except="HirBody,MirBuilt,MirOptimized")]
abe05a73 82#[rustc_clean(cfg="cfail3")]
c30ab7b3 83pub fn arithmetic_overflow_negation(val: i32) -> i32 {
ff7c6d11
XL
84 #[cfg(cfail1)]
85 {
86 -val
87 }
88 #[cfg(not(cfail1))]
89 {
90 -val
91 }
c30ab7b3
SL
92}
93
94
95// Division by zero ------------------------------------------------------------
9fa01778 96#[rustc_clean(cfg="cfail2", except="HirBody,MirBuilt,MirOptimized")]
abe05a73 97#[rustc_clean(cfg="cfail3")]
c30ab7b3 98pub fn division_by_zero(val: i32) -> i32 {
ff7c6d11
XL
99 #[cfg(cfail1)]
100 {
101 2 / val
102 }
103 #[cfg(not(cfail1))]
104 {
105 2 / val
106 }
c30ab7b3
SL
107}
108
109// Division by zero ------------------------------------------------------------
9fa01778 110#[rustc_clean(cfg="cfail2", except="HirBody,MirBuilt,MirOptimized")]
abe05a73 111#[rustc_clean(cfg="cfail3")]
c30ab7b3 112pub fn mod_by_zero(val: i32) -> i32 {
ff7c6d11
XL
113 #[cfg(cfail1)]
114 {
115 2 % val
116 }
117 #[cfg(not(cfail1))]
118 {
119 2 % val
120 }
c30ab7b3
SL
121}
122
123
abe05a73 124// shift left ------------------------------------------------------------------
9fa01778 125#[rustc_clean(cfg="cfail2", except="HirBody,MirBuilt,MirOptimized")]
abe05a73 126#[rustc_clean(cfg="cfail3")]
abe05a73 127pub fn shift_left(val: i32, shift: usize) -> i32 {
ff7c6d11
XL
128 #[cfg(cfail1)]
129 {
130 val << shift
131 }
132 #[cfg(not(cfail1))]
133 {
134 val << shift
135 }
abe05a73
XL
136}
137
138
139// shift right ------------------------------------------------------------------
9fa01778 140#[rustc_clean(cfg="cfail2", except="HirBody,MirBuilt,MirOptimized")]
abe05a73 141#[rustc_clean(cfg="cfail3")]
abe05a73 142pub fn shift_right(val: i32, shift: usize) -> i32 {
ff7c6d11
XL
143 #[cfg(cfail1)]
144 {
145 val >> shift
146 }
147 #[cfg(not(cfail1))]
148 {
149 val >> shift
150 }
c30ab7b3 151}