[Mlir-commits] [mlir] 5f1a388 - Fix crash in ODS backend for Type/Attr when an incorrect construct is used for Type/Attr
Mehdi Amini
llvmlistbot at llvm.org
Fri Jul 21 22:06:13 PDT 2023
Author: Mehdi Amini
Date: 2023-07-21T22:06:02-07:00
New Revision: 5f1a388a11ae67c2e5d7a4d1fe45e369a393c572
URL: https://github.com/llvm/llvm-project/commit/5f1a388a11ae67c2e5d7a4d1fe45e369a393c572
DIFF: https://github.com/llvm/llvm-project/commit/5f1a388a11ae67c2e5d7a4d1fe45e369a393c572.diff
LOG: 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.
Added:
Modified:
mlir/lib/TableGen/AttrOrTypeDef.cpp
Removed:
################################################################################
diff --git a/mlir/lib/TableGen/AttrOrTypeDef.cpp b/mlir/lib/TableGen/AttrOrTypeDef.cpp
index e9fc9274dee9e8..56c96ffd159cfd 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<llvm::StringInit>(getDef()))
return stringType->getValue();
- return *getDefValue<llvm::StringInit>("cppType");
+ auto cppType = getDefValue<llvm::StringInit>("cppType");
+ if (cppType)
+ return *cppType;
+ if (auto *init = dyn_cast<llvm::DefInit>(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 {
More information about the Mlir-commits
mailing list