Commit Graph

72 Commits

Author SHA1 Message Date
Vedant Kumar ce05a5324b [Coverage] Do not write out coverage mappings with zero entries
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
2016-07-26 00:24:59 +00:00
Vedant Kumar 2e51ff6dc2 [Coverage] Remove '..' from filenames *after* getting an absolute path
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
2016-07-18 22:32:02 +00:00
Vedant Kumar bca87a6cb2 [Coverage] Normalize '..' out of filename strings
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
2016-07-18 21:01:27 +00:00
Vedant Kumar f379326a64 [Coverage] Do not map regions from system headers
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
2016-07-11 22:57:46 +00:00
Vedant Kumar 1ba972442a Delete some dead code, NFC
Found using clang's code coverage tool.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@274599 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-06 03:08:47 +00:00
Vedant Kumar 03f9ee026f Revert "[Coverage] Adopt llvm::coverage::encodeFilenamesAndRawMappings (NFC)"
This reverts commit 161ff9db3a (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
2016-06-29 05:33:09 +00:00
Vedant Kumar c35b5c603d [Coverage] Push a new region when handling CXXTryStmts
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
2016-06-22 19:57:58 +00:00
Vedant Kumar 161ff9db3a [Coverage] Adopt llvm::coverage::encodeFilenamesAndRawMappings (NFC)
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
2016-06-17 21:53:55 +00:00
Igor Kudrin 10ab2e4543 Reapply [Coverage] Fix an assertion failure if the definition of an unused 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
2016-06-07 10:07:51 +00:00
Igor Kudrin de3b5e4903 Revert [Coverage] Fix an assertion failure if the definition of an unused 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
2016-06-07 04:11:51 +00:00
Igor Kudrin f962670a08 [Coverage] Fix an assertion failure if the definition of an unused 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.

Differential Revision: http://reviews.llvm.org/D20997


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@271969 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-07 02:17:03 +00:00
Vedant Kumar a47c5ddbad [Coverage] Remove redundant handleFileExit() call (NFC)
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
2016-05-31 20:35:12 +00:00
Vedant Kumar e0c001cbf6 [Coverage] Fix crash on a switch partially covered by a macro (PR27948)
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
2016-05-31 18:06:19 +00:00
Igor Kudrin b5f1f3cacd [Coverage] Fix an issue where a coverage region might not be created for a 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
2016-05-04 15:38:26 +00:00
Easwaran Raman 2fc800b54b Use the new path for coverage related headers and update CMakeLists.txt
Differential Revision: http://reviews.llvm.org/D19612


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@268090 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-29 18:53:16 +00:00
Vedant Kumar f377a655e7 [Coverage] Fix the start/end locations of switch statements
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
2016-03-04 08:07:15 +00:00
Vedant Kumar 61cd9c9fc2 [Coverage] Fix crash when handling certain macro expansions
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
2016-02-08 19:25:45 +00:00
Vedant Kumar f2b57cf149 [Coverage] Use a set to track visited FileIDs (NFC)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@259061 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-28 17:52:18 +00:00
Vedant Kumar 62a6c88a53 [Coverage] Reduce complexity of adding function mapping records
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
2016-01-21 19:25:35 +00:00
Xinliang David Li b5997a7e74 Reference the updated function name /NFC
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@258261 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-20 00:24:52 +00:00
Xinliang David Li 328d83f2b2 Fix local variable name /NFC
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@258106 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-19 00:49:06 +00:00
Xinliang David Li 81238425d2 [PGO] Simplify coverage mapping lowering
Coverage mapping data may reference names of functions
that are skipped by FE (e.g, unused inline functions). Since
those functions are skipped, normal instr-prof function lowering
pass won't put those names in the right section, so special 
handling is needed to walk through coverage mapping structure
and recollect the references.

With this patch, only names that are skipped are processed. This
simplifies the lowering code and it no longer needs to make 
assumptions coverage mapping data layout. It should also be 
more efficient.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@257092 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-07 20:05:55 +00:00
Xinliang David Li b0da766c2f [PGO] Cleanup: Use covmap header definition in the template file
This is one last remaining instrumentatation related structure
that needs to be migrate to use the centralized template
definition.  With this change, instrumentation code 
related to coverage module header will be kept in sync
with the coverage mapping reader. The remaining code
which makes implicit assumption about covmap control
structure layout in the the lowering pass will cleaned
up in a different patch. This patch is not intended to
have no functional change.




git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256714 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-03 19:25:54 +00:00
Sanjay Patel 76fc8176f8 use auto for obvious type; NFC
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256393 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-24 21:11:29 +00:00
Xinliang David Li cca12de649 Use profile data template file for covmap func record (NFC)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@252147 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-05 05:46:39 +00:00
Xinliang David Li 0a6b992d56 Use newly introduced interfaces in LLVM (NFC)
Replaced references to raw strings in instrumentation
and coverage code.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@251072 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-22 22:25:11 +00:00
Yaron Keren 4d9c4a9b23 Replace double negation of !FileID.isInvalid() with FileID.isValid().
+couple more of double-negated !SourceLocation.isInvalid() unfixed in r249228.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@249235 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-03 10:46:20 +00:00
Yaron Keren facf2d2c3b Replace double-negated !SourceLocation.isInvalid() with SourceLocation.isValid().
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@249228 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-03 05:15:57 +00:00
Craig Topper 9f31d79132 Remove move constructor and assignment operator from SourceMappingRegion. The types of the fields are trivially copyable. NFC
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@248659 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-26 05:10:16 +00:00
Craig Topper 7bba9558b8 Fix a couple other places that were returning SourceLocation by reference. NFC
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@248658 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-26 05:10:14 +00:00
Pete Cooper 34219cae4a Use llvm::reverse to make a bunch of loops use foreach. NFC.
In llvm commit r243581, a reverse range adapter was added which allows
us to change code such as

  for (auto I = Fields.rbegin(), E = Fields.rend(); I != E; ++I) {

in to

  for (const FieldDecl *I : llvm::reverse(Fields))

This commit changes a few of the places in clang which are eligible to use
this new adapter.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@243663 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-30 17:22:52 +00:00
Justin Bogner bd40a9cd8e InstrProf: Don't extend coverage regions into the catch keyword
The catch keyword isn't really part of a region, so it's fairly
meaningless to extend into it. This was usually harmless, but it could
crash when catch blocks involved macros in strange ways.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@243066 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-23 23:24:21 +00:00
Justin Bogner 92d5b410b9 InstrProf: Promote this assert to a report_fatal_error
If this assert does fire, the no-asserts behaviour is an infinite
loop. It's better to crash in this case so we get a crash report and
stop wasting the user's cpu cycles.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@242591 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-17 23:31:21 +00:00
Benjamin Kramer 247b5bd74b Switch users of the 'for (StmtRange range = stmt->children(); range; ++range)‘ pattern to range for loops.
The pattern was born out of the lack of range-based for loops in C++98
and is somewhat obscure. No functionality change intended.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241300 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-02 21:03:14 +00:00
Justin Bogner e06d40075e InstrProf: Add a comment to clarify an argument
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241296 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-02 20:47:25 +00:00
Justin Bogner cafa2f92bd InstrProf: Pack the coverage mapping structs that we write out
When we read this data we treat it as unaligned and packed, so we
should really be explicit about that when we write it.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241218 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-02 00:42:32 +00:00
Justin Bogner 7f949a04e3 InstrProf: Fix a crash when an implicit def appears in a macro
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240452 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-23 20:29:09 +00:00
Alexander Kornienko 8ca7705aa3 Revert r240270 ("Fixed/added namespace ending comments using clang-tidy").
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240353 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-22 23:07:51 +00:00
Alexander Kornienko ac58acc7f2 Fixed/added namespace ending comments using clang-tidy. NFC
The patch is generated using this command:

  $ tools/extra/clang-tidy/tool/run-clang-tidy.py -fix \
      -checks=-*,llvm-namespace-comment -header-filter='llvm/.*|clang/.*' \
      work/llvm/tools/clang

To reduce churn, not touching namespaces spanning less than 10 lines.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240270 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-22 09:47:44 +00:00
Justin Bogner 2e855badf1 InstrProf: Fix coverage mapping when "if" is a macro
We were propagating the coverage map into the body of an if statement,
but not into the condition thereafter. This is fine as long as the two
locations are in the same virtual file, but they won't be when the
"if" part of the statement is from a macro and the condition is not.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239803 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-16 06:24:15 +00:00
Justin Bogner 84a3a5ee34 InstrProf: Only disable coverage in built-in macros, not all system macros
The issue I was trying to solve in r236547 was about built-in macros,
but I disabled coverage in all system macros. This is actually a bit
of overkill, and makes the display of coverage around system macros
degrade unnecessarily. Instead, limit this to builtins specifically.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237397 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-14 22:14:10 +00:00
Justin Bogner f3509fceef InstrProf: Don't start or end coverage regions inside of system macros
It doesn't make much sense to try to show coverage inside system
macros, and source locations in builtins confuses the coverage
mapping. Just avoid doing this.

Fixes an assert that fired when a __block storage specifier starts a
region.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236547 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-05 21:46:14 +00:00
Justin Bogner 88c8a7cc71 InstrProf: Fix a coverage crash where a macro begins in an unreachable block
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236335 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-01 19:23:34 +00:00
Richard Trieu 13ce320747 Fix -Wpessimizing-move by removing call to std::move
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236281 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-30 23:13:52 +00:00
Justin Bogner dd4d8b2b5f InstrProf: Make sure coverage propagates out of foreach loops correctly
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236264 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-30 21:31:02 +00:00
Justin Bogner 7f4fa8c5a9 InstrProf: Mark code regions after throw expressions as unreachable
We weren't setting regions as being unreachable after C++ throw
expressions, leading to incorrect count propagations.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235967 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-28 06:31:55 +00:00
Justin Bogner ec83e36968 InstrProf: Fix coverage maps for conditional operators
This fixes a crash when we're emitting coverage and a macro appears
between two binary conditional operators, ie, "foo ?: MACRO ?: bar",
and fixes the interaction of macros and conditional operators in
general.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235793 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-24 23:37:57 +00:00
Richard Trieu 2142eabc7c Change range-based for-loops to be -Wrange-loop-analysis clean.
No functionality change.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@234964 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-15 01:21:42 +00:00
Justin Bogner 293a0c4d8d InstrProf: Handle whitespace and comments at the ends of macros
When we try to find the end loc for a token, we have to re-lex the
token. This was running into a problem when we'd store the end loc of
a macro's coverage region, since we wouldn't actually be at the
beginning of a token when we tried to re-lex it, leading us to do
silly things (and eventually assert) when whitespace or comments
followed.

This pushes our use of getPreciseTokenLocEnd earlier, so that we won't
call it when it doesn't make sense to. It also removes an unnecessary
adjustment by 1 that was working around this problem in some cases.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@233169 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-25 04:13:49 +00:00
Justin Bogner bf25ca0250 InstrProf: Make sure counts in lambdas don't escape to the parent scope
When generating coverage maps, we were traversing the body as if it
were part of the parent function, but this doesn't make sense since
we're currently counting lambdas as separate functions.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@230304 91177308-0d34-0410-b5e6-96231b3b80d8
2015-02-24 04:13:56 +00:00