aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/FileCheck
AgeCommit message (Collapse)AuthorFilesLines
2025-09-09[FileCheck] Fix --enable-var-scope for numvars after reassignment (#157158)Clipi1-0/+8
* When `--enable-var-scope` is active, `lib/FileCheck.cpp#clearLocalVars` gets called. * That function loops through `GlobalNumericVariableTable` and then calls `NumericVariable::clear` on most items. It also removes them from `GlobalNumericVariableTable`. * When reassigning an already cleared variable, `Pattern::match` calls `NumericVariable::setValue`, but it doesn't reinsert it into `GlobalNumericVariableTable`. Therefore, the next time `clearLocalVars` is called, it won't be able to loop through the variables. Fix it by reinserting them in `GlobalNumericVariableTable` inside `Pattern::match`. Co-authored-by: Thomas Preud'homme <thomas.preudhomme@arm.com>
2025-07-23[FileCheck] Limit quadratic partial-match search behavior (#147833)Jon Roelofs1-0/+6
2025-07-10[llvm] export private symbols needed by unittests (#145767)Andrew Rogers1-29/+39
## Purpose Export a small number of private LLVM symbols so that unit tests can still build/run when LLVM is built as a Windows DLL or a shared library with default hidden symbol visibility. ## Background The effort to build LLVM as a WIndows DLL is tracked in #109483. Additional context is provided in [this discourse](https://discourse.llvm.org/t/psa-annotating-llvm-public-interface/85307). Some LLVM unit tests use internal/private symbols that are not part of LLVM's public interface. When building LLVM as a DLL or shared library with default hidden symbol visibility, the symbols are not available when the unit test links against the DLL or shared library. This problem can be solved in one of two ways: 1. Export the private symbols from the DLL. 2. Link the unit tests against the intermediate static libraries instead of the final LLVM DLL. This PR applies option 1. Based on the discussion of option 2 in #145448, this option is preferable. ## Overview * Adds a new `LLVM_ABI_FOR_TEST` export macro, which is currently just an alias for `LLVM_ABI`. * Annotates the sub-set of symbols under `llvm/lib` that are required to get unit tests building using the new macro.
2025-06-27[FileCheck] Improve printing variables with escapes (#145865)Mészáros Gergely2-10/+68
Firstly fix FileCheck printing string variables double-escaped (first regex, then C-style). This is confusing because it is not clear if the printed value is the literal value or exactly how it is escaped, without looking at FileCheck's source code. Secondly, only escape when doing so makes it easier to read the value (when the string contains tabs, newlines or non-printable characters). When the variable value is escaped, make a note of it in the output too, in order to avoid confusion. The common case that is motivating this change is variables that contain windows style paths with backslashes. These were printed as `"C:\\\\Program Files\\\\MyApp\\\\file.txt"`. Now prefer to print them as `"C:\Program Files\MyApp\file.txt"`. Printing the value literally also makes it easier to search for variables in the output, since the user can just copy-paste it.
2025-06-04[llvm] Remove unused includes (NFC) (#142733)Kazu Hirata1-1/+0
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-05-03[FileCheck] Use default member initialization in ExpressionFormat (NFC) ↵Kazu Hirata1-2/+2
(#138409)
2025-03-30[llvm] Use llvm::append_range (NFC) (#133658)Kazu Hirata1-4/+2
2025-03-26[llvm] Use *Set::insert_range (NFC) (#133041)Kazu Hirata1-8/+4
We can use *Set::insert_range to collapse: for (auto Elem : Range) Set.insert(E); down to: Set.insert_range(Range); In some cases, we can further fold that into the set declaration.
2025-03-17[FileCheck] Avoid repeated hash lookups (NFC) (#131553)Kazu Hirata1-2/+4
2025-02-13[FileCheck] Avoid repeated hash lookups (NFC) (#127026)Kazu Hirata1-8/+5
2025-01-23[FileCheck] Use move semantics instead of std::swap. NFC. (#123304)Jay Foad2-6/+7
This code was using a pre-move-semantics trick of using std::swap to avoid expensive vector copies.
2025-01-16[FileCheck] Remove unneeded unique_ptr. NFC. (#123216)Jay Foad1-10/+9
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 Dev2-33/+48
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'homme2-21/+12
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'homme2-94/+52
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'homme2-121/+112
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'homme2-186/+67
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'homme2-40/+15
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-04-25[llvm] Replace None with std::nullopt in comments (NFC)Kazu Hirata1-3/+3
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
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 Song2-34/+34
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 Yung2-35/+35
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 Song2-35/+35
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-04[llvm] Use std::nullopt instead of None in comments (NFC)Kazu Hirata1-15/+15
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-02[llvm] Use std::nullopt instead of None (NFC)Kazu Hirata2-10/+11
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