[llvm] [llvm] Change the implementation of isValidFeatureListFormat (PR #219266)
Jun Wang via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 27 15:54:36 PDT 2026
https://github.com/jwanggit86 updated https://github.com/llvm/llvm-project/pull/219266
>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 1/4] [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(
>From b099feec6e743581ec9925002df2a68d8c4b20b5 Mon Sep 17 00:00:00 2001
From: Jun Wang <jwang86 at yahoo.com>
Date: Thu, 27 Aug 2026 15:15:48 -0700
Subject: [PATCH 2/4] Allow +/- to be part of a feature substring, as previous
Regex does.
---
llvm/lib/MC/TargetRegistry.cpp | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/llvm/lib/MC/TargetRegistry.cpp b/llvm/lib/MC/TargetRegistry.cpp
index c8a154b3dcb1f..3bce62b623834 100644
--- a/llvm/lib/MC/TargetRegistry.cpp
+++ b/llvm/lib/MC/TargetRegistry.cpp
@@ -29,19 +29,13 @@ bool Target::isValidFeatureListFormat(StringRef Features) {
if (Features.empty())
return true;
- // 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;
-
+ // 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; 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
+ 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;
}
}
>From 0b00b9f83e038ca2304de6fe3d94ef8a3103be45 Mon Sep 17 00:00:00 2001
From: Jun Wang <jwang86 at yahoo.com>
Date: Thu, 27 Aug 2026 15:26:18 -0700
Subject: [PATCH 3/4] Remove the #include directive for Regex.h
---
llvm/lib/MC/TargetRegistry.cpp | 1 -
1 file changed, 1 deletion(-)
diff --git a/llvm/lib/MC/TargetRegistry.cpp b/llvm/lib/MC/TargetRegistry.cpp
index 3bce62b623834..ca0621dba4815 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>
>From 71557a8849ba35fdf1723f208ffcf179be90bde9 Mon Sep 17 00:00:00 2001
From: Jun Wang <jwang86 at yahoo.com>
Date: Thu, 27 Aug 2026 15:54:01 -0700
Subject: [PATCH 4/4] Fix for-loop head
---
llvm/lib/MC/TargetRegistry.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/MC/TargetRegistry.cpp b/llvm/lib/MC/TargetRegistry.cpp
index ca0621dba4815..185f63637a460 100644
--- a/llvm/lib/MC/TargetRegistry.cpp
+++ b/llvm/lib/MC/TargetRegistry.cpp
@@ -30,7 +30,7 @@ bool Target::isValidFeatureListFormat(StringRef 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; I < Features.size(); ++I) {
+ 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] != '-') ||
More information about the llvm-commits
mailing list