[libcxx-commits] [libcxx] [libc++] Add a few _LIBCPP_ASSERT_INTERNALs to make sure internal invariants are kept (PR #114575)

Vitaly Buka via libcxx-commits libcxx-commits at lists.llvm.org
Fri Nov 29 15:26:48 PST 2024


================
@@ -1990,10 +1998,12 @@ private:
   }
 
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pointer __get_long_pointer() _NOEXCEPT {
+    _LIBCPP_ASSERT_INTERNAL(__rep_.__l.__is_long_, "String has to be long when trying to get the long pointer");
     return _LIBCPP_ASAN_VOLATILE_WRAPPER(__rep_.__l.__data_);
   }
 
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_pointer __get_long_pointer() const _NOEXCEPT {
+    _LIBCPP_ASSERT_INTERNAL(__rep_.__l.__is_long_, "String has to be long when trying to get the long pointer");
----------------
vitalybuka wrote:

I tried to bisect llvm revisions and it still reproducible >1 years back, if I insert just a single equivalent of 
`_LIBCPP_ASSERT_INTERNAL(__rep_.__l.__is_long_, "String has to be long when trying to get the long pointer");`

Something like

```
# just to normalize for sed
clang-format -i llvm/include/c++/v1/string

sed -E -i 's/(__get_long_pointer\(\) .*_NOEXCEPT \{)/\1 _LIBCPP_ASSERT_INTERNAL(__r_.first().__l.__is_long_, "");/g' llvm/include/c++/v1/string
```

I am in progress of creduce example, but I rather suspect a compiler bug.

https://github.com/llvm/llvm-project/pull/114575


More information about the libcxx-commits mailing list