1 // Test basic new functionality.
2 // RUN: %clangxx_hwasan -std=c++17 %s -o %t
9 #include <sanitizer/allocator_interface.h>
10 #include <sanitizer/hwasan_interface.h>
13 __hwasan_enable_allocator_tagging();
15 size_t volatile n
= 0;
16 char *a1
= new char[n
];
17 assert(a1
!= nullptr);
18 assert(__sanitizer_get_allocated_size(a1
) == 0);
21 #if defined(__cpp_aligned_new) && \
22 (!defined(__GLIBCXX__) || \
23 (defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE >= 7))
25 constexpr auto kAlign
= std::align_val_t
{8};
26 void *a2
= ::operator new(4, kAlign
);
27 assert(a2
!= nullptr);
28 assert(reinterpret_cast<uintptr_t>(a2
) % static_cast<uintptr_t>(kAlign
) == 0);
29 assert(__sanitizer_get_allocated_size(a2
) >= 4);
30 ::operator delete(a2
, kAlign
);