]> granicus.if.org Git - llvm/commitdiff
Fix a bug with casts to bool. This fixes testcase UnitTests/2003-05-31-CastToBool.c
authorChris Lattner <sabre@nondot.org>
Sun, 1 Jun 2003 03:36:51 +0000 (03:36 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 1 Jun 2003 03:36:51 +0000 (03:36 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6507 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/CBackend/CBackend.cpp
lib/Target/CBackend/Writer.cpp

index df95757200bde134e9ede0b5609a956459dc101f..a12afa7958136792d26602de992a123a86dc8000 100644 (file)
@@ -997,6 +997,12 @@ void CWriter::visitBinaryOperator(Instruction &I) {
 }
 
 void CWriter::visitCastInst(CastInst &I) {
+  if (I.getType() == Type::BoolTy) {
+    Out << "(";
+    writeOperand(I.getOperand(0));
+    Out << " != 0)";
+    return;
+  }
   Out << "(";
   printType(Out, I.getType(), "", /*ignoreName*/false, /*namedContext*/false);
   Out << ")";
@@ -1005,7 +1011,7 @@ void CWriter::visitCastInst(CastInst &I) {
     // Avoid "cast to pointer from integer of different size" warnings
     Out << "(long)";  
   }
-
+  
   writeOperand(I.getOperand(0));
 }
 
index df95757200bde134e9ede0b5609a956459dc101f..a12afa7958136792d26602de992a123a86dc8000 100644 (file)
@@ -997,6 +997,12 @@ void CWriter::visitBinaryOperator(Instruction &I) {
 }
 
 void CWriter::visitCastInst(CastInst &I) {
+  if (I.getType() == Type::BoolTy) {
+    Out << "(";
+    writeOperand(I.getOperand(0));
+    Out << " != 0)";
+    return;
+  }
   Out << "(";
   printType(Out, I.getType(), "", /*ignoreName*/false, /*namedContext*/false);
   Out << ")";
@@ -1005,7 +1011,7 @@ void CWriter::visitCastInst(CastInst &I) {
     // Avoid "cast to pointer from integer of different size" warnings
     Out << "(long)";  
   }
-
+  
   writeOperand(I.getOperand(0));
 }