From f410ef7d961f7ca17a5589ade14f4165170e4d26 Mon Sep 17 00:00:00 2001 From: Nicolai Haehnle Date: Thu, 22 Feb 2018 15:27:12 +0000 Subject: [PATCH] TableGen: Add strict assertions to sanity check earlier type checking 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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@325800 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/TableGen/Record.h | 2 ++ lib/TableGen/Record.cpp | 3 +++ 2 files changed, 5 insertions(+) diff --git a/include/llvm/TableGen/Record.h b/include/llvm/TableGen/Record.h index 0d55c032f22..0c27f395cfb 100644 --- a/include/llvm/TableGen/Record.h +++ b/include/llvm/TableGen/Record.h @@ -1241,6 +1241,8 @@ public: bool setValue(Init *V) { if (V) { Value = V->convertInitializerTo(getType()); + assert(!Value || !isa(Value) || + cast(Value)->getType()->typeIsConvertibleTo(getType())); return Value == nullptr; } Value = nullptr; diff --git a/lib/TableGen/Record.cpp b/lib/TableGen/Record.cpp index 9a9f43de167..f447b3b1b47 100644 --- a/lib/TableGen/Record.cpp +++ b/lib/TableGen/Record.cpp @@ -478,6 +478,9 @@ ListInit *ListInit::get(ArrayRef Range, RecTy *EltTy) { if (ListInit *I = ThePool.FindNodeOrInsertPos(ID, IP)) return I; + assert(Range.empty() || !isa(Range[0]) || + cast(Range[0])->getType()->typeIsConvertibleTo(EltTy)); + void *Mem = Allocator.Allocate(totalSizeToAlloc(Range.size()), alignof(ListInit)); ListInit *I = new(Mem) ListInit(Range.size(), EltTy); -- 2.11.0