Skip to content

Commit

Permalink
Add knowledge of __rust_{alloc,realloc,dealloc}
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Jun 20, 2017
1 parent 8e1e6e6 commit fd2b33b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 8 additions & 3 deletions include/llvm/Analysis/TargetLibraryInfo.def
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,23 @@ TLI_DEFINE_STRING_INTERNAL("__memset_chk")
TLI_DEFINE_ENUM_INTERNAL(nvvm_reflect)
TLI_DEFINE_STRING_INTERNAL("__nvvm_reflect")

TLI_DEFINE_ENUM_INTERNAL(rust_alloc)
TLI_DEFINE_STRING_INTERNAL("__rust_alloc")

/// uint8_t *__rust_allocate(size_t size, size_t align)
TLI_DEFINE_ENUM_INTERNAL(rust_allocate)
TLI_DEFINE_STRING_INTERNAL("__rust_allocate")

/// uint8_t *__rust_allocate_zeroed(size_t size, size_t align)
TLI_DEFINE_ENUM_INTERNAL(rust_allocate_zeroed)
TLI_DEFINE_STRING_INTERNAL("__rust_allocate_zeroed")
TLI_DEFINE_ENUM_INTERNAL(rust_dealloc)
TLI_DEFINE_STRING_INTERNAL("__rust_dealloc")

/// void __rust_deallocate(uint8_t *ptr, size_t size, size_t align)
TLI_DEFINE_ENUM_INTERNAL(rust_deallocate)
TLI_DEFINE_STRING_INTERNAL("__rust_deallocate")

TLI_DEFINE_ENUM_INTERNAL(rust_realloc)
TLI_DEFINE_STRING_INTERNAL("__rust_realloc")

/// uint8_t *__rust_reallocate(uint8_t *ptr, size_t oldsz, size_t newsz, size_t align)
TLI_DEFINE_ENUM_INTERNAL(rust_reallocate)
TLI_DEFINE_STRING_INTERNAL("__rust_reallocate")
Expand Down
4 changes: 4 additions & 0 deletions lib/Analysis/MemoryBuiltins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ static const std::pair<LibFunc::Func, AllocFnsTy> AllocationFnData[] = {
{LibFunc::strdup, {StrDupLike, 1, -1, -1}},
{LibFunc::strndup, {StrDupLike, 2, 1, -1}},

{LibFunc::rust_alloc, {MallocLike, 3, 0, -1}},
{LibFunc::rust_allocate, {MallocLike, 2, 0, -1}},
{LibFunc::rust_realloc, {ReallocLike, 6, 3, -1}},
{LibFunc::rust_reallocate, {ReallocLike, 4, 2, -1}},
// TODO: Handle "int posix_memalign(void **, size_t, size_t)"
};
Expand Down Expand Up @@ -366,6 +368,8 @@ const CallInst *llvm::isFreeCall(const Value *I, const TargetLibraryInfo *TLI) {
ExpectedNumParams = 2;
else if (TLIFn == LibFunc::rust_deallocate)
ExpectedNumParams = 3;
else if (TLIFn == LibFunc::rust_dealloc)
ExpectedNumParams = 3;
else
return nullptr;

Expand Down

0 comments on commit fd2b33b

Please sign in to comment.