-
Notifications
You must be signed in to change notification settings - Fork 12.1k
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
[clang][CoverageMapping] do not emit gap when either end is an ImplicitValueInitExpr
#89564
Conversation
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-codegen Author: Wentao Zhang (whentojump) ChangesFixes #86998 Two compiler explorer examples: 1, 2 Cause:
Full diff: https://github.com/llvm/llvm-project/pull/89564.diff 1 Files Affected:
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 64c39c5de351c7..45296ff9cfb5e3 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1370,7 +1370,9 @@ struct CounterCoverageMappingBuilder
// If last statement contains terminate statements, add a gap area
// between the two statements. Skipping attributed statements, because
// they don't have valid start location.
- if (LastStmt && HasTerminateStmt && !isa<AttributedStmt>(Child)) {
+ if (LastStmt && HasTerminateStmt && !isa<AttributedStmt>(Child) &&
+ !isa<ImplicitValueInitExpr>(Child) &&
+ !isa<ImplicitValueInitExpr>(LastStmt)) {
auto Gap = findGapAreaBetween(getEnd(LastStmt), getStart(Child));
if (Gap)
fillGapAreaWithCount(Gap->getBegin(), Gap->getEnd(),
|
73e29e5
to
abbdb31
Compare
There could be some other statements with invalid source locations (we have seen that before). I suggest validating both source locations inside Also need a test case. You can add the crashed example as a test case under |
…n ImplicitValueInitExpr" This reverts commit abbdb31.
cc42595
to
c7359dd
Compare
Thanks for your suggestion! @ZequanWu Would you please take another look? |
Fwiw, I uncovered #86998 in the first place when I was compiling this file in Linux kernel: https://elixir.bootlin.com/linux/v6.8.1/source/fs/coredump.c#L545. I can confirm on my local side, with this patch, I am going to squash merge this PR. |
/cherry-pick c1b6cca |
…sn't have valid source locations (llvm#89564) Fixes llvm#86998 (cherry picked from commit c1b6cca)
/pull-request #90369 |
…sn't have valid source locations (llvm#89564) Fixes llvm#86998 (cherry picked from commit c1b6cca)
Fixes #86998
Two compiler explorer examples: 1, 2
Cause:
When visiting AST and generating mapping regions, a region terminator (like
break
andgoto
) is likely followed by a stmt with<invalid sloc>
(likeImplicitValueInitExpr
).Because a terminator is seen, the below branch will be executed when visiting the 2nd stmt:
llvm-project/clang/lib/CodeGen/CoverageMappingGen.cpp
Lines 1375 to 1376 in e6c3289
However, the 2nd stmt doesn't have a valid source location and will fail some assertions in
findGapAreaBetween()
.