@@ -240,21 +240,18 @@ getAllocationData(const Value *V, AllocType AllocTy,
240
240
}
241
241
242
242
static std::optional<AllocFnsTy>
243
- getAllocationSize (const Value *V , const TargetLibraryInfo *TLI) {
243
+ getAllocationSize (const CallBase *CB , const TargetLibraryInfo *TLI) {
244
244
bool IsNoBuiltinCall;
245
- const Function *Callee =
246
- getCalledFunction (V, IsNoBuiltinCall);
247
- if (!Callee)
248
- return std::nullopt;
249
-
250
- // Prefer to use existing information over allocsize. This will give us an
251
- // accurate AllocTy.
252
- if (!IsNoBuiltinCall)
245
+ const Function *Callee = getCalledFunction (CB, IsNoBuiltinCall);
246
+ if (Callee && !IsNoBuiltinCall) {
247
+ // Prefer to use existing information over allocsize. This will give us an
248
+ // accurate AllocTy.
253
249
if (std::optional<AllocFnsTy> Data =
254
250
getAllocationDataForFunction (Callee, AnyAlloc, TLI))
255
251
return Data;
252
+ }
256
253
257
- Attribute Attr = Callee-> getFnAttribute (Attribute::AllocSize);
254
+ Attribute Attr = CB-> getFnAttr (Attribute::AllocSize);
258
255
if (Attr == Attribute ())
259
256
return std::nullopt;
260
257
@@ -264,7 +261,7 @@ getAllocationSize(const Value *V, const TargetLibraryInfo *TLI) {
264
261
// Because allocsize only tells us how many bytes are allocated, we're not
265
262
// really allowed to assume anything, so we use MallocLike.
266
263
Result.AllocTy = MallocLike;
267
- Result.NumParams = Callee-> getNumOperands ();
264
+ Result.NumParams = CB-> arg_size ();
268
265
Result.FstParam = Args.first ;
269
266
Result.SndParam = Args.second .value_or (-1 );
270
267
// Allocsize has no way to specify an alignment argument
@@ -512,19 +509,20 @@ std::optional<StringRef>
512
509
llvm::getAllocationFamily (const Value *I, const TargetLibraryInfo *TLI) {
513
510
bool IsNoBuiltin;
514
511
const Function *Callee = getCalledFunction (I, IsNoBuiltin);
515
- if (Callee == nullptr || IsNoBuiltin)
516
- return std::nullopt ;
517
- LibFunc TLIFn;
518
-
519
- if (TLI && TLI-> getLibFunc (*Callee, TLIFn) && TLI-> has (TLIFn)) {
520
- // Callee is some known library function.
521
- const auto AllocData = getAllocationDataForFunction (Callee, AnyAlloc, TLI);
522
- if (AllocData)
523
- return mangledNameForMallocFamily (AllocData-> Family );
524
- const auto FreeData = getFreeFunctionDataForFunction (Callee, TLIFn);
525
- if (FreeData)
526
- return mangledNameForMallocFamily (FreeData-> Family );
512
+ if (Callee && ! IsNoBuiltin) {
513
+ LibFunc TLIFn ;
514
+ if (TLI && TLI-> getLibFunc (*Callee, TLIFn) && TLI-> has (TLIFn)) {
515
+ // Callee is some known library function.
516
+ const auto AllocData =
517
+ getAllocationDataForFunction (Callee, AnyAlloc, TLI);
518
+ if (AllocData)
519
+ return mangledNameForMallocFamily (AllocData-> Family );
520
+ const auto FreeData = getFreeFunctionDataForFunction (Callee, TLIFn );
521
+ if (FreeData)
522
+ return mangledNameForMallocFamily (FreeData-> Family );
523
+ }
527
524
}
525
+
528
526
// Callee isn't a known library function, still check attributes.
529
527
if (checkFnAllocKind (I, AllocFnKind::Free | AllocFnKind::Alloc |
530
528
AllocFnKind::Realloc)) {
@@ -558,14 +556,13 @@ bool llvm::isLibFreeFunction(const Function *F, const LibFunc TLIFn) {
558
556
Value *llvm::getFreedOperand (const CallBase *CB, const TargetLibraryInfo *TLI) {
559
557
bool IsNoBuiltinCall;
560
558
const Function *Callee = getCalledFunction (CB, IsNoBuiltinCall);
561
- if (Callee == nullptr || IsNoBuiltinCall)
562
- return nullptr ;
563
-
564
- LibFunc TLIFn;
565
- if (TLI && TLI->getLibFunc (*Callee, TLIFn) && TLI->has (TLIFn) &&
566
- isLibFreeFunction (Callee, TLIFn)) {
567
- // All currently supported free functions free the first argument.
568
- return CB->getArgOperand (0 );
559
+ if (Callee && !IsNoBuiltinCall) {
560
+ LibFunc TLIFn;
561
+ if (TLI && TLI->getLibFunc (*Callee, TLIFn) && TLI->has (TLIFn) &&
562
+ isLibFreeFunction (Callee, TLIFn)) {
563
+ // All currently supported free functions free the first argument.
564
+ return CB->getArgOperand (0 );
565
+ }
569
566
}
570
567
571
568
if (checkFnAllocKind (CB, AllocFnKind::Free))
0 commit comments