From eba8f1893b5d8b115fc4d537cddf02f1a9269dda Mon Sep 17 00:00:00 2001 From: Bruno Cardoso Lopes Date: Thu, 17 Jun 2010 00:31:36 +0000 Subject: [PATCH] For a tablegen expression such as !if(a,b,c), let 'a' be evaluated for 'bit' operators git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@106185 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/TableGenFundamentals.html | 3 ++- test/TableGen/ifbit.td | 11 +++++++++++ utils/TableGen/Record.cpp | 6 ++++-- 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 test/TableGen/ifbit.td diff --git a/docs/TableGenFundamentals.html b/docs/TableGenFundamentals.html index 3410cacb62d..f7a082d7050 100644 --- a/docs/TableGenFundamentals.html +++ b/docs/TableGenFundamentals.html @@ -422,7 +422,8 @@ class. This operation is analogous to $(foreach) in GNU make.
!null(a)
An integer {0,1} indicating whether list 'a' is empty.
!if(a,b,c)
-
'b' if the result of integer operator 'a' is nonzero, 'c' otherwise.
+
'b' if the result of 'int' or 'bit' operator 'a' is nonzero, + 'c' otherwise.
!eq(a,b)
Integer one if string a is equal to string b, zero otherwise. This only operates on string, int and bit objects. Use !cast to diff --git a/test/TableGen/ifbit.td b/test/TableGen/ifbit.td new file mode 100644 index 00000000000..3b0349e19b4 --- /dev/null +++ b/test/TableGen/ifbit.td @@ -0,0 +1,11 @@ +// RUN: tblgen %s | FileCheck %s +// XFAIL: vg_leak +// CHECK: a = 6 +// CHECK: a = 5 + +class A { + int a = !if(b, 5, 6); +} + +def X : A<0>; +def Y : A; diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp index d9c5dd30e18..53a4abdaf2b 100644 --- a/utils/TableGen/Record.cpp +++ b/utils/TableGen/Record.cpp @@ -981,7 +981,8 @@ Init *TernOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) { } case IF: { - IntInit *LHSi = dynamic_cast(LHS); + IntInit *LHSi = + dynamic_cast(LHS->convertInitializerTo(new IntRecTy())); if (LHSi) { if (LHSi->getValue()) { return MHS; @@ -1000,7 +1001,8 @@ Init *TernOpInit::resolveReferences(Record &R, const RecordVal *RV) { Init *lhs = LHS->resolveReferences(R, RV); if (Opc == IF && lhs != LHS) { - IntInit *Value = dynamic_cast(lhs); + IntInit *Value = + dynamic_cast(LHS->convertInitializerTo(new IntRecTy())); if (Value != 0) { // Short-circuit if (Value->getValue()) { -- 2.34.1