[PATCH] D81074: [TableGen] Add error messages
Sebastian Neubauer via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 4 02:40:29 PDT 2020
Flakebi updated this revision to Diff 268395.
Flakebi added a comment.
Thank you for the fast review!
> What breaks if the table is empty?
In the case where I encountered it, the types cannot be determined because the for loop is never executed and it crashed below, trying to access null types.
I guess you are right that empty tables can work if all types are specified, so I changed it to a warning as you suggested and throw a fatal error only if a type does not exist.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D81074/new/
https://reviews.llvm.org/D81074
Files:
llvm/utils/TableGen/SearchableTableEmitter.cpp
Index: llvm/utils/TableGen/SearchableTableEmitter.cpp
===================================================================
--- llvm/utils/TableGen/SearchableTableEmitter.cpp
+++ llvm/utils/TableGen/SearchableTableEmitter.cpp
@@ -119,9 +119,12 @@
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::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 @@
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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81074.268395.patch
Type: text/x-patch
Size: 1798 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200604/2672e85c/attachment.bin>
More information about the llvm-commits
mailing list