[llvm] 1cfb207 - [TableGen] Report an error instead of asserting
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 17 03:33:11 PDT 2020
Author: Jay Foad
Date: 2020-07-17T11:32:46+01:00
New Revision: 1cfb207737cc347baeb55999bd2cbd46fb5d9309
URL: https://github.com/llvm/llvm-project/commit/1cfb207737cc347baeb55999bd2cbd46fb5d9309
DIFF: https://github.com/llvm/llvm-project/commit/1cfb207737cc347baeb55999bd2cbd46fb5d9309.diff
LOG: [TableGen] Report an error instead of asserting
This gives a nice error if you accidentally try to use an empty list for
the RegTypes of a RegisterClass.
Differential Revision: https://reviews.llvm.org/D78285
Added:
llvm/test/TableGen/RegisterClass.td
Modified:
llvm/utils/TableGen/CodeGenRegisters.cpp
Removed:
################################################################################
diff --git a/llvm/test/TableGen/RegisterClass.td b/llvm/test/TableGen/RegisterClass.td
new file mode 100644
index 000000000000..d81c2df45309
--- /dev/null
+++ b/llvm/test/TableGen/RegisterClass.td
@@ -0,0 +1,7 @@
+// RUN: not llvm-tblgen -gen-register-bank -I %p/../../include %s 2>&1 | FileCheck %s
+
+include "llvm/Target/Target.td"
+
+def MyTarget : Target;
+def R0 : Register<"r0">;
+def ClassA : RegisterClass<"MyTarget", [], 32, (add R0)>; // CHECK: [[@LINE]]:1: error: RegTypes list must not be empty!
diff --git a/llvm/utils/TableGen/CodeGenRegisters.cpp b/llvm/utils/TableGen/CodeGenRegisters.cpp
index 4584bc7cfae3..eeb715dded43 100644
--- a/llvm/utils/TableGen/CodeGenRegisters.cpp
+++ b/llvm/utils/TableGen/CodeGenRegisters.cpp
@@ -743,6 +743,8 @@ CodeGenRegisterClass::CodeGenRegisterClass(CodeGenRegBank &RegBank, Record *R)
TopoSigs(RegBank.getNumTopoSigs()), EnumValue(-1) {
GeneratePressureSet = R->getValueAsBit("GeneratePressureSet");
std::vector<Record*> TypeList = R->getValueAsListOfDefs("RegTypes");
+ if (TypeList.empty())
+ PrintFatalError(R->getLoc(), "RegTypes list must not be empty!");
for (unsigned i = 0, e = TypeList.size(); i != e; ++i) {
Record *Type = TypeList[i];
if (!Type->isSubClassOf("ValueType"))
@@ -751,7 +753,6 @@ CodeGenRegisterClass::CodeGenRegisterClass(CodeGenRegBank &RegBank, Record *R)
"' does not derive from the ValueType class!");
VTs.push_back(getValueTypeByHwMode(Type, RegBank.getHwModes()));
}
- assert(!VTs.empty() && "RegisterClass must contain at least one ValueType!");
// Allocation order 0 is the full set. AltOrders provides others.
const SetTheory::RecVec *Elements = RegBank.getSets().expand(R);
More information about the llvm-commits
mailing list