[llvm] d089e1f - [llvm] Change the implementation of isValidFeatureListFormat (#219266)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 28 12:07:29 PDT 2026
Author: Jun Wang
Date: 2026-08-28T12:07:25-07:00
New Revision: d089e1f04ded2b691bc431e43799d7e93ff56015
URL: https://github.com/llvm/llvm-project/commit/d089e1f04ded2b691bc431e43799d7e93ff56015
DIFF: https://github.com/llvm/llvm-project/commit/d089e1f04ded2b691bc431e43799d7e93ff56015.diff
LOG: [llvm] Change the implementation of isValidFeatureListFormat (#219266)
This is mostly to change the function-local static variable because some
programs are having static initialization order problems. Also the
coding standard states statics with ctor/dtor should be avoided. The new
implementation also does not use Regex anymore.
Added:
Modified:
llvm/lib/MC/TargetRegistry.cpp
Removed:
################################################################################
diff --git a/llvm/lib/MC/TargetRegistry.cpp b/llvm/lib/MC/TargetRegistry.cpp
index 2727e587496f3..185f63637a460 100644
--- a/llvm/lib/MC/TargetRegistry.cpp
+++ b/llvm/lib/MC/TargetRegistry.cpp
@@ -16,7 +16,6 @@
#include "llvm/MC/MCLFI.h"
#include "llvm/MC/MCObjectStreamer.h"
#include "llvm/MC/MCObjectWriter.h"
-#include "llvm/Support/Regex.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
#include <vector>
@@ -29,8 +28,17 @@ bool Target::isValidFeatureListFormat(StringRef Features) {
if (Features.empty())
return true;
- static const llvm::Regex pattern("^([+-][^,]+)(,[+-][^,]+)*,?$");
- return pattern.match(Features);
+ // Each feature starts with '+'/'-' followed by at least one non-comma
+ // character. Features are comma-separated with an optional trailing comma.
+ for (size_t I = 0, E = Features.size(); I != E; ++I) {
+ if (I == 0 || Features[I - 1] == ',') {
+ // At the start of a feature: must have a sign and a non-empty name.
+ if ((Features[I] != '+' && Features[I] != '-') ||
+ I + 1 == Features.size() || Features[I + 1] == ',')
+ return false;
+ }
+ }
+ return true;
}
MCStreamer *Target::createMCObjectStreamer(
More information about the llvm-commits
mailing list