[llvm] 9d72444 - [MemoryBuiltins] Remove CallocLike (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 9 03:46:34 PST 2022


Author: Nikita Popov
Date: 2022-12-09T12:46:26+01:00
New Revision: 9d7244409dbbb5bbb505dcd258b250b8f95b736d

URL: https://github.com/llvm/llvm-project/commit/9d7244409dbbb5bbb505dcd258b250b8f95b736d
DIFF: https://github.com/llvm/llvm-project/commit/9d7244409dbbb5bbb505dcd258b250b8f95b736d.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/lib/Analysis/MemoryBuiltins.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp
index 3920095a6be4..cde29bb9eef8 100644
--- a/llvm/lib/Analysis/MemoryBuiltins.cpp
+++ b/llvm/lib/Analysis/MemoryBuiltins.cpp
@@ -54,11 +54,9 @@ using namespace llvm;
 enum AllocType : uint8_t {
   OpNewLike          = 1<<0, // allocates; never returns null
   MallocLike         = 1<<1, // allocates; may return null
-  CallocLike         = 1<<2, // allocates + bzero
-  StrDupLike         = 1<<3,
+  StrDupLike         = 1<<2,
   MallocOrOpNewLike  = MallocLike | OpNewLike,
-  MallocOrCallocLike = MallocLike | OpNewLike | CallocLike,
-  AllocLike          = MallocOrCallocLike | StrDupLike,
+  AllocLike          = MallocOrOpNewLike | StrDupLike,
   AnyAlloc           = AllocLike
 };
 
@@ -303,22 +301,11 @@ bool llvm::isNewLikeFn(const Value *V, const TargetLibraryInfo *TLI) {
   return getAllocationData(V, OpNewLike, TLI).has_value();
 }
 
-/// Tests if a value is a call or invoke to a library function that
-/// allocates uninitialized memory (such as malloc).
-static bool isMallocLikeFn(const Value *V, const TargetLibraryInfo *TLI) {
-  return getAllocationData(V, MallocOrOpNewLike, TLI).has_value();
-}
-
-/// Tests if a value is a call or invoke to a library function that
-/// allocates zero-filled memory (such as calloc).
-static bool isCallocLikeFn(const Value *V, const TargetLibraryInfo *TLI) {
-  return getAllocationData(V, CallocLike, TLI).has_value();
-}
-
 /// Tests if a value is a call or invoke to a library function that
 /// allocates memory similar to malloc or calloc.
 bool llvm::isMallocOrCallocLikeFn(const Value *V, const TargetLibraryInfo *TLI) {
-  return getAllocationData(V, MallocOrCallocLike, TLI).has_value();
+  // TODO: Function behavior does not match name.
+  return getAllocationData(V, MallocOrOpNewLike, TLI).has_value();
 }
 
 /// Tests if a value is a call or invoke to a library function that
@@ -447,13 +434,9 @@ Constant *llvm::getInitialValueOfAllocation(const Value *V,
     return nullptr;
 
   // malloc are uninitialized (undef)
-  if (isMallocLikeFn(Alloc, TLI))
+  if (getAllocationData(Alloc, MallocOrOpNewLike, TLI).has_value())
     return UndefValue::get(Ty);
 
-  // calloc zero initializes
-  if (isCallocLikeFn(Alloc, TLI))
-    return Constant::getNullValue(Ty);
-
   AllocFnKind AK = getAllocFnKind(Alloc);
   if ((AK & AllocFnKind::Uninitialized) != AllocFnKind::Unknown)
     return UndefValue::get(Ty);


        


More information about the llvm-commits mailing list