From b5e990c4ac8efef0ee97ec6e380086cd6d4c0846 Mon Sep 17 00:00:00 2001 From: Oliver Stannard Date: Thu, 12 Oct 2017 09:28:23 +0000 Subject: [PATCH] [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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315571 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/TableGen/AsmMatcherEmitter.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/utils/TableGen/AsmMatcherEmitter.cpp b/utils/TableGen/AsmMatcherEmitter.cpp index a345b19024e..fd1d7e0dba4 100644 --- a/utils/TableGen/AsmMatcherEmitter.cpp +++ b/utils/TableGen/AsmMatcherEmitter.cpp @@ -2256,20 +2256,26 @@ static void emitOperandMatchErrorDiagStrings(AsmMatcherInfo &Info, raw_ostream & 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"; } -- 2.50.1