Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions libcxx/include/variant
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ namespace std {
#include <new>
#include <version>

#if __has_feature(memory_sanitizer)
# include <sanitizer/msan_interface.h>
#endif

// standard-mandated includes

// [variant.syn]
Expand Down Expand Up @@ -781,6 +785,10 @@ _LIBCPP_VARIANT_DESTRUCTOR(
_Trait::_TriviallyAvailable,
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~__dtor() = default,
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __destroy() noexcept {
# if __has_feature(memory_sanitizer)
if (!std::is_constant_evaluated())
__sanitizer_dtor_callback(&this->__data, sizeof(this->__data));
# endif
this->__index = __variant_npos<__index_t>;
} _LIBCPP_EAT_SEMICOLON);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: c++03, c++11, c++14

// <variant>

// template <class ...Types> class variant;

#include <variant>

#if __has_feature(memory_sanitizer)
# include <sanitizer/msan_interface.h>
#endif

int main(int, char**) {
#if __has_feature(memory_sanitizer)
std::variant<double, int> v;
v.emplace<double>();
double& d = std::get<double>(v);
v.emplace<int>();
if (__msan_test_shadow(&d, sizeof(d)) == -1) {
// Unexpected: The entire range is accessible.
return 1;
}
#endif

return 0;
}