[llvm] [llvm] Change the implementation of isValidFeatureListFormat (PR #219266)
Jun Wang via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 27 11:55:40 PDT 2026
https://github.com/jwanggit86 created https://github.com/llvm/llvm-project/pull/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.
>From 00b727d9c24698212181e9ba2e754d1f4446985b Mon Sep 17 00:00:00 2001
From: Jun Wang <jwang86 at yahoo.com>
Date: Thu, 27 Aug 2026 11:44:02 -0700
Subject: [PATCH] [llvm] Change the implementation of isValidFeatureListFormat
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.
---
llvm/lib/MC/TargetRegistry.cpp | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/MC/TargetRegistry.cpp b/llvm/lib/MC/TargetRegistry.cpp
index 2727e587496f3..c8a154b3dcb1f 100644
--- a/llvm/lib/MC/TargetRegistry.cpp
+++ b/llvm/lib/MC/TargetRegistry.cpp
@@ -29,8 +29,23 @@ bool Target::isValidFeatureListFormat(StringRef Features) {
if (Features.empty())
return true;
- static const llvm::Regex pattern("^([+-][^,]+)(,[+-][^,]+)*,?$");
- return pattern.match(Features);
+ // Each feature starts with a '+' or '-' and ends with a ',', except
+ // the trailing comma is optional for the last feature.
+ if (Features[0] != '+' && Features[0] != '-')
+ return false;
+
+ for (size_t I = 0; I < Features.size(); ++I) {
+ if (Features[I] == ',') {
+ if (I + 1 == Features.size()) // trailing comma
+ break;
+ if (Features[I + 1] != '+' && Features[I + 1] != '-')
+ return false;
+ } else if (Features[I] == '+' || Features[I] == '-') {
+ if (I + 1 == Features.size() || Features[I + 1] == ',') // empty feature
+ return false;
+ }
+ }
+ return true;
}
MCStreamer *Target::createMCObjectStreamer(
More information about the llvm-commits
mailing list