[llvm] d668d8b - [TableGen] Add error messages
Sebastian Neubauer via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 23 03:03:30 PDT 2020
Author: Sebastian Neubauer
Date: 2020-06-23T11:52:12+02:00
New Revision: d668d8b6197545cb8d8749c5c58b18ccd4468ddd
URL: https://github.com/llvm/llvm-project/commit/d668d8b6197545cb8d8749c5c58b18ccd4468ddd
DIFF: https://github.com/llvm/llvm-project/commit/d668d8b6197545cb8d8749c5c58b18ccd4468ddd.diff
LOG: [TableGen] Add error messages
Print an error instead of crashing in two places.
Differential Revision: https://reviews.llvm.org/D81074
Added:
Modified:
llvm/utils/TableGen/SearchableTableEmitter.cpp
Removed:
################################################################################
diff --git a/llvm/utils/TableGen/SearchableTableEmitter.cpp b/llvm/utils/TableGen/SearchableTableEmitter.cpp
index 0c79a2a6938f..326cb4e54edc 100644
--- a/llvm/utils/TableGen/SearchableTableEmitter.cpp
+++ b/llvm/utils/TableGen/SearchableTableEmitter.cpp
@@ -119,9 +119,12 @@ class SearchableTableEmitter {
return "Intrinsic::" + getIntrinsic(I).EnumName;
else if (Field.IsInstruction)
return I->getAsString();
- else if (Field.Enum)
- return std::string(
- Field.Enum->EntryMap[cast<DefInit>(I)->getDef()]->first);
+ else if (Field.Enum) {
+ auto *Entry = Field.Enum->EntryMap[cast<DefInit>(I)->getDef()];
+ if (!Entry)
+ PrintFatalError(Twine("Entry for field '") + Field.Name + "' is null");
+ return std::string(Entry->first);
+ }
PrintFatalError(Twine("invalid field type for field '") + Field.Name +
"', expected: string, bits, bit or code");
}
@@ -596,6 +599,9 @@ void SearchableTableEmitter::collectEnumEntries(
void SearchableTableEmitter::collectTableEntries(
GenericTable &Table, const std::vector<Record *> &Items) {
+ if (Items.empty())
+ PrintWarning(Twine("Table '") + Table.Name + "' has no items");
+
for (auto EntryRec : Items) {
for (auto &Field : Table.Fields) {
auto TI = dyn_cast<TypedInit>(EntryRec->getValueInit(Field.Name));
@@ -624,6 +630,10 @@ void SearchableTableEmitter::collectTableEntries(
Record *IntrinsicClass = Records.getClass("Intrinsic");
Record *InstructionClass = Records.getClass("Instruction");
for (auto &Field : Table.Fields) {
+ if (!Field.RecType)
+ PrintFatalError(Twine("Cannot determine type of field '") + Field.Name +
+ "' in table '" + Table.Name + "'. Maybe it is not used?");
+
if (auto RecordTy = dyn_cast<RecordRecTy>(Field.RecType)) {
if (IntrinsicClass && RecordTy->isSubClassOf(IntrinsicClass))
Field.IsIntrinsic = true;
More information about the llvm-commits
mailing list