Avoid generating underlying value to symbol conversion function if there is an enumer...
authorLei Zhang <antiagainst@google.com>
Mon, 1 Jul 2019 13:51:39 +0000 (06:51 -0700)
committerjpienaar <jpienaar@google.com>
Mon, 1 Jul 2019 16:55:59 +0000 (09:55 -0700)
PiperOrigin-RevId: 255945801

mlir/tools/mlir-tblgen/EnumsGen.cpp

index 962a7ea..b750e0a 100644 (file)
@@ -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")