aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CoverageMappingGen.cpp
AgeCommit message (Collapse)AuthorFilesLines
2023-12-13Reland "[Coverage][llvm-cov] Enable MC/DC Support in LLVM Source-based Code ↵Alan Phipps1-0/+4
Coverage (2/3)" Part 2 of 3. This includes the Visualization and Evaluation components. Differential Revision: https://reviews.llvm.org/D138847
2023-11-07[NFC] Remove Type::getInt8PtrTy (#71029)Paulo Matos1-1/+1
Replace this with PointerType::getUnqual(). Followup to the opaque pointer transition. Fixes an in-code TODO item.
2023-10-30[clang] Remove no-op ptr-to-ptr bitcasts (NFC)Youngsuk Kim1-3/+1
2023-09-26Revert "[Coverage] Allow Clang coverage to be used with debug info correlation."Zequan Wu1-20/+0
This reverts commit 32db121b29f78e4c41116b2a8f1c730f9522b202 and subsequent commits. This causes time regression on llvm-cov even with debug info correlation off.
2023-09-20Revert "[Coverage] Fix -Wswitch after D138847"Fangrui Song1-6/+0
This reverts commit ca22d6e40508f6d24a9352835bda9c152e3eee1b. The base patch 618a22144db5e45da8c95dc22064103e1b5e5b71 has been reverted.
2023-09-20[Coverage] Fix -Wswitch after D138847Fangrui Song1-0/+6
2023-09-19[Coverage] Skip visiting ctor member initializers with invalid source locations.Zequan Wu1-1/+2
2023-09-15[Coverage] Add coverage for constructor member initializers. (#66441)Zequan Wu1-1/+10
Before, constructor member initializers are shown as not covered. This adds coverage info for them.
2023-09-15[Coverage] Allow Clang coverage to be used with debug info correlation.Zequan Wu1-0/+20
Debug info correlation is an option in InstrProfiling pass, which is used by both IR instrumentation and front-end instrumentation. So, Clang coverage can also benefits the binary size saving from it. Reviewed By: ellis Differential Revision: https://reviews.llvm.org/D157913
2023-09-06[clang] NFCI: Use `FileEntryRef` in `CoverageMappingGen`Jan Svoboda1-5/+5
This removes some uses of the deprecated `FileEntry::getName()`.
2023-04-27[clang] Apply -fcoverage-prefix-map reverse orderGulfem Savrun Yeniceri1-2/+7
This patch changes handling multiple -fcoverage-prefix-map options to match GCC's behavior. GCC applies prefix remappings that are provided in reverse order (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109591). Reviewed By: phosek Differential Revision: https://reviews.llvm.org/D148757
2023-04-25[CodeGen] Remove unneeded CoveragePrefixMap. NFCFangrui Song1-4/+2
2023-04-13[Coverage] Handle invalid end location of an expression/statement.Zequan Wu1-2/+16
Fix a crash when an expression/statement can have valid start location but invalid end location in some situations. For example: https://github.com/llvm/llvm-project/blob/llvmorg-16.0.1/clang/lib/Sema/SemaExprCXX.cpp#L1536 This confuses `CounterCoverageMappingBuilder` when popping a region from region stack as if the end location is a macro or include location. Reviewed By: hans, aaron.ballman Differential Revision: https://reviews.llvm.org/D147073
2023-04-05[Coverage] Fix crash when visiting PseudoObjectExpr.Zequan Wu1-0/+9
This is a split of D147073. Fixes #45481 Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D147569
2023-03-02[Coverage] Fix an issue: a statement after calling 'assert()' function is ↵Ying Yi1-4/+25
wrongly marked as 'not executed'. In the current coverage mapping implementation, we terminate the current region and start a zero region when we hit a nonreturn function. However, for logical OR, the second operand is not executed if the first operand evaluates to true. If the nonreturn function is called in the right side of logical OR and the left side of logical OR is TRUE, we should not start a zero `GapRegionCounter`. This will also apply to `VisitAbstractConditionalOperator`. Fixes https://github.com/llvm/llvm-project/issues/59030 Reviewed By: zequanwu Differential Revision: https://reviews.llvm.org/D144371
2023-02-06[Coverage] Map regions from system headersGulfem Savrun Yeniceri1-6/+16
Originally, the following commit removed mapping coverage regions for system headers: https://github.com/llvm/llvm-project/commit/93205af066341a53733046894bd75c72c99566db It might be viable and useful to collect coverage from system headers in some systems. This patch adds --system-headers-coverage option (disabled by default) to enable collecting coverage from system headers. Differential Revision: https://reviews.llvm.org/D143304
2023-01-14[clang] Remove remaining uses of llvm::Optional (NFC)Kazu Hirata1-1/+0
This patch removes several "using" declarations and #include "llvm/ADT/Optional.h". This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-14[clang] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata1-23/+25
This patch replaces (llvm::|)Optional< with std::optional<. I'll post a separate patch to remove #include "llvm/ADT/Optional.h". This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-14[clang] Add #include <optional> (NFC)Kazu Hirata1-0/+1
This patch adds #include <optional> to those files containing llvm::Optional<...> or Optional<...>. I'll post a separate patch to actually replace llvm::Optional with std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-09Move from llvm::makeArrayRef to ArrayRef deduction guides - clang/ partserge-sans-paille1-10/+9
This is a follow-up to https://reviews.llvm.org/D140896, split into several parts as it touches a lot of files. Differential Revision: https://reviews.llvm.org/D141139
2022-12-04[clang] Use std::nullopt instead of None in comments (NFC)Kazu Hirata1-2/+2
This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-03[CodeGen] Use std::nullopt instead of None (NFC)Kazu Hirata1-8/+9
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-08-26[Clang] Fix crash in coverage of if consteval.Corentin Jabot1-13/+19
Clang crashes when encountering an `if consteval` statement. This is the minimum fix not to crash. The fix is consistent with the current behavior of if constexpr, which does generate coverage data for the discarded branches. This is of course not correct and a better solution is needed for both if constexpr and if consteval. See https://github.com/llvm/llvm-project/issues/54419. Fixes #57377 Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D132723
2022-06-20Don't use Optional::hasValue (NFC)Kazu Hirata1-3/+3
2022-06-20[clang] Don't use Optional::hasValue (NFC)Kazu Hirata1-2/+2
2022-06-08[Clang][CoverageMapping] Fix compile time explosions by adjusting only ↵Bruno Cardoso Lopes1-7/+15
appropriated skipped ranges D83592 added comments to be part of skipped regions, and as part of that, it also shrinks a skipped range if it spans a line that contains a non-comment token. This is done by `adjustSkippedRange`. The `adjustSkippedRange` currently runs on skipped regions that are not comments, causing a 5min regression while building a big C++ files without any comments. Fix the compile time introduced in D83592 by tagging SkippedRange with kind information and use that to decide what needs additional processing. Differential Revision: https://reviews.llvm.org/D127338
2022-05-26[Clang][CoverageMapping] Fix switch counter codegen compile time explosionBruno Cardoso Lopes1-7/+13
C++ generated code with huge amount of switch cases chokes badly while emitting coverage mapping, in our specific testcase (~72k cases), it won't stop after hours. After this change, the frontend job now finishes in 4.5s and shrinks down `@__covrec_` by 288k when compared to disabling simplification altogether. There's probably no good way to create a testcase for this, but it's easy to reproduce, just add thousands of cases in the below switch, and build with `-fprofile-instr-generate -fcoverage-mapping`. ``` enum type : int { FEATURE_INVALID = 0, FEATURE_A = 1, ... }; const char *to_string(type e) { switch (e) { case type::FEATURE_INVALID: return "FEATURE_INVALID"; case type::FEATURE_A: return "FEATURE_A";} ... } ``` Differential Revision: https://reviews.llvm.org/D126345
2021-11-14[clang] Use isa instead of dyn_cast (NFC)Kazu Hirata1-1/+1
2021-10-24Use llvm::any_of and llvm::none_of (NFC)Kazu Hirata1-7/+5
2021-03-04Revert "Revert "[Coverage] Emit gap region between statements if first ↵Zequan Wu1-136/+93
statements contains terminate statements."" Reland with update on test case ContinuousSyncmode/basic.c. This reverts commit fe5c2c3ca682b140dd5e640e75948363b6b25ef9.
2021-03-04Revert "[Coverage] Emit gap region between statements if first statements ↵Nico Weber1-93/+136
contains terminate statements." This reverts commit 2d7374a0c680f96bdcdb3d05034a93bf145d140f. Breaks ContinuousSyncMode/basic.c in check-profile on macOS.
2021-03-03[Coverage] Emit gap region between statements if first statements contains ↵Zequan Wu1-136/+93
terminate statements. Differential Revision: https://reviews.llvm.org/D97101
2021-02-25[Driver] Rename -fprofile-{prefix-map,compilation-dir} to ↵Petr Hosek1-4/+4
-fcoverage-{prefix-map,compilation-dir} These flags affect coverage mapping (-fcoverage-mapping), not -fprofile-[instr-]generate so it makes more sense to use the -fcoverage-* prefix. Differential Revision: https://reviews.llvm.org/D97434
2021-02-19[Coverage] Normalize compilation dir as wellPetr Hosek1-1/+1
This matches debug info behavior. Differential Revision: https://reviews.llvm.org/D97001
2021-02-18[Coverage] Store compilation dir separately in coverage mappingPetr Hosek1-12/+18
We currently always store absolute filenames in coverage mapping. This is problematic for several reasons. It poses a problem for distributed compilation as source location might vary across machines. We are also duplicating the path prefix potentially wasting space. This change modifies how we store filenames in coverage mapping. Rather than absolute paths, it stores the compilation directory and file paths as given to the compiler, either relative or absolute. Later when reading the coverage mapping information, we recombine relative paths with the working directory. This approach is similar to handling ofDW_AT_comp_dir in DWARF. Finally, we also provide a new option, -fprofile-compilation-dir akin to -fdebug-compilation-dir which can be used to manually override the compilation directory which is useful in distributed compilation cases. Differential Revision: https://reviews.llvm.org/D95753
2021-02-18Move a second variable only used in an assert into the assert.Sterling Augustine1-2/+2
This prevents unused variable warnings when building without asserts.
2021-02-18Move variable only used in an assert into the assert.Sterling Augustine1-2/+2
This prevents unused variable warnings when building without asserts.
2021-02-18Revert "[Coverage] Store compilation dir separately in coverage mapping"Petr Hosek1-18/+12
This reverts commit 97ec8fa5bb07e3f5bf25ddcb216b545cd3d03b65 since the test is failing on some bots.
2021-02-18[Coverage] Store compilation dir separately in coverage mappingPetr Hosek1-12/+18
We currently always store absolute filenames in coverage mapping. This is problematic for several reasons. It poses a problem for distributed compilation as source location might vary across machines. We are also duplicating the path prefix potentially wasting space. This change modifies how we store filenames in coverage mapping. Rather than absolute paths, it stores the compilation directory and file paths as given to the compiler, either relative or absolute. Later when reading the coverage mapping information, we recombine relative paths with the working directory. This approach is similar to handling ofDW_AT_comp_dir in DWARF. Finally, we also provide a new option, -fprofile-compilation-dir akin to -fdebug-compilation-dir which can be used to manually override the compilation directory which is useful in distributed compilation cases. Differential Revision: https://reviews.llvm.org/D95753
2021-02-18[Coverage] Emit gap region after conditions when macro is present.Zequan Wu1-16/+31
2021-02-03[Coverage] Propogate counter to condition of conditional operatorZequan Wu1-1/+1
Clang usually propagates counter mapping region for conditions of `if`, `while`, `for`, etc from parent counter. We should do the same for condition of conditional operator. Differential Revision: https://reviews.llvm.org/D95918
2021-01-25[clang] Add -fprofile-prefix-mapKeith Smiley1-7/+17
This flag allows you to re-write absolute paths in coverage data analogous to -fdebug-prefix-map. This flag is also implied by -ffile-prefix-map.
2021-01-05[Coverage] Add support for Branch Coverage in LLVM Source-Based Code CoverageAlan Phipps1-25/+210
This is an enhancement to LLVM Source-Based Code Coverage in clang to track how many times individual branch-generating conditions are taken (evaluate to TRUE) and not taken (evaluate to FALSE). Individual conditions may comprise larger boolean expressions using boolean logical operators. This functionality is very similar to what is supported by GCOV except that it is very closely anchored to the ASTs. Differential Revision: https://reviews.llvm.org/D84467
2020-09-21[Coverage] Add empty line regions to SkippedRegionsZequan Wu1-32/+46
Differential Revision: https://reviews.llvm.org/D84988
2020-08-25Revert "[Coverage] Enable emitting gap area between macros"Zequan Wu1-8/+14
This reverts commit a31c89c1b7a0a2fd3e2c0b8a587a60921abf4abd.
2020-08-18[Coverage] Adjust skipped regions only if {Prev,Next}TokLoc is in the same ↵Zequan Wu1-10/+14
file as regions' {start, end}Loc Fix a bug if {Prev, Next}TokLoc is in different file from skipped regions' {start, end}Loc Differential Revision: https://reviews.llvm.org/D86116
2020-08-12[Coverage] Enable emitting gap area between macrosZequan Wu1-14/+8
Differential Revision: https://reviews.llvm.org/D85176
2020-07-28Reland [Coverage] Add comment to skipped regionsZequan Wu1-5/+64
Bug filled here: https://bugs.llvm.org/show_bug.cgi?id=45757. Add comment to skipped regions so we don't track execution count for lines containing only comments. Differential Revision: https://reviews.llvm.org/D83592
2020-07-22Revert abd45154b "[Coverage] Add comment to skipped regions"Hans Wennborg1-69/+5
This casued assertions during Chromium builds. See comment on the code review > Bug filled here: https://bugs.llvm.org/show_bug.cgi?id=45757. > Add comment to skipped regions so we don't track execution count for lines containing only comments. > > Differential Revision: https://reviews.llvm.org/D84208 This reverts commit abd45154bdb6b76c5b480455eacc8c75b08242aa and the follow-up 87d725473380652bbe845fd2fbd9c0507a55172f.
2020-07-21[Coverage] Add comment to skipped regionsZequan Wu1-5/+69
Bug filled here: https://bugs.llvm.org/show_bug.cgi?id=45757. Add comment to skipped regions so we don't track execution count for lines containing only comments. Differential Revision: https://reviews.llvm.org/D84208