diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2008-01-29 18:13:51 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2008-01-29 18:13:51 +0000 |
commit | 356916ec84826a793b0353e5db0e9a7589b9ec5c (patch) | |
tree | cad0e6b89645c9c855dabd15f53868d406690951 | |
parent | 68fd257ada1ed5a20728241962a21826ae36ef63 (diff) |
Fix a bug where CodeGen would attempt to erase an instruction that was
already used.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46519 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | CodeGen/CGExprScalar.cpp | 6 | ||||
-rw-r--r-- | test/CodeGen/boolassign.c | 6 |
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)) {} +} |