Commit Graph

90 Commits

Author SHA1 Message Date
Alexey Bataev 86ec3fe950 [OPENMP] Fix PR38256: Fix locations of the artificial conditional op.
Fixed the source locations of the conditional op so that they don'r
crash coverage pass.

llvm-svn: 337928
2018-07-25 14:40:26 +00:00
Vedant Kumar fd657bd4be [Coverage] Remove a test dependency on the itanium ABI
This should address a bot failure:
http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/9994/

llvm-svn: 333775
2018-06-01 17:11:18 +00:00
Vedant Kumar d781d97ed4 [Coverage] End deferred regions before labels, fixes PR35867
A deferred region should end before the start of a label, and should not
extend to the start of the label sub-statement.

Fixes llvm.org/PR35867.

llvm-svn: 333715
2018-06-01 00:37:13 +00:00
Vedant Kumar 61763b65af [Coverage] Discard the last uncompleted deferred region in a decl
Discard the last uncompleted deferred region in a decl, if one exists.
This prevents lines at the end of a function containing only whitespace
or closing braces from being marked as uncovered, if they follow a
region terminator (return/break/etc).

The previous behavior was to heuristically complete deferred regions at
the end of a decl. In practice this ended up being too brittle for too
little gain. Users would complain that there was no way to reach full
code coverage because whitespace at the end of a function would be
marked uncovered.

rdar://40238228

Differential Revision: https://reviews.llvm.org/D46918

llvm-svn: 333609
2018-05-30 23:35:44 +00:00
Vedant Kumar 3e2ae49a25 [Coverage] Handle break/continue outside of loop bodies
Teach the coverage mapping logic to handle break or continue statements
within for loop increments.

Fixes llvm.org/PR36406.

llvm-svn: 325319
2018-02-16 07:59:43 +00:00
Vedant Kumar a14a1f923f [Parse] Forward brace locations to TypeConstructExpr
When parsing C++ type construction expressions with list initialization,
forward the locations of the braces to Sema.

Without these locations, the code coverage pass crashes on the given test
case, because the pass relies on getLocEnd() returning a valid location.

Here is what this patch does in more detail:

  - Forwards init-list brace locations to Sema (ParseExprCXX),
  - Builds an InitializationKind with these locations (SemaExprCXX), and
  - Uses these locations for constructor initialization (SemaInit).

The remaining changes fall out of introducing a new overload for
creating direct-list InitializationKinds.

Testing: check-clang, and a stage2 coverage-enabled build of clang with
asserts enabled.

Differential Revision: https://reviews.llvm.org/D41921

llvm-svn: 322729
2018-01-17 18:53:51 +00:00
Vedant Kumar fa8fa044ec [Coverage] Emit gap areas in braces-optional statements (PR35387)
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
llvm-svn: 319373
2017-11-29 22:25:14 +00:00
Vedant Kumar f9a0d44eea [Coverage] Emit deferred regions in headers
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

llvm-svn: 317760
2017-11-09 02:33:40 +00:00
Vedant Kumar 8046d22a36 [Coverage] Complete top-level deferred regions before labels
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

llvm-svn: 317759
2017-11-09 02:33:39 +00:00
Vedant Kumar 2e8c875905 [Coverage] Emit a gap area after if conditions
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

llvm-svn: 317758
2017-11-09 02:33:38 +00:00
Vedant Kumar 341bf42991 [Coverage] Discard deferred region in closing if-else
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.

llvm-svn: 315982
2017-10-17 07:47:39 +00:00
Vedant Kumar e5f06a81a8 [Coverage] Explicitly mark the l.h.s of && and || (fixes PR33465)
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 '||'.

llvm-svn: 315979
2017-10-17 06:51:54 +00:00
Vedant Kumar 0acf3434e7 [Coverage] Add an option to emit limited coverage info
Add an option to emit limited coverage info for unused decls. It's just a
cl::opt for now to allow us to experiment quickly.

When building llc, this results in an 84% size reduction in the llvm_covmap
section, and a similar size reduction in the llvm_prf_names section. In
practice I expect the size reduction to be roughly quadratic with the size of
the program.

The downside is that coverage for headers will no longer be complete. This will
make the line/function/region coverage metrics incorrect, since they will be
artificially high. One mitigation would be to somehow disable those metrics
when using limited-coverage=true.

This is related to: llvm.org/PR34533 (make SourceBasedCodeCoverage scale)

