Skip to content

Commit

Permalink
Relocations
Browse files Browse the repository at this point in the history
  • Loading branch information
Advenam Tacet committed May 5, 2024
1 parent 0dab486 commit 35a0328
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions libcxx/include/string
Original file line number Diff line number Diff line change
Expand Up @@ -711,23 +711,7 @@ template <class _CharT, class _Traits, class _Allocator>
class basic_string {
private:
using __default_allocator_type = allocator<_CharT>;
#ifndef _LIBCPP_HAS_NO_ASAN
pointer __asan_volatile_wrapper(pointer __ptr) const {
volatile pointer __copy_ptr = __ptr;

return __copy_ptr;
}

const_pointer const __asan_volatile_wrapper(const_pointer __ptr) const {
volatile const_pointer __copy_ptr = __ptr;

return __copy_ptr;
}

#define _LIBCPP_ASAN_VOLATILE_WRAPPER(ptr) __asan_volatile_wrapper(ptr)
#else
#define _LIBCPP_ASAN_VOLATILE_WRAPPER(ptr) ptr
#endif
public:
typedef basic_string __self;
typedef basic_string_view<_CharT, _Traits> __self_view;
Expand All @@ -751,7 +735,7 @@ public:
//
// This string implementation doesn't contain any references into itself. It only contains a bit that says whether
// it is in small or large string mode, so the entire structure is trivially relocatable if its members are.
#ifndef _LIBCPP_HAS_NO_ASAN
#if !defined(_LIBCPP_HAS_NO_ASAN) && defined(_LIBCPP_INSTRUMENTED_WITH_ASAN)
// When compiling with AddressSanitizer (ASan), basic_string cannot be trivially
// relocatable. Because the object's memory might be poisoned when its content
// is kept inside objects memory (short string optimization), instead of in allocated
Expand All @@ -765,7 +749,23 @@ public:
basic_string,
void>;
#endif
#if !defined(_LIBCPP_HAS_NO_ASAN) && defined(_LIBCPP_INSTRUMENTED_WITH_ASAN)
pointer __asan_volatile_wrapper(pointer __ptr) const {
volatile pointer __copy_ptr = __ptr;

return __copy_ptr;
}

const_pointer const __asan_volatile_wrapper(const_pointer __ptr) const {
volatile const_pointer __copy_ptr = __ptr;

return __copy_ptr;
}

#define _LIBCPP_ASAN_VOLATILE_WRAPPER(ptr) __asan_volatile_wrapper(ptr)
#else
#define _LIBCPP_ASAN_VOLATILE_WRAPPER(ptr) ptr
#endif
static_assert((!is_array<value_type>::value), "Character type of basic_string must not be an array");
static_assert((is_standard_layout<value_type>::value), "Character type of basic_string must be standard-layout");
static_assert((is_trivial<value_type>::value), "Character type of basic_string must be trivial");
Expand Down

0 comments on commit 35a0328

Please sign in to comment.