1 //===-- runtime/memory.cpp ------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "flang/Runtime/memory.h"
10 #include "terminator.h"
12 #include "flang/Runtime/freestanding-tools.h"
15 namespace Fortran::runtime
{
16 RT_OFFLOAD_API_GROUP_BEGIN
18 void *AllocateMemoryOrCrash(const Terminator
&terminator
, std::size_t bytes
) {
19 if (void *p
{std::malloc(bytes
)}) {
24 "Fortran runtime internal error: out of memory, needed %zd bytes",
30 void *ReallocateMemoryOrCrash(
31 const Terminator
&terminator
, void *ptr
, std::size_t newByteSize
) {
32 if (void *p
{Fortran::runtime::realloc(ptr
, newByteSize
)}) {
35 if (newByteSize
> 0) {
36 terminator
.Crash("Fortran runtime internal error: memory realloc returned "
37 "null, needed %zd bytes",
43 void FreeMemory(void *p
) { std::free(p
); }
45 RT_OFFLOAD_API_GROUP_END
46 } // namespace Fortran::runtime