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

Commit

Permalink
Merge pull request #80 from nagisa/builtins
Browse files Browse the repository at this point in the history
Remind LLVM about alloc function names in Rust
  • Loading branch information
TimNN committed Jul 20, 2017
2 parents e520dbc + 468e5b0 commit cdb751d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
21 changes: 21 additions & 0 deletions include/llvm/Analysis/TargetLibraryInfo.def
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,27 @@ TLI_DEFINE_STRING_INTERNAL("__powf_finite")
/// long double __powl_finite(long double x, long double y);
TLI_DEFINE_ENUM_INTERNAL(powl_finite)
TLI_DEFINE_STRING_INTERNAL("__powl_finite")

/// 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")

/// void __rust_deallocate(uint8_t *ptr, size_t size, size_t align)
TLI_DEFINE_ENUM_INTERNAL(rust_deallocate)
TLI_DEFINE_STRING_INTERNAL("__rust_deallocate")

/// 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")

/// uint8_t *__rust_reallocate_inplace(uint8_t *ptr, size_t oldsz, size_t newsz, size_t align)
TLI_DEFINE_ENUM_INTERNAL(rust_reallocate_inplace)
TLI_DEFINE_STRING_INTERNAL("__rust_reallocate_inplace")

/// double __sincospi_stret(double x);
TLI_DEFINE_ENUM_INTERNAL(sincospi_stret)
TLI_DEFINE_STRING_INTERNAL("__sincospi_stret")
Expand Down
9 changes: 8 additions & 1 deletion lib/Analysis/MemoryBuiltins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ static const std::pair<LibFunc, AllocFnsTy> AllocationFnData[] = {
{LibFunc_realloc, {ReallocLike, 2, 1, -1}},
{LibFunc_reallocf, {ReallocLike, 2, 1, -1}},
{LibFunc_strdup, {StrDupLike, 1, -1, -1}},
{LibFunc_strndup, {StrDupLike, 2, 1, -1}}
{LibFunc_strndup, {StrDupLike, 2, 1, -1}},

{LibFunc_rust_allocate, {MallocLike, 2, 0, -1}},
{LibFunc_rust_allocate_zeroed, {MallocLike, 2, 0, -1}},
{LibFunc_rust_reallocate, {ReallocLike, 4, 2, -1}},
{LibFunc_rust_reallocate_inplace, {ReallocLike, 4, 2, -1}}
// TODO: Handle "int posix_memalign(void **, size_t, size_t)"
};

Expand Down Expand Up @@ -370,6 +375,8 @@ const CallInst *llvm::isFreeCall(const Value *I, const TargetLibraryInfo *TLI) {
TLIFn == LibFunc_msvc_delete_array_ptr32_nothrow || // delete[](void*, nothrow)
TLIFn == LibFunc_msvc_delete_array_ptr64_nothrow) // delete[](void*, nothrow)
ExpectedNumParams = 2;
else if (TLIFn == LibFunc_rust_deallocate)
ExpectedNumParams = 3;
else
return nullptr;

Expand Down

0 comments on commit cdb751d

Please sign in to comment.