[PATCH] D95987: [llvm-cov] Reset ExecutionCount only if first line segment is start of a new region.
Zequan Wu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 4 17:14:00 PST 2021
zequanwu added a comment.
In D95987#2541091 <https://reviews.llvm.org/D95987#2541091>, @pirama wrote:
> Thanks for the patch Zequan. This fixes the C++ test case that prompted this issue.
>
> The underlying Rust issue is not fixed though:
>
> 1| |fn notatest() -> Result<(), std::env::VarError> {
> 2| 1| let result = std::env::var("MEOW")
> 3| 0| .or(Ok("a".to_string()))?;
> 4| 1| println!("{}", result);
> 5| 1| Ok(())
> 6| 1|}
> 7| |
> 8| 1|fn main() {
> 9| 1| println!("Hello, world! {:?}", notatest());
> 10| 1|}
>
> Here're the regions from `-debug-only=coverage-mapping`:
>
> Segment at 2:13 (count = 1), RegionEntry
> Segment at 2:19 (count = 0), Skipped
> Segment at 2:22 (count = 1), RegionEntry
> Segment at 3:45 (count = 0), RegionEntry
> Segment at 3:46 (count = 0), Skipped
> Segment at 4:13 (count = 1), RegionEntry
> Segment at 5:23 (count = 0), Skipped
> Segment at 6:1 (count = 1), RegionEntry
> Segment at 6:2 (count = 0), Skipped
> Segment at 8:11 (count = 1), RegionEntry
> Segment at 10:2 (count = 0), Skipped
>
> The ternary operator case in the C++ test case has a gap region corresponding to the `?`. For the Rust `?` operator, there is no similar gap region. In fact, the rust frontend associates the counter corresponding to the error path of the `?` operator to the `?` token . Is there a better sequence of Segments that the Rust frontend can emit to handle this case?
Sorry, I don't know about Rust. I just read the `?` operator doc on https://doc.rust-lang.org/edition-guide/rust-2018/error-handling-and-panics/the-question-mark-operator-for-easier-error-handling.html.
For the example you provided, I am not sure if it's a bug or not. `Segment at 3:45 (count = 0), RegionEntry` corresponds to the error path of the `?` operator, which means error path is not executed. So, the 0 count looks reasonable. If we mark line 3 as executed regardless of which path is chosen, we may lost the information of path choices.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D95987/new/
https://reviews.llvm.org/D95987
More information about the llvm-commits
mailing list