[cfe-commits] r62060 - in /cfe/trunk: lib/CodeGen/CGExprScalar.cpp test/CodeGenCXX/expr.cpp

Nuno Lopes nunoplopes at sapo.pt
Sun Jan 11 15:22:37 PST 2009


Author: nlopes
Date: Sun Jan 11 17:22:37 2009
New Revision: 62060

URL: http://llvm.org/viewvc/llvm-project?rev=62060&view=rev
Log:
make ScalarExprEmitter::EmitCompare() emit the expression with the correct type instead of always zext it to an int
this fixes codegen of simple exprs in C++ like 'if (x != 0)'

Added:
    cfe/trunk/test/CodeGenCXX/expr.cpp
Modified:
    cfe/trunk/lib/CodeGen/CGExprScalar.cpp

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=62060&r1=62059&r2=62060&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Sun Jan 11 17:22:37 2009
@@ -1021,9 +1021,8 @@
       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) {

Added: cfe/trunk/test/CodeGenCXX/expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/expr.cpp?rev=62060&view=auto

==============================================================================
--- cfe/trunk/test/CodeGenCXX/expr.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/expr.cpp Sun Jan 11 17:22:37 2009
@@ -0,0 +1,5 @@
+// RUN: clang -emit-llvm -x c++ < %s
+
+void f(int x) {
+          if (x != 0) return;
+}





More information about the cfe-commits mailing list