aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/TableGenFundamentals.html3
-rw-r--r--test/TableGen/ifbit.td11
-rw-r--r--utils/TableGen/Record.cpp6
3 files changed, 17 insertions, 3 deletions
diff --git a/docs/TableGenFundamentals.html b/docs/TableGenFundamentals.html
index 3410cac..f7a082d 100644
--- a/docs/TableGenFundamentals.html
+++ b/docs/TableGenFundamentals.html
@@ -422,7 +422,8 @@ class. This operation is analogous to $(foreach) in GNU make.</dd>
<dt><tt>!null(a)</tt></dt>
<dd>An integer {0,1} indicating whether list 'a' is empty.</dd>
<dt><tt>!if(a,b,c)</tt></dt>
- <dd>'b' if the result of integer operator 'a' is nonzero, 'c' otherwise.</dd>
+ <dd>'b' if the result of 'int' or 'bit' operator 'a' is nonzero,
+ 'c' otherwise.</dd>
<dt><tt>!eq(a,b)</tt></dt>
<dd>Integer one if string a is equal to string b, zero otherwise. This
only operates on string, int and bit objects. Use !cast<string> to
diff --git a/test/TableGen/ifbit.td b/test/TableGen/ifbit.td
new file mode 100644
index 0000000..3b0349e
--- /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<bit b = 1> {
+ 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 d9c5dd3..53a4abd 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<IntInit*>(LHS);
+ IntInit *LHSi =
+ dynamic_cast<IntInit*>(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<IntInit*>(lhs);
+ IntInit *Value =
+ dynamic_cast<IntInit*>(LHS->convertInitializerTo(new IntRecTy()));
if (Value != 0) {
// Short-circuit
if (Value->getValue()) {