1 #![feature(core_intrinsics)]
3 pub fn __llvm_incr_counter(_region_loc: &str) {
7 pub fn __incr_cov<T>(region_loc: &str, result: T) -> T {
8 __llvm_incr_counter(region_loc);
12 static TEST_FUNC_NAME: &'static [u8; 6] = b"main()";
15 let mut countdown = 10;
16 if __incr_cov("start", countdown > 0) {
19 // // TEST CALLING INTRINSIC:
20 unsafe { core::intrinsics::instrprof_increment(TEST_FUNC_NAME as *const u8, 1234 as u64, 314 as u32, 31 as u32) };
22 // // LLVM ERROR: Cannot select: intrinsic %llvm.instrprof.increment
23 // // I may need to pass one or more of the following flags (or equivalent opts) to LLVM to enable this:
24 // // -fprofile-instr-generate -fcoverage-mapping
28 __incr_cov("if block",());
29 } else if countdown > 5 {
31 __incr_cov("else if block",());
36 let mut countdown = 10;
37 if { let _tcov = countdown > 0; __llvm_incr_counter("start", ); _tcov } {
39 __incr_cov("if block",());
40 } else if countdown > 5 {
42 __incr_cov("else if block",());
48 // NOTE: hir REDUNDANTLY lowers the manually inlined counter in the second if block to:
53 // let _tcov = countdown > 0;
54 // __llvm_incr_counter("start");
60 // I don't know if optimization phases will fix this or not.
61 // Otherwise, a more optimal (but definitely special case) way to handle this would be
62 // to inject the counter between the hir-introduced temp `_t` assignment and the block result
63 // line returning `_t`:
66 // let _t = countdown > 0;
67 // __llvm_incr_counter("start"); // <-- the only thing inserted for coverage here
71 // UNFORTUNATELY THIS IS NOT A PATTERN WE CAN ALWAYS LEVERAGE, FOR EXPRESSIONS THAT HAVE VALUES
72 // WHERE WE NEED TO INJECT THE COUNTER AFTER THE EXPRESSION BUT BEFORE IT IS USED.
74 // IT DOES APPEAR TO BE THE CASE FOR WHILE EXPRESSIONS, (BECOMES loop { match { let _t = condition; _t} { true => {...} _ => break, }})
75 // AND IS TRUE FOR IF EXPRESSIONS AS NOTED
76 // BUT NOT FOR RETURN STATEMENT (and I'm guessing not for loop { break value; } ? )
78 // AND NOT FOR LAZY BOOLEAN EXPRESSIONS!
80 // AND NOT FOR MATCH EXPRESSIONS IN THE ORIGINAL SOURCE!