[clang] Add test for CWG190 "Layout-compatible POD-struct types" (#121668)
[llvm-project.git] / llvm / lib / Support / Memory.cpp
blobf1ba2d0cfe3a93e11a44564f52d7410d015b0ff6
1 //===- Memory.cpp - Memory Handling Support ---------------------*- 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 // This file defines some helpful functions for allocating memory and dealing
10 // with memory mapped files
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Support/Memory.h"
15 #include "llvm/Config/llvm-config.h"
17 #ifndef NDEBUG
18 #include "llvm/Support/raw_ostream.h"
19 #endif // ifndef NDEBUG
21 // Include the platform-specific parts of this class.
22 #ifdef LLVM_ON_UNIX
23 #include "Unix/Memory.inc"
24 #endif
25 #ifdef _WIN32
26 #include "Windows/Memory.inc"
27 #endif
29 #ifndef NDEBUG
31 namespace llvm {
32 namespace sys {
34 raw_ostream &operator<<(raw_ostream &OS, const Memory::ProtectionFlags &PF) {
35 assert((PF & ~(Memory::MF_READ | Memory::MF_WRITE | Memory::MF_EXEC)) == 0 &&
36 "Unrecognized flags");
38 return OS << (PF & Memory::MF_READ ? 'R' : '-')
39 << (PF & Memory::MF_WRITE ? 'W' : '-')
40 << (PF & Memory::MF_EXEC ? 'X' : '-');
43 raw_ostream &operator<<(raw_ostream &OS, const MemoryBlock &MB) {
44 return OS << "[ " << MB.base() << " .. "
45 << (void *)((char *)MB.base() + MB.allocatedSize()) << " ] ("
46 << MB.allocatedSize() << " bytes)";
49 } // end namespace sys
50 } // end namespace llvm
52 #endif // ifndef NDEBUG