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

Remind LLVM about alloc function names in Rust #80

Merged
merged 1 commit into from
Jun 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions include/llvm/Analysis/TargetLibraryInfo.def
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,26 @@ TLI_DEFINE_STRING_INTERNAL("__memset_chk")
TLI_DEFINE_ENUM_INTERNAL(nvvm_reflect)
TLI_DEFINE_STRING_INTERNAL("__nvvm_reflect")

/// 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 @@ -73,7 +73,12 @@ static const std::pair<LibFunc::Func, 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}}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is rust_reallocate_inplace really ReallocLike? realloc invalidates the old pointer on success (even if the block does not move), and rust_reallocate_inplace explicitly does not do that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point. reallocate_inplace does not return a pointer. I’ll remove it just to be safe.

// TODO: Handle "int posix_memalign(void **, size_t, size_t)"
};

Expand Down Expand Up @@ -361,6 +366,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