[InstCombine] Annotate strdup with deref_or_null
llvm-svn: 372098
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index e96e45e..9043818 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -4208,6 +4208,12 @@
Call.addAttribute(AttributeList::ReturnIndex,
Attribute::getWithDereferenceableOrNullBytes(
Call.getContext(), Size.getZExtValue()));
+ } else if (isStrdupLikeFn(&Call, TLI) && Call.getNumArgOperands() == 1) {
+ // TODO: handle strndup
+ if (uint64_t Len = GetStringLength(Call.getOperand(0)))
+ Call.addAttribute(
+ AttributeList::ReturnIndex,
+ Attribute::getWithDereferenceableOrNullBytes(Call.getContext(), Len));
}
}