From: Mehdi Amini Date: Sat, 22 Jul 2023 04:47:33 +0000 (-0700) Subject: Fix crash in ODS backend for Type/Attr when an incorrect construct is used for Type... X-Git-Tag: upstream/17.0.6~728 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5f1a388a11ae67c2e5d7a4d1fe45e369a393c572;p=platform%2Fupstream%2Fllvm.git 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. --- 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 {