From 5f1a388a11ae67c2e5d7a4d1fe45e369a393c572 Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Fri, 21 Jul 2023 21:47:33 -0700 Subject: [PATCH] Fix crash in ODS backend for Type/Attr when an incorrect construct is used for Type/Attr Instead of crashing, try to print a useful error message. --- mlir/lib/TableGen/AttrOrTypeDef.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/mlir/lib/TableGen/AttrOrTypeDef.cpp b/mlir/lib/TableGen/AttrOrTypeDef.cpp index e9fc927..56c96ff 100644 --- a/mlir/lib/TableGen/AttrOrTypeDef.cpp +++ b/mlir/lib/TableGen/AttrOrTypeDef.cpp @@ -11,6 +11,7 @@ #include "llvm/ADT/FunctionExtras.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/Support/ErrorHandling.h" #include "llvm/TableGen/Error.h" #include "llvm/TableGen/Record.h" @@ -257,7 +258,18 @@ StringRef AttrOrTypeParameter::getComparator() const { StringRef AttrOrTypeParameter::getCppType() const { if (auto *stringType = dyn_cast(getDef())) return stringType->getValue(); - return *getDefValue("cppType"); + auto cppType = getDefValue("cppType"); + if (cppType) + return *cppType; + if (auto *init = dyn_cast(getDef())) + llvm::PrintFatalError( + init->getDef()->getLoc(), + Twine("Missing `cppType` field in Attribute/Type parameter: ") + + init->getAsString()); + llvm::report_fatal_error( + Twine("Missing `cppType` field in Attribute/Type parameter: ") + + getDef()->getAsString(), + /*gen_crash_diag=*/false); } StringRef AttrOrTypeParameter::getCppAccessorType() const { -- 2.7.4