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

Commit cca16c0

Browse files
committed
Add some Rust allocation functions to TargetLibraryInfo + MemoryBuiltins
Original patch by Nathaniel Theis
1 parent de62574 commit cca16c0

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

include/llvm/Analysis/TargetLibraryInfo.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@ TLI_DEFINE_STRING_INTERNAL("__memmove_chk")
195195
/// void *__memset_chk(void *s, char v, size_t n, size_t s1size);
196196
TLI_DEFINE_ENUM_INTERNAL(memset_chk)
197197
TLI_DEFINE_STRING_INTERNAL("__memset_chk")
198+
/// void *__rust_allocate(size_t size, size_t align)
199+
TLI_DEFINE_ENUM_INTERNAL(rust_allocate)
200+
TLI_DEFINE_STRING_INTERNAL("__rust_allocate")
201+
/// void __rust_deallocate(void *ptr, size_t size, size_t align)
202+
TLI_DEFINE_ENUM_INTERNAL(rust_deallocate)
203+
TLI_DEFINE_STRING_INTERNAL("__rust_deallocate")
198204
/// double __sincospi_stret(double x);
199205
TLI_DEFINE_ENUM_INTERNAL(sincospi_stret)
200206
TLI_DEFINE_STRING_INTERNAL("__sincospi_stret")

lib/Analysis/MemoryBuiltins.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ static const AllocFnsTy AllocationFnData[] = {
7474
{LibFunc::realloc, ReallocLike, 2, 1, -1},
7575
{LibFunc::reallocf, ReallocLike, 2, 1, -1},
7676
{LibFunc::strdup, StrDupLike, 1, -1, -1},
77-
{LibFunc::strndup, StrDupLike, 2, 1, -1}
77+
{LibFunc::strndup, StrDupLike, 2, 1, -1},
78+
{LibFunc::rust_allocate, MallocLike, 2, 0, -1}
7879
// TODO: Handle "int posix_memalign(void **, size_t, size_t)"
7980
};
8081

@@ -323,6 +324,8 @@ const CallInst *llvm::isFreeCall(const Value *I, const TargetLibraryInfo *TLI) {
323324
TLIFn == LibFunc::msvc_delete_array_ptr32_nothrow || // delete[](void*, nothrow)
324325
TLIFn == LibFunc::msvc_delete_array_ptr64_nothrow) // delete[](void*, nothrow)
325326
ExpectedNumParams = 2;
327+
else if (TLIFn == LibFunc::rust_deallocate)
328+
ExpectedNumParams = 3;
326329
else
327330
return nullptr;
328331

0 commit comments

Comments
 (0)