clang 8.0.0

Classes | Public Member Functions | List of all members
clang::MemoryBufferCache Class Reference

Manage memory buffers across multiple users. More...

`#include "clang/Basic/MemoryBufferCache.h"`

Inheritance diagram for clang::MemoryBufferCache:
[legend]
Collaboration diagram for clang::MemoryBufferCache:
[legend]

## Public Member Functions
llvm::MemoryBuffer & | addBuffer (llvm::StringRef Filename, std::unique_ptr< llvm::MemoryBuffer > Buffer)
| Store the Buffer under the Filename. More...
bool | tryToRemoveBuffer (llvm::StringRef Filename)
| Try to remove a buffer from the cache. More...
llvm::MemoryBuffer * | lookupBuffer (llvm::StringRef Filename)
| Get a pointer to the buffer if it exists; else nullptr. More...
bool | isBufferFinal (llvm::StringRef Filename)
| Check whether the buffer is final. More...
void | finalizeCurrentBuffers ()
| Finalize the current buffers in the cache. More...

## Detailed Description

Manage memory buffers across multiple users.

Ensures that multiple users have a consistent view of each buffer. This is used by CompilerInstance when building PCMs to ensure that each ModuleManager sees the same files.

finalizeCurrentBuffers() should be called before creating a new user. This locks in the current buffers, ensuring that no buffer that has already been accessed can be purged, preventing use-after-frees.

Definition at line 32 of file MemoryBufferCache.h.

## Member Function Documentation

## ◆ addBuffer()

llvm::MemoryBuffer & MemoryBufferCache::addBuffer | ( | llvm::StringRef | Filename,
|  | std::unique_ptr< llvm::MemoryBuffer > | Buffer
| ) |  |

Store the Buffer under the Filename.

Precondition
  There is not already buffer is not already in the cache.

Returns
  a reference to the buffer as a convenience.

Definition at line 16 of file MemoryBufferCache.cpp.

References Filename.

Referenced by clang::ASTWriter::WriteAST().

## ◆ finalizeCurrentBuffers()

void MemoryBufferCache::finalizeCurrentBuffers | ( |  | ) |

Finalize the current buffers in the cache.

Should be called when creating a new user to ensure previous uses aren't invalidated.

Definition at line 48 of file MemoryBufferCache.cpp.

Referenced by clang::CompilerInstance::CompilerInstance().

## ◆ isBufferFinal()

bool MemoryBufferCache::isBufferFinal | ( | llvm::StringRef | Filename | ) |

Check whether the buffer is final.

Returns
  true iff finalizeCurrentBuffers() has been called since the buffer was added. This prevents buffers from being removed.

Definition at line 31 of file MemoryBufferCache.cpp.

## ◆ lookupBuffer()

llvm::MemoryBuffer * MemoryBufferCache::lookupBuffer | ( | llvm::StringRef | Filename | ) |

Get a pointer to the buffer if it exists; else nullptr.

Definition at line 24 of file MemoryBufferCache.cpp.

## ◆ tryToRemoveBuffer()

bool MemoryBufferCache::tryToRemoveBuffer | ( | llvm::StringRef | Filename | ) |

Try to remove a buffer from the cache.

Returns
  false on success, iff `!isBufferFinal`().

Definition at line 38 of file MemoryBufferCache.cpp.

The documentation for this class was generated from the following files:

- include/clang/Basic/MemoryBufferCache.h
- lib/Basic/MemoryBufferCache.cpp