From 2652be7934433e91b92d029386ef55c429bc2496 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Mon, 1 Jul 2019 06:51:39 -0700 Subject: [PATCH] Avoid generating underlying value to symbol conversion function if there is an enumerant without explicit value. PiperOrigin-RevId: 255945801 --- mlir/tools/mlir-tblgen/EnumsGen.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mlir/tools/mlir-tblgen/EnumsGen.cpp b/mlir/tools/mlir-tblgen/EnumsGen.cpp index 962a7ea..b750e0a 100644 --- a/mlir/tools/mlir-tblgen/EnumsGen.cpp +++ b/mlir/tools/mlir-tblgen/EnumsGen.cpp @@ -167,6 +167,13 @@ static void emitUnderlyingToSymFn(const Record &enumDef, raw_ostream &os) { StringRef underlyingToSymFnName = enumAttr.getUnderlyingToSymbolFnName(); auto enumerants = enumAttr.getAllCases(); + // Avoid generating the underlying value to symbol conversion function if + // there is an enumerant without explicit value. + if (llvm::any_of(enumerants, [](EnumAttrCase enumerant) { + return enumerant.getValue() < 0; + })) + return; + os << formatv("llvm::Optional<{0}> {1}({2} value) {{\n", enumName, underlyingToSymFnName, underlyingType.empty() ? std::string("unsigned") -- 2.7.4