From: Eli Friedman Date: Tue, 29 Jan 2008 18:13:51 +0000 (+0000) Subject: Fix a bug where CodeGen would attempt to erase an instruction that was X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=356916ec84826a793b0353e5db0e9a7589b9ec5c;p=clang 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 --- 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(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)) {} +}