Differential Revision: https://reviews.llvm.org/D38107

llvm-svn: 314002
2017-09-22 18:23:04 +00:00
Vedant Kumar ef8e05ff07 [Coverage] Remove deferred region for trailing return, fixes PR34611
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.

llvm-svn: 313603
2017-09-19 00:29:46 +00:00
Vedant Kumar a1c4deb792 [Coverage] Use a new API to label gap areas
This will make it possible for llvm-cov to pick better line execution
counts, and is part of the fix for llvm.org/PR34612.

llvm-svn: 313598
2017-09-18 23:37:30 +00:00
Vedant Kumar 3919a501f3 [Lexer] Report more precise skipped regions (PR34166)
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

llvm-svn: 312947
2017-09-11 20:47:42 +00:00
Vedant Kumar 747b0e2905 [Coverage] Precise region termination with deferred regions (reapply)
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.

llvm-svn: 312818
2017-09-08 18:44:56 +00:00
Kuba Mracek 5b57633a45 [clang] Get rid of "%T" expansions
The %T lit expansion expands to a common directory shared between all the tests in the same directory, which is unexpected and unintuitive, and more importantly, it's been a source of subtle race conditions and flaky tests. In https://reviews.llvm.org/D35396, it was agreed that it would be best to simply ban %T and only keep %t, which is unique to each test. When a test needs a temporary directory, it can just create one using mkdir %t.

This patch removes %T in clang.

Differential Revision: https://reviews.llvm.org/D36437

llvm-svn: 310950
2017-08-15 19:47:06 +00:00
Eli Friedman 181dfe4c92 [coverage] Special-case calls to noreturn functions.
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

llvm-svn: 310406
2017-08-08 20:10:14 +00:00
Vedant Kumar a7764adcbb Revert "[Coverage] Precise region termination with deferred regions"
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.

llvm-svn: 310154
2017-08-05 00:34:10 +00:00
Vedant Kumar 0b48042a65 Revert "[coverage] Special-case calls to noreturn functions."
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.

llvm-svn: 310019
2017-08-04 04:08:23 +00:00
Vedant Kumar 85e6dce1eb [Coverage] Precise region termination with deferred regions
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
llvm-svn: 310010
2017-08-04 00:29:20 +00:00
Eli Friedman 2d30c64ae3 [coverage] Special-case calls to noreturn functions.
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

llvm-svn: 309995
2017-08-03 22:27:36 +00:00
Eli Friedman 7f53fbfcdc [coverage] Make smaller regions for the first case of a switch.
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

llvm-svn: 309901
2017-08-02 23:22:50 +00:00
Vedant Kumar bc370f0c18 [Coverage] Avoid null deref in skipRegionMappingForDecl (fixes PR32761)
Patch by Adam Folwarczny!

Differential Revision: https://reviews.llvm.org/D32406

llvm-svn: 301249
2017-04-24 20:52:04 +00:00
Vedant Kumar f224d707df [Coverage] Don't emit mappings for functions in dependent contexts (fixes PR32679)
The coverage implementation marks functions which won't be emitted as
'deferred', so that it can emit empty coverage regions for them later
(once their linkages are known).

Functions in dependent contexts are an exception: if there isn't a full
instantiation of a function, it shouldn't be marked 'deferred'. We've
been breaking that rule without much consequence because we just ended
up with useless, extra, empty coverage mappings. With PR32679, this
behavior finally caused a crash, because clang marked a partial template
specialization as 'deferred', causing the MS mangler to choke in its
delayed-template-parsing mode:

  error: cannot mangle this template type parameter type yet
  (http://bugs.llvm.org/show_bug.cgi?id=32679)

Fix this by checking if a decl's context is a dependent context before
marking it 'deferred'.

Based on a patch by Adam Folwarczny!

Differential Revision: https://reviews.llvm.org/D32144

llvm-svn: 300723
2017-04-19 17:58:30 +00:00
NAKAMURA Takumi 3a59e1a78f clang/test/CoverageMapping/unused_names.c: Relax an expression for targeting PECOFF.
llvm-svn: 300303
2017-04-14 03:16:48 +00:00
Vedant Kumar 3ec213e05c Suppress uninteresting warnings in test/CoverageMapping, NFC.
llvm-svn: 296247
2017-02-25 07:05:41 +00:00
Vedant Kumar 9503004089 [profiling] Update test cases to deal with name variable change (NFC)
This is a re-try of r295085: fix up some test cases that assume that
profile name variables are preserved by the instrprof pass.

This catches one additional case in test/CoverageMapping/unused_names.c.

llvm-svn: 295101
2017-02-14 20:03:56 +00:00
Vedant Kumar 9d2a16b9b1 [Coverage] Support for C++17 if initializers
Differential Revision: https://reviews.llvm.org/D25572

llvm-svn: 284293
2016-10-14 23:38:16 +00:00
Vedant Kumar f2a6ec5521 [Coverage] Support for C++17 switch initializers
Differential Revision: https://reviews.llvm.org/D25539

llvm-svn: 284292
2016-10-14 23:38:13 +00:00
Alex Lorenz 08780529b3 [Coverage] The coverage region for switch covers the code after the switch.
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

llvm-svn: 282554
2016-09-27 23:30:36 +00:00
Igor Kudrin fc05ee344c [Coverage] Suppress creating a code region if the same area is covered by an 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

llvm-svn: 280199
2016-08-31 07:04:16 +00:00
Igor Kudrin 8545dae226 [Coverage] Prevent creating a redundant counter if a nested body ends with a 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

llvm-svn: 279962
2016-08-29 11:48:50 +00:00
Vedant Kumar efd319a2ad [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.

llvm-svn: 276716
2016-07-26 00:24:59 +00:00
Vedant Kumar 9fc15de174 [Coverage] Attempt to appease a Windows builder
The builder prints out the following IR:

  \5CCoverageMapping\5COutput\5Ctest\5Cf1.c

The updated test in r276367 expects path separators to be either '/' or
'\\', so it chokes on the unexpected "5C" stuff. I'm not sure what that
is, but I included a kludge that should work around it.

Failing bot:

  http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/8718

llvm-svn: 276370
2016-07-22 00:25:09 +00:00
Vedant Kumar fe28a0fdd5 [Coverage] Strengthen a test case
We should be able to use `mkdir` without turning on `REQUIRES: shell`.
Moreover, this test should check for a path separator which precedes the
relative filename to make sure that absolute paths are being used.

llvm-svn: 276367
2016-07-22 00:00:02 +00:00
Vedant Kumar d04929d875 [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.

llvm-svn: 275924
2016-07-18 22:32:02 +00:00
Vedant Kumar 14f8fb6864 [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.

llvm-svn: 275913
2016-07-18 21:01:27 +00:00
Vedant Kumar 93205af066 [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).

llvm-svn: 275121
2016-07-11 22:57:46 +00:00
Vedant Kumar 049908b296 [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.

llvm-svn: 273463
2016-06-22 19:57:58 +00:00
Igor Kudrin d9e1a61d31 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

llvm-svn: 271995
2016-06-07 10:07:51 +00:00
Igor Kudrin a8c1d8bb6d Revert [Coverage] Fix an assertion failure if the definition of an unused function spans multiple files.
r271969 The test case fails on Windows.

llvm-svn: 271976
2016-06-07 04:11:51 +00:00
Igor Kudrin 6fd589a763 [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

llvm-svn: 271969
2016-06-07 02:17:03 +00:00
Vedant Kumar 3836482abc [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.

llvm-svn: 271308
2016-05-31 18:06:19 +00:00
Vedant Kumar 95a2a7f2a1 [Lexer] Don't merge macro args from different macro files
The lexer sets the end location of macro arguments incorrectly *if*,
while merging consecutive args to fit into a single SLocEntry, it finds
args which come from different macro files.

Fix the issue by using separate SLocEntries in this situation.

This fixes a code coverage crasher (rdar://problem/26181005). Because
the lexer reported end locations for certain macro args incorrectly, we
would generate bogus coverage mappings with negative line offsets.

Reviewed-by: akyrtzi

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

llvm-svn: 270160
2016-05-19 23:44:02 +00:00
Igor Kudrin 0a7c9d110c [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

llvm-svn: 268511
2016-05-04 15:38:26 +00:00
Vedant Kumar 22bd871ea6 [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.

llvm-svn: 262697
2016-03-04 08:07:15 +00:00
Xinliang David Li 534ace01ad Restrengthen tests relaxed in r259955
llvm-svn: 261046
2016-02-17 00:58:13 +00:00
Vedant Kumar 39f01975ef [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

llvm-svn: 260129
2016-02-08 19:25:45 +00:00