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

Commit d1144af

Browse files
alexcrichtonarielb1
authored andcommitted
Merge pull request #80 from nagisa/builtins
Remind LLVM about alloc function names in Rust
2 parents c99a03e + bcadd92 commit d1144af

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

include/llvm/Analysis/TargetLibraryInfo.def

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

203+
/// uint8_t *__rust_allocate(size_t size, size_t align)
204+
TLI_DEFINE_ENUM_INTERNAL(rust_allocate)
205+
TLI_DEFINE_STRING_INTERNAL("__rust_allocate")
206+
207+
/// uint8_t *__rust_allocate_zeroed(size_t size, size_t align)
208+
TLI_DEFINE_ENUM_INTERNAL(rust_allocate_zeroed)
209+
TLI_DEFINE_STRING_INTERNAL("__rust_allocate_zeroed")
210+
211+
/// void __rust_deallocate(uint8_t *ptr, size_t size, size_t align)
212+
TLI_DEFINE_ENUM_INTERNAL(rust_deallocate)
213+
TLI_DEFINE_STRING_INTERNAL("__rust_deallocate")
214+
215+
/// uint8_t *__rust_reallocate(uint8_t *ptr, size_t oldsz, size_t newsz, size_t align)
216+
TLI_DEFINE_ENUM_INTERNAL(rust_reallocate)
217+
TLI_DEFINE_STRING_INTERNAL("__rust_reallocate")
218+
219+
/// uint8_t *__rust_reallocate_inplace(uint8_t *ptr, size_t oldsz, size_t newsz, size_t align)
220+
TLI_DEFINE_ENUM_INTERNAL(rust_reallocate_inplace)
221+
TLI_DEFINE_STRING_INTERNAL("__rust_reallocate_inplace")
222+
203223
/// double __sincospi_stret(double x);
204224
TLI_DEFINE_ENUM_INTERNAL(sincospi_stret)
205225
TLI_DEFINE_STRING_INTERNAL("__sincospi_stret")

lib/Analysis/MemoryBuiltins.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,12 @@ 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+
78+
{LibFunc::rust_allocate, {MallocLike, 2, 0, -1}},
79+
{LibFunc::rust_allocate_zeroed, {MallocLike, 2, 0, -1}},
80+
{LibFunc::rust_reallocate, {ReallocLike, 4, 2, -1}},
81+
{LibFunc::rust_reallocate_inplace, {ReallocLike, 4, 2, -1}}
7782
// TODO: Handle "int posix_memalign(void **, size_t, size_t)"
7883
};
7984

@@ -361,6 +366,8 @@ const CallInst *llvm::isFreeCall(const Value *I, const TargetLibraryInfo *TLI) {
361366
TLIFn == LibFunc::msvc_delete_array_ptr32_nothrow || // delete[](void*, nothrow)
362367
TLIFn == LibFunc::msvc_delete_array_ptr64_nothrow) // delete[](void*, nothrow)
363368
ExpectedNumParams = 2;
369+
else if (TLIFn == LibFunc::rust_deallocate)
370+
ExpectedNumParams = 3;
364371
else
365372
return nullptr;
366373

0 commit comments

Comments
 (0)