[flang-commits] [flang] [flang][cli] Add diagnostic flags to the CLI (PR #142022)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Sat May 31 13:17:38 PDT 2025


================
@@ -107,44 +114,138 @@ static std::optional<char> GetWarningChar(char ch) {
   }
 }
 
-static bool WarningNameMatch(const char *a, const char *b) {
+// Check for case and punctuation insensitive string equality.
+// NB, b is probably not null terminated, so don't treat is like a C string.
+static bool InsensitiveWarningNameMatch(
+    std::string_view a, std::string_view b) {
+  size_t j{0}, aSize{a.size()}, k{0}, bSize{b.size()};
   while (true) {
-    auto ach{GetWarningChar(*a)};
-    while (!ach && *a) {
-      ach = GetWarningChar(*++a);
+    optional<char> ach{nullopt};
+    while (!ach && j < aSize) {
+      ach = GetWarningChar(a[j++]);
     }
-    auto bch{GetWarningChar(*b)};
-    while (!bch && *b) {
-      bch = GetWarningChar(*++b);
+    optional<char> bch{};
+    while (!bch && k < bSize) {
+      bch = GetWarningChar(b[k++]);
     }
     if (!ach && !bch) {
       return true;
     } else if (!ach || !bch || *ach != *bch) {
       return false;
     }
-    ++a, ++b;
+    ach = bch = nullopt;
   }
 }
 
-template <typename ENUM, std::size_t N>
-std::optional<ENUM> ScanEnum(const char *name) {
-  if (name) {
-    for (std::size_t j{0}; j < N; ++j) {
-      auto feature{static_cast<ENUM>(j)};
-      if (WarningNameMatch(name, EnumToString(feature).data())) {
-        return feature;
+// Check if lower case hyphenated words are equal to camel case words.
+// Because of out use case we know that 'r' the camel case string is
+// well formed in the sense that it is a sequence [a-zA-Z]+[a-zA-Z0-9]*.
+// This is checked in the enum-class.h file.
+static bool SensitiveWarningNameMatch(llvm::StringRef l, llvm::StringRef r) {
----------------
klausler wrote:

Would this algorithm be more clear if you essentially converted the optional name to CamelCase by using hyphens to indicate capitalization of the following letter?

https://github.com/llvm/llvm-project/pull/142022


More information about the flang-commits mailing list