68 Commits

Author SHA1 Message Date
Jon Roelofs
a7867fcd94
[FileCheck] Limit quadratic partial-match search behavior (#147833) 2025-07-23 08:40:11 -07:00
Andrew Rogers
4e2efa55c6
[llvm] export private symbols needed by unittests (#145767)
## 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-07-10 08:20:09 -07:00
Mészáros Gergely
98f7d756e3
[FileCheck] Improve printing variables with escapes (#145865)
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-27 22:39:07 +02:00
Kazu Hirata
228f66807d
[llvm] Remove unused includes (NFC) (#142733)
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-06-04 12:30:52 -07:00
Kazu Hirata
7cc5e64a26
[FileCheck] Use default member initialization in ExpressionFormat (NFC) (#138409) 2025-05-03 10:27:08 -07:00
Kazu Hirata
6257621f41
[llvm] Use llvm::append_range (NFC) (#133658) 2025-03-30 18:43:02 -07:00
Kazu Hirata
40d251db4a
[llvm] Use *Set::insert_range (NFC) (#133041)
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-26 07:46:24 -07:00
Kazu Hirata
b8317df8d8
[FileCheck] Avoid repeated hash lookups (NFC) (#131553) 2025-03-17 07:41:51 -07:00
Kazu Hirata
fec04f286e
[FileCheck] Avoid repeated hash lookups (NFC) (#127026) 2025-02-13 09:11:43 -08:00
Jay Foad
d3d605b7cd
[FileCheck] Use move semantics instead of std::swap. NFC. (#123304)
This code was using a pre-move-semantics trick of using std::swap to
avoid expensive vector copies.
2025-01-23 13:28:59 +00:00
Jay Foad
c10e8261bf
[FileCheck] Remove unneeded unique_ptr. NFC. (#123216) 2025-01-16 17:19:41 +00:00
Kazu Hirata
22e55ba329
[llvm] Prefer StringRef::substr to StringRef::slice (NFC) (#106330)
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-08-28 01:13:46 -07:00
Youngsuk Kim
34855405b0 [llvm] Avoid 'raw_string_ostream::str' (NFC)
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-07-05 17:22:03 -05:00
Jay Foad
d4a0154902
[llvm-project] Fix typo "seperate" (#95373) 2024-06-13 20:20:27 +01:00
Kazu Hirata
bb6df0804b
[llvm] Use StringRef::operator== instead of StringRef::equals (NFC) (#91441)
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-05-08 10:33:53 -07:00
Daniil Kovalev
3105cfe783
[FileCheck] Fix parsing empty global and pseudo variable names (#83667)
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-05 11:20:16 +03:00
Daniil Kovalev
28b354a960
Revert "[FileCheck] Fix parsing empty global and pseudo variable names" (#83657)
Reverts llvm/llvm-project#82595

See build failure
https://lab.llvm.org/buildbot/#/builders/139/builds/60549
2024-03-02 08:09:10 +03:00
Daniil Kovalev
aab3d13179
[FileCheck] Fix parsing empty global and pseudo variable names (#82595)
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-02 07:03:50 +03:00
Kazu Hirata
e7d3a4f34a [FileCheck] Simplify a use of StringRef::consume_front (NFC) 2024-02-04 14:57:28 -08:00
Kazu Hirata
3be989e8c3 [FileCheck] Use StringRef::rtrim (NFC) 2024-02-03 21:43:03 -08:00
Vinayak Dev
497a8604b3
[FileCheck]: Fix diagnostics for NOT prefixes (#78412)
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.
2024-01-19 15:08:24 +00:00
Kazu Hirata
586ecdf205
[llvm] Use StringRef::{starts,ends}_with (NFC) (#74956)
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-12-11 21:01:36 -08:00
Nikita Popov
261b471015
[FileCheck] Don't use regex to find prefixes (#72237)
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-15 09:34:52 +01:00
Nikita Popov
a3eeef82da
[FileCheck] Avoid capturing group for {{regex}} (#72136)
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-11-14 09:03:54 +01:00
Thomas Preud'homme
b743c19360 [FileCheck] Turn errors into assert in valueFromStringRepr()
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 21:27:44 +01:00
Thomas Preud'homme
e15e969a4f [FileCheck, 4/4] NFC: Stop using ExpressionValue
Use APInt directly instead.

Depends On D150880

Reviewed By: arichardson

Differential Revision: https://reviews.llvm.org/D154430
2023-08-07 17:36:05 +01:00
Thomas Preud'homme
0726cb0047 [FileCheck, 3/4] Allow AP value for numeric expressions
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-08-07 14:48:48 +01:00
Thomas Preud'homme
fc0d1c05a0 [FileCheck, 2/4] NFC: Switch to APInt getter for ExpressionValue
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 21:42:11 +01:00
Thomas Preud'homme
cf57fcfa02 [FileCheck, 1/4] NFC: Switch ExpressionValue to APInt
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-07-04 21:39:20 +01:00
Elliot Goodrich
b0abd4893f [llvm] Add missing StringExtras.h includes
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-06-25 15:42:22 +01:00
Thomas Preud'homme
13eb298d5c Turn unreachable error into assert
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-05-23 13:52:22 +01:00
Kazu Hirata
1ca0cb717a [llvm] Replace None with std::nullopt in comments (NFC)
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-04-25 23:53:32 -07:00
Kazu Hirata
b595eb83e5 [llvm] Use *{Set,Map}::contains (NFC) 2023-03-14 18:56:07 -07:00
Benjamin Kramer
20bdb4514e [FileCheck] Remove the last llvm::Optional
It doesn't seem necessary and it's blocking std::optional.
2022-12-19 20:22:14 +01:00
Fangrui Song
9408164254 [FileCheck] llvm::Optional => std::optional
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-14 18:44:30 +00:00
Douglas Yung
547e40a91b Revert "[FileCheck] llvm::Optional => std::optional"
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 10:05:01 -08:00
Fangrui Song
13fd37c931 [FileCheck] llvm::Optional => std::optional 2022-12-14 10:07:47 +00:00
Kazu Hirata
93b1ec3652 Revert "[FileCheck] Use std::optional in FileCheck.cpp (NFC)"
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 09:28:07 -08:00
Kazu Hirata
f555ec57cc [FileCheck] Use std::optional in FileCheck.cpp (NFC)
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-10 08:24:18 -08:00
Fangrui Song
3dfacc0a56 CheckedArithmetic: llvm::Optional => std::optional 2022-12-05 04:30:54 +00:00
Kazu Hirata
595f1a6aaf [llvm] Use std::nullopt instead of None in comments (NFC)
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-04 19:47:13 -08:00
Kazu Hirata
aadaaface2 [llvm] Use std::nullopt instead of None (NFC)
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-12-02 21:11:44 -08:00
Kazu Hirata
01fc2b8515 Revert "[FileCheck] Use std::optional in FileCheck.cpp (NFC)"
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 17:08:27 -08:00
Kazu Hirata
e5a1ee531b [FileCheck] Use std::optional in FileCheck.cpp (NFC)
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-26 15:27:16 -08:00
David Spickett
3a35bcef22 [llvm][FileCheck] Fix unit tests failures with EXPENSIVE_CHECKS
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-07-25 08:19:28 +00:00
Ivan Kosarev
ad1d60c3be [FileCheck] Catch missspelled directives.
Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D125604
2022-05-26 11:37:19 +01:00
Jay Foad
821dd3b0e5 [FileCheck] Allow literal '['s before "[[var...]]"
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-13 09:47:37 +00:00
Kazu Hirata
2aed08131d [llvm] Use true/false instead of 1/0 (NFC)
Identified with modernize-use-bool-literals.
2022-01-07 00:39:14 -08:00
Kazu Hirata
d14d7068b6 [llvm] Use StringRef::contains (NFC) 2021-10-23 08:45:27 -07:00
Florian Hahn
a3d357e504
[FileCheck] Use StringRef for MatchRegexp to fix crash.
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-09-01 14:27:14 +02:00