summaryrefslogtreecommitdiff
path: root/llvm/unittests/FileCheck/FileCheckTest.cpp
AgeCommit message (Collapse)Author
2025-06-27[FileCheck] Improve printing variables with escapes (#145865)Mészáros Gergely
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.
2023-12-13[llvm] Use StringRef::{starts,ends}_with (NFC)Kazu Hirata
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-09-27[NFC] Use const references to avoid copying objects in for-loopsGregory Alfonso
Differential Revision: https://reviews.llvm.org/D139487
2023-08-08[FileCheck] Fix MSVC 'argument': truncation from 'int' to 'bool' warning.Simon Pilgrim
Ensure expectOperationValueResult performs the is_integral_v as constexpr to prevent MSVC getting confused between the mixture of integer / string constructors in the if-else. Warning introduced in D150880
2023-08-07[FileCheck] Turn errors into assert in valueFromStringRepr()Thomas Preud'homme
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'homme
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'homme
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'homme
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-05-23Turn unreachable error into assertThomas Preud'homme
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
2022-12-16std::optional::value => operator*/operator->Fangrui Song
value() has undesired exception checking semantics and calls __throw_bad_optional_access in libc++. Moreover, the API is unavailable without _LIBCPP_NO_EXCEPTIONS on older Mach-O platforms (see _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS). This commit fixes LLVMAnalysis and its dependencies.
2022-12-14[FileCheck] llvm::Optional => std::optionalFangrui Song
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 Yung
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 Song
2022-07-13[llvm] Use value instead of getValue (NFC)Kazu Hirata
2022-06-25Revert "Don't use Optional::hasValue (NFC)"Kazu Hirata
This reverts commit aa8feeefd3ac6c78ee8f67bf033976fc7d68bc6d.
2022-06-25Don't use Optional::hasValue (NFC)Kazu Hirata
2021-05-14Bump googletest to 1.10.0Benjamin Kramer
2021-04-20Fix PR46880: Fail CHECK-NOT with undefined variableThomas Preud'homme
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-04-08[FileCheck, test] Rename checkWildcardRegexCharMatchFailureThomas Preud'homme
Proposed edit https://reviews.llvm.org/D97845#inline-922769 in D97845 suggests the checkWildcardRegexCharMatchFailure function name is misleading because it is not clear it checks for a match failure on each character in the string parameter. This commit renames it to an hopefully clearer name. Reviewed By: jdenny Differential Revision: https://reviews.llvm.org/D98343
2021-03-24[FileCheck] Fix PR49531: invalid use of string varThomas Preud'homme
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 numeric error propagationJoel E. Denny
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'homme
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
2020-09-01Reland [FileCheck] Move FileCheck implementation out of LLVMSupport into its ↵Raphael Isemann
own library This relands e9a3d1a401b07cbf7b11695637f1b549782a26cd which was originally missing linking LLVMSupport into LLMVFileCheck which broke the SHARED_LIBS build. Original summary: The actual FileCheck logic seems to be implemented in LLVMSupport. I don't see a good reason for having FileCheck implemented there as it has a very specific use while LLVMSupport is a dependency of pretty much every LLVM tool there is. In fact, the only use of FileCheck I could find (outside the FileCheck tool and the FileCheck unit test) is a single call in GISelMITest.h. This moves the FileCheck logic to its own LLVMFileCheck library. This way only FileCheck and the GlobalISelTests now have a dependency on this code. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D86344
2020-08-31Revert "[FileCheck] Move FileCheck implementation out of LLVMSupport into ↵Raphael Isemann
its own library" This reverts commit e9a3d1a401b07cbf7b11695637f1b549782a26cd. Seems the new FileCheck library doesn't link on some bots. Reverting for now.
2020-08-31[FileCheck] Move FileCheck implementation out of LLVMSupport into its own ↵Raphael Isemann
library The actual FileCheck logic seems to be implemented in LLVMSupport. I don't see a good reason for having FileCheck implemented there as it has a very specific use while LLVMSupport is a dependency of pretty much every LLVM tool there is. In fact, the only use of FileCheck I could find (outside the FileCheck tool and the FileCheck unit test) is a single call in GISelMITest.h. This moves the FileCheck logic to its own LLVMFileCheck library. This way only FileCheck and the GlobalISelTests now have a dependency on this code. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D86344