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

Commit cdb751d

Browse files
committed
Merge pull request #80 from nagisa/builtins
Remind LLVM about alloc function names in Rust
2 parents e520dbc + 468e5b0 commit cdb751d

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

include/llvm/Analysis/TargetLibraryInfo.def

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,27 @@ TLI_DEFINE_STRING_INTERNAL("__powf_finite")
316316
/// long double __powl_finite(long double x, long double y);
317317
TLI_DEFINE_ENUM_INTERNAL(powl_finite)
318318
TLI_DEFINE_STRING_INTERNAL("__powl_finite")
319+
320+
/// uint8_t *__rust_allocate(size_t size, size_t align)
321+
TLI_DEFINE_ENUM_INTERNAL(rust_allocate)
322+
TLI_DEFINE_STRING_INTERNAL("__rust_allocate")
323+
324+
/// uint8_t *__rust_allocate_zeroed(size_t size, size_t align)
325+
TLI_DEFINE_ENUM_INTERNAL(rust_allocate_zeroed)
326+
TLI_DEFINE_STRING_INTERNAL("__rust_allocate_zeroed")
327+
328+
/// void __rust_deallocate(uint8_t *ptr, size_t size, size_t align)
329+
TLI_DEFINE_ENUM_INTERNAL(rust_deallocate)
330+
TLI_DEFINE_STRING_INTERNAL("__rust_deallocate")
331+
332+
/// uint8_t *__rust_reallocate(uint8_t *ptr, size_t oldsz, size_t newsz, size_t align)
333+
TLI_DEFINE_ENUM_INTERNAL(rust_reallocate)
334+
TLI_DEFINE_STRING_INTERNAL("__rust_reallocate")
335+
336+
/// uint8_t *__rust_reallocate_inplace(uint8_t *ptr, size_t oldsz, size_t newsz, size_t align)
337+
TLI_DEFINE_ENUM_INTERNAL(rust_reallocate_inplace)
338+
TLI_DEFINE_STRING_INTERNAL("__rust_reallocate_inplace")
339+
319340
/// double __sincospi_stret(double x);
320341
TLI_DEFINE_ENUM_INTERNAL(sincospi_stret)
321342
TLI_DEFINE_STRING_INTERNAL("__sincospi_stret")

lib/Analysis/MemoryBuiltins.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,12 @@ static const std::pair<LibFunc, 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+
79+
{LibFunc_rust_allocate, {MallocLike, 2, 0, -1}},
80+
{LibFunc_rust_allocate_zeroed, {MallocLike, 2, 0, -1}},
81+
{LibFunc_rust_reallocate, {ReallocLike, 4, 2, -1}},
82+
{LibFunc_rust_reallocate_inplace, {ReallocLike, 4, 2, -1}}
7883
// TODO: Handle "int posix_memalign(void **, size_t, size_t)"
7984
};
8085

@@ -370,6 +375,8 @@ const CallInst *llvm::isFreeCall(const Value *I, const TargetLibraryInfo *TLI) {
370375
TLIFn == LibFunc_msvc_delete_array_ptr32_nothrow || // delete[](void*, nothrow)
371376
TLIFn == LibFunc_msvc_delete_array_ptr64_nothrow) // delete[](void*, nothrow)
372377
ExpectedNumParams = 2;
378+
else if (TLIFn == LibFunc_rust_deallocate)
379+
ExpectedNumParams = 3;
373380
else
374381
return nullptr;
375382

0 commit comments

Comments
 (0)