Skip to content

Commit 1db44af

Browse files
committed
Ensure profiling runtime for -Zinstrument-coverage
If config.toml `profiler = false`, the test/mir-opt/instrument_coverage test is ignored. Otherwise, this patch ensures the profiler_runtime is loaded when -Zinstrument-coverage is enabled. Confirmed that this works for MacOS.
1 parent 98685a4 commit 1db44af

File tree

5 files changed

+44
-40
lines changed

5 files changed

+44
-40
lines changed

config.toml.example

+2-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@
209209
# Build the sanitizer runtimes
210210
#sanitizers = false
211211

212-
# Build the profiler runtime
212+
# Build the profiler runtime (required when compiling with options that depend
213+
# on this runtime, such as `-C profile-generate` or `-Z instrument-coverage`).
213214
#profiler = false
214215

215216
# Indicates whether the native libraries linked into Cargo will be statically

src/librustc_metadata/creader.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,9 @@ impl<'a> CrateLoader<'a> {
698698
}
699699

700700
fn inject_profiler_runtime(&mut self) {
701-
if (self.sess.opts.debugging_opts.profile || self.sess.opts.cg.profile_generate.enabled())
701+
if (self.sess.opts.debugging_opts.instrument_coverage
702+
|| self.sess.opts.debugging_opts.profile
703+
|| self.sess.opts.cg.profile_generate.enabled())
702704
&& !self.sess.opts.debugging_opts.no_profiler_runtime
703705
{
704706
info!("loading profiler");

src/test/mir-opt/instrument_coverage.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// at the top of each function. The placeholders are later converted into LLVM instrprof.increment
33
// intrinsics, during codegen.
44

5+
// needs-profiler-support
56
// compile-flags: -Zinstrument-coverage
67
// EMIT_MIR rustc.main.InstrumentCoverage.diff
78
// EMIT_MIR rustc.bar.InstrumentCoverage.diff

src/test/mir-opt/instrument_coverage/rustc.bar.InstrumentCoverage.diff

+11-11
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,40 @@
22
+ // MIR for `bar` after InstrumentCoverage
33

44
fn bar() -> bool {
5-
let mut _0: bool; // return place in scope 0 at $DIR/instrument_coverage.rs:17:13: 17:17
6-
+ let mut _1: (); // in scope 0 at $DIR/instrument_coverage.rs:17:1: 19:2
5+
let mut _0: bool; // return place in scope 0 at $DIR/instrument_coverage.rs:18:13: 18:17
6+
+ let mut _1: (); // in scope 0 at $DIR/instrument_coverage.rs:18:1: 20:2
77

88
bb0: {
9-
+ StorageLive(_1); // scope 0 at $DIR/instrument_coverage.rs:17:1: 19:2
10-
+ _1 = const std::intrinsics::count_code_region(const 0u32) -> bb2; // scope 0 at $DIR/instrument_coverage.rs:17:1: 19:2
9+
+ StorageLive(_1); // scope 0 at $DIR/instrument_coverage.rs:18:1: 20:2
10+
+ _1 = const std::intrinsics::count_code_region(const 0u32) -> bb2; // scope 0 at $DIR/instrument_coverage.rs:18:1: 20:2
1111
+ // ty::Const
1212
+ // + ty: unsafe extern "rust-intrinsic" fn(u32) {std::intrinsics::count_code_region}
1313
+ // + val: Value(Scalar(<ZST>))
1414
+ // mir::Constant
15-
+ // + span: $DIR/instrument_coverage.rs:17:1: 17:1
15+
+ // + span: $DIR/instrument_coverage.rs:18:1: 18:1
1616
+ // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(u32) {std::intrinsics::count_code_region}, val: Value(Scalar(<ZST>)) }
1717
+ // ty::Const
1818
+ // + ty: u32
1919
+ // + val: Value(Scalar(0x00000000))
2020
+ // mir::Constant
21-
+ // + span: $DIR/instrument_coverage.rs:17:1: 17:1
21+
+ // + span: $DIR/instrument_coverage.rs:18:1: 18:1
2222
+ // + literal: Const { ty: u32, val: Value(Scalar(0x00000000)) }
2323
+ }
2424
+
2525
+ bb1 (cleanup): {
26-
+ resume; // scope 0 at $DIR/instrument_coverage.rs:17:1: 19:2
26+
+ resume; // scope 0 at $DIR/instrument_coverage.rs:18:1: 20:2
2727
+ }
2828
+
2929
+ bb2: {
30-
+ StorageDead(_1); // scope 0 at $DIR/instrument_coverage.rs:18:5: 18:9
31-
_0 = const true; // scope 0 at $DIR/instrument_coverage.rs:18:5: 18:9
30+
+ StorageDead(_1); // scope 0 at $DIR/instrument_coverage.rs:19:5: 19:9
31+
_0 = const true; // scope 0 at $DIR/instrument_coverage.rs:19:5: 19:9
3232
// ty::Const
3333
// + ty: bool
3434
// + val: Value(Scalar(0x01))
3535
// mir::Constant
36-
// + span: $DIR/instrument_coverage.rs:18:5: 18:9
36+
// + span: $DIR/instrument_coverage.rs:19:5: 19:9
3737
// + literal: Const { ty: bool, val: Value(Scalar(0x01)) }
38-
return; // scope 0 at $DIR/instrument_coverage.rs:19:2: 19:2
38+
return; // scope 0 at $DIR/instrument_coverage.rs:20:2: 20:2
3939
}
4040
}
4141

src/test/mir-opt/instrument_coverage/rustc.main.InstrumentCoverage.diff

+27-27
Original file line numberDiff line numberDiff line change
@@ -2,81 +2,81 @@
22
+ // MIR for `main` after InstrumentCoverage
33

44
fn main() -> () {
5-
let mut _0: (); // return place in scope 0 at $DIR/instrument_coverage.rs:8:11: 8:11
6-
let mut _1: (); // in scope 0 at $DIR/instrument_coverage.rs:8:1: 14:2
7-
let mut _2: bool; // in scope 0 at $DIR/instrument_coverage.rs:10:12: 10:17
8-
let mut _3: !; // in scope 0 at $DIR/instrument_coverage.rs:10:18: 12:10
9-
+ let mut _4: (); // in scope 0 at $DIR/instrument_coverage.rs:8:1: 14:2
5+
let mut _0: (); // return place in scope 0 at $DIR/instrument_coverage.rs:9:11: 9:11
6+
let mut _1: (); // in scope 0 at $DIR/instrument_coverage.rs:9:1: 15:2
7+
let mut _2: bool; // in scope 0 at $DIR/instrument_coverage.rs:11:12: 11:17
8+
let mut _3: !; // in scope 0 at $DIR/instrument_coverage.rs:11:18: 13:10
9+
+ let mut _4: (); // in scope 0 at $DIR/instrument_coverage.rs:9:1: 15:2
1010

1111
bb0: {
12-
- falseUnwind -> [real: bb1, cleanup: bb2]; // scope 0 at $DIR/instrument_coverage.rs:9:5: 13:6
13-
+ StorageLive(_4); // scope 0 at $DIR/instrument_coverage.rs:8:1: 14:2
14-
+ _4 = const std::intrinsics::count_code_region(const 0u32) -> bb7; // scope 0 at $DIR/instrument_coverage.rs:8:1: 14:2
12+
- falseUnwind -> [real: bb1, cleanup: bb2]; // scope 0 at $DIR/instrument_coverage.rs:10:5: 14:6
13+
+ StorageLive(_4); // scope 0 at $DIR/instrument_coverage.rs:9:1: 15:2
14+
+ _4 = const std::intrinsics::count_code_region(const 0u32) -> bb7; // scope 0 at $DIR/instrument_coverage.rs:9:1: 15:2
1515
+ // ty::Const
1616
+ // + ty: unsafe extern "rust-intrinsic" fn(u32) {std::intrinsics::count_code_region}
1717
+ // + val: Value(Scalar(<ZST>))
1818
+ // mir::Constant
19-
+ // + span: $DIR/instrument_coverage.rs:8:1: 8:1
19+
+ // + span: $DIR/instrument_coverage.rs:9:1: 9:1
2020
+ // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(u32) {std::intrinsics::count_code_region}, val: Value(Scalar(<ZST>)) }
2121
+ // ty::Const
2222
+ // + ty: u32
2323
+ // + val: Value(Scalar(0x00000000))
2424
+ // mir::Constant
25-
+ // + span: $DIR/instrument_coverage.rs:8:1: 8:1
25+
+ // + span: $DIR/instrument_coverage.rs:9:1: 9:1
2626
+ // + literal: Const { ty: u32, val: Value(Scalar(0x00000000)) }
2727
}
2828

2929
bb1: {
30-
StorageLive(_2); // scope 0 at $DIR/instrument_coverage.rs:10:12: 10:17
31-
_2 = const bar() -> [return: bb3, unwind: bb2]; // scope 0 at $DIR/instrument_coverage.rs:10:12: 10:17
30+
StorageLive(_2); // scope 0 at $DIR/instrument_coverage.rs:11:12: 11:17
31+
_2 = const bar() -> [return: bb3, unwind: bb2]; // scope 0 at $DIR/instrument_coverage.rs:11:12: 11:17
3232
// ty::Const
3333
// + ty: fn() -> bool {bar}
3434
// + val: Value(Scalar(<ZST>))
3535
// mir::Constant
36-
// + span: $DIR/instrument_coverage.rs:10:12: 10:15
36+
// + span: $DIR/instrument_coverage.rs:11:12: 11:15
3737
// + literal: Const { ty: fn() -> bool {bar}, val: Value(Scalar(<ZST>)) }
3838
}
3939

4040
bb2 (cleanup): {
41-
resume; // scope 0 at $DIR/instrument_coverage.rs:8:1: 14:2
41+
resume; // scope 0 at $DIR/instrument_coverage.rs:9:1: 15:2
4242
}
4343

4444
bb3: {
45-
FakeRead(ForMatchedPlace, _2); // scope 0 at $DIR/instrument_coverage.rs:10:12: 10:17
46-
switchInt(_2) -> [false: bb5, otherwise: bb4]; // scope 0 at $DIR/instrument_coverage.rs:10:9: 12:10
45+
FakeRead(ForMatchedPlace, _2); // scope 0 at $DIR/instrument_coverage.rs:11:12: 11:17
46+
switchInt(_2) -> [false: bb5, otherwise: bb4]; // scope 0 at $DIR/instrument_coverage.rs:11:9: 13:10
4747
}
4848

4949
bb4: {
50-
falseEdge -> [real: bb6, imaginary: bb5]; // scope 0 at $DIR/instrument_coverage.rs:10:9: 12:10
50+
falseEdge -> [real: bb6, imaginary: bb5]; // scope 0 at $DIR/instrument_coverage.rs:11:9: 13:10
5151
}
5252

5353
bb5: {
54-
_1 = const (); // scope 0 at $DIR/instrument_coverage.rs:10:9: 12:10
54+
_1 = const (); // scope 0 at $DIR/instrument_coverage.rs:11:9: 13:10
5555
// ty::Const
5656
// + ty: ()
5757
// + val: Value(Scalar(<ZST>))
5858
// mir::Constant
59-
// + span: $DIR/instrument_coverage.rs:10:9: 12:10
59+
// + span: $DIR/instrument_coverage.rs:11:9: 13:10
6060
// + literal: Const { ty: (), val: Value(Scalar(<ZST>)) }
61-
StorageDead(_2); // scope 0 at $DIR/instrument_coverage.rs:13:5: 13:6
62-
goto -> bb0; // scope 0 at $DIR/instrument_coverage.rs:9:5: 13:6
61+
StorageDead(_2); // scope 0 at $DIR/instrument_coverage.rs:14:5: 14:6
62+
goto -> bb0; // scope 0 at $DIR/instrument_coverage.rs:10:5: 14:6
6363
}
6464

6565
bb6: {
66-
_0 = const (); // scope 0 at $DIR/instrument_coverage.rs:11:13: 11:18
66+
_0 = const (); // scope 0 at $DIR/instrument_coverage.rs:12:13: 12:18
6767
// ty::Const
6868
// + ty: ()
6969
// + val: Value(Scalar(<ZST>))
7070
// mir::Constant
71-
// + span: $DIR/instrument_coverage.rs:11:13: 11:18
71+
// + span: $DIR/instrument_coverage.rs:12:13: 12:18
7272
// + literal: Const { ty: (), val: Value(Scalar(<ZST>)) }
73-
StorageDead(_2); // scope 0 at $DIR/instrument_coverage.rs:13:5: 13:6
74-
return; // scope 0 at $DIR/instrument_coverage.rs:14:2: 14:2
73+
StorageDead(_2); // scope 0 at $DIR/instrument_coverage.rs:14:5: 14:6
74+
return; // scope 0 at $DIR/instrument_coverage.rs:15:2: 15:2
7575
+ }
7676
+
7777
+ bb7: {
78-
+ StorageDead(_4); // scope 0 at $DIR/instrument_coverage.rs:9:5: 13:6
79-
+ falseUnwind -> [real: bb1, cleanup: bb2]; // scope 0 at $DIR/instrument_coverage.rs:9:5: 13:6
78+
+ StorageDead(_4); // scope 0 at $DIR/instrument_coverage.rs:10:5: 14:6
79+
+ falseUnwind -> [real: bb1, cleanup: bb2]; // scope 0 at $DIR/instrument_coverage.rs:10:5: 14:6
8080
}
8181
}
8282

0 commit comments

Comments
 (0)