[libc++][Android] Allow testing libc++ with clang-r536225 (#116149)
[llvm-project.git] / libc / src / stdlib / gpu / realloc.cpp
blob4fd4d6b278179e67a57dc1c1198d19b4b6f4dde0
1 //===-- GPU Implementation of realloc -------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "src/stdlib/realloc.h"
11 #include "src/__support/GPU/allocator.h"
12 #include "src/__support/common.h"
13 #include "src/__support/macros/config.h"
14 #include "src/string/memory_utils/inline_memcpy.h"
16 namespace LIBC_NAMESPACE_DECL {
18 LLVM_LIBC_FUNCTION(void *, realloc, (void *ptr, size_t size)) {
19 if (ptr == nullptr)
20 return gpu::allocate(size);
22 void *newmem = gpu::allocate(size);
23 if (newmem == nullptr)
24 return nullptr;
26 // This will copy garbage if it goes beyond the old allocation size.
27 inline_memcpy(newmem, ptr, size);
28 gpu::deallocate(ptr);
29 return newmem;
32 } // namespace LIBC_NAMESPACE_DECL