[PATCH] D27463: Change llvm::Regex to expose a fallible constructor.

David L. Jones via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 6 08:38:24 PST 2016


dlj created this revision.
dlj added reviewers: rsmith, llvm-commits.

Currently, if llvm::Regex is constructed with an invalid pattern, it only
exposes this fact if the call site checks isValid(). The Regex class itself also
statefully maintains a (mutable) error code internally, which means its match()
function is not const.

This change adds a "fallible constructor" to llvm::Regex:
http://llvm.org/docs/ProgrammersManual.html#fallible-constructors
and then plumbs it through LLVM code. (Follow-up changes are prepared to update
uses in Clang.)

I plan to expand RegexError to handle the error values directly (see regerror.c)
and return it from match(), which will remove the last of the error state from
Regex, allowing match() to become const. Right away, though, this change deletes
the last vestiges of stateful error codes from the internal regex implementation
(regexec.c). This allows constructing cheap errors that require only the code,
and do not need to refer to the compiled regex. These error cases (REG_ATOI and
REG_ITOA) never happen in LLVM code, and are not POSIX-standard.


https://reviews.llvm.org/D27463

Files:
  include/llvm/Support/Regex.h
  include/llvm/Support/YAMLTraits.h
  lib/IR/AutoUpgrade.cpp
  lib/IR/DiagnosticInfo.cpp
  lib/Passes/PassBuilder.cpp
  lib/Support/Regex.cpp
  lib/Support/SpecialCaseList.cpp
  lib/Support/regerror.c
  lib/Support/regex_impl.h
  lib/Target/AArch64/Utils/AArch64BaseInfo.cpp
  lib/Transforms/Utils/SymbolRewriter.cpp
  tools/llvm-cov/CodeCoverage.cpp
  tools/llvm-cov/CoverageFilters.cpp
  tools/llvm-cov/CoverageFilters.h
  tools/llvm-extract/llvm-extract.cpp
  tools/llvm-pdbdump/LinePrinter.h
  tools/llvm-pdbdump/llvm-pdbdump.cpp
  tools/sancov/sancov.cc
  unittests/Support/RegexTest.cpp
  utils/FileCheck/FileCheck.cpp
  utils/TableGen/CodeGenSchedule.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27463.80426.patch
Type: text/x-patch
Size: 26217 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161206/d0c0d863/attachment.bin>


More information about the llvm-commits mailing list