xref: /llvm-project/flang/runtime/memory.cpp (revision f7be251804e63ba6b8634f40cb808e89d924a0b0)
1 //===-- runtime/memory.cpp --------------------------------------*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
8 
9 #include "memory.h"
10 #include "terminator.h"
11 #include <cstdlib>
12 
13 namespace Fortran::runtime {
14 
15 void *AllocateMemoryOrCrash(Terminator &terminator, std::size_t bytes) {
16   if (void *p{std::malloc(bytes)}) {
17     return p;
18   }
19   if (bytes > 0) {
20     terminator.Crash(
21         "Fortran runtime internal error: out of memory, needed %zd bytes",
22         bytes);
23   }
24   return nullptr;
25 }
26 
27 void FreeMemory(void *p) { std::free(p); }
28 }
29