Skip to content

Commit 9d72444

Browse files
committed
[MemoryBuiltins] Remove CallocLike (NFC)
All functions of this kind already use allocator attributes. This also highlights that isMallocOrCallocLikeFn() doesn't really do what the name says (notably, it does not check for allocator attributes). The places it is used in are also very dubious, so we'll want to remove it.
1 parent 90b02f6 commit 9d72444

File tree

1 file changed

+5
-22
lines changed

1 file changed

+5
-22
lines changed

llvm/lib/Analysis/MemoryBuiltins.cpp

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,9 @@ using namespace llvm;
5454
enum AllocType : uint8_t {
5555
OpNewLike = 1<<0, // allocates; never returns null
5656
MallocLike = 1<<1, // allocates; may return null
57-
CallocLike = 1<<2, // allocates + bzero
58-
StrDupLike = 1<<3,
57+
StrDupLike = 1<<2,
5958
MallocOrOpNewLike = MallocLike | OpNewLike,
60-
MallocOrCallocLike = MallocLike | OpNewLike | CallocLike,
61-
AllocLike = MallocOrCallocLike | StrDupLike,
59+
AllocLike = MallocOrOpNewLike | StrDupLike,
6260
AnyAlloc = AllocLike
6361
};
6462

@@ -303,22 +301,11 @@ bool llvm::isNewLikeFn(const Value *V, const TargetLibraryInfo *TLI) {
303301
return getAllocationData(V, OpNewLike, TLI).has_value();
304302
}
305303

306-
/// Tests if a value is a call or invoke to a library function that
307-
/// allocates uninitialized memory (such as malloc).
308-
static bool isMallocLikeFn(const Value *V, const TargetLibraryInfo *TLI) {
309-
return getAllocationData(V, MallocOrOpNewLike, TLI).has_value();
310-
}
311-
312-
/// Tests if a value is a call or invoke to a library function that
313-
/// allocates zero-filled memory (such as calloc).
314-
static bool isCallocLikeFn(const Value *V, const TargetLibraryInfo *TLI) {
315-
return getAllocationData(V, CallocLike, TLI).has_value();
316-
}
317-
318304
/// Tests if a value is a call or invoke to a library function that
319305
/// allocates memory similar to malloc or calloc.
320306
bool llvm::isMallocOrCallocLikeFn(const Value *V, const TargetLibraryInfo *TLI) {
321-
return getAllocationData(V, MallocOrCallocLike, TLI).has_value();
307+
// TODO: Function behavior does not match name.
308+
return getAllocationData(V, MallocOrOpNewLike, TLI).has_value();
322309
}
323310

324311
/// Tests if a value is a call or invoke to a library function that
@@ -447,13 +434,9 @@ Constant *llvm::getInitialValueOfAllocation(const Value *V,
447434
return nullptr;
448435

449436
// malloc are uninitialized (undef)
450-
if (isMallocLikeFn(Alloc, TLI))
437+
if (getAllocationData(Alloc, MallocOrOpNewLike, TLI).has_value())
451438
return UndefValue::get(Ty);
452439

453-
// calloc zero initializes
454-
if (isCallocLikeFn(Alloc, TLI))
455-
return Constant::getNullValue(Ty);
456-
457440
AllocFnKind AK = getAllocFnKind(Alloc);
458441
if ((AK & AllocFnKind::Uninitialized) != AllocFnKind::Unknown)
459442
return UndefValue::get(Ty);

0 commit comments

Comments
 (0)