]> granicus.if.org Git - clang/commitdiff
make ScalarExprEmitter::EmitCompare() emit the expression with the correct type inste...
authorNuno Lopes <nunoplopes@sapo.pt>
Sun, 11 Jan 2009 23:22:37 +0000 (23:22 +0000)
committerNuno Lopes <nunoplopes@sapo.pt>
Sun, 11 Jan 2009 23:22:37 +0000 (23:22 +0000)
this fixes codegen of simple exprs in C++ like 'if (x != 0)'

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62060 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprScalar.cpp
test/CodeGenCXX/expr.cpp [new file with mode: 0644]

index 7b71d7b1294556125ea84f81aa042d38c802e67e..4bb5fd1a4ffbee2d0866c230615ca95d9d04e3aa 100644 (file)
@@ -1021,9 +1021,8 @@ Value *ScalarExprEmitter::EmitCompare(const BinaryOperator *E,unsigned UICmpOpc,
       Result = Builder.CreateOr(ResultR, ResultI, "or.ri");
     }
   }
-  
-  // ZExt result to int.
-  return Builder.CreateZExt(Result, CGF.LLVMIntTy, "cmp.ext");
+
+  return EmitScalarConversion(Result, CGF.getContext().BoolTy, E->getType());
 }
 
 Value *ScalarExprEmitter::VisitBinAssign(const BinaryOperator *E) {
diff --git a/test/CodeGenCXX/expr.cpp b/test/CodeGenCXX/expr.cpp
new file mode 100644 (file)
index 0000000..5b8efac
--- /dev/null
@@ -0,0 +1,5 @@
+// RUN: clang -emit-llvm -x c++ < %s
+
+void f(int x) {
+          if (x != 0) return;
+}