summaryrefslogtreecommitdiffstats
path: root/llvm/utils/FileCheck/FileCheck.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Refactor FileCheck to make it usable as an APIAditya Nandakumar2018-08-071-1442/+29
| | | | | | | | | | https://reviews.llvm.org/D50283 reviewed by bogner This patch refactors FileCheck's implementation into support so it can be used from C++ in other places (Unit tests). llvm-svn: 339192
* [FileCheck] Provide an option for FileCheck to dump original input to stderr ↵George Karpenkov2018-07-201-1/+12
| | | | | | | | | | | | | | | | on failure The option can be either set using environment variable (e.g. env FILECHECK_DUMP_INPUT_ON_FAILURE=1 ninja check-fuzzer) or with a FileCheck flag. This can be extremely useful for debugging, cf. https://groups.google.com/forum/#!topic/llvm-dev/kLrzg8OM_h8 for discussion. Differential Revision: https://reviews.llvm.org/D49328 llvm-svn: 337609
* [FileCheck] Fix search ranges for DAG-NOT-DAGJoel E. Denny2018-07-201-46/+46
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A DAG-NOT-DAG is a CHECK-DAG group, X, followed by a CHECK-NOT group, N, followed by a CHECK-DAG group, Y. Let y be the initial directive of Y. This patch makes the following changes to the behavior: 1. Directives in N can no longer match within part of Y's match range just because y happens not to be the earliest match from Y. Specifically, this patch withdraws N's search range end from y's match range start to Y's match range start. 2. y can no longer match within X's match range, where a y match produced a reordering complaint, which is thus no longer possible. Specifically, this patch withdraws y's search range start from X's permitted range start to X's match range end, which was already the search range start for other members of Y. Both of these changes can only increase the number of test passes: #1 constrains the ability of CHECK-NOTs to match, and #2 expands the ability of CHECK-DAGs to match without complaints. These changes are based on discussions at: <http://lists.llvm.org/pipermail/llvm-dev/2018-May/123550.html> <https://reviews.llvm.org/D47106> which conclude that: 1. These changes simplify the FileCheck conceptual model. First, it makes search ranges for DAG-NOT-DAG more consistent with other cases. Second, it was confusing that y was treated differently from the rest of Y. 2. These changes add theoretical use cases for DAG-NOT-DAG that had no obvious means to be expressed otherwise. We can justify the first half of this assertion with the observation that these changes can only increase the number of test passes. 3. Reordering detection for DAG-NOT-DAG had no obvious real benefit. We don't have evidence from real uses cases to help us debate conclusions #2 and #3, but #1 at least seems intuitive. Reviewed By: probinson Differential Revision: https://reviews.llvm.org/D48986 llvm-svn: 337605
* [FileCheck] Implement -v and -vv for tracing matchesJoel E. Denny2018-07-131-33/+137
| | | | | | | | | | | | | | | | | | -v prints all directive pattern matches. -vv additionally prints info that might be noise to users but that can be helpful to FileCheck developers. To maximize code reuse and to make diagnostics more consistent, this patch also adjusts and extends some of the existing diagnostics. CHECK-NOT failures now report variables uses. Many more diagnostics now report the check prefix and kind of directive. Reviewed By: probinson Differential Revision: https://reviews.llvm.org/D47114 llvm-svn: 336967
* [FileCheck] Don't permit overlapping CHECK-DAGJoel E. Denny2018-07-111-12/+53
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | That is, make CHECK-DAG skip matches that overlap the matches of any preceding consecutive CHECK-DAG directives. This change makes CHECK-DAG more consistent with other directives, and there is evidence it makes CHECK-DAG more intuitive and less error-prone. See the RFC discussion starting at: http://lists.llvm.org/pipermail/llvm-dev/2018-May/123010.html Moreover, this behavior enables CHECK-DAG groups for unordered, non-unique strings or patterns. For example, it is useful for verifying output or logs from a parallel program, such as the OpenMP runtime. This patch also implements the command-line option -allow-deprecated-dag-overlap, which reverts CHECK-DAG to the old overlapping behavior. This option should not be used in new tests. It is meant only for the existing tests that are broken by this change and that need time to update. See the following bugzilla issue for tracking of such tests: https://bugs.llvm.org/show_bug.cgi?id=37532 Patches to add -allow-deprecated-dag-overlap to those tests will follow immediately. Reviewed By: probinson Differential Revision: https://reviews.llvm.org/D47106 llvm-svn: 336847
* Revert r336830: [FileCheck] Don't permit overlapping CHECK-DAGJoel E. Denny2018-07-111-53/+12
| | | | | | | Companion patches are failing to commit, and this patch alone breaks many tests. llvm-svn: 336833
* [FileCheck] Don't permit overlapping CHECK-DAGJoel E. Denny2018-07-111-12/+53
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | That is, make CHECK-DAG skip matches that overlap the matches of any preceding consecutive CHECK-DAG directives. This change makes CHECK-DAG more consistent with other directives, and there is evidence it makes CHECK-DAG more intuitive and less error-prone. See the RFC discussion starting at: http://lists.llvm.org/pipermail/llvm-dev/2018-May/123010.html Moreover, this behavior enables CHECK-DAG groups for unordered, non-unique strings or patterns. For example, it is useful for verifying output or logs from a parallel program, such as the OpenMP runtime. This patch also implements the command-line option -allow-deprecated-dag-overlap, which reverts CHECK-DAG to the old overlapping behavior. This option should not be used in new tests. It is meant only for the existing tests that are broken by this change and that need time to update. See the following bugzilla issue for tracking of such tests: https://bugs.llvm.org/show_bug.cgi?id=37532 Patches to add -allow-deprecated-dag-overlap to those tests will follow immediately. Reviewed By: probinson Differential Revision: https://reviews.llvm.org/D47106 llvm-svn: 336830
* [FileCheck] Add CHECK-EMPTY directive for checking for blank linesJames Henderson2018-06-261-10/+44
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Prior to this change, there was no clean way of getting FileCheck to check that a line is completely empty. The expected way of using "CHECK: {{^$}}" does not work because the '^' matches the end of the previous match (this behaviour may be desirable in certain instances). For the same reason, "CHECK-NEXT: {{^$}}" will fail when the previous match was at the end of the line, as the pattern will match there. Using the recommended [[:space:]] to match an explicit new line could also match a space, and thus is not always desired. Literal '\n' matches also do not work. A workaround was suggested in the review, but it is a little clunky. This change adds a new directive that behaves the same as CHECK-NEXT, except that it only matches against empty lines (nothing, not even whitespace, is allowed). As with CHECK-NEXT, it will fail if more than one newline occurs before the next blank line. Example usage: ; test.txt foo bar ; CHECK: foo ; CHECK-EMPTY: ; CHECK-NEXT: bar Differential Revision: https://reviews.llvm.org/D28896 Reviewed by: probinson llvm-svn: 335613
* Define InitLLVM to do common initialization all at once.Rui Ueyama2018-04-131-4/+2
| | | | | | | | | | | We have a few functions that virtually all command wants to run on process startup/shutdown. This patch adds InitLLVM class to do that all at once, so that we don't need to copy-n-paste boilerplate code to each llvm command's main() function. Differential Revision: https://reviews.llvm.org/D45602 llvm-svn: 330046
* [FileCheck] - Fix possible buffer out of bounds access when parsing ↵George Rimar2018-01-161-0/+3
| | | | | | | | | | | | | | | | | | | --check-prefix. FileCheck tool crashes when trying to parse --check-prefix argument if there is no any data after it. For example test like following would crash if there are no symbols and no EOL mark after `boom`: # REQUIRES: x86 # RUN: <skipped few lines> # RUN: llvm-readobj -t %t | FileCheck %s --check-prefix=boom Patch fixes the issue. Differential revision: https://reviews.llvm.org/D42057 llvm-svn: 322536
* Add a -D flag to FileCheck to define variablesAlexander Richardson2017-11-071-0/+7
| | | | | | | | | | | | | | | | Summary: This makes it very easy to test files that only differ in a constant value somewhere in the test case. Reviewers: jlebar, hfinkel, chandlerc, probinson Reviewed By: probinson Subscribers: probinson, llvm-commits Differential Revision: https://reviews.llvm.org/D39629 llvm-svn: 317572
* [FileCheck] Don't scan past the closing CHECK-DAG for CHECK-NOT inside CHECK-DAGBenjamin Kramer2017-06-071-1/+1
| | | | | | | If there's enough data in fron of it the skipped region would just become arbitrarily large, and we scan for the CHECK-NOT everywhere. llvm-svn: 304900
* Test commit.James Henderson2017-03-141-1/+1
| | | | llvm-svn: 297731
* [FileCheck] Added --enable-var-scope option to enable scope for regex variables.Artem Belevich2017-03-091-8/+33
| | | | | | | | | | | | | If `--enable-var-scope` is in effect, variables with names that start with `$` are considered to be global. All other variables are local. All local variables get undefined at the beginning of each CHECK-LABEL block. Global variables are not affected by CHECK-LABEL. This makes it easier to ensure that individual tests are not affected by variables set in preceding tests. Differential Revision: https://reviews.llvm.org/D30749 llvm-svn: 297396
* [FileCheck] Fix --strict-whitespace --match-full-linesTom de Vries2016-12-181-5/+7
| | | | | | | Make sure FileCheck --strict-whitespace --match-full-lines translates 'CHECK: bla ' into pattern '^ bla $' instead of pattern '^bla$'. llvm-svn: 290069
* [FileCheck] Fix comment in ReadCheckFileTom de Vries2016-12-181-1/+1
| | | | | | | The comment in ReadCheckFile claims that both leading and trailing whitespace are removed, but the associated statement only removes leading whitespace. llvm-svn: 290061
* [FileCheck] Re-implement the logic to find each check prefix in theChandler Carruth2016-12-111-93/+94
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | check file to not be unreasonably slow in the face of multiple check prefixes. The previous logic would repeatedly scan potentially large portions of the check file looking for alternative prefixes. In the worst case this would scan most of the file looking for a rare prefix between every single occurance of a common prefix. Even if we bounded the scan, this would do bad things if the order of the prefixes was "unlucky" and the distant prefix was scanned for first. None of this is necessary. It is straightforward to build a state machine that recognizes the first, longest of the set of alternative prefixes. That is in fact exactly whan a regular expression does. This patch builds a regular expression once for the set of prefixes and then uses it to search incrementally for the next prefix. This requires some threading of state but actually makes the code dramatically simpler. I've also added a big comment describing the algorithm as it was not at all obvious to me when I started. With this patch, several previously pathological test cases in test/CodeGen/X86 are 5x and more faster. Overall, running all tests under test/CodeGen/X86 uses 10% less CPU after this, and because all the slowest tests were hitting this, finishes in 40% less wall time on my system (going from just over 5.38s to just over 3.23s) on a release build! This patch substantially improves the time of all 7 X86 tests that were in the top 20 reported by --time-tests, 5 of them are completely off the list and the remaining 2 are much lower. (Sadly, the new tests on the list include 2 new X86 ones that are slow for unrelated reasons, so the count stays at 4 of the top 20.) It isn't clear how much this helps debug builds in aggregate in part because of the noise, but it again makes mane of the slowest x86 tests significantly faster (10% or more improvement). llvm-svn: 289382
* [FileCheck] Remove a parameter that was simply always set toChandler Carruth2016-12-111-9/+4
| | | | | | | | a commandline flag and test the flag directly. NFC. If we ever need this generality it can be added back. llvm-svn: 289381
* [FileCheck] Clean up doxygen comments throughout. NFC.Chandler Carruth2016-12-111-70/+62
| | | | llvm-svn: 289380
* [FileCheck] Run clang-format over this code. NFC.Chandler Carruth2016-12-111-118/+108
| | | | | | | | | | This fixes one formatting goof I left in my previous commit and *many* other inconsistencies. I'm planning to make substantial changes here and so wanted to get to a clean baseline. llvm-svn: 289379
* Refactor FileCheck some to reduce memory allocation and copying. AlsoChandler Carruth2016-12-111-87/+90
| | | | | | | | | | | | | | | | | | | | | | | | | | | | make some readability improvements. Both the check file and input file have to be fully buffered to normalize their whitespace. But previously this would be done in a stack SmallString and then copied into a heap allocated MemoryBuffer. That seems pretty wasteful, especially for something like FileCheck where there are only ever two such entities. This just rearranges the code so that we can keep the canonicalized buffers on the stack of the main function, use reasonably large stack buffers to reduce allocation. A rough estimate seems to show that about 80% of LLVM's .ll and .s files will fit into a 4k buffer, so this should completely avoid heap allocation for the buffer in those cases. My system's malloc is fast enough that the allocations don't directly show up in timings. However, on some very slow test cases, this saves 1% - 2% by avoiding the copy into the heap allocated buffer. This also splits out the code which checks the input into a helper much like the code to build the checks as that made the code much more readable to me. Nit picks and suggestions welcome here. It has really exposed a *bunch* of stuff that could be cleaned up though, so I'm probably going to go and spring clean all of this code as I have more changes coming to speed things up. llvm-svn: 289378
* FileCheck: Minor cleanup of the class PatternSaleem Abdulrasool2016-08-261-8/+6
| | | | | | | | | 1. Add the "explicit" specifier to the single-argument constructor of Pattern 2. Reorder the fields to remove excessive padding (8 bytes). Patch by Alexander Shaposhnikov! llvm-svn: 279832
* [FileCheck] Add --check-prefixes as a shorthand for multiple --check-prefix ↵Daniel Sanders2016-06-141-0/+5
| | | | | | | | | | | | | | | | | options. Summary: This new alias takes a comma separated list of prefixes which allows '--check-prefix=A --check-prefix=B --check-prefix=C' to be written as '--check-prefixes=A,B,C'. Reviewers: probinson Subscribers: probinson, llvm-commits, dsanders Differential Revision: http://reviews.llvm.org/D21293 llvm-svn: 272670
* Search for llvm-symbolizer binary in the same directory as argv[0], beforeRichard Smith2016-06-091-1/+1
| | | | | | | looking for it along $PATH. This allows installs of LLVM tools outside of $PATH to find the symbolizer and produce pretty backtraces if they crash. llvm-svn: 272232
* FileCheck: dump command line context with empty inputXinliang David Li2016-05-271-0/+8
| | | | | | Differential Revision: http://reviews.llvm.org/D20716 llvm-svn: 271047
* Reapply r262092: [FileCheck] Abort if -NOT is combined with another suffix.Paul Robinson2016-02-291-1/+18
| | | | | | | | | Combinations of suffixes that look useful are actually ignored; complaining about them will avoid mistakes. Differential Revision: http://reviews.llvm.org/D17587 llvm-svn: 262263
* Revert r262092, caught LLD testsPaul Robinson2016-02-261-18/+1
| | | | llvm-svn: 262093
* [FileCheck] Abort if -NOT is combined with another suffix.Paul Robinson2016-02-261-1/+18
| | | | | | | | | Combinations of suffixes that look useful actually are ignored; complaining about them will avoid mistakes. Differential Revision: http://reviews.llvm.org/D17587 llvm-svn: 262092
* Add -match-full-lines argument to FileCheck.James Y Knight2016-02-111-17/+32
| | | | | | | This is useful for some tests where more-exact matching is useful, such as clang's Preprocessor tests. llvm-svn: 260540
* StringRef-ify some Option APIsDavid Blaikie2015-11-171-1/+1
| | | | | | | | Patch by Eugene Kosov! Differential Revision: http://reviews.llvm.org/D14711 llvm-svn: 253360
* Cleanup places that passed SMLoc by const reference to pass it by value ↵Craig Topper2015-09-201-1/+1
| | | | | | instead. NFC llvm-svn: 248135
* [FileCheck] Use range-based for loops. NFC.Benjamin Kramer2015-09-101-26/+14
| | | | llvm-svn: 247272
* Replace push_back(Constructor(foo)) with emplace_back(foo) for non-trivial typesBenjamin Kramer2015-05-291-8/+4
| | | | | | | | | | | | | | | | | | | | If the type isn't trivially moveable emplace can skip a potentially expensive move. It also saves a couple of characters. Call sites were found with the ASTMatcher + some semi-automated cleanup. memberCallExpr( argumentCountIs(1), callee(methodDecl(hasName("push_back"))), on(hasType(recordDecl(has(namedDecl(hasName("emplace_back")))))), hasArgument(0, bindTemporaryExpr( hasType(recordDecl(hasNonTrivialDestructor())), has(constructExpr()))), unless(isInTemplateInstantiation())) No functional change intended. llvm-svn: 238602
* [NFC] Updating FileCheck to reduce the std::vector interface used via cl::list.Chris Bieneman2015-04-291-6/+8
| | | | llvm-svn: 236164
* Fix FileCheck: substr() expect the length of the string as 2nd argMehdi Amini2015-03-121-2/+1
| | | | | | | | The code assumed that substr() was taking start,end while it takes start,length. From: Mehdi Amini <mehdi.amini@apple.com> llvm-svn: 231988
* FileCheck: Add CHECK-SAMEDuncan P. N. Exon Smith2015-02-261-2/+47
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add `CHECK-SAME`, which requires that the pattern matches on the *same* line as the previous `CHECK`/`CHECK-NEXT` -- in other words, no newline is allowed in the skipped region. This is similar to `CHECK-NEXT`, which requires exactly 1 newline in the skipped region. My motivation is to simplify checking the long lines of LLVM assembly for the new debug info hierarchy. This allows CHECK sequences like the following: CHECK: ![[REF]] = !SomeMDNode( CHECK-SAME: file: ![[FILE:[0-9]+]] CHECK-SAME: otherField: 93{{[,)]}} which is equivalent to: CHECK: ![[REF]] = !SomeMDNode({{.*}}file: ![[FILE:[0-9]+]]{{.*}}otherField: 93{{[,)]}} While this example just has two fields, many nodes in debug info have more than that. `CHECK-SAME` will keep the logic easy to follow. Morever, it enables interleaving `CHECK-NOT`s without allowing newlines. Consider the following: CHECK: ![[REF]] = !SomeMDNode( CHECK-SAME: file: ![[FILE:[0-9]+]] CHECK-NOT: unexpectedField: CHECK-SAME: otherField: 93{{[,)]}} CHECK-NOT: otherUnexpectedField: CHECK-SAME: ) which doesn't seem to have an equivalent `CHECK` line. llvm-svn: 230612
* Make StringSet::insert return pair<iterator, bool> like other ↵David Blaikie2014-11-191-1/+1
| | | | | | | | | | | | self-associative containers StringSet is still a bit dodgy in that it exposes the raw iterator of the StringMap parent, which exposes the weird detail that StringSet actually has a 'value'... but anyway, this is useful for a handful of clients that want to reference the newly inserted/persistent string data in the StringSet/Map/Entry/thing. llvm-svn: 222302
* Return a std::unique_ptr when creating a new MemoryBuffer.Rafael Espindola2014-08-271-4/+5
| | | | llvm-svn: 216583
* Explicitly pass ownership of the MemoryBuffer to AddNewSourceBuffer using ↵David Blaikie2014-08-211-18/+19
| | | | | | std::unique_ptr llvm-svn: 216223
* FileCheck: Add a flag to allow checking empty inputJustin Bogner2014-08-071-1/+6
| | | | | | | | | | | | | Currently FileCheck errors out on empty input. This is usually the right thing to do, but makes testing things like "this command does not emit some error message" hard to test. This usually leads to people using "command 2>&1 | count 0" instead, and then the bots that use guard malloc fail a few hours later. By adding a flag to FileCheck that allows empty inputs, we can make tests that consist entirely of "CHECK-NOT" lines feasible. llvm-svn: 215127
* Remove some calls to std::move.Rafael Espindola2014-08-011-1/+1
| | | | | | | | | Instead of moving out the data in a ErrorOr<std::unique_ptr<Foo>>, get a reference to it. Thanks to David Blaikie for the suggestion. llvm-svn: 214516
* Simplify the code a bit with std::unique_ptr.Rafael Espindola2014-08-011-9/+5
| | | | llvm-svn: 214514
* Fix FileCheck crash when empty prefix is passed.Eli Bendersky2014-07-291-0/+4
| | | | llvm-svn: 214210
* Add FileCheck -implicit-check-not option to allow stricter tests without ↵Alexander Kornienko2014-07-111-1/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | adding too many CHECK-NOTs manually. Summary: Add FileCheck -implicit-check-not option which allows specifying a pattern that should only occur in the input when explicitly matched by a positive check. This feature allows checking tool diagnostics in a way clang -verify does it for compiler diagnostics. The option has been tested on a number of clang-tidy checks, I'll post a link to the clang-tidy patch to this thread. Once there's an agreement on the general direction, I can add tests and documentation. Reviewers: djasper, bkramer Reviewed By: bkramer Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D4462 llvm-svn: 212810
* Update the MemoryBuffer API to use ErrorOr.Rafael Espindola2014-07-061-10/+13
| | | | llvm-svn: 212405
* Revert "Introduce a string_ostream string builder facilty"Alp Toker2014-06-261-1/+2
| | | | | | Temporarily back out commits r211749, r211752 and r211754. llvm-svn: 211814
* Introduce a string_ostream string builder faciltyAlp Toker2014-06-261-2/+1
| | | | | | | | | | | | | | | | | | | | string_ostream is a safe and efficient string builder that combines opaque stack storage with a built-in ostream interface. small_string_ostream<bytes> additionally permits an explicit stack storage size other than the default 128 bytes to be provided. Beyond that, storage is transferred to the heap. This convenient class can be used in most places an std::string+raw_string_ostream pair or SmallString<>+raw_svector_ostream pair would previously have been used, in order to guarantee consistent access without byte truncation. The patch also converts much of LLVM to use the new facility. These changes include several probable bug fixes for truncated output, a programming error that's no longer possible with the new interface. llvm-svn: 211749
* Remove the last uses of 'using std::error_code'Rafael Espindola2014-06-131-5/+2
| | | | | | This finishes the transition to std::error_code. llvm-svn: 210877
* Don't use 'using std::error_code' in include/llvm.Rafael Espindola2014-06-121-0/+1
| | | | | | This should make sure that most new uses use the std prefix. llvm-svn: 210835
* Remove system_error.h.Rafael Espindola2014-06-121-1/+1
| | | | | | | This is a minimal change to remove the header. I will remove the occurrences of "using std::error_code" in a followup patch. llvm-svn: 210803
OpenPOWER on IntegriCloud