]> granicus.if.org Git - clang/commitdiff
Fix a bug where CodeGen would attempt to erase an instruction that was
authorEli Friedman <eli.friedman@gmail.com>
Tue, 29 Jan 2008 18:13:51 +0000 (18:13 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Tue, 29 Jan 2008 18:13:51 +0000 (18:13 +0000)
already used.

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

CodeGen/CGExprScalar.cpp
test/CodeGen/boolassign.c [new file with mode: 0644]

index e1771e80f855e9471674615499add2c527fb7258..8617a3e340169a50aaef327b2c1663f24f95063c 100644 (file)
@@ -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 (file)
index 0000000..7f76a92
--- /dev/null
@@ -0,0 +1,6 @@
+// RUN: clang %s -emit-llvm
+
+int testBoolAssign(void) {
+int ss;
+if ((ss = ss && ss)) {}
+}