Skip to content

Commit c416b2e

Browse files
author
Tacet
authored
[ASan][JSON] Unpoison memory before its reuse (#79065)
This commit unpoisons memory before its reuse (with reinterpret_cast). Required by #79049 Notice that it's a temporary solution to prevent buildbots from failing. Read FIXME for details.
1 parent 80fcc92 commit c416b2e

File tree

1 file changed

+14
-1
lines changed
  • llvm/include/llvm/Support

1 file changed

+14
-1
lines changed

llvm/include/llvm/Support/JSON.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@
4747
#define LLVM_SUPPORT_JSON_H
4848

4949
#include "llvm/ADT/DenseMap.h"
50+
#include "llvm/ADT/STLFunctionalExtras.h"
5051
#include "llvm/ADT/SmallVector.h"
5152
#include "llvm/ADT/StringRef.h"
52-
#include "llvm/ADT/STLFunctionalExtras.h"
53+
#include "llvm/Support/Compiler.h"
5354
#include "llvm/Support/Error.h"
5455
#include "llvm/Support/FormatVariadic.h"
5556
#include "llvm/Support/raw_ostream.h"
@@ -482,6 +483,18 @@ class Value {
482483
friend class Object;
483484

484485
template <typename T, typename... U> void create(U &&... V) {
486+
#if LLVM_ADDRESS_SANITIZER_BUILD
487+
// Unpoisoning to prevent overwriting poisoned object (e.g., annotated short
488+
// string). Objects that have had their memory poisoned may cause an ASan
489+
// error if their memory is reused without calling their destructor.
490+
// Unpoisoning the memory prevents this error from occurring.
491+
// FIXME: This is a temporary solution to prevent buildbots from failing.
492+
// The more appropriate approach would be to call the object's destructor
493+
// to unpoison memory. This would prevent any potential memory leaks (long
494+
// strings). Read for details:
495+
// https://github.com/llvm/llvm-project/pull/79065#discussion_r1462621761
496+
__asan_unpoison_memory_region(&Union, sizeof(T));
497+
#endif
485498
new (reinterpret_cast<T *>(&Union)) T(std::forward<U>(V)...);
486499
}
487500
template <typename T> T &as() const {

0 commit comments

Comments
 (0)