-
Notifications
You must be signed in to change notification settings - Fork 13.6k
first stage of implementing LLVM code coverage #73011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
a6127e3
d139a72
395256a
5068ae1
088037a
2c5c2a6
d2cd59a
e4df7e7
7e49a9e
46ebd57
20aba8f
163e585
98685a4
1db44af
c338729
b9f0304
36c9014
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Addresses feedback from @oli-obk (Thanks!)
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -389,6 +389,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { | |||||
); | ||||||
self.copy_op(self.operand_index(args[0], index)?, dest)?; | ||||||
} | ||||||
// FIXME(#73156): Handle source code coverage in const eval | ||||||
sym::count_code_region => (), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please always ping @rust-lang/wg-const-eval for new intrinsics in CTFE. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, note that as per this comment, T-lang should have been involved as well: rust/src/libcore/intrinsics.rs Lines 8 to 9 in 394e1b4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. amusingly this intrinsic is not marked as const at all. The static checks preventing non-const intrinsics from being invoked happen before mir optimizations. Since instrumentation is a MIR transformation... this isn't caught. Maybe instrumentation should happen before const checking and such? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, so this intrinsic is not called by users, but the call is inserted by an instrumentation pass later? Interesting. That reduces my T-lang concern.
Maybe -- I am not sure to what extend it would be useful to check the instrumented code as if it was user-written. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I write const fn a() -> u8 {
42
}
const A: u8 = a();
fn main() {
println!("{}", A);
} Then currently There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't see that issue, thanks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry about that @RalfJung! That was my fault; I didn't realize we should be pinging that group. I will try to keep that in mind in the future. Do you think we still need to get the lang team involved? This intrinsic is used by an unstable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I doubt they will have any objections, but sending T-lang an "FYI this is what we did here" would still be a good idea I think. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for flagging the issue @RalfJung ... Note also, the next PR increment is under review, and adds some additional Rust intrinsics that I believe we need for coverage map generation. See this related note: Since the MIR analysis is minimal at the moment (injecting at the function level only) I'm not generating calls to these intrinsics yet, but when I do, I suspect I may need to add these new intrinsics to src/librustc_mir/interpret/intrinsics.rs as well, similarly stubbed out. |
||||||
_ => return Ok(false), | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Test that the initial version of Rust coverage injects count_code_region() placeholder calls, | ||
// at the top of each function. The placeholders are later converted into LLVM instrprof.increment | ||
// intrinsics, during codegen. | ||
|
||
// compile-flags: -Zinstrument-coverage | ||
// EMIT_MIR rustc.main.InstrumentCoverage.diff | ||
// EMIT_MIR rustc.bar.InstrumentCoverage.diff | ||
fn main() { | ||
loop { | ||
if bar() { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
#[inline(never)] | ||
fn bar() -> bool { | ||
true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
- // MIR for `bar` before InstrumentCoverage | ||
+ // MIR for `bar` after InstrumentCoverage | ||
|
||
fn bar() -> bool { | ||
let mut _0: bool; // return place in scope 0 at $DIR/instrument_coverage.rs:17:13: 17:17 | ||
+ let mut _1: (); // in scope 0 at $DIR/instrument_coverage.rs:17:1: 19:2 | ||
|
||
bb0: { | ||
+ StorageLive(_1); // scope 0 at $DIR/instrument_coverage.rs:17:1: 19:2 | ||
+ _1 = const std::intrinsics::count_code_region(const 0u32) -> bb2; // scope 0 at $DIR/instrument_coverage.rs:17:1: 19:2 | ||
+ // ty::Const | ||
+ // + ty: unsafe extern "rust-intrinsic" fn(u32) {std::intrinsics::count_code_region} | ||
+ // + val: Value(Scalar(<ZST>)) | ||
+ // mir::Constant | ||
+ // + span: $DIR/instrument_coverage.rs:17:1: 17:1 | ||
+ // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(u32) {std::intrinsics::count_code_region}, val: Value(Scalar(<ZST>)) } | ||
+ // ty::Const | ||
+ // + ty: u32 | ||
+ // + val: Value(Scalar(0x00000000)) | ||
+ // mir::Constant | ||
+ // + span: $DIR/instrument_coverage.rs:17:1: 17:1 | ||
+ // + literal: Const { ty: u32, val: Value(Scalar(0x00000000)) } | ||
+ } | ||
+ | ||
+ bb1 (cleanup): { | ||
+ resume; // scope 0 at $DIR/instrument_coverage.rs:17:1: 19:2 | ||
+ } | ||
+ | ||
+ bb2: { | ||
+ StorageDead(_1); // scope 0 at $DIR/instrument_coverage.rs:18:5: 18:9 | ||
_0 = const true; // scope 0 at $DIR/instrument_coverage.rs:18:5: 18:9 | ||
// ty::Const | ||
// + ty: bool | ||
// + val: Value(Scalar(0x01)) | ||
// mir::Constant | ||
// + span: $DIR/instrument_coverage.rs:18:5: 18:9 | ||
// + literal: Const { ty: bool, val: Value(Scalar(0x01)) } | ||
return; // scope 0 at $DIR/instrument_coverage.rs:19:2: 19:2 | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
- // MIR for `main` before InstrumentCoverage | ||
+ // MIR for `main` after InstrumentCoverage | ||
|
||
fn main() -> () { | ||
let mut _0: (); // return place in scope 0 at $DIR/instrument_coverage.rs:8:11: 8:11 | ||
let mut _1: (); // in scope 0 at $DIR/instrument_coverage.rs:8:1: 14:2 | ||
let mut _2: bool; // in scope 0 at $DIR/instrument_coverage.rs:10:12: 10:17 | ||
let mut _3: !; // in scope 0 at $DIR/instrument_coverage.rs:10:18: 12:10 | ||
+ let mut _4: (); // in scope 0 at $DIR/instrument_coverage.rs:8:1: 14:2 | ||
|
||
bb0: { | ||
- falseUnwind -> [real: bb1, cleanup: bb6]; // scope 0 at $DIR/instrument_coverage.rs:9:5: 13:6 | ||
+ StorageLive(_4); // scope 0 at $DIR/instrument_coverage.rs:8:1: 14:2 | ||
+ _4 = const std::intrinsics::count_code_region(const 0u32) -> bb7; // scope 0 at $DIR/instrument_coverage.rs:8:1: 14:2 | ||
+ // ty::Const | ||
+ // + ty: unsafe extern "rust-intrinsic" fn(u32) {std::intrinsics::count_code_region} | ||
+ // + val: Value(Scalar(<ZST>)) | ||
+ // mir::Constant | ||
+ // + span: $DIR/instrument_coverage.rs:8:1: 8:1 | ||
+ // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(u32) {std::intrinsics::count_code_region}, val: Value(Scalar(<ZST>)) } | ||
+ // ty::Const | ||
+ // + ty: u32 | ||
+ // + val: Value(Scalar(0x00000000)) | ||
+ // mir::Constant | ||
+ // + span: $DIR/instrument_coverage.rs:8:1: 8:1 | ||
+ // + literal: Const { ty: u32, val: Value(Scalar(0x00000000)) } | ||
} | ||
|
||
bb1: { | ||
StorageLive(_2); // scope 0 at $DIR/instrument_coverage.rs:10:12: 10:17 | ||
_2 = const bar() -> [return: bb2, unwind: bb6]; // scope 0 at $DIR/instrument_coverage.rs:10:12: 10:17 | ||
// ty::Const | ||
// + ty: fn() -> bool {bar} | ||
// + val: Value(Scalar(<ZST>)) | ||
// mir::Constant | ||
// + span: $DIR/instrument_coverage.rs:10:12: 10:15 | ||
// + literal: Const { ty: fn() -> bool {bar}, val: Value(Scalar(<ZST>)) } | ||
} | ||
|
||
bb2: { | ||
FakeRead(ForMatchedPlace, _2); // scope 0 at $DIR/instrument_coverage.rs:10:12: 10:17 | ||
switchInt(_2) -> [false: bb4, otherwise: bb3]; // scope 0 at $DIR/instrument_coverage.rs:10:9: 12:10 | ||
} | ||
|
||
bb3: { | ||
falseEdges -> [real: bb5, imaginary: bb4]; // scope 0 at $DIR/instrument_coverage.rs:10:9: 12:10 | ||
} | ||
|
||
bb4: { | ||
_1 = const (); // scope 0 at $DIR/instrument_coverage.rs:10:9: 12:10 | ||
// ty::Const | ||
// + ty: () | ||
// + val: Value(Scalar(<ZST>)) | ||
// mir::Constant | ||
// + span: $DIR/instrument_coverage.rs:10:9: 12:10 | ||
// + literal: Const { ty: (), val: Value(Scalar(<ZST>)) } | ||
StorageDead(_2); // scope 0 at $DIR/instrument_coverage.rs:13:5: 13:6 | ||
goto -> bb0; // scope 0 at $DIR/instrument_coverage.rs:9:5: 13:6 | ||
} | ||
|
||
bb5: { | ||
_0 = const (); // scope 0 at $DIR/instrument_coverage.rs:11:13: 11:18 | ||
// ty::Const | ||
// + ty: () | ||
// + val: Value(Scalar(<ZST>)) | ||
// mir::Constant | ||
// + span: $DIR/instrument_coverage.rs:11:13: 11:18 | ||
// + literal: Const { ty: (), val: Value(Scalar(<ZST>)) } | ||
StorageDead(_2); // scope 0 at $DIR/instrument_coverage.rs:13:5: 13:6 | ||
return; // scope 0 at $DIR/instrument_coverage.rs:14:2: 14:2 | ||
} | ||
|
||
bb6 (cleanup): { | ||
resume; // scope 0 at $DIR/instrument_coverage.rs:8:1: 14:2 | ||
+ } | ||
+ | ||
+ bb7: { | ||
+ StorageDead(_4); // scope 0 at $DIR/instrument_coverage.rs:9:5: 13:6 | ||
+ falseUnwind -> [real: bb1, cleanup: bb6]; // scope 0 at $DIR/instrument_coverage.rs:9:5: 13:6 | ||
} | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.