diff options
author | Jacques Lucke <jacques@blender.org> | 2021-09-21 18:50:53 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-09-21 18:51:15 +0300 |
commit | 3c1e75a2301c352dac72b1742cdd8efa2b335d6e (patch) | |
tree | 92110d3bcd3367a7ff0da2bb299fd4831d168f0a /source/blender/functions | |
parent | 2df7d1ebce862a7c7471f7a6ba3d7d14d392b3a5 (diff) |
Functions: make asserts more correct
It is valid to e.g. copy construct an integer in the same place,
because it is a trivial type. It does not work for types like std::string.
This fixes a crash reported in D12584 where it would copy a buffer
into itself. We should probably also avoid doing this copy alltogether
but that can be done separately.
Diffstat (limited to 'source/blender/functions')
-rw-r--r-- | source/blender/functions/FN_cpp_type.hh | 11 | ||||
-rw-r--r-- | source/blender/functions/FN_cpp_type_make.hh | 1 |
2 files changed, 6 insertions, 6 deletions
diff --git a/source/blender/functions/FN_cpp_type.hh b/source/blender/functions/FN_cpp_type.hh index 7277bf99c12..643b2fc1f28 100644 --- a/source/blender/functions/FN_cpp_type.hh +++ b/source/blender/functions/FN_cpp_type.hh @@ -96,6 +96,7 @@ class CPPType : NonCopyable, NonMovable { int64_t size_ = 0; int64_t alignment_ = 0; uintptr_t alignment_mask_ = 0; + bool is_trivial_ = false; bool is_trivially_destructible_ = false; bool has_special_member_functions_ = false; @@ -340,7 +341,6 @@ class CPPType : NonCopyable, NonMovable { */ void copy_assign(const void *src, void *dst) const { - BLI_assert(src != dst); BLI_assert(this->pointer_can_point_to_instance(src)); BLI_assert(this->pointer_can_point_to_instance(dst)); @@ -371,7 +371,7 @@ class CPPType : NonCopyable, NonMovable { */ void copy_construct(const void *src, void *dst) const { - BLI_assert(src != dst); + BLI_assert(src != dst || is_trivial_); BLI_assert(this->pointer_can_point_to_instance(src)); BLI_assert(this->pointer_can_point_to_instance(dst)); @@ -402,7 +402,6 @@ class CPPType : NonCopyable, NonMovable { */ void move_assign(void *src, void *dst) const { - BLI_assert(src != dst); BLI_assert(this->pointer_can_point_to_instance(src)); BLI_assert(this->pointer_can_point_to_instance(dst)); @@ -433,7 +432,7 @@ class CPPType : NonCopyable, NonMovable { */ void move_construct(void *src, void *dst) const { - BLI_assert(src != dst); + BLI_assert(src != dst || is_trivial_); BLI_assert(this->pointer_can_point_to_instance(src)); BLI_assert(this->pointer_can_point_to_instance(dst)); @@ -464,7 +463,7 @@ class CPPType : NonCopyable, NonMovable { */ void relocate_assign(void *src, void *dst) const { - BLI_assert(src != dst); + BLI_assert(src != dst || is_trivial_); BLI_assert(this->pointer_can_point_to_instance(src)); BLI_assert(this->pointer_can_point_to_instance(dst)); @@ -495,7 +494,7 @@ class CPPType : NonCopyable, NonMovable { */ void relocate_construct(void *src, void *dst) const { - BLI_assert(src != dst); + BLI_assert(src != dst || is_trivial_); BLI_assert(this->pointer_can_point_to_instance(src)); BLI_assert(this->pointer_can_point_to_instance(dst)); diff --git a/source/blender/functions/FN_cpp_type_make.hh b/source/blender/functions/FN_cpp_type_make.hh index 088f6b469f4..74dbcabf81a 100644 --- a/source/blender/functions/FN_cpp_type_make.hh +++ b/source/blender/functions/FN_cpp_type_make.hh @@ -195,6 +195,7 @@ CPPType::CPPType(CPPTypeParam<T, Flags> /* unused */, StringRef debug_name) debug_name_ = debug_name; size_ = (int64_t)sizeof(T); alignment_ = (int64_t)alignof(T); + is_trivial_ = std::is_trivial_v<T>; is_trivially_destructible_ = std::is_trivially_destructible_v<T>; if constexpr (std::is_default_constructible_v<T>) { default_construct_ = default_construct_cb<T>; |