aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CodeGen/CGExprScalar.cpp6
-rw-r--r--test/CodeGen/boolassign.c6
2 files changed, 11 insertions, 1 deletions
diff --git a/CodeGen/CGExprScalar.cpp b/CodeGen/CGExprScalar.cpp
index e1771e80f8..8617a3e340 100644
--- a/CodeGen/CGExprScalar.cpp
+++ b/CodeGen/CGExprScalar.cpp
@@ -320,7 +320,11 @@ Value *ScalarExprEmitter::EmitConversionToBool(Value *Src, QualType SrcType) {
if (llvm::ZExtInst *ZI = dyn_cast<llvm::ZExtInst>(Src)) {
if (ZI->getOperand(0)->getType() == llvm::Type::Int1Ty) {
Value *Result = ZI->getOperand(0);
- ZI->eraseFromParent();
+ // If there aren't any more uses, zap the instruction to save space.
+ // Note that there can be more uses, for example if this
+ // is the result of an assignment.
+ if (ZI->use_empty())
+ ZI->eraseFromParent();
return Result;
}
}
diff --git a/test/CodeGen/boolassign.c b/test/CodeGen/boolassign.c
new file mode 100644
index 0000000000..7f76a92459
--- /dev/null
+++ b/test/CodeGen/boolassign.c
@@ -0,0 +1,6 @@
+// RUN: clang %s -emit-llvm
+
+int testBoolAssign(void) {
+int ss;
+if ((ss = ss && ss)) {}
+}