diff --git a/llvm/include/llvm/Analysis/MemoryBuiltins.h b/llvm/include/llvm/Analysis/MemoryBuiltins.h index b0ff7f969484a..457a9d330ae24 100644 --- a/llvm/include/llvm/Analysis/MemoryBuiltins.h +++ b/llvm/include/llvm/Analysis/MemoryBuiltins.h @@ -108,13 +108,16 @@ bool isRemovableAlloc(const CallBase *V, const TargetLibraryInfo *TLI); /// the definition of the allocalign attribute. Value *getAllocAlignment(const CallBase *V, const TargetLibraryInfo *TLI); -/// Return the size of the requested allocation. With a trivial mapper, this is -/// identical to calling getObjectSize(..., Exact). A mapper function can be -/// used to replace one Value* (operand to the allocation) with another. This -/// is useful when doing abstract interpretation. -Optional getAllocSize(const CallBase *CB, - const TargetLibraryInfo *TLI, - std::function Mapper); +/// Return the size of the requested allocation. With a trivial mapper, this is +/// similar to calling getObjectSize(..., Exact), but without looking through +/// calls that return their argument. A mapper function can be used to replace +/// one Value* (operand to the allocation) with another. This is useful when +/// doing abstract interpretation. +Optional getAllocSize( + const CallBase *CB, const TargetLibraryInfo *TLI, + function_ref Mapper = [](const Value *V) { + return V; + }); /// If this is a call to an allocation function that initializes memory to a /// fixed value, return said value in the requested type. Otherwise, return diff --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp index 50256a2629d4c..bf81d3b4dbe1f 100644 --- a/llvm/lib/Analysis/MemoryBuiltins.cpp +++ b/llvm/lib/Analysis/MemoryBuiltins.cpp @@ -361,9 +361,8 @@ static bool CheckedZextOrTrunc(APInt &I, unsigned IntTyBits) { } Optional -llvm::getAllocSize(const CallBase *CB, - const TargetLibraryInfo *TLI, - std::function Mapper) { +llvm::getAllocSize(const CallBase *CB, const TargetLibraryInfo *TLI, + function_ref Mapper) { // Note: This handles both explicitly listed allocation functions and // allocsize. The code structure could stand to be cleaned up a bit. Optional FnData = getAllocationSize(CB, TLI); @@ -769,8 +768,7 @@ SizeOffsetType ObjectSizeOffsetVisitor::visitArgument(Argument &A) { } SizeOffsetType ObjectSizeOffsetVisitor::visitCallBase(CallBase &CB) { - auto Mapper = [](const Value *V) { return V; }; - if (Optional Size = getAllocSize(&CB, TLI, Mapper)) + if (Optional Size = getAllocSize(&CB, TLI)) return std::make_pair(*Size, Zero); return unknown(); }