aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/FileCheck/FileCheck.cpp
AgeCommit message (Collapse)AuthorFilesLines
2024-08-28[llvm] Prefer StringRef::substr to StringRef::slice (NFC) (#106330)Kazu Hirata1-1/+1
S.substr(N) is simpler than S.slice(N, StringRef::npos). Also, substr is probably better recognizable than slice thanks to std::string_view::substr.
2024-07-05[llvm] Avoid 'raw_string_ostream::str' (NFC)Youngsuk Kim1-1/+1
Since `raw_string_ostream` doesn't own the string buffer, it is desirable (in terms of memory safety) for users to directly reference the string buffer rather than use `raw_string_ostream::str()`. Work towards TODO item to remove `raw_string_ostream::str()`.
2024-06-13[llvm-project] Fix typo "seperate" (#95373)Jay Foad1-1/+1
2024-05-08[llvm] Use StringRef::operator== instead of StringRef::equals (NFC) (#91441)Kazu Hirata1-1/+1
I'm planning to remove StringRef::equals in favor of StringRef::operator==. - StringRef::operator==/!= outnumber StringRef::equals by a factor of 70 under llvm/ in terms of their usage. - The elimination of StringRef::equals brings StringRef closer to std::string_view, which has operator== but not equals. - S == "foo" is more readable than S.equals("foo"), especially for !Long.Expression.equals("str") vs Long.Expression != "str".
2024-03-05[FileCheck] Fix parsing empty global and pseudo variable names (#83667)Daniil Kovalev1-0/+6
Reland #82595 with fixes of build failures related to colored output. See https://lab.llvm.org/buildbot/#/builders/139/builds/60549 Use `%ProtectFileCheckOutput` to avoid colored output. Original commit message below. In `Pattern::parseVariable`, for global variables (those starting with '$') and for pseudo variables (those starting with '@') the first character is consumed before actual variable name parsing. If the name is empty, it leads to out-of-bound access to the corresponding `StringRef`. This patch adds an if statement against the case described.
2024-03-02Revert "[FileCheck] Fix parsing empty global and pseudo variable names" (#83657)Daniil Kovalev1-6/+0
Reverts llvm/llvm-project#82595 See build failure https://lab.llvm.org/buildbot/#/builders/139/builds/60549
2024-03-02[FileCheck] Fix parsing empty global and pseudo variable names (#82595)Daniil Kovalev1-0/+6
In `Pattern::parseVariable`, for global variables (those starting with '$') and for pseudo variables (those starting with '@') the first character is consumed before actual variable name parsing. If the name is empty, it leads to out-of-bound access to the corresponding `StringRef`. This patch adds an if statement against the case described.
2024-02-04[FileCheck] Simplify a use of StringRef::consume_front (NFC)Kazu Hirata1-3/+1
2024-02-03[FileCheck] Use StringRef::rtrim (NFC)Kazu Hirata1-3/+1
2024-01-19[FileCheck]: Fix diagnostics for NOT prefixes (#78412)Vinayak Dev1-28/+33
Fixes #70221 Fix a bug in FileCheck that corrects the error message when multiple prefixes are provided through --check-prefixes and one of them is a PREFIX-NOT. Earlier, only the first of the provided prefixes was displayed as the erroneous prefix, while the actual error might be on the prefix that occurred at the end of the prefix list in the input file. Now, the right NOT prefix is shown in the error message.
2023-12-11[llvm] Use StringRef::{starts,ends}_with (NFC) (#74956)Kazu Hirata1-16/+16
This patch replaces uses of StringRef::{starts,ends}with with StringRef::{starts,ends}_with for consistency with std::{string,string_view}::{starts,ends}_with in C++20. I'm planning to deprecate and eventually remove StringRef::{starts,ends}with.
2023-11-15[FileCheck] Don't use regex to find prefixes (#72237)Nikita Popov1-40/+62
FileCheck currently compiles a regular expression of the form `Prefix1|Prefix2|...` and uses it to find the next prefix in the input. If we had a fast regex implementation, this would be a useful thing to do, as the regex implementation would be able to match multiple prefixes more efficiently than a naive approach. However, with our actual regex implementation, finding the prefixes basically becomes O(InputLen * RegexLen * LargeConstantFactor), which is a lot worse than a simple string search. Replace the regex with StringRef::find(), and keeping track of the next position of each prefix. There are various ways this could be improved on, but it's already significantly faster that the previous approach. For me, this improves check-llvm time from 138.5s to 132.5s, so by around 4-5%. For vector-interleaved-load-i16-stride-7.ll in particular, test time drops from 5s to 2.5s.
2023-11-14[FileCheck] Avoid capturing group for {{regex}} (#72136)Nikita Popov1-3/+7
For `{{regex}}` we don't really need a capturing group, and only add it to properly handle cases like `{{foo|bar}}`. This is problematic, because the use of capturing groups makes our regex implementation slower (we have to go through the "dissect" stage, which can have quadratic complexity). Unfortunately, our regex implementation does not support non-capturing groups like `(?:regex)`. So instead, avoid adding the group entirely if the regex doesn't contain any alternations. This causes a slight difference in escaping behavior, where previously it was possible to write `{{{{}}` and get the same behavior as `{{\{\{}}`. This will no longer work. I don't think this is a problem, especially as we recently taught update_analyze_test_checks.py to emit `{{\{\{}}`, so this shouldn't get introduced in any new tests. For CodeGen/X86/vector-interleaved-store-i16-stride-7.ll (our slowest X86 test) this drops FileCheck time from 6s to 5s (the remainder is spent in a different regex issue). I expect similar speedups in other tests using a lot of `{{}}`.
2023-08-07[FileCheck] Turn errors into assert in valueFromStringRepr()Thomas Preud'homme1-16/+10
getWildcardRegex() guarantees that only valid hex numbers are matched by FileCheck numeric expressions. This commit therefore only asserts the lack of parsing failure in valueFromStringRepr(). Depends On D154430 Reviewed By: arichardson Differential Revision: https://reviews.llvm.org/D154431
2023-08-07[FileCheck, 4/4] NFC: Stop using ExpressionValueThomas Preud'homme1-55/+34
Use APInt directly instead. Depends On D150880 Reviewed By: arichardson Differential Revision: https://reviews.llvm.org/D154430
2023-08-07[FileCheck, 3/4] Allow AP value for numeric expressionsThomas Preud'homme1-103/+96
Use APInt to represent numeric variables and expressions, therefore removing overflow concerns. Only remains underflow when the format of an expression is unsigned (incl. hex values) but the result is negative. Note that this can only happen when substituting an expression, not when capturing since the regex used to capture unsigned value will not include minus sign, hence all the code removal for match propagation testing. This is what this patch implement. Reviewed By: arichardson Differential Revision: https://reviews.llvm.org/D150880
2023-07-04[FileCheck, 2/4] NFC: Switch to APInt getter for ExpressionValueThomas Preud'homme1-164/+66
Use an APInt getter as the only interface to getting the value out of an ExpressionValue. This paves the way to switch ExpressionValue to handle any integer without causing too big of a patch. Reviewed By: arichardson Differential Revision: https://reviews.llvm.org/D154429
2023-07-04[FileCheck, 1/4] NFC: Switch ExpressionValue to APIntThomas Preud'homme1-32/+9
Use APInt internally to store values represented by ExpressionValue. This will allow to support any integer values in FileCheck numeric expression in a subsequent commit. Reviewed By: arichardson Differential Revision: https://reviews.llvm.org/D154428
2023-06-25[llvm] Add missing StringExtras.h includesElliot Goodrich1-0/+1
In preparation for removing the `#include "llvm/ADT/StringExtras.h"` from the header to source file of `llvm/Support/Error.h`, first add in all the missing includes that were previously included transitively through this header.
2023-05-23Turn unreachable error into assertThomas Preud'homme1-5/+2
Function valueFromStringRepr() throws an error on missing 0x prefix when parsing a number string into a value. However, getWildcardRegex() already ensures that only text with the 0x prefix will match and be parsed, making that error throwing code dead code. This commit turn the code into an assert and remove the unit tests exercising that test accordingly. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D150797
2023-03-14[llvm] Use *{Set,Map}::contains (NFC)Kazu Hirata1-6/+3
2022-12-19[FileCheck] Remove the last llvm::OptionalBenjamin Kramer1-2/+2
It doesn't seem necessary and it's blocking std::optional.
2022-12-14[FileCheck] llvm::Optional => std::optionalFangrui Song1-13/+13
Don't touch FileCheck.cpp:698 StringSwitch<Optional<binop_eval_t>>(FuncName). MSVC and older GCC may report errors: error C2664: 'llvm::StringSwitch<std::optional<llvm::binop_eval_t>,T> &llvm::StringSwitch<T,T>::Case(llvm::StringLiteral,T)': cannot convert argument 2 from 'overloaded-function' to 'T' with [ T=std::optional<llvm::binop_eval_t> ] llvm/lib/FileCheck/FileCheck.cpp:699:44: error: no matching function for call to ‘llvm::StringSwitch<std::optional<llvm::Expected<llvm::ExpressionValue> (*)(const llvm::ExpressionValue&, const llvm::ExpressionValue&)> >::Case(const char [4], <unresolved overloaded function type>)’ .Case("add", operator+) ^
2022-12-14Revert "[FileCheck] llvm::Optional => std::optional"Douglas Yung1-14/+14
This reverts commit 13fd37c931c26ec07613dcad67b5ab2a593cd416. This change is causing bot failures on some Windows and older GCC bots: - https://lab.llvm.org/buildbot/#/builders/123/builds/14678 - https://lab.llvm.org/buildbot/#/builders/216/builds/14436 - https://lab.llvm.org/staging/#/builders/235/builds/993
2022-12-14[FileCheck] llvm::Optional => std::optionalFangrui Song1-14/+14
2022-12-10Revert "[FileCheck] Use std::optional in FileCheck.cpp (NFC)"Kazu Hirata1-2/+1
This reverts commit f555ec57cc01181ce09c802194b6f572f7a3f78a. One build failure has been reported: https://lab.llvm.org/buildbot/#/builders/67/builds/9785/steps/6/logs/stdio
2022-12-10[FileCheck] Use std::optional in FileCheck.cpp (NFC)Kazu Hirata1-1/+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-05CheckedArithmetic: llvm::Optional => std::optionalFangrui Song1-4/+4
2022-12-02[llvm] Use std::nullopt instead of None (NFC)Kazu Hirata1-4/+5
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-11-26Revert "[FileCheck] Use std::optional in FileCheck.cpp (NFC)"Kazu Hirata1-2/+1
This reverts commit e5a1ee531b2d325b0c793f849abbbbd4c9d315fd. Build errors have been reported: https://lab.llvm.org/buildbot/#/builders/123/builds/14344 https://lab.llvm.org/buildbot#builders/216/builds/13360
2022-11-26[FileCheck] Use std::optional in FileCheck.cpp (NFC)Kazu Hirata1-1/+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-07-25[llvm][FileCheck] Fix unit tests failures with EXPENSIVE_CHECKSDavid Spickett1-0/+2
EXPENSIVE_CHECKS enables _GLIBCXX_DEBUG, which makes std::sort check that the compare function is implemented correctly. To do this it calls it with the first item as both sides. Which trips the assert here because we think they're 2 capture ranges that overlap, when it's just the same range twice. Check up front for the two sides being the same item (same address, not just ==). Reviewed By: kazu Differential Revision: https://reviews.llvm.org/D130282
2022-05-26[FileCheck] Catch missspelled directives.Ivan Kosarev1-2/+26
Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D125604
2022-01-13[FileCheck] Allow literal '['s before "[[var...]]"Jay Foad1-4/+7
Change FileCheck to accept patterns like "[[[var...]]" and treat the excess open brackets at the start as literals. This makes the patterns for matching assembler output with literal brackets much cleaner. For example an AMDGPU pattern that used to be written like: buffer_store_dwordx2 v{{\[}}[[LO]]:[[HI]]{{\]}} can now be: buffer_store_dwordx2 v[[[LO]]:[[HI]]] (Even before this patch the final close bracket did not need to be wrapped in {{}}, but people tended to do it anyway for symmetry.) This does not introduce any ambiguity since "[[" was always followed by an identifier or '@' or '#', so "[[[" was always an error. I've included a few test updates in this patch just for illustration and testing. There are a couple of hundred tests that could be updated as a follow up, mostly in test/CodeGen/. Differential Revision: https://reviews.llvm.org/D117117 Change-Id: Ia6bc6f65cb69734821c911f54a43fe1c673bcca7
2022-01-07[llvm] Use true/false instead of 1/0 (NFC)Kazu Hirata1-1/+1
Identified with modernize-use-bool-literals.
2021-10-23[llvm] Use StringRef::contains (NFC)Kazu Hirata1-2/+2
2021-09-01[FileCheck] Use StringRef for MatchRegexp to fix crash.Florian Hahn1-3/+5
If MatchRegexp is an invalid regex, an error message will be printed using SourceManager::PrintMessage via AddRegExToRegEx. PrintMessage relies on the input being a StringRef into a string managed by SourceManager. At the moment, a StringRef to a std::string allocated in the caller of AddRegExToRegEx is passed. If the regex is invalid, this StringRef is passed to PrintMessage, where it will crash, because it does not point to a string managed via SourceMgr. This patch fixes the crash by turning MatchRegexp into a StringRef If we use MatchStr, we directly use that StringRef, which points into a string from SourceMgr. Otherwise, MatchRegexp gets assigned Format.getWildcardRegex(), which returns a std::string. To extend the lifetime, assign it to a std::string variable WildcardRegexp and assign MatchRegexp to a stringref to WildcardRegexp. WildcardRegexp should always be valid, so we should never have to print an error message via the SoureMgr I think. Fixes PR49319. Reviewed By: thopre Differential Revision: https://reviews.llvm.org/D109050
2021-06-25[llvm] Rename StringRef _lower() method calls to _insensitive()Martin Storsjö1-1/+1
This is a mechanical change. This actually also renames the similarly named methods in the SmallString class, however these methods don't seem to be used outside of the llvm subproject, so this doesn't break building of the rest of the monorepo.
2021-04-20Fix PR46880: Fail CHECK-NOT with undefined variableThomas Preud'homme1-39/+26
Currently a CHECK-NOT directive succeeds whenever the corresponding match fails. However match can fail due to an error rather than a lack of match, for instance if a variable is undefined. This commit makes match error a failure for CHECK-NOT. Reviewed By: jdenny Differential Revision: https://reviews.llvm.org/D86222
2021-03-24[FileCheck] Fix PR49531: invalid use of string varThomas Preud'homme1-1/+8
FileCheck string substitution block parsing code only report an invalid variable name in a string variable use if it starts with a forbidden character. It does not report anything if there are unparsed characters after the variable name, i.e. [[X-Y]] is parsed as [[X]] and no error is returned. This commit fixes that. Reviewed By: jdenny, jhenderson Differential Revision: https://reviews.llvm.org/D98691
2021-03-17[FileCheck] Fix redundant diagnostics due to numeric errorsJoel E. Denny1-0/+2
Fixed substitution printing not to produce an empty diagnostic for errors handled elsewhere. Reviewed By: thopre Differential Revision: https://reviews.llvm.org/D98088
2021-03-17[FileCheck] Fix numeric error propagationJoel E. Denny1-132/+186
A more general name might be match-time error propagation. That is, it's conceivable we'll one day have non-numeric errors that require the handling fixed by this patch. Without this patch, FileCheck behaves as follows: ``` $ cat check CHECK-NOT: [[#0x8000000000000000+0x8000000000000000]] $ FileCheck -vv -dump-input=never check < input check:1:54: remark: implicit EOF: expected string found in input CHECK-NOT: [[#0x8000000000000000+0x8000000000000000]] ^ <stdin>:2:1: note: found here ^ check:1:15: error: unable to substitute variable or numeric expression: overflow error CHECK-NOT: [[#0x8000000000000000+0x8000000000000000]] ^ $ echo $? 0 ``` Notice that the exit status is 0 even though there's an error. Moreover, FileCheck doesn't print the error diagnostic unless both `-dump-input=never` and `-vv` are specified. The same problem occurs when `CHECK-NOT` does have a match but a capture fails due to overflow: exit status is 0, and no diagnostic is printed unless both `-dump-input=never` and `-vv` are specified. The usefulness of capturing from `CHECK-NOT` is questionable, but this case should certainly produce an error. With this patch, FileCheck always includes the error diagnostic and has non-zero exit status for the above examples. It's conceivable that this change will cause some existing tests to fail, but my assumption is that they should fail. Moreover, with nearly every project enabled, this patch didn't produce additional `check-all` failures for me. This patch also extends input dumps to include such numeric error diagnostics for both expected and excluded patterns. As noted in fixmes in some of the tests added by this patch, this patch worsens an existing issue with redundant diagnostics. I'll fix that bug in a subsequent patch. Reviewed By: thopre, jhenderson Differential Revision: https://reviews.llvm.org/D98086
2021-03-12[FileCheck] Add support for hex alternate form in FileCheckThomas Preud'homme1-11/+34
Add printf-style alternate form flag to prefix hex number with 0x when present. This works on both empty numeric expression (e.g. variable definition from input) and when matching a numeric expression. The syntax is as follows: [[#%#<precision specifier><format specifier>, ...] where <precision specifier> and <format specifier> are optional and ... can be a variable definition or not with an empty expression or not. This feature was requested in https://reviews.llvm.org/D81144#2075532 for llvm/test/MC/ELF/gen-dwarf64.s Reviewed By: jdenny Differential Revision: https://reviews.llvm.org/D97845
2021-03-11[FileCheck] Fix naming of OverflowErrorStr varThomas Preud'homme1-3/+8
As pointed out by Joel E. Denny in D97845, the OverflowErrorStr variable is misnamed because the error is raised for any parsing error. Note that in FileCheck proper this only happens in case of (under|over)flow because the regex will ensure a number in the correct format is matched. Reviewed By: jdenny Differential Revision: https://reviews.llvm.org/D98342
2021-03-03[FileCheck] Do not skip end of line in diagnosticsThomas Preud'homme1-3/+0
When commit da108b4ed4e6e7267701e76d5fd3b87609c9ab77 introduced the CHECK-NEXT directive, it added logic to skip to the next line when printing a diagnostic if the current matching position is at the end of a line. This was fine while FileCheck did not support regular expression but since it does now it can be confusing when the pattern to match starts with the expectation of a newline (e.g. CHECK-NEXT: {{\n}}foo). It is also inconsistent with the column information in the diagnostic which does point to the end of line. This commit removes this logic altogether, such that failure to match diagnostic for such cases would show the end of line and be consistent with the column information. The commit also adapts all existing testcases accordingly. Note to reviewers: An alternative approach would be to restrict the code to only skip to the next line if the first character of the pattern is known not to match a whitespace-like character. This would respect the original intent but keep the inconsistency in terms of column info and requires more code. I've only chosen this current approach by laziness and would be happy to restrict the logic instead. Reviewed By: jdenny, jhenderson Differential Revision: https://reviews.llvm.org/D93341
2021-01-17[llvm] Use llvm::sort (NFC)Kazu Hirata1-6/+5
2021-01-14[llvm] Remove redundant return and continue statements (NFC)Kazu Hirata1-1/+0
Identified with readability-redundant-control-flow.
2020-12-18[FileCheck] Add a literal check directive modifierJacques Pienaar1-36/+82
Introduce CHECK modifiers that change the behavior of the CHECK directive. Also add a LITERAL modifier for cases where matching could end requiring escaping strings interpreted as regex where only literal/fixed string matching is desired (making the CHECK's more difficult to write/fragile and difficult to interpret).
2020-12-16Use basic_string::find(char) instead of basic_string::find(const char *s, ↵Fangrui Song1-1/+1
size_type pos=0) Many (StringRef) cannot be detected by clang-tidy performance-faster-string-find.
2020-10-30[FileCheck] Report missing prefixes when more than one is provided.Mircea Trofin1-8/+16
If more than a prefix is provided - e.g. --check-prefixes=CHECK,FOO - we don't report if (say) FOO is never used. This may lead to a gap in our test coverage. This patch introduces a new option, --allow-unused-prefixes. It currently is set to true, keeping today's behavior. After we explicitly set it in tests where this behavior was actually intentional, we will switch it to false by default. Differential Revision: https://reviews.llvm.org/D90281