Skip to content

Commit

Permalink
[JSON] Unpoison memory before its reuse
Browse files Browse the repository at this point in the history
This commit unpoisons memory before its reuse (with reinterpret_cast).
Required by llvm#79049
  • Loading branch information
Advenam Tacet committed Jan 22, 2024
1 parent 8675952 commit d3a2144
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions llvm/include/llvm/Support/JSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,12 @@ class Value {
friend class Object;

template <typename T, typename... U> void create(U &&... V) {
#if defined(ADDRESS_SANITIZER) || defined(__SANITIZE_ADDRESS__)
// Unpoisoning to prevent overwriting poisoned object (e.g., annotated short string).
// Objects that have had their memory poisoned may cause an ASan error if their memory is reused
// without calling their destructor. Unpoisoning the memory prevents this error from occurring.
__asan_unpoison_memory_region(&Union, sizeof(T));
#endif
new (reinterpret_cast<T *>(&Union)) T(std::forward<U>(V)...);
}
template <typename T> T &as() const {
Expand Down

0 comments on commit d3a2144

Please sign in to comment.