[clang] [clang][coverage] Add opt-in call continuation counters for coverage (PR #201079)

via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 18 07:31:33 PDT 2026


ankurrj7 wrote:

Pushed one more fix for the RDBMS-style cases we found.

The issue was not just "macro coverage" by itself. The continuation region we create after a call starts out without a source start, and later it can inherit an end location from the surrounding region. In a few real shapes that inherited end was stale:

```c
p = alloc();
if (!p)
  return 2;

if (ret) {
  f();
  return 1;
}
```

and also in the cleanup macro cases where a call continuation is followed by repeated function-like cleanup macros.

When the region was popped, that stale inherited end could make the mapping range go out of source order after macro/include unnesting. That is what was tripping the coverage mapping assertion.

The fix now does two things:

* If a call-continuation region does not have its own end, it looks for the closest enclosing end location that still stays in source order after the same unnesting that `popRegions()` will do. So we avoid blindly using a parent end that belongs to an older source range.
* For function-like macro continuations, the new region starts at the macro invocation location. I limited that only to call-continuation regions. I had a broader version first, but that changed existing macro mapping (`switchmacro.c`), so this keeps the change scoped to the new continuation regions.

I added coverage-mapping regressions for both the plain guard case and the repeated cleanup macro case.

Validation I ran after the final version:

```text
ninja -C /scratch/ankurraj/clang_experiment_23/build/cov-broad-build clang llvm-cov llvm-profdata
git diff --check
git-clang-format --diff HEAD ...
llvm-lit -sv clang/test/CoverageMapping/call-continuations.c \
  clang/test/CoverageMapping/call-continuations-tight.c \
  clang/test/Profile/call-continuations.c \
  clang/test/Driver/coverage-call-continuations.c \
  clang/test/CoverageMapping/terminate-statements.cpp \
  clang/test/CoverageMapping/switchmacro.c
llvm-lit -sv clang/test/CoverageMapping
```

The focused lit set passed, full `clang/test/CoverageMapping` passed `77/77`, and I also reran the local RDBMS scenario matrix plus the scratch reducer cases we collected from the failures.


https://github.com/llvm/llvm-project/pull/201079


More information about the cfe-commits mailing list