diff options
| author | Chris Lattner <sabre@nondot.org> | 2009-10-17 04:24:20 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2009-10-17 04:24:20 +0000 |
| commit | 671fec8727926eebea88265905e54cb82fafecc7 (patch) | |
| tree | b2a9141a40953bf07b33d1e8b8db858feef6c3dc /clang/lib/CodeGen | |
| parent | 6e924a3090e54a52da133bbdb8add7b8ef528d3a (diff) | |
| download | bcm5719-llvm-671fec8727926eebea88265905e54cb82fafecc7.tar.gz bcm5719-llvm-671fec8727926eebea88265905e54cb82fafecc7.zip | |
Fix PR5211: codegen shouldn't assume that the result of ||/&& is int
anymore. In C++ it is bool.
llvm-svn: 84308
Diffstat (limited to 'clang/lib/CodeGen')
| -rw-r--r-- | clang/lib/CodeGen/CGExprScalar.cpp | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index cc81256032a..422e2b65bca 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -1379,18 +1379,20 @@ Value *ScalarExprEmitter::VisitBinAssign(const BinaryOperator *E) { } Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) { + const llvm::Type *ResTy = ConvertType(E->getType()); + // If we have 0 && RHS, see if we can elide RHS, if so, just return 0. // If we have 1 && X, just emit X without inserting the control flow. if (int Cond = CGF.ConstantFoldsToSimpleInteger(E->getLHS())) { if (Cond == 1) { // If we have 1 && X, just emit X. Value *RHSCond = CGF.EvaluateExprAsBool(E->getRHS()); - // ZExt result to int. - return Builder.CreateZExt(RHSCond, CGF.LLVMIntTy, "land.ext"); + // ZExt result to int or bool. + return Builder.CreateZExtOrBitCast(RHSCond, ResTy, "land.ext"); } - // 0 && RHS: If it is safe, just elide the RHS, and return 0. + // 0 && RHS: If it is safe, just elide the RHS, and return 0/false. if (!CGF.ContainsLabel(E->getRHS())) - return llvm::Constant::getNullValue(CGF.LLVMIntTy); + return llvm::Constant::getNullValue(ResTy); } llvm::BasicBlock *ContBlock = CGF.createBasicBlock("land.end"); @@ -1423,22 +1425,24 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) { PN->addIncoming(RHSCond, RHSBlock); // ZExt result to int. - return Builder.CreateZExt(PN, CGF.LLVMIntTy, "land.ext"); + return Builder.CreateZExtOrBitCast(PN, ResTy, "land.ext"); } Value *ScalarExprEmitter::VisitBinLOr(const BinaryOperator *E) { + const llvm::Type *ResTy = ConvertType(E->getType()); + // If we have 1 || RHS, see if we can elide RHS, if so, just return 1. // If we have 0 || X, just emit X without inserting the control flow. if (int Cond = CGF.ConstantFoldsToSimpleInteger(E->getLHS())) { if (Cond == -1) { // If we have 0 || X, just emit X. Value *RHSCond = CGF.EvaluateExprAsBool(E->getRHS()); - // ZExt result to int. - return Builder.CreateZExt(RHSCond, CGF.LLVMIntTy, "lor.ext"); + // ZExt result to int or bool. + return Builder.CreateZExtOrBitCast(RHSCond, ResTy, "lor.ext"); } - // 1 || RHS: If it is safe, just elide the RHS, and return 1. + // 1 || RHS: If it is safe, just elide the RHS, and return 1/true. if (!CGF.ContainsLabel(E->getRHS())) - return llvm::ConstantInt::get(CGF.LLVMIntTy, 1); + return llvm::ConstantInt::get(ResTy, 1); } llvm::BasicBlock *ContBlock = CGF.createBasicBlock("lor.end"); @@ -1474,7 +1478,7 @@ Value *ScalarExprEmitter::VisitBinLOr(const BinaryOperator *E) { PN->addIncoming(RHSCond, RHSBlock); // ZExt result to int. - return Builder.CreateZExt(PN, CGF.LLVMIntTy, "lor.ext"); + return Builder.CreateZExtOrBitCast(PN, ResTy, "lor.ext"); } Value *ScalarExprEmitter::VisitBinComma(const BinaryOperator *E) { |

