From 6a224c30a5d358305e6cfda1a62a78f658baa943 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Fri, 31 Jul 2015 01:12:06 +0000 Subject: [PATCH] TableGen: Support folding casts from bits to int This is to fix an incorrect error when trying to initialize DwarfNumbers with a !cast of a bits initializer. getValuesAsListOfInts("DwarfNumbers") would not see an IntInit and instead the cast, so would give up. It seems likely that this could be generalized to attempt the convertInitializerTo for any type. I'm not really sure why the existing code seems to special case the string cast cases when convertInitializerTo seems like it should generally handle this sort of thing. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@243722 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/TableGen/Record.cpp | 8 ++++++++ test/TableGen/cast-list-initializer.td | 10 ++++++++++ 2 files changed, 18 insertions(+) create mode 100644 test/TableGen/cast-list-initializer.td diff --git a/lib/TableGen/Record.cpp b/lib/TableGen/Record.cpp index c9a31b64cfd..271e52567a2 100644 --- a/lib/TableGen/Record.cpp +++ b/lib/TableGen/Record.cpp @@ -673,6 +673,14 @@ Init *UnOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const { PrintFatalError(CurRec->getLoc(), "Undefined reference:'" + Name + "'\n"); } + + if (isa(getType())) { + if (BitsInit *BI = dyn_cast(LHS)) { + if (Init *NewInit = BI->convertInitializerTo(IntRecTy::get())) + return NewInit; + break; + } + } } break; } diff --git a/test/TableGen/cast-list-initializer.td b/test/TableGen/cast-list-initializer.td new file mode 100644 index 00000000000..4c83773a5a7 --- /dev/null +++ b/test/TableGen/cast-list-initializer.td @@ -0,0 +1,10 @@ +// RUN: llvm-tblgen %s | FileCheck %s + +class Foo b> { +// CHECK: list ListOfInts = [170]; +// CHECK: list AnotherList = [170, 7]; + list ListOfInts = [!cast(b)]; + list AnotherList = [!cast(b), !cast({1, 1, 1})]; +} + +def : Foo<{1, 0, 1, 0, 1, 0, 1, 0}>; -- 2.34.1