diff --git a/llvm/include/llvm/Support/JSON.h b/llvm/include/llvm/Support/JSON.h index a81881c52d6c96..95394866f7e9ef 100644 --- a/llvm/include/llvm/Support/JSON.h +++ b/llvm/include/llvm/Support/JSON.h @@ -482,6 +482,12 @@ class Value { friend class Object; template 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(&Union)) T(std::forward(V)...); } template T &as() const {