[Lldb-commits] [clang] [clang-tools-extra] [llvm] [libcxx] [libc] [lldb] [flang] [openmp] [mlir] [compiler-rt] [libc++][span] P2821R5: span.at() (PR #74994)

2023-12-16 Thread Mark de Wever via lldb-commits


@@ -343,6 +347,15 @@ public:
 return __data_[__idx];
 }
 
+#  if _LIBCPP_STD_VER >= 26
+_LIBCPP_HIDE_FROM_ABI constexpr reference at(size_type __idx) const {

mordante wrote:

Nevermind this only applies to non-member functions and classes themselves.

https://github.com/llvm/llvm-project/pull/74994
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang] [clang-tools-extra] [openmp] [llvm] [mlir] [lldb] [libc] [libcxx] [flang] [compiler-rt] [libc++][span] P2821R5: span.at() (PR #74994)

2023-12-16 Thread Mark de Wever via lldb-commits


@@ -0,0 +1,170 @@
+//===--===//
+//
+// 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, c++17, c++20, c++23
+
+// 
+
+// constexpr reference at(size_type idx) const; // since C++26
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_macros.h"
+
+template 
+constexpr void testSpanAt(auto&& anySpan, int index, int expectedValue) {
+  // non-const
+  {
+std::same_as decltype(auto) elem = anySpan.at(index);
+assert(elem == expectedValue);
+  }
+
+  // const
+  {
+std::same_as decltype(auto) elem = 
std::as_const(anySpan).at(index);
+assert(elem == expectedValue);
+  }
+}
+
+constexpr bool test() {
+  // With static extent
+  {
+std::array arr{0, 1, 2, 3, 4, 5, 9084};
+std::span arrSpan{arr};
+
+assert(std::dynamic_extent != arrSpan.extent);
+
+using ReferenceT = typename decltype(arrSpan)::reference;
+
+testSpanAt(arrSpan, 0, 0);
+testSpanAt(arrSpan, 1, 1);
+testSpanAt(arrSpan, 6, 9084);
+  }
+
+  // With dynamic extent
+  {
+std::vector vec{0, 1, 2, 3, 4, 5, 9084};
+std::span vecSpan{vec};
+
+assert(std::dynamic_extent == vecSpan.extent);
+
+using ReferenceT = typename decltype(vecSpan)::reference;
+
+testSpanAt(vecSpan, 0, 0);
+testSpanAt(vecSpan, 1, 1);
+testSpanAt(vecSpan, 6, 9084);
+  }
+
+  return true;
+}
+
+void test_exceptions() {
+#ifndef TEST_HAS_NO_EXCEPTIONS
+  using namespace std::string_literals;
+
+  // With static extent
+  {
+std::array arr{0, 1, 2, 3, 4, 5, 9084, std::numeric_limits::max()};
+const std::span arrSpan{arr};
+
+try {
+  std::ignore = arrSpan.at(arr.size());
+  assert(false);
+} catch (const std::out_of_range& e) {
+  // pass
+  assert(e.what() == "span"s);
+} catch (...) {
+  assert(false);
+}
+
+try {
+  std::ignore = arrSpan.at(arr.size() - 1);
+  // pass
+  assert(arrSpan.at(arr.size() - 1) == std::numeric_limits::max());
+} catch (const std::out_of_range&) {
+  assert(false);

mordante wrote:

```suggestion
```
It think it looks better to only use a `catch(...)` when we don't expect an 
exception.

https://github.com/llvm/llvm-project/pull/74994
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang] [clang-tools-extra] [llvm] [libcxx] [libc] [lldb] [flang] [openmp] [mlir] [compiler-rt] [libc++][span] P2821R5: span.at() (PR #74994)

2023-12-16 Thread Mark de Wever via lldb-commits

https://github.com/mordante requested changes to this pull request.

Mostly looks good, a few comments.

https://github.com/llvm/llvm-project/pull/74994
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang-tools-extra] [mlir] [libcxx] [compiler-rt] [clang] [llvm] [lldb] [openmp] [libc] [flang] [libc++][span] P2821R5: span.at() (PR #74994)

2023-12-16 Thread Mark de Wever via lldb-commits

https://github.com/mordante edited 
https://github.com/llvm/llvm-project/pull/74994
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [compiler-rt] [clang-tools-extra] [clang] [flang] [mlir] [lldb] [libcxx] [llvm] [openmp] [libc] [libc++][span] P2821R5: span.at() (PR #74994)

2023-12-16 Thread Mark de Wever via lldb-commits




mordante wrote:

What is this submodule? I assume it's not intended to be here.

https://github.com/llvm/llvm-project/pull/74994
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang] [lld] [compiler-rt] [clang-tools-extra] [llvm] [lldb] [mlir] [libcxx] [libc++][ranges] Implement ranges::contains_subrange (PR #66963)

2023-12-16 Thread Mark de Wever via lldb-commits


@@ -0,0 +1,145 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H
+#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H
+
+#include <__algorithm/ranges_search.h>
+#include <__config>
+#include <__functional/identity.h>
+#include <__functional/ranges_operations.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/indirectly_comparable.h>
+#include <__iterator/projected.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER >= 23
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace ranges {
+namespace __contains_subrange {
+struct __fn {
+  template  _Sent1,
+forward_iterator _Iter2,
+sentinel_for<_Iter2> _Sent2,
+class _Pred,
+class _Proj1,
+class _Proj2,
+class _Offset = int>
+  static _LIBCPP_HIDE_FROM_ABI constexpr bool __contains_subrange_fn_impl(
+  _Iter1 __first1,
+  _Sent1 __last1,
+  _Iter2 __first2,
+  _Sent2 __last2,
+  _Pred& __pred,
+  _Proj1& __proj1,
+  _Proj2& __proj2,
+  _Offset __offset) {
+if (__offset < 0)
+  return false;
+else {
+  auto result = ranges::search(
+  std::move(__first1),
+  std::move(__last1),
+  std::move(__first2),
+  std::move(__last2),
+  std::ref(__pred),
+  std::ref(__proj1),
+  std::ref(__proj2));
+  return result.empty() == false;
+}
+  }
+
+  template  _Sent1,
+forward_iterator _Iter2,
+sentinel_for<_Iter2> _Sent2,
+class _Pred  = ranges::equal_to,
+class _Proj1 = identity,
+class _Proj2 = identity>
+requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(
+  _Iter1 __first1,
+  _Sent1 __last1,
+  _Iter2 __first2,
+  _Sent2 __last2,
+  _Pred __pred   = {},
+  _Proj1 __proj1 = {},
+  _Proj2 __proj2 = {}) const {
+int __n1 = ranges::distance(__first1, __last1);
+int __n2 = ranges::distance(__first2, __last2);
+if (__n2 == 0)
+  return true;
+int __offset = __n1 - __n2;
+
+return __contains_subrange_fn_impl(
+std::move(__first1),
+std::move(__last1),
+std::move(__first2),
+std::move(__last2),
+__pred,
+__proj1,
+__proj2,
+std::move(__offset));
+  }
+
+  template 
+requires indirectly_comparable, iterator_t<_Range2>, 
_Pred, _Proj1, _Proj2>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(
+  _Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 
__proj1 = {}, _Proj2 __proj2 = {}) const {
+int __n1 = 0;
+int __n2 = 0;
+
+if constexpr (sized_range<_Range1> && sized_range<_Range2>) {
+  __n1 = ranges::size(__range1);
+  __n2 = ranges::size(__range2);
+} else {
+  __n1 = ranges::distance(__range1);
+  __n2 = ranges::distance(__range2);
+}
+
+if (__n2 == 0)
+  return true;
+int __offset = __n1 - __n2;
+return __contains_subrange_fn_impl(
+ranges::begin(__range1),
+ranges::end(__range1),
+ranges::begin(__range2),
+ranges::end(__range2),
+__pred,
+__proj1,
+__proj2,
+__offset);
+  }
+};
+} // namespace __contains_subrange
+
+inline namespace __cpo {
+inline constexpr auto contains_subrange = __contains_subrange::__fn{};

mordante wrote:

This function needs to be exported from modules. See 
https://github.com/llvm/llvm-project/blob/main/libcxx/modules/std/algorithm.inc#L44

https://github.com/llvm/llvm-project/pull/66963
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [libcxx] [clang] [lld] [clang-tools-extra] [lldb] [mlir] [compiler-rt] [llvm] [libc++][ranges] Implement ranges::contains_subrange (PR #66963)

2023-12-16 Thread Mark de Wever via lldb-commits

https://github.com/mordante commented:

Thanks for your patch!
I mainly glossed over the patch, and left some comments.

https://github.com/llvm/llvm-project/pull/66963
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lld] [clang] [llvm] [compiler-rt] [clang-tools-extra] [lldb] [libcxx] [mlir] [libc++][ranges] Implement ranges::contains_subrange (PR #66963)

2023-12-16 Thread Mark de Wever via lldb-commits

https://github.com/mordante edited 
https://github.com/llvm/llvm-project/pull/66963
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang-tools-extra] [compiler-rt] [lld] [clang] [libcxx] [mlir] [lldb] [llvm] [libc++][ranges] Implement ranges::contains_subrange (PR #66963)

2023-12-16 Thread Mark de Wever via lldb-commits


@@ -0,0 +1,145 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H
+#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H
+
+#include <__algorithm/ranges_search.h>
+#include <__config>
+#include <__functional/identity.h>
+#include <__functional/ranges_operations.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/indirectly_comparable.h>
+#include <__iterator/projected.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER >= 23
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace ranges {
+namespace __contains_subrange {
+struct __fn {
+  template  _Sent1,
+forward_iterator _Iter2,
+sentinel_for<_Iter2> _Sent2,
+class _Pred,
+class _Proj1,
+class _Proj2,
+class _Offset = int>
+  static _LIBCPP_HIDE_FROM_ABI constexpr bool __contains_subrange_fn_impl(
+  _Iter1 __first1,
+  _Sent1 __last1,
+  _Iter2 __first2,
+  _Sent2 __last2,
+  _Pred& __pred,
+  _Proj1& __proj1,
+  _Proj2& __proj2,
+  _Offset __offset) {
+if (__offset < 0)
+  return false;
+else {
+  auto result = ranges::search(
+  std::move(__first1),
+  std::move(__last1),
+  std::move(__first2),
+  std::move(__last2),
+  std::ref(__pred),
+  std::ref(__proj1),
+  std::ref(__proj2));
+  return result.empty() == false;
+}
+  }
+
+  template  _Sent1,
+forward_iterator _Iter2,
+sentinel_for<_Iter2> _Sent2,
+class _Pred  = ranges::equal_to,
+class _Proj1 = identity,
+class _Proj2 = identity>
+requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(

mordante wrote:

The `_LIBCPP_NODISCARD_EXT` need to be tested. Can you add them too
`libcxx/test/libcxx/diagnostics/ranges.nodiscard_extensions.compile.pass.cpp`
`libcxx/test/libcxx/diagnostics/ranges.nodiscard_extensions.verify.cpp`


https://github.com/llvm/llvm-project/pull/66963
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [llvm] [flang] [mlir] [lldb] [libcxx] [compiler-rt] [clang-tools-extra] [libc] [openmp] [clang] [libc++][span] P2821R5: span.at() (PR #74994)

2023-12-17 Thread Mark de Wever via lldb-commits

https://github.com/mordante commented:

A few more comments, I overlooked parts of them yesterday.

Please make sure to apply the suggestions to all similar places in the code.

https://github.com/llvm/llvm-project/pull/74994
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [compiler-rt] [llvm] [clang] [flang] [openmp] [libcxx] [mlir] [libc] [lldb] [clang-tools-extra] [libc++][span] P2821R5: span.at() (PR #74994)

2023-12-17 Thread Mark de Wever via lldb-commits


@@ -0,0 +1,168 @@
+//===--===//
+//
+// 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, c++17, c++20, c++23
+
+// 
+
+// constexpr reference at(size_type idx) const; // since C++26
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_macros.h"
+
+template 
+constexpr void testSpanAt(auto&& anySpan, int index, int expectedValue) {
+  // non-const
+  {
+std::same_as decltype(auto) elem = anySpan.at(index);
+assert(elem == expectedValue);
+  }
+
+  // const
+  {
+std::same_as decltype(auto) elem = 
std::as_const(anySpan).at(index);
+assert(elem == expectedValue);
+  }
+}
+
+constexpr bool test() {
+  // With static extent
+  {
+std::array arr{0, 1, 2, 3, 4, 5, 9084};
+std::span arrSpan{arr};
+
+assert(std::dynamic_extent != arrSpan.extent);
+
+using ReferenceT = typename decltype(arrSpan)::reference;
+
+testSpanAt(arrSpan, 0, 0);
+testSpanAt(arrSpan, 1, 1);
+testSpanAt(arrSpan, 6, 9084);
+  }
+
+  // With dynamic extent
+  {
+std::vector vec{0, 1, 2, 3, 4, 5, 9084};
+std::span vecSpan{vec};
+
+assert(std::dynamic_extent == vecSpan.extent);
+
+using ReferenceT = typename decltype(vecSpan)::reference;
+
+testSpanAt(vecSpan, 0, 0);
+testSpanAt(vecSpan, 1, 1);
+testSpanAt(vecSpan, 6, 9084);
+  }
+
+  return true;
+}
+
+void test_exceptions() {
+#ifndef TEST_HAS_NO_EXCEPTIONS
+  using namespace std::string_literals;
+
+  // With static extent
+  {
+std::array arr{0, 1, 2, 3, 4, 5, 9084, std::numeric_limits::max()};
+const std::span arrSpan{arr};
+
+try {
+  std::ignore = arrSpan.at(arr.size());
+  assert(false);
+} catch (const std::out_of_range& e) {
+  // pass
+  assert(e.what() == "span"s);
+} catch (...) {
+  assert(false);
+}
+
+try {
+  std::ignore = arrSpan.at(arr.size() - 1);
+  // pass
+  assert(arrSpan.at(arr.size() - 1) == std::numeric_limits::max());
+} catch (...) {
+  assert(false);
+}
+  }
+
+  {
+std::array arr{};
+const std::span arrSpan{arr};
+
+try {
+  std::ignore = arrSpan.at(0);
+  assert(false);
+} catch (const std::out_of_range& e) {
+  // pass
+  assert(e.what() == "span"s);

mordante wrote:

```suggestion
  LIBCPP_ASSERT(e.what() == "span"s);
```
This assert should only be tested for libc++. This means on other 
implementations the `e` is unused.

https://github.com/llvm/llvm-project/pull/74994
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang] [libcxx] [flang] [lldb] [mlir] [llvm] [openmp] [clang-tools-extra] [compiler-rt] [libc] [libc++][span] P2821R5: span.at() (PR #74994)

2023-12-17 Thread Mark de Wever via lldb-commits

https://github.com/mordante edited 
https://github.com/llvm/llvm-project/pull/74994
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang] [compiler-rt] [flang] [libcxx] [lldb] [libc] [llvm] [openmp] [mlir] [clang-tools-extra] [libc++][span] P2821R5: span.at() (PR #74994)

2023-12-17 Thread Mark de Wever via lldb-commits


@@ -0,0 +1,168 @@
+//===--===//
+//
+// 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, c++17, c++20, c++23
+
+// 
+
+// constexpr reference at(size_type idx) const; // since C++26
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_macros.h"
+
+template 
+constexpr void testSpanAt(auto&& anySpan, int index, int expectedValue) {
+  // non-const
+  {
+std::same_as decltype(auto) elem = anySpan.at(index);
+assert(elem == expectedValue);
+  }
+
+  // const
+  {
+std::same_as decltype(auto) elem = 
std::as_const(anySpan).at(index);
+assert(elem == expectedValue);
+  }
+}
+
+constexpr bool test() {
+  // With static extent
+  {
+std::array arr{0, 1, 2, 3, 4, 5, 9084};
+std::span arrSpan{arr};
+
+assert(std::dynamic_extent != arrSpan.extent);
+
+using ReferenceT = typename decltype(arrSpan)::reference;
+
+testSpanAt(arrSpan, 0, 0);
+testSpanAt(arrSpan, 1, 1);
+testSpanAt(arrSpan, 6, 9084);
+  }
+
+  // With dynamic extent
+  {
+std::vector vec{0, 1, 2, 3, 4, 5, 9084};
+std::span vecSpan{vec};
+
+assert(std::dynamic_extent == vecSpan.extent);
+
+using ReferenceT = typename decltype(vecSpan)::reference;
+
+testSpanAt(vecSpan, 0, 0);
+testSpanAt(vecSpan, 1, 1);
+testSpanAt(vecSpan, 6, 9084);
+  }
+
+  return true;
+}
+
+void test_exceptions() {
+#ifndef TEST_HAS_NO_EXCEPTIONS
+  using namespace std::string_literals;
+
+  // With static extent
+  {
+std::array arr{0, 1, 2, 3, 4, 5, 9084, std::numeric_limits::max()};
+const std::span arrSpan{arr};
+
+try {
+  std::ignore = arrSpan.at(arr.size());
+  assert(false);
+} catch (const std::out_of_range& e) {
+  // pass
+  assert(e.what() == "span"s);
+} catch (...) {
+  assert(false);
+}
+
+try {
+  std::ignore = arrSpan.at(arr.size() - 1);
+  // pass
+  assert(arrSpan.at(arr.size() - 1) == std::numeric_limits::max());
+} catch (...) {

mordante wrote:

please apply this change to similar places too,

https://github.com/llvm/llvm-project/pull/74994
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [mlir] [lldb] [openmp] [libc] [llvm] [clang] [flang] [libcxx] [clang-tools-extra] [compiler-rt] [libc++][span] P2821R5: span.at() (PR #74994)

2023-12-17 Thread Mark de Wever via lldb-commits

https://github.com/mordante approved this pull request.

Thanks for the fixes, LGTM!

https://github.com/llvm/llvm-project/pull/74994
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [llvm] [clang-tools-extra] [libcxx] [flang] [compiler-rt] [libc] [clang] [lldb] [libc++][variant] P2637R3: Member `visit` (`std::variant`) (PR #76447)

2023-12-30 Thread Mark de Wever via lldb-commits

https://github.com/mordante edited 
https://github.com/llvm/llvm-project/pull/76447
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [llvm] [clang] [compiler-rt] [clang-tools-extra] [flang] [libc] [libcxx] [lldb] [libc++][variant] P2637R3: Member `visit` (`std::variant`) (PR #76447)

2023-12-30 Thread Mark de Wever via lldb-commits

https://github.com/mordante requested changes to this pull request.

Thanks for working on this!

https://github.com/llvm/llvm-project/pull/76447
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [llvm] [clang-tools-extra] [libcxx] [compiler-rt] [libc] [flang] [lldb] [clang] [libc++][variant] P2637R3: Member `visit` (`std::variant`) (PR #76447)

2023-12-30 Thread Mark de Wever via lldb-commits


@@ -40,6 +40,8 @@ Paper Status
 .. note::
 
.. [#note-P2510R3] This paper is applied as DR against C++20. (MSVC STL and 
libstdc++ will do the same.)
+   .. [#note-P2637R3] P2637R3: Implemented `variant` member `visit`

mordante wrote:

Since we have both patches under review I don't mind to strongly about this 
note. It's more important when there a no other patches. (However I don't 
object.)

https://github.com/llvm/llvm-project/pull/76447
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [libc] [llvm] [libcxx] [clang-tools-extra] [flang] [clang] [lldb] [compiler-rt] [libc++][variant] P2637R3: Member `visit` (`std::variant`) (PR #76447)

2023-12-30 Thread Mark de Wever via lldb-commits


@@ -0,0 +1,268 @@
+//===--===//
+//
+// 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, c++17, c++20, c++23
+
+// 
+
+// class variant;
+
+// template
+//   constexpr decltype(auto) visit(this Self&&, Visitor&&); // since C++26
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_macros.h"
+#include "variant_test_helpers.h"
+
+void test_call_operator_forwarding() {
+  using Fn = ForwardingCallObject;
+  Fn obj{};
+  const Fn& cobj = obj;
+
+  { // test call operator forwarding - no variant
+// non-member
+{
+  std::visit(obj);
+  assert(Fn::check_call<>(CT_NonConst | CT_LValue));
+  std::visit(cobj);
+  assert(Fn::check_call<>(CT_Const | CT_LValue));
+  std::visit(std::move(obj));
+  assert(Fn::check_call<>(CT_NonConst | CT_RValue));
+  std::visit(std::move(cobj));
+  assert(Fn::check_call<>(CT_Const | CT_RValue));
+}
+  }
+  { // test call operator forwarding - single variant, single arg
+using V = std::variant;
+V v(42);
+
+v.visit(obj);
+assert(Fn::check_call(CT_NonConst | CT_LValue));
+v.visit(cobj);
+assert(Fn::check_call(CT_Const | CT_LValue));
+v.visit(std::move(obj));
+assert(Fn::check_call(CT_NonConst | CT_RValue));
+v.visit(std::move(cobj));
+assert(Fn::check_call(CT_Const | CT_RValue));
+  }
+  { // test call operator forwarding - single variant, multi arg
+using V = std::variant;
+V v(42L);
+
+v.visit(obj);
+assert(Fn::check_call(CT_NonConst | CT_LValue));
+v.visit(cobj);
+assert(Fn::check_call(CT_Const | CT_LValue));
+v.visit(std::move(obj));
+assert(Fn::check_call(CT_NonConst | CT_RValue));
+v.visit(std::move(cobj));
+assert(Fn::check_call(CT_Const | CT_RValue));
+  }
+}
+
+// Applies to non-member `std::visit` only.
+void test_argument_forwarding() {
+  using Fn = ForwardingCallObject;
+  Fn obj{};
+  const auto val = CT_LValue | CT_NonConst;
+
+  { // single argument - value type
+using V = std::variant;
+V v(42);
+const V& cv = v;
+
+v.visit(obj);
+assert(Fn::check_call(val));
+cv.visit(obj);
+assert(Fn::check_call(val));
+std::move(v).visit(obj);
+assert(Fn::check_call(val));
+std::move(cv).visit(obj);
+assert(Fn::check_call(val));
+  }
+#if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
+  { // single argument - lvalue reference
+using V = std::variant;
+int x   = 42;
+V v(x);
+const V& cv = v;
+
+v.visit(obj);
+assert(Fn::check_call(val));
+cv.visit(obj);
+assert(Fn::check_call(val));
+std::move(v).visit(obj);
+assert(Fn::check_call(val));
+std::move(cv).visit(obj);
+assert(Fn::check_call(val));
+assert(false);
+  }
+  { // single argument - rvalue reference
+using V = std::variant;
+int x   = 42;
+V v(std::move(x));
+const V& cv = v;
+
+v.visit(obj);
+assert(Fn::check_call(val));
+cvstd::visit(obj);
+assert(Fn::check_call(val));
+std::move(v).visit(obj);
+assert(Fn::check_call(val));
+std::move(cv).visit(obj);
+assert(Fn::check_call(val));
+  }
+#endif
+}
+
+void test_return_type() {
+  using Fn = ForwardingCallObject;
+  Fn obj{};
+  const Fn& cobj = obj;
+
+  { // test call operator forwarding - single variant, single arg
+using V = std::variant;
+V v(42);
+
+static_assert(std::is_same_v);
+static_assert(std::is_same_v);
+static_assert(std::is_same_v);
+static_assert(std::is_same_v);
+  }
+  { // test call operator forwarding - single variant, multi arg
+using V = std::variant;
+V v(42L);
+
+static_assert(std::is_same_v);
+static_assert(std::is_same_v);
+static_assert(std::is_same_v);
+static_assert(std::is_same_v);
+  }
+}
+
+void test_constexpr() {
+  constexpr ReturnFirst obj{};
+
+  {
+using V = std::variant;
+constexpr V v(42);
+
+static_assert(v.visit(obj) == 42);
+  }
+  {
+using V = std::variant;
+constexpr V v(42L);
+
+static_assert(v.visit(obj) == 42);
+  }
+}
+
+void test_exceptions() {
+#ifndef TEST_HAS_NO_EXCEPTIONS
+  ReturnArity obj{};
+
+  auto test = [&](auto&& v) {
+try {
+  v.visit(obj);
+} catch (const std::bad_variant_access&) {
+  return true;
+} catch (...) {
+}
+return false;
+  };
+
+  {
+using V = std::variant;
+V v;
+makeEmpty(v);
+
+assert(test(v));
+  }
+#endif
+}
+
+// See https://llvm.org/PR31916
+void test_caller_accepts_nonconst() {
+  struct A {};
+  struct Visitor {
+void operator()(A&) {}
+  };
+  std::variant v;
+
+  v.visit(Visitor{});
+}
+
+struct MyVariant : std::variant {};
+
+n

[Lldb-commits] [libc] [clang] [clang-tools-extra] [libcxx] [compiler-rt] [lldb] [llvm] [flang] [libc++][variant] P2637R3: Member `visit` (`std::variant`) (PR #76447)

2023-12-30 Thread Mark de Wever via lldb-commits


@@ -69,6 +69,12 @@ namespace std {
 
 // 20.7.2.6, swap
 void swap(variant&) noexcept(see below);
+
+// [variant.visit], visitation
+template
+  constexpr decltype(auto) visit(this Self&&, Visitor&&);
+template
+  constexpr R visit(this Self&&, Visitor&&);

mordante wrote:

```suggestion
template
  constexpr decltype(auto) visit(this Self&&, Visitor&&);// Since C++26
template
  constexpr R visit(this Self&&, Visitor&&); // Since C++26
```

https://github.com/llvm/llvm-project/pull/76447
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [llvm] [compiler-rt] [libc] [clang] [libcxx] [flang] [clang-tools-extra] [lldb] [libc++][variant] P2637R3: Member `visit` (`std::variant`) (PR #76447)

2023-12-30 Thread Mark de Wever via lldb-commits


@@ -17,27 +17,28 @@
 #include "test_macros.h"
 
 struct Incomplete;
-template struct Holder { T t; };

mordante wrote:

For this file too.

https://github.com/llvm/llvm-project/pull/76447
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [libcxx] [llvm] [libc] [lldb] [compiler-rt] [clang-tools-extra] [clang] [flang] [libc++][variant] P2637R3: Member `visit` (`std::variant`) (PR #76447)

2023-12-30 Thread Mark de Wever via lldb-commits


@@ -26,7 +26,7 @@ template 
 void test_call_operator_forwarding() {
   using Fn = ForwardingCallObject;
   Fn obj{};
-  const Fn &cobj = obj;

mordante wrote:

Please undo the formatting changes to this file. It's hard to see what really 
changed.

https://github.com/llvm/llvm-project/pull/76447
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [flang] [clang] [lldb] [libc] [libcxx] [llvm] [compiler-rt] [clang-tools-extra] [libc++][variant] P2637R3: Member `visit` (`std::variant`) (PR #76447)

2023-12-30 Thread Mark de Wever via lldb-commits


@@ -0,0 +1,268 @@
+//===--===//
+//
+// 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, c++17, c++20, c++23
+
+// 
+
+// class variant;
+
+// template
+//   constexpr decltype(auto) visit(this Self&&, Visitor&&); // since C++26
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_macros.h"
+#include "variant_test_helpers.h"
+
+void test_call_operator_forwarding() {
+  using Fn = ForwardingCallObject;
+  Fn obj{};
+  const Fn& cobj = obj;
+
+  { // test call operator forwarding - no variant
+// non-member
+{
+  std::visit(obj);
+  assert(Fn::check_call<>(CT_NonConst | CT_LValue));

mordante wrote:

I assume this code is copied from somewhere else. I find it quite hard to read 
what is tested here.

https://github.com/llvm/llvm-project/pull/76447
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [flang] [llvm] [lldb] [compiler-rt] [clang-tools-extra] [libc] [clang] [libcxx] [libc++][variant] P2637R3: Member `visit` (`std::variant`) (PR #76447)

2023-12-30 Thread Mark de Wever via lldb-commits


@@ -1273,6 +1280,15 @@ public:
 __impl_.__swap(__that.__impl_);
   }
 
+#  if _LIBCPP_STD_VER >= 26
+  // [variant.visit], visitation
+  template 
+  constexpr decltype(auto) visit(this _Self&& __self, _Visitor&& __visitor);

mordante wrote:

nowadays we prefer to write the body in the class.

https://github.com/llvm/llvm-project/pull/76447
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [compiler-rt] [clang-tools-extra] [flang] [libc] [lldb] [clang] [llvm] [libcxx] [libc++][variant] P2637R3: Member `visit` (`std::variant`) (PR #76447)

2023-12-31 Thread Mark de Wever via lldb-commits


@@ -26,7 +26,7 @@ template 
 void test_call_operator_forwarding() {
   using Fn = ForwardingCallObject;
   Fn obj{};
-  const Fn &cobj = obj;

mordante wrote:

Thanks! We still need to reformat all our tests like we did with the headers. 
The main problem with mixing formatting and real changes that it often is hard 
for the reviewer to find the real changes in a file.

https://github.com/llvm/llvm-project/pull/76447
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [openmp] [clang-tools-extra] [flang] [mlir] [llvm] [lld] [compiler-rt] [libc] [lldb] [clang] [libcxx] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-03 Thread Mark de Wever via lldb-commits

mordante wrote:

> > I did a full review. There are a number of comments, once these are 
> > addressed the patch is ready.
> 
> Thank you for the detailed review and patience!
> 
> I believe the failing tests are unrelated to this patch:
> 
> > Failed Tests (2):
> > llvm-libc++-shared-clangcl.cfg.in :: 
> > libcxx/utilities/expected/expected.expected/transform_error.mandates.verify.cpp
> > llvm-libc++-shared-clangcl.cfg.in :: 
> > libcxx/utilities/expected/expected.void/transform_error.mandates.verify.cpp

The breakage is indeed unrelated. I've reverted the patch that introduced it.

https://github.com/llvm/llvm-project/pull/76632
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [flang] [clang] [openmp] [libcxx] [lld] [lldb] [clang-tools-extra] [llvm] [mlir] [compiler-rt] [libc] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-03 Thread Mark de Wever via lldb-commits

https://github.com/mordante requested changes to this pull request.

LGTM modulo some nits. I like to have a quick look at the final version before 
approving.

https://github.com/llvm/llvm-project/pull/76632
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [openmp] [clang-tools-extra] [flang] [mlir] [llvm] [lld] [compiler-rt] [libc] [lldb] [clang] [libcxx] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-03 Thread Mark de Wever via lldb-commits

https://github.com/mordante edited 
https://github.com/llvm/llvm-project/pull/76632
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [libcxx] [lld] [llvm] [openmp] [libc] [lldb] [mlir] [compiler-rt] [flang] [clang] [clang-tools-extra] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-03 Thread Mark de Wever via lldb-commits


@@ -24,6 +24,10 @@
 
 #include "test_macros.h"
 
+#if _LIBCPP_STD_VER >= 26

mordante wrote:

This is the way to test for versions in the test suite.
```suggestion
#if TEST_STD_VER >= 26
```
The same for other places. Also since we can no longer use 
`native_handle_test_helpers` I prefer the use the C++ version guard in that 
header. (I know I asked for it's removal earlier, sorry).

https://github.com/llvm/llvm-project/pull/76632
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [mlir] [openmp] [lldb] [libc] [compiler-rt] [libcxx] [llvm] [lld] [clang-tools-extra] [flang] [clang] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-03 Thread Mark de Wever via lldb-commits


@@ -0,0 +1,30 @@
+//===--===//
+//
+// 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, c++17, c++20, c++23
+
+// REQUIRES: has-unix-headers
+// UNSUPPORTED: libcpp-hardening-mode=none
+// XFAIL: availability-verbose_abort-missing
+
+// 
+
+// class basic_filebuf;
+
+// native_handle_type native_handle() const noexcept;
+
+#include 
+
+#include "../native_handle_test_helpers.h"
+
+int main(int, char**) {
+  test_native_handle_assertion>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+  test_native_handle_assertion>();
+#endif

mordante wrote:

```suggestion
#endif
  return 0;
```
The same for the other assert tests.

https://github.com/llvm/llvm-project/pull/76632
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang-tools-extra] [clang] [llvm] [mlir] [libc] [libcxx] [flang] [openmp] [lldb] [compiler-rt] [lld] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-03 Thread Mark de Wever via lldb-commits


@@ -0,0 +1,58 @@
+//===--===//
+//
+// 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, c++17, c++20, c++23
+
+// 
+
+// class basic_filebuf;
+
+// native_handle_type native_handle() const noexcept;
+
+#include 
+#include 
+#include 
+#include 
+
+#include "platform_support.h"
+#include "test_macros.h"
+#include "../native_handle_test_helpers.h"
+
+template 
+void test() {
+  std::basic_filebuf f;
+  std::filesystem::path p = get_temp_file_name();
+
+  // non-const
+  {

mordante wrote:

Thanks I find this a lot more readable.

https://github.com/llvm/llvm-project/pull/76632
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lld] [llvm] [openmp] [clang-tools-extra] [flang] [libcxx] [compiler-rt] [mlir] [lldb] [clang] [libc] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-03 Thread Mark de Wever via lldb-commits


@@ -0,0 +1,101 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+#ifndef TEST_STD_INPUT_OUTPUT_FILE_STREAMS_FSTREAMS_TEST_HELPERS_H
+#define TEST_STD_INPUT_OUTPUT_FILE_STREAMS_FSTREAMS_TEST_HELPERS_H
+
+#include "test_macros.h"
+
+#if TEST_STD_VER >= 26
+
+#  include 
+#  include 
+#  include 
+#  include 
+#  include 
+#  include 
+#  include 
+
+#  if defined(_WIN32)
+#define WIN32_LEAN_AND_MEAN
+#define NOMINMAX
+#include 
+#include 
+#  else
+#include 
+#  endif
+
+#  include "check_assertion.h"
+#  include "platform_support.h"
+#  include "types.h"
+
+inline bool is_handle_valid(NativeHandleT handle) {

mordante wrote:

I would do it after the all the includes, that is the natural way.

https://github.com/llvm/llvm-project/pull/76632
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [compiler-rt] [libc] [mlir] [clang-tools-extra] [lldb] [lld] [openmp] [flang] [clang] [libcxx] [llvm] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-04 Thread Mark de Wever via lldb-commits


@@ -0,0 +1,97 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+#ifndef TEST_STD_INPUT_OUTPUT_FILE_STREAMS_FSTREAMS_TEST_HELPERS_H
+#define TEST_STD_INPUT_OUTPUT_FILE_STREAMS_FSTREAMS_TEST_HELPERS_H
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#if defined(_WIN32)
+#  include 
+#  include 
+#else
+#  include 
+#endif
+
+#include "platform_support.h"
+#include "test_macros.h"
+#include "types.h"
+
+#if TEST_STD_VER >= 26
+
+#  include "check_assertion.h"
+
+inline bool is_handle_valid(NativeHandleT handle) {
+#  if defined(_WIN32)
+  BY_HANDLE_FILE_INFORMATION fileInformation;
+  return GetFileInformationByHandle(handle, &fileInformation));
+#  elif __has_include() // POSIX
+  return fcntl(handle, F_GETFL) != -1 || errno != EBADF;
+#  else
+#error "Provide a native file handle!"
+#  endif
+}
+
+template 
+inline void test_native_handle() {
+  static_assert(
+  std::is_same_v::native_handle_type, 
typename StreamT::native_handle_type>);
+
+  StreamT f;
+  std::filesystem::path p = get_temp_file_name();
+
+  // non-const
+  {
+f.open(p);
+std::same_as decltype(auto) handle = f.native_handle();
+assert(is_handle_valid(handle));
+assert(f.rdbuf()->native_handle() == handle);
+assert(std::as_const(f).rdbuf()->native_handle() == handle);
+f.close();
+assert(!is_handle_valid(handle));
+static_assert(noexcept(f.native_handle()));
+  }
+  // const
+  {
+f.open(p);
+std::same_as decltype(auto) const_handle = 
std::as_const(f).native_handle();
+assert(is_handle_valid(const_handle));
+assert(f.rdbuf()->native_handle() == const_handle);
+assert(std::as_const(f).rdbuf()->native_handle() == const_handle);
+f.close();
+assert(!is_handle_valid(const_handle));
+static_assert(noexcept(std::as_const(f).native_handle()));
+  }
+}
+
+template 
+inline void test_native_handle_assertion() {
+  StreamT f;
+
+  // non-const
+  { TEST_LIBCPP_ASSERT_FAILURE(f.native_handle(), "File must be opened"); }

mordante wrote:

nit: We don't need an extra scope here. I'm not objecting either.

https://github.com/llvm/llvm-project/pull/76632
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [libc] [llvm] [openmp] [mlir] [lldb] [flang] [lld] [clang] [libcxx] [compiler-rt] [clang-tools-extra] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-04 Thread Mark de Wever via lldb-commits

https://github.com/mordante approved this pull request.

Thanks LGTM!

https://github.com/llvm/llvm-project/pull/76632
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [openmp] [lld] [llvm] [libcxx] [lldb] [clang-tools-extra] [mlir] [flang] [compiler-rt] [libc] [clang] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-04 Thread Mark de Wever via lldb-commits

https://github.com/mordante edited 
https://github.com/llvm/llvm-project/pull/76632
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][libc++] Adds some C++20 calendar data formatters. (PR #76983)

2024-01-04 Thread Mark de Wever via lldb-commits

https://github.com/mordante created 
https://github.com/llvm/llvm-project/pull/76983

This adds a subset of the C++20 calendar data formatters:
- day,
- month,
- year,
- month_day,
- month_day_last, and
- year_month_day.

A followup patch will add the missing calendar data formatters:
- weekday,
- weekday_indexed,
- weekday_last,
- month_weekday,
- month_weekday_last,
- year_month,
- year_month_day_last
- year_month_weekday, and
- year_month_weekday_last.

>From f92402067fcdb6b87adcf3d727bff1888ebf4ab7 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Thu, 4 Jan 2024 18:43:54 +0100
Subject: [PATCH] [lldb][libc++] Adds some C++20 calendar data formatters.

This adds a subset of the C++20 calendar data formatters:
- day,
- month,
- year,
- month_day,
- month_day_last, and
- year_month_day.

A followup patch will add the missing calendar data formatters:
- weekday,
- weekday_indexed,
- weekday_last,
- month_weekday,
- month_weekday_last,
- year_month,
- year_month_day_last
- year_month_weekday, and
- year_month_weekday_last.
---
 .../Language/CPlusPlus/CPlusPlusLanguage.cpp  | 35 ++
 .../Plugins/Language/CPlusPlus/LibCxx.cpp | 40 +++
 .../Plugins/Language/CPlusPlus/LibCxx.h   |  8 +++
 .../chrono/TestDataFormatterLibcxxChrono.py   | 67 +++
 .../data-formatter-stl/libcxx/chrono/main.cpp | 54 +++
 5 files changed, 204 insertions(+)

diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
index 586cc08a6f1233..c6937ebca319fa 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -1031,6 +1031,41 @@ static void 
LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
   "^std::__[[:alnum:]]+::chrono::seconds", eFormatterMatchRegex,
   TypeSummaryImplSP(new StringSummaryFormat(
   eTypeOptionHideChildren | eTypeOptionHideValue, "${var.__rep_} s")));
+
+  // Chrono calendar types
+
+  cpp_category_sp->AddTypeSummary(
+  "^std::__[[:alnum:]]+::chrono::day$", eFormatterMatchRegex,
+  TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
+eTypeOptionHideValue,
+"day=${var.__d_%u}")));
+  AddCXXSummary(cpp_category_sp,
+lldb_private::formatters::LibcxxChronoMonthSummaryProvider,
+"libc++ std::chrono::month summary provider",
+"^std::__[[:alnum:]]+::chrono::month$",
+eTypeOptionHideChildren | eTypeOptionHideValue, true);
+
+  cpp_category_sp->AddTypeSummary(
+  "^std::__[[:alnum:]]+::chrono::year$", eFormatterMatchRegex,
+  TypeSummaryImplSP(new StringSummaryFormat(
+  eTypeOptionHideChildren | eTypeOptionHideValue, 
"year=${var.__y_}")));
+
+  cpp_category_sp->AddTypeSummary(
+  "^std::__[[:alnum:]]+::chrono::month_day$", eFormatterMatchRegex,
+  TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
+eTypeOptionHideValue,
+"${var.__m_} ${var.__d_}")));
+  cpp_category_sp->AddTypeSummary(
+  "^std::__[[:alnum:]]+::chrono::month_day_last$", eFormatterMatchRegex,
+  TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
+eTypeOptionHideValue,
+"${var.__m_} day=last")));
+  AddCXXSummary(
+  cpp_category_sp,
+  lldb_private::formatters::LibcxxChronoYearMonthDaySummaryProvider,
+  "libc++ std::chrono::year_month_day summary provider",
+  "^std::__[[:alnum:]]+::chrono::year_month_day$",
+  eTypeOptionHideChildren | eTypeOptionHideValue, true);
 }
 
 static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
index cae17ef992b215..5f9228c7b020c8 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
@@ -1084,3 +1084,43 @@ bool 
lldb_private::formatters::LibcxxWStringViewSummaryProvider(
   return ::LibcxxWStringSummaryProvider(valobj, stream, summary_options,
 dataobj, size);
 }
+
+bool lldb_private::formatters::LibcxxChronoMonthSummaryProvider(
+ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
+  // These are the names used in the C++20 ostream operator. Since LLVM uses
+  // C++17 it's not possible to use the ostream operator directly.
+  static const std::array months = {
+  "January", "February", "March", "April",   "May",  "June",
+  "July","August",   "September", "October", "November", "December"};
+
+  unsigned month = 
valobj.GetCh

[Lldb-commits] [lldb] [lldb][libc++] Adds some C++20 calendar data formatters. (PR #76983)

2024-01-04 Thread Mark de Wever via lldb-commits

mordante wrote:

Note: I'd be happy to add the missing calendar data formatters to this review. 
I just want to make sure we're happy with the proposed output before adding 
them.

https://github.com/llvm/llvm-project/pull/76983
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [libunwind] [llvm] [libcxx] [lld] [lldb] [flang] [libc] [clang] [compiler-rt] [clang-tools-extra] [libc++][test] try to directly create socket file in /tmp when filepath is too long (PR

2024-01-08 Thread Mark de Wever via lldb-commits

https://github.com/mordante approved this pull request.

Thanks! LGTM!

https://github.com/llvm/llvm-project/pull/77058
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang] [lld] [compiler-rt] [flang] [llvm] [libcxx] [lldb] [libunwind] [libc] [clang-tools-extra] [libc++][test] try to directly create socket file in /tmp when filepath is too long (PR

2024-01-08 Thread Mark de Wever via lldb-commits

https://github.com/mordante edited 
https://github.com/llvm/llvm-project/pull/77058
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang-tools-extra] [libcxx] [clang] [lldb] [compiler-rt] [lld] [llvm] [libunwind] [libc] [flang] [libc++][test] try to directly create socket file in /tmp when filepath is too long (PR

2024-01-08 Thread Mark de Wever via lldb-commits


@@ -320,16 +320,26 @@ struct scoped_test_env
   // allow tests to call this unguarded.
 #if !defined(__FreeBSD__) && !defined(__APPLE__) && !defined(_WIN32)
 std::string create_socket(std::string file) {
-file = sanitize_path(std::move(file));
-
-::sockaddr_un address;
-address.sun_family = AF_UNIX;
-assert(file.size() <= sizeof(address.sun_path));
-::strncpy(address.sun_path, file.c_str(), sizeof(address.sun_path));
-int fd = ::socket(AF_UNIX, SOCK_STREAM, 0);
-::bind(fd, reinterpret_cast<::sockaddr*>(&address), sizeof(address));
-return file;
+  file = sanitize_path(std::move(file));
+
+  ::sockaddr_un address;
+  address.sun_family = AF_UNIX;
+
+// If file.size() is too big, try to create a file directly inside
+// /tmp to make sure file path is short enough.
+// Android platform warns about tmpnam, since the problem does not appear
+// on Android, let's not apply it for Android.

mordante wrote:

Not too happy about this, but since we assert afterwards it will fail the test. 
If that happens we can investigate.

https://github.com/llvm/llvm-project/pull/77058
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][libc++] Adds some C++20 calendar data formatters. (PR #76983)

2024-01-09 Thread Mark de Wever via lldb-commits

https://github.com/mordante updated 
https://github.com/llvm/llvm-project/pull/76983

>From f92402067fcdb6b87adcf3d727bff1888ebf4ab7 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Thu, 4 Jan 2024 18:43:54 +0100
Subject: [PATCH 1/2] [lldb][libc++] Adds some C++20 calendar data formatters.

This adds a subset of the C++20 calendar data formatters:
- day,
- month,
- year,
- month_day,
- month_day_last, and
- year_month_day.

A followup patch will add the missing calendar data formatters:
- weekday,
- weekday_indexed,
- weekday_last,
- month_weekday,
- month_weekday_last,
- year_month,
- year_month_day_last
- year_month_weekday, and
- year_month_weekday_last.
---
 .../Language/CPlusPlus/CPlusPlusLanguage.cpp  | 35 ++
 .../Plugins/Language/CPlusPlus/LibCxx.cpp | 40 +++
 .../Plugins/Language/CPlusPlus/LibCxx.h   |  8 +++
 .../chrono/TestDataFormatterLibcxxChrono.py   | 67 +++
 .../data-formatter-stl/libcxx/chrono/main.cpp | 54 +++
 5 files changed, 204 insertions(+)

diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
index 586cc08a6f1233..c6937ebca319fa 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -1031,6 +1031,41 @@ static void 
LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
   "^std::__[[:alnum:]]+::chrono::seconds", eFormatterMatchRegex,
   TypeSummaryImplSP(new StringSummaryFormat(
   eTypeOptionHideChildren | eTypeOptionHideValue, "${var.__rep_} s")));
+
+  // Chrono calendar types
+
+  cpp_category_sp->AddTypeSummary(
+  "^std::__[[:alnum:]]+::chrono::day$", eFormatterMatchRegex,
+  TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
+eTypeOptionHideValue,
+"day=${var.__d_%u}")));
+  AddCXXSummary(cpp_category_sp,
+lldb_private::formatters::LibcxxChronoMonthSummaryProvider,
+"libc++ std::chrono::month summary provider",
+"^std::__[[:alnum:]]+::chrono::month$",
+eTypeOptionHideChildren | eTypeOptionHideValue, true);
+
+  cpp_category_sp->AddTypeSummary(
+  "^std::__[[:alnum:]]+::chrono::year$", eFormatterMatchRegex,
+  TypeSummaryImplSP(new StringSummaryFormat(
+  eTypeOptionHideChildren | eTypeOptionHideValue, 
"year=${var.__y_}")));
+
+  cpp_category_sp->AddTypeSummary(
+  "^std::__[[:alnum:]]+::chrono::month_day$", eFormatterMatchRegex,
+  TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
+eTypeOptionHideValue,
+"${var.__m_} ${var.__d_}")));
+  cpp_category_sp->AddTypeSummary(
+  "^std::__[[:alnum:]]+::chrono::month_day_last$", eFormatterMatchRegex,
+  TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
+eTypeOptionHideValue,
+"${var.__m_} day=last")));
+  AddCXXSummary(
+  cpp_category_sp,
+  lldb_private::formatters::LibcxxChronoYearMonthDaySummaryProvider,
+  "libc++ std::chrono::year_month_day summary provider",
+  "^std::__[[:alnum:]]+::chrono::year_month_day$",
+  eTypeOptionHideChildren | eTypeOptionHideValue, true);
 }
 
 static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
index cae17ef992b215..5f9228c7b020c8 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
@@ -1084,3 +1084,43 @@ bool 
lldb_private::formatters::LibcxxWStringViewSummaryProvider(
   return ::LibcxxWStringSummaryProvider(valobj, stream, summary_options,
 dataobj, size);
 }
+
+bool lldb_private::formatters::LibcxxChronoMonthSummaryProvider(
+ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
+  // These are the names used in the C++20 ostream operator. Since LLVM uses
+  // C++17 it's not possible to use the ostream operator directly.
+  static const std::array months = {
+  "January", "February", "March", "April",   "May",  "June",
+  "July","August",   "September", "October", "November", "December"};
+
+  unsigned month = 
valobj.GetChildMemberWithName("__m_")->GetValueAsUnsigned(0);
+  if (month >= 1 && month <= 12)
+stream << "month=" << months[month - 1];
+  else
+stream.Printf("month=%u", month);
+
+  return true;
+}
+
+bool lldb_private::formatters::LibcxxChronoYearMonthDaySummaryProvider(
+ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
+
+  stream << "dat

[Lldb-commits] [lldb] [lldb][libc++] Adds some C++20 calendar data formatters. (PR #76983)

2024-01-09 Thread Mark de Wever via lldb-commits

mordante wrote:

Thanks for the reviews!

https://github.com/llvm/llvm-project/pull/76983
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][libc++] Adds some C++20 calendar data formatters. (PR #76983)

2024-01-09 Thread Mark de Wever via lldb-commits

https://github.com/mordante closed 
https://github.com/llvm/llvm-project/pull/76983
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [flang] [compiler-rt] [libunwind] [libc] [libcxx] [lld] [llvm] [clang] [lldb] [clang-tools-extra] [libc++][test] try to directly create socket file in /tmp when filepath is too long (PR

2024-01-09 Thread Mark de Wever via lldb-commits

https://github.com/mordante closed 
https://github.com/llvm/llvm-project/pull/77058
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [flang] [compiler-rt] [libunwind] [libc] [libcxx] [lld] [llvm] [clang] [lldb] [clang-tools-extra] [libc++][test] try to directly create socket file in /tmp when filepath is too long (PR

2024-01-09 Thread Mark de Wever via lldb-commits

mordante wrote:

Done.

https://github.com/llvm/llvm-project/pull/77058
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB][doc] Updates build instructions. (PR #84630)

2024-03-09 Thread Mark de Wever via lldb-commits

https://github.com/mordante created 
https://github.com/llvm/llvm-project/pull/84630

Recently building libc++ requires building libunwind too. This updates the LLDB 
instructions.

I noticed this recently and it was separately filed as 
https://github.com/llvm/llvm-project/issues/84053

>From 9943bf871deaf30468850702397e3f1a649339dd Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Sat, 9 Mar 2024 15:01:08 +0100
Subject: [PATCH] [LLDB][doc] Updates build instructions.

Recently building libc++ requires building libunwind too. This updates
the LLDB instructions.

I noticed this recently and it was separately filed as
https://github.com/llvm/llvm-project/issues/84053
---
 lldb/docs/resources/build.rst | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lldb/docs/resources/build.rst b/lldb/docs/resources/build.rst
index 5f4d35ced6236c..54f7d1cc93c4b0 100644
--- a/lldb/docs/resources/build.rst
+++ b/lldb/docs/resources/build.rst
@@ -331,7 +331,7 @@ macOS
 ^
 
 On macOS the LLDB test suite requires libc++. Either add
-``LLVM_ENABLE_RUNTIMES="libcxx;libcxxabi"`` or disable the test suite with
+``LLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind"`` or disable the test 
suite with
 ``LLDB_INCLUDE_TESTS=OFF``. Further useful options:
 
 * ``LLDB_BUILD_FRAMEWORK:BOOL``: Builds the LLDB.framework.
@@ -370,7 +370,7 @@ LLVM `_):
   $ cmake -B /path/to/lldb-build -G Ninja \
   -C /path/to/llvm-project/lldb/cmake/caches/Apple-lldb-macOS.cmake \
   -DLLVM_ENABLE_PROJECTS="clang;lldb" \
-  -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \
+  -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" \
   llvm-project/llvm
 
   $ DESTDIR=/path/to/lldb-install ninja -C /path/to/lldb-build check-lldb 
install-distribution
@@ -386,7 +386,7 @@ Build LLDB standalone for development with Xcode:
   $ cmake -B /path/to/llvm-build -G Ninja \
   -C /path/to/llvm-project/lldb/cmake/caches/Apple-lldb-base.cmake \
   -DLLVM_ENABLE_PROJECTS="clang" \
-  -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \
+  -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" \
   llvm-project/llvm
   $ ninja -C /path/to/llvm-build
 

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB][doc] Updates build instructions. (PR #84630)

2024-03-11 Thread Mark de Wever via lldb-commits

https://github.com/mordante closed 
https://github.com/llvm/llvm-project/pull/84630
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB][doc] Updates build instructions. (PR #84630)

2024-03-11 Thread Mark de Wever via lldb-commits

mordante wrote:

> Looks good. I see the PR test for "Test documentation build" is failing, but 
> that's an issue with the bot and pexpect.

Is this a known issue and is somebody already working on fixing this?

https://github.com/llvm/llvm-project/pull/84630
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][libc++] Adds slice_array data formatters. (PR #85544)

2024-03-16 Thread Mark de Wever via lldb-commits

https://github.com/mordante created 
https://github.com/llvm/llvm-project/pull/85544

None

>From 52d525c8377fe36d2c8c7705736482ee6a021366 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Sat, 16 Mar 2024 17:25:32 +0100
Subject: [PATCH] [lldb][libc++] Adds slice_array data formatters.

---
 .../Plugins/Language/CPlusPlus/CMakeLists.txt |   1 +
 .../Language/CPlusPlus/CPlusPlusLanguage.cpp  |  10 ++
 .../Plugins/Language/CPlusPlus/LibCxx.h   |   8 +
 .../Language/CPlusPlus/LibCxxSliceArray.cpp   | 166 ++
 .../TestDataFormatterLibcxxValarray.py|  31 
 .../libcxx/valarray/main.cpp  |   3 +
 6 files changed, 219 insertions(+)
 create mode 100644 lldb/source/Plugins/Language/CPlusPlus/LibCxxSliceArray.cpp

diff --git a/lldb/source/Plugins/Language/CPlusPlus/CMakeLists.txt 
b/lldb/source/Plugins/Language/CPlusPlus/CMakeLists.txt
index 97fa894ea73761..0c6fdb2b957315 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CMakeLists.txt
+++ b/lldb/source/Plugins/Language/CPlusPlus/CMakeLists.txt
@@ -13,6 +13,7 @@ add_lldb_library(lldbPluginCPlusPlusLanguage PLUGIN
   LibCxxMap.cpp
   LibCxxQueue.cpp
   LibCxxRangesRefView.cpp
+  LibCxxSliceArray.cpp
   LibCxxSpan.cpp
   LibCxxTuple.cpp
   LibCxxUnorderedMap.cpp
diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
index 675ca385186102..4a536096a066ff 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -755,6 +755,11 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP 
cpp_category_sp) {
   lldb_private::formatters::LibcxxStdValarraySyntheticFrontEndCreator,
   "libc++ std::valarray synthetic children",
   "^std::__[[:alnum:]]+::valarray<.+>$", stl_deref_flags, true);
+  AddCXXSynthetic(
+  cpp_category_sp,
+  lldb_private::formatters::LibcxxStdSliceArraySyntheticFrontEndCreator,
+  "libc++ std::slice_array synthetic children",
+  "^std::__[[:alnum:]]+::slice_array<.+>$", stl_deref_flags, true);
   AddCXXSynthetic(
   cpp_category_sp,
   lldb_private::formatters::LibcxxStdForwardListSyntheticFrontEndCreator,
@@ -880,6 +885,11 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP 
cpp_category_sp) {
 lldb_private::formatters::LibcxxContainerSummaryProvider,
 "libc++ std::valarray summary provider",
 "^std::__[[:alnum:]]+::valarray<.+>$", stl_summary_flags, 
true);
+  AddCXXSummary(cpp_category_sp,
+lldb_private::formatters::LibcxxStdSliceArraySummaryProvider,
+"libc++ std::slice_array summary provider",
+"^std::__[[:alnum:]]+::slice_array<.+>$", stl_summary_flags,
+true);
   AddCXXSummary(
   cpp_category_sp, 
lldb_private::formatters::LibcxxContainerSummaryProvider,
   "libc++ std::list summary provider",
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h 
b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
index a59f21841ec890..d8b807d180e068 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
@@ -59,6 +59,10 @@ bool LibcxxWStringViewSummaryProvider(
 ValueObject &valobj, Stream &stream,
 const TypeSummaryOptions &options); // libc++ std::wstring_view
 
+bool LibcxxStdSliceArraySummaryProvider(
+ValueObject &valobj, Stream &stream,
+const TypeSummaryOptions &options); // libc++ std::slice_array
+
 bool LibcxxSmartPointerSummaryProvider(
 ValueObject &valobj, Stream &stream,
 const TypeSummaryOptions
@@ -223,6 +227,10 @@ SyntheticChildrenFrontEnd *
 LibcxxStdValarraySyntheticFrontEndCreator(CXXSyntheticChildren *,
   lldb::ValueObjectSP);
 
+SyntheticChildrenFrontEnd *
+LibcxxStdSliceArraySyntheticFrontEndCreator(CXXSyntheticChildren *,
+lldb::ValueObjectSP);
+
 SyntheticChildrenFrontEnd *
 LibcxxStdListSyntheticFrontEndCreator(CXXSyntheticChildren *,
   lldb::ValueObjectSP);
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxSliceArray.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/LibCxxSliceArray.cpp
new file mode 100644
index 00..724514dd0697b9
--- /dev/null
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxSliceArray.cpp
@@ -0,0 +1,166 @@
+//===-- 
LibCxxSliceArray.cpp---===//
+//
+// 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
+//
+//===--===//
+
+#include "LibCxx.h"
+
+#include "lldb/Core/ValueObject.h"
+#include "lldb/DataFormatters/FormattersHelpers.h"
+#include 
+
+using na

[Lldb-commits] [lldb] [lldb][libc++] Adds slice_array data formatters. (PR #85544)

2024-03-17 Thread Mark de Wever via lldb-commits

https://github.com/mordante updated 
https://github.com/llvm/llvm-project/pull/85544

>From 52d525c8377fe36d2c8c7705736482ee6a021366 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Sat, 16 Mar 2024 17:25:32 +0100
Subject: [PATCH 1/2] [lldb][libc++] Adds slice_array data formatters.

---
 .../Plugins/Language/CPlusPlus/CMakeLists.txt |   1 +
 .../Language/CPlusPlus/CPlusPlusLanguage.cpp  |  10 ++
 .../Plugins/Language/CPlusPlus/LibCxx.h   |   8 +
 .../Language/CPlusPlus/LibCxxSliceArray.cpp   | 166 ++
 .../TestDataFormatterLibcxxValarray.py|  31 
 .../libcxx/valarray/main.cpp  |   3 +
 6 files changed, 219 insertions(+)
 create mode 100644 lldb/source/Plugins/Language/CPlusPlus/LibCxxSliceArray.cpp

diff --git a/lldb/source/Plugins/Language/CPlusPlus/CMakeLists.txt 
b/lldb/source/Plugins/Language/CPlusPlus/CMakeLists.txt
index 97fa894ea73761..0c6fdb2b957315 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CMakeLists.txt
+++ b/lldb/source/Plugins/Language/CPlusPlus/CMakeLists.txt
@@ -13,6 +13,7 @@ add_lldb_library(lldbPluginCPlusPlusLanguage PLUGIN
   LibCxxMap.cpp
   LibCxxQueue.cpp
   LibCxxRangesRefView.cpp
+  LibCxxSliceArray.cpp
   LibCxxSpan.cpp
   LibCxxTuple.cpp
   LibCxxUnorderedMap.cpp
diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
index 675ca385186102..4a536096a066ff 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -755,6 +755,11 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP 
cpp_category_sp) {
   lldb_private::formatters::LibcxxStdValarraySyntheticFrontEndCreator,
   "libc++ std::valarray synthetic children",
   "^std::__[[:alnum:]]+::valarray<.+>$", stl_deref_flags, true);
+  AddCXXSynthetic(
+  cpp_category_sp,
+  lldb_private::formatters::LibcxxStdSliceArraySyntheticFrontEndCreator,
+  "libc++ std::slice_array synthetic children",
+  "^std::__[[:alnum:]]+::slice_array<.+>$", stl_deref_flags, true);
   AddCXXSynthetic(
   cpp_category_sp,
   lldb_private::formatters::LibcxxStdForwardListSyntheticFrontEndCreator,
@@ -880,6 +885,11 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP 
cpp_category_sp) {
 lldb_private::formatters::LibcxxContainerSummaryProvider,
 "libc++ std::valarray summary provider",
 "^std::__[[:alnum:]]+::valarray<.+>$", stl_summary_flags, 
true);
+  AddCXXSummary(cpp_category_sp,
+lldb_private::formatters::LibcxxStdSliceArraySummaryProvider,
+"libc++ std::slice_array summary provider",
+"^std::__[[:alnum:]]+::slice_array<.+>$", stl_summary_flags,
+true);
   AddCXXSummary(
   cpp_category_sp, 
lldb_private::formatters::LibcxxContainerSummaryProvider,
   "libc++ std::list summary provider",
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h 
b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
index a59f21841ec890..d8b807d180e068 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
@@ -59,6 +59,10 @@ bool LibcxxWStringViewSummaryProvider(
 ValueObject &valobj, Stream &stream,
 const TypeSummaryOptions &options); // libc++ std::wstring_view
 
+bool LibcxxStdSliceArraySummaryProvider(
+ValueObject &valobj, Stream &stream,
+const TypeSummaryOptions &options); // libc++ std::slice_array
+
 bool LibcxxSmartPointerSummaryProvider(
 ValueObject &valobj, Stream &stream,
 const TypeSummaryOptions
@@ -223,6 +227,10 @@ SyntheticChildrenFrontEnd *
 LibcxxStdValarraySyntheticFrontEndCreator(CXXSyntheticChildren *,
   lldb::ValueObjectSP);
 
+SyntheticChildrenFrontEnd *
+LibcxxStdSliceArraySyntheticFrontEndCreator(CXXSyntheticChildren *,
+lldb::ValueObjectSP);
+
 SyntheticChildrenFrontEnd *
 LibcxxStdListSyntheticFrontEndCreator(CXXSyntheticChildren *,
   lldb::ValueObjectSP);
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxSliceArray.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/LibCxxSliceArray.cpp
new file mode 100644
index 00..724514dd0697b9
--- /dev/null
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxSliceArray.cpp
@@ -0,0 +1,166 @@
+//===-- 
LibCxxSliceArray.cpp---===//
+//
+// 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
+//
+//===--===//
+
+#include "LibCxx.h"
+
+#include "lldb/Core/ValueObject.h"
+#include "lldb/DataFormatters/FormattersHelpers.h"
+#include 
+
+using name

[Lldb-commits] [lldb] [lldb][libc++] Adds slice_array data formatters. (PR #85544)

2024-03-17 Thread Mark de Wever via lldb-commits

https://github.com/mordante closed 
https://github.com/llvm/llvm-project/pull/85544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][libc++] Adds slice_array data formatters. (PR #85544)

2024-03-17 Thread Mark de Wever via lldb-commits

mordante wrote:

Thanks for the review!

https://github.com/llvm/llvm-project/pull/85544
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][DataFormatter] Fix format specifiers in LibCxxSliceArray summary provider (PR #85763)

2024-03-19 Thread Mark de Wever via lldb-commits

https://github.com/mordante approved this pull request.

I wasn't aware LLDB's print accepts `%zu`, thanks for the fix!

https://github.com/llvm/llvm-project/pull/85763
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][libc++] Adds local_t clock data formatters. (PR #88178)

2024-04-09 Thread Mark de Wever via lldb-commits

https://github.com/mordante created 
https://github.com/llvm/llvm-project/pull/88178

None

>From 656ee030e38be24732dd78f96204ce12fe40e788 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Tue, 19 Mar 2024 20:31:41 +0100
Subject: [PATCH] [lldb][libc++] Adds local_t clock data formatters.

---
 .../Language/CPlusPlus/CPlusPlusLanguage.cpp  |  23 
 .../Plugins/Language/CPlusPlus/LibCxx.cpp |  38 ++-
 .../Plugins/Language/CPlusPlus/LibCxx.h   |   8 ++
 .../chrono/TestDataFormatterLibcxxChrono.py   | 104 ++
 .../data-formatter-stl/libcxx/chrono/main.cpp |  52 +
 5 files changed, 220 insertions(+), 5 deletions(-)

diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
index 4a536096a066ff..5c28f6fe059e1a 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -1068,6 +1068,29 @@ static void 
LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
 eTypeOptionCascade,
 true);
 
+  AddCXXSummary(
+  cpp_category_sp,
+  lldb_private::formatters::LibcxxChronoLocalSecondsSummaryProvider,
+  "libc++ std::chrono::local_seconds summary provider",
+  "^std::__[[:alnum:]]+::chrono::time_point<"
+  "std::__[[:alnum:]]+::chrono::local_t, "
+  "std::__[[:alnum:]]+::chrono::duration "
+  "> >$",
+  eTypeOptionHideChildren | eTypeOptionHideValue | eTypeOptionCascade,
+  true);
+  AddCXXSummary(cpp_category_sp,
+lldb_private::formatters::LibcxxChronoLocalDaysSummaryProvider,
+"libc++ std::chrono::local_seconds summary provider",
+"^std::__[[:alnum:]]+::chrono::time_point<"
+"std::__[[:alnum:]]+::chrono::local_t, "
+"std::__[[:alnum:]]+::chrono::duration "
+"> >$",
+eTypeOptionHideChildren | eTypeOptionHideValue |
+eTypeOptionCascade,
+true);
+
   // Chrono calendar types
 
   cpp_category_sp->AddTypeSummary(
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
index d2d50152c07cf8..e160fd07639395 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
@@ -1087,8 +1087,10 @@ bool 
lldb_private::formatters::LibcxxWStringViewSummaryProvider(
 dataobj, size);
 }
 
-bool lldb_private::formatters::LibcxxChronoSysSecondsSummaryProvider(
-ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
+static bool
+LibcxxChronoTimePointSecondsSummaryProvider(ValueObject &valobj, Stream 
&stream,
+const TypeSummaryOptions &options,
+const char *fmt) {
   ValueObjectSP ptr_sp = valobj.GetChildMemberWithName("__d_");
   if (!ptr_sp)
 return false;
@@ -1112,7 +1114,7 @@ bool 
lldb_private::formatters::LibcxxChronoSysSecondsSummaryProvider(
   else {
 std::array str;
 std::size_t size =
-std::strftime(str.data(), str.size(), "%FT%H:%M:%SZ", 
gmtime(&seconds));
+std::strftime(str.data(), str.size(), fmt, gmtime(&seconds));
 if (size == 0)
   return false;
 
@@ -1123,8 +1125,22 @@ bool 
lldb_private::formatters::LibcxxChronoSysSecondsSummaryProvider(
   return true;
 }
 
-bool lldb_private::formatters::LibcxxChronoSysDaysSummaryProvider(
+bool lldb_private::formatters::LibcxxChronoSysSecondsSummaryProvider(
 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
+  return LibcxxChronoTimePointSecondsSummaryProvider(valobj, stream, options,
+ "%FT%H:%M:%SZ");
+}
+
+bool lldb_private::formatters::LibcxxChronoLocalSecondsSummaryProvider(
+ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
+  return LibcxxChronoTimePointSecondsSummaryProvider(valobj, stream, options,
+ "%FT%H:%M:%S");
+}
+
+static bool
+LibcxxChronoTimepointDaysSummaryProvider(ValueObject &valobj, Stream &stream,
+ const TypeSummaryOptions &options,
+ const char *fmt) {
   ValueObjectSP ptr_sp = valobj.GetChildMemberWithName("__d_");
   if (!ptr_sp)
 return false;
@@ -1148,7 +1164,7 @@ bool 
lldb_private::formatters::LibcxxChronoSysDaysSummaryProvider(
 
 std::array str;
 std::size_t size =
-std::strftime(str.data(), str.size(), "%FZ", gmtime(&seconds));
+std::strftime(str.data(), str.size(), fmt, gmtime(&seconds));
 if (size == 0)
   return false;
 
@@ -1158,6 +1174,18 @@ bool 
lldb_private::formatters::LibcxxChronoSysDaysSummaryProvider(
   return true;
 }
 
+bool lldb_private::f

[Lldb-commits] [libcxx] [lldb] [libc++][CI] Tests LLDB libc++ data formatters. (PR #88312)

2024-04-10 Thread Mark de Wever via lldb-commits

https://github.com/mordante created 
https://github.com/llvm/llvm-project/pull/88312

None

>From a94781dd9a993d88dc1eb0897eade23fb4acdf4e Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 10 Apr 2024 21:12:29 +0200
Subject: [PATCH] [libc++][CI] Tests LLDB libc++ data formatters.

---
 libcxx/utils/ci/run-buildbot| 10 +++---
 lldb/packages/Python/lldbsuite/test/lldbtest.py |  2 ++
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/libcxx/utils/ci/run-buildbot b/libcxx/utils/ci/run-buildbot
index a6f3eb174308b4..e6240a829b0c73 100755
--- a/libcxx/utils/ci/run-buildbot
+++ b/libcxx/utils/ci/run-buildbot
@@ -376,18 +376,22 @@ bootstrapping-build)
   -DCMAKE_CXX_COMPILER_LAUNCHER="ccache" \
   -DCMAKE_BUILD_TYPE=Release \
   -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
-  -DLLVM_ENABLE_PROJECTS="clang" \
+  -DLLVM_ENABLE_PROJECTS="clang;lldb" \
   -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" \
   -DLLVM_RUNTIME_TARGETS="$(${CXX} --print-target-triple)" \
+  -DLLVM_HOST_TRIPLE="$(${CXX} --print-target-triple)" \
   -DLLVM_TARGETS_TO_BUILD="host" \
   -DRUNTIMES_BUILD_ALLOW_DARWIN=ON \
   -DLLVM_ENABLE_ASSERTIONS=ON \
   -DLLVM_LIT_ARGS="-sv --xunit-xml-output test-results.xml 
--timeout=1500 --time-tests"
 
-echo "+++ Running the libc++ and libc++abi tests"
+echo "+++ Running the LLDB libc++ data formatter tests"
+${NINJA} -vC "${BUILD_DIR}" 
check-lldb-api-functionalities-data-formatter-data-formatter-stl-libcxx
+
+echo "--- Running the libc++ and libc++abi tests"
 ${NINJA} -vC "${BUILD_DIR}" check-runtimes
 
-echo "--- Installing libc++ and libc++abi to a fake location"
+echo "+++ Installing libc++ and libc++abi to a fake location"
 ${NINJA} -vC "${BUILD_DIR}" install-runtimes
 
 ccache -s
diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py 
b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index c28a78a2c4a27a..7a7afec7345707 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -751,6 +751,8 @@ def setUpCommands(cls):
 "settings set symbols.enable-external-lookup false",
 # Inherit the TCC permissions from the inferior's parent.
 "settings set target.inherit-tcc true",
+# Based on 
https://discourse.llvm.org/t/running-lldb-in-a-container/76801/4
+"settings set target.disable-aslr false",
 # Kill rather than detach from the inferior if something goes 
wrong.
 "settings set target.detach-on-error false",
 # Disable fix-its by default so that incorrect expressions in 
tests don't

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [libcxx] [lldb] [libc++][CI] Tests LLDB libc++ data formatters. (PR #88312)

2024-04-12 Thread Mark de Wever via lldb-commits

https://github.com/mordante edited 
https://github.com/llvm/llvm-project/pull/88312
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [libcxx] [lldb] [libc++][CI] Tests LLDB libc++ data formatters. (PR #88312)

2024-04-12 Thread Mark de Wever via lldb-commits


@@ -751,6 +751,8 @@ def setUpCommands(cls):
 "settings set symbols.enable-external-lookup false",
 # Inherit the TCC permissions from the inferior's parent.
 "settings set target.inherit-tcc true",
+# Based on 
https://discourse.llvm.org/t/running-lldb-in-a-container/76801/4
+"settings set target.disable-aslr false",

mordante wrote:

The reason for change is in the Discourse link. This probably needs to be done 
in a separate commit.

https://github.com/llvm/llvm-project/pull/88312
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [libcxx] [lldb] [libc++][CI] Tests LLDB libc++ data formatters. (PR #88312)

2024-04-12 Thread Mark de Wever via lldb-commits

https://github.com/mordante ready_for_review 
https://github.com/llvm/llvm-project/pull/88312
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][libc++] Adds local_t clock data formatters. (PR #88178)

2024-04-12 Thread Mark de Wever via lldb-commits


@@ -1068,6 +1068,29 @@ static void 
LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
 eTypeOptionCascade,
 true);
 
+  AddCXXSummary(
+  cpp_category_sp,
+  lldb_private::formatters::LibcxxChronoLocalSecondsSummaryProvider,
+  "libc++ std::chrono::local_seconds summary provider",
+  "^std::__[[:alnum:]]+::chrono::time_point<"
+  "std::__[[:alnum:]]+::chrono::local_t, "
+  "std::__[[:alnum:]]+::chrono::durationhttp://eel.is/c++draft/time.syn#def:signed_integer_type_of_at_least_35_bits)>;

In libc++ this is hard coded to `long long` on all platforms
https://github.com/llvm/llvm-project/blob/main/libcxx/include/__chrono/duration.h#L287

There is some value in it to future proof it, if we ever get a platform where 
long is 64 bit and long long 128 bit.

I'll also update `LibcxxChronoSysSecondsSummaryProvider` above.

https://github.com/llvm/llvm-project/pull/88178
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][libc++] Adds local_t clock data formatters. (PR #88178)

2024-04-13 Thread Mark de Wever via lldb-commits

https://github.com/mordante updated 
https://github.com/llvm/llvm-project/pull/88178

>From 5140ce2929ca56c865fc9c02fb0849ba06727c56 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Tue, 19 Mar 2024 20:31:41 +0100
Subject: [PATCH] [lldb][libc++] Adds local_t clock data formatters.

---
 .../Language/CPlusPlus/CPlusPlusLanguage.cpp  |  25 -
 .../Plugins/Language/CPlusPlus/LibCxx.cpp |  38 ++-
 .../Plugins/Language/CPlusPlus/LibCxx.h   |   8 ++
 .../chrono/TestDataFormatterLibcxxChrono.py   | 104 ++
 .../data-formatter-stl/libcxx/chrono/main.cpp |  52 +
 5 files changed, 221 insertions(+), 6 deletions(-)

diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
index 4a536096a066ff..afb683f7d846a6 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -1050,7 +1050,7 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP 
cpp_category_sp) {
 "libc++ std::chrono::sys_seconds summary provider",
 "^std::__[[:alnum:]]+::chrono::time_point<"
 "std::__[[:alnum:]]+::chrono::system_clock, "
-"std::__[[:alnum:]]+::chrono::duration "
 "> >$",
 eTypeOptionHideChildren | eTypeOptionHideValue |
@@ -1068,6 +1068,29 @@ static void 
LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
 eTypeOptionCascade,
 true);
 
+  AddCXXSummary(
+  cpp_category_sp,
+  lldb_private::formatters::LibcxxChronoLocalSecondsSummaryProvider,
+  "libc++ std::chrono::local_seconds summary provider",
+  "^std::__[[:alnum:]]+::chrono::time_point<"
+  "std::__[[:alnum:]]+::chrono::local_t, "
+  "std::__[[:alnum:]]+::chrono::duration<.*, "
+  "std::__[[:alnum:]]+::ratio<1, 1> "
+  "> >$",
+  eTypeOptionHideChildren | eTypeOptionHideValue | eTypeOptionCascade,
+  true);
+  AddCXXSummary(cpp_category_sp,
+lldb_private::formatters::LibcxxChronoLocalDaysSummaryProvider,
+"libc++ std::chrono::local_seconds summary provider",
+"^std::__[[:alnum:]]+::chrono::time_point<"
+"std::__[[:alnum:]]+::chrono::local_t, "
+"std::__[[:alnum:]]+::chrono::duration "
+"> >$",
+eTypeOptionHideChildren | eTypeOptionHideValue |
+eTypeOptionCascade,
+true);
+
   // Chrono calendar types
 
   cpp_category_sp->AddTypeSummary(
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
index d2d50152c07cf8..e160fd07639395 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
@@ -1087,8 +1087,10 @@ bool 
lldb_private::formatters::LibcxxWStringViewSummaryProvider(
 dataobj, size);
 }
 
-bool lldb_private::formatters::LibcxxChronoSysSecondsSummaryProvider(
-ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
+static bool
+LibcxxChronoTimePointSecondsSummaryProvider(ValueObject &valobj, Stream 
&stream,
+const TypeSummaryOptions &options,
+const char *fmt) {
   ValueObjectSP ptr_sp = valobj.GetChildMemberWithName("__d_");
   if (!ptr_sp)
 return false;
@@ -1112,7 +1114,7 @@ bool 
lldb_private::formatters::LibcxxChronoSysSecondsSummaryProvider(
   else {
 std::array str;
 std::size_t size =
-std::strftime(str.data(), str.size(), "%FT%H:%M:%SZ", 
gmtime(&seconds));
+std::strftime(str.data(), str.size(), fmt, gmtime(&seconds));
 if (size == 0)
   return false;
 
@@ -1123,8 +1125,22 @@ bool 
lldb_private::formatters::LibcxxChronoSysSecondsSummaryProvider(
   return true;
 }
 
-bool lldb_private::formatters::LibcxxChronoSysDaysSummaryProvider(
+bool lldb_private::formatters::LibcxxChronoSysSecondsSummaryProvider(
 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
+  return LibcxxChronoTimePointSecondsSummaryProvider(valobj, stream, options,
+ "%FT%H:%M:%SZ");
+}
+
+bool lldb_private::formatters::LibcxxChronoLocalSecondsSummaryProvider(
+ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
+  return LibcxxChronoTimePointSecondsSummaryProvider(valobj, stream, options,
+ "%FT%H:%M:%S");
+}
+
+static bool
+LibcxxChronoTimepointDaysSummaryProvider(ValueObject &valobj, Stream &stream,
+ const TypeSummaryOptions &options,
+ const char *fmt) {
   ValueObjectSP ptr_sp = valobj.GetChildMemberWithName("__d_");
   if (!

[Lldb-commits] [lldb] [lldb][libc++] Adds local_t clock data formatters. (PR #88178)

2024-04-13 Thread Mark de Wever via lldb-commits

https://github.com/mordante closed 
https://github.com/llvm/llvm-project/pull/88178
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] a33a754 - [lldb] Fixes comment typos.

2024-04-13 Thread Mark de Wever via lldb-commits

Author: Mark de Wever
Date: 2024-04-13T12:03:18+02:00
New Revision: a33a754cff02fda7520fa63fbc6c85c274a44baa

URL: 
https://github.com/llvm/llvm-project/commit/a33a754cff02fda7520fa63fbc6c85c274a44baa
DIFF: 
https://github.com/llvm/llvm-project/commit/a33a754cff02fda7520fa63fbc6c85c274a44baa.diff

LOG: [lldb] Fixes comment typos.

Added: 


Modified: 
lldb/source/Plugins/Language/CPlusPlus/LibCxxSliceArray.cpp

Removed: 




diff  --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxSliceArray.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/LibCxxSliceArray.cpp
index 32e67d2e38c5d3..c33d8e91af7099 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxSliceArray.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxSliceArray.cpp
@@ -73,9 +73,9 @@ class LibcxxStdSliceArraySyntheticFrontEnd : public 
SyntheticChildrenFrontEnd {
   size_t m_size = 0;
   /// slice_array.__stride_.
   size_t m_stride = 0;
-  /// The type of slize_array's template argument T.
+  /// The type of slice_array's template argument T.
   CompilerType m_element_type;
-  /// The sizeof slize_array's template argument T.
+  /// The sizeof slice_array's template argument T.
   uint32_t m_element_size = 0;
 };
 



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB][libc++] Adds valarray proxy data formatters. (PR #88613)

2024-04-13 Thread Mark de Wever via lldb-commits

https://github.com/mordante created 
https://github.com/llvm/llvm-project/pull/88613

These proxies are returned by operator[](...). These proxies all "behave" the 
same. They store a pointer to the data of the valarray they are a proxy for and 
they have an internal array of indices. This internal array is considered its 
contents.

>From a63ce7e68c7eb056fc2aead592792a37f647a4da Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 20 Mar 2024 19:16:18 +0100
Subject: [PATCH] [LLDB][libc++] Adds valarray proxy data formatters.

These proxies are returned by operator[](...). These proxies all
"behave" the same. They store a pointer to the data of the valarray they
are a proxy for and they have an internal array of indices. This
internal array is considered its contents.
---
 .../Plugins/Language/CPlusPlus/CMakeLists.txt |   1 +
 .../Language/CPlusPlus/CPlusPlusLanguage.cpp  |  11 +
 .../Plugins/Language/CPlusPlus/LibCxx.h   |   4 +
 .../Language/CPlusPlus/LibCxxProxyArray.cpp   | 194 ++
 .../TestDataFormatterLibcxxValarray.py|  88 +++-
 .../libcxx/valarray/main.cpp  |   6 +-
 6 files changed, 295 insertions(+), 9 deletions(-)
 create mode 100644 lldb/source/Plugins/Language/CPlusPlus/LibCxxProxyArray.cpp

diff --git a/lldb/source/Plugins/Language/CPlusPlus/CMakeLists.txt 
b/lldb/source/Plugins/Language/CPlusPlus/CMakeLists.txt
index 0c6fdb2b957315..f59032c423880f 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CMakeLists.txt
+++ b/lldb/source/Plugins/Language/CPlusPlus/CMakeLists.txt
@@ -14,6 +14,7 @@ add_lldb_library(lldbPluginCPlusPlusLanguage PLUGIN
   LibCxxQueue.cpp
   LibCxxRangesRefView.cpp
   LibCxxSliceArray.cpp
+  LibCxxProxyArray.cpp
   LibCxxSpan.cpp
   LibCxxTuple.cpp
   LibCxxUnorderedMap.cpp
diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
index afb683f7d846a6..5f0684163328f5 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -760,6 +760,12 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP 
cpp_category_sp) {
   lldb_private::formatters::LibcxxStdSliceArraySyntheticFrontEndCreator,
   "libc++ std::slice_array synthetic children",
   "^std::__[[:alnum:]]+::slice_array<.+>$", stl_deref_flags, true);
+  AddCXXSynthetic(
+  cpp_category_sp,
+  lldb_private::formatters::LibcxxStdProxyArraySyntheticFrontEndCreator,
+  "libc++ synthetic children for the valarray proxy arrays",
+  "^std::__[[:alnum:]]+::(gslice|mask|indirect)_array<.+>$",
+  stl_deref_flags, true);
   AddCXXSynthetic(
   cpp_category_sp,
   lldb_private::formatters::LibcxxStdForwardListSyntheticFrontEndCreator,
@@ -890,6 +896,11 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP 
cpp_category_sp) {
 "libc++ std::slice_array summary provider",
 "^std::__[[:alnum:]]+::slice_array<.+>$", stl_summary_flags,
 true);
+  AddCXXSummary(cpp_category_sp,
+lldb_private::formatters::LibcxxContainerSummaryProvider,
+"libc++ summary provider for the valarray proxy arrays",
+"^std::__[[:alnum:]]+::(gslice|mask|indirect)_array<.+>$",
+stl_summary_flags, true);
   AddCXXSummary(
   cpp_category_sp, 
lldb_private::formatters::LibcxxContainerSummaryProvider,
   "libc++ std::list summary provider",
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h 
b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
index 8e97174dc30757..7fe15d1bf3f7af 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
@@ -231,6 +231,10 @@ SyntheticChildrenFrontEnd *
 LibcxxStdSliceArraySyntheticFrontEndCreator(CXXSyntheticChildren *,
 lldb::ValueObjectSP);
 
+SyntheticChildrenFrontEnd *
+LibcxxStdProxyArraySyntheticFrontEndCreator(CXXSyntheticChildren *,
+lldb::ValueObjectSP);
+
 SyntheticChildrenFrontEnd *
 LibcxxStdListSyntheticFrontEndCreator(CXXSyntheticChildren *,
   lldb::ValueObjectSP);
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxProxyArray.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/LibCxxProxyArray.cpp
new file mode 100644
index 00..726f06523b97b4
--- /dev/null
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxProxyArray.cpp
@@ -0,0 +1,194 @@
+//===-- 
LibCxxProxyArray.cpp---===//
+//
+// 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
+//
+//===--===//
+
+#include "LibCxx.h"
+
+#incl

[Lldb-commits] [libcxx] [lldb] [libc++][CI] Tests LLDB libc++ data formatters. (PR #88312)

2024-04-15 Thread Mark de Wever via lldb-commits

https://github.com/mordante closed 
https://github.com/llvm/llvm-project/pull/88312
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB][libc++] Adds valarray proxy data formatters. (PR #88613)

2024-04-15 Thread Mark de Wever via lldb-commits

https://github.com/mordante edited 
https://github.com/llvm/llvm-project/pull/88613
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB][libc++] Adds valarray proxy data formatters. (PR #88613)

2024-04-15 Thread Mark de Wever via lldb-commits


@@ -0,0 +1,194 @@
+//===-- 
LibCxxProxyArray.cpp---===//
+//
+// 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
+//
+//===--===//
+
+#include "LibCxx.h"
+
+#include "lldb/Core/ValueObject.h"
+#include "lldb/DataFormatters/FormattersHelpers.h"
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::formatters;
+
+namespace lldb_private {
+namespace formatters {
+
+/// Data formatter for libc++'s std::"proxy_array".
+///
+/// A proxy_array's are created by using:
+///   std::gslice_array   operator[](const std::gslice& gslicearr);
+///   std::mask_array operator[](const std::valarray& boolarr);
+///   std::indirect_array operator[](const std::valarray& indarr);
+///
+/// These arrays have the following members:
+/// - __vp_ points to std::valarray::__begin_
+/// - __1d_ an array of offsets of the elements from @a __vp_
+class LibcxxStdProxyArraySyntheticFrontEnd : public SyntheticChildrenFrontEnd {
+public:
+  LibcxxStdProxyArraySyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
+
+  ~LibcxxStdProxyArraySyntheticFrontEnd() override;
+
+  llvm::Expected CalculateNumChildren() override;
+
+  lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override;
+
+  lldb::ChildCacheState Update() override;
+
+  bool MightHaveChildren() override;
+
+  size_t GetIndexOfChildWithName(ConstString name) override;
+
+private:
+  /// A non-owning pointer to the array's __vp_.
+  ValueObject *m_base = nullptr;
+  /// The type of the array's template argument T.
+  CompilerType m_element_type;
+  /// The sizeof the array's template argument T.
+  uint32_t m_element_size = 0;
+
+  /// A non-owning pointer to the array's __1d_.__begin_.
+  ValueObject *m_start = nullptr;
+  /// A non-owning pointer to the array's __1d_.__end_.
+  ValueObject *m_finish = nullptr;
+  /// The type of the __1d_ array's template argument T (size_t).
+  CompilerType m_element_type_size_t;
+  /// The sizeof the __1d_ array's template argument T (size_t)
+  uint32_t m_element_size_size_t = 0;
+};
+
+} // namespace formatters
+} // namespace lldb_private
+
+lldb_private::formatters::LibcxxStdProxyArraySyntheticFrontEnd::
+LibcxxStdProxyArraySyntheticFrontEnd(lldb::ValueObjectSP valobj_sp)
+: SyntheticChildrenFrontEnd(*valobj_sp), m_element_type() {
+  if (valobj_sp)
+Update();
+}
+
+lldb_private::formatters::LibcxxStdProxyArraySyntheticFrontEnd::
+~LibcxxStdProxyArraySyntheticFrontEnd() {
+  // these need to stay around because they are child objects who will follow
+  // their parent's life cycle
+  // delete m_base;
+}
+
+llvm::Expected lldb_private::formatters::
+LibcxxStdProxyArraySyntheticFrontEnd::CalculateNumChildren() {

mordante wrote:

Agreed. I noticed some duplication when looking at these too. This one is 
slightly different due to the indirect access.

https://github.com/llvm/llvm-project/pull/88613
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB][libc++] Adds valarray proxy data formatters. (PR #88613)

2024-04-15 Thread Mark de Wever via lldb-commits

https://github.com/mordante commented:

Thanks for the review!

https://github.com/llvm/llvm-project/pull/88613
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB][libc++] Adds valarray proxy data formatters. (PR #88613)

2024-04-15 Thread Mark de Wever via lldb-commits

https://github.com/mordante closed 
https://github.com/llvm/llvm-project/pull/88613
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [libcxx] [lldb] [libc++][CI] Tests LLDB libc++ data formatters. (PR #88312)

2024-04-16 Thread Mark de Wever via lldb-commits

mordante wrote:

Thanks for the fix!

https://github.com/llvm/llvm-project/pull/88312
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Correct documentation of LLDB_TEST_USER_ARGS (PR #89042)

2024-04-17 Thread Mark de Wever via lldb-commits

https://github.com/mordante approved this pull request.

Thanks! The changes LGTM, but I haven't verified the commands work as described.

https://github.com/llvm/llvm-project/pull/89042
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][libc++] Adds missing C++20 calendar data formatters. (PR #77954)

2024-01-12 Thread Mark de Wever via lldb-commits

https://github.com/mordante created 
https://github.com/llvm/llvm-project/pull/77954

This is a followup of #76983 and adds the libc++ data formatters for
- weekday,
- weekday_indexed,
- weekday_last,
- month_weekday,
- month_weekday_last,
- year_month,
- year_month_day_last
- year_month_weekday, and
- year_month_weekday_last.

>From 65b4143db4d7074d7b8604420591856a2fcfc0ee Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Fri, 12 Jan 2024 18:54:14 +0100
Subject: [PATCH] [lldb][libc++] Adds missing C++20 calendar data formatters.

This is a followup of #76983 and adds the data formatters for
- weekday,
- weekday_indexed,
- weekday_last,
- month_weekday,
- month_weekday_last,
- year_month,
- year_month_day_last
- year_month_weekday, and
- year_month_weekday_last.
---
 .../Language/CPlusPlus/CPlusPlusLanguage.cpp  | 57 
 .../Plugins/Language/CPlusPlus/LibCxx.cpp | 21 +
 .../Plugins/Language/CPlusPlus/LibCxx.h   |  4 +
 .../chrono/TestDataFormatterLibcxxChrono.py   | 93 +++
 .../data-formatter-stl/libcxx/chrono/main.cpp | 56 +++
 5 files changed, 231 insertions(+)

diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
index c6937ebca319fa..7131ccb9d05eca 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -1039,6 +1039,7 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP 
cpp_category_sp) {
   TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
 eTypeOptionHideValue,
 "day=${var.__d_%u}")));
+
   AddCXXSummary(cpp_category_sp,
 lldb_private::formatters::LibcxxChronoMonthSummaryProvider,
 "libc++ std::chrono::month summary provider",
@@ -1050,6 +1051,23 @@ static void 
LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
   TypeSummaryImplSP(new StringSummaryFormat(
   eTypeOptionHideChildren | eTypeOptionHideValue, 
"year=${var.__y_}")));
 
+  AddCXXSummary(cpp_category_sp,
+lldb_private::formatters::LibcxxChronoWeekdaySummaryProvider,
+"libc++ std::chrono::weekday summary provider",
+"^std::__[[:alnum:]]+::chrono::weekday$",
+eTypeOptionHideChildren | eTypeOptionHideValue, true);
+
+  cpp_category_sp->AddTypeSummary(
+  "^std::__[[:alnum:]]+::chrono::weekday_indexed$", eFormatterMatchRegex,
+  TypeSummaryImplSP(new StringSummaryFormat(
+  eTypeOptionHideChildren | eTypeOptionHideValue,
+  "${var.__wd_} index=${var.__idx_%u}")));
+
+  cpp_category_sp->AddTypeSummary(
+  "^std::__[[:alnum:]]+::chrono::weekday_last$", eFormatterMatchRegex,
+  TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
+eTypeOptionHideValue,
+"${var.__wd_} index=last")));
   cpp_category_sp->AddTypeSummary(
   "^std::__[[:alnum:]]+::chrono::month_day$", eFormatterMatchRegex,
   TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
@@ -1060,12 +1078,51 @@ static void 
LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
   TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
 eTypeOptionHideValue,
 "${var.__m_} day=last")));
+
+  cpp_category_sp->AddTypeSummary(
+  "^std::__[[:alnum:]]+::chrono::month_weekday$", eFormatterMatchRegex,
+  TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
+eTypeOptionHideValue,
+"${var.__m_} ${var.__wdi_}")));
+
+  cpp_category_sp->AddTypeSummary(
+  "^std::__[[:alnum:]]+::chrono::month_weekday_last$", 
eFormatterMatchRegex,
+  TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
+eTypeOptionHideValue,
+"${var.__m_} ${var.__wdl_}")));
+
+  cpp_category_sp->AddTypeSummary(
+  "^std::__[[:alnum:]]+::chrono::year_month$", eFormatterMatchRegex,
+  TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
+eTypeOptionHideValue,
+"${var.__y_} ${var.__m_}")));
+
   AddCXXSummary(
   cpp_category_sp,
   lldb_private::formatters::LibcxxChronoYearMonthDaySummaryProvider,
   "libc++ std::chrono::year_month_day summary provider",
   "^std::__[[:alnum:]]+::chrono::year_month_day$",
   eTypeOptionHideChildren | eTypeOptionHideValue, true);
+
+  cpp_category_sp->AddTypeSummary(
+

[Lldb-commits] [lldb] [lldb][libc++] Adds missing C++20 calendar data formatters. (PR #77954)

2024-01-13 Thread Mark de Wever via lldb-commits

https://github.com/mordante closed 
https://github.com/llvm/llvm-project/pull/77954
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [llvm] [libcxx] [mlir] [clang-tools-extra] [compiler-rt] [lld] [flang] [clang] [libc++][numeric] P0543R3: Saturation arithmetic (PR #77967)

2024-01-14 Thread Mark de Wever via lldb-commits


@@ -0,0 +1,119 @@
+// -*- C++ -*-
+//===--===//
+//
+// 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
+//
+//===--===//
+
+#ifndef _LIBCPP___NUMERIC_SATURATION_ARITHMETIC_H
+#define _LIBCPP___NUMERIC_SATURATION_ARITHMETIC_H
+
+#include <__concepts/arithmetic.h>
+#include <__config>
+#include <__type_traits/decay.h>
+#include <__utility/cmp.h>
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 26
+
+template 
+concept __libcpp_standard_integer = __libcpp_unsigned_integer> || 
__libcpp_signed_integer>;
+
+template <__libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp add_sat(_Tp __x, _Tp __y) noexcept {
+  if (_Tp __sum; !__builtin_add_overflow(__x, __y, &__sum))

mordante wrote:

I asked both, extend `__builtin_add_overflow` for 128 bit, but typically there 
is a set like
`__builtin_[su]addl{0,2}_overflow` too, I think it would be good to keep that 
pattern from Clang's PoV. Having a new builtin also makes it easy for us to 
query whether `__builtin_add_overflow` has 128-bit support.

https://github.com/llvm/llvm-project/pull/77967
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang] [libcxx] [mlir] [llvm] [lld] [compiler-rt] [clang-tools-extra] [flang] [lldb] [libc++][numeric] P0543R3: Saturation arithmetic (PR #77967)

2024-01-14 Thread Mark de Wever via lldb-commits


@@ -0,0 +1,119 @@
+// -*- C++ -*-
+//===--===//
+//
+// 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
+//
+//===--===//
+
+#ifndef _LIBCPP___NUMERIC_SATURATION_ARITHMETIC_H
+#define _LIBCPP___NUMERIC_SATURATION_ARITHMETIC_H
+
+#include <__concepts/arithmetic.h>
+#include <__config>
+#include <__type_traits/decay.h>
+#include <__utility/cmp.h>
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 26
+
+template 
+concept __libcpp_standard_integer = __libcpp_unsigned_integer> || 
__libcpp_signed_integer>;
+
+template <__libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp add_sat(_Tp __x, _Tp __y) noexcept {
+  if (_Tp __sum; !__builtin_add_overflow(__x, __y, &__sum))
+return __sum;
+  // Handle overflow
+  if constexpr (__libcpp_unsigned_integer<_Tp>) {
+return std::numeric_limits<_Tp>::max();
+  } else {
+// Signed addition overflow
+if (__x > 0)
+  // Overflows if (x > 0 && y > 0)
+  return std::numeric_limits<_Tp>::max();
+else
+  // Overflows if  (x < 0 && y < 0)
+  return std::numeric_limits<_Tp>::min();
+  }
+}
+
+template <__libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp sub_sat(_Tp __x, _Tp __y) noexcept {
+  if (_Tp __sub; !__builtin_sub_overflow(__x, __y, &__sub))
+return __sub;
+  // Handle overflow
+  if constexpr (__libcpp_unsigned_integer<_Tp>) {
+// Overflows if (x < y)
+return std::numeric_limits<_Tp>::min();
+  } else {
+// Signed subtration overflow
+if (__x > 0)
+  // Overflows if (x > 0 && y < 0)
+  return std::numeric_limits<_Tp>::max();
+else
+  // Overflows if (x < 0 && y > 0)
+  return std::numeric_limits<_Tp>::min();
+  }
+}
+
+template <__libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp mul_sat(_Tp __x, _Tp __y) noexcept {
+  if (_Tp __mul; !__builtin_mul_overflow(__x, __y, &__mul))
+return __mul;
+  // Handle overflow
+  if constexpr (__libcpp_unsigned_integer<_Tp>) {
+return std::numeric_limits<_Tp>::max();
+  } else {
+// Signed multiplication overflow
+if (__x > 0) {
+  if (__y > 0)
+// Overflows if (x > 0 && y > 0)
+return std::numeric_limits<_Tp>::max();
+  // Overflows if (x > 0 && y < 0)
+  return std::numeric_limits<_Tp>::min();
+}
+if (__y > 0)
+  // Overflows if (x < 0 && y > 0)
+  return std::numeric_limits<_Tp>::min();
+// Overflows if (x < 0 && y < 0)
+return std::numeric_limits<_Tp>::max();
+  }
+}
+
+template <__libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp div_sat(_Tp __x, _Tp __y) noexcept {
+  _LIBCPP_ASSERT_UNCATEGORIZED(__y != 0, "Division by 0 is undefined");
+  if constexpr (__libcpp_unsigned_integer<_Tp>) {
+return __x / __y;
+  } else {
+// Handle signed division overflow
+if (__x == std::numeric_limits<_Tp>::min() && __y == _Tp{-1})
+  return std::numeric_limits<_Tp>::max();
+return __x / __y;
+  }
+}
+
+template <__libcpp_standard_integer _Rp, __libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Rp saturate_cast(_Tp __x) noexcept {

mordante wrote:

I don't think it's backwards, I'm quite sure we have used `if constexpr` to do 
optimizations. I see it only matters on `-O0`. Maybe add a comment the compiler 
can do this optimization.

https://github.com/llvm/llvm-project/pull/77967
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [libc] [lldb] [libunwind] [libcxx] [clang-tools-extra] [libcxxabi] [llvm] [compiler-rt] [lld] [clang] [flang] [mlir] [libc++][numeric] P0543R3: Saturation arithmetic (PR #77967)

2024-01-16 Thread Mark de Wever via lldb-commits


@@ -0,0 +1,119 @@
+// -*- C++ -*-
+//===--===//
+//
+// 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
+//
+//===--===//
+
+#ifndef _LIBCPP___NUMERIC_SATURATION_ARITHMETIC_H
+#define _LIBCPP___NUMERIC_SATURATION_ARITHMETIC_H
+
+#include <__concepts/arithmetic.h>
+#include <__config>
+#include <__type_traits/decay.h>
+#include <__utility/cmp.h>
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 26
+
+template 
+concept __libcpp_standard_integer = __libcpp_unsigned_integer> || 
__libcpp_signed_integer>;
+
+template <__libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp add_sat(_Tp __x, _Tp __y) noexcept {
+  if (_Tp __sum; !__builtin_add_overflow(__x, __y, &__sum))

mordante wrote:

> `__builtin_add_overflow` already works with 128-bit integers: 
> https://godbolt.org/z/non8eMTfj, as well as bit-precise integers: 
> https://godbolt.org/z/dxs7h4G5b so I'm not certain there are Clang changes 
> needed?

Thanks @AaronBallman there are indeed no changes needed. I just need to learn 
how to read ;-)

https://github.com/llvm/llvm-project/pull/77967
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [libc] [llvm] [lld] [flang] [libcxx] [libunwind] [mlir] [clang] [compiler-rt] [lldb] [libcxxabi] [clang-tools-extra] [libc++][numeric] P0543R3: Saturation arithmetic (PR #77967)

2024-01-16 Thread Mark de Wever via lldb-commits


@@ -0,0 +1,119 @@
+// -*- C++ -*-
+//===--===//
+//
+// 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
+//
+//===--===//
+
+#ifndef _LIBCPP___NUMERIC_SATURATION_ARITHMETIC_H
+#define _LIBCPP___NUMERIC_SATURATION_ARITHMETIC_H
+
+#include <__concepts/arithmetic.h>
+#include <__config>
+#include <__type_traits/decay.h>
+#include <__utility/cmp.h>
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 26
+
+template 
+concept __libcpp_standard_integer = __libcpp_unsigned_integer> || 
__libcpp_signed_integer>;
+
+template <__libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp add_sat(_Tp __x, _Tp __y) noexcept {
+  if (_Tp __sum; !__builtin_add_overflow(__x, __y, &__sum))

mordante wrote:

> You'll probably want to add test coverage for `_BitInt` as well given that 
> it's an extension Clang supports in C++.

I think at the moment we have no support at all for `_BigInt` and `_ExtInt` in 
libc++. Maybe this is something to discuss how to support in general in libc++. 
I expect this to become part of C++ once we "rebase" the Standard on C23.

https://github.com/llvm/llvm-project/pull/77967
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang-tools-extra] [clang] [lldb] [polly] [libcxx] [llvm] [mlir] [compiler-rt] [libunwind] [libc] [libcxxabi] [flang] [libc++][any] LWG3305: `any_cast` (PR #78215)

2024-01-17 Thread Mark de Wever via lldb-commits

mordante wrote:

> > I see you implemented this code only for C++26. In general we retroactively 
> > apply LWG issues to all previous standard versions. Is there a reason why 
> > you only applied this to C++26?
> 
> I am not familiar with this process. I'm happy to do what's needed to be 
> done. So I assume I need to remove the version guards and test against the 
> original implementation?

Yes that is the general rule for LWG-issues. The other implementations handle 
them in the same fashion.

https://github.com/llvm/llvm-project/pull/78215
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang-tools-extra] [lldb] [libc] [llvm] [clang] [libcxxabi] [libunwind] [libcxx] [flang] [compiler-rt] [libc++][span] P2447R4: `std::span` over an initializer list (PR #78157)

2024-01-18 Thread Mark de Wever via lldb-commits

https://github.com/mordante approved this pull request.

> Thanks. The documentation build fails due to some CMake error consistently 
> otherwise I believe I addressed all comments.
I think I fixed this a few days ago.

LGTM modulo 1 nit.



https://github.com/llvm/llvm-project/pull/78157
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [libunwind] [libcxxabi] [llvm] [flang] [libc] [libcxx] [lldb] [clang] [clang-tools-extra] [compiler-rt] [libc++][span] P2447R4: `std::span` over an initializer list (PR #78157)

2024-01-18 Thread Mark de Wever via lldb-commits

https://github.com/mordante edited 
https://github.com/llvm/llvm-project/pull/78157
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [libc] [compiler-rt] [libcxxabi] [lldb] [llvm] [clang] [flang] [clang-tools-extra] [libunwind] [libcxx] [libc++][span] P2447R4: `std::span` over an initializer list (PR #78157)

2024-01-18 Thread Mark de Wever via lldb-commits


@@ -0,0 +1,38 @@
+//===--===//
+//
+// 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, c++17, c++20, c++23
+
+// REQUIRES: has-unix-headers
+// REQUIRES: libcpp-hardening-mode={{extensive|debug}}
+// XFAIL: availability-verbose_abort-missing
+
+// 
+
+// constexpr explicit(extent != dynamic_extent) 
span(std::initializer_list il); // Since C++26
+
+#include 
+#include 
+#include 
+
+#include "check_assertion.h"
+
+bool test() {
+  TEST_LIBCPP_ASSERT_FAILURE(
+  (std::span({1, 2, 3, 9084, 5})), "Size mismatch in span's 
constructor _Extent != __il.size().");
+  TEST_LIBCPP_ASSERT_FAILURE((std::span(std::initializer_list{1, 2, 3, 9084, 5})),
+ "Size mismatch in span's constructor _Extent != 
__il.size().");
+
+  return true;
+}
+
+int main(int, char**) {
+  assert(test());

mordante wrote:

We typically don't do this for run-time tests. We do it for compile-time tests 
so we can use `static_assert`s. In this case I would remove the `test` function 
and move the test code in `main`.

I overlooked this in the previous review.

https://github.com/llvm/llvm-project/pull/78157
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang] [llvm] [libcxx] [flang] [lldb] [libcxxabi] [libunwind] [compiler-rt] [libc] [clang-tools-extra] [libc++][span] P2447R4: `std::span` over an initializer list (PR #78157)

2024-01-18 Thread Mark de Wever via lldb-commits


@@ -5,39 +5,134 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 
//===--===//
+
 // UNSUPPORTED: c++03, c++11, c++14, c++17
 
 // 
 
-#include 
+// constexpr explicit(extent != dynamic_extent) 
span(std::initializer_list il); // Since C++26
+
+#include 
 #include 
 #include 
+#include 
+#include 
+#include 
+
+#include "test_convertible.h"
+#include "test_macros.h"
+
+#if TEST_STD_VER >= 26
+
+// SFINAE
+
+template 
+concept ConstElementType = std::is_const_v;
+
+static_assert(ConstElementType>);
+static_assert(!ConstElementType>);
+static_assert(ConstElementType>);
+static_assert(!ConstElementType>);
+
+// Constructor constraings
+
+template 
+concept HasInitializerListCtr = requires(I il) { std::span{il}; };
+
+static_assert(HasInitializerListCtr, const 
int>);
+static_assert(!HasInitializerListCtr, int>);
+static_assert(HasInitializerListCtr, const 
int, 94>);
+static_assert(!HasInitializerListCtr, int, 94>);
+
+// Constructor conditionally explicit
+
+static_assert(!test_convertible, 
std::initializer_list>(),
+  "This constructor must be explicit");
+static_assert(std::is_constructible_v, 
std::initializer_list>);
+static_assert(test_convertible, 
std::initializer_list>(),
+  "This constructor must not be explicit");
+static_assert(std::is_constructible_v, 
std::initializer_list>);
+
+#endif
 
 struct Sink {
-constexpr Sink() = default;
-constexpr Sink(Sink*) {}
+  constexpr Sink() = default;
+  constexpr Sink(Sink*) {}
 };
 
-constexpr std::size_t count(std::span sp) {
-return sp.size();
-}
+constexpr std::size_t count(std::span sp) { return sp.size(); }
 
-template
-constexpr std::size_t countn(std::span sp) {
-return sp.size();
+template 
+constexpr std::size_t count_n(std::span sp) {
+  return sp.size();
 }
 
 constexpr bool test() {
+#if TEST_STD_VER >= 26
+  // Dynamic extent
+  {
+Sink a[10];
+
+assert(count({a}) == 1);
+assert(count({a, a + 10}) == 2);
+assert(count({a, a + 1, a + 2}) == 3);
+assert(count(std::initializer_list{a[0], a[1], a[2], a[3]}) == 4);
+  }
+#else
+  {
 Sink a[10];
+
 assert(count({a}) == 10);
-assert(count({a, a+10}) == 10);
-assert(countn<10>({a}) == 10);
-return true;
+assert(count({a, a + 10}) == 10);
+assert(count_n<10>({a}) == 10);
+  }
+#endif
+
+  return true;
+}
+
+// Test P2447R4 "Annex C examples"
+
+constexpr int three(std::span sp) { return sp.size(); }
+
+constexpr int four(std::span sp) { return sp.size(); }
+
+bool test_P2447R4_annex_c_examples() {
+  // 1. Overload resolution is affected
+  // --> tested in "initializer_list.verify.cpp"
+
+  // 2. The `initializer_list` ctor has high precedence
+  // --> tested in "initializer_list.verify.cpp"
+
+  // 3. Implicit two-argument construction with a highly convertible value_type

mordante wrote:

nice! thanks for referring to the other test too!

https://github.com/llvm/llvm-project/pull/78157
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [flang] [llvm] [libcxx] [libunwind] [lld] [clang] [mlir] [libc] [clang-tools-extra] [compiler-rt] [lldb] [libcxxabi] [openmp] [polly] [libc++][numeric] P0543R3: Saturation arithmetic (P

2024-01-18 Thread Mark de Wever via lldb-commits

https://github.com/mordante requested changes to this pull request.

Thanks I think this is getting close, I would like to see it again after 
addressing the comments.

https://github.com/llvm/llvm-project/pull/77967
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang-tools-extra] [lldb] [compiler-rt] [mlir] [libcxx] [openmp] [llvm] [libcxxabi] [lld] [clang] [libc] [libunwind] [polly] [flang] [libc++][numeric] P0543R3: Saturation arithmetic (P

2024-01-18 Thread Mark de Wever via lldb-commits


@@ -0,0 +1,75 @@
+//===--===//
+//
+// 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, c++17, c++20, c++23
+
+// 
+
+// template
+// constexpr T add_sat(T x, T y) noexcept; // freestanding
+
+#include 
+#include 
+
+template 
+concept CanDo = requires(T x, U y) {
+  { std::add_sat(x, y) } -> std::same_as;
+};
+
+template 
+constexpr void test_constraint_success() {
+  static_assert(CanDo);
+  static_assert(!CanDo);
+  static_assert(!CanDo);
+}
+
+template 
+constexpr void test_constraint_fail() {
+  using I = int;
+  static_assert(!CanDo);
+  static_assert(!CanDo);
+  static_assert(!CanDo);
+}
+
+constexpr void test() {
+  // Contraint success - Signed
+  using SI = long long int;
+  test_constraint_success();
+  test_constraint_success();
+  test_constraint_success();
+  test_constraint_success();
+  test_constraint_success();
+  test_constraint_success();
+  test_constraint_success();
+#ifndef _LIBCPP_HAS_NO_INT128

mordante wrote:

```suggestion
#ifndef TEST_HAS_NO_INT128
```
In general we do not use libc++ internal macros. Our test suite is used by MSVC 
STL too to test their implementation. The `TEST_x` macros work for them. the 
`_LIBCPP_x` not. The exception is that you can use
`_LIBCPP_VERSION` if you want to test the library under test is libc++.

https://github.com/llvm/llvm-project/pull/77967
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lld] [lldb] [polly] [flang] [llvm] [libunwind] [mlir] [clang-tools-extra] [libc] [openmp] [libcxxabi] [clang] [compiler-rt] [libcxx] [libc++][numeric] P0543R3: Saturation arithmetic (P

2024-01-18 Thread Mark de Wever via lldb-commits


@@ -0,0 +1,76 @@
+//===--===//
+//
+// 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, c++17, c++20, c++23
+
+// 
+
+// template
+//   constexpr R saturate_cast(T x) noexcept;// 
freestanding
+
+#include 
+#include 
+
+template 
+concept CanDo = requires(T x) {
+  { std::saturate_cast(x) } -> std::same_as;
+};
+
+template 
+constexpr void test_constraint_success() {
+  static_assert(CanDo);

mordante wrote:

```suggestion
  static_assert(CanDo);
  static_assert(CanDo);
```

https://github.com/llvm/llvm-project/pull/77967
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [libc] [polly] [openmp] [clang-tools-extra] [compiler-rt] [libunwind] [flang] [lldb] [clang] [libcxx] [mlir] [lld] [llvm] [libcxxabi] [libc++][numeric] P0543R3: Saturation arithmetic (P

2024-01-18 Thread Mark de Wever via lldb-commits

https://github.com/mordante edited 
https://github.com/llvm/llvm-project/pull/77967
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang-tools-extra] [libcxxabi] [lld] [clang] [libc] [libcxx] [lldb] [polly] [libunwind] [flang] [openmp] [mlir] [llvm] [compiler-rt] [libc++][numeric] P0543R3: Saturation arithmetic (P

2024-01-18 Thread Mark de Wever via lldb-commits


@@ -0,0 +1,157 @@
+//===--===//
+//
+// 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, c++17, c++20, c++23
+
+// 
+
+// template
+//   constexpr R saturate_cast(T x) noexcept; // 
freestanding
+
+#include 
+#include 
+#include 
+#include 
+
+template 

mordante wrote:

I'm not fond of this test. IMO it's a bit too smart and it makes it hard to 
understand what is tested.
What I often do for these kind of tests is something like
```
assert(std::saturate_cast(-255) == -128);
assert(std::saturate_cast(-128) == -128);
assert(std::saturate_cast(0) == 0);
assert(std::saturate_cast(127) == 127);
assert(std::saturate_cast(255) == 127);
```

and similar for other conversions. I think that is easier to follow. (Note I 
like the add, sub, mul, and div test.)


https://github.com/llvm/llvm-project/pull/77967
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang-tools-extra] [libcxxabi] [mlir] [clang] [polly] [openmp] [lldb] [flang] [libunwind] [compiler-rt] [libc] [llvm] [lld] [libcxx] [libc++][numeric] P0543R3: Saturation arithmetic (P

2024-01-18 Thread Mark de Wever via lldb-commits


@@ -0,0 +1,281 @@
+//===--===//
+//
+// 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, c++17, c++20, c++23
+
+// 
+
+// template
+// constexpr T add_sat(T x, T y) noexcept; // freestanding
+
+#include 
+#include 
+#include 
+#include 
+
+template 
+constexpr bool test_signed() {
+  constexpr auto minVal = std::numeric_limits::min();
+  constexpr auto maxVal = std::numeric_limits::max();
+
+  static_assert(noexcept(std::div_sat(minVal, maxVal)));
+
+  // No saturation (-1, 0, 1)
+  {
+std::same_as decltype(auto) sum = std::add_sat(IntegerT{0}, 
IntegerT{0});
+assert(sum == IntegerT{0});
+  }
+
+  {
+std::same_as decltype(auto) sum = std::add_sat(IntegerT{0}, 
IntegerT{1});
+assert(sum == IntegerT{1});
+  }
+
+  {
+std::same_as decltype(auto) sum = std::add_sat(IntegerT{1}, 
IntegerT{0});
+assert(sum == IntegerT{1});
+  }
+
+  {
+std::same_as decltype(auto) sum = std::add_sat(IntegerT{0}, 
IntegerT{-1});
+assert(sum == IntegerT{-1});
+  }
+
+  {
+std::same_as decltype(auto) sum = std::add_sat(IntegerT{-1}, 
IntegerT{0});
+assert(sum == IntegerT{-1});
+  }
+
+  {
+std::same_as decltype(auto) sum = std::add_sat(IntegerT{1}, 
IntegerT{1});
+assert(sum == IntegerT{2});
+  }
+
+  {
+std::same_as decltype(auto) sum = std::add_sat(IntegerT{1}, 
IntegerT{-1});
+assert(sum == IntegerT{0});
+  }
+
+  {
+std::same_as decltype(auto) sum = std::add_sat(IntegerT{-1}, 
IntegerT{1});
+assert(sum == IntegerT{0});
+  }
+
+  {
+std::same_as decltype(auto) sum = std::add_sat(IntegerT{-1}, 
IntegerT{-1});
+assert(sum == IntegerT{-2});
+  }
+
+  // No saturation (any value)
+
+  {
+std::same_as decltype(auto) sum = std::add_sat(IntegerT{27}, 
IntegerT{28});
+assert(sum == IntegerT{55});
+  }
+
+  {
+std::same_as decltype(auto) sum = std::add_sat(IntegerT{-27}, 
IntegerT{28});
+assert(sum == IntegerT{1});
+  }
+
+  // No saturation (min, -1, 0, 1, max)
+
+  {
+std::same_as decltype(auto) sum = std::add_sat(minVal, 
IntegerT{0});
+assert(sum == minVal);
+  }
+
+  {
+std::same_as decltype(auto) sum = std::add_sat(minVal, 
IntegerT{1});
+assert(sum == minVal + IntegerT{1});
+  }
+
+  {
+std::same_as decltype(auto) sum = std::add_sat(maxVal, 
IntegerT{0});
+assert(sum == maxVal);
+  }
+
+  {
+std::same_as decltype(auto) sum = std::add_sat(maxVal, 
IntegerT{-1});
+assert(sum == maxVal + IntegerT{-1});
+  }
+
+  {
+std::same_as decltype(auto) sum = std::add_sat(minVal, maxVal);
+assert(sum == IntegerT{-1});
+  }
+
+  {
+std::same_as decltype(auto) sum = std::add_sat(maxVal, minVal);
+assert(sum == IntegerT{-1});
+  }
+
+  // Saturation - max - both arguments positive
+  {
+std::same_as decltype(auto) sum = std::add_sat(maxVal, 
IntegerT{27});
+assert(sum == maxVal);
+  }
+
+  {
+// Large values
+constexpr IntegerT x = maxVal / IntegerT{2} + IntegerT{27};
+constexpr IntegerT y = maxVal / IntegerT{2} + IntegerT{28};
+
+std::same_as decltype(auto) sum = std::add_sat(x, y);
+assert(sum == maxVal);
+  }
+
+  {
+std::same_as decltype(auto) sum = std::add_sat(maxVal, maxVal);
+assert(sum == maxVal);
+  }
+
+  // Saturation - min - both arguments negative
+  {
+// Large values
+constexpr IntegerT x = minVal / IntegerT{2} + IntegerT{-27};
+constexpr IntegerT y = minVal / IntegerT{2} + IntegerT{-28};
+
+std::same_as decltype(auto) sum = std::add_sat(x, y);
+assert(sum == minVal);
+  }
+
+  {
+std::same_as decltype(auto) sum = std::add_sat(minVal, minVal);
+assert(sum == minVal);
+  }
+
+  return true;
+}
+
+template 
+constexpr bool test_unsigned() {
+  constexpr auto minVal = std::numeric_limits::min();
+  constexpr auto maxVal = std::numeric_limits::max();
+
+  static_assert(noexcept(std::div_sat(minVal, maxVal)));
+
+  // No Saturation
+
+  {
+std::same_as decltype(auto) sum = std::add_sat(IntegerT{0}, 
IntegerT{0});
+assert(sum == IntegerT{0});
+  }
+
+  {
+std::same_as decltype(auto) sum = std::add_sat(IntegerT{0}, 
IntegerT{1});
+assert(sum == IntegerT{1});
+  }
+
+  {
+std::same_as decltype(auto) sum = std::add_sat(IntegerT{1}, 
IntegerT{0});
+assert(sum == IntegerT{1});
+  }
+
+  {
+std::same_as decltype(auto) sum = std::add_sat(IntegerT{1}, 
IntegerT{1});
+assert(sum == IntegerT{2});
+  }
+
+  {
+std::same_as decltype(auto) sum = std::add_sat(minVal, 
IntegerT{0});
+assert(sum == IntegerT{0});
+  }
+
+  {
+std::same_as decltype(auto) sum = std::add_sat(minVal, 
IntegerT{1});
+assert(sum == IntegerT{1});
+  }
+
+  {

[Lldb-commits] [mlir] [lld] [openmp] [polly] [flang] [llvm] [lldb] [clang] [clang-tools-extra] [libcxxabi] [libc] [libunwind] [compiler-rt] [libcxx] [libc++][numeric] P0543R3: Saturation arithmetic (P

2024-01-18 Thread Mark de Wever via lldb-commits


@@ -0,0 +1,267 @@
+//===--===//
+//
+// 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, c++17, c++20, c++23
+
+// 
+
+// template
+// constexpr T div_sat(T x, T y) noexcept; // freestanding
+
+#include 
+#include 
+#include 
+#include 
+
+template 
+constexpr bool test_signed() {
+  constexpr auto minVal = std::numeric_limits::min();
+  constexpr auto maxVal = std::numeric_limits::max();
+
+  static_assert(noexcept(std::div_sat(minVal, maxVal)));
+
+  // No saturation
+  {
+std::same_as decltype(auto) quot = std::div_sat(IntegerT{-1}, 
IntegerT{-1});
+assert(quot == IntegerT{1});
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(IntegerT{-1}, 
IntegerT{1});
+assert(quot == IntegerT{-1});
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(IntegerT{-1}, 
minVal);
+assert(quot == IntegerT{0});
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(IntegerT{-1}, 
maxVal);
+assert(quot == IntegerT{0});
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(maxVal, 
IntegerT{-1});
+assert(quot == IntegerT{-1} * maxVal);
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(IntegerT{0}, 
IntegerT{-1});
+assert(quot == IntegerT{0});
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(IntegerT{0}, 
IntegerT{1});
+assert(quot == IntegerT{0});
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(IntegerT{0}, 
minVal);
+assert(quot == IntegerT{0});
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(IntegerT{1}, 
IntegerT{-1});
+assert(quot == IntegerT{-1});
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(IntegerT{1}, 
minVal);
+assert(quot == IntegerT{0});
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(IntegerT{1}, 
maxVal);
+assert(quot == IntegerT{0});
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(minVal, 
IntegerT{1});
+assert(quot == minVal);
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(maxVal, 
IntegerT{1});
+assert(quot == maxVal);
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(IntegerT{27}, 
IntegerT{28});
+assert(quot == IntegerT{0});
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(IntegerT{28}, 
IntegerT{27});
+assert(quot == IntegerT{1});
+  }
+
+  {
+// Large values
+constexpr IntegerT x = minVal / IntegerT{2} + IntegerT{-27};
+constexpr IntegerT y = maxVal / IntegerT{2} + IntegerT{28};
+
+std::same_as decltype(auto) sum = std::div_sat(x, y);

mordante wrote:

I see quite a bit of copy paste with `sum`. That should be `quot`, or not use a 
temporary value.

https://github.com/llvm/llvm-project/pull/77967
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang-tools-extra] [lld] [libcxxabi] [lldb] [libunwind] [llvm] [libcxx] [openmp] [libc] [clang] [mlir] [flang] [polly] [compiler-rt] [libc++][numeric] P0543R3: Saturation arithmetic (P

2024-01-18 Thread Mark de Wever via lldb-commits


@@ -0,0 +1,267 @@
+//===--===//
+//
+// 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, c++17, c++20, c++23
+
+// 
+
+// template
+// constexpr T div_sat(T x, T y) noexcept; // freestanding
+
+#include 
+#include 
+#include 
+#include 
+
+template 
+constexpr bool test_signed() {
+  constexpr auto minVal = std::numeric_limits::min();
+  constexpr auto maxVal = std::numeric_limits::max();
+
+  static_assert(noexcept(std::div_sat(minVal, maxVal)));
+
+  // No saturation
+  {
+std::same_as decltype(auto) quot = std::div_sat(IntegerT{-1}, 
IntegerT{-1});
+assert(quot == IntegerT{1});
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(IntegerT{-1}, 
IntegerT{1});
+assert(quot == IntegerT{-1});
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(IntegerT{-1}, 
minVal);
+assert(quot == IntegerT{0});
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(IntegerT{-1}, 
maxVal);
+assert(quot == IntegerT{0});
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(maxVal, 
IntegerT{-1});
+assert(quot == IntegerT{-1} * maxVal);
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(IntegerT{0}, 
IntegerT{-1});
+assert(quot == IntegerT{0});
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(IntegerT{0}, 
IntegerT{1});
+assert(quot == IntegerT{0});
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(IntegerT{0}, 
minVal);
+assert(quot == IntegerT{0});
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(IntegerT{1}, 
IntegerT{-1});
+assert(quot == IntegerT{-1});
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(IntegerT{1}, 
minVal);
+assert(quot == IntegerT{0});
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(IntegerT{1}, 
maxVal);
+assert(quot == IntegerT{0});
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(minVal, 
IntegerT{1});
+assert(quot == minVal);
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(maxVal, 
IntegerT{1});
+assert(quot == maxVal);
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(IntegerT{27}, 
IntegerT{28});
+assert(quot == IntegerT{0});
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(IntegerT{28}, 
IntegerT{27});
+assert(quot == IntegerT{1});
+  }
+
+  {
+// Large values
+constexpr IntegerT x = minVal / IntegerT{2} + IntegerT{-27};
+constexpr IntegerT y = maxVal / IntegerT{2} + IntegerT{28};
+
+std::same_as decltype(auto) sum = std::div_sat(x, y);
+assert(sum == IntegerT{-1});
+  }
+
+  {
+// Large values
+constexpr IntegerT x = maxVal / IntegerT{2} + IntegerT{28};
+constexpr IntegerT y = minVal / IntegerT{2} + IntegerT{-27};
+
+std::same_as decltype(auto) sum = std::div_sat(x, y);
+assert(sum == IntegerT{-1});
+  }
+
+  {
+// Large values
+constexpr IntegerT x = minVal / IntegerT{2} + IntegerT{-27};
+constexpr IntegerT y = minVal / IntegerT{2} + IntegerT{-28};
+
+std::same_as decltype(auto) sum = std::div_sat(x, y);
+assert(sum == IntegerT{0});
+  }
+
+  {
+// Large values
+constexpr IntegerT x = minVal / IntegerT{2} + IntegerT{-28};
+constexpr IntegerT y = minVal / IntegerT{2} + IntegerT{-27};
+
+std::same_as decltype(auto) sum = std::div_sat(x, y);
+assert(sum == IntegerT{1});
+  }
+
+  {
+// Large values
+constexpr IntegerT x = maxVal / IntegerT{2} + IntegerT{27};
+constexpr IntegerT y = maxVal / IntegerT{2} + IntegerT{28};
+
+std::same_as decltype(auto) sum = std::div_sat(x, y);
+assert(sum == IntegerT{0});
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(maxVal, minVal);
+assert(quot == (maxVal / minVal));
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(minVal, maxVal);
+assert(quot == (minVal / maxVal));
+  }
+
+  // Saturation - max only
+  {
+std::same_as decltype(auto) quot = std::div_sat(minVal, 
IntegerT{-1});
+assert(quot == maxVal);
+  }
+
+  return true;
+}
+
+template 
+constexpr bool test_unsigned() {
+  constexpr auto minVal = std::numeric_limits::min();
+  constexpr auto maxVal = std::numeric_limits::max();
+
+  static_assert(noexcept(std::div_sat(minVal, maxVal)));
+
+  // No saturation
+  {
+std::same_as decltype(auto) quot = std::div_sat(IntegerT{0}, 
IntegerT{1});
+assert(quot == IntegerT{0});
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(IntegerT{0}, 
maxVal);
+assert(quot == IntegerT{0});
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(IntegerT{1}, 

[Lldb-commits] [libcxxabi] [clang-tools-extra] [libunwind] [openmp] [lldb] [mlir] [flang] [libcxx] [lld] [libc] [compiler-rt] [polly] [llvm] [clang] [libc++][numeric] P0543R3: Saturation arithmetic (P

2024-01-18 Thread Mark de Wever via lldb-commits


@@ -0,0 +1,119 @@
+// -*- C++ -*-
+//===--===//
+//
+// 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
+//
+//===--===//
+
+#ifndef _LIBCPP___NUMERIC_SATURATION_ARITHMETIC_H
+#define _LIBCPP___NUMERIC_SATURATION_ARITHMETIC_H
+
+#include <__concepts/arithmetic.h>
+#include <__config>
+#include <__type_traits/decay.h>
+#include <__utility/cmp.h>
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 26
+
+template 
+concept __libcpp_standard_integer = __libcpp_unsigned_integer> || 
__libcpp_signed_integer>;
+
+template <__libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp add_sat(_Tp __x, _Tp __y) noexcept {
+  if (_Tp __sum; !__builtin_add_overflow(__x, __y, &__sum))
+return __sum;
+  // Handle overflow
+  if constexpr (__libcpp_unsigned_integer<_Tp>) {
+return std::numeric_limits<_Tp>::max();
+  } else {
+// Signed addition overflow
+if (__x > 0)
+  // Overflows if (x > 0 && y > 0)
+  return std::numeric_limits<_Tp>::max();
+else
+  // Overflows if  (x < 0 && y < 0)
+  return std::numeric_limits<_Tp>::min();
+  }
+}
+
+template <__libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp sub_sat(_Tp __x, _Tp __y) noexcept {
+  if (_Tp __sub; !__builtin_sub_overflow(__x, __y, &__sub))
+return __sub;
+  // Handle overflow
+  if constexpr (__libcpp_unsigned_integer<_Tp>) {
+// Overflows if (x < y)
+return std::numeric_limits<_Tp>::min();
+  } else {
+// Signed subtration overflow
+if (__x > 0)
+  // Overflows if (x > 0 && y < 0)
+  return std::numeric_limits<_Tp>::max();
+else
+  // Overflows if (x < 0 && y > 0)
+  return std::numeric_limits<_Tp>::min();
+  }
+}
+
+template <__libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp mul_sat(_Tp __x, _Tp __y) noexcept {
+  if (_Tp __mul; !__builtin_mul_overflow(__x, __y, &__mul))
+return __mul;
+  // Handle overflow
+  if constexpr (__libcpp_unsigned_integer<_Tp>) {
+return std::numeric_limits<_Tp>::max();
+  } else {
+// Signed multiplication overflow
+if (__x > 0) {
+  if (__y > 0)
+// Overflows if (x > 0 && y > 0)
+return std::numeric_limits<_Tp>::max();
+  // Overflows if (x > 0 && y < 0)
+  return std::numeric_limits<_Tp>::min();
+}
+if (__y > 0)
+  // Overflows if (x < 0 && y > 0)
+  return std::numeric_limits<_Tp>::min();
+// Overflows if (x < 0 && y < 0)
+return std::numeric_limits<_Tp>::max();
+  }
+}
+
+template <__libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp div_sat(_Tp __x, _Tp __y) noexcept {
+  _LIBCPP_ASSERT_UNCATEGORIZED(__y != 0, "Division by 0 is undefined");
+  if constexpr (__libcpp_unsigned_integer<_Tp>) {
+return __x / __y;
+  } else {
+// Handle signed division overflow
+if (__x == std::numeric_limits<_Tp>::min() && __y == _Tp{-1})
+  return std::numeric_limits<_Tp>::max();
+return __x / __y;
+  }
+}
+
+template <__libcpp_standard_integer _Rp, __libcpp_standard_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Rp saturate_cast(_Tp __x) noexcept {

mordante wrote:

In the past I had seem improvements with `if constexpr` in these cases. But it 
seems compilers got better.
I'm happy to have slightly less optimizations with -O0.

https://github.com/llvm/llvm-project/pull/77967
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [libunwind] [flang] [mlir] [openmp] [clang-tools-extra] [lldb] [polly] [compiler-rt] [clang] [lld] [llvm] [libcxx] [libc] [libcxxabi] [libc++][numeric] P0543R3: Saturation arithmetic (P

2024-01-18 Thread Mark de Wever via lldb-commits


@@ -0,0 +1,281 @@
+//===--===//
+//
+// 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, c++17, c++20, c++23
+
+// 
+
+// template
+// constexpr T add_sat(T x, T y) noexcept; // freestanding
+
+#include 
+#include 
+#include 
+#include 
+
+template 
+constexpr bool test_signed() {
+  constexpr auto minVal = std::numeric_limits::min();
+  constexpr auto maxVal = std::numeric_limits::max();
+
+  static_assert(noexcept(std::div_sat(minVal, maxVal)));
+
+  // No saturation (-1, 0, 1)
+  {
+std::same_as decltype(auto) sum = std::add_sat(IntegerT{0}, 
IntegerT{0});

mordante wrote:

How about testing the result type once and then directly assert the result. 
Something like
```
  std::same_as decltype(auto) sum = std::add_sat(IntegerT{0}, 
IntegerT{0});
  assert(sum == IntegerT{0});

  assert(std::add_sat(IntegerT{1}, IntegerT{0}) == IntegerT{1});
  assert(std::add_sat(IntegerT{1}, IntegerT{1}) == IntegerT{0});
  assert(std::add_sat(IntegerT{1}, IntegerT{0}) == IntegerT{-1});
  assert(std::add_sat(IntegerT{1}, IntegerT{-1}) == IntegerT{0});
  assert(std::add_sat(IntegerT{1}, IntegerT{1}) == IntegerT{1});
  ...
```
Currently every test entry is 5 lines, which makes the test quite long. (I'm 
not against long tests in general, but here the test density is a bit low.)

https://github.com/llvm/llvm-project/pull/77967
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang] [llvm] [mlir] [libc] [openmp] [libcxx] [polly] [compiler-rt] [lldb] [flang] [clang-tools-extra] [libunwind] [libcxxabi] [lld] [libc++][numeric] P0543R3: Saturation arithmetic (P

2024-01-18 Thread Mark de Wever via lldb-commits


@@ -0,0 +1,267 @@
+//===--===//
+//
+// 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, c++17, c++20, c++23
+
+// 
+
+// template
+// constexpr T div_sat(T x, T y) noexcept; // freestanding
+
+#include 
+#include 
+#include 
+#include 
+
+template 
+constexpr bool test_signed() {
+  constexpr auto minVal = std::numeric_limits::min();
+  constexpr auto maxVal = std::numeric_limits::max();
+
+  static_assert(noexcept(std::div_sat(minVal, maxVal)));
+
+  // No saturation
+  {
+std::same_as decltype(auto) quot = std::div_sat(IntegerT{-1}, 
IntegerT{-1});
+assert(quot == IntegerT{1});
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(IntegerT{-1}, 
IntegerT{1});
+assert(quot == IntegerT{-1});
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(IntegerT{-1}, 
minVal);
+assert(quot == IntegerT{0});
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(IntegerT{-1}, 
maxVal);
+assert(quot == IntegerT{0});
+  }
+
+  {
+std::same_as decltype(auto) quot = std::div_sat(maxVal, 
IntegerT{-1});
+assert(quot == IntegerT{-1} * maxVal);
+  }

mordante wrote:

why not `-maxVal`? 

https://github.com/llvm/llvm-project/pull/77967
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [polly] [clang-tools-extra] [libc] [libcxxabi] [lld] [libunwind] [flang] [mlir] [llvm] [compiler-rt] [libcxx] [clang] [openmp] [lldb] [libc++][numeric] P0543R3: Saturation arithmetic (P

2024-01-18 Thread Mark de Wever via lldb-commits


@@ -0,0 +1,281 @@
+//===--===//
+//
+// 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, c++17, c++20, c++23
+
+// 
+
+// template
+// constexpr T add_sat(T x, T y) noexcept; // freestanding
+
+#include 
+#include 
+#include 
+#include 
+
+template 
+constexpr bool test_signed() {
+  constexpr auto minVal = std::numeric_limits::min();
+  constexpr auto maxVal = std::numeric_limits::max();
+
+  static_assert(noexcept(std::div_sat(minVal, maxVal)));

mordante wrote:

```suggestion
  static_assert(noexcept(std::add_sat(minVal, maxVal)));
```
please check all noexcept test for the copy paste issue.

https://github.com/llvm/llvm-project/pull/77967
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][libc++] Adds system_clock data formatters. (PR #78609)

2024-01-18 Thread Mark de Wever via lldb-commits

https://github.com/mordante created 
https://github.com/llvm/llvm-project/pull/78609

None

>From 31a7604f872116521558dcb9f1b4c2c4f5f9d439 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Thu, 18 Jan 2024 19:21:09 +0100
Subject: [PATCH] [lldb][libc++] Adds system_clock data formatters.

---
 .../Language/CPlusPlus/CPlusPlusLanguage.cpp  |  25 +
 .../Plugins/Language/CPlusPlus/LibCxx.cpp |  65 +++-
 .../Plugins/Language/CPlusPlus/LibCxx.h   |   8 ++
 .../chrono/TestDataFormatterLibcxxChrono.py   | 100 ++
 .../data-formatter-stl/libcxx/chrono/main.cpp |  52 +
 5 files changed, 248 insertions(+), 2 deletions(-)

diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
index 21c73e6361904e..f0fe6c9e06d9d4 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -1032,6 +1032,31 @@ static void 
LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
   TypeSummaryImplSP(new StringSummaryFormat(
   eTypeOptionHideChildren | eTypeOptionHideValue, "${var.__rep_} s")));
 
+  // Chrono time point types
+
+  AddCXXSummary(cpp_category_sp,
+
lldb_private::formatters::LibcxxChronoSysSecondsSummaryProvider,
+"libc++ std::chrono::sys_seconds summary provider",
+"^std::__[[:alnum:]]+::chrono::time_point<"
+"std::__[[:alnum:]]+::chrono::system_clock, "
+"std::__[[:alnum:]]+::chrono::duration "
+"> >$",
+eTypeOptionHideChildren | eTypeOptionHideValue |
+eTypeOptionCascade,
+true);
+  AddCXXSummary(cpp_category_sp,
+lldb_private::formatters::LibcxxChronoSysDaysSummaryProvider,
+"libc++ std::chrono::sys_seconds summary provider",
+"^std::__[[:alnum:]]+::chrono::time_point<"
+"std::__[[:alnum:]]+::chrono::system_clock, "
+"std::__[[:alnum:]]+::chrono::duration "
+"> >$",
+eTypeOptionHideChildren | eTypeOptionHideValue |
+eTypeOptionCascade,
+true);
+
   // Chrono calendar types
 
   cpp_category_sp->AddTypeSummary(
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
index d232a38adc029a..042e2262696998 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
@@ -1073,18 +1073,79 @@ bool 
lldb_private::formatters::LibcxxWStringViewSummaryProvider(
   bool success;
   ValueObjectSP dataobj;
   size_t size;
-  std::tie( success, dataobj, size ) = LibcxxExtractStringViewData(valobj);
+  std::tie(success, dataobj, size) = LibcxxExtractStringViewData(valobj);
 
   if (!success) {
 stream << "Summary Unavailable";
 return true;
   }
 
-
   return ::LibcxxWStringSummaryProvider(valobj, stream, summary_options,
 dataobj, size);
 }
 
+bool lldb_private::formatters::LibcxxChronoSysSecondsSummaryProvider(
+ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
+  ValueObjectSP ptr_sp = valobj.GetChildMemberWithName("__d_");
+  if (!ptr_sp)
+return false;
+  ptr_sp = ptr_sp->GetChildMemberWithName("__rep_");
+  if (!ptr_sp)
+return false;
+
+  // The date time in the chrono library is valid in the range
+  // [-32767-01-01T00:00:00Z, 32767-12-31T23:59:59Z]. A 64-bit time_t has a
+  // larger range, the function strftime is not able to format the entire range
+  // of time_t. The exact point has not been investigated; it's limited to
+  // chrono's range.
+  const std::time_t chrono_timestamp_min =
+  -1'096'193'779'200; // -32767-01-01T00:00:00Z
+  const std::time_t chrono_timestamp_max =
+  971'890'963'199; // 32767-12-31T23:59:59Z
+
+  const std::time_t seconds = ptr_sp->GetValueAsSigned(0);
+  if (seconds < chrono_timestamp_min || seconds > chrono_timestamp_max)
+stream.Printf("timestamp=%ld s", seconds);
+  else {
+std::array str;
+std::strftime(str.data(), str.size(), "%FT%H:%M:%SZ", gmtime(&seconds));
+stream.Printf("date/time=%s timestamp=%ld s", str.data(), seconds);
+  }
+
+  return true;
+}
+
+bool lldb_private::formatters::LibcxxChronoSysDaysSummaryProvider(
+ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
+  ValueObjectSP ptr_sp = valobj.GetChildMemberWithName("__d_");
+  if (!ptr_sp)
+return false;
+  ptr_sp = ptr_sp->GetChildMemberWithName("__rep_");
+  if (!ptr_sp)
+return false;
+
+  // The date time in the chrono library is valid in the range
+  // [-32767-01-01Z, 32767-12-31Z]. A 32-bit time_t has a larger range, the
+  // function strftime is not able to format the entire range of time_t. The
+  // exact point has not been investigated;

[Lldb-commits] [flang] [lld] [compiler-rt] [clang] [clang-tools-extra] [mlir] [libcxx] [libc] [llvm] [lldb] [libc++][format] P2637R3: Member `visit` (`std::basic_format_arg`) (PR #76449)

2024-01-18 Thread Mark de Wever via lldb-commits

https://github.com/mordante edited 
https://github.com/llvm/llvm-project/pull/76449
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [mlir] [lldb] [libc] [clang] [flang] [compiler-rt] [clang-tools-extra] [lld] [llvm] [libcxx] [libc++][format] P2637R3: Member `visit` (`std::basic_format_arg`) (PR #76449)

2024-01-18 Thread Mark de Wever via lldb-commits

https://github.com/mordante requested changes to this pull request.

In general this looks good. I'd like to have another look after addressing the 
comments.

https://github.com/llvm/llvm-project/pull/76449
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang-tools-extra] [llvm] [compiler-rt] [mlir] [clang] [libc] [flang] [libcxx] [lldb] [lld] [libc++][format] P2637R3: Member `visit` (`std::basic_format_arg`) (PR #76449)

2024-01-18 Thread Mark de Wever via lldb-commits


@@ -163,20 +163,26 @@ class _LIBCPP_TEMPLATE_VIS basic_format_context basic_format_arg {
-if constexpr (same_as)
-  return {};
-else if constexpr (same_as::handle>)
-  // At the moment it's not possible for formatting to use a 
re-targeted handle.
-  // TODO FMT add this when support is needed.
-  std::__throw_format_error("Re-targeting handle not 
supported");
-else
-  return basic_format_arg{
-  __format::__determine_arg_t(),
-  __basic_format_arg_value(__arg)};
-  },
-  static_cast<_Context*>(__c)->arg(__id));
+  auto __visitor = [&](auto __arg) -> 
basic_format_arg {
+if constexpr (same_as)
+  return {};
+else if constexpr (same_as::handle>)
+  // At the moment it's not possible for formatting to use a 
re-targeted handle.
+  // TODO FMT add this when support is needed.
+  std::__throw_format_error("Re-targeting handle not supported");
+else
+  return basic_format_arg{
+  __format::__determine_arg_t(),
+  __basic_format_arg_value(__arg)};
+  };
+#  if _LIBCPP_STD_VER >= 26 && (!defined(_LIBCPP_COMPILER_CLANG_BASED) || 
_LIBCPP_CLANG_VER >= 1800)
+  return 
static_cast<_Context*>(__c)->arg(__id).visit(std::move(__visitor));
+#  else
+  _LIBCPP_DIAGNOSTIC_PUSH
+  _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
+  return std::visit_format_arg(std::move(__visitor), 
static_cast<_Context*>(__c)->arg(__id));
+  _LIBCPP_DIAGNOSTIC_POP

mordante wrote:

```suggestion
  _LIBCPP_SUPPRESS_DEPRECATED_POP
```

https://github.com/llvm/llvm-project/pull/76449
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [compiler-rt] [lldb] [libc] [clang-tools-extra] [mlir] [llvm] [clang] [flang] [lld] [libcxx] [libc++][format] P2637R3: Member `visit` (`std::basic_format_arg`) (PR #76449)

2024-01-18 Thread Mark de Wever via lldb-commits


@@ -19,19 +19,25 @@
 #include "test_macros.h"
 #include "make_string.h"
 
+#if _LIBCPP_STD_VER >= 26
+TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
+#endif
+
 template 
 void test(From value) {
   auto store = std::make_format_args(value);
   const std::basic_format_args format_args{store};
 
-  std::visit_format_arg(
-  [v = To(value)](auto a) {
-if constexpr (std::is_same_v)
-  assert(v == a);
-else
-  assert(false);
-  },
-  format_args.get(0));
+  auto visitor = [v = To(value)](auto a) {
+if constexpr (std::is_same_v)
+  assert(v == a);
+else
+  assert(false);
+  };
+#if _LIBCPP_STD_VER >= 26

mordante wrote:

This needs to test for the FTM too.

https://github.com/llvm/llvm-project/pull/76449
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [flang] [mlir] [libcxx] [clang] [clang-tools-extra] [llvm] [libc] [compiler-rt] [lld] [lldb] [libc++][format] P2637R3: Member `visit` (`std::basic_format_arg`) (PR #76449)

2024-01-18 Thread Mark de Wever via lldb-commits


@@ -193,7 +194,8 @@ _LIBCPP_HIDE_FROM_ABI _Rp __visit_format_arg(_Visitor&& 
__vis, basic_format_arg<
 
   __libcpp_unreachable();
 }
-#  endif
+
+#  endif // if _LIBCPP_STD_VER >= 26

mordante wrote:

```suggestion
#  endif // if _LIBCPP_STD_VER >= 26  && defined(__cpp_explicit_this_parameter)
```

https://github.com/llvm/llvm-project/pull/76449
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [flang] [mlir] [clang-tools-extra] [llvm] [clang] [libc] [lld] [lldb] [compiler-rt] [libcxx] [libc++][format] P2637R3: Member `visit` (`std::basic_format_arg`) (PR #76449)

2024-01-18 Thread Mark de Wever via lldb-commits


@@ -163,20 +163,26 @@ class _LIBCPP_TEMPLATE_VIS basic_format_context basic_format_arg {
-if constexpr (same_as)
-  return {};
-else if constexpr (same_as::handle>)
-  // At the moment it's not possible for formatting to use a 
re-targeted handle.
-  // TODO FMT add this when support is needed.
-  std::__throw_format_error("Re-targeting handle not 
supported");
-else
-  return basic_format_arg{
-  __format::__determine_arg_t(),
-  __basic_format_arg_value(__arg)};
-  },
-  static_cast<_Context*>(__c)->arg(__id));
+  auto __visitor = [&](auto __arg) -> 
basic_format_arg {
+if constexpr (same_as)
+  return {};
+else if constexpr (same_as::handle>)
+  // At the moment it's not possible for formatting to use a 
re-targeted handle.
+  // TODO FMT add this when support is needed.
+  std::__throw_format_error("Re-targeting handle not supported");
+else
+  return basic_format_arg{
+  __format::__determine_arg_t(),
+  __basic_format_arg_value(__arg)};
+  };
+#  if _LIBCPP_STD_VER >= 26 && (!defined(_LIBCPP_COMPILER_CLANG_BASED) || 
_LIBCPP_CLANG_VER >= 1800)
+  return 
static_cast<_Context*>(__c)->arg(__id).visit(std::move(__visitor));
+#  else
+  _LIBCPP_DIAGNOSTIC_PUSH
+  _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")

mordante wrote:

```suggestion
  _LIBCPP_SUPPRESS_DEPRECATED_PUSH
```

https://github.com/llvm/llvm-project/pull/76449
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [llvm] [clang-tools-extra] [compiler-rt] [libcxx] [clang] [flang] [libc] [mlir] [lldb] [lld] [libc++][format] P2637R3: Member `visit` (`std::basic_format_arg`) (PR #76449)

2024-01-18 Thread Mark de Wever via lldb-commits


@@ -7,6 +7,7 @@
 
 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
+// XFAIL: clang-16 || clang-17

mordante wrote:

We know it fails so there is no real need to test that.
Quite often we do XFAIL when we want to update tests when they suddenly start 
to work.
```suggestion
// The tested functionality needs deducing this.
// UNSUPPORTED: clang-16 || clang-17
```

https://github.com/llvm/llvm-project/pull/76449
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


  1   2   >