This is an archive of the discontinued LLVM Phabricator instance.

[Coverage] Emit gap region after conditions when macro is present.
ClosedPublic

Authored by zequanwu on Aug 3 2020, 6:37 PM.

Details

Summary

Bug filed here: https://bugs.llvm.org/show_bug.cgi?id=45849
This is caused by gap area not emitted if either AfterLoc or BeforeLoc is a macro location.

Diff Detail

Event Timeline

zequanwu created this revision.Aug 3 2020, 6:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 3 2020, 6:37 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
zequanwu requested review of this revision.Aug 3 2020, 6:37 PM
vsk added inline comments.Aug 4 2020, 4:51 PM
clang/test/CoverageMapping/macro-expressions.cpp
64

The gap region appears to start from the 'E' in 'EXPR'. That looks like it's too early -- I'd expect it to start after the final closing parenthesis ")".

78

Ditto.

zequanwu updated this revision to Diff 284858.Aug 11 2020, 12:39 PM

Address comments.

zequanwu marked 2 inline comments as done.Aug 11 2020, 12:40 PM
vsk accepted this revision.Aug 12 2020, 2:18 PM

Thanks, looks good to me! Please check for any issues in a stage2 coverage build before landing this.

This revision is now accepted and ready to land.Aug 12 2020, 2:18 PM
This revision was landed with ongoing or failed builds.Aug 12 2020, 4:26 PM
This revision was automatically updated to reflect the committed changes.
zequanwu reopened this revision.Aug 26 2020, 5:04 PM

Here is a repro of crash caused by this change.

int k, l;
#define m(e) e##e
void p() {
  int kk,ll;
  if (k)
    m(k);
  else
    l = m(l);
}

SM.getExpansLoc(AfterLoc) for m(k) gives location pointing to m(l), which caused the crash.

This revision is now accepted and ready to land.Aug 26 2020, 5:04 PM
phosek added a subscriber: phosek.Aug 27 2020, 1:14 AM

We started seeing assertion failure after rolling a toolchain that contains this change and git bisect identified this change. I have filed a bug with a reproducer as PR47324.

We started seeing assertion failure after rolling a toolchain that contains this change and git bisect identified this change. I have filed a bug with a reproducer as PR47324.

It has been reverted for now.

zequanwu updated this revision to Diff 324695.Feb 18 2021, 10:12 AM

Tested on clange stage2 build.

zequanwu retitled this revision from [Coverage] Enable emitting gap area between macros to [Coverage] Emit gap region after conditions when macro is present..Feb 18 2021, 10:12 AM
vsk added a comment.Feb 18 2021, 10:50 AM

Could you check in the reproducer program (void p) as a regression test?

clang/lib/CodeGen/CoverageMappingGen.cpp
995

It could aid debugging to assert that the result of getIncludeOrExpansionLoc(AfterLoc) is valid.

clang/test/CoverageMapping/if.cpp
10

Just to double-check: this is now starting the gap after the '?', instead of including the '?' - if so, that looks right.

zequanwu updated this revision to Diff 324710.Feb 18 2021, 11:12 AM
zequanwu marked 2 inline comments as done.
  • Added regression test.
  • Assert getIncludeOrExpansionLoc(AfterLoc) is valid.
clang/test/CoverageMapping/if.cpp
10

Yes.

vsk accepted this revision.Feb 18 2021, 11:23 AM

Thanks!

zequanwu closed this revision.Feb 18 2021, 11:43 AM

This commit introduced an unused variable warning when built without asserts. (CoverageMappingGen.cpp:984) I have fixed it with rG4544a63b7705.

This commit introduced an unused variable warning when built without asserts. (CoverageMappingGen.cpp:984) I have fixed it with rG4544a63b7705.

Thanks.