Fix the handling of !if result, avoiding null results for non 'int'.
authorBruno Cardoso Lopes <bruno.cardoso@gmail.com>
Thu, 17 Jun 2010 01:50:39 +0000 (01:50 +0000)
committerBruno Cardoso Lopes <bruno.cardoso@gmail.com>
Thu, 17 Jun 2010 01:50:39 +0000 (01:50 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@106201 91177308-0d34-0410-b5e6-96231b3b80d8

utils/TableGen/Record.cpp

index 53a4abdaf2bde9c9117e2c114eeac8b9efefde5c..f0147d328b8ea32cb45e7e62927797ce81ca2a15 100644 (file)
@@ -981,8 +981,9 @@ Init *TernOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) {
   }
 
   case IF: {
-    IntInit *LHSi =
-      dynamic_cast<IntInit*>(LHS->convertInitializerTo(new IntRecTy()));
+    IntInit *LHSi = dynamic_cast<IntInit*>(LHS);
+    if (Init *I = LHS->convertInitializerTo(new IntRecTy()))
+      LHSi = dynamic_cast<IntInit*>(I);
     if (LHSi) {
       if (LHSi->getValue()) {
         return MHS;
@@ -1001,8 +1002,9 @@ 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->convertInitializerTo(new IntRecTy()));
+    IntInit *Value = dynamic_cast<IntInit*>(lhs);
+    if (Init *I = lhs->convertInitializerTo(new IntRecTy()))
+      Value = dynamic_cast<IntInit*>(I);
     if (Value != 0) {
       // Short-circuit
       if (Value->getValue()) {