diff --git a/lib/Transforms/InstCombine/InstCombineCalls.cpp b/lib/Transforms/InstCombine/InstCombineCalls.cpp index c3be8c4e9a9..d304f98ceae 100644 --- a/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -4183,8 +4183,10 @@ static void annotateAnyAllocSite(CallBase &Call, const TargetLibraryInfo *TLI) { ConstantInt *Op1C = (Call.getNumArgOperands() == 1) ? nullptr : dyn_cast(Call.getOperand(1)); + // Bail out if the allocation size is zero. if ((Op0C && Op0C->isNullValue()) || (Op1C && Op1C->isNullValue())) return; + if (isMallocLikeFn(&Call, TLI) && Op0C) { Call.addAttribute(AttributeList::ReturnIndex, Attribute::getWithDereferenceableOrNullBytes(