[InstCombine] Fix use after free
Load the nowrap flags before calling EmitGEPOffset(), as this may free the instruction.
This commit is contained in:
@@ -711,9 +711,11 @@ Instruction *InstCombinerImpl::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS,
|
||||
Value *PtrBase = GEPLHS->getOperand(0);
|
||||
if (PtrBase == RHS && CanFold(GEPLHS->getNoWrapFlags())) {
|
||||
// ((gep Ptr, OFFSET) cmp Ptr) ---> (OFFSET cmp 0).
|
||||
GEPNoWrapFlags NW = GEPLHS->getNoWrapFlags();
|
||||
// Do not access GEPLHS after EmitGEPOffset, as the instruction may be
|
||||
// destroyed.
|
||||
Value *Offset = EmitGEPOffset(GEPLHS, /*RewriteGEP=*/true);
|
||||
return NewICmp(GEPLHS->getNoWrapFlags(), Offset,
|
||||
Constant::getNullValue(Offset->getType()));
|
||||
return NewICmp(NW, Offset, Constant::getNullValue(Offset->getType()));
|
||||
}
|
||||
|
||||
if (GEPLHS->isInBounds() && ICmpInst::isEquality(Cond) &&
|
||||
|
||||
Reference in New Issue
Block a user