From fd2b33b0d036814e4913ac630fb186fce1ca6df7 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sat, 17 Jun 2017 11:20:45 -0700 Subject: [PATCH] Add knowledge of __rust_{alloc,realloc,dealloc} --- include/llvm/Analysis/TargetLibraryInfo.def | 11 ++++++++--- lib/Analysis/MemoryBuiltins.cpp | 4 ++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/include/llvm/Analysis/TargetLibraryInfo.def b/include/llvm/Analysis/TargetLibraryInfo.def index 29e048d79f84..77c33dd6be88 100644 --- a/include/llvm/Analysis/TargetLibraryInfo.def +++ b/include/llvm/Analysis/TargetLibraryInfo.def @@ -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") diff --git a/lib/Analysis/MemoryBuiltins.cpp b/lib/Analysis/MemoryBuiltins.cpp index 1c991d2e4184..6a049f1814a3 100644 --- a/lib/Analysis/MemoryBuiltins.cpp +++ b/lib/Analysis/MemoryBuiltins.cpp @@ -75,7 +75,9 @@ static const std::pair 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)" }; @@ -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;