Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 4daef48

Browse files
alexcrichtonpftbest
authored andcommitted
Add some Rust allocation functions to TargetLibraryInfo + MemoryBuiltins
Original patch by Nathaniel Theis
1 parent 4607999 commit 4daef48

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

include/llvm/Analysis/TargetLibraryInfo.def

+6
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@ TLI_DEFINE_STRING_INTERNAL("__memset_chk")
200200
TLI_DEFINE_ENUM_INTERNAL(nvvm_reflect)
201201
TLI_DEFINE_STRING_INTERNAL("__nvvm_reflect")
202202

203+
/// void *__rust_allocate(size_t size, size_t align)
204+
TLI_DEFINE_ENUM_INTERNAL(rust_allocate)
205+
TLI_DEFINE_STRING_INTERNAL("__rust_allocate")
206+
/// void __rust_deallocate(void *ptr, size_t size, size_t align)
207+
TLI_DEFINE_ENUM_INTERNAL(rust_deallocate)
208+
TLI_DEFINE_STRING_INTERNAL("__rust_deallocate")
203209
/// double __sincospi_stret(double x);
204210
TLI_DEFINE_ENUM_INTERNAL(sincospi_stret)
205211
TLI_DEFINE_STRING_INTERNAL("__sincospi_stret")

lib/Analysis/MemoryBuiltins.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ static const std::pair<LibFunc::Func, AllocFnsTy> AllocationFnData[] = {
7373
{LibFunc::realloc, {ReallocLike, 2, 1, -1}},
7474
{LibFunc::reallocf, {ReallocLike, 2, 1, -1}},
7575
{LibFunc::strdup, {StrDupLike, 1, -1, -1}},
76-
{LibFunc::strndup, {StrDupLike, 2, 1, -1}}
76+
{LibFunc::strndup, {StrDupLike, 2, 1, -1}},
77+
{LibFunc::rust_allocate, {MallocLike, 2, 0, -1}}
7778
// TODO: Handle "int posix_memalign(void **, size_t, size_t)"
7879
};
7980

@@ -344,6 +345,8 @@ const CallInst *llvm::isFreeCall(const Value *I, const TargetLibraryInfo *TLI) {
344345
TLIFn == LibFunc::msvc_delete_array_ptr32_nothrow || // delete[](void*, nothrow)
345346
TLIFn == LibFunc::msvc_delete_array_ptr64_nothrow) // delete[](void*, nothrow)
346347
ExpectedNumParams = 2;
348+
else if (TLIFn == LibFunc::rust_deallocate)
349+
ExpectedNumParams = 3;
347350
else
348351
return nullptr;
349352

0 commit comments

Comments
 (0)