[llvm] r315571 - [AsmParser] Suppress compile warning for targets with no register diags

Oliver Stannard via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 12 02:28:24 PDT 2017


Author: olista01
Date: Thu Oct 12 02:28:23 2017
New Revision: 315571

URL: http://llvm.org/viewvc/llvm-project?rev=315571&view=rev
Log:
[AsmParser] Suppress compile warning for targets with no register diags

This fixes the "switch statement contains 'default' but no 'case' labels"
warnings in table-generated code introduced in r315295.


Modified:
    llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp

Modified: llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp?rev=315571&r1=315570&r2=315571&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/AsmMatcherEmitter.cpp Thu Oct 12 02:28:23 2017
@@ -2256,20 +2256,26 @@ static void emitOperandMatchErrorDiagStr
 static void emitRegisterMatchErrorFunc(AsmMatcherInfo &Info, raw_ostream &OS) {
   OS << "static unsigned getDiagKindFromRegisterClass(MatchClassKind "
         "RegisterClass) {\n";
-  OS << "  switch (RegisterClass) {\n";
-
-  for (const auto &CI: Info.Classes) {
-    if (CI.isRegisterClass() && !CI.DiagnosticType.empty()) {
-      OS << "  case " << CI.Name << ":\n";
-      OS << "    return " << Info.Target.getName() << "AsmParser::Match_"
-         << CI.DiagnosticType << ";\n";
+  if (std::none_of(Info.Classes.begin(), Info.Classes.end(),
+                   [](const ClassInfo &CI) {
+                     return CI.isRegisterClass() && !CI.DiagnosticType.empty();
+                   })) {
+    OS << "  return MCTargetAsmParser::Match_InvalidOperand;\n";
+  } else {
+    OS << "  switch (RegisterClass) {\n";
+    for (const auto &CI: Info.Classes) {
+      if (CI.isRegisterClass() && !CI.DiagnosticType.empty()) {
+        OS << "  case " << CI.Name << ":\n";
+        OS << "    return " << Info.Target.getName() << "AsmParser::Match_"
+           << CI.DiagnosticType << ";\n";
+      }
     }
-  }
 
-  OS << "  default:\n";
-  OS << "    return MCTargetAsmParser::Match_InvalidOperand;\n";
+    OS << "  default:\n";
+    OS << "    return MCTargetAsmParser::Match_InvalidOperand;\n";
 
-  OS << "  }\n";
+    OS << "  }\n";
+  }
   OS << "}\n\n";
 }
 




More information about the llvm-commits mailing list