summaryrefslogtreecommitdiff
path: root/llvm/lib/Support/Regex.cpp
AgeCommit message (Collapse)Author
2023-12-01Avoid nullptr+0 in Regex (#73071)Tanmay
A zero-length StringRef can have a null data pointer, which, if passed to the llvm_regex functions which take a pointer+length, but then convert it into a [begin, end) pointer pair can cause a nullptr+0 expression to be evaluated, which is UB. So avoid that by ensuring the data pointer is always non-null, even in the zero-length case.
2023-10-12[Support] Add `\g<ref>` backreferences in Regex::sub() (#67220)Igor Kudrin
The existing format of backreferences, `\<ref>`, does not allow digits to be placed directly after the reference because they are included in the reference number. The new format solves this problem by adding explicit delimiters.
2023-05-09Undo include order work-around in Regex.cppHans Wennborg
r327256 / 2b8b90a7686858b1d22cae6fcfbd0904135112aa added this include-order work-around since regex_impl.h's include guard conflicted with macOS's xlocale.h which used the same macro. Since b86c249691a7973a451bc6a586b39da64778d219 renamed the include guard, that work-around is no longer needed. Differential revision: https://reviews.llvm.org/D150127
2021-12-02[llvm] Use range-based for loops (NFC)Kazu Hirata
2020-07-02[ASTMatchers] Enhanced support for matchers taking Regex argumentsNathan James
Added new Macros `AST(_POLYMORPHIC)_MATCHER_REGEX(_OVERLOAD)` that define a matchers that take a regular expression string and optionally regular expression flags. This lets users match against nodes while ignoring the case without having to manually use `[Aa]` or `[A-Fa-f]` in their regex. The other point this addresses is in the current state, matchers that use regular expressions have to compile them for each node they try to match on, Now the regular expression is compiled once when you define the matcher and used for every node that it tries to match against. If there is an error while compiling the regular expression an error will be logged to stderr showing the bad regex string and the reason it couldn't be compiled. The old behaviour of this was down to the Matcher implementation and some would assert, whereas others just would never match. Support for this has been added to the documentation script as well. Support for this has been added to dynamic matchers ensuring functionality is the same between the 2 use cases. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D82706
2020-03-02Explicitly include <cassert> when using assertJoerg Sonnenberger
Depending on the OS used, a module-enabled build can fail due to the special handling <cassert> gets as textual header.
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer
This is how it should've been and brings it more in line with std::string_view. There should be no functional change here. This is mostly mechanical from a custom clang-tidy check, with a lot of manual fixups. It uncovers a lot of minor inefficiencies. This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2019-09-24Regex: Make "match" and "sub" const member functionsThomas Preud'homme
Summary: The Regex "match" and "sub" member functions were previously not "const" because they wrote to the "error" member variable. This commit removes those assignments, and instead assumes that the validity of the regex is already known after the initial compilation of the regular expression. As a result, these member functions were possible to make "const". This makes it easier to do things like pre-compile Regexes up-front, and makes "match" and "sub" thread-safe. The error status is now returned as an optional output, which also makes the API of "match" and "sub" more consistent with each other. Also, some uses of Regex that could be refactored to be const were made const. Patch by Nicolas Guillemot Reviewers: jankratochvil, thopre Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D67241 llvm-svn: 372764
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-03-12Fix compilation on Darwin with expensive checks.Jonas Devlieghere
After r327219 was landed, the bot with expensive checks on GreenDragon started failing. The problem was missing symbols `regex_t` and `regmatch_t` in `xlocale/_regex.h`. The latter was included because after the change in r327219, `random` is needed, which transitively includes `xlocale.h.` which in turn conditionally includes `xlocale/_regex.h` when _REGEX_H_ is defined. Because this is the header guard in `regex_impl.h` and because `regex_impl.h` was included before the other LLVM includes, `xlocale/_regex.h` was included without the necessary types being available. This commit fixes this by moving the include of `regex_impl.h` all the way down. I also added a comment to stress the significance of its position. llvm-svn: 327256
2017-04-18Add const to a const method. NFCGeorge Burgess IV
llvm-svn: 300520
2016-09-02[Support] - Fix possible crash in match() of llvm::Regex.George Rimar
Crash was possible if match() method was called on object that was moved or object created with empty constructor. Testcases updated. DIfferential revision: https://reviews.llvm.org/D24123 llvm-svn: 280473
2016-09-01[Support] Fix a warning introduced in r280339 due to the memberChandler Carruth
initializers not being in the same order as the members. Specifically, 'preg' is the first member followed by 'error', so they will be initialized in that order and should be written in the member initializer list in that order. For the constructor in question, there is no change in behavior. llvm-svn: 280345
2016-09-01[LLVM/Support] - Create no-arguments constructor for llvm::RegexGeorge Rimar
This is useful when need to defer the construction, e.g. using Regex as a member of class. Differential revision: https://reviews.llvm.org/D24101 llvm-svn: 280339
2015-03-30Remove more superfluous .str() and replace std::string concatenation with Twine.Yaron Keren
Following r233392, http://llvm.org/viewvc/llvm-project?rev=233392&view=rev. llvm-svn: 233555
2015-03-23Purge unused includes throughout libSupport.Benjamin Kramer
NFC. llvm-svn: 232976
2014-04-07[C++11] Make use of 'nullptr' in the Support library.Craig Topper
llvm-svn: 205697
2014-01-02Make llvm::Regex non-copyable but movable.David Blaikie
Based on a patch by Maciej Piechotka. llvm-svn: 198334
2013-12-12Add missing escape characters to the new Regex::escape() functionAlp Toker
The old AddFixedStringToRegEx() it was based on got away with this for the longest time, but the problem became easy to spot after the cleanup in r197096. Also add a quick unit test to cover regex escaping. llvm-svn: 197121
2013-12-12Expose FileCheck's AddFixedStringToRegEx as Regex::escapeHans Wennborg
Both FileCheck and clang's -verify need to escape strings for regexes, so let's expose this as a utility in the Regex class. llvm-svn: 197096
2013-08-08Fix off-by-one error in Regex::isValidAlexey Samsonov
llvm-svn: 187992
2013-08-05Introduce Regex::isLiteralERE function.Peter Collingbourne
This will be used to implement an optimisation for literal entries in special case lists. Differential Revision: http://llvm-reviews.chandlerc.com/D1278 llvm-svn: 187731
2012-12-03Use the new script to sort the includes of every file under lib.Chandler Carruth
Sooooo many of these had incorrect or strange main module includes. I have manually inspected all of these, and fixed the main module include to be the nearest plausible thing I could find. If you own or care about any of these source files, I encourage you to take some time and check that these edits were sensible. I can't have broken anything (I strictly added headers, and reordered them, never removed), but they may not be the headers you'd really like to identify as containing the API being implemented. Many forward declarations and missing includes were added to a header files to allow them to parse cleanly when included first. The main module rule does in fact have its merits. =] llvm-svn: 169131
2012-11-28Add backreference matching capabilities to Support/Regex, withEli Bendersky
appropriate unit tests. This change in itself is not expected to affect any functionality at this point, but it will serve as a stepping stone to improve FileCheck's variable matching capabilities. Luckily, our regex implementation already supports backreferences, although a bit of hacking is required to enable it. It supports both Basic Regular Expressions (BREs) and Extended Regular Expressions (EREs), without supporting backrefs for EREs, following POSIX strictly in this respect. And EREs is what we actually use (rightly). This is contrary to many implementations (including the default on Linux) of POSIX regexes, that do allow backrefs in EREs. Adding backref support to our EREs is a very simple change in the regcomp parsing code. I fail to think of significant cases where it would clash with existing things, and can bring more versatility to the regexes we write. There's always the danger of a backref in a specially crafted regex causing exponential matching times, but since we mainly use them for testing purposes I don't think it's a big problem. [it can also be placed behind a flag specific to FileCheck, if needed]. For more details, see: * http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-November/055840.html * http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20121126/156878.html llvm-svn: 168802
2011-04-09regexes are allowed to match empty things, e.g. {{.*}} in filecheck.Chris Lattner
llvm-svn: 129193
2010-07-14Don't pass StringRef by reference.Benjamin Kramer
llvm-svn: 108366
2010-02-17Add Regex::sub, for doing regular expression substitution with backreferences.Daniel Dunbar
llvm-svn: 96503
2009-09-26remove support for "NoSub" from regex. It seems like a minor optimizationChris Lattner
and makes the API more annoying. Add a Regex::getNumMatches() method. llvm-svn: 82877
2009-09-24add and document regex support for FileCheck. You can now do stuff like:Chris Lattner
; CHECK: movl {{%e[a-z][xi]}}, %eax or whatever. llvm-svn: 82717
2009-09-24tidy up, fix a memory leak in Regex::isValidChris Lattner
llvm-svn: 82707
2009-08-30Add regular expression matching support, based on OpenBSD regexec()/regcomp()Torok Edwin
implementation. llvm-svn: 80493