Skip to content

Commit d3a2144

Browse files
author
Advenam Tacet
committed
[JSON] Unpoison memory before its reuse
This commit unpoisons memory before its reuse (with reinterpret_cast). Required by #79049
1 parent 8675952 commit d3a2144

File tree

1 file changed

+6
-0
lines changed
  • llvm/include/llvm/Support

1 file changed

+6
-0
lines changed

llvm/include/llvm/Support/JSON.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,12 @@ class Value {
482482
friend class Object;
483483

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

0 commit comments

Comments
 (0)