summaryrefslogtreecommitdiffstats
path: root/lib/CodeGen/CoverageMappingGen.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [Coverage] Emit gap areas in braces-optional statements (PR35387)Vedant Kumar2017-11-291-9/+61
| | | | | | | | | | | | | Emit a gap area starting after the r-paren location and ending at the start of the body for the braces-optional statements (for, for-each, while, etc). The count for the gap area equal to the body's count. This extends the fix in r317758. Fixes PR35387, rdar://35570345 Testing: stage2 coverage-enabled build of clang, check-clang git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@319373 91177308-0d34-0410-b5e6-96231b3b80d8
* [Coverage] Emit deferred regions in headersVedant Kumar2017-11-091-3/+5
| | | | | | | | | | | There are some limitations with emitting regions in macro expansions because we don't gather file IDs within the expansions. Fix the check that prevents us from emitting deferred regions in expansions to make an exception for headers, which is something we can handle. rdar://35373009 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@317760 91177308-0d34-0410-b5e6-96231b3b80d8
* [Coverage] Complete top-level deferred regions before labelsVedant Kumar2017-11-091-3/+38
| | | | | | | | | | | | | | | | | | | The area immediately after a terminated region in the function top-level should have the same count as the label it precedes. This solves another problem with wrapped segments. Consider: 1| a: 2| return 0; 3| b: 4| return 1; Without a gap area starting after the first return, the wrapped segment from line 2 would make it look like line 3 is executed, when it's not. rdar://35373009 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@317759 91177308-0d34-0410-b5e6-96231b3b80d8
* [Coverage] Emit a gap area after if conditionsVedant Kumar2017-11-091-1/+26
| | | | | | | | | | | | | | | | | | | The area immediately after the closing right-paren of an if condition should have a count equal to the 'then' block's count. Use a gap region to set this count, so that region highlighting for the 'then' block remains precise. This solves a problem we have with wrapped segments. Consider: 1| if (false) 2| foo(); Without a gap area starting after the condition, the wrapped segment from line 1 would make it look like line 2 is executed, when it's not. rdar://35373009 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@317758 91177308-0d34-0410-b5e6-96231b3b80d8
* [Coverage] Discard deferred region in closing if-elseVedant Kumar2017-10-171-7/+23
| | | | | | | | | | | | | | | | A trailing deferred region isn't necessary in a function that ends with this pattern: ... else { ... return; } Special-case this pattern so that the closing curly brace of the function isn't marked as uncovered. This issue came up in PR34962. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@315982 91177308-0d34-0410-b5e6-96231b3b80d8
* [Coverage] Explicitly mark the l.h.s of && and || (fixes PR33465)Vedant Kumar2017-10-171-4/+6
| | | | | | | | | | This makes it possible to view sub-line region counts for the l.h.s of && and || expressions in coverage reports. It also fixes PR33465, which shows an example of incorrect coverage output for an assignment statement containing '||'. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@315979 91177308-0d34-0410-b5e6-96231b3b80d8
* [Coverage] Remove deferred region for trailing return, fixes PR34611Vedant Kumar2017-09-191-1/+7
| | | | | | | | As a special case, throw away deferred regions for trailing returns. This allows the closing curly brace to have a count, and is less distracting. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@313603 91177308-0d34-0410-b5e6-96231b3b80d8
* [Coverage] Use a new API to label gap areasVedant Kumar2017-09-181-5/+25
| | | | | | | This will make it possible for llvm-cov to pick better line execution counts, and is part of the fix for llvm.org/PR34612. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@313598 91177308-0d34-0410-b5e6-96231b3b80d8
* [Lexer] Report more precise skipped regions (PR34166)Vedant Kumar2017-09-111-1/+1
| | | | | | | | | | | | | | | | | | | | This patch teaches the preprocessor to report more precise source ranges for code that is skipped due to conditional directives. The new behavior includes the '#' from the opening directive and the full text of the line containing the closing directive in the skipped area. This matches up clang's behavior (we don't IRGen the code between the closing "endif" and the end of a line). This also affects the code coverage implementation. See llvm.org/PR34166 (this also happens to be rdar://problem/23224058). The old behavior (report the end of the skipped range as the end location of the 'endif' token) is preserved for indexing clients. Differential Revision: https://reviews.llvm.org/D36642 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@312947 91177308-0d34-0410-b5e6-96231b3b80d8
* [Coverage] Precise region termination with deferred regions (reapply)Vedant Kumar2017-09-081-5/+86
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The current coverage implementation doesn't handle region termination very precisely. Take for example an `if' statement with a `return': void f() { if (true) { return; // The `if' body's region is terminated here. } // This line gets the same coverage as the `if' condition. } If the function `f' is called, the line containing the comment will be marked as having executed once, which is not correct. The solution here is to create a deferred region after terminating a region. The deferred region is completed once the start location of the next statement is known, and is then pushed onto the region stack. In the cases where it's not possible to complete a deferred region, it can safely be dropped. Testing: lit test updates, a stage2 coverage-enabled build of clang This is a reapplication but there are no changes from the original commit. With D36813, the segment builder in llvm will be able to handle deferred regions correctly. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@312818 91177308-0d34-0410-b5e6-96231b3b80d8
* [coverage] Special-case calls to noreturn functions.Eli Friedman2017-08-081-0/+10
| | | | | | | | | | | | | | | | | The code after a noreturn call doesn't execute. The pattern in the testcase is pretty common in LLVM (a switch with a default case that calls llvm_unreachable). The original version of this patch was reverted in r309995 due to a crash. This version includes a fix for that crash (testcase in test/CoverageMapping/md.cpp). Differential Revision: https://reviews.llvm.org/D36250 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@310406 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert "[Coverage] Precise region termination with deferred regions"Vedant Kumar2017-08-051-86/+5
| | | | | | | | | | | | | | This reverts commit r310010. I don't think there's anything wrong with this commit, but it's causing clang to generate output that llvm-cov doesn't do a good job with and the fix isn't immediately clear. See Eli's comment in D36250 for more context. I'm reverting the clang change so the coverage bot can revert back to producing sensible output, and to give myself some time to investigate what went wrong in llvm. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@310154 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert "[coverage] Special-case calls to noreturn functions."Vedant Kumar2017-08-041-12/+0
| | | | | | | | | | | This reverts commit r309995. It looks like it's responsible for breaking the stage2 coverage build: http://green.lab.llvm.org/green/job/clang-stage2-coverage-R_build/1402 The cfe-commits discussion re: r309995 has more context. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@310019 91177308-0d34-0410-b5e6-96231b3b80d8
* [Coverage] Precise region termination with deferred regionsVedant Kumar2017-08-041-5/+86
| | | | | | | | | | | | | | | | | | | | | | | | | The current coverage implementation doesn't handle region termination very precisely. Take for example an `if' statement with a `return': void f() { if (true) { return; // The `if' body's region is terminated here. } // This line gets the same coverage as the `if' condition. } If the function `f' is called, the line containing the comment will be marked as having executed once, which is not correct. The solution here is to create a deferred region after terminating a region. The deferred region is completed once the start location of the next statement is known, and is then pushed onto the region stack. In the cases where it's not possible to complete a deferred region, it can safely be dropped. Testing: lit test updates, a stage2 coverage-enabled build of clang git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@310010 91177308-0d34-0410-b5e6-96231b3b80d8
* [coverage] Special-case calls to noreturn functions.Eli Friedman2017-08-031-0/+12
| | | | | | | | | | | | | The code after a noreturn call doesn't execute. The pattern in the testcase is pretty common in LLVM (a switch with a default case that calls llvm_unreachable). Differential Revision: https://reviews.llvm.org/D36250 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@309995 91177308-0d34-0410-b5e6-96231b3b80d8
* [coverage] Make smaller regions for the first case of a switch.Eli Friedman2017-08-021-6/+13
| | | | | | | | | | | | | | | We never overwrite the end location of a region, so we would end up with an overly large region when we reused the switch's region. It's possible this code will be substantially rewritten in the near future to deal with fallthrough more accurately, but this seems like an improvement on its own for now. Differential Revision: https://reviews.llvm.org/D34801 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@309901 91177308-0d34-0410-b5e6-96231b3b80d8
* [Coverage] NFC: Simplify sanity checks with a SpellingRange utilityVedant Kumar2017-07-271-21/+41
| | | | | | This should simplify D35925. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@309245 91177308-0d34-0410-b5e6-96231b3b80d8
* [Coverage] NFC: Save a pair of calls to get{Start,End}Vedant Kumar2017-07-271-3/+5
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@309244 91177308-0d34-0410-b5e6-96231b3b80d8
* [Coverage] Use the new getInstrProfSectionName API (NFC)Vedant Kumar2017-04-151-1/+3
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@300382 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix use after free errorXinliang David Li2017-04-141-1/+1
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@300304 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove unused function /nfcXinliang David Li2017-04-141-4/+0
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@300301 91177308-0d34-0410-b5e6-96231b3b80d8
* [Profile] PE binary coverage bug fixXinliang David Li2017-04-131-1/+1
| | | | | | | | | PR/32584 Differential Revision: https://reviews.llvm.org/D32023 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@300279 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix use-of-temporary with StringRef in code coverageJordan Rose2016-11-071-2/+7
| | | | | | | | | | | | | The fixed code is basically identical to the same loop below, which might indicate an opportunity for refactoring. I just wanted to fix the use-of-temporary issue. Caught by adding a similar check to StringRef as r283798 did for ArrayRef. I'll be upstreaming that soon. Reviewed by Vedant Kumar as https://reviews.llvm.org/D26317. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@286122 91177308-0d34-0410-b5e6-96231b3b80d8
* [Coverage] Support for C++17 if initializersVedant Kumar2016-10-141-0/+3
| | | | | | Differential Revision: https://reviews.llvm.org/D25572 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@284293 91177308-0d34-0410-b5e6-96231b3b80d8
* [Coverage] Support for C++17 switch initializersVedant Kumar2016-10-141-0/+2
| | | | | | Differential Revision: https://reviews.llvm.org/D25539 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@284292 91177308-0d34-0410-b5e6-96231b3b80d8
* Use StringRef for MemoryBuffer identifier API (NFC)Mehdi Amini2016-10-011-1/+1
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@283043 91177308-0d34-0410-b5e6-96231b3b80d8
* [Coverage] The coverage region for switch covers the code after the switch.Alex Lorenz2016-09-271-1/+5
| | | | | | | | | | | | | | | This patch fixes a regression introduced in r262697 that changed the way the coverage regions for switches are constructed. The PGO instrumentation counter for a switch statement refers to the counter at the exit of the switch. Therefore, the coverage region for the switch statement should cover the code that comes after the switch, and not the switch statement itself. rdar://28480997 Differential Revision: https://reviews.llvm.org/D24981 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@282554 91177308-0d34-0410-b5e6-96231b3b80d8
* [Coverage] Suppress creating a code region if the same area is covered by an ↵Igor Kudrin2016-08-311-5/+23
| | | | | | | | | | | | | expansion region. In most cases these code regions are just redundant, but sometimes they could be assigned to the counter of the parent code region instead of the counter of the nested block. Differential Revision: https://reviews.llvm.org/D23987 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@280199 91177308-0d34-0410-b5e6-96231b3b80d8
* [Coverage] Prevent creating a redundant counter if a nested body ends with a ↵Igor Kudrin2016-08-291-1/+2
| | | | | | | | | | | | | | | | | | macro. If there were several nested statements arranged in a way that all of them end up with the same macro, then the expansion of this macro was assigned with all the corresponding counters of these statements. As a result, the wrong counter value was shown for the macro in llvm-cov. This patch fixes the issue by preventing adding a counter for an expanded source range if it already has an assigned counter, which is expected to come from the most specific statement. Differential Revision: https://reviews.llvm.org/D23160 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@279962 91177308-0d34-0410-b5e6-96231b3b80d8
* [Coverage] Do not write out coverage mappings with zero entriesVedant Kumar2016-07-261-0/+11
| | | | | | | | | | | | | After r275121, we stopped mapping regions from system headers. Lambdas declared in regions belonging to system headers started producing empty coverage mappings, since the files corresponding to their spelling locs were being ignored. The coverage reader doesn't know what to do with these empty mappings. This commit makes sure that we don't produce them and adds a test. I'll make the reader stricter in a follow-up commit. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@276716 91177308-0d34-0410-b5e6-96231b3b80d8
* [Coverage] Remove '..' from filenames *after* getting an absolute pathVedant Kumar2016-07-181-1/+1
| | | | | | | | Failure to do this breaks relative paths which begin with '..'. This issue was caught by the (still nascent) coverage bot. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@275924 91177308-0d34-0410-b5e6-96231b3b80d8
* [Coverage] Normalize '..' out of filename stringsVedant Kumar2016-07-181-8/+14
| | | | | | | | This fixes the issue of having duplicate entries for the same file in a coverage report s.t none of the entries actually displayed the correct coverage information. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@275913 91177308-0d34-0410-b5e6-96231b3b80d8
* [Coverage] Do not map regions from system headersVedant Kumar2016-07-111-0/+8
| | | | | | | | | | | | | | | Do not assign source regions located within system headers file ID's, and do not construct counter mapping regions out of them. This makes coverage reports less cluttered and less mysterious. E.g using the "assert" macro doesn't cause assert.h to appear in reports, and it no longer shows the "assertion failed" branch as an uncovered region. It also makes coverage mapping sections a bit smaller (e.g a 1% reduction in a stage2 build of bin/llvm-as). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@275121 91177308-0d34-0410-b5e6-96231b3b80d8
* Delete some dead code, NFCVedant Kumar2016-07-061-10/+0
| | | | | | Found using clang's code coverage tool. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@274599 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert "[Coverage] Adopt llvm::coverage::encodeFilenamesAndRawMappings (NFC)"Vedant Kumar2016-06-291-10/+18
| | | | | | | | | This reverts commit 161ff9db3a3d0d62880d1cb18d58182cd3034912 (r273056). This is breaking stage2 instrumented builds with "malformed coverage data" errors. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@274104 91177308-0d34-0410-b5e6-96231b3b80d8
* [Coverage] Push a new region when handling CXXTryStmtsVedant Kumar2016-06-221-1/+6
| | | | | | | | Push a new region for the try block and propagate execution counts through it. This ensures that catch statements get a region counter distinct from the try block's counter. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@273463 91177308-0d34-0410-b5e6-96231b3b80d8
* [Coverage] Adopt llvm::coverage::encodeFilenamesAndRawMappings (NFC)Vedant Kumar2016-06-171-18/+10
| | | | | | Use an llvm helper function to encode filenames and raw mappings. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@273056 91177308-0d34-0410-b5e6-96231b3b80d8
* Reapply [Coverage] Fix an assertion failure if the definition of an unused ↵Igor Kudrin2016-06-071-11/+31
| | | | | | | | | | | | | | | | function spans multiple files. We have an assertion failure if, for example, the definition of an unused inline function starts in one macro and ends in another. This patch fixes the issue by finding the common ancestor of the start and end locations of that function's body and changing the locations accordingly. Thanks to NAKAMURA Takumi for helping with fixing the test failure on Windows. Differential Revision: http://reviews.llvm.org/D20997 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@271995 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert [Coverage] Fix an assertion failure if the definition of an unused ↵Igor Kudrin2016-06-071-31/+11
| | | | | | | | | function spans multiple files. r271969 The test case fails on Windows. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@271976 91177308-0d34-0410-b5e6-96231b3b80d8
* [Coverage] Fix an assertion failure if the definition of an unused function ↵Igor Kudrin2016-06-071-11/+31
| | | | | | | | | | | | | | spans multiple files. We have an assertion failure if, for example, the definition of an unused inline function starts in one macro and ends in another. This patch fixes the issue by finding the common ancestor of the start and end locations of that function's body and changing the locations accordingly. Differential Revision: http://reviews.llvm.org/D20997 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@271969 91177308-0d34-0410-b5e6-96231b3b80d8
* [Coverage] Remove redundant handleFileExit() call (NFC)Vedant Kumar2016-05-311-3/+1
| | | | | | | | | I added this call in r271308. It's redundant because it's dominated by a call to extendRegion(). Thanks to Justin Bogner for pointing this out! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@271331 91177308-0d34-0410-b5e6-96231b3b80d8
* [Coverage] Fix crash on a switch partially covered by a macro (PR27948)Vedant Kumar2016-05-311-2/+6
| | | | | | | We have to handle file exits before and after visiting regions in the switch body. Fixes PR27948. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@271308 91177308-0d34-0410-b5e6-96231b3b80d8
* [Coverage] Fix an issue where a coverage region might not be created for a ↵Igor Kudrin2016-05-041-3/+19
| | | | | | | | | | | | macro containing a loop statement. The issue happened when a macro contained a full for or while statement, which body ended at the end of the macro. Differential Revision: http://reviews.llvm.org/D19725 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@268511 91177308-0d34-0410-b5e6-96231b3b80d8
* Use the new path for coverage related headers and update CMakeLists.txtEaswaran Raman2016-04-291-3/+3
| | | | | | | Differential Revision: http://reviews.llvm.org/D19612 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@268090 91177308-0d34-0410-b5e6-96231b3b80d8
* [Coverage] Fix the start/end locations of switch statementsVedant Kumar2016-03-041-1/+1
| | | | | | | | | | | | While pushing switch statements onto the region stack we neglected to specify their start/end locations. This results in a crash (PR26825) if we end up in nested macro expansions without enough information to handle the relevant file exits. I added a test in switchmacro.c and fixed up a bunch of incorrect CHECK lines that specify strange end locations for switches. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@262697 91177308-0d34-0410-b5e6-96231b3b80d8
* [Coverage] Fix crash when handling certain macro expansionsVedant Kumar2016-02-081-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | When handling 'if' statements, we crash if the condition and the consequent branch are spanned by a single macro expansion. The crash occurs because of a sanity 'reset' in popRegions(): if an expansion exactly spans an entire region, we set MostRecentLocation to the start of the expansion (its 'include location'). This ensures we don't handleFileExit() ourselves out of the expansion before we're done processing all of the regions within it. This is tested in test/CoverageMapping/macro-expressions.c. This causes a problem when an expansion spans both the condition and the consequent branch of an 'if' statement. MostRecentLocation is updated to the start of the 'if' statement in popRegions(), so the file for the expansion isn't exited by the time we're done handling the statement. We then crash with 'fatal: File exit not handled before popRegions'. The fix for this is to detect these kinds of expansions, and conservatively update MostRecentLocation to the end of expansion region containing the conditional. I've added tests to make sure we don't have the same problem with other kinds of statements. rdar://problem/23630316 Differential Revision: http://reviews.llvm.org/D16934 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@260129 91177308-0d34-0410-b5e6-96231b3b80d8
* [Coverage] Use a set to track visited FileIDs (NFC)Vedant Kumar2016-01-281-3/+3
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@259061 91177308-0d34-0410-b5e6-96231b3b80d8
* [Coverage] Reduce complexity of adding function mapping recordsVedant Kumar2016-01-211-3/+6
| | | | | | | | | | Replace a string append operation in addFunctionMappingRecord with a vector append. The existing behavior is quadratic in the worst case: this patch makes it linear. Differential Revision: http://reviews.llvm.org/D16395 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@258424 91177308-0d34-0410-b5e6-96231b3b80d8
* Reference the updated function name /NFCXinliang David Li2016-01-201-1/+1
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@258261 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix local variable name /NFCXinliang David Li2016-01-191-2/+2
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@258106 91177308-0d34-0410-b5e6-96231b3b80d8