]> git.proxmox.com Git - rustc.git/blob - src/test/incremental/thinlto/cgu_invalidated_when_import_added.rs
New upstream version 1.43.0+dfsg1
[rustc.git] / src / test / incremental / thinlto / cgu_invalidated_when_import_added.rs
1 // revisions: cfail1 cfail2
2 // compile-flags: -O -Zhuman-readable-cgu-names -Cllvm-args=-import-instr-limit=10
3 // build-pass
4
5 // rust-lang/rust#59535:
6 //
7 // This is analogous to cgu_invalidated_when_import_removed.rs, but it covers
8 // the other direction:
9 //
10 // We start with a call-graph like `[A] -> [B -> D] [C]` (where the letters are
11 // functions and the modules are enclosed in `[]`), and add a new call `D <- C`,
12 // yielding the new call-graph: `[A] -> [B -> D] <- [C]`
13 //
14 // The effect of this is that the compiler previously classfied `D` as internal
15 // and the import-set of `[A]` to be just `B`. But after adding the `D <- C` call,
16 // `D` is no longer classified as internal, and the import-set of `[A]` becomes
17 // both `B` and `D`.
18 //
19 // We check this case because an early proposed pull request included an
20 // assertion that the import-sets monotonically decreased over time, a claim
21 // which this test case proves to be false.
22
23 fn main() {
24 foo::foo();
25 bar::baz();
26 }
27
28 mod foo {
29
30 // In cfail1, ThinLTO decides that foo() does not get inlined into main, and
31 // instead bar() gets inlined into foo().
32 // In cfail2, foo() gets inlined into main.
33 pub fn foo(){
34 bar()
35 }
36
37 // This function needs to be big so that it does not get inlined by ThinLTO
38 // but *does* get inlined into foo() when it is declared `internal` in
39 // cfail1 (alone).
40 pub fn bar(){
41 println!("quux1");
42 println!("quux2");
43 println!("quux3");
44 println!("quux4");
45 println!("quux5");
46 println!("quux6");
47 println!("quux7");
48 println!("quux8");
49 println!("quux9");
50 }
51 }
52
53 mod bar {
54
55 #[inline(never)]
56 pub fn baz() {
57 #[cfg(cfail2)]
58 {
59 crate::foo::bar();
60 }
61 }
62 }