TableGen: Add strict assertions to sanity check earlier type checking
authorNicolai Haehnle <nhaehnle@gmail.com>
Thu, 22 Feb 2018 15:27:12 +0000 (15:27 +0000)
committerNicolai Haehnle <nhaehnle@gmail.com>
Thu, 22 Feb 2018 15:27:12 +0000 (15:27 +0000)
Summary:
Both of these errors should have been caught by type-checking during
parsing.

Change-Id: I891087936fd1a91d21bcda57c256e3edbe12b94d

Reviewers: arsenm, craig.topper, tra, MartinO

Subscribers: wdng, llvm-commits

Differential Revision: https://reviews.llvm.org/D43558

llvm-svn: 325800

llvm/include/llvm/TableGen/Record.h
llvm/lib/TableGen/Record.cpp

index 0d55c032f2223a1a285fee7e4aab777a17aae6e8..0c27f395cfbd0c98d5269b615999f84535f3aba7 100644 (file)
@@ -1241,6 +1241,8 @@ public:
   bool setValue(Init *V) {
     if (V) {
       Value = V->convertInitializerTo(getType());
+      assert(!Value || !isa<TypedInit>(Value) ||
+             cast<TypedInit>(Value)->getType()->typeIsConvertibleTo(getType()));
       return Value == nullptr;
     }
     Value = nullptr;
index 9a9f43de167ef1266d2c8aaf30353a1009f637fe..f447b3b1b4774639b14566653e07654458b4a35c 100644 (file)
@@ -478,6 +478,9 @@ ListInit *ListInit::get(ArrayRef<Init *> Range, RecTy *EltTy) {
   if (ListInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
     return I;
 
+  assert(Range.empty() || !isa<TypedInit>(Range[0]) ||
+         cast<TypedInit>(Range[0])->getType()->typeIsConvertibleTo(EltTy));
+
   void *Mem = Allocator.Allocate(totalSizeToAlloc<Init *>(Range.size()),
                                  alignof(ListInit));
   ListInit *I = new(Mem) ListInit(Range.size(), EltTy);