From: Sanjay Patel Date: Fri, 25 Jun 2021 15:36:28 +0000 (-0400) Subject: [Analysis] use better version of getLibFunc to check for alloc/free calls X-Git-Tag: llvmorg-14-init~2998 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1076b6c4f022a024a54af9e6a0e9997472cb89ef;p=platform%2Fupstream%2Fllvm.git [Analysis] use better version of getLibFunc to check for alloc/free calls There's no reason to use the weaker name-only analysis when we have a function prototype to check (in fact, we probably should not even have that name-only function exposed for general use, but removing it requires auditing all of the callers). The version of getLibFunc that takes a Function argument also does some prototype checking to make sure the arguments/return type match the expected signature of a real library call. This is NFC-intended because the code in MemoryBuiltins does its own function signature checking. For now, that means there may be some redundancy in the checking, but that should not be above the noise for compile-time. Ideally, we can move the checks to a single location. There's still a hole in the logic that allows the example in https://llvm.org/PR50846 to cause a compiler crash. --- diff --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp index cf7ee0f..e3d197c 100644 --- a/llvm/lib/Analysis/MemoryBuiltins.cpp +++ b/llvm/lib/Analysis/MemoryBuiltins.cpp @@ -142,9 +142,8 @@ static Optional getAllocationDataForFunction(const Function *Callee, AllocType AllocTy, const TargetLibraryInfo *TLI) { // Make sure that the function is available. - StringRef FnName = Callee->getName(); LibFunc TLIFn; - if (!TLI || !TLI->getLibFunc(FnName, TLIFn) || !TLI->has(TLIFn)) + if (!TLI || !TLI->getLibFunc(*Callee, TLIFn) || !TLI->has(TLIFn)) return None; const auto *Iter = find_if( @@ -492,9 +491,8 @@ const CallInst *llvm::isFreeCall(const Value *I, const TargetLibraryInfo *TLI) { if (Callee == nullptr || IsNoBuiltinCall) return nullptr; - StringRef FnName = Callee->getName(); LibFunc TLIFn; - if (!TLI || !TLI->getLibFunc(FnName, TLIFn) || !TLI->has(TLIFn)) + if (!TLI || !TLI->getLibFunc(*Callee, TLIFn) || !TLI->has(TLIFn)) return nullptr; return isLibFreeFunction(Callee, TLIFn) ? dyn_cast(I) : nullptr;