[gcov] Ignore blocks from another file
authorFangrui Song <i@maskray.me>
Mon, 14 Aug 2023 17:30:13 +0000 (10:30 -0700)
committerTobias Hieta <tobias@hieta.se>
Tue, 22 Aug 2023 05:42:27 +0000 (07:42 +0200)
commitcd119b354a934575aa0c8f84ac71a7be1f3def7f
tree45ea9e790cda39c1f19a49371d9ed94838ddfd9d
parent4ec6595d6e5bb62839524ecfe6d6699d12c4f7dd
[gcov] Ignore blocks from another file

Constructs such as inline variables, #line, and #include can create
lexical blocks with a different filename.
GCOVProfiling and llvm-cov gcov currently don't handle such cases (see
GCOVLines::writeOut and GCOVFile::readGCNO) and would incorrectly
attribute the line number to the current file.

For now, ignore such blocks. Missing line execution counts is better
than wrong ones.

---

As a workaround that Apple targets don't use -mconstructor-aliases yet,
allow line execution count 4 on the A::A line (1f34e282e8066281eb1447e21e44a2a2e9983e79).

(cherry picked from commit 406e81b79d26dae6838cc69d10a3e22635da09ef)
compiler-rt/test/profile/Posix/gcov-file-change.cpp [new file with mode: 0644]
llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp