]> git.lizzy.rs Git - rust.git/blob - tests/codegen/issue-45222.rs
Rollup merge of #107769 - compiler-errors:pointer-like, r=eholk
[rust.git] / tests / codegen / issue-45222.rs
1 // compile-flags: -O
2 // ignore-debug: the debug assertions get in the way
3
4 #![crate_type = "lib"]
5
6 // verify that LLVM recognizes a loop involving 0..=n and will const-fold it.
7
8 // Example from original issue #45222
9
10 fn foo2(n: u64) -> u64 {
11     let mut count = 0;
12     for _ in 0..n {
13         for j in (0..=n).rev() {
14             count += j;
15         }
16     }
17     count
18 }
19
20 // CHECK-LABEL: @check_foo2
21 #[no_mangle]
22 pub fn check_foo2() -> u64 {
23     // CHECK: ret i64 500005000000000
24     foo2(100000)
25 }
26
27 // Simplified example of #45222
28 //
29 // Temporarily disabled in #68835 to fix a soundness hole.
30 //
31 // fn triangle_inc(n: u64) -> u64 {
32 //     let mut count = 0;
33 //     for j in 0 ..= n {
34 //         count += j;
35 //     }
36 //     count
37 // }
38 //
39 // // COMMENTEDCHECK-LABEL: @check_triangle_inc
40 // #[no_mangle]
41 // pub fn check_triangle_inc() -> u64 {
42 //     // COMMENTEDCHECK: ret i64 5000050000
43 //     triangle_inc(100000)
44 // }
45
46 // Demo in #48012
47
48 fn foo3r(n: u64) -> u64 {
49     let mut count = 0;
50     (0..n).for_each(|_| {
51         (0..=n).rev().for_each(|j| {
52             count += j;
53         })
54     });
55     count
56 }
57
58 // CHECK-LABEL: @check_foo3r
59 #[no_mangle]
60 pub fn check_foo3r() -> u64 {
61     // CHECK: ret i64 500050000000
62     foo3r(10000)
63 }