Skip to content

Commit cad9b6b

Browse files
committed
Apply review feedback
1 parent 26d260b commit cad9b6b

File tree

3 files changed

+94
-78
lines changed

3 files changed

+94
-78
lines changed

compiler/rustc_codegen_llvm/src/back/write.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,11 @@ pub(crate) unsafe fn optimize(
549549
continue;
550550
}
551551
if pass_name == "insert-gcov-profiling" || pass_name == "instrprof" {
552-
// Instrumentation should be inserted before optimization.
552+
// Instrumentation must be inserted before optimization,
553+
// otherwise LLVM may optimize some functions away which
554+
// breaks llvm-cov.
555+
//
556+
// This mirrors what Clang does in lib/CodeGen/BackendUtil.cpp.
553557
llvm::LLVMRustAddPass(mpm, find_pass(pass_name).unwrap());
554558
continue;
555559
}

src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.uses_inline_crate.txt

+83-77
Original file line numberDiff line numberDiff line change
@@ -31,103 +31,109 @@
3131
29| 1| use_this_lib_crate();
3232
30| 1|}
3333
31| |
34-
32| |#[inline(always)]
35-
33| 2|pub fn used_only_from_bin_crate_generic_function<T: Debug>(arg: T) {
36-
34| 2| println!("used_only_from_bin_crate_generic_function with {:?}", arg);
37-
35| 2|}
34+
32| |
35+
33| |
36+
34| |
37+
35| |
38+
36| |
39+
37| |
40+
38| |#[inline(always)]
41+
39| 2|pub fn used_only_from_bin_crate_generic_function<T: Debug>(arg: T) {
42+
40| 2| println!("used_only_from_bin_crate_generic_function with {:?}", arg);
43+
41| 2|}
3844
------------------
3945
| used_inline_crate::used_only_from_bin_crate_generic_function::<&alloc::vec::Vec<i32>>:
40-
| 33| 1|pub fn used_only_from_bin_crate_generic_function<T: Debug>(arg: T) {
41-
| 34| 1| println!("used_only_from_bin_crate_generic_function with {:?}", arg);
42-
| 35| 1|}
46+
| 39| 1|pub fn used_only_from_bin_crate_generic_function<T: Debug>(arg: T) {
47+
| 40| 1| println!("used_only_from_bin_crate_generic_function with {:?}", arg);
48+
| 41| 1|}
4349
------------------
4450
| used_inline_crate::used_only_from_bin_crate_generic_function::<&str>:
45-
| 33| 1|pub fn used_only_from_bin_crate_generic_function<T: Debug>(arg: T) {
46-
| 34| 1| println!("used_only_from_bin_crate_generic_function with {:?}", arg);
47-
| 35| 1|}
51+
| 39| 1|pub fn used_only_from_bin_crate_generic_function<T: Debug>(arg: T) {
52+
| 40| 1| println!("used_only_from_bin_crate_generic_function with {:?}", arg);
53+
| 41| 1|}
4854
------------------
4955
| Unexecuted instantiation: used_inline_crate::used_only_from_bin_crate_generic_function::<_>
5056
------------------
51-
36| |// Expect for above function: `Unexecuted instantiation` (see notes in `used_crate.rs`)
52-
37| |
53-
38| |#[inline(always)]
54-
39| 4|pub fn used_only_from_this_lib_crate_generic_function<T: Debug>(arg: T) {
55-
40| 4| println!("used_only_from_this_lib_crate_generic_function with {:?}", arg);
56-
41| 4|}
57+
42| |// Expect for above function: `Unexecuted instantiation` (see notes in `used_crate.rs`)
58+
43| |
59+
44| |#[inline(always)]
60+
45| 4|pub fn used_only_from_this_lib_crate_generic_function<T: Debug>(arg: T) {
61+
46| 4| println!("used_only_from_this_lib_crate_generic_function with {:?}", arg);
62+
47| 4|}
5763
------------------
5864
| used_inline_crate::used_only_from_this_lib_crate_generic_function::<alloc::vec::Vec<i32>>:
59-
| 39| 2|pub fn used_only_from_this_lib_crate_generic_function<T: Debug>(arg: T) {
60-
| 40| 2| println!("used_only_from_this_lib_crate_generic_function with {:?}", arg);
61-
| 41| 2|}
65+
| 45| 2|pub fn used_only_from_this_lib_crate_generic_function<T: Debug>(arg: T) {
66+
| 46| 2| println!("used_only_from_this_lib_crate_generic_function with {:?}", arg);
67+
| 47| 2|}
6268
------------------
6369
| used_inline_crate::used_only_from_this_lib_crate_generic_function::<&str>:
64-
| 39| 2|pub fn used_only_from_this_lib_crate_generic_function<T: Debug>(arg: T) {
65-
| 40| 2| println!("used_only_from_this_lib_crate_generic_function with {:?}", arg);
66-
| 41| 2|}
70+
| 45| 2|pub fn used_only_from_this_lib_crate_generic_function<T: Debug>(arg: T) {
71+
| 46| 2| println!("used_only_from_this_lib_crate_generic_function with {:?}", arg);
72+
| 47| 2|}
6773
------------------
68-
42| |
69-
43| |#[inline(always)]
70-
44| 3|pub fn used_from_bin_crate_and_lib_crate_generic_function<T: Debug>(arg: T) {
71-
45| 3| println!("used_from_bin_crate_and_lib_crate_generic_function with {:?}", arg);
72-
46| 3|}
74+
48| |
75+
49| |#[inline(always)]
76+
50| 3|pub fn used_from_bin_crate_and_lib_crate_generic_function<T: Debug>(arg: T) {
77+
51| 3| println!("used_from_bin_crate_and_lib_crate_generic_function with {:?}", arg);
78+
52| 3|}
7379
------------------
7480
| used_inline_crate::used_from_bin_crate_and_lib_crate_generic_function::<alloc::vec::Vec<i32>>:
75-
| 44| 1|pub fn used_from_bin_crate_and_lib_crate_generic_function<T: Debug>(arg: T) {
76-
| 45| 1| println!("used_from_bin_crate_and_lib_crate_generic_function with {:?}", arg);
77-
| 46| 1|}
81+
| 50| 1|pub fn used_from_bin_crate_and_lib_crate_generic_function<T: Debug>(arg: T) {
82+
| 51| 1| println!("used_from_bin_crate_and_lib_crate_generic_function with {:?}", arg);
83+
| 52| 1|}
7884
------------------
7985
| used_inline_crate::used_from_bin_crate_and_lib_crate_generic_function::<&str>:
80-
| 44| 2|pub fn used_from_bin_crate_and_lib_crate_generic_function<T: Debug>(arg: T) {
81-
| 45| 2| println!("used_from_bin_crate_and_lib_crate_generic_function with {:?}", arg);
82-
| 46| 2|}
86+
| 50| 2|pub fn used_from_bin_crate_and_lib_crate_generic_function<T: Debug>(arg: T) {
87+
| 51| 2| println!("used_from_bin_crate_and_lib_crate_generic_function with {:?}", arg);
88+
| 52| 2|}
8389
------------------
84-
47| |
85-
48| |#[inline(always)]
86-
49| 3|pub fn used_with_same_type_from_bin_crate_and_lib_crate_generic_function<T: Debug>(arg: T) {
87-
50| 3| println!("used_with_same_type_from_bin_crate_and_lib_crate_generic_function with {:?}", arg);
88-
51| 3|}
90+
53| |
91+
54| |#[inline(always)]
92+
55| 3|pub fn used_with_same_type_from_bin_crate_and_lib_crate_generic_function<T: Debug>(arg: T) {
93+
56| 3| println!("used_with_same_type_from_bin_crate_and_lib_crate_generic_function with {:?}", arg);
94+
57| 3|}
8995
------------------
9096
| used_inline_crate::used_with_same_type_from_bin_crate_and_lib_crate_generic_function::<&str>:
91-
| 49| 1|pub fn used_with_same_type_from_bin_crate_and_lib_crate_generic_function<T: Debug>(arg: T) {
92-
| 50| 1| println!("used_with_same_type_from_bin_crate_and_lib_crate_generic_function with {:?}", arg);
93-
| 51| 1|}
97+
| 55| 1|pub fn used_with_same_type_from_bin_crate_and_lib_crate_generic_function<T: Debug>(arg: T) {
98+
| 56| 1| println!("used_with_same_type_from_bin_crate_and_lib_crate_generic_function with {:?}", arg);
99+
| 57| 1|}
94100
------------------
95101
| used_inline_crate::used_with_same_type_from_bin_crate_and_lib_crate_generic_function::<&str>:
96-
| 49| 2|pub fn used_with_same_type_from_bin_crate_and_lib_crate_generic_function<T: Debug>(arg: T) {
97-
| 50| 2| println!("used_with_same_type_from_bin_crate_and_lib_crate_generic_function with {:?}", arg);
98-
| 51| 2|}
102+
| 55| 2|pub fn used_with_same_type_from_bin_crate_and_lib_crate_generic_function<T: Debug>(arg: T) {
103+
| 56| 2| println!("used_with_same_type_from_bin_crate_and_lib_crate_generic_function with {:?}", arg);
104+
| 57| 2|}
99105
------------------
100-
52| |
101-
53| |#[inline(always)]
102-
54| 0|pub fn unused_generic_function<T: Debug>(arg: T) {
103-
55| 0| println!("unused_generic_function with {:?}", arg);
104-
56| 0|}
105-
57| |
106-
58| |#[inline(always)]
107-
59| 0|pub fn unused_function() {
108-
60| 0| let is_true = std::env::args().len() == 1;
109-
61| 0| let mut countdown = 2;
110-
62| 0| if !is_true {
111-
63| 0| countdown = 20;
112-
64| 0| }
113-
65| 0|}
114-
66| |
115-
67| |#[inline(always)]
116-
68| 0|fn unused_private_function() {
117-
69| 0| let is_true = std::env::args().len() == 1;
118-
70| 0| let mut countdown = 2;
119-
71| 0| if !is_true {
120-
72| 0| countdown = 20;
121-
73| 0| }
122-
74| 0|}
123-
75| |
124-
76| 2|fn use_this_lib_crate() {
125-
77| 2| used_from_bin_crate_and_lib_crate_generic_function("used from library used_crate.rs");
126-
78| 2| used_with_same_type_from_bin_crate_and_lib_crate_generic_function(
127-
79| 2| "used from library used_crate.rs",
128-
80| 2| );
129-
81| 2| let some_vec = vec![5, 6, 7, 8];
130-
82| 2| used_only_from_this_lib_crate_generic_function(some_vec);
131-
83| 2| used_only_from_this_lib_crate_generic_function("used ONLY from library used_crate.rs");
132-
84| 2|}
106+
58| |
107+
59| |#[inline(always)]
108+
60| 0|pub fn unused_generic_function<T: Debug>(arg: T) {
109+
61| 0| println!("unused_generic_function with {:?}", arg);
110+
62| 0|}
111+
63| |
112+
64| |#[inline(always)]
113+
65| 0|pub fn unused_function() {
114+
66| 0| let is_true = std::env::args().len() == 1;
115+
67| 0| let mut countdown = 2;
116+
68| 0| if !is_true {
117+
69| 0| countdown = 20;
118+
70| 0| }
119+
71| 0|}
120+
72| |
121+
73| |#[inline(always)]
122+
74| 0|fn unused_private_function() {
123+
75| 0| let is_true = std::env::args().len() == 1;
124+
76| 0| let mut countdown = 2;
125+
77| 0| if !is_true {
126+
78| 0| countdown = 20;
127+
79| 0| }
128+
80| 0|}
129+
81| |
130+
82| 2|fn use_this_lib_crate() {
131+
83| 2| used_from_bin_crate_and_lib_crate_generic_function("used from library used_crate.rs");
132+
84| 2| used_with_same_type_from_bin_crate_and_lib_crate_generic_function(
133+
85| 2| "used from library used_crate.rs",
134+
86| 2| );
135+
87| 2| let some_vec = vec![5, 6, 7, 8];
136+
88| 2| used_only_from_this_lib_crate_generic_function(some_vec);
137+
89| 2| used_only_from_this_lib_crate_generic_function("used ONLY from library used_crate.rs");
138+
90| 2|}
133139

src/test/run-make-fulldeps/coverage/lib/used_inline_crate.rs

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ pub fn used_inline_function() {
2929
use_this_lib_crate();
3030
}
3131

32+
33+
34+
35+
36+
37+
3238
#[inline(always)]
3339
pub fn used_only_from_bin_crate_generic_function<T: Debug>(arg: T) {
3440
println!("used_only_from_bin_crate_generic_function with {:?}", arg);

0 commit comments

Comments
 (0)