[clang-tools-extra] [llvm] [clang] [libcxx] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-18 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,100 @@
+//===--===//
+//
+// 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_SUPPORT_INVOCABLE_WITH_TELEMETRY_H
+#define TEST_SUPPORT_INVOCABLE_WITH_TELEMETRY_H
+
+#include 
+#include 
+#include 
+
+#if TEST_STD_VER < 20
+#  error invocable_with_telemetry requires C++20
+#else
+template 
+class invocable_with_telemetry {

cjdb wrote:

I've added `invocable_telemetry` to structure this a bit better.

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


[clang] [libcxx] [clang-tools-extra] [llvm] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-19 Thread Christopher Di Bella via cfe-commits


@@ -87,4 +89,15 @@ void test() {
   std::ranges::unique(iter, iter); // expected-warning {{ignoring return value 
of function declared with 'nodiscard' attribute}}
   std::ranges::upper_bound(range, 1); // expected-warning {{ignoring return 
value of function declared with 'nodiscard' attribute}}
   std::ranges::upper_bound(iter, iter, 1); // expected-warning {{ignoring 
return value of function declared with 'nodiscard' attribute}}
+
+#if TEST_STD_VER >= 23
+  std::ranges::fold_left(range, 0, std::plus());
+  // expected-warning@-1{{ignoring return value of function declared with 
'nodiscard' attribute}}

cjdb wrote:

I think it's substantially better to be explicit about wanting to discard the 
result, since the primary function of this algorithm is to return a computed 
result. I also expect the common case to be to want the result, rather than not.

```cpp
(void)std::ranges::fold_left(r, 0, side_effect_f); // clearly discarding the 
result
```

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


[libcxx] [clang-tools-extra] [clang] [llvm] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-19 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,93 @@
+//===--===//
+//
+// 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
+
+// template S, class T,
+//  indirectly-binary-left-foldable F>
+//   constexpr see below ranges::fold_left(I first, S last, T init, F f);
+//
+// template> F>
+//   constexpr see below ranges::fold_left(R&& r, T init, F f);
+
+#include 
+#include 
+#include 

cjdb wrote:

This is a clang-format issue.

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


[libcxx] [clang-tools-extra] [clang] [llvm] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-19 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,93 @@
+//===--===//
+//
+// 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
+
+// template S, class T,
+//  indirectly-binary-left-foldable F>
+//   constexpr see below ranges::fold_left(I first, S last, T init, F f);
+//
+// template> F>
+//   constexpr see below ranges::fold_left(R&& r, T init, F f);
+
+#include 
+#include 
+#include 
+#include 
+
+#include "test_range.h"
+#include "../gaussian_sum.h"
+
+constexpr bool test() {
+  {

cjdb wrote:

I've instead put each test into its own test case function.

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


[libcxx] [clang-tools-extra] [llvm] [clang] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-19 Thread Christopher Di Bella via cfe-commits


@@ -83,6 +83,10 @@ static_assert(test(std::ranges::find_end, a, a));
 static_assert(test(std::ranges::find_first_of, a, a));

cjdb wrote:

I'm a bit hesitant to use that test file, so `left_folds.pass.cpp` does checks 
to ensure invocable robustness. I'll my concerns in the new year, when I tackle 
the other folds.

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


[libcxx] [clang-tools-extra] [llvm] [clang] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-19 Thread Christopher Di Bella via cfe-commits

https://github.com/cjdb edited https://github.com/llvm/llvm-project/pull/75259
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] [clang-tools-extra] [llvm] [clang] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-19 Thread Christopher Di Bella via cfe-commits


@@ -89,9 +89,7 @@ struct __fold_left_with_iter {
   }
 };
 
-inline namespace __cpo {
 inline constexpr auto fold_left_with_iter = __fold_left_with_iter();

cjdb wrote:

I've updated the description in this PR, which I _think_ becomes the main 
message for a squash-and-merge.

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


[libcxx] [clang-tools-extra] [llvm] [clang] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-19 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,118 @@
+// -*- 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___ALGORITHM_FOLD_H
+#define _LIBCPP___ALGORITHM_FOLD_H
+
+#include <__concepts/assignable.h>
+#include <__concepts/convertible_to.h>
+#include <__concepts/invocable.h>
+#include <__concepts/movable.h>
+#include <__config>
+#include <__functional/invoke.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/iterator_traits.h>
+#include <__iterator/next.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__ranges/dangling.h>
+#include <__type_traits/decay.h>
+#include <__type_traits/invoke.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+template 
+struct in_value_result {
+  _Ip in;
+  _Tp result;
+};
+
+template 
+using fold_left_with_iter_result = in_value_result<_Ip, _Tp>;
+
+template >
+concept __indirectly_binary_left_foldable_impl =
+convertible_to<_Rp, _Up> &&//

cjdb wrote:

Done.

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


[libcxx] [clang] [clang-tools-extra] [llvm] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-19 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,118 @@
+// -*- 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___ALGORITHM_FOLD_H
+#define _LIBCPP___ALGORITHM_FOLD_H
+
+#include <__concepts/assignable.h>
+#include <__concepts/convertible_to.h>
+#include <__concepts/invocable.h>
+#include <__concepts/movable.h>
+#include <__config>
+#include <__functional/invoke.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/iterator_traits.h>
+#include <__iterator/next.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__ranges/dangling.h>
+#include <__type_traits/decay.h>
+#include <__type_traits/invoke.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+template 
+struct in_value_result {
+  _Ip in;
+  _Tp result;
+};
+
+template 
+using fold_left_with_iter_result = in_value_result<_Ip, _Tp>;
+
+template >
+concept __indirectly_binary_left_foldable_impl =
+convertible_to<_Rp, _Up> &&//
+movable<_Tp> &&//
+movable<_Up> &&//
+convertible_to<_Tp, _Up> &&//
+invocable<_Fp&, _Up, iter_reference_t<_Ip>> && //
+assignable_from<_Up&, invoke_result_t<_Fp&, _Up, iter_reference_t<_Ip>>>;
+
+template 
+concept __indirectly_binary_left_foldable =
+copy_constructible<_Fp> && //
+invocable<_Fp&, _Tp, iter_reference_t<_Ip>> && //
+__indirectly_binary_left_foldable_impl<_Fp, _Tp, _Ip, 
invoke_result_t<_Fp&, _Tp, iter_reference_t<_Ip>>>;
+
+struct __fold_left_with_iter {
+  template  _Sp, class _Tp, 
__indirectly_binary_left_foldable<_Tp, _Ip> _Fp>

cjdb wrote:

Correct, subsumption is transitive.

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


[libunwind] [libunwind] Bump to CXX_STANDARD 17 (PR #75986)

2023-12-19 Thread Christopher Di Bella via cfe-commits

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

Thanks for making this change!

CC @ajordanr-google

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


[clang] [libcxx] [llvm] [clang-tools-extra] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-19 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,202 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.

cjdb wrote:

Ah, this comment was made before my revert, so it's no longer applicable.

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


[clang-tools-extra] [llvm] [libcxx] [clang] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-19 Thread Christopher Di Bella via cfe-commits

cjdb wrote:

Merging, with the promise to diligently resolve post-commit feedback in early 
January. Anything that's specific to this patch will be actioned before 
starting work on the remaining fold algorithms, and anything that's generalised 
to `std::ranges` will be actioned after finishing them.

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


[clang-tools-extra] [llvm] [libcxx] [clang] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-19 Thread Christopher Di Bella via cfe-commits

https://github.com/cjdb closed https://github.com/llvm/llvm-project/pull/75259
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] changes where a test writes its output (PR #73560)

2023-11-27 Thread Christopher Di Bella via cfe-commits

https://github.com/cjdb closed https://github.com/llvm/llvm-project/pull/73560
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] changes where a test writes its output (PR #73560)

2023-11-27 Thread Christopher Di Bella via cfe-commits

https://github.com/cjdb created https://github.com/llvm/llvm-project/pull/73560

Writing directly to /dev/null has permission issues on some systems, so we've 
changed this to a temporary file instead.

>From 786d368b9d4d315254df1b8631adead6f8c8e379 Mon Sep 17 00:00:00 2001
From: Christopher Di Bella 
Date: Mon, 27 Nov 2023 19:58:51 +
Subject: [PATCH] [clang] changes where a test writes its output

Writing directly to /dev/null has permission issues on some systems, so
we've changed this to a temporary file instead.
---
 clang/test/OpenMP/dispatch_unsupported.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/OpenMP/dispatch_unsupported.c 
b/clang/test/OpenMP/dispatch_unsupported.c
index fe7ccfa90a5831a..729c046e2635ee4 100644
--- a/clang/test/OpenMP/dispatch_unsupported.c
+++ b/clang/test/OpenMP/dispatch_unsupported.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -emit-llvm -fopenmp -disable-llvm-passes %s -o /dev/null 
-verify=expected
+// RUN: %clang_cc1 -emit-llvm -fopenmp -disable-llvm-passes %s -o %t 
-verify=expected
 
 // expected-error@+2 {{cannot compile this OpenMP dispatch directive yet}}
 void a(){

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


[clang-tools-extra] [llvm] [clang] [libcxx] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-28 Thread Christopher Di Bella via cfe-commits

cjdb wrote:

> > I see @var-const has "requested changes" set, but I feel we've addressed 
> > the one unresolved comment of his.
> 
> @EricWF In fact, this patch changed quite significantly since I last looked 
> at it (based on your feedback, I believe), so I would have appreciated being 
> able to do another round of review before this was merged.

That is fair. My understanding is that Eric was trying to balance respecting 
that you might have feedback with me struggling to switch off while OOO, if a 
PR is still in my "active context".

I ended up coming back into the office early, and prioritised applying your 
feedback as a result (see #76534). Please do make further commentary as 
necessary.

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


[clang-tools-extra] [llvm] [clang] [libcxx] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-28 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,104 @@
+//===--===//
+//
+// 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
+
+// template 
+// struct in_value_result;
+
+#include 
+#include 
+#include 
+#include 
+
+#include "MoveOnly.h"
+
+struct A {
+  explicit A(int);
+};
+// no implicit conversion
+static_assert(!std::is_constructible_v, 
std::ranges::in_value_result>);
+
+struct B {
+  B(int);
+};
+// implicit conversion
+static_assert(std::is_constructible_v, 
std::ranges::in_value_result>);
+static_assert(std::is_constructible_v, 
std::ranges::in_value_result&>);
+static_assert(
+std::is_constructible_v, const 
std::ranges::in_value_result>);
+static_assert(
+std::is_constructible_v, const 
std::ranges::in_value_result&>);
+
+struct C {
+  C(int&);
+};
+static_assert(!std::is_constructible_v, 
std::ranges::in_value_result&>);
+
+// has to be convertible via const&
+static_assert(std::is_convertible_v&, 
std::ranges::in_value_result>);
+static_assert(
+std::is_convertible_v&, 
std::ranges::in_value_result>);
+static_assert(
+std::is_convertible_v&&, 
std::ranges::in_value_result>);
+static_assert(
+std::is_convertible_v&&, 
std::ranges::in_value_result>);
+
+// should be move constructible
+static_assert(std::is_move_constructible_v>);
+static_assert(std::is_move_constructible_v>);
+
+// should not copy constructible with move-only type

cjdb wrote:

> I fully agree that adding this to a project-wide style guide would be very 
> useful (to be clear, I don't mean to imply it has to be a comprehensive huge 
> guide, even if it documents just a few randomly chosen aspects, it's already 
> helpful and we can always expand later). We do have a ["Coding 
> standards"](https://libcxx.llvm.org/Contributing.html#coding-standards) 
> section in the `Contributing` document -- we might want to add a new page and 
> link it from that section. Thanks for taking this on!

Re ultranit: applied in #76534.

Re second comment: Not sure what this is pertaining to?

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


[clang] [clang-tools-extra] [llvm] [libcxx] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-28 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,104 @@
+//===--===//
+//
+// 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
+
+// template 
+// struct in_value_result;
+
+#include 
+#include 
+#include 
+#include 
+
+#include "MoveOnly.h"
+
+struct A {
+  explicit A(int);
+};
+// no implicit conversion
+static_assert(!std::is_constructible_v, 
std::ranges::in_value_result>);
+
+struct B {
+  B(int);
+};
+// implicit conversion
+static_assert(std::is_constructible_v, 
std::ranges::in_value_result>);
+static_assert(std::is_constructible_v, 
std::ranges::in_value_result&>);
+static_assert(
+std::is_constructible_v, const 
std::ranges::in_value_result>);
+static_assert(
+std::is_constructible_v, const 
std::ranges::in_value_result&>);
+
+struct C {
+  C(int&);
+};
+static_assert(!std::is_constructible_v, 
std::ranges::in_value_result&>);
+
+// has to be convertible via const&
+static_assert(std::is_convertible_v&, 
std::ranges::in_value_result>);
+static_assert(
+std::is_convertible_v&, 
std::ranges::in_value_result>);
+static_assert(
+std::is_convertible_v&&, 
std::ranges::in_value_result>);
+static_assert(
+std::is_convertible_v&&, 
std::ranges::in_value_result>);
+
+// should be move constructible
+static_assert(std::is_move_constructible_v>);
+static_assert(std::is_move_constructible_v>);
+
+// should not copy constructible with move-only type
+static_assert(!std::is_copy_constructible_v>);
+static_assert(!std::is_copy_constructible_v>);
+
+struct NotConvertible {};
+// conversions should not work if there is no conversion
+static_assert(
+!std::is_convertible_v, 
std::ranges::in_value_result>);
+static_assert(
+!std::is_convertible_v, 
std::ranges::in_value_result>);
+
+template 
+struct ConvertibleFrom {
+  constexpr ConvertibleFrom(T c) : content{c} {}
+  T content;
+};
+
+constexpr bool test() {
+  {
+std::ranges::in_value_result res{10, 0.};
+assert(res.in == 10);
+assert(res.value == 0.);
+std::ranges::in_value_result, 
ConvertibleFrom> res2 = res;
+assert(res2.in.content == 10);
+assert(res2.value.content == 0.);
+  }

cjdb wrote:

I've applied this in #76534.

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


[clang-tools-extra] [libcxx] [clang] [llvm] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-28 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,89 @@
+//===--===//
+//
+// 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_SUPPORT_INVOCABLE_WITH_TELEMETRY_H
+#define TEST_SUPPORT_INVOCABLE_WITH_TELEMETRY_H
+
+#include 
+#include 
+#include 
+#include 
+
+#if TEST_STD_VER < 20
+#  error invocable_with_telemetry requires C++20
+#else
+struct invocable_telemetry {

cjdb wrote:

Thoughts summarised in the comment below.

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


[clang-tools-extra] [llvm] [clang] [libcxx] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-28 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,89 @@
+//===--===//
+//
+// 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_SUPPORT_INVOCABLE_WITH_TELEMETRY_H

cjdb wrote:

My guess is "probably not", though we should come up with a consistent design 
(happy to work with you on that). I wasn't aware of those two, but the contents 
of `support/counting_predicates.h` weren't quite right for the application. I 
suggest we consolidate all of the counting invocable types into a single 
`counting_invocable` or `TracedInvocable` so that there's only one canonical 
type.

Looking at `TracedCopyMove`, it looks like it'll need a call operator added. 
Would you like me to add tests for explicitly counting copies and moves? It may 
be better to have these be separate tests for modularity.

Nothing has been applied yet, but I suspect a change to be made in the next 
week or so.

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


[clang-tools-extra] [llvm] [clang] [libcxx] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-28 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,104 @@
+//===--===//
+//
+// 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
+
+// template 
+// struct in_value_result;
+
+#include 
+#include 
+#include 
+#include 
+
+#include "MoveOnly.h"
+
+struct A {
+  explicit A(int);
+};
+// no implicit conversion
+static_assert(!std::is_constructible_v, 
std::ranges::in_value_result>);
+
+struct B {
+  B(int);
+};
+// implicit conversion
+static_assert(std::is_constructible_v, 
std::ranges::in_value_result>);
+static_assert(std::is_constructible_v, 
std::ranges::in_value_result&>);
+static_assert(
+std::is_constructible_v, const 
std::ranges::in_value_result>);
+static_assert(
+std::is_constructible_v, const 
std::ranges::in_value_result&>);
+
+struct C {
+  C(int&);
+};
+static_assert(!std::is_constructible_v, 
std::ranges::in_value_result&>);
+
+// has to be convertible via const&
+static_assert(std::is_convertible_v&, 
std::ranges::in_value_result>);
+static_assert(
+std::is_convertible_v&, 
std::ranges::in_value_result>);
+static_assert(
+std::is_convertible_v&&, 
std::ranges::in_value_result>);
+static_assert(
+std::is_convertible_v&&, 
std::ranges::in_value_result>);
+
+// should be move constructible
+static_assert(std::is_move_constructible_v>);
+static_assert(std::is_move_constructible_v>);
+
+// should not copy constructible with move-only type
+static_assert(!std::is_copy_constructible_v>);
+static_assert(!std::is_copy_constructible_v>);
+
+struct NotConvertible {};
+// conversions should not work if there is no conversion
+static_assert(
+!std::is_convertible_v, 
std::ranges::in_value_result>);
+static_assert(
+!std::is_convertible_v, 
std::ranges::in_value_result>);
+
+template 
+struct ConvertibleFrom {
+  constexpr ConvertibleFrom(T c) : content{c} {}
+  T content;
+};
+
+constexpr bool test() {
+  {

cjdb wrote:

I lifted these from one of the other tests in this directory, so we should add 
the description to all of them. Applied in #76534.

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


[clang-tools-extra] [libcxx] [clang] [llvm] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-28 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,259 @@
+//===--===//
+//
+// 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
+
+// Checks that `std::ranges::fold_left_with_iter`'s requirements reject 
parameters that don't meet

cjdb wrote:

Applied in #76534.

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


[clang-tools-extra] [libcxx] [clang] [llvm] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-28 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,315 @@
+//===--===//
+//
+// 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
+
+// template S, class T,
+//  indirectly-binary-left-foldable F>
+//   constexpr see below ranges::fold_left_with_iter(I first, S last, T init, 
F f);
+//
+// template> F>
+//   constexpr see below ranges::fold_left_with_iter(R&& r, T init, F f);
+
+// template S, class T,
+//  indirectly-binary-left-foldable F>
+//   constexpr see below ranges::fold_left(I first, S last, T init, F f);
+//
+// template> F>
+//   constexpr see below ranges::fold_left(R&& r, T init, F f);
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_range.h"
+#include "invocable_with_telemetry.h"
+#include "maths.h"
+
+using std::ranges::fold_left;
+using std::ranges::fold_left_with_iter;
+
+template 
+concept is_in_value_result =
+std::same_as, T>>;
+
+template 
+concept is_dangling_with = std::same_as>;
+
+struct Long {

cjdb wrote:

Agreed. Renamed in #76534.

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


[clang-tools-extra] [libcxx] [clang] [llvm] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-28 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,118 @@
+// -*- 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___ALGORITHM_FOLD_H
+#define _LIBCPP___ALGORITHM_FOLD_H
+
+#include <__concepts/assignable.h>
+#include <__concepts/convertible_to.h>
+#include <__concepts/invocable.h>
+#include <__concepts/movable.h>
+#include <__config>
+#include <__functional/invoke.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/iterator_traits.h>
+#include <__iterator/next.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__ranges/dangling.h>
+#include <__type_traits/decay.h>
+#include <__type_traits/invoke.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+template 
+struct in_value_result {
+  _Ip in;
+  _Tp result;
+};
+
+template 
+using fold_left_with_iter_result = in_value_result<_Ip, _Tp>;
+
+template >
+concept __indirectly_binary_left_foldable_impl =
+convertible_to<_Rp, _Up> &&//
+movable<_Tp> &&//
+movable<_Up> &&//
+convertible_to<_Tp, _Up> &&//
+invocable<_Fp&, _Up, iter_reference_t<_Ip>> && //
+assignable_from<_Up&, invoke_result_t<_Fp&, _Up, iter_reference_t<_Ip>>>;
+
+template 
+concept __indirectly_binary_left_foldable =
+copy_constructible<_Fp> && //
+invocable<_Fp&, _Tp, iter_reference_t<_Ip>> && //
+__indirectly_binary_left_foldable_impl<_Fp, _Tp, _Ip, 
invoke_result_t<_Fp&, _Tp, iter_reference_t<_Ip>>>;
+
+struct __fold_left_with_iter {
+  template  _Sp, class _Tp, 
__indirectly_binary_left_foldable<_Tp, _Ip> _Fp>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI static constexpr auto
+  operator()(_Ip __first, _Sp __last, _Tp __init, _Fp __f) {
+using _Up = decay_t>>;
+
+if (__first == __last) {
+  return fold_left_with_iter_result<_Ip, _Up>{std::move(__first), 
_Up(std::move(__init))};
+}
+
+_Up __result = std::invoke(__f, std::move(__init), *__first);
+for (++__first; __first != __last; ++__first) {
+  __result = std::invoke(__f, std::move(__result), *__first);
+}
+
+return fold_left_with_iter_result<_Ip, _Up>{std::move(__first), 
std::move(__result)};
+  }
+
+  template > _Fp>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI static constexpr auto 
operator()(_Rp&& __r, _Tp __init, _Fp __f) {
+auto __result = operator()(ranges::begin(__r), ranges::end(__r), 
std::move(__init), std::ref(__f));
+
+using _Up = decay_t>>;
+return fold_left_with_iter_result, _Up>{
+std::move(__result.in), std::move(__result.result)};
+  }
+};
+
+inline namespace __cpo {
+inline constexpr auto fold_left_with_iter = __fold_left_with_iter();
+} // namespace __cpo
+
+struct __fold_left {
+  template  _Sp, class _Tp, 
__indirectly_binary_left_foldable<_Tp, _Ip> _Fp>

cjdb wrote:

I am okay with the current resolution given that a discussion has happened, and 
am happy to make a dedicated migration patch for all `_Ip`/`_Sp` names. This 
has **not** been applied in #76534: I'll make a dedicated commit for that in 
about an hour.

I think that the contribution guidelines should probably issue guidance on what 
kinds of names we expect, especially when it comes to names that we want to 
have some element of consistency for. Perhaps that could be the subject of the 
new discussion.

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


[clang-tools-extra] [llvm] [clang] [libcxx] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-28 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,93 @@
+//===--===//
+//
+// 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
+
+// template S, class T,
+//  indirectly-binary-left-foldable F>
+//   constexpr see below ranges::fold_left(I first, S last, T init, F f);
+//
+// template> F>
+//   constexpr see below ranges::fold_left(R&& r, T init, F f);
+
+#include 
+#include 
+#include 
+#include 
+
+#include "test_range.h"
+#include "../gaussian_sum.h"
+
+constexpr bool test() {
+  {
+auto data = std::vector{1, 2, 3, 4};
+auto const result = std::ranges::fold_left(data.begin(), data.begin(), 0, 
std::plus());
+
+assert(result == 0);
+
+auto range = std::span(data.data(), 0);
+assert(std::ranges::fold_left(range, 0, std::plus()) == result);
+  }

cjdb wrote:

I've completely separated them per more recent feedback below.

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


[clang-tools-extra] [llvm] [libcxx] [clang] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-28 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,118 @@
+// -*- 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___ALGORITHM_FOLD_H
+#define _LIBCPP___ALGORITHM_FOLD_H
+
+#include <__concepts/assignable.h>
+#include <__concepts/convertible_to.h>
+#include <__concepts/invocable.h>
+#include <__concepts/movable.h>
+#include <__config>
+#include <__functional/invoke.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/iterator_traits.h>
+#include <__iterator/next.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__ranges/dangling.h>
+#include <__type_traits/decay.h>
+#include <__type_traits/invoke.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+template 
+struct in_value_result {
+  _Ip in;
+  _Tp result;
+};
+
+template 
+using fold_left_with_iter_result = in_value_result<_Ip, _Tp>;
+
+template >
+concept __indirectly_binary_left_foldable_impl =
+convertible_to<_Rp, _Up> &&//
+movable<_Tp> &&//
+movable<_Up> &&//
+convertible_to<_Tp, _Up> &&//
+invocable<_Fp&, _Up, iter_reference_t<_Ip>> && //
+assignable_from<_Up&, invoke_result_t<_Fp&, _Up, iter_reference_t<_Ip>>>;
+
+template 
+concept __indirectly_binary_left_foldable =
+copy_constructible<_Fp> && //
+invocable<_Fp&, _Tp, iter_reference_t<_Ip>> && //
+__indirectly_binary_left_foldable_impl<_Fp, _Tp, _Ip, 
invoke_result_t<_Fp&, _Tp, iter_reference_t<_Ip>>>;
+
+struct __fold_left_with_iter {
+  template  _Sp, class _Tp, 
__indirectly_binary_left_foldable<_Tp, _Ip> _Fp>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI static constexpr auto
+  operator()(_Ip __first, _Sp __last, _Tp __init, _Fp __f) {
+using _Up = decay_t>>;
+
+if (__first == __last) {
+  return fold_left_with_iter_result<_Ip, _Up>{std::move(__first), 
_Up(std::move(__init))};
+}
+
+_Up __result = std::invoke(__f, std::move(__init), *__first);
+for (++__first; __first != __last; ++__first) {
+  __result = std::invoke(__f, std::move(__result), *__first);
+}
+
+return fold_left_with_iter_result<_Ip, _Up>{std::move(__first), 
std::move(__result)};
+  }
+
+  template > _Fp>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI static constexpr auto 
operator()(_Rp&& __r, _Tp __init, _Fp __f) {
+auto __result = operator()(ranges::begin(__r), ranges::end(__r), 
std::move(__init), std::ref(__f));
+
+using _Up = decay_t>>;
+return fold_left_with_iter_result, _Up>{
+std::move(__result.in), std::move(__result.result)};
+  }
+};
+
+inline namespace __cpo {
+inline constexpr auto fold_left_with_iter = __fold_left_with_iter();
+} // namespace __cpo
+
+struct __fold_left {
+  template  _Sp, class _Tp, 
__indirectly_binary_left_foldable<_Tp, _Ip> _Fp>

cjdb wrote:

See #76540 for the renaming patch.

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


[llvm] [libcxx] [lld] [flang] [compiler-rt] [clang-tools-extra] [clang] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits

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

Thanks for working on this! There's a fair bit that I've provided comments for, 
but I think you're off to a great start, and I would like to see this merged in 
January, if at all possible.

Some comments are short and repetitive: those are usually coupled with a 
starter comment that explains my perspective, and then I just flag the others 
as I see them in a (hopefully) non-intrusive way.

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


[compiler-rt] [clang-tools-extra] [lld] [libcxx] [llvm] [flang] [clang] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,129 @@
+//===--===//
+//
+// 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
+
+// 
+
+// class enumerate_view
+
+// constexpr auto begin() requires (!simple-view);
+// constexpr auto begin() const requires range-with-movable-references;
+
+#include 
+#include 
+#include 
+
+#include "test_iterators.h"
+#include "types.h"
+
+// Helpers
+
+template 

cjdb wrote:

I would prefer it if these were declared at their point of use, rather than at 
the top of the file (and same for other tests).

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


[clang-tools-extra] [libcxx] [flang] [compiler-rt] [clang] [lld] [llvm] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,333 @@
+// -*- 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___RANGES_ENUMERATE_VIEW_H
+#define _LIBCPP___RANGES_ENUMERATE_VIEW_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/iter_move.h>
+#include <__iterator/iterator_traits.h>
+#include <__ranges/access.h>
+#include <__ranges/all.h>
+#include <__ranges/concepts.h>
+#include <__ranges/enable_borrowed_range.h>
+#include <__ranges/range_adaptor.h>
+#include <__ranges/size.h>
+#include <__ranges/view_interface.h>
+#include <__type_traits/maybe_const.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+// [concept.object]
+
+template 
+concept __range_with_movable_references =
+ranges::input_range<_Rp> && 
std::move_constructible> &&
+std::move_constructible>;

cjdb wrote:

```suggestion
template 
concept __range_with_movable_references =
   input_range<_Rp> && move_constructible> &&
   move_constructible>;
```
We don't need to qualify these names in their native namespace.

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


[clang] [lld] [clang-tools-extra] [llvm] [flang] [compiler-rt] [libcxx] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits

https://github.com/cjdb edited https://github.com/llvm/llvm-project/pull/73617
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libcxx] [llvm] [lld] [flang] [clang-tools-extra] [compiler-rt] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,333 @@
+// -*- 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___RANGES_ENUMERATE_VIEW_H
+#define _LIBCPP___RANGES_ENUMERATE_VIEW_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/iter_move.h>
+#include <__iterator/iterator_traits.h>
+#include <__ranges/access.h>
+#include <__ranges/all.h>
+#include <__ranges/concepts.h>
+#include <__ranges/enable_borrowed_range.h>
+#include <__ranges/range_adaptor.h>
+#include <__ranges/size.h>
+#include <__ranges/view_interface.h>
+#include <__type_traits/maybe_const.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+// [concept.object]
+
+template 
+concept __range_with_movable_references =
+ranges::input_range<_Rp> && 
std::move_constructible> &&
+std::move_constructible>;
+
+// [range.enumerate.view]
+
+template 
+  requires __range_with_movable_references<_View>
+class enumerate_view : public view_interface> {
+  _View __base_ = _View();
+
+  // [range.enumerate.iterator]
+  template 
+  class __iterator;
+
+  // [range.enumerate.sentinel]
+  template 
+  class __sentinel;
+
+  template 
+  _LIBCPP_HIDE_FROM_ABI static constexpr decltype(auto) __get_current(const 
__iterator<_AnyConst>& __iter) {
+return (__iter.__current_);
+  }
+
+public:
+  _LIBCPP_HIDE_FROM_ABI constexpr enumerate_view()
+requires(default_initializable<_View>)
+  = default;
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit enumerate_view(_View __base) : 
__base_(std::move(__base)){};
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto begin()
+requires(!__simple_view<_View>)
+  {
+return __iterator(ranges::begin(__base_), 0);
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const
+requires __range_with_movable_references
+  {
+return __iterator(ranges::begin(__base_), 0);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto end()
+requires(!__simple_view<_View>)
+  {
+if constexpr (common_range<_View> && sized_range<_View>)
+  return __iterator(ranges::end(__base_), 
ranges::distance(__base_));
+else
+  return __sentinel(ranges::end(__base_));
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto end() const
+requires __range_with_movable_references
+  {
+if constexpr (common_range && sized_range)
+  return __iterator(ranges::end(__base_), ranges::distance(__base_));
+else
+  return __sentinel(ranges::end(__base_));
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto size()
+requires sized_range<_View>
+  {
+return ranges::size(__base_);
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto size() const
+requires sized_range
+  {
+return ranges::size(__base_);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr _View base() const&
+requires copy_constructible<_View>
+  {
+return __base_;
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); 
}
+};
+
+template 
+enumerate_view(_Range&&) -> enumerate_view>;
+
+// [range.enumerate.iterator]
+
+template 
+  requires __range_with_movable_references<_View>
+template 
+class enumerate_view<_View>::__iterator {
+  using _Base = __maybe_const<_Const, _View>;
+
+  static consteval auto __get_iterator_concept() {
+if constexpr (random_access_range<_Base>) {
+  return random_access_iterator_tag{};
+} else if constexpr (bidirectional_range<_Base>) {
+  return bidirectional_iterator_tag{};
+} else if constexpr (forward_range<_Base>) {
+  return forward_iterator_tag{};
+} else {
+  return input_iterator_tag{};
+}
+  }
+
+  friend class enumerate_view<_View>;
+
+public:
+  using iterator_category = input_iterator_tag;
+  using iterator_concept  = decltype(__get_iterator_concept());
+  using difference_type   = range_difference_t<_Base>;
+  using value_type= tuple>;
+
+private:
+  using __reference_type   = tuple>;
+  iterator_t<_Base> __current_ = iterator_t<_Base>();
+  difference_type __pos_   = 0;
+
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit __iterator(iterator_t<_Base> 
__current, difference_type __pos)
+  : __current_(std::move(__current)), __pos_(__pos) {}
+
+public:
+  _LIBCPP_HIDE_FROM_ABI __iterator()
+requires(default_initializable>)
+  = default;
+  _LIBCPP_HIDE_FROM_ABI constexpr __iterator(__iterator __i)
+requires _Const && convertible_to, iterator_t<_Base>>
+  : __current_(std::move(__i.__current_)), __pos_(__i.__pos_) {}
+
+  _L

[libcxx] [clang] [lld] [llvm] [clang-tools-extra] [flang] [compiler-rt] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,333 @@
+// -*- 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___RANGES_ENUMERATE_VIEW_H
+#define _LIBCPP___RANGES_ENUMERATE_VIEW_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/iter_move.h>
+#include <__iterator/iterator_traits.h>
+#include <__ranges/access.h>
+#include <__ranges/all.h>
+#include <__ranges/concepts.h>
+#include <__ranges/enable_borrowed_range.h>
+#include <__ranges/range_adaptor.h>
+#include <__ranges/size.h>
+#include <__ranges/view_interface.h>
+#include <__type_traits/maybe_const.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+// [concept.object]
+
+template 
+concept __range_with_movable_references =
+ranges::input_range<_Rp> && 
std::move_constructible> &&
+std::move_constructible>;
+
+// [range.enumerate.view]
+
+template 
+  requires __range_with_movable_references<_View>
+class enumerate_view : public view_interface> {
+  _View __base_ = _View();
+
+  // [range.enumerate.iterator]
+  template 
+  class __iterator;
+
+  // [range.enumerate.sentinel]
+  template 
+  class __sentinel;
+
+  template 
+  _LIBCPP_HIDE_FROM_ABI static constexpr decltype(auto) __get_current(const 
__iterator<_AnyConst>& __iter) {
+return (__iter.__current_);
+  }
+
+public:
+  _LIBCPP_HIDE_FROM_ABI constexpr enumerate_view()
+requires(default_initializable<_View>)
+  = default;
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit enumerate_view(_View __base) : 
__base_(std::move(__base)){};
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto begin()
+requires(!__simple_view<_View>)
+  {
+return __iterator(ranges::begin(__base_), 0);
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const
+requires __range_with_movable_references
+  {
+return __iterator(ranges::begin(__base_), 0);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto end()
+requires(!__simple_view<_View>)
+  {
+if constexpr (common_range<_View> && sized_range<_View>)
+  return __iterator(ranges::end(__base_), 
ranges::distance(__base_));
+else
+  return __sentinel(ranges::end(__base_));
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto end() const
+requires __range_with_movable_references
+  {
+if constexpr (common_range && sized_range)
+  return __iterator(ranges::end(__base_), ranges::distance(__base_));
+else
+  return __sentinel(ranges::end(__base_));
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto size()
+requires sized_range<_View>
+  {
+return ranges::size(__base_);
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto size() const
+requires sized_range
+  {
+return ranges::size(__base_);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr _View base() const&
+requires copy_constructible<_View>
+  {
+return __base_;
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); 
}
+};
+
+template 
+enumerate_view(_Range&&) -> enumerate_view>;
+
+// [range.enumerate.iterator]
+
+template 
+  requires __range_with_movable_references<_View>
+template 
+class enumerate_view<_View>::__iterator {
+  using _Base = __maybe_const<_Const, _View>;
+
+  static consteval auto __get_iterator_concept() {
+if constexpr (random_access_range<_Base>) {
+  return random_access_iterator_tag{};
+} else if constexpr (bidirectional_range<_Base>) {
+  return bidirectional_iterator_tag{};
+} else if constexpr (forward_range<_Base>) {
+  return forward_iterator_tag{};
+} else {
+  return input_iterator_tag{};
+}
+  }
+
+  friend class enumerate_view<_View>;
+
+public:
+  using iterator_category = input_iterator_tag;
+  using iterator_concept  = decltype(__get_iterator_concept());
+  using difference_type   = range_difference_t<_Base>;
+  using value_type= tuple>;
+
+private:
+  using __reference_type   = tuple>;
+  iterator_t<_Base> __current_ = iterator_t<_Base>();
+  difference_type __pos_   = 0;
+
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit __iterator(iterator_t<_Base> 
__current, difference_type __pos)
+  : __current_(std::move(__current)), __pos_(__pos) {}
+
+public:
+  _LIBCPP_HIDE_FROM_ABI __iterator()
+requires(default_initializable>)
+  = default;
+  _LIBCPP_HIDE_FROM_ABI constexpr __iterator(__iterator __i)
+requires _Const && convertible_to, iterator_t<_Base>>
+  : __current_(std::move(__i.__current_)), __pos_(__i.__pos_) {}
+
+  _L

[libcxx] [compiler-rt] [clang] [llvm] [clang-tools-extra] [flang] [lld] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,138 @@
+//===--===//
+//
+// 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
+
+// 
+
+// class enumerate_view
+
+// class enumerate_view::iterator
+
+// constexpr const iterator_t& base() const & noexcept;
+// constexpr iterator_t base() &&;
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_iterators.h"
+#include "../types.h"
+
+// template 
+// class MovableIterator {
+//   using Traits = std::iterator_traits;
+//   It it_;
+
+//   template 
+//   friend class MovableIterator;
+
+// public:
+//   using iterator_category = std::input_iterator_tag;
+//   using value_type= typename Traits::value_type;
+//   using difference_type   = typename Traits::difference_type;
+//   using pointer   = It;
+//   using reference = typename Traits::reference;
+
+//   TEST_CONSTEXPR explicit MovableIterator(It it) : it_(it), 
justInitialized{true} { static_assert(false); }
+
+//   template 
+//   TEST_CONSTEXPR MovableIterator(const MovableIterator& u) : 
it_(u.it_), wasCopyInitialized{true} {
+// static_assert(false);
+//   }
+
+//   template ::value>::type>
+//   TEST_CONSTEXPR_CXX14 MovableIterator(MovableIterator&& u) : 
it_(u.it_), wasMoveInitialized{true} {
+// static_assert(false);
+// u.it_ = U();
+//   }
+
+//   TEST_CONSTEXPR reference operator*() const { return *it_; }
+
+//   TEST_CONSTEXPR_CXX14 MovableIterator& operator++() {
+// ++it_;
+// return *this;
+//   }
+//   TEST_CONSTEXPR_CXX14 MovableIterator operator++(int) { return 
MovableIterator(it_++); }
+
+//   friend TEST_CONSTEXPR bool operator==(const MovableIterator& x, const 
MovableIterator& y) { return x.it_ == y.it_; }
+//   friend TEST_CONSTEXPR bool operator!=(const MovableIterator& x, const 
MovableIterator& y) { return x.it_ != y.it_; }
+
+//   friend TEST_CONSTEXPR It base(const MovableIterator& i) { return i.it_; }
+
+//   template 
+//   void operator,(T const&) = delete;
+
+//   bool justInitialized= false;
+//   bool wasCopyInitialized = false;
+//   bool wasMoveInitialized = false;
+// };

cjdb wrote:

```suggestion
```
Please delete this if it's not being used.

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


[lld] [libcxx] [clang-tools-extra] [flang] [clang] [llvm] [compiler-rt] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,333 @@
+// -*- 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___RANGES_ENUMERATE_VIEW_H
+#define _LIBCPP___RANGES_ENUMERATE_VIEW_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/iter_move.h>
+#include <__iterator/iterator_traits.h>
+#include <__ranges/access.h>
+#include <__ranges/all.h>
+#include <__ranges/concepts.h>
+#include <__ranges/enable_borrowed_range.h>
+#include <__ranges/range_adaptor.h>
+#include <__ranges/size.h>
+#include <__ranges/view_interface.h>
+#include <__type_traits/maybe_const.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+// [concept.object]
+
+template 
+concept __range_with_movable_references =
+ranges::input_range<_Rp> && 
std::move_constructible> &&
+std::move_constructible>;
+
+// [range.enumerate.view]
+
+template 
+  requires __range_with_movable_references<_View>
+class enumerate_view : public view_interface> {
+  _View __base_ = _View();
+
+  // [range.enumerate.iterator]
+  template 
+  class __iterator;
+
+  // [range.enumerate.sentinel]
+  template 
+  class __sentinel;
+
+  template 
+  _LIBCPP_HIDE_FROM_ABI static constexpr decltype(auto) __get_current(const 
__iterator<_AnyConst>& __iter) {
+return (__iter.__current_);
+  }
+
+public:
+  _LIBCPP_HIDE_FROM_ABI constexpr enumerate_view()
+requires(default_initializable<_View>)
+  = default;
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit enumerate_view(_View __base) : 
__base_(std::move(__base)){};
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto begin()
+requires(!__simple_view<_View>)
+  {
+return __iterator(ranges::begin(__base_), 0);
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const
+requires __range_with_movable_references
+  {
+return __iterator(ranges::begin(__base_), 0);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto end()
+requires(!__simple_view<_View>)
+  {
+if constexpr (common_range<_View> && sized_range<_View>)
+  return __iterator(ranges::end(__base_), 
ranges::distance(__base_));
+else
+  return __sentinel(ranges::end(__base_));
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto end() const
+requires __range_with_movable_references
+  {
+if constexpr (common_range && sized_range)
+  return __iterator(ranges::end(__base_), ranges::distance(__base_));
+else
+  return __sentinel(ranges::end(__base_));
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto size()
+requires sized_range<_View>
+  {
+return ranges::size(__base_);
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto size() const
+requires sized_range
+  {
+return ranges::size(__base_);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr _View base() const&
+requires copy_constructible<_View>
+  {
+return __base_;
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); 
}
+};
+
+template 
+enumerate_view(_Range&&) -> enumerate_view>;
+
+// [range.enumerate.iterator]
+
+template 
+  requires __range_with_movable_references<_View>
+template 
+class enumerate_view<_View>::__iterator {
+  using _Base = __maybe_const<_Const, _View>;
+
+  static consteval auto __get_iterator_concept() {
+if constexpr (random_access_range<_Base>) {
+  return random_access_iterator_tag{};
+} else if constexpr (bidirectional_range<_Base>) {
+  return bidirectional_iterator_tag{};
+} else if constexpr (forward_range<_Base>) {
+  return forward_iterator_tag{};
+} else {
+  return input_iterator_tag{};
+}
+  }
+
+  friend class enumerate_view<_View>;
+
+public:
+  using iterator_category = input_iterator_tag;
+  using iterator_concept  = decltype(__get_iterator_concept());
+  using difference_type   = range_difference_t<_Base>;
+  using value_type= tuple>;
+
+private:
+  using __reference_type   = tuple>;
+  iterator_t<_Base> __current_ = iterator_t<_Base>();
+  difference_type __pos_   = 0;
+
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit __iterator(iterator_t<_Base> 
__current, difference_type __pos)
+  : __current_(std::move(__current)), __pos_(__pos) {}
+
+public:
+  _LIBCPP_HIDE_FROM_ABI __iterator()
+requires(default_initializable>)
+  = default;
+  _LIBCPP_HIDE_FROM_ABI constexpr __iterator(__iterator __i)
+requires _Const && convertible_to, iterator_t<_Base>>
+  : __current_(std::move(__i.__current_)), __pos_(__i.__pos_) {}
+
+  _L

[clang-tools-extra] [compiler-rt] [flang] [libcxx] [clang] [lld] [llvm] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,96 @@
+//===--===//
+//
+// 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
+
+// 
+
+// class enumerate_view
+
+// class enumerate_view::iterator
+
+// friend constexpr bool operator==(const iterator& x, const iterator& y) 
noexcept;
+
+#include 
+#include 
+
+#include "test_iterators.h"
+#include "../types.h"
+// #include "../types_iterators.h"
+
+// template 
+// struct Iterator {
+//   using value_type   = int
+//   using difference_type  = std::std::ptrdiff_t;
+//   using iterator_concept = std::input_iterator_tag;
+
+//   constexpr decltype(auto) operator*() const { return *it_; }
+//   constexpr Iterator& operator++() {
+// ++it_;
+
+// return *this;
+//   }
+//   constexpr void operator++(int) { ++it_; }
+
+//   std::tuple* it_;
+// };
+
+// template 
+// struct Sentinel {
+//   constexpr bool operator==(const Iterator& i) const { return i.it_ 
== end_; }
+
+//   std::tuple* end_;
+// };
+
+// template 
+// struct CrossComparableSentinel {
+//   template 
+//   constexpr bool operator==(const Iterator& i) const {
+// return i.it_ == end_;
+//   }
+
+//   std::tuple* end_;
+// };
+
+constexpr bool test() {
+  int buff[] = {0, 1, 2, 3, 5};
+  {
+using View = std::ranges::enumerate_view;
+RangeView const range(buff, buff + 5);
+
+std::same_as decltype(auto) ev = std::views::enumerate(range);
+
+auto it1 = ev.begin();
+auto it2 = it1 + 5;
+
+assert(it1 == it1);
+ASSERT_NOEXCEPT(it1 == it1);
+assert(it1 != it2);
+ASSERT_NOEXCEPT(it1 != it2);
+assert(it2 != it1);
+ASSERT_NOEXCEPT(it2 != it1);
+assert(it2 == ev.end());
+assert(ev.end() == it2);
+
+for (std::size_t index = 0; index != 5; ++index) {
+  ++it1;
+}

cjdb wrote:

Please hand-roll.

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


[llvm] [clang-tools-extra] [flang] [libcxx] [lld] [compiler-rt] [clang] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,333 @@
+// -*- 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___RANGES_ENUMERATE_VIEW_H
+#define _LIBCPP___RANGES_ENUMERATE_VIEW_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/iter_move.h>
+#include <__iterator/iterator_traits.h>
+#include <__ranges/access.h>
+#include <__ranges/all.h>
+#include <__ranges/concepts.h>
+#include <__ranges/enable_borrowed_range.h>
+#include <__ranges/range_adaptor.h>
+#include <__ranges/size.h>
+#include <__ranges/view_interface.h>
+#include <__type_traits/maybe_const.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+// [concept.object]
+
+template 
+concept __range_with_movable_references =
+ranges::input_range<_Rp> && 
std::move_constructible> &&
+std::move_constructible>;
+
+// [range.enumerate.view]
+
+template 
+  requires __range_with_movable_references<_View>
+class enumerate_view : public view_interface> {
+  _View __base_ = _View();
+
+  // [range.enumerate.iterator]
+  template 
+  class __iterator;
+
+  // [range.enumerate.sentinel]
+  template 
+  class __sentinel;
+
+  template 
+  _LIBCPP_HIDE_FROM_ABI static constexpr decltype(auto) __get_current(const 
__iterator<_AnyConst>& __iter) {
+return (__iter.__current_);
+  }
+
+public:
+  _LIBCPP_HIDE_FROM_ABI constexpr enumerate_view()
+requires(default_initializable<_View>)
+  = default;
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit enumerate_view(_View __base) : 
__base_(std::move(__base)){};
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto begin()
+requires(!__simple_view<_View>)
+  {
+return __iterator(ranges::begin(__base_), 0);
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const
+requires __range_with_movable_references
+  {
+return __iterator(ranges::begin(__base_), 0);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto end()
+requires(!__simple_view<_View>)
+  {
+if constexpr (common_range<_View> && sized_range<_View>)
+  return __iterator(ranges::end(__base_), 
ranges::distance(__base_));
+else
+  return __sentinel(ranges::end(__base_));
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto end() const
+requires __range_with_movable_references
+  {
+if constexpr (common_range && sized_range)
+  return __iterator(ranges::end(__base_), ranges::distance(__base_));
+else
+  return __sentinel(ranges::end(__base_));
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto size()
+requires sized_range<_View>
+  {
+return ranges::size(__base_);
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto size() const
+requires sized_range
+  {
+return ranges::size(__base_);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr _View base() const&
+requires copy_constructible<_View>
+  {
+return __base_;
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); 
}
+};
+
+template 
+enumerate_view(_Range&&) -> enumerate_view>;
+
+// [range.enumerate.iterator]
+
+template 
+  requires __range_with_movable_references<_View>
+template 
+class enumerate_view<_View>::__iterator {
+  using _Base = __maybe_const<_Const, _View>;
+
+  static consteval auto __get_iterator_concept() {
+if constexpr (random_access_range<_Base>) {
+  return random_access_iterator_tag{};
+} else if constexpr (bidirectional_range<_Base>) {
+  return bidirectional_iterator_tag{};
+} else if constexpr (forward_range<_Base>) {
+  return forward_iterator_tag{};
+} else {
+  return input_iterator_tag{};
+}
+  }
+
+  friend class enumerate_view<_View>;
+
+public:
+  using iterator_category = input_iterator_tag;
+  using iterator_concept  = decltype(__get_iterator_concept());
+  using difference_type   = range_difference_t<_Base>;
+  using value_type= tuple>;
+
+private:
+  using __reference_type   = tuple>;
+  iterator_t<_Base> __current_ = iterator_t<_Base>();
+  difference_type __pos_   = 0;
+
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit __iterator(iterator_t<_Base> 
__current, difference_type __pos)
+  : __current_(std::move(__current)), __pos_(__pos) {}
+
+public:
+  _LIBCPP_HIDE_FROM_ABI __iterator()
+requires(default_initializable>)

cjdb wrote:

```suggestion
requires default_initializable>
```

https://github.com/llvm/llvm-project/pull/73617
___
cfe-commits mailing list
cfe-co

[lld] [clang] [flang] [libcxx] [llvm] [clang-tools-extra] [compiler-rt] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,333 @@
+// -*- 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___RANGES_ENUMERATE_VIEW_H
+#define _LIBCPP___RANGES_ENUMERATE_VIEW_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/iter_move.h>
+#include <__iterator/iterator_traits.h>
+#include <__ranges/access.h>
+#include <__ranges/all.h>
+#include <__ranges/concepts.h>
+#include <__ranges/enable_borrowed_range.h>
+#include <__ranges/range_adaptor.h>
+#include <__ranges/size.h>
+#include <__ranges/view_interface.h>
+#include <__type_traits/maybe_const.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+// [concept.object]
+
+template 
+concept __range_with_movable_references =
+ranges::input_range<_Rp> && 
std::move_constructible> &&
+std::move_constructible>;
+
+// [range.enumerate.view]
+
+template 
+  requires __range_with_movable_references<_View>
+class enumerate_view : public view_interface> {
+  _View __base_ = _View();
+
+  // [range.enumerate.iterator]
+  template 
+  class __iterator;
+
+  // [range.enumerate.sentinel]
+  template 
+  class __sentinel;
+
+  template 
+  _LIBCPP_HIDE_FROM_ABI static constexpr decltype(auto) __get_current(const 
__iterator<_AnyConst>& __iter) {
+return (__iter.__current_);
+  }

cjdb wrote:

I'm not sure this function is necessary.

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


[flang] [llvm] [clang-tools-extra] [lld] [libcxx] [compiler-rt] [clang] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// 
+
+// class enumerate_view
+
+// class enumerate_view::iterator
+
+// constexpr auto operator*() const;
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_iterators.h"
+#include "test_macros.h"
+#include "../types.h"
+
+template >
+constexpr void test() {
+  using View  = MinimalView;
+  using EnumerateView = std::ranges::enumerate_view;
+  using EnumerateIterator = std::ranges::iterator_t;
+
+  using Result = std::tuple>>;
+
+  std::array array{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
+
+  View view{Iterator(array.begin()), Sentinel(Iterator(array.end()))};
+  EnumerateView ev{std::move(view)};
+
+  {
+auto it = ev.begin();
+for (std::size_t index = 0; index < array.size(); ++index) {
+  std::same_as decltype(auto) result = *it;
+
+  auto [resultIndex, resultValue] = result;
+  assert(std::cmp_equal(index, resultIndex));
+  assert(array[index] == resultValue);
+
+  ++it;
+}
+
+assert(it == ev.end());
+  }
+
+  // const
+  {
+auto constIt = std::as_const(ev).begin();
+for (std::size_t index = 0; index < array.size(); ++index) {
+  std::same_as decltype(auto) result = *constIt;
+
+  auto [resultIndex, resultValue] = result;
+  assert(std::cmp_equal(index, resultIndex));
+  assert(array[index] == resultValue);
+
+  ++constIt;
+}

cjdb wrote:

Please hand-roll.

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


[compiler-rt] [llvm] [lld] [flang] [clang-tools-extra] [libcxx] [clang] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,114 @@
+//===--===//
+//
+// 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
+
+// 
+
+// class enumerate_view
+
+// constexpr auto end() requires (!simple-view);
+// constexpr auto end() const requires range-with-movable-references;
+
+#include 
+#include 
+#include 
+
+#include "test_iterators.h"
+#include "types.h"
+
+constexpr bool test() {
+  int buff[] = {1, 2, 3, 4, 5, 6, 7, 8};
+
+  // Check the return type of .end()
+  {
+RangeView range(buff, buff + 1);
+
+std::ranges::enumerate_view view(range);
+using Iterator = std::ranges::iterator_t;
+static_assert(std::same_as);
+using Sentinel = std::ranges::sentinel_t;
+static_assert(std::same_as);
+  }
+
+  // Check the return type of .end() const
+  {
+RangeView range(buff, buff + 1);
+
+const std::ranges::enumerate_view view(range);
+using Iterator = std::ranges::iterator_t;
+static_assert(std::same_as);
+using Sentinel = std::ranges::sentinel_t;
+static_assert(std::same_as);
+  }

cjdb wrote:

This feels like it's testing `ranges::iterator_t` and `ranges::sentinel_t` more 
than anything in `enumerate_view`. I think we can remove it, or at least 
condense it to checking that we have a common range in both cases.

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


[lld] [libcxx] [llvm] [clang-tools-extra] [clang] [flang] [compiler-rt] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,333 @@
+// -*- 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___RANGES_ENUMERATE_VIEW_H
+#define _LIBCPP___RANGES_ENUMERATE_VIEW_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/iter_move.h>
+#include <__iterator/iterator_traits.h>
+#include <__ranges/access.h>
+#include <__ranges/all.h>
+#include <__ranges/concepts.h>
+#include <__ranges/enable_borrowed_range.h>
+#include <__ranges/range_adaptor.h>
+#include <__ranges/size.h>
+#include <__ranges/view_interface.h>
+#include <__type_traits/maybe_const.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+// [concept.object]
+
+template 
+concept __range_with_movable_references =
+ranges::input_range<_Rp> && 
std::move_constructible> &&
+std::move_constructible>;
+
+// [range.enumerate.view]
+
+template 
+  requires __range_with_movable_references<_View>
+class enumerate_view : public view_interface> {
+  _View __base_ = _View();
+
+  // [range.enumerate.iterator]
+  template 
+  class __iterator;
+
+  // [range.enumerate.sentinel]
+  template 
+  class __sentinel;
+
+  template 
+  _LIBCPP_HIDE_FROM_ABI static constexpr decltype(auto) __get_current(const 
__iterator<_AnyConst>& __iter) {
+return (__iter.__current_);
+  }
+
+public:
+  _LIBCPP_HIDE_FROM_ABI constexpr enumerate_view()
+requires(default_initializable<_View>)

cjdb wrote:

```suggestion
requires default_initializable<_View>
```

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


[llvm] [libcxx] [compiler-rt] [flang] [clang] [clang-tools-extra] [lld] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,129 @@
+//===--===//
+//
+// 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
+
+// 
+
+// class enumerate_view
+
+// constexpr auto begin() requires (!simple-view);
+// constexpr auto begin() const requires range-with-movable-references;
+
+#include 
+#include 
+#include 
+
+#include "test_iterators.h"
+#include "types.h"
+
+// Helpers
+
+template 
+concept HasConstBegin = requires(const T ct) { ct.begin(); };
+
+template 
+concept HasBegin = requires(T t) { t.begin(); };
+
+template 
+concept HasConstAndNonConstBegin =
+HasConstBegin &&
+// Because const begin() and non-const begin() returns different types: 
iterator vs. iterator
+requires(T t, const T ct) { requires !std::same_as; };
+
+template 
+concept HasOnlyNonConstBegin = HasBegin && !HasConstBegin;
+
+template 
+concept HasOnlyConstBegin = HasConstBegin && !HasConstAndNonConstBegin;
+
+// Types
+
+template 
+struct CommonView : std::ranges::view_base {
+  constexpr std::tuple* begin()
+requires(!Simple)
+  {
+return nullptr;
+  }
+  constexpr const std::tuple* begin() const { return 
nullptr; }
+  constexpr std::tuple* end()
+requires(!Simple)
+  {
+return nullptr;
+  }
+  constexpr const std::tuple* end() const { return 
nullptr; }
+};
+using SimpleCommonView= CommonView;
+using NonSimpleCommonView = CommonView;
+
+struct NoConstBeginView : std::ranges::view_base {
+  constexpr std::tuple* begin() { return nullptr; }
+  constexpr std::tuple* end() { return nullptr; }
+};
+
+// SFINAE
+
+// simple-view
+static_assert(HasOnlyConstBegin>);
+
+// !simple-view && range
+static_assert(HasConstAndNonConstBegin>);
+
+// !range
+static_assert(HasOnlyNonConstBegin>);
+
+constexpr bool test() {
+  int buff[] = {1, 2, 3, 4, 5, 6, 7, 8};
+
+  // Check the return type of begin()
+  {
+RangeView range(buff, buff + 1);
+
+std::ranges::enumerate_view view(range);
+using Iterator = std::ranges::iterator_t;
+static_assert(std::same_as);
+  }

cjdb wrote:

This feels like it's testing `ranges::iterator_t` more than `view.begin()`.

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


[libcxx] [llvm] [lld] [flang] [clang-tools-extra] [clang] [compiler-rt] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,107 @@
+//===--===//
+//
+// 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
+
+// 
+
+// class enumerate_view
+
+// class enumerate_view::iterator
+
+// friend constexpr strong_ordering operator<=>(const iterator& x, const 
iterator& y) noexcept;
+
+#include 
+#include 
+
+#include "test_iterators.h"
+#include "../types.h"
+
+constexpr void compareOperatorTest(const auto& iter1, const auto& iter2) {
+  assert(!(iter1 < iter1));
+  assert(iter1 < iter2);
+  assert(!(iter2 < iter1));
+
+  assert(iter1 <= iter1);
+  assert(iter1 <= iter2);
+  assert(!(iter2 <= iter1));
+
+  assert(!(iter1 > iter1));
+  assert(!(iter1 > iter2));
+  assert(iter2 > iter1);
+
+  assert(iter1 >= iter1);
+  assert(!(iter1 >= iter2));
+  assert(iter2 >= iter1);
+
+  assert(iter1 == iter1);
+  assert(!(iter1 == iter2));
+  assert(iter2 == iter2);
+
+  assert(!(iter1 != iter1));
+  assert(iter1 != iter2);
+  assert(!(iter2 != iter2));
+}
+
+constexpr bool test() {
+  int buff[] = {0, 1, 2, 3};
+  {
+using View = std::ranges::enumerate_view;
+
+using Iterator = std::ranges::iterator_t;
+static_assert(std::three_way_comparable);
+using Subrange = std::ranges::subrange;
+
static_assert(std::three_way_comparable>);
+using EnumerateView = std::ranges::enumerate_view;
+
static_assert(std::three_way_comparable>);
+
+RangeView const range(buff, buff + 4);
+
+std::same_as decltype(auto) ev = std::views::enumerate(range);
+
+auto it1 = ev.begin();
+auto it2 = it1 + 1;

cjdb wrote:

Please const-qualify (I'm specifically calling these out because the interface 
requires them to be `const`-qualified).

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


[llvm] [lld] [libcxx] [compiler-rt] [clang-tools-extra] [clang] [flang] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,333 @@
+// -*- 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___RANGES_ENUMERATE_VIEW_H
+#define _LIBCPP___RANGES_ENUMERATE_VIEW_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/iter_move.h>
+#include <__iterator/iterator_traits.h>
+#include <__ranges/access.h>
+#include <__ranges/all.h>
+#include <__ranges/concepts.h>
+#include <__ranges/enable_borrowed_range.h>
+#include <__ranges/range_adaptor.h>
+#include <__ranges/size.h>
+#include <__ranges/view_interface.h>
+#include <__type_traits/maybe_const.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+// [concept.object]
+
+template 
+concept __range_with_movable_references =
+ranges::input_range<_Rp> && 
std::move_constructible> &&
+std::move_constructible>;
+
+// [range.enumerate.view]
+
+template 
+  requires __range_with_movable_references<_View>
+class enumerate_view : public view_interface> {
+  _View __base_ = _View();
+
+  // [range.enumerate.iterator]
+  template 
+  class __iterator;
+
+  // [range.enumerate.sentinel]
+  template 
+  class __sentinel;
+
+  template 
+  _LIBCPP_HIDE_FROM_ABI static constexpr decltype(auto) __get_current(const 
__iterator<_AnyConst>& __iter) {
+return (__iter.__current_);
+  }
+
+public:
+  _LIBCPP_HIDE_FROM_ABI constexpr enumerate_view()
+requires(default_initializable<_View>)
+  = default;
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit enumerate_view(_View __base) : 
__base_(std::move(__base)){};
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto begin()
+requires(!__simple_view<_View>)
+  {
+return __iterator(ranges::begin(__base_), 0);
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const
+requires __range_with_movable_references
+  {
+return __iterator(ranges::begin(__base_), 0);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto end()
+requires(!__simple_view<_View>)
+  {
+if constexpr (common_range<_View> && sized_range<_View>)
+  return __iterator(ranges::end(__base_), 
ranges::distance(__base_));
+else
+  return __sentinel(ranges::end(__base_));
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto end() const
+requires __range_with_movable_references
+  {
+if constexpr (common_range && sized_range)
+  return __iterator(ranges::end(__base_), ranges::distance(__base_));
+else
+  return __sentinel(ranges::end(__base_));
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto size()
+requires sized_range<_View>
+  {
+return ranges::size(__base_);
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto size() const
+requires sized_range
+  {
+return ranges::size(__base_);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr _View base() const&
+requires copy_constructible<_View>
+  {
+return __base_;
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); 
}
+};
+
+template 
+enumerate_view(_Range&&) -> enumerate_view>;
+
+// [range.enumerate.iterator]
+
+template 
+  requires __range_with_movable_references<_View>
+template 
+class enumerate_view<_View>::__iterator {
+  using _Base = __maybe_const<_Const, _View>;
+
+  static consteval auto __get_iterator_concept() {
+if constexpr (random_access_range<_Base>) {
+  return random_access_iterator_tag{};
+} else if constexpr (bidirectional_range<_Base>) {
+  return bidirectional_iterator_tag{};
+} else if constexpr (forward_range<_Base>) {
+  return forward_iterator_tag{};
+} else {
+  return input_iterator_tag{};
+}
+  }
+
+  friend class enumerate_view<_View>;
+
+public:
+  using iterator_category = input_iterator_tag;
+  using iterator_concept  = decltype(__get_iterator_concept());
+  using difference_type   = range_difference_t<_Base>;
+  using value_type= tuple>;
+
+private:
+  using __reference_type   = tuple>;
+  iterator_t<_Base> __current_ = iterator_t<_Base>();
+  difference_type __pos_   = 0;
+
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit __iterator(iterator_t<_Base> 
__current, difference_type __pos)
+  : __current_(std::move(__current)), __pos_(__pos) {}
+
+public:
+  _LIBCPP_HIDE_FROM_ABI __iterator()
+requires(default_initializable>)
+  = default;
+  _LIBCPP_HIDE_FROM_ABI constexpr __iterator(__iterator __i)
+requires _Const && convertible_to, iterator_t<_Base>>
+  : __current_(std::move(__i.__current_)), __pos_(__i.__pos_) {}
+
+  _L

[lld] [compiler-rt] [clang] [libcxx] [llvm] [clang-tools-extra] [flang] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,107 @@
+//===--===//
+//
+// 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
+
+// 
+
+// class enumerate_view
+
+// class enumerate_view::iterator
+
+// friend constexpr strong_ordering operator<=>(const iterator& x, const 
iterator& y) noexcept;
+
+#include 
+#include 
+
+#include "test_iterators.h"
+#include "../types.h"
+
+constexpr void compareOperatorTest(const auto& iter1, const auto& iter2) {
+  assert(!(iter1 < iter1));
+  assert(iter1 < iter2);
+  assert(!(iter2 < iter1));
+
+  assert(iter1 <= iter1);
+  assert(iter1 <= iter2);
+  assert(!(iter2 <= iter1));
+
+  assert(!(iter1 > iter1));
+  assert(!(iter1 > iter2));
+  assert(iter2 > iter1);
+
+  assert(iter1 >= iter1);
+  assert(!(iter1 >= iter2));
+  assert(iter2 >= iter1);
+
+  assert(iter1 == iter1);
+  assert(!(iter1 == iter2));
+  assert(iter2 == iter2);
+
+  assert(!(iter1 != iter1));
+  assert(iter1 != iter2);
+  assert(!(iter2 != iter2));
+}
+
+constexpr bool test() {
+  int buff[] = {0, 1, 2, 3};

cjdb wrote:

Same as before: we should have multiple categories of range being tested.

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


[clang-tools-extra] [compiler-rt] [clang] [flang] [lld] [llvm] [libcxx] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-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
+
+// 
+
+// class enumerate_view
+
+// class enumerate_view::iterator
+
+// friend constexpr auto iter_move(const iterator& i)
+//   noexcept(noexcept(ranges::iter_move(i.current_)) &&
+// 
is_nothrow_move_constructible_v>);
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_iterators.h"
+#include "../types.h"
+
+template 
+constexpr void test() {
+  using Sentinel  = sentinel_wrapper;
+  using View  = MinimalView;
+  using EnumerateView = std::ranges::enumerate_view;
+  using EnumerateIterator = std::ranges::iterator_t;
+
+  std::array array{0, 1, 2, 3, 4};
+
+  View view{Iterator(array.begin()), Sentinel(Iterator(array.end()))};
+  EnumerateView ev{std::move(view)};
+  EnumerateIterator const it = ev.begin();
+
+  auto&& result = iter_move(it);
+
+  static_assert(std::is_same_v::difference_type, int&&>&&>);

cjdb wrote:

Consider using `ranges::range_difference_t`.

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


[libcxx] [clang-tools-extra] [flang] [compiler-rt] [llvm] [clang] [lld] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,95 @@
+//===--===//
+//
+// 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
+
+// 
+
+// class enumerate_view
+
+// class enumerate_view::iterator
+
+// constexpr difference_type index() const noexcept;
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_iterators.h"
+#include "test_macros.h"
+#include "../types.h"
+
+template >
+constexpr void test() {
+  using View  = MinimalView;
+  using EnumerateView = std::ranges::enumerate_view;
+
+  std::array array{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
+
+  View view{Iterator(array.begin()), Sentinel(Iterator(array.end()))};
+  EnumerateView ev(std::move(view));
+
+  {
+auto it = ev.begin();
+ASSERT_NOEXCEPT(it.index());
+
+static_assert(std::same_as);
+for (std::size_t index = 0; index < array.size(); ++index) {
+  assert(std::cmp_equal(index, it.index()));
+
+  ++it;
+}

cjdb wrote:

Please hand-roll.

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


[llvm] [clang] [libcxx] [clang-tools-extra] [compiler-rt] [lld] [flang] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,77 @@
+//===--===//
+//
+// 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
+
+// 
+
+// class enumerate_view
+
+// class enumerate_view::iterator
+
+// constexpr auto operator[](difference_type n) const
+//   requires random_access_range;
+
+#include 
+#include 
+#include 
+#include 
+
+#include "test_iterators.h"
+
+template 
+concept HasSubscriptOperator = requires(T t, U u) { t[u]; };
+
+template 
+using EnumerateIterator = 
std::ranges::iterator_t>;
+
+using RandomAccessRange = std::ranges::subrange;
+static_assert(std::ranges::random_access_range);
+
+static_assert(HasSubscriptOperator, int>);
+
+using BidirectionalRange = std::ranges::subrange>;
+static_assert(!std::ranges::random_access_range);
+
+static_assert(!HasSubscriptOperator, 
int>);
+
+constexpr bool test() {
+  // Reference
+  {
+std::array ts = {0, 1, 2, 3, 84};
+auto view = ts | std::views::enumerate;
+auto it   = view.begin();
+
+for (std::size_t index = 0; index != ts.size(); ++index) {
+  assert(it[index] == *(it + index));
+}
+
+static_assert(std::is_same_v>);
+  }
+
+  // Value
+  {
+auto view = std::views::iota(0, 5) | std::views::enumerate;
+auto it   = view.begin();
+
+for (std::size_t index = 0; index != 5; ++index) {
+  assert(it[index] == *(it + index));
+}
+
+static_assert(std::is_same_v>);

cjdb wrote:

Consider using `std::iter_difference_t`.

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


[libcxx] [compiler-rt] [llvm] [flang] [lld] [clang-tools-extra] [clang] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-02 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,104 @@
+//===--===//
+//
+// 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
+
+// 
+
+// class enumerate_view
+
+// class enumerate_view::iterator
+
+// std::enumerate_viewdifference_type;
+// std::enumerate_viewvalue_type;
+// std::enumerate_viewiterator_category;
+// std::enumerate_viewiterator_concept;
+
+#include 
+
+#include 
+#include "test_iterators.h"
+#include "../types.h"
+
+template 
+concept HasIteratorCategory = requires { typename T::iterator_category; };
+
+template 
+using EnumerateViewFor = std::ranges::enumerate_view< MinimalView>>;
+
+template 
+using EnumerateIteratorFor = 
std::ranges::iterator_t>;
+
+struct ForwardIteratorWithInputCategory {
+  using difference_type   = int;
+  using value_type= int;
+  using iterator_category = std::input_iterator_tag;
+  using iterator_concept  = std::forward_iterator_tag;
+  ForwardIteratorWithInputCategory();
+  ForwardIteratorWithInputCategory& operator++();
+  ForwardIteratorWithInputCategory operator++(int);
+  int& operator*() const;
+  friend bool operator==(ForwardIteratorWithInputCategory, 
ForwardIteratorWithInputCategory);
+};
+static_assert(std::forward_iterator);
+
+constexpr void test() {
+  // Check that value_type is range_value_t and difference_type is 
range_difference_t
+  {
+auto test = [] {
+  using EnumerateView = EnumerateViewFor;
+  using EnumerateIterator = EnumerateIteratorFor;
+  static_assert(std::is_same_v>);
+  static_assert(
+  std::is_same_v>);
+};
+test.operator()>();
+test.operator()>();
+test.operator()>();
+test.operator()>();
+test.operator()>();
+test.operator()>();
+test.operator()();

cjdb wrote:

Please turn `test` into a function template instead of a lambda template. It 
lends itself to a nicer syntax.

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


[libcxx] [compiler-rt] [flang] [clang-tools-extra] [llvm] [lld] [clang] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-03 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,333 @@
+// -*- 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___RANGES_ENUMERATE_VIEW_H
+#define _LIBCPP___RANGES_ENUMERATE_VIEW_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/iter_move.h>
+#include <__iterator/iterator_traits.h>
+#include <__ranges/access.h>
+#include <__ranges/all.h>
+#include <__ranges/concepts.h>
+#include <__ranges/enable_borrowed_range.h>
+#include <__ranges/range_adaptor.h>
+#include <__ranges/size.h>
+#include <__ranges/view_interface.h>
+#include <__type_traits/maybe_const.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+// [concept.object]
+
+template 
+concept __range_with_movable_references =
+ranges::input_range<_Rp> && 
std::move_constructible> &&
+std::move_constructible>;
+
+// [range.enumerate.view]
+
+template 
+  requires __range_with_movable_references<_View>
+class enumerate_view : public view_interface> {
+  _View __base_ = _View();
+
+  // [range.enumerate.iterator]
+  template 
+  class __iterator;
+
+  // [range.enumerate.sentinel]
+  template 
+  class __sentinel;
+
+  template 
+  _LIBCPP_HIDE_FROM_ABI static constexpr decltype(auto) __get_current(const 
__iterator<_AnyConst>& __iter) {
+return (__iter.__current_);
+  }
+
+public:
+  _LIBCPP_HIDE_FROM_ABI constexpr enumerate_view()
+requires(default_initializable<_View>)
+  = default;
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit enumerate_view(_View __base) : 
__base_(std::move(__base)){};
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto begin()
+requires(!__simple_view<_View>)
+  {
+return __iterator(ranges::begin(__base_), 0);
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const
+requires __range_with_movable_references
+  {
+return __iterator(ranges::begin(__base_), 0);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto end()
+requires(!__simple_view<_View>)
+  {
+if constexpr (common_range<_View> && sized_range<_View>)
+  return __iterator(ranges::end(__base_), 
ranges::distance(__base_));
+else
+  return __sentinel(ranges::end(__base_));
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto end() const
+requires __range_with_movable_references
+  {
+if constexpr (common_range && sized_range)
+  return __iterator(ranges::end(__base_), ranges::distance(__base_));
+else
+  return __sentinel(ranges::end(__base_));
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto size()
+requires sized_range<_View>
+  {
+return ranges::size(__base_);
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto size() const
+requires sized_range
+  {
+return ranges::size(__base_);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr _View base() const&
+requires copy_constructible<_View>
+  {
+return __base_;
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); 
}
+};
+
+template 
+enumerate_view(_Range&&) -> enumerate_view>;
+
+// [range.enumerate.iterator]
+
+template 
+  requires __range_with_movable_references<_View>
+template 
+class enumerate_view<_View>::__iterator {
+  using _Base = __maybe_const<_Const, _View>;
+
+  static consteval auto __get_iterator_concept() {
+if constexpr (random_access_range<_Base>) {
+  return random_access_iterator_tag{};
+} else if constexpr (bidirectional_range<_Base>) {
+  return bidirectional_iterator_tag{};
+} else if constexpr (forward_range<_Base>) {
+  return forward_iterator_tag{};
+} else {
+  return input_iterator_tag{};
+}
+  }
+
+  friend class enumerate_view<_View>;
+
+public:
+  using iterator_category = input_iterator_tag;
+  using iterator_concept  = decltype(__get_iterator_concept());
+  using difference_type   = range_difference_t<_Base>;
+  using value_type= tuple>;
+
+private:
+  using __reference_type   = tuple>;
+  iterator_t<_Base> __current_ = iterator_t<_Base>();
+  difference_type __pos_   = 0;
+
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit __iterator(iterator_t<_Base> 
__current, difference_type __pos)
+  : __current_(std::move(__current)), __pos_(__pos) {}
+
+public:
+  _LIBCPP_HIDE_FROM_ABI __iterator()
+requires(default_initializable>)
+  = default;
+  _LIBCPP_HIDE_FROM_ABI constexpr __iterator(__iterator __i)
+requires _Const && convertible_to, iterator_t<_Base>>
+  : __current_(std::move(__i.__current_)), __pos_(__i.__pos_) {}
+
+  _L

[libcxx] [compiler-rt] [flang] [clang-tools-extra] [llvm] [lld] [clang] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-03 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,333 @@
+// -*- 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___RANGES_ENUMERATE_VIEW_H
+#define _LIBCPP___RANGES_ENUMERATE_VIEW_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/iter_move.h>
+#include <__iterator/iterator_traits.h>
+#include <__ranges/access.h>
+#include <__ranges/all.h>
+#include <__ranges/concepts.h>
+#include <__ranges/enable_borrowed_range.h>
+#include <__ranges/range_adaptor.h>
+#include <__ranges/size.h>
+#include <__ranges/view_interface.h>
+#include <__type_traits/maybe_const.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+// [concept.object]
+
+template 
+concept __range_with_movable_references =
+ranges::input_range<_Rp> && 
std::move_constructible> &&
+std::move_constructible>;
+
+// [range.enumerate.view]
+
+template 
+  requires __range_with_movable_references<_View>
+class enumerate_view : public view_interface> {
+  _View __base_ = _View();
+
+  // [range.enumerate.iterator]
+  template 
+  class __iterator;
+
+  // [range.enumerate.sentinel]
+  template 
+  class __sentinel;
+
+  template 
+  _LIBCPP_HIDE_FROM_ABI static constexpr decltype(auto) __get_current(const 
__iterator<_AnyConst>& __iter) {
+return (__iter.__current_);
+  }
+
+public:
+  _LIBCPP_HIDE_FROM_ABI constexpr enumerate_view()
+requires(default_initializable<_View>)
+  = default;
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit enumerate_view(_View __base) : 
__base_(std::move(__base)){};
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto begin()
+requires(!__simple_view<_View>)
+  {
+return __iterator(ranges::begin(__base_), 0);
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const
+requires __range_with_movable_references
+  {
+return __iterator(ranges::begin(__base_), 0);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto end()
+requires(!__simple_view<_View>)
+  {
+if constexpr (common_range<_View> && sized_range<_View>)
+  return __iterator(ranges::end(__base_), 
ranges::distance(__base_));
+else
+  return __sentinel(ranges::end(__base_));
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto end() const
+requires __range_with_movable_references
+  {
+if constexpr (common_range && sized_range)
+  return __iterator(ranges::end(__base_), ranges::distance(__base_));
+else
+  return __sentinel(ranges::end(__base_));
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto size()
+requires sized_range<_View>
+  {
+return ranges::size(__base_);
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto size() const
+requires sized_range
+  {
+return ranges::size(__base_);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr _View base() const&
+requires copy_constructible<_View>
+  {
+return __base_;
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); 
}
+};
+
+template 
+enumerate_view(_Range&&) -> enumerate_view>;
+
+// [range.enumerate.iterator]
+
+template 
+  requires __range_with_movable_references<_View>
+template 
+class enumerate_view<_View>::__iterator {
+  using _Base = __maybe_const<_Const, _View>;
+
+  static consteval auto __get_iterator_concept() {
+if constexpr (random_access_range<_Base>) {
+  return random_access_iterator_tag{};
+} else if constexpr (bidirectional_range<_Base>) {
+  return bidirectional_iterator_tag{};
+} else if constexpr (forward_range<_Base>) {
+  return forward_iterator_tag{};
+} else {
+  return input_iterator_tag{};
+}
+  }
+
+  friend class enumerate_view<_View>;
+
+public:
+  using iterator_category = input_iterator_tag;
+  using iterator_concept  = decltype(__get_iterator_concept());
+  using difference_type   = range_difference_t<_Base>;
+  using value_type= tuple>;
+
+private:
+  using __reference_type   = tuple>;
+  iterator_t<_Base> __current_ = iterator_t<_Base>();
+  difference_type __pos_   = 0;
+
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit __iterator(iterator_t<_Base> 
__current, difference_type __pos)
+  : __current_(std::move(__current)), __pos_(__pos) {}
+
+public:
+  _LIBCPP_HIDE_FROM_ABI __iterator()
+requires(default_initializable>)
+  = default;
+  _LIBCPP_HIDE_FROM_ABI constexpr __iterator(__iterator __i)
+requires _Const && convertible_to, iterator_t<_Base>>
+  : __current_(std::move(__i.__current_)), __pos_(__i.__pos_) {}
+
+  _L

[libcxx] [compiler-rt] [flang] [clang-tools-extra] [llvm] [lld] [clang] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-03 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,333 @@
+// -*- 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___RANGES_ENUMERATE_VIEW_H
+#define _LIBCPP___RANGES_ENUMERATE_VIEW_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/iter_move.h>
+#include <__iterator/iterator_traits.h>
+#include <__ranges/access.h>
+#include <__ranges/all.h>
+#include <__ranges/concepts.h>
+#include <__ranges/enable_borrowed_range.h>
+#include <__ranges/range_adaptor.h>
+#include <__ranges/size.h>
+#include <__ranges/view_interface.h>
+#include <__type_traits/maybe_const.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+// [concept.object]
+
+template 
+concept __range_with_movable_references =
+ranges::input_range<_Rp> && 
std::move_constructible> &&
+std::move_constructible>;
+
+// [range.enumerate.view]
+
+template 
+  requires __range_with_movable_references<_View>
+class enumerate_view : public view_interface> {
+  _View __base_ = _View();
+
+  // [range.enumerate.iterator]
+  template 
+  class __iterator;
+
+  // [range.enumerate.sentinel]
+  template 
+  class __sentinel;
+
+  template 
+  _LIBCPP_HIDE_FROM_ABI static constexpr decltype(auto) __get_current(const 
__iterator<_AnyConst>& __iter) {
+return (__iter.__current_);
+  }
+
+public:
+  _LIBCPP_HIDE_FROM_ABI constexpr enumerate_view()
+requires(default_initializable<_View>)
+  = default;
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit enumerate_view(_View __base) : 
__base_(std::move(__base)){};
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto begin()
+requires(!__simple_view<_View>)
+  {
+return __iterator(ranges::begin(__base_), 0);
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const
+requires __range_with_movable_references
+  {
+return __iterator(ranges::begin(__base_), 0);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto end()
+requires(!__simple_view<_View>)
+  {
+if constexpr (common_range<_View> && sized_range<_View>)
+  return __iterator(ranges::end(__base_), 
ranges::distance(__base_));
+else
+  return __sentinel(ranges::end(__base_));
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto end() const
+requires __range_with_movable_references
+  {
+if constexpr (common_range && sized_range)
+  return __iterator(ranges::end(__base_), ranges::distance(__base_));
+else
+  return __sentinel(ranges::end(__base_));
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto size()
+requires sized_range<_View>
+  {
+return ranges::size(__base_);
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto size() const
+requires sized_range
+  {
+return ranges::size(__base_);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr _View base() const&
+requires copy_constructible<_View>
+  {
+return __base_;
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); 
}
+};
+
+template 
+enumerate_view(_Range&&) -> enumerate_view>;
+
+// [range.enumerate.iterator]
+
+template 
+  requires __range_with_movable_references<_View>
+template 
+class enumerate_view<_View>::__iterator {
+  using _Base = __maybe_const<_Const, _View>;
+
+  static consteval auto __get_iterator_concept() {
+if constexpr (random_access_range<_Base>) {
+  return random_access_iterator_tag{};
+} else if constexpr (bidirectional_range<_Base>) {
+  return bidirectional_iterator_tag{};
+} else if constexpr (forward_range<_Base>) {
+  return forward_iterator_tag{};
+} else {
+  return input_iterator_tag{};
+}
+  }
+
+  friend class enumerate_view<_View>;
+
+public:
+  using iterator_category = input_iterator_tag;
+  using iterator_concept  = decltype(__get_iterator_concept());
+  using difference_type   = range_difference_t<_Base>;
+  using value_type= tuple>;
+
+private:
+  using __reference_type   = tuple>;
+  iterator_t<_Base> __current_ = iterator_t<_Base>();
+  difference_type __pos_   = 0;
+
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit __iterator(iterator_t<_Base> 
__current, difference_type __pos)
+  : __current_(std::move(__current)), __pos_(__pos) {}
+
+public:
+  _LIBCPP_HIDE_FROM_ABI __iterator()
+requires(default_initializable>)
+  = default;
+  _LIBCPP_HIDE_FROM_ABI constexpr __iterator(__iterator __i)
+requires _Const && convertible_to, iterator_t<_Base>>
+  : __current_(std::move(__i.__current_)), __pos_(__i.__pos_) {}
+
+  _L

[libcxx] [compiler-rt] [flang] [clang-tools-extra] [llvm] [lld] [clang] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-03 Thread Christopher Di Bella via cfe-commits

https://github.com/cjdb edited https://github.com/llvm/llvm-project/pull/73617
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] [clang] [clang-tools-extra] [compiler-rt] [llvm] [flang] [lldb] [libunwind] [libc] [libc++] Implement ranges::iota (PR #68494)

2024-01-05 Thread Christopher Di Bella via cfe-commits


@@ -13,7 +13,7 @@
 // Range algorithms should return `std::ranges::dangling` when given a 
dangling range.
 

cjdb wrote:

Please revert and apply in a separate patch.

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


[clang] [lldb] [llvm] [compiler-rt] [libcxx] [libc] [clang-tools-extra] [flang] [libunwind] [libc++] Implement ranges::iota (PR #68494)

2024-01-05 Thread Christopher Di Bella via cfe-commits

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

Thanks for working on this, it's an important algorithm to have. I've left some 
comments, but would like to see this merged by the end of January.

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


[flang] [clang] [lldb] [libcxx] [libc] [libunwind] [llvm] [clang-tools-extra] [compiler-rt] [libc++] Implement ranges::iota (PR #68494)

2024-01-05 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,171 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// Testing std::ranges::iota
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+#include 
+#include 
+#include 
+#include 
+#include  // TODO RM
+
+#include "test_macros.h"
+#include "test_iterators.h"
+#include "almost_satisfies_types.h"
+
+//
+// Testing constraints
+//
+
+// Concepts to check different overloads of std::ranges::iota
+template 
+concept HasIotaIter = requires(Iter&& iter, Sent&& sent, Value&& val) {
+  std::ranges::iota(std::forward(iter), std::forward(sent), 
std::forward(val));
+};
+
+template 
+concept HasIotaRange =
+requires(Range&& range, Value&& val) { 
std::ranges::iota(std::forward(range), std::forward(val)); };
+
+// Test constraints of the iterator/sentinel overload
+// ==
+static_assert(HasIotaIter);
+
+// !input_or_output_iterator
+static_assert(!HasIotaIter);
+
+// !sentinel_for
+static_assert(!HasIotaIter);
+static_assert(!HasIotaIter);
+
+// !weakly_incrementable
+static_assert(!HasIotaIter);
+
+// !indirectly writable 
+static_assert(!HasIotaIter);
+
+// Test constraints for the range overload
+// ===
+static_assert(HasIotaRange, int>);
+
+// !weakly_incrementable
+static_assert(!HasIotaRange, 
WeaklyIncrementableNotMovable>);
+
+// !ranges::output_range
+static_assert(!HasIotaRange, 
OutputIteratorNotIndirectlyWritable>);
+
+//
+// Testing results
+//
+
+struct DangerousCopyAssign {
+  int val;
+  using difference_type = int;
+
+  constexpr explicit DangerousCopyAssign(int v) : val(v) {}
+
+  // Needed in postfix
+  constexpr DangerousCopyAssign(DangerousCopyAssign const& other) { this->val 
= other.val; }
+
+  // mischievious copy assignment that we won't use if the
+  // std::as_const inside ranges::iota isn't working, this should perturb the
+  // results
+  constexpr DangerousCopyAssign& operator=(DangerousCopyAssign& a) {
+++a.val;
+this->val = a.val;
+return *this;
+  }
+
+  // safe copy assignment std::as_const inside ranges::iota should ensure this
+  // overload gets called
+  constexpr DangerousCopyAssign& operator=(DangerousCopyAssign const& a) {
+this->val = a.val;
+return *this;
+  }
+
+  constexpr bool operator==(DangerousCopyAssign const& rhs) { return this->val 
== rhs.val; }
+
+  // prefix
+  constexpr DangerousCopyAssign& operator++() {
+++(this->val);
+return *this;
+  }
+
+  // postfix
+  constexpr DangerousCopyAssign operator++(int) {
+auto tmp = *this;
+++this->val;
+return tmp;
+  }
+};
+
+template 
+constexpr void test_result(std::array input, T starting_value, 
std::array const expected) {
+  { // (iterator, sentinel) overload
+auto in_begin = Iter(input.data());
+auto in_end   = Sent(Iter(input.data() + input.size()));
+std::same_as> decltype(auto) result 
=
+std::ranges::iota(std::move(in_begin), std::move(in_end), 
starting_value);
+assert(result.out == in_end);
+if constexpr (expected.size() > 0) {
+  assert(result.value == expected.back() + 1);
+} else {
+  assert(result.value == starting_value);
+}
+assert(std::ranges::equal(input, expected));
+  }
+
+  // The range overload adds the additional constraint that it must be an 
outputrange
+  // so skip this for the input iterators we test
+  if constexpr (!std::is_same_v> &&
+!std::is_same_v>) { // (range) 
overload
+auto in_begin = Iter(input.data());
+auto in_end   = Sent(Iter(input.data() + input.size()));
+auto range= std::ranges::subrange(std::move(in_begin), 
std::move(in_end));
+
+std::same_as> decltype(auto) result 
=
+std::ranges::iota(range, starting_value);
+assert(result.out == in_end);
+assert(result.value == starting_value + N);
+assert(std::ranges::equal(input, expected));
+  }

cjdb wrote:

Please move this conditional logic into a separate test case.

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


[libunwind] [lldb] [flang] [libc] [llvm] [clang-tools-extra] [clang] [libcxx] [compiler-rt] [libc++] Implement ranges::iota (PR #68494)

2024-01-05 Thread Christopher Di Bella via cfe-commits


@@ -1083,6 +1083,27 @@ rvalue_iterator(T*) -> rvalue_iterator;
 
 static_assert(std::random_access_iterator>);
 
+// The ProxyDiffTBase allows us to conditionally specify 
Proxy::difference_type
+// which we need in certain situations. For example when we want
+// std::weakly_incrementable> to be true.
+template 
+struct ProxyDiffTBase {};
+
+template 
+  requires requires { std::iter_difference_t{}; }
+struct ProxyDiffTBase {
+  using difference_type = std::iter_difference_t;
+};
+
+// These concepts allow us to conditionally add the pre-/postfix operators
+// when T also supports those member functions. Like ProxyDiffTBase, this
+// is necessary when we want std::weakly_incrementable> to be true.
+template 
+concept HasPreIncrementOp = requires(T const& obj) { ++obj; };
+
+template 
+concept HasPostIncrementOp = requires(T const& obj) { obj++; };
+

cjdb wrote:

These may be better off in a local header, since they're very 
`ranges::iota`-specific.

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


[libunwind] [clang] [clang-tools-extra] [llvm] [flang] [compiler-rt] [libcxx] [libc] [lldb] [libc++] Implement ranges::iota (PR #68494)

2024-01-05 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,71 @@
+// -*- 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_RANGES_IOTA_H
+#define _LIBCPP___NUMERIC_RANGES_IOTA_H
+
+#include <__algorithm/out_value_result.h>
+#include <__config>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__ranges/dangling.h>
+#include <__utility/as_const.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+namespace ranges {
+template 
+using iota_result = ranges::out_value_result<_Out, _Tp>;
+
+namespace __ranges_iota {

cjdb wrote:

This namespace isn't necessary, and I'm working on a patch to remove the ones 
that are already checked in. Since this patch is happening concurrently, would 
you mind removing this namespace here?

Alternatively, you can track #76543 and hold off removing this until that lands 
in main.

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


[clang-tools-extra] [flang] [libunwind] [libc] [llvm] [lldb] [libcxx] [compiler-rt] [clang] [libc++] Implement ranges::iota (PR #68494)

2024-01-05 Thread Christopher Di Bella via cfe-commits


@@ -1149,9 +1171,11 @@ struct Proxy {
   // Calling swap(Proxy{}, Proxy{}) would fail (pass prvalues)
 
   // Compare operators are defined for the convenience of the tests
-  friend constexpr bool operator==(const Proxy&, const Proxy&)
-requires (std::equality_comparable && !std::is_reference_v)
-  = default;
+  friend constexpr bool operator==(const Proxy& lhs, const Proxy& rhs)
+requires(std::equality_comparable && !std::is_reference_v)
+  {
+return lhs.data == rhs.data;
+  };

cjdb wrote:

What is the intention of this change?

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


[flang] [libcxx] [libc] [clang-tools-extra] [llvm] [libunwind] [lldb] [clang] [compiler-rt] [libc++] Implement ranges::iota (PR #68494)

2024-01-05 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,71 @@
+// -*- 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_RANGES_IOTA_H
+#define _LIBCPP___NUMERIC_RANGES_IOTA_H
+
+#include <__algorithm/out_value_result.h>
+#include <__config>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__ranges/dangling.h>
+#include <__utility/as_const.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+namespace ranges {
+template 
+using iota_result = ranges::out_value_result<_Out, _Tp>;
+
+namespace __ranges_iota {
+struct __iota_fn {
+private:
+  // Private helper function
+  template 
+  _LIBCPP_HIDE_FROM_ABI static constexpr iota_result<_Out, _Tp> 
__iota_impl(_Out __first, _Sent __last, _Tp __value) {
+while (__first != __last) {
+  *__first = std::as_const(__value);
+  ++__first;
+  ++__value;
+}
+return {std::move(__first), std::move(__value)};
+  }
+
+public:
+  // Public facing interfaces
+  template  _Sent, 
weakly_incrementable _Tp>
+requires indirectly_writable<_Out, const _Tp&>
+  _LIBCPP_HIDE_FROM_ABI static constexpr iota_result<_Out, _Tp> 
operator()(_Out __first, _Sent __last, _Tp __value) {
+return __iota_impl(std::move(__first), std::move(__last), 
std::move(__value));
+  }
+
+  template  _Range>
+  _LIBCPP_HIDE_FROM_ABI static constexpr 
iota_result, _Tp>
+  operator()(_Range&& __r, _Tp __value) {
+return __iota_impl(ranges::begin(__r), ranges::end(__r), 
std::move(__value));
+  }
+};
+} // namespace __ranges_iota
+
+inline namespace __cpo {

cjdb wrote:

Similar to the `__iota` namespace, this is likely going to be removed. Please 
track the discussion in #76542.

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


[libcxx] [compiler-rt] [clang-tools-extra] [libc] [clang] [flang] [lldb] [llvm] [libunwind] [libc++] Implement ranges::iota (PR #68494)

2024-01-05 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,171 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// Testing std::ranges::iota
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+#include 
+#include 
+#include 
+#include 
+#include  // TODO RM
+
+#include "test_macros.h"
+#include "test_iterators.h"
+#include "almost_satisfies_types.h"
+
+//
+// Testing constraints
+//
+
+// Concepts to check different overloads of std::ranges::iota
+template 
+concept HasIotaIter = requires(Iter&& iter, Sent&& sent, Value&& val) {
+  std::ranges::iota(std::forward(iter), std::forward(sent), 
std::forward(val));
+};
+
+template 
+concept HasIotaRange =
+requires(Range&& range, Value&& val) { 
std::ranges::iota(std::forward(range), std::forward(val)); };
+
+// Test constraints of the iterator/sentinel overload
+// ==
+static_assert(HasIotaIter);
+
+// !input_or_output_iterator
+static_assert(!HasIotaIter);
+
+// !sentinel_for
+static_assert(!HasIotaIter);
+static_assert(!HasIotaIter);
+
+// !weakly_incrementable
+static_assert(!HasIotaIter);
+
+// !indirectly writable 
+static_assert(!HasIotaIter);
+
+// Test constraints for the range overload
+// ===
+static_assert(HasIotaRange, int>);
+
+// !weakly_incrementable
+static_assert(!HasIotaRange, 
WeaklyIncrementableNotMovable>);
+
+// !ranges::output_range
+static_assert(!HasIotaRange, 
OutputIteratorNotIndirectlyWritable>);
+
+//
+// Testing results
+//
+
+struct DangerousCopyAssign {
+  int val;
+  using difference_type = int;
+
+  constexpr explicit DangerousCopyAssign(int v) : val(v) {}
+
+  // Needed in postfix
+  constexpr DangerousCopyAssign(DangerousCopyAssign const& other) { this->val 
= other.val; }
+
+  // mischievious copy assignment that we won't use if the
+  // std::as_const inside ranges::iota isn't working, this should perturb the
+  // results
+  constexpr DangerousCopyAssign& operator=(DangerousCopyAssign& a) {
+++a.val;
+this->val = a.val;
+return *this;
+  }
+
+  // safe copy assignment std::as_const inside ranges::iota should ensure this
+  // overload gets called
+  constexpr DangerousCopyAssign& operator=(DangerousCopyAssign const& a) {
+this->val = a.val;
+return *this;
+  }
+
+  constexpr bool operator==(DangerousCopyAssign const& rhs) { return this->val 
== rhs.val; }
+
+  // prefix
+  constexpr DangerousCopyAssign& operator++() {
+++(this->val);
+return *this;
+  }
+
+  // postfix
+  constexpr DangerousCopyAssign operator++(int) {
+auto tmp = *this;
+++this->val;
+return tmp;
+  }
+};
+
+template 
+constexpr void test_result(std::array input, T starting_value, 
std::array const expected) {
+  { // (iterator, sentinel) overload
+auto in_begin = Iter(input.data());
+auto in_end   = Sent(Iter(input.data() + input.size()));
+std::same_as> decltype(auto) result 
=
+std::ranges::iota(std::move(in_begin), std::move(in_end), 
starting_value);
+assert(result.out == in_end);
+if constexpr (expected.size() > 0) {
+  assert(result.value == expected.back() + 1);
+} else {
+  assert(result.value == starting_value);
+}

cjdb wrote:

Please avoid using logic in test cases.

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


[llvm] [compiler-rt] [libcxx] [lldb] [libunwind] [flang] [libc] [clang-tools-extra] [clang] [libc++] Implement ranges::iota (PR #68494)

2024-01-05 Thread Christopher Di Bella via cfe-commits

https://github.com/cjdb edited https://github.com/llvm/llvm-project/pull/68494
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc] [llvm] [libunwind] [flang] [lldb] [libcxx] [clang] [compiler-rt] [libc++] Implement ranges::iota (PR #68494)

2024-01-05 Thread Christopher Di Bella via cfe-commits


@@ -1172,6 +1198,22 @@ struct Proxy {
 requires std::three_way_comparable_with, std::decay_t> {
 return lhs.data <=> rhs.data;
   }
+
+  // Needed to allow certain types to be weakly_incremental
+  constexpr Proxy& operator++()
+requires(HasPreIncrementOp)
+  {
+++data;
+return *this;
+  }
+
+  constexpr Proxy operator++(int)
+requires(HasPostIncrementOp)
+  {
+Proxy tmp = *this;
+operator++();
+return tmp;
+  }

cjdb wrote:

Please use `std::weakly_incrementable` and `std::incrementable`. You'll also 
need to support `void operator++(int)` for when a type is weakly 
incremenetable, but not incrementable.

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


[libcxx] [flang] [libunwind] [libc] [llvm] [lldb] [clang-tools-extra] [compiler-rt] [clang] [libc++] Implement ranges::iota (PR #68494)

2024-01-05 Thread Christopher Di Bella via cfe-commits


@@ -1161,9 +1185,11 @@ struct Proxy {
 return lhs.data == rhs.data;
   }
 
-  friend constexpr auto operator<=>(const Proxy&, const Proxy&)
-requires (std::three_way_comparable && !std::is_reference_v)
-  = default;
+  friend constexpr auto operator<=>(const Proxy& lhs, const Proxy& rhs)
+requires(std::three_way_comparable && !std::is_reference_v)
+  {
+return lhs.data <=> rhs.data;
+  };

cjdb wrote:

What is the intention of this change?

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


[flang] [compiler-rt] [llvm] [lldb] [clang-tools-extra] [libunwind] [clang] [libcxx] [libc] [libc++] Implement ranges::iota (PR #68494)

2024-01-05 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,71 @@
+// -*- 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_RANGES_IOTA_H
+#define _LIBCPP___NUMERIC_RANGES_IOTA_H
+
+#include <__algorithm/out_value_result.h>
+#include <__config>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__ranges/dangling.h>
+#include <__utility/as_const.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+namespace ranges {
+template 
+using iota_result = ranges::out_value_result<_Out, _Tp>;
+
+namespace __ranges_iota {
+struct __iota_fn {
+private:
+  // Private helper function
+  template 
+  _LIBCPP_HIDE_FROM_ABI static constexpr iota_result<_Out, _Tp> 
__iota_impl(_Out __first, _Sent __last, _Tp __value) {
+while (__first != __last) {
+  *__first = std::as_const(__value);
+  ++__first;
+  ++__value;
+}
+return {std::move(__first), std::move(__value)};
+  }

cjdb wrote:

Please move this into the iterator-based `operator()` and have the range-based 
one call that. As it's currently implemented, additional and unnecessary moves 
need to happen, and we also incur some debug overhead that I'd rather avoid.

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


[compiler-rt] [lldb] [llvm] [libunwind] [clang-tools-extra] [libcxx] [libc] [clang] [flang] [libc++] Implement ranges::iota (PR #68494)

2024-01-09 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,54 @@
+// -*- 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_RANGES_IOTA_H
+#define _LIBCPP___NUMERIC_RANGES_IOTA_H
+
+#include <__algorithm/out_value_result.h>
+#include <__config>
+#include <__ranges/concepts.h>
+#include <__utility/as_const.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+namespace ranges {
+template 
+using iota_result = ranges::out_value_result<_Out, _Tp>;
+
+struct __iota_fn {
+  template  _Sent, 
weakly_incrementable _Tp>
+requires indirectly_writable<_Out, const _Tp&>
+  constexpr iota_result<_Out, _Tp> operator()(_Out __first, _Sent __last, _Tp 
__value) const {
+while (__first != __last) {
+  *__first = std::as_const(__value);
+  ++__first;
+  ++__value;
+}
+return {std::move(__first), std::move(__value)};
+  }
+
+  template  _Range>
+  constexpr iota_result, _Tp> 
operator()(_Range&& __r, _Tp __value) const {
+return (*this)(ranges::begin(__r), ranges::end(__r), std::move(__value));

cjdb wrote:

I don't see why this would cause problems?

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


[compiler-rt] [lldb] [llvm] [libunwind] [clang-tools-extra] [libcxx] [libc] [clang] [flang] [libc++] Implement ranges::iota (PR #68494)

2024-01-09 Thread Christopher Di Bella via cfe-commits


@@ -1149,9 +1171,11 @@ struct Proxy {
   // Calling swap(Proxy{}, Proxy{}) would fail (pass prvalues)
 
   // Compare operators are defined for the convenience of the tests
-  friend constexpr bool operator==(const Proxy&, const Proxy&)
-requires (std::equality_comparable && !std::is_reference_v)
-  = default;
+  friend constexpr bool operator==(const Proxy& lhs, const Proxy& rhs)
+requires(std::equality_comparable && !std::is_reference_v)
+  {
+return lhs.data == rhs.data;
+  };

cjdb wrote:

Understood, I didn't realise that references implicitly delete defaulted 
comparison operators (it makes sense to me that they do). Could you please 
provide a comment about why this is required (same as below)?

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


[clang] 9a72580 - [clang][Sema] removes -Wfree-nonheap-object reference param false positive

2021-07-21 Thread Christopher Di Bella via cfe-commits

Author: Christopher Di Bella
Date: 2021-07-21T21:30:16Z
New Revision: 9a72580a548da8008dca479ec50e4eb75e56db71

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

LOG: [clang][Sema] removes -Wfree-nonheap-object reference param false positive

Taking the address of a reference parameter might be valid, and without
CFA, false positives are going to be more trouble than they're worth.

Differential Revision: https://reviews.llvm.org/D102728

Added: 


Modified: 
clang/lib/Sema/SemaChecking.cpp
clang/test/Sema/warn-free-nonheap-object.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 075fad6476ef..242c2968da45 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -10726,8 +10726,9 @@ void CheckFreeArgumentsAddressof(Sema &S, const 
std::string &CalleeName,
  const UnaryOperator *UnaryExpr) {
   if (const auto *Lvalue = dyn_cast(UnaryExpr->getSubExpr())) {
 const Decl *D = Lvalue->getDecl();
-if (isa(D))
-  return CheckFreeArgumentsOnLvalue(S, CalleeName, UnaryExpr, D);
+if (isa(D))
+  if (!dyn_cast(D)->getType()->isReferenceType())
+return CheckFreeArgumentsOnLvalue(S, CalleeName, UnaryExpr, D);
   }
 
   if (const auto *Lvalue = dyn_cast(UnaryExpr->getSubExpr()))

diff  --git a/clang/test/Sema/warn-free-nonheap-object.cpp 
b/clang/test/Sema/warn-free-nonheap-object.cpp
index 9347709a23ca..37dc0fdaad93 100644
--- a/clang/test/Sema/warn-free-nonheap-object.cpp
+++ b/clang/test/Sema/warn-free-nonheap-object.cpp
@@ -10,23 +10,34 @@ void free(void *p);
 
 int GI;
 
+void free_reference(char &x) { ::free(&x); }
+void free_reference(char &&x) { ::free(&x); }
+void std_free_reference(char &x) { std::free(&x); }
+void std_free_reference(char &&x) { std::free(&x); }
+
 struct S {
-  operator char *() { return ptr; }
+  operator char *() { return ptr1; }
 
   void CFree() {
-::free(&ptr); // expected-warning {{attempt to call free on non-heap 
object 'ptr'}}
-::free(&I);   // expected-warning {{attempt to call free on non-heap 
object 'I'}}
-::free(ptr);
+::free(&ptr1); // expected-warning {{attempt to call free on non-heap 
object 'ptr1'}}
+::free(&I);// expected-warning {{attempt to call free on non-heap 
object 'I'}}
+::free(ptr1);
+free_reference(*ptr2);
+free_reference(static_cast(*ptr3));
   }
 
   void CXXFree() {
-std::free(&ptr); // expected-warning {{attempt to call std::free on 
non-heap object 'ptr'}}
-std::free(&I);   // expected-warning {{attempt to call std::free on 
non-heap object 'I'}}
-std::free(ptr);
+std::free(&ptr1); // expected-warning {{attempt to call std::free on 
non-heap object 'ptr1'}}
+std::free(&I);// expected-warning {{attempt to call std::free on 
non-heap object 'I'}}
+std::free(ptr1);
+std_free_reference(*ptr2);
+std_free_reference(static_cast(*ptr3));
   }
 
 private:
-  char *ptr = (char *)std::malloc(10);
+  char *ptr1 = (char *)std::malloc(10);
+  char *ptr2 = (char *)std::malloc(10);
+  char *ptr3 = (char *)std::malloc(10);
   static int I;
 };
 
@@ -93,6 +104,14 @@ void test2() {
 void *P = std::malloc(8);
 std::free(P);
   }
+  {
+char* P = (char *)std::malloc(2);
+std_free_reference(*P);
+  }
+  {
+char* P = (char *)std::malloc(2);
+std_free_reference(static_cast(*P));
+  }
   {
 int A[] = {0, 1, 2, 3};
 std::free(A); // expected-warning {{attempt to call std::free on non-heap 
object 'A'}}



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


[clang] e8a64e5 - [clang][pp] adds '#pragma include_instead'

2021-07-26 Thread Christopher Di Bella via cfe-commits

Author: Christopher Di Bella
Date: 2021-07-26T16:07:45Z
New Revision: e8a64e5491260714c79dab65d1aa73245931d314

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

LOG: [clang][pp] adds '#pragma include_instead'

`#pragma clang include_instead()` is a pragma that can be used
by system headers (and only system headers) to indicate to a tool that
the file containing said pragma is an implementation-detail header and
should not be directly included by user code.

The library alternative is very messy code that can be seen in the first
diff of D106124, and we'd rather avoid that with something more
universal.

This patch takes the first step by warning a user when they include a
detail header in their code, and suggests alternative headers that the
user should include instead. Future work will involve adding a fixit to
automate the process, as well as cleaning up modules diagnostics to not
suggest said detail headers. Other tools, such as clangd can also take
advantage of this pragma to add the correct user headers.

Differential Revision: https://reviews.llvm.org/D106394

Added: 
clang/test/Preprocessor/Inputs/include_instead/bad-syntax.h
clang/test/Preprocessor/Inputs/include_instead/file-not-found.h
clang/test/Preprocessor/Inputs/include_instead/non-system-header.h
clang/test/Preprocessor/Inputs/include_instead/private-x.h
clang/test/Preprocessor/Inputs/include_instead/private1.h
clang/test/Preprocessor/Inputs/include_instead/private2.h
clang/test/Preprocessor/Inputs/include_instead/private3.h
clang/test/Preprocessor/Inputs/include_instead/public-after.h
clang/test/Preprocessor/Inputs/include_instead/public-before.h
clang/test/Preprocessor/Inputs/include_instead/public-empty.h
clang/test/Preprocessor/include_instead.cpp
clang/test/Preprocessor/include_instead_file_not_found.cpp

Modified: 
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/include/clang/Lex/HeaderSearch.h
clang/include/clang/Lex/Preprocessor.h
clang/include/clang/Lex/PreprocessorLexer.h
clang/lib/Lex/Lexer.cpp
clang/lib/Lex/PPDirectives.cpp
clang/lib/Lex/PPLexerChange.cpp
clang/lib/Lex/Pragma.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index ce6d0d0394b48..690ea693bd366 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -300,6 +300,12 @@ def pp_pragma_once_in_main_file : Warning<"#pragma once in 
main file">,
 def pp_pragma_sysheader_in_main_file : Warning<
   "#pragma system_header ignored in main file">,
   InGroup>;
+
+def err_pragma_include_instead_not_sysheader : Error<
+  "'#pragma clang include_instead' cannot be used outside of system headers">;
+def err_pragma_include_instead_system_reserved : Error<
+  "header '%0' is an implementation detail; #include %select{'%2'|either '%2' 
or '%3'|one of %2}1 instead">;
+
 def pp_poisoning_existing_macro : Warning<"poisoning existing macro">;
 def pp_out_of_date_dependency : Warning<
   "current file is older than dependency %0">;

diff  --git a/clang/include/clang/Lex/HeaderSearch.h 
b/clang/include/clang/Lex/HeaderSearch.h
index 93d6ea72270aa..a35a394f719b0 100644
--- a/clang/include/clang/Lex/HeaderSearch.h
+++ b/clang/include/clang/Lex/HeaderSearch.h
@@ -20,9 +20,12 @@
 #include "clang/Lex/ModuleMap.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/SetVector.h"
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringMap.h"
-#include "llvm/ADT/StringSet.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSet.h"
 #include "llvm/Support/Allocator.h"
 #include 
 #include 
@@ -110,6 +113,14 @@ struct HeaderFileInfo {
   /// of the framework.
   StringRef Framework;
 
+  /// List of aliases that this header is known as.
+  /// Most headers should only have at most one alias, but a handful
+  /// have two.
+  llvm::SetVector,
+  llvm::SmallVector, 2>,
+  llvm::SmallSet, 2>>
+  Aliases;
+
   HeaderFileInfo()
   : isImport(false), isPragmaOnce(false), DirInfo(SrcMgr::C_User),
 External(false), isModuleHeader(false), isCompilingModuleHeader(false),
@@ -453,6 +464,10 @@ class HeaderSearch {
 getFileInfo(File).DirInfo = SrcMgr::C_System;
   }
 
+  void AddFileAlias(const FileEntry *File, StringRef Alias) {
+getFileInfo(File).Aliases.insert(Alias);
+  }
+
   /// Mark the specified file as part of a module.
   void MarkFileModuleHeader(const FileEntry *FE,
 ModuleMap::ModuleHeaderRole Role,

diff  --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
i

[clang] 0871954 - Revert "Revert "[clang][pp] adds '#pragma include_instead'""

2021-07-29 Thread Christopher Di Bella via cfe-commits

Author: Christopher Di Bella
Date: 2021-07-29T19:21:43Z
New Revision: 087195419719e908394081b4cc6f365170b9882c

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

LOG: Revert "Revert "[clang][pp] adds '#pragma include_instead'""

Includes regression test for problem noted by @hans.
This reverts commit 973de7185606a21fd5e9d5e8c014fbf898c0e72f.

Differential Revision: https://reviews.llvm.org/D106898

Added: 
clang/test/PCH/ms-pch-macro-include_instead-regression.c
clang/test/Preprocessor/Inputs/include_instead/bad-syntax.h
clang/test/Preprocessor/Inputs/include_instead/file-not-found.h
clang/test/Preprocessor/Inputs/include_instead/non-system-header.h
clang/test/Preprocessor/Inputs/include_instead/private-x.h
clang/test/Preprocessor/Inputs/include_instead/private1.h
clang/test/Preprocessor/Inputs/include_instead/private2.h
clang/test/Preprocessor/Inputs/include_instead/private3.h
clang/test/Preprocessor/Inputs/include_instead/public-after.h
clang/test/Preprocessor/Inputs/include_instead/public-before.h
clang/test/Preprocessor/Inputs/include_instead/public-empty.h
clang/test/Preprocessor/include_instead.cpp
clang/test/Preprocessor/include_instead_file_not_found.cpp

Modified: 
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/include/clang/Lex/HeaderSearch.h
clang/include/clang/Lex/Preprocessor.h
clang/include/clang/Lex/PreprocessorLexer.h
clang/lib/Lex/Lexer.cpp
clang/lib/Lex/PPDirectives.cpp
clang/lib/Lex/PPLexerChange.cpp
clang/lib/Lex/Pragma.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 174f6c3dfd4c6..f621cdb466560 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -300,6 +300,13 @@ def pp_pragma_once_in_main_file : Warning<"#pragma once in 
main file">,
 def pp_pragma_sysheader_in_main_file : Warning<
   "#pragma system_header ignored in main file">,
   InGroup>;
+
+def err_pragma_include_instead_not_sysheader : Error<
+  "'#pragma clang include_instead' cannot be used outside of system headers">;
+def err_pragma_include_instead_system_reserved : Error<
+  "header '%0' is an implementation detail; #include %select{'%2'|either '%2' "
+  "or '%3'|one of %2}1 instead">;
+
 def pp_poisoning_existing_macro : Warning<"poisoning existing macro">;
 def pp_out_of_date_dependency : Warning<
   "current file is older than dependency %0">;

diff  --git a/clang/include/clang/Lex/HeaderSearch.h 
b/clang/include/clang/Lex/HeaderSearch.h
index 93d6ea72270aa..a35a394f719b0 100644
--- a/clang/include/clang/Lex/HeaderSearch.h
+++ b/clang/include/clang/Lex/HeaderSearch.h
@@ -20,9 +20,12 @@
 #include "clang/Lex/ModuleMap.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/SetVector.h"
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringMap.h"
-#include "llvm/ADT/StringSet.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSet.h"
 #include "llvm/Support/Allocator.h"
 #include 
 #include 
@@ -110,6 +113,14 @@ struct HeaderFileInfo {
   /// of the framework.
   StringRef Framework;
 
+  /// List of aliases that this header is known as.
+  /// Most headers should only have at most one alias, but a handful
+  /// have two.
+  llvm::SetVector,
+  llvm::SmallVector, 2>,
+  llvm::SmallSet, 2>>
+  Aliases;
+
   HeaderFileInfo()
   : isImport(false), isPragmaOnce(false), DirInfo(SrcMgr::C_User),
 External(false), isModuleHeader(false), isCompilingModuleHeader(false),
@@ -453,6 +464,10 @@ class HeaderSearch {
 getFileInfo(File).DirInfo = SrcMgr::C_System;
   }
 
+  void AddFileAlias(const FileEntry *File, StringRef Alias) {
+getFileInfo(File).Aliases.insert(Alias);
+  }
+
   /// Mark the specified file as part of a module.
   void MarkFileModuleHeader(const FileEntry *FE,
 ModuleMap::ModuleHeaderRole Role,

diff  --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 45ee0ad9fd21e..8ecd6a965cf86 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -1961,7 +1961,8 @@ class Preprocessor {
   /// This either returns the EOF token and returns true, or
   /// pops a level off the include stack and returns false, at which point the
   /// client should call lex again.
-  bool HandleEndOfFile(Token &Result, bool isEndOfMacro = false);
+  bool HandleEndOfFile(Token &Result, SourceLocation Loc,
+   bool isEndOfMacro = false);
 
   /// Callback invoked when the current TokenLexer hits the end of its
   /// toke

[clang-tools-extra] d7b1c84 - [clangd][NFC] includes missing headers

2022-02-15 Thread Christopher Di Bella via cfe-commits

Author: Christopher Di Bella
Date: 2022-02-15T17:44:47Z
New Revision: d7b1c840ba4e1f8c04fe1c5455242629893c7e3a

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

LOG: [clangd][NFC] includes missing headers

`Shutdown.h` was transitively depending on two headers, but this isn't
allowed under a modules build, so they're now explicitly included.

Differential Revision: https://reviews.llvm.org/D119806

Added: 


Modified: 
clang-tools-extra/clangd/support/Shutdown.h

Removed: 




diff  --git a/clang-tools-extra/clangd/support/Shutdown.h 
b/clang-tools-extra/clangd/support/Shutdown.h
index 896e1521fe6a1..e295576c1fda0 100644
--- a/clang-tools-extra/clangd/support/Shutdown.h
+++ b/clang-tools-extra/clangd/support/Shutdown.h
@@ -45,6 +45,8 @@
 
 #include 
 #include 
+#include 
+#include 
 
 namespace clang {
 namespace clangd {



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


[clang-tools-extra] e9a902c - Revert "Revert "Revert "[clang][pp] adds '#pragma include_instead'"""

2022-04-22 Thread Christopher Di Bella via cfe-commits

Author: Christopher Di Bella
Date: 2022-04-22T16:37:20Z
New Revision: e9a902c7f755a378e197c4b246a32859c0ee162d

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

LOG: Revert "Revert "Revert "[clang][pp] adds '#pragma include_instead'"""

> Includes regression test for problem noted by @hans.
> is reverts commit 973de71.
>
> Differential Revision: https://reviews.llvm.org/D106898

Feature implemented as-is is fairly expensive and hasn't been used by
libc++. A potential reimplementation is possible if libc++ become
interested in this feature again.

Differential Revision: https://reviews.llvm.org/D123885

Added: 


Modified: 
clang-tools-extra/clangd/Selection.cpp
clang-tools-extra/pseudo/lib/Lex.cpp
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/include/clang/Basic/SourceManager.h
clang/include/clang/Lex/HeaderSearch.h
clang/include/clang/Lex/Lexer.h
clang/include/clang/Lex/Preprocessor.h
clang/include/clang/Lex/PreprocessorLexer.h
clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
clang/lib/Lex/Lexer.cpp
clang/lib/Lex/PPDirectives.cpp
clang/lib/Lex/PPLexerChange.cpp
clang/lib/Lex/Pragma.cpp

Removed: 
clang/test/PCH/ms-pch-macro-include_instead-regression.c
clang/test/Preprocessor/Inputs/include_instead/bad-syntax.h
clang/test/Preprocessor/Inputs/include_instead/file-not-found.h
clang/test/Preprocessor/Inputs/include_instead/non-system-header.h
clang/test/Preprocessor/Inputs/include_instead/private-x.h
clang/test/Preprocessor/Inputs/include_instead/private1.h
clang/test/Preprocessor/Inputs/include_instead/private2.h
clang/test/Preprocessor/Inputs/include_instead/private3.h
clang/test/Preprocessor/Inputs/include_instead/public-after.h
clang/test/Preprocessor/Inputs/include_instead/public-before.h
clang/test/Preprocessor/Inputs/include_instead/public-empty.h
clang/test/Preprocessor/include_instead.cpp
clang/test/Preprocessor/include_instead_file_not_found.cpp



diff  --git a/clang-tools-extra/clangd/Selection.cpp 
b/clang-tools-extra/clangd/Selection.cpp
index ba2f253eb0757..fa3e6ff22a00a 100644
--- a/clang-tools-extra/clangd/Selection.cpp
+++ b/clang-tools-extra/clangd/Selection.cpp
@@ -30,6 +30,7 @@
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
+#include 
 #include 
 
 namespace clang {

diff  --git a/clang-tools-extra/pseudo/lib/Lex.cpp 
b/clang-tools-extra/pseudo/lib/Lex.cpp
index e99bf3a63e5e1..72eff3c12f25c 100644
--- a/clang-tools-extra/pseudo/lib/Lex.cpp
+++ b/clang-tools-extra/pseudo/lib/Lex.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "clang-pseudo/Token.h"
+#include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/TokenKinds.h"
 #include "clang/Lex/Lexer.h"

diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 0f424b02c812a..543ce8a3649d1 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -315,12 +315,6 @@ def pp_pragma_sysheader_in_main_file : Warning<
   "#pragma system_header ignored in main file">,
   InGroup>;
 
-def err_pragma_include_instead_not_sysheader : Error<
-  "'#pragma clang include_instead' cannot be used outside of system headers">;
-def err_pragma_include_instead_system_reserved : Error<
-  "header '%0' is an implementation detail; #include %select{'%2'|either '%2' "
-  "or '%3'|one of %2}1 instead">;
-
 def err_illegal_use_of_flt_eval_macro : Error<
   "'__FLT_EVAL_METHOD__' cannot be expanded inside a scope containing "
   "'#pragma clang fp eval_method'">;

diff  --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index cc29c24f5a35f..3f3f1bb65c2c1 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -36,6 +36,7 @@
 
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/FileEntry.h"
+#include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/BitVector.h"

diff  --git a/clang/include/clang/Lex/HeaderSearch.h 
b/clang/include/clang/Lex/HeaderSearch.h
index 3a170d2d3fa8d..e88e600ba2b97 100644
--- a/clang/include/clang/Lex/HeaderSearch.h
+++ b/clang/include/clang/Lex/HeaderSearch.h
@@ -20,9 +20,6 @@
 #include "clang/Lex/ModuleMap.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/SetVector.h"
-#include "llvm/ADT/SmallSet.h"
-#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSet.h"
@@ -119,1

[clang] 119d223 - [clang] Add -fdiagnostics-format=sarif option for future SARIF output

2022-07-21 Thread Christopher Di Bella via cfe-commits

Author: Abraham Corea Diaz
Date: 2022-07-21T16:51:15Z
New Revision: 119d22310bd622d4b39e9760667b6fa58d15a8c5

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

LOG: [clang] Add -fdiagnostics-format=sarif option for future SARIF output

Adds `sarif` option to the existing `-fdiagnostics-format` flag
for intended future work with SARIF diagnostics. Currently issues a warning
against the use of diagnostics in SARIF mode, then defaults to clang style for
diagnostics.

Reviewed By: cjdb, denik, aaron.ballman

Differential Revision: https://reviews.llvm.org/D129886

Added: 
clang/test/Driver/fdiagnostics-format-sarif.cpp

Modified: 
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Basic/DiagnosticOptions.h
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/TextDiagnostic.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 68685baf76331..3c5f7e087de85 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -678,4 +678,8 @@ def err_drv_invalid_format_dxil_validator_version : Error<
 def err_drv_invalid_empty_dxil_validator_version : Error<
   "invalid validator version : %0\n"
   "If validator major version is 0, minor version must also be 0.">;
+
+def warn_drv_sarif_format_unstable : Warning<
+  "diagnostic formatting in SARIF mode is currently unstable">,
+  InGroup>;
 }

diff  --git a/clang/include/clang/Basic/DiagnosticOptions.h 
b/clang/include/clang/Basic/DiagnosticOptions.h
index 17533b38ff5f3..c4134835b5dec 100644
--- a/clang/include/clang/Basic/DiagnosticOptions.h
+++ b/clang/include/clang/Basic/DiagnosticOptions.h
@@ -74,7 +74,7 @@ class DiagnosticOptions : public 
RefCountedBase{
   friend class CompilerInvocation;
 
 public:
-  enum TextDiagnosticFormat { Clang, MSVC, Vi };
+  enum TextDiagnosticFormat { Clang, MSVC, Vi, SARIF };
 
   // Default values.
   enum {

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 3bd3550c9c60f..b9c2e4d528e44 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5588,8 +5588,8 @@ def diagnostic_serialized_file : Separate<["-"], 
"serialize-diagnostic-file">,
 
 def fdiagnostics_format : Separate<["-"], "fdiagnostics-format">,
   HelpText<"Change diagnostic formatting to match IDE and command line tools">,
-  Values<"clang,msvc,vi">,
-  NormalizedValuesScope<"DiagnosticOptions">, NormalizedValues<["Clang", 
"MSVC", "Vi"]>,
+  Values<"clang,msvc,vi,sarif,SARIF">,
+  NormalizedValuesScope<"DiagnosticOptions">, NormalizedValues<["Clang", 
"MSVC", "Vi", "SARIF", "SARIF"]>,
   MarshallingInfoEnum, "Clang">;
 def fdiagnostics_show_category : Separate<["-"], "fdiagnostics-show-category">,
   HelpText<"Print diagnostic category">,

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 6337a996a9ace..3ad08ad7e11d1 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4007,6 +4007,9 @@ static void RenderDiagnosticsOptions(const Driver &D, 
const ArgList &Args,
   if (const Arg *A = Args.getLastArg(options::OPT_fdiagnostics_format_EQ)) {
 CmdArgs.push_back("-fdiagnostics-format");
 CmdArgs.push_back(A->getValue());
+if (StringRef(A->getValue()) == "sarif" ||
+StringRef(A->getValue()) == "SARIF")
+  D.Diag(diag::warn_drv_sarif_format_unstable);
   }
 
   if (const Arg *A = Args.getLastArg(

diff  --git a/clang/lib/Frontend/TextDiagnostic.cpp 
b/clang/lib/Frontend/TextDiagnostic.cpp
index 6c0ea0cde3589..ab0dbcef65344 100644
--- a/clang/lib/Frontend/TextDiagnostic.cpp
+++ b/clang/lib/Frontend/TextDiagnostic.cpp
@@ -815,6 +815,7 @@ void TextDiagnostic::emitDiagnosticLoc(FullSourceLoc Loc, 
PresumedLoc PLoc,
 
   emitFilename(PLoc.getFilename(), Loc.getManager());
   switch (DiagOpts->getFormat()) {
+  case DiagnosticOptions::SARIF:
   case DiagnosticOptions::Clang:
 if (DiagOpts->ShowLine)
   OS << ':' << LineNo;
@@ -837,6 +838,7 @@ void TextDiagnostic::emitDiagnosticLoc(FullSourceLoc Loc, 
PresumedLoc PLoc,
   OS << ColNo;
 }
   switch (DiagOpts->getFormat()) {
+  case DiagnosticOptions::SARIF:
   case DiagnosticOptions::Clang:
   case DiagnosticOptions::Vi:OS << ':';break;
   case DiagnosticOptions::MSVC:

diff  --git a/clang/test/Driver/fdiagnostics-format-sarif.cpp 
b/clang/test/Driver/fdiagnostics-format-sarif.cpp
new file mode 100644
index 0..f7e2274e532b1
--- /dev/null
+++ b/clang/test/Driver/fdiagnostics-format-sarif.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang -fsyntax-only -fdiagn

[clang] 4f395db - adds more checks to -Wfree-nonheap-object

2021-02-25 Thread Christopher Di Bella via cfe-commits

Author: Christopher Di Bella
Date: 2021-02-25T19:25:00Z
New Revision: 4f395db86b5cc11bb56853323d3cb1d4b6db5a0b

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

LOG: adds more checks to -Wfree-nonheap-object

This commit adds checks for the following:

* labels
* block expressions
* random integers cast to `void*`
* function pointers cast to `void*`

Differential Revision: https://reviews.llvm.org/D94640

Added: 
clang/test/Analysis/free.cpp

Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaChecking.cpp
clang/test/Analysis/free.c
clang/test/Analysis/malloc-fnptr-plist.c
clang/test/Analysis/malloc.c
clang/test/Analysis/weak-functions.c

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8f71962502ae..481ed57c0b58 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7637,7 +7637,7 @@ def warn_condition_is_assignment : Warning<"using the 
result of an "
   "assignment as a condition without parentheses">,
   InGroup;
 def warn_free_nonheap_object
-  : Warning<"attempt to call %0 on non-heap object %1">,
+  : Warning<"attempt to call %0 on non-heap %select{object %2|object: block 
expression|object: lambda-to-function-pointer conversion}1">,
 InGroup;
 
 // Completely identical except off by default.

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 2c19e91c906e..f69bdf97aa8d 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -10269,65 +10269,109 @@ void Sema::CheckStrncatArguments(const CallExpr *CE,
 }
 
 namespace {
-void CheckFreeArgumentsOnLvalue(Sema &S, const std::string &CalleeName,
-const UnaryOperator *UnaryExpr,
-const VarDecl *Var) {
-  StorageClass Class = Var->getStorageClass();
-  if (Class == StorageClass::SC_Extern ||
-  Class == StorageClass::SC_PrivateExtern ||
-  Var->getType()->isReferenceType())
-return;
-
-  S.Diag(UnaryExpr->getBeginLoc(), diag::warn_free_nonheap_object)
-  << CalleeName << Var;
-}
-
 void CheckFreeArgumentsOnLvalue(Sema &S, const std::string &CalleeName,
 const UnaryOperator *UnaryExpr, const Decl *D) 
{
-  if (const auto *Field = dyn_cast(D))
+  if (isa(D)) {
 S.Diag(UnaryExpr->getBeginLoc(), diag::warn_free_nonheap_object)
-<< CalleeName << Field;
+<< CalleeName << 0 /*object: */ << cast(D);
+return;
+  }
 }
 
 void CheckFreeArgumentsAddressof(Sema &S, const std::string &CalleeName,
  const UnaryOperator *UnaryExpr) {
-  if (UnaryExpr->getOpcode() != UnaryOperator::Opcode::UO_AddrOf)
-return;
-
-  if (const auto *Lvalue = dyn_cast(UnaryExpr->getSubExpr()))
-if (const auto *Var = dyn_cast(Lvalue->getDecl()))
-  return CheckFreeArgumentsOnLvalue(S, CalleeName, UnaryExpr, Var);
+  if (const auto *Lvalue = dyn_cast(UnaryExpr->getSubExpr())) {
+const Decl *D = Lvalue->getDecl();
+if (isa(D))
+  return CheckFreeArgumentsOnLvalue(S, CalleeName, UnaryExpr, D);
+  }
 
   if (const auto *Lvalue = dyn_cast(UnaryExpr->getSubExpr()))
 return CheckFreeArgumentsOnLvalue(S, CalleeName, UnaryExpr,
   Lvalue->getMemberDecl());
 }
 
-void CheckFreeArgumentsStackArray(Sema &S, const std::string &CalleeName,
-  const DeclRefExpr *Lvalue) {
-  if (!Lvalue->getType()->isArrayType())
+void CheckFreeArgumentsPlus(Sema &S, const std::string &CalleeName,
+const UnaryOperator *UnaryExpr) {
+  const auto *Lambda = dyn_cast(
+  UnaryExpr->getSubExpr()->IgnoreImplicitAsWritten()->IgnoreParens());
+  if (!Lambda)
 return;
 
+  S.Diag(Lambda->getBeginLoc(), diag::warn_free_nonheap_object)
+  << CalleeName << 2 /*object: lambda expression*/;
+}
+
+void CheckFreeArgumentsStackArray(Sema &S, const std::string &CalleeName,
+  const DeclRefExpr *Lvalue) {
   const auto *Var = dyn_cast(Lvalue->getDecl());
   if (Var == nullptr)
 return;
 
   S.Diag(Lvalue->getBeginLoc(), diag::warn_free_nonheap_object)
-  << CalleeName << Var;
+  << CalleeName << 0 /*object: */ << Var;
+}
+
+void CheckFreeArgumentsCast(Sema &S, const std::string &CalleeName,
+const CastExpr *Cast) {
+  SmallString<128> SizeString;
+  llvm::raw_svector_ostream OS(SizeString);
+  switch (Cast->getCastKind()) {
+  case clang::CK_BitCast:
+if (!Cast->getSubExpr()->getType()->isFunctionPointerType())
+  return;
+[[clang::fallthrough]];
+  case clang::CK_Integral

[clang-tools-extra] c874dd5 - [llvm][clang][NFC] updates inline licence info

2021-08-10 Thread Christopher Di Bella via cfe-commits

Author: Christopher Di Bella
Date: 2021-08-11T02:48:53Z
New Revision: c874dd53628db8170d4c5ba3878817abc385a695

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

LOG: [llvm][clang][NFC] updates inline licence info

Some files still contained the old University of Illinois Open Source
Licence header. This patch replaces that with the Apache 2 with LLVM
Exception licence.

Differential Revision: https://reviews.llvm.org/D107528

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.h
clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.h
clang-tools-extra/clang-tidy/objc/SuperSelfCheck.cpp
clang-tools-extra/clang-tidy/objc/SuperSelfCheck.h
clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.h
clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp
clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.h
clang/include/clang/AST/ASTConcept.h
clang/include/clang/AST/ASTImporterSharedState.h
clang/include/clang/AST/CurrentSourceLocExprScope.h
clang/include/clang/AST/JSONNodeDumper.h
clang/include/clang/Sema/SemaConcept.h
clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
clang/lib/AST/ASTConcept.cpp
clang/lib/Format/MacroExpander.cpp
clang/lib/Format/Macros.h
clang/lib/Index/FileIndexRecord.cpp
clang/lib/Sema/SemaConcept.cpp
clang/lib/StaticAnalyzer/Core/SMTConstraintManager.cpp
clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
clang/unittests/Format/TestLexer.h
clang/unittests/Tooling/RecursiveASTVisitorTests/LambdaTemplateParams.cpp
lldb/docs/use/python.rst
lldb/unittests/Symbol/TestLineEntry.cpp
llvm/include/llvm/Analysis/HeatUtils.h
llvm/include/llvm/CodeGen/MIRFormatter.h
llvm/include/llvm/CodeGen/RegAllocCommon.h
llvm/include/llvm/Support/ExtensibleRTTI.h
llvm/include/llvm/Support/LICENSE.TXT
llvm/include/llvm/Support/Signposts.h
llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h
llvm/include/llvm/Transforms/Instrumentation/AddressSanitizerCommon.h
llvm/include/llvm/Transforms/Instrumentation/AddressSanitizerOptions.h
llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h
llvm/include/llvm/Transforms/Instrumentation/InstrOrderFile.h
llvm/include/llvm/Transforms/Instrumentation/MemProfiler.h
llvm/include/llvm/Transforms/Utils/MemoryOpRemark.h
llvm/lib/Analysis/DevelopmentModeInlineAdvisor.cpp
llvm/lib/Analysis/HeatUtils.cpp
llvm/lib/Analysis/InlineSizeEstimatorAnalysis.cpp
llvm/lib/Analysis/TFUtils.cpp
llvm/lib/BinaryFormat/MsgPackDocumentYAML.cpp
llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp
llvm/lib/DebugInfo/GSYM/FileWriter.cpp
llvm/lib/DebugInfo/GSYM/Range.cpp
llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp
llvm/lib/ExecutionEngine/JITLink/ELF.cpp
llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
llvm/lib/ExecutionEngine/JITLink/JITLinkMemoryManager.cpp
llvm/lib/ExecutionEngine/JITLink/MachO.cpp
llvm/lib/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.cpp
llvm/lib/Support/ExtensibleRTTI.cpp
llvm/lib/Support/Signposts.cpp
llvm/lib/Target/AArch64/AArch64StackTagging.cpp
llvm/lib/Target/AArch64/AArch64StackTaggingPreRA.cpp
llvm/lib/Target/AArch64/SVEIntrinsicOpts.cpp
llvm/lib/Target/CSKY/AsmParser/CSKYAsmParser.cpp
llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp
llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.h
llvm/lib/Target/PowerPC/MCTargetDesc/PPCXCOFFStreamer.cpp
llvm/lib/Target/PowerPC/MCTargetDesc/PPCXCOFFStreamer.h
llvm/lib/Target/X86/X86InstrKL.td
llvm/lib/Transforms/Instrumentation/InstrOrderFile.cpp
llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp
llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp
llvm/unittests/BinaryFormat/MsgPackDocumentTest.cpp
llvm/unittests/DebugInfo/GSYM/GSYMTest.cpp
llvm/unittests/Support/ExtensibleRTTITest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
index 9b449515f27da..86e3f3b7da6a2 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
@@ -1,9 +1,8 @@
 //===--- BranchCloneCheck.cpp - clang-tidy 
===//
 //
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illi

[clang] c874dd5 - [llvm][clang][NFC] updates inline licence info

2021-08-10 Thread Christopher Di Bella via cfe-commits

Author: Christopher Di Bella
Date: 2021-08-11T02:48:53Z
New Revision: c874dd53628db8170d4c5ba3878817abc385a695

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

LOG: [llvm][clang][NFC] updates inline licence info

Some files still contained the old University of Illinois Open Source
Licence header. This patch replaces that with the Apache 2 with LLVM
Exception licence.

Differential Revision: https://reviews.llvm.org/D107528

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.h
clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.h
clang-tools-extra/clang-tidy/objc/SuperSelfCheck.cpp
clang-tools-extra/clang-tidy/objc/SuperSelfCheck.h
clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.h
clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp
clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.h
clang/include/clang/AST/ASTConcept.h
clang/include/clang/AST/ASTImporterSharedState.h
clang/include/clang/AST/CurrentSourceLocExprScope.h
clang/include/clang/AST/JSONNodeDumper.h
clang/include/clang/Sema/SemaConcept.h
clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
clang/lib/AST/ASTConcept.cpp
clang/lib/Format/MacroExpander.cpp
clang/lib/Format/Macros.h
clang/lib/Index/FileIndexRecord.cpp
clang/lib/Sema/SemaConcept.cpp
clang/lib/StaticAnalyzer/Core/SMTConstraintManager.cpp
clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
clang/unittests/Format/TestLexer.h
clang/unittests/Tooling/RecursiveASTVisitorTests/LambdaTemplateParams.cpp
lldb/docs/use/python.rst
lldb/unittests/Symbol/TestLineEntry.cpp
llvm/include/llvm/Analysis/HeatUtils.h
llvm/include/llvm/CodeGen/MIRFormatter.h
llvm/include/llvm/CodeGen/RegAllocCommon.h
llvm/include/llvm/Support/ExtensibleRTTI.h
llvm/include/llvm/Support/LICENSE.TXT
llvm/include/llvm/Support/Signposts.h
llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h
llvm/include/llvm/Transforms/Instrumentation/AddressSanitizerCommon.h
llvm/include/llvm/Transforms/Instrumentation/AddressSanitizerOptions.h
llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h
llvm/include/llvm/Transforms/Instrumentation/InstrOrderFile.h
llvm/include/llvm/Transforms/Instrumentation/MemProfiler.h
llvm/include/llvm/Transforms/Utils/MemoryOpRemark.h
llvm/lib/Analysis/DevelopmentModeInlineAdvisor.cpp
llvm/lib/Analysis/HeatUtils.cpp
llvm/lib/Analysis/InlineSizeEstimatorAnalysis.cpp
llvm/lib/Analysis/TFUtils.cpp
llvm/lib/BinaryFormat/MsgPackDocumentYAML.cpp
llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp
llvm/lib/DebugInfo/GSYM/FileWriter.cpp
llvm/lib/DebugInfo/GSYM/Range.cpp
llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp
llvm/lib/ExecutionEngine/JITLink/ELF.cpp
llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
llvm/lib/ExecutionEngine/JITLink/JITLinkMemoryManager.cpp
llvm/lib/ExecutionEngine/JITLink/MachO.cpp
llvm/lib/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.cpp
llvm/lib/Support/ExtensibleRTTI.cpp
llvm/lib/Support/Signposts.cpp
llvm/lib/Target/AArch64/AArch64StackTagging.cpp
llvm/lib/Target/AArch64/AArch64StackTaggingPreRA.cpp
llvm/lib/Target/AArch64/SVEIntrinsicOpts.cpp
llvm/lib/Target/CSKY/AsmParser/CSKYAsmParser.cpp
llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp
llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.h
llvm/lib/Target/PowerPC/MCTargetDesc/PPCXCOFFStreamer.cpp
llvm/lib/Target/PowerPC/MCTargetDesc/PPCXCOFFStreamer.h
llvm/lib/Target/X86/X86InstrKL.td
llvm/lib/Transforms/Instrumentation/InstrOrderFile.cpp
llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp
llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp
llvm/unittests/BinaryFormat/MsgPackDocumentTest.cpp
llvm/unittests/DebugInfo/GSYM/GSYMTest.cpp
llvm/unittests/Support/ExtensibleRTTITest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
index 9b449515f27da..86e3f3b7da6a2 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
@@ -1,9 +1,8 @@
 //===--- BranchCloneCheck.cpp - clang-tidy 
===//
 //
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illi

[clang-tools-extra] 478092d - [clangd][iwyu] explicitly includes ``

2021-07-03 Thread Christopher Di Bella via cfe-commits

Author: Christopher Di Bella
Date: 2021-07-04T06:00:39Z
New Revision: 478092d33116ec01ad0b82f7eeedb1e1f07aef93

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

LOG: [clangd][iwyu] explicitly includes ``

Compiling clangd with Clang modules and libc++ revealed that
`support/Threading.h` uses `std::atomic` but wasn't including the
correct header.

Differential Revision: https://reviews.llvm.org/D105400

Added: 


Modified: 
clang-tools-extra/clangd/support/Threading.h

Removed: 




diff  --git a/clang-tools-extra/clangd/support/Threading.h 
b/clang-tools-extra/clangd/support/Threading.h
index da9e3b8ea8b68..7f4ef6c0b1cbe 100644
--- a/clang-tools-extra/clangd/support/Threading.h
+++ b/clang-tools-extra/clangd/support/Threading.h
@@ -12,6 +12,7 @@
 #include "support/Context.h"
 #include "llvm/ADT/FunctionExtras.h"
 #include "llvm/ADT/Twine.h"
+#include 
 #include 
 #include 
 #include 



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


[clang] 9830901 - [clang] removes check against integral-to-pointer conversion...

2021-03-04 Thread Christopher Di Bella via cfe-commits

Author: Christopher Di Bella
Date: 2021-03-04T17:00:54Z
New Revision: 9830901b341cfb884cdef00e0335c6e3e62d107a

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

LOG: [clang] removes check against integral-to-pointer conversion...

... unless it's a literal

D94640 was a bit too aggressive in its analysis, considering integers
representing valid addresses as invalid. This change rolls back some of
the check, so that only the most obvious case is still flagged.

Before:

```cpp
free((void*)1000);   // literal converted to `void*`: warning good
free((void*)an_int); // `int` object converted to `void*`: warning might
 //  be a false positive
```

After

```cpp
free((void*)1000);   // literal converted to `void*`: warning good
free((void*)an_int); // doesn't warn
```

Differential Revision: https://reviews.llvm.org/D97512

Added: 


Modified: 
clang/lib/Sema/SemaChecking.cpp
clang/test/Analysis/free.c
clang/test/Analysis/free.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 7e6dd354caace..22dd634c5031a 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -10316,11 +10316,18 @@ void CheckFreeArgumentsCast(Sema &S, const 
std::string &CalleeName,
 const CastExpr *Cast) {
   SmallString<128> SizeString;
   llvm::raw_svector_ostream OS(SizeString);
+
+  clang::CastKind Kind = Cast->getCastKind();
+  if (Kind == clang::CK_BitCast &&
+  !Cast->getSubExpr()->getType()->isFunctionPointerType())
+return;
+  if (Kind == clang::CK_IntegralToPointer &&
+  !isa(
+  Cast->getSubExpr()->IgnoreParenImpCasts()->IgnoreParens()))
+return;
+
   switch (Cast->getCastKind()) {
   case clang::CK_BitCast:
-if (!Cast->getSubExpr()->getType()->isFunctionPointerType())
-  return;
-LLVM_FALLTHROUGH;
   case clang::CK_IntegralToPointer:
   case clang::CK_FunctionToPointerDecay:
 OS << '\'';

diff  --git a/clang/test/Analysis/free.c b/clang/test/Analysis/free.c
index 84d53472158cd..59767b5917d79 100644
--- a/clang/test/Analysis/free.c
+++ b/clang/test/Analysis/free.c
@@ -108,3 +108,11 @@ void t17(void) {
   // expected-warning@-1{{Argument to free() is the address of the function 
'iptr', which is not memory allocated by malloc()}}
   // expected-warning@-2{{attempt to call free on non-heap object 'iptr'}}
 }
+
+struct S {
+  const char* p;
+};
+
+void t18 (struct S s) {
+  free((void*)(unsigned long long)s.p); // no warning
+}

diff  --git a/clang/test/Analysis/free.cpp b/clang/test/Analysis/free.cpp
index 2559770d6ddb7..85b0935a51992 100644
--- a/clang/test/Analysis/free.cpp
+++ b/clang/test/Analysis/free.cpp
@@ -208,3 +208,39 @@ void t17b (char **x, int offset) {
   // Unknown value
   std::free(x[offset]); // no-warning
 }
+
+struct S {
+  const char* p;
+};
+
+void t18_C_style_C_style_free (S s) {
+  free((void*)(unsigned long long)s.p); // no warning
+}
+
+void t18_C_style_C_style_std_free (S s) {
+  std::free((void*)(unsigned long long)s.p); // no warning
+}
+
+void t18_C_style_reinterpret_free (S s) {
+  free((void*)reinterpret_cast(s.p)); // no warning
+}
+
+void t18_C_style_reinterpret_std_free (S s) {
+  std::free((void*)reinterpret_cast(s.p)); // no warning
+}
+
+void t18_reinterpret_C_style_free (S s) {
+  free(reinterpret_cast((unsigned long long)(s.p))); // no warning
+}
+
+void t18_reinterpret_C_style_std_free (S s) {
+  std::free(reinterpret_cast((unsigned long long)(s.p))); // no warning
+}
+
+void t18_reinterpret_reinterpret_free (S s) {
+  free(reinterpret_cast(reinterpret_cast(s.p))); // 
no warning
+}
+
+void t18_reinterpret_reinterpret_std_free (S s) {
+  std::free(reinterpret_cast(reinterpret_cast(s.p))); // no warning
+}



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


[clang] e137fb6 - [clang][libcxx] renames `__remove_reference`

2022-08-22 Thread Christopher Di Bella via cfe-commits

Author: Christopher Di Bella
Date: 2022-08-22T23:15:10Z
New Revision: e137fb6fb85b41978814e64eae652d05688bcca5

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

LOG: [clang][libcxx] renames `__remove_reference`

libc++ prior to LLVM 15 has a bug in it due to it excluding
`remove_reference_t` when `__remove_reference` is available as a
compiler built-in. This went unnoticed until D116203 because it wasn't
available in any compiler.

To work around this, we're renaming `__remove_reference` to
`__remove_reference_t`.

TEST=Tested locally, tested using emscripten

Added: 


Modified: 
clang/include/clang/Basic/TransformTypeTraits.def
clang/test/CodeGenCXX/mangle.cpp
clang/test/SemaCXX/libstdcxx_transform_type_traits_hack.cpp
clang/test/SemaCXX/type-traits.cpp
libcxx/include/__type_traits/remove_reference.h

Removed: 




diff  --git a/clang/include/clang/Basic/TransformTypeTraits.def 
b/clang/include/clang/Basic/TransformTypeTraits.def
index 9389effc6d835..e27a2719a9680 100644
--- a/clang/include/clang/Basic/TransformTypeTraits.def
+++ b/clang/include/clang/Basic/TransformTypeTraits.def
@@ -22,7 +22,7 @@ TRANSFORM_TYPE_TRAIT_DEF(RemoveCV, remove_cv)
 TRANSFORM_TYPE_TRAIT_DEF(RemoveCVRef, remove_cvref)
 TRANSFORM_TYPE_TRAIT_DEF(RemoveExtent, remove_extent)
 TRANSFORM_TYPE_TRAIT_DEF(RemovePointer, remove_pointer)
-TRANSFORM_TYPE_TRAIT_DEF(RemoveReference, remove_reference)
+TRANSFORM_TYPE_TRAIT_DEF(RemoveReference, remove_reference_t)
 TRANSFORM_TYPE_TRAIT_DEF(RemoveRestrict, remove_restrict)
 TRANSFORM_TYPE_TRAIT_DEF(RemoveVolatile, remove_volatile)
 TRANSFORM_TYPE_TRAIT_DEF(EnumUnderlyingType, underlying_type)

diff  --git a/clang/test/CodeGenCXX/mangle.cpp 
b/clang/test/CodeGenCXX/mangle.cpp
index 708b492a2ebed..84315591a4977 100644
--- a/clang/test/CodeGenCXX/mangle.cpp
+++ b/clang/test/CodeGenCXX/mangle.cpp
@@ -1163,9 +1163,9 @@ template  void f14(T, __remove_pointer(T)) {}
 template void f14(int, __remove_pointer(int));
 // CHECK-LABEL: @_ZN6test553f14IiEEvT_u16__remove_pointerIS1_E
 
-template  void f15(T, __remove_reference(T)) {}
-template void f15(int, __remove_reference(int));
-// CHECK-LABEL: @_ZN6test553f15IiEEvT_u18__remove_referenceIS1_E
+template  void f15(T, __remove_reference_t(T)) {}
+template void f15(int, __remove_reference_t(int));
+// CHECK-LABEL: @_ZN6test553f15IiEEvT_u20__remove_reference_tIS1_E
 
 template  void f16(T, __remove_volatile(T)) {}
 template void f16(int, __remove_volatile(int));

diff  --git a/clang/test/SemaCXX/libstdcxx_transform_type_traits_hack.cpp 
b/clang/test/SemaCXX/libstdcxx_transform_type_traits_hack.cpp
index 5032c3ad00e4d..fc38b424fc242 100644
--- a/clang/test/SemaCXX/libstdcxx_transform_type_traits_hack.cpp
+++ b/clang/test/SemaCXX/libstdcxx_transform_type_traits_hack.cpp
@@ -49,9 +49,9 @@ template 
 using H = Same<__add_rvalue_reference, __add_rvalue_reference>;
 
 template 
-using __remove_reference = int; // expected-warning{{keyword 
'__remove_reference' will be made available as an identifier here}}
+using __remove_reference_t = int; // expected-warning{{keyword 
'__remove_reference_t' will be made available as an identifier here}}
 template 
-using I = Same<__remove_reference, __remove_reference>;
+using I = Same<__remove_reference_t, __remove_reference_t>;
 
 template 
 using __remove_cvref = int; // expected-warning{{keyword '__remove_cvref' will 
be made available as an identifier here}}

diff  --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index f54ae0eb2c578..ab2a9f74090a4 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3157,7 +3157,7 @@ void add_rvalue_reference() {
   static_assert(__is_same(add_rvalue_reference_t, int(S::* 
&&)()), "");
 }
 
-template  using remove_reference_t = __remove_reference(T);
+template  using remove_reference_t = __remove_reference_t(T);
 
 void check_remove_reference() {
   static_assert(__is_same(remove_reference_t, void), "");

diff  --git a/libcxx/include/__type_traits/remove_reference.h 
b/libcxx/include/__type_traits/remove_reference.h
index 7ea7fa52ecc59..023b36cbc2cf6 100644
--- a/libcxx/include/__type_traits/remove_reference.h
+++ b/libcxx/include/__type_traits/remove_reference.h
@@ -18,16 +18,16 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if __has_builtin(__remove_reference)
+#if __has_builtin(__remove_reference_t)
 template 
 struct remove_reference {
-  using type _LIBCPP_NODEBUG = __remove_reference(_Tp);
+  using type _LIBCPP_NODEBUG = __remove_reference_t(_Tp);
 };
 #else
 template  struct _LIBCPP_TEMPLATE_VIS remove_reference
{typedef _LIBCPP_NODEBUG _Tp type;};
 template  struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&>  
{typedef _LIBCPP_NODEBUG _Tp type;};
 template  struct _LI

[clang] 82e893c - [clang] Enable output of SARIF diagnostics

2022-08-26 Thread Christopher Di Bella via cfe-commits

Author: Abraham Corea Diaz
Date: 2022-08-26T18:49:29Z
New Revision: 82e893c47c77430ca59f92d7a814a336e3873a35

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

LOG: [clang] Enable output of SARIF diagnostics

Enables Clang to emit diagnostics in SARIF format when
`-fdiagnostics-format=sarif`. Adds a new DiagnosticConsumer named
SARIFDiagnosticPrinter and a new DiagnosticRenderer named SARIFDiagnostic
to constuct and emit a SARIF object containing the run's basic diagnostic info.

Reviewed By: cjdb, denik, aaron.ballman

Differential Revision: https://reviews.llvm.org/D131632

Added: 
clang/include/clang/Frontend/SARIFDiagnostic.h
clang/include/clang/Frontend/SARIFDiagnosticPrinter.h
clang/lib/Frontend/SARIFDiagnostic.cpp
clang/lib/Frontend/SARIFDiagnosticPrinter.cpp
clang/test/Frontend/sarif-diagnostics.cpp

Modified: 
clang/lib/Frontend/CMakeLists.txt
clang/lib/Frontend/CompilerInstance.cpp
clang/lib/Frontend/FrontendAction.cpp

Removed: 




diff  --git a/clang/include/clang/Frontend/SARIFDiagnostic.h 
b/clang/include/clang/Frontend/SARIFDiagnostic.h
new file mode 100644
index 0..bd0f1df9aa58f
--- /dev/null
+++ b/clang/include/clang/Frontend/SARIFDiagnostic.h
@@ -0,0 +1,76 @@
+//===--- SARIFDiagnostic.h - SARIF Diagnostic Formatting -*- 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
+//
+//===--===//
+//
+// This is a utility class that provides support for constructing a SARIF 
object
+// containing diagnostics.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_FRONTEND_SARIFDIAGNOSTIC_H
+#define LLVM_CLANG_FRONTEND_SARIFDIAGNOSTIC_H
+
+#include "clang/Basic/Sarif.h"
+#include "clang/Frontend/DiagnosticRenderer.h"
+#include "llvm/ADT/StringRef.h"
+
+namespace clang {
+
+class SARIFDiagnostic : public DiagnosticRenderer {
+public:
+  SARIFDiagnostic(raw_ostream &OS, const LangOptions &LangOpts,
+  DiagnosticOptions *DiagOpts, SarifDocumentWriter *Writer);
+
+  ~SARIFDiagnostic() = default;
+
+  SARIFDiagnostic &operator=(const SARIFDiagnostic &&) = delete;
+  SARIFDiagnostic(SARIFDiagnostic &&) = delete;
+  SARIFDiagnostic &operator=(const SARIFDiagnostic &) = delete;
+  SARIFDiagnostic(const SARIFDiagnostic &) = delete;
+
+protected:
+  void emitDiagnosticMessage(FullSourceLoc Loc, PresumedLoc PLoc,
+ DiagnosticsEngine::Level Level, StringRef Message,
+ ArrayRef Ranges,
+ DiagOrStoredDiag D) override;
+
+  void emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc,
+ DiagnosticsEngine::Level Level,
+ ArrayRef Ranges) override;
+
+  void emitCodeContext(FullSourceLoc Loc, DiagnosticsEngine::Level Level,
+   SmallVectorImpl &Ranges,
+   ArrayRef Hints) override {}
+
+  void emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) override;
+
+  void emitImportLocation(FullSourceLoc Loc, PresumedLoc PLoc,
+  StringRef ModuleName) override;
+
+  void emitBuildingModuleLocation(FullSourceLoc Loc, PresumedLoc PLoc,
+  StringRef ModuleName) override;
+
+private:
+  raw_ostream &OS;
+
+  // Shared between SARIFDiagnosticPrinter and this renderer.
+  SarifDocumentWriter *Writer;
+
+  SarifResult addLocationToResult(SarifResult Result, FullSourceLoc Loc,
+  PresumedLoc PLoc,
+  ArrayRef Ranges,
+  const Diagnostic &Diag);
+
+  SarifRule addDiagnosticLevelToRule(SarifRule Rule,
+ DiagnosticsEngine::Level Level);
+
+  llvm::StringRef emitFilename(StringRef Filename, const SourceManager &SM);
+};
+
+} // end namespace clang
+
+#endif

diff  --git a/clang/include/clang/Frontend/SARIFDiagnosticPrinter.h 
b/clang/include/clang/Frontend/SARIFDiagnosticPrinter.h
new file mode 100644
index 0..f2652833b3c18
--- /dev/null
+++ b/clang/include/clang/Frontend/SARIFDiagnosticPrinter.h
@@ -0,0 +1,76 @@
+//===-- SARIFDiagnosticPrinter.h - SARIF Diagnostic Client ---*- 
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
+//
+//===--===//
+//
+// This 

[clang] 0e5813b - [clang][NFC] silences warnings

2022-08-26 Thread Christopher Di Bella via cfe-commits

Author: Abraham Corea Diaz
Date: 2022-08-26T21:09:39Z
New Revision: 0e5813b88e50576940070003e093d696390a6959

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

LOG: [clang][NFC] silences warnings

* removes unused data member `OS` from `SARIFDiagnostic`
* flags `Filename` variable as currently unused

This is a follow-up to D131632.

Added: 


Modified: 
clang/include/clang/Frontend/SARIFDiagnostic.h
clang/lib/Frontend/SARIFDiagnostic.cpp

Removed: 




diff  --git a/clang/include/clang/Frontend/SARIFDiagnostic.h 
b/clang/include/clang/Frontend/SARIFDiagnostic.h
index bd0f1df9aa58..ec1d0b8e6a7c 100644
--- a/clang/include/clang/Frontend/SARIFDiagnostic.h
+++ b/clang/include/clang/Frontend/SARIFDiagnostic.h
@@ -55,8 +55,6 @@ class SARIFDiagnostic : public DiagnosticRenderer {
   StringRef ModuleName) override;
 
 private:
-  raw_ostream &OS;
-
   // Shared between SARIFDiagnosticPrinter and this renderer.
   SarifDocumentWriter *Writer;
 

diff  --git a/clang/lib/Frontend/SARIFDiagnostic.cpp 
b/clang/lib/Frontend/SARIFDiagnostic.cpp
index 2bcbd5cf34f2..f0f32a179825 100644
--- a/clang/lib/Frontend/SARIFDiagnostic.cpp
+++ b/clang/lib/Frontend/SARIFDiagnostic.cpp
@@ -33,7 +33,7 @@ namespace clang {
 SARIFDiagnostic::SARIFDiagnostic(raw_ostream &OS, const LangOptions &LangOpts,
  DiagnosticOptions *DiagOpts,
  SarifDocumentWriter *Writer)
-: DiagnosticRenderer(LangOpts, DiagOpts), OS(OS), Writer(Writer) {}
+: DiagnosticRenderer(LangOpts, DiagOpts), Writer(Writer) {}
 
 // FIXME(llvm-project/issues/57323): Refactor Diagnostic classes.
 void SARIFDiagnostic::emitDiagnosticMessage(
@@ -71,7 +71,8 @@ SarifResult SARIFDiagnostic::addLocationToResult(
 FileID FID = Loc.getFileID();
 if (FID.isValid()) {
   if (const FileEntry *FE = Loc.getFileEntry()) {
-emitFilename(FE->getName(), Loc.getManager());
+[[gnu::unused]] llvm::StringRef Filename =
+emitFilename(FE->getName(), Loc.getManager());
 // FIXME(llvm-project/issues/57366): File-only locations
   }
 }



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


[clang] a089def - [clang] adds `__is_scoped_enum`, `__is_nullptr`, and `__is_referenceable`

2022-10-10 Thread Christopher Di Bella via cfe-commits

Author: Christopher Di Bella
Date: 2022-10-11T00:13:58Z
New Revision: a089defa24dd4050192e1e8d7e704188d2214787

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

LOG: [clang] adds `__is_scoped_enum`, `__is_nullptr`, and `__is_referenceable`

... as builtins.

This is information that the compiler already has, and should be exposed
so that the library doesn't need to reimplement the exact same
functionality.

This was originally a part of D116280.

Depends on D135175.

Differential Revision: https://reviews.llvm.org/D135177

Added: 


Modified: 
clang/docs/LanguageExtensions.rst
clang/include/clang/Basic/TokenKinds.def
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Parse/ParseExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/test/SemaCXX/type-traits.cpp

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 83f49d9bf13bd..162bcdd9fba70 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1428,16 +1428,25 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__is_nothrow_constructible`` (C++, MSVC 2013)
 * ``__is_nothrow_destructible`` (C++, MSVC 2013)
   Only available in ``-fms-extensions`` mode.
+* ``__is_nullptr`` (C++, GNU, Microsoft, Embarcadero):
+  Returns true for ``std::nullptr_t`` and false for everything else. The
+  corresponding standard library feature is ``std::is_null_pointer``, but
+  ``__is_null_pointer`` is already in use by some implementations.
 * ``__is_object`` (C++, Embarcadero)
 * ``__is_pod`` (C++, GNU, Microsoft, Embarcadero):
   Note, the corresponding standard trait was deprecated in C++20.
 * ``__is_pointer`` (C++, Embarcadero)
 * ``__is_polymorphic`` (C++, GNU, Microsoft, Embarcadero)
 * ``__is_reference`` (C++, Embarcadero)
+* ``__is_referenceable`` (C++, GNU, Microsoft, Embarcadero):
+  Returns true if a type is referenceable, and false otherwise. A referenceable
+  type is a type that's either an object type, a reference type, or an 
unqualified
+  function type.
 * ``__is_rvalue_reference`` (C++, Embarcadero)
 * ``__is_same`` (C++, Embarcadero)
 * ``__is_same_as`` (GCC): Synonym for ``__is_same``.
 * ``__is_scalar`` (C++, Embarcadero)
+* ``__is_scoped_enum`` (C++, GNU, Microsoft, Embarcadero)
 * ``__is_sealed`` (Microsoft):
   Synonym for ``__is_final``.
 * ``__is_signed`` (C++, Embarcadero):

diff  --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 747565e7fac4e..4e89752051bdc 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -520,6 +520,9 @@ TYPE_TRAIT_1(__has_unique_object_representations,
 TYPE_TRAIT_1(__is_trivially_relocatable, IsTriviallyRelocatable, KEYCXX)
 TYPE_TRAIT_1(__is_bounded_array, IsBoundedArray, KEYCXX)
 TYPE_TRAIT_1(__is_unbounded_array, IsUnboundedArray, KEYCXX)
+TYPE_TRAIT_1(__is_nullptr, IsNullPointer, KEYCXX)
+TYPE_TRAIT_1(__is_scoped_enum, IsScopedEnum, KEYCXX)
+TYPE_TRAIT_1(__is_referenceable, IsReferenceable, KEYCXX)
 TYPE_TRAIT_2(__reference_binds_to_temporary, ReferenceBindsToTemporary, KEYCXX)
 
 // Embarcadero Expression Traits

diff  --git a/clang/lib/Parse/ParseDeclCXX.cpp 
b/clang/lib/Parse/ParseDeclCXX.cpp
index 4eeba4787b57d..bb5394f04 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -1605,15 +1605,18 @@ void Parser::ParseClassSpecifier(tok::TokenKind 
TagTokKind,
   tok::kw___is_nothrow_assignable,
   tok::kw___is_nothrow_constructible,
   tok::kw___is_nothrow_destructible,
+  tok::kw___is_nullptr,
   tok::kw___is_object,
   tok::kw___is_pod,
   tok::kw___is_pointer,
   tok::kw___is_polymorphic,
   tok::kw___is_reference,
+  tok::kw___is_referenceable,
   tok::kw___is_rvalue_expr,
   tok::kw___is_rvalue_reference,
   tok::kw___is_same,
   tok::kw___is_scalar,
+  tok::kw___is_scoped_enum,
   tok::kw___is_sealed,
   tok::kw___is_signed,
   tok::kw___is_standard_layout,

diff  --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 956361123f998..b8f351dbbf1e1 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1067,8 +1067,8 @@ ExprResult Parser::ParseCastExpression(CastParseKind 
ParseKind,
   REVERTIBLE_TYPE_TRAIT(__is_arithmetic);
   REVERTIBLE_TYPE_TRAIT(__is_array);
   REVERTIBLE_TYPE_TRAIT(__is_assignable);
-  REVERTIBLE_TYPE_TRAIT(__is_bounded_array);
   REVERTIBLE_TYPE_TRAIT(__is_base_of);
+  REVERTIBLE_TYPE_TRAIT(__is_bounded_array);
   REVERTIBLE_TYPE_TRAIT(__is_class);
 

[clang] 14e64cb - [clang] makes `__is_destructible` KEYALL instead of KEYMS

2022-10-10 Thread Christopher Di Bella via cfe-commits

Author: Christopher Di Bella
Date: 2022-10-11T00:13:58Z
New Revision: 14e64cb8d594c16c722da83d3e8af9fc0d013c4e

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

LOG: [clang] makes `__is_destructible` KEYALL instead of KEYMS

This makes it possible to be used in all modes, instead of just when
`-fms-extensions` is enabled. Also moves the `-fms-extensions`-exclusive
traits into their own file so we can check the others aren't dependent
on this flag.

This is information that the compiler already has, and should be exposed
so that the library doesn't need to reimplement the exact same
functionality.

This was originally a part of D116280.

Depends on D135177.

Differential Revision: https://reviews.llvm.org/D135339

Added: 
clang/test/SemaCXX/type-traits-ms-extensions.cpp

Modified: 
clang/docs/LanguageExtensions.rst
clang/include/clang/Basic/TokenKinds.def
clang/test/SemaCXX/type-traits.cpp

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 162bcdd9fba7..b449809c88d5 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1404,8 +1404,7 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__is_convertible`` (C++, Embarcadero)
 * ``__is_convertible_to`` (Microsoft):
   Synonym for ``__is_convertible``.
-* ``__is_destructible`` (C++, MSVC 2013):
-  Only available in ``-fms-extensions`` mode.
+* ``__is_destructible`` (C++, MSVC 2013)
 * ``__is_empty`` (C++, GNU, Microsoft, Embarcadero)
 * ``__is_enum`` (C++, GNU, Microsoft, Embarcadero)
 * ``__is_final`` (C++, GNU, Microsoft)
@@ -1427,7 +1426,6 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__is_nothrow_assignable`` (C++, MSVC 2013)
 * ``__is_nothrow_constructible`` (C++, MSVC 2013)
 * ``__is_nothrow_destructible`` (C++, MSVC 2013)
-  Only available in ``-fms-extensions`` mode.
 * ``__is_nullptr`` (C++, GNU, Microsoft, Embarcadero):
   Returns true for ``std::nullptr_t`` and false for everything else. The
   corresponding standard library feature is ``std::is_null_pointer``, but

diff  --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 4e89752051bd..1127dc88c312 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -466,9 +466,9 @@ TYPE_TRAIT_1(__is_interface_class, IsInterfaceClass, KEYMS)
 TYPE_TRAIT_1(__is_sealed, IsSealed, KEYMS)
 
 // MSVC12.0 / VS2013 Type Traits
-TYPE_TRAIT_1(__is_destructible, IsDestructible, KEYMS)
+TYPE_TRAIT_1(__is_destructible, IsDestructible, KEYALL)
 TYPE_TRAIT_1(__is_trivially_destructible, IsTriviallyDestructible, KEYCXX)
-TYPE_TRAIT_1(__is_nothrow_destructible, IsNothrowDestructible, KEYMS)
+TYPE_TRAIT_1(__is_nothrow_destructible, IsNothrowDestructible, KEYALL)
 TYPE_TRAIT_2(__is_nothrow_assignable, IsNothrowAssignable, KEYCXX)
 TYPE_TRAIT_N(__is_constructible, IsConstructible, KEYCXX)
 TYPE_TRAIT_N(__is_nothrow_constructible, IsNothrowConstructible, KEYCXX)

diff  --git a/clang/test/SemaCXX/type-traits-ms-extensions.cpp 
b/clang/test/SemaCXX/type-traits-ms-extensions.cpp
new file mode 100644
index ..2f4e81498090
--- /dev/null
+++ b/clang/test/SemaCXX/type-traits-ms-extensions.cpp
@@ -0,0 +1,92 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify 
-std=gnu++11 -fblocks -Wno-deprecated-builtins -fms-extensions -Wno-microsoft 
%s -Wno-c++17-extensions
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify 
-std=gnu++14 -fblocks -Wno-deprecated-builtins -fms-extensions -Wno-microsoft 
%s -Wno-c++17-extensions
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify 
-std=gnu++1z -fblocks -Wno-deprecated-builtins -fms-extensions -Wno-microsoft %s
+// RUN: %clang_cc1 -x c -triple x86_64-apple-darwin10 -fsyntax-only -verify 
-std=gnu11 -fblocks -Wno-deprecated-builtins -fms-extensions -Wno-microsoft %s
+
+#ifdef __cplusplus
+
+// expected-no-diagnostics
+
+using Int = int;
+
+struct NonPOD { NonPOD(int); };
+enum Enum { EV };
+struct POD { Enum e; int i; float f; NonPOD* p; };
+struct Derives : POD {};
+using ClassType = Derives;
+
+union Union { int i; float f; };
+
+struct HasAnonymousUnion {
+  union {
+int i;
+float f;
+  };
+};
+
+struct FinalClass final {
+};
+
+template
+struct PotentiallyFinal { };
+
+template
+struct PotentiallyFinal final { };
+
+template<>
+struct PotentiallyFinal final { };
+
+struct SealedClass sealed {
+};
+
+template
+struct PotentiallySealed { };
+
+template
+struct PotentiallySealed sealed { };
+
+template<>
+struct PotentiallySealed sealed { };
+
+void is_final() {
+  static_assert(__is_final(SealedClass));
+  static_assert(__is_

[clang] bd3f48e - [clang] adds `__is_bounded_array` and `__is_unbounded_array` as builtins

2022-10-10 Thread Christopher Di Bella via cfe-commits

Author: Christopher Di Bella
Date: 2022-10-11T00:13:58Z
New Revision: bd3f48eefc11c2f1ef6eb034418697e24e9a965d

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

LOG: [clang] adds `__is_bounded_array` and `__is_unbounded_array` as builtins

This is information that the compiler already has, and should be exposed
so that the library doesn't need to reimplement the exact same
functionality.

This was originally a part of D116280.

Differential Revision: https://reviews.llvm.org/D135175

Added: 


Modified: 
clang/docs/LanguageExtensions.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/TokenKinds.def
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Parse/ParseExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaType.cpp
clang/test/SemaCXX/type-traits.cpp

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index f680b1f1d2ad7..83f49d9bf13bd 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1392,6 +1392,7 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__is_array`` (C++, Embarcadero)
 * ``__is_assignable`` (C++, MSVC 2015)
 * ``__is_base_of`` (C++, GNU, Microsoft, Embarcadero)
+* ``__is_bounded_array`` (C++, GNU, Microsoft, Embarcadero)
 * ``__is_class`` (C++, GNU, Microsoft, Embarcadero)
 * ``__is_complete_type(type)`` (Embarcadero):
   Return ``true`` if ``type`` is a complete type.
@@ -1454,6 +1455,7 @@ The following type trait primitives are supported by 
Clang. Those traits marked
   functionally equivalent to copying the underlying bytes and then dropping the
   source object on the floor. This is true of trivial types and types which
   were made trivially relocatable via the ``clang::trivial_abi`` attribute.
+* ``__is_unbounded_array`` (C++, GNU, Microsoft, Embarcadero)
 * ``__is_union`` (C++, GNU, Microsoft, Embarcadero)
 * ``__is_unsigned`` (C++, Embarcadero):
   Returns false for enumeration types. Note, before Clang 13, returned true for
@@ -4245,7 +4247,7 @@ The ``__declspec`` style syntax is also supported:
 
   #pragma clang attribute pop
 
-A single push directive can contain multiple attributes, however, 
+A single push directive can contain multiple attributes, however,
 only one syntax style can be used within a single directive:
 
 .. code-block:: c++
@@ -4255,7 +4257,7 @@ only one syntax style can be used within a single 
directive:
   void function1(); // The function now has the [[noreturn]] and [[noinline]] 
attributes
 
   #pragma clang attribute pop
-  
+
   #pragma clang attribute push (__attribute((noreturn, noinline)), apply_to = 
function)
 
   void function2(); // The function now has the __attribute((noreturn)) and 
__attribute((noinline)) attributes

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index d6fbaed126d64..3e9fe53eea8ea 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -147,7 +147,7 @@ def ext_vla_folded_to_constant : ExtWarn<
   "variable length array folded to constant array as an extension">,
   InGroup;
 def err_vla_unsupported : Error<
-  "variable length arrays are not supported for the current target">;
+  "variable length arrays are not supported for %select{the current 
target|'%1'}0">;
 def note_vla_unsupported : Note<
   "variable length arrays are not supported for the current target">;
 

diff  --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 44a8c3181f142..747565e7fac4e 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -518,6 +518,8 @@ TYPE_TRAIT_1(__has_unique_object_representations,
 
 // Clang-only C++ Type Traits
 TYPE_TRAIT_1(__is_trivially_relocatable, IsTriviallyRelocatable, KEYCXX)
+TYPE_TRAIT_1(__is_bounded_array, IsBoundedArray, KEYCXX)
+TYPE_TRAIT_1(__is_unbounded_array, IsUnboundedArray, KEYCXX)
 TYPE_TRAIT_2(__reference_binds_to_temporary, ReferenceBindsToTemporary, KEYCXX)
 
 // Embarcadero Expression Traits

diff  --git a/clang/lib/Parse/ParseDeclCXX.cpp 
b/clang/lib/Parse/ParseDeclCXX.cpp
index 639320c6bb474..4eeba4787b57d 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -1579,6 +1579,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind 
TagTokKind,
   tok::kw___is_array,
   tok::kw___is_assignable,
   tok::kw___is_base_of,
+  tok::kw___is_bounded_array,
   tok::kw___is_class,
   tok::kw___is_complete_type,
   tok::kw___is_compound,
@@ -1620,6 +1621,7 @@ void Parser::ParseClassSpecifier(tok::Toke

[clang-tools-extra] 716469b - [clang-tidy] Fix segfault in bugprone-standalone-empty

2023-01-25 Thread Christopher Di Bella via cfe-commits

Author: Denis Nikitin
Date: 2023-01-25T20:06:41Z
New Revision: 716469b6139ab5ec5c5b5dac32891300260db8eb

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

LOG: [clang-tidy] Fix segfault in bugprone-standalone-empty

The check incorrectly identified empty() method call in the template
class definition as a stand-alone function call.
This led to a crash because the checker did not expect empty() function
calls without arguments.

Fixes: https://github.com/llvm/llvm-project/issues/59487

Reviewed By: cjdb

Differential Revision: https://reviews.llvm.org/D142423

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp
clang-tools-extra/docs/clang-tidy/checks/bugprone/standalone-empty.rst
clang-tools-extra/test/clang-tidy/checkers/bugprone/standalone-empty.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp
index 67d8e3693fb56..a66f838f1c8fa 100644
--- a/clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp
@@ -29,10 +29,12 @@ namespace clang::tidy::bugprone {
 using ast_matchers::BoundNodes;
 using ast_matchers::callee;
 using ast_matchers::callExpr;
+using ast_matchers::classTemplateDecl;
 using ast_matchers::cxxMemberCallExpr;
 using ast_matchers::cxxMethodDecl;
 using ast_matchers::expr;
 using ast_matchers::functionDecl;
+using ast_matchers::hasAncestor;
 using ast_matchers::hasName;
 using ast_matchers::hasParent;
 using ast_matchers::ignoringImplicit;
@@ -70,10 +72,13 @@ const Expr *getCondition(const BoundNodes &Nodes, const 
StringRef NodeId) {
 }
 
 void StandaloneEmptyCheck::registerMatchers(ast_matchers::MatchFinder *Finder) 
{
+  // Ignore empty calls in a template definition which fall under callExpr
+  // non-member matcher even if they are methods.
   const auto NonMemberMatcher = expr(ignoringImplicit(ignoringParenImpCasts(
   callExpr(
   hasParent(stmt(optionally(hasParent(stmtExpr().bind("stexpr"
 .bind("parent")),
+  unless(hasAncestor(classTemplateDecl())),
   callee(functionDecl(hasName("empty"), unless(returns(voidType())
   .bind("empty";
   const auto MemberMatcher =
@@ -154,6 +159,8 @@ void StandaloneEmptyCheck::check(const 
MatchFinder::MatchResult &Result) {
   return;
 if (ParentReturnStmt)
   return;
+if (NonMemberCall->getNumArgs() != 1)
+  return;
 
 SourceLocation NonMemberLoc = NonMemberCall->getExprLoc();
 SourceLocation NonMemberEndLoc = NonMemberCall->getEndLoc();

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/standalone-empty.rst 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/standalone-empty.rst
index 049698a8b0f7a..80805bafddd50 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/standalone-empty.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/standalone-empty.rst
@@ -3,8 +3,8 @@
 bugprone-standalone-empty
 =
 
-Warns when `empty()` is used on a range and the result is ignored. Suggests 
-`clear()` if it is an existing member function.
+Warns when ``empty()`` is used on a range and the result is ignored. Suggests
+``clear()`` if it is an existing member function.
 
 The ``empty()`` method on several common ranges returns a Boolean indicating
 whether or not the range is empty, but is often mistakenly interpreted as
@@ -29,3 +29,8 @@ A call to ``clear()`` would appropriately clear the contents 
of the range:
   std::vector v;
   ...
   v.clear();
+
+Limitations:
+- Doesn't warn if ``empty()`` is defined and used with the ignore result in the
+  class template definition (for example in the library implementation). These
+  error cases can be caught with ``[[nodiscard]]`` attribute.

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/standalone-empty.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/standalone-empty.cpp
index d7615fdbbe922..53c651879f84b 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/standalone-empty.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/standalone-empty.cpp
@@ -80,6 +80,10 @@ template 
 void empty(T &&);
 } // namespace test
 
+namespace test_no_args {
+bool empty();
+} // namespace test_no_args
+
 namespace base {
 template 
 struct base_vector {
@@ -306,6 +310,9 @@ bool test_qualified_empty() {
 
 test::empty(v);
 // no-warning
+
+test_no_args::empty();
+// no-warning
   }
 
   {
@@ -876,3 +883,24 @@ bool test_clear_with_qualifiers() {
 // no-warning
   }
 }
+
+namespace user_lib {
+template 
+struct vector {
+  bool empty();
+  bool test_empty_inside_

[clang] 8effeb4 - Add -Wreturn-local-addr, GCC alias for -Wreturn-stack-address

2023-01-12 Thread Christopher Di Bella via cfe-commits

Author: Adrian Dole
Date: 2023-01-12T18:25:12Z
New Revision: 8effeb44f4a8ae3da8c594fdc69ac46dd6ab6f1b

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

LOG: Add -Wreturn-local-addr, GCC alias for -Wreturn-stack-address

For warning compatibility with GCC.

Reviewed By: cjdb

Differential Revision: https://reviews.llvm.org/D139570

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticGroups.td
clang/test/SemaCXX/return-stack-addr-2.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ebc177ef1b1e..65a9d65715dd 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -449,6 +449,7 @@ Improvements to Clang's diagnostics
   concepts-ts compatibility extension.
 - Clang now diagnoses overflow undefined behavior in a constant expression 
while
   evaluating a compound assignment with remainder as operand.
+- Add ``-Wreturn-local-addr``, a GCC alias for ``-Wreturn-stack-address``.
 
 Non-comprehensive list of changes in this release
 -

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6f282071b525..f71bb401e9a1 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -413,6 +413,8 @@ def DanglingField : DiagGroup<"dangling-field">;
 def DanglingInitializerList : DiagGroup<"dangling-initializer-list">;
 def DanglingGsl : DiagGroup<"dangling-gsl">;
 def ReturnStackAddress : DiagGroup<"return-stack-address">;
+// Name of this warning in GCC
+def : DiagGroup<"return-local-addr", [ReturnStackAddress]>;
 def Dangling : DiagGroup<"dangling", [DanglingField,
   DanglingInitializerList,
   DanglingGsl,

diff  --git a/clang/test/SemaCXX/return-stack-addr-2.cpp 
b/clang/test/SemaCXX/return-stack-addr-2.cpp
index e848189bde78..fb810902d5e3 100644
--- a/clang/test/SemaCXX/return-stack-addr-2.cpp
+++ b/clang/test/SemaCXX/return-stack-addr-2.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -std=c++11 
-Wno-return-stack-address -Wreturn-local-addr %s
 
 namespace PR26599 {
 template 



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


[clang-tools-extra] 7910ee7 - [clang-tidy] don't warn when returning the result for bugprone-standalone-empty

2023-01-12 Thread Christopher Di Bella via cfe-commits

Author: v1nh1shungry
Date: 2023-01-13T01:14:51Z
New Revision: 7910ee7d8c6dcb679200ba171fba5d8d5f237007

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

LOG: [clang-tidy] don't warn when returning the result for 
bugprone-standalone-empty

Relevant issue: https://github.com/llvm/llvm-project/issues/59517

Currently this check will warn when the result is used in a `return`
statement, e.g.

```
bool foobar() {
  std::vector v;
  return v.empty();
  // will get a warning here, which makes no sense IMO
}
```

Reviewed By: cjdb, denik

Differential Revision: https://reviews.llvm.org/D141107

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/bugprone/standalone-empty.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp
index 34ccd2c61c784..9236bb9009145 100644
--- a/clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp
@@ -98,6 +98,7 @@ void StandaloneEmptyCheck::check(const 
MatchFinder::MatchResult &Result) {
   const auto PParentStmtExpr = Result.Nodes.getNodeAs("stexpr");
   const auto ParentCompStmt = Result.Nodes.getNodeAs("parent");
   const auto *ParentCond = getCondition(Result.Nodes, "parent");
+  const auto *ParentReturnStmt = Result.Nodes.getNodeAs("parent");
 
   if (const auto *MemberCall =
   Result.Nodes.getNodeAs("empty")) {
@@ -109,6 +110,9 @@ void StandaloneEmptyCheck::check(const 
MatchFinder::MatchResult &Result) {
 if (PParentStmtExpr && ParentCompStmt &&
 ParentCompStmt->body_back() == MemberCall->getExprStmt())
   return;
+// Skip if it's a return statement
+if (ParentReturnStmt)
+  return;
 
 SourceLocation MemberLoc = MemberCall->getBeginLoc();
 SourceLocation ReplacementLoc = MemberCall->getExprLoc();
@@ -150,6 +154,8 @@ void StandaloneEmptyCheck::check(const 
MatchFinder::MatchResult &Result) {
 if (PParentStmtExpr && ParentCompStmt &&
 ParentCompStmt->body_back() == NonMemberCall->getExprStmt())
   return;
+if (ParentReturnStmt)
+  return;
 
 SourceLocation NonMemberLoc = NonMemberCall->getExprLoc();
 SourceLocation NonMemberEndLoc = NonMemberCall->getEndLoc();

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/standalone-empty.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/standalone-empty.cpp
index 4f7248a78546f..d7615fdbbe922 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/standalone-empty.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/standalone-empty.cpp
@@ -155,7 +155,7 @@ bool empty(T &&);
 } // namespace qualifiers
 
 
-void test_member_empty() {
+bool test_member_empty() {
   {
 std::vector v;
 v.empty();
@@ -231,9 +231,69 @@ void test_member_empty() {
 s.empty();
 // CHECK-MESSAGES: :[[#@LINE-1]]:5: warning: ignoring the result of 
'empty()' [bugprone-standalone-empty]
   }
+
+  {
+std::vector v;
+return v.empty();
+// no-warning
+  }
+
+  {
+std::vector_with_clear v;
+return v.empty();
+// no-warning
+  }
+
+  {
+std::vector_with_int_empty v;
+return v.empty();
+// no-warning
+  }
+
+  {
+std::vector_with_clear_args v;
+return v.empty();
+// no-warning
+  }
+
+  {
+std::vector_with_clear_variable v;
+return v.empty();
+// no-warning
+  }
+
+  {
+absl::string s;
+return s.empty();
+// no-warning
+  }
+
+  {
+absl::string_with_clear s;
+return s.empty();
+// no-warning
+  }
+
+  {
+absl::string_with_int_empty s;
+return s.empty();
+// no-warning
+  }
+
+  {
+absl::string_with_clear_args s;
+return s.empty();
+// no-warning
+  }
+
+  {
+absl::string_with_clear_variable s;
+return s.empty();
+// no-warning
+  }
 }
 
-void test_qualified_empty() {
+bool test_qualified_empty() {
   {
 absl::string_with_clear v;
 std::empty(v);
@@ -260,9 +320,30 @@ void test_qualified_empty() {
 absl::empty(nullptr);
 // no-warning
   }
+
+  {
+absl::string_with_clear s;
+return std::empty(s);
+// no-warning
+return absl::empty(s);
+// no-warning
+  }
+
+  {
+absl::string s;
+return std::empty(s);
+// no-warning
+  }
+
+  {
+return std::empty(0);
+// no-warning
+return absl::empty(nullptr);
+// no-warning
+  }
 }
 
-void test_unqualified_empty() {
+bool test_unqualified_empty() {
   {
 std::vector v;
 empty(v);
@@ -370,6 +451,106 @@ void test_unqualified_empty() {
 // CHECK-MESSAGES: :[[#@LINE-1]]:5: warning: ignoring the result of 
'absl::empty'; did you mean '

[clang] f21187e - [clang][tablegen] adds human documentation to `WarningOption`

2022-06-10 Thread Christopher Di Bella via cfe-commits

Author: Christopher Di Bella
Date: 2022-06-10T17:23:00Z
New Revision: f21187eb2d943c1407ae764b87f73602177dcba8

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

LOG: [clang][tablegen] adds human documentation to `WarningOption`

Building on D126796, this commit adds the infrastructure for being able
to print out descriptions of what each warning does.

Differential Revision: https://reviews.llvm.org/D126832

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticCategories.h
clang/include/clang/Basic/DiagnosticIDs.h
clang/lib/Basic/DiagnosticIDs.cpp
clang/tools/diagtool/DiagnosticNames.cpp
clang/utils/TableGen/ClangDiagnosticsEmitter.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5905fa2e917e5..cf140d31f6187 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -110,12 +110,12 @@ Bug Fixes
   `51414 `_,
   `51416 `_,
   and `51641 `_.
-- The builtin function __builtin_dump_struct would crash clang when the target 
+- The builtin function __builtin_dump_struct would crash clang when the target
   struct contains a bitfield. It now correctly handles bitfields.
   This fixes Issue `Issue 54462 
`_.
 - Statement expressions are now disabled in default arguments in general.
   This fixes Issue `Issue 53488 
`_.
-- According to `CWG 1394 `_ and 
+- According to `CWG 1394 `_ and
   `C++20 [dcl.fct.def.general]p2 
`_,
   Clang should not diagnose incomplete types in function definitions if the 
function body is "= delete;".
   This fixes Issue `Issue 52802 
`_.
@@ -149,8 +149,8 @@ Bug Fixes
   because there is no way to fully qualify the enumerator name, so this
   "extension" was unintentional and useless. This fixes
   `Issue 42372 `_.
-- Clang will now find and emit a call to an allocation function in a 
-  promise_type body for coroutines if there is any allocation function 
+- Clang will now find and emit a call to an allocation function in a
+  promise_type body for coroutines if there is any allocation function
   declaration in the scope of promise_type. Additionally, to implement CWG2585,
   a coroutine will no longer generate a call to a global allocation function
   with the signature (std::size_t, p0, ..., pn).
@@ -296,6 +296,8 @@ New Compiler Flags
   operations, such as division or float-to-integer conversion, on ``_BitInt``
   types with more than 128 bits currently crash clang. This option will be
   removed in the future once clang supports all such operations.
+- Added the ``-print-diagnostic-options`` option, which prints a list of
+  warnings the compiler supports.
 
 Deprecated Compiler Flags
 -
@@ -545,7 +547,7 @@ Static Analyzer
 
 - Added a new checker ``alpha.unix.cstring.UninitializedRead`` this will check 
for uninitialized reads
   from common memory copy/manipulation functions such as ``memcpy``, 
``mempcpy``, ``memmove``, ``memcmp``, `
-  `strcmp``, ``strncmp``, ``strcpy``, ``strlen``, ``strsep`` and many more. 
Although 
+  `strcmp``, ``strncmp``, ``strcpy``, ``strlen``, ``strsep`` and many more. 
Although
   this checker currently is in list of alpha checkers due to a false positive.
 
 .. _release-notes-ubsan:

diff  --git a/clang/include/clang/Basic/DiagnosticCategories.h 
b/clang/include/clang/Basic/DiagnosticCategories.h
index 2bbdeb31a7b7d..14be326f7515f 100644
--- a/clang/include/clang/Basic/DiagnosticCategories.h
+++ b/clang/include/clang/Basic/DiagnosticCategories.h
@@ -21,7 +21,8 @@ namespace clang {
 };
 
 enum class Group {
-#define DIAG_ENTRY(GroupName, FlagNameOffset, Members, SubGroups) GroupName,
+#define DIAG_ENTRY(GroupName, FlagNameOffset, Members, SubGroups, Docs)
\
+  GroupName,
 #include "clang/Basic/DiagnosticGroups.inc"
 #undef CATEGORY
 #undef DIAG_ENTRY

diff  --git a/clang/include/clang/Basic/DiagnosticIDs.h 
b/clang/include/clang/Basic/DiagnosticIDs.h
index f27bf356888c4..709d5e1dc80d4 100644
--- a/clang/include/clang/Basic/DiagnosticIDs.h
+++ b/clang/include/clang/Basic/DiagnosticIDs.h
@@ -231,6 +231,9 @@ class DiagnosticIDs : public RefCountedBase {
   /// "deprecated-declarations".
   static StringRef getWarningOptionForGroup(diag::Group);
 
+  /// Given a diagnostic group ID, return it

[clang] 288c1bf - [clang][driver] adds `-print-diagnostics`

2022-06-08 Thread Christopher Di Bella via cfe-commits

Author: Christopher Di Bella
Date: 2022-06-08T17:55:31Z
New Revision: 288c1bff96fc9042d01b7055dc6e1049d8b54b26

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

LOG: [clang][driver] adds `-print-diagnostics`

Prints a list of all the warnings that Clang offers.

Differential Revision: https://reviews.llvm.org/D126796

Added: 
clang/test/Driver/print-diagnostic-options.c

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Basic/DiagnosticIDs.cpp
clang/lib/Driver/Driver.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index b2feed0e36329..de3cd2ded8bef 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4005,6 +4005,8 @@ def print_rocm_search_dirs : Flag<["-", "--"], 
"print-rocm-search-dirs">,
   HelpText<"Print the paths used for finding ROCm installation">;
 def print_runtime_dir : Flag<["-", "--"], "print-runtime-dir">,
   HelpText<"Print the directory pathname containing clangs runtime libraries">;
+def print_diagnostic_options : Flag<["-", "--"], "print-diagnostic-options">,
+  HelpText<"Print all of Clang's warning options">;
 def private__bundle : Flag<["-"], "private_bundle">;
 def pthreads : Flag<["-"], "pthreads">;
 defm pthread : BoolOption<"", "pthread",

diff  --git a/clang/lib/Basic/DiagnosticIDs.cpp 
b/clang/lib/Basic/DiagnosticIDs.cpp
index a8a17994f7fc8..cc6b19646d1d6 100644
--- a/clang/lib/Basic/DiagnosticIDs.cpp
+++ b/clang/lib/Basic/DiagnosticIDs.cpp
@@ -653,7 +653,7 @@ StringRef DiagnosticIDs::getWarningOptionForDiag(unsigned 
DiagID) {
 }
 
 std::vector DiagnosticIDs::getDiagnosticFlags() {
-  std::vector Res;
+  std::vector Res{"-W", "-Wno-"};
   for (size_t I = 1; DiagGroupNames[I] != '\0';) {
 std::string Diag(DiagGroupNames + I + 1, DiagGroupNames[I]);
 I += DiagGroupNames[I] + 1;

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 8e698a2a7cbef..8f7e411696e2c 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2010,6 +2010,13 @@ bool Driver::HandleImmediateArgs(const Compilation &C) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_diagnostic_options)) {
+std::vector Flags = DiagnosticIDs::getDiagnosticFlags();
+for (std::size_t I = 0; I != Flags.size(); I += 2)
+  llvm::outs() << "  " << Flags[I] << "\n  " << Flags[I + 1] << "\n\n";
+return false;
+  }
+
   // FIXME: The following handlers should use a callback mechanism, we don't
   // know what the client would like to do.
   if (Arg *A = C.getArgs().getLastArg(options::OPT_print_file_name_EQ)) {

diff  --git a/clang/test/Driver/print-diagnostic-options.c 
b/clang/test/Driver/print-diagnostic-options.c
new file mode 100644
index 0..fc6d1bf2eff53
--- /dev/null
+++ b/clang/test/Driver/print-diagnostic-options.c
@@ -0,0 +1,13 @@
+// Test that -print-diagnostic-options prints warning groups and disablers
+
+// RUN: %clang -print-diagnostic-options | FileCheck %s
+
+// CHECK:  -W
+// CHECK:  -Wno-
+// CHECK:  -W#pragma-messages
+// CHECK:  -Wno-#pragma-messages
+// CHECK:  -W#warnings
+// CHECK:  -Wabi
+// CHECK:  -Wno-abi
+// CHECK:  -Wall
+// CHECK:  -Wno-all



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


[clang] [clang][Diagnostics] Highlight code snippets (PR #66514)

2023-09-22 Thread Christopher Di Bella via cfe-commits
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= 
Message-ID:
In-Reply-To: 


cjdb wrote:

I'm okay with the change in general.

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


[clang] [clang][Diagnostics] Make 'note' color CYAN (PR #66997)

2023-09-26 Thread Christopher Di Bella via cfe-commits

cjdb wrote:

This doesn't really fix the problem, it just shuffles it around. I expect 
people with blue(ish) terminals will experience the same issue after this is 
applied, so we ought to try and detect what colours to print out, and then have 
compatible themes.

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


[clang] [clang][Diagnostics] Make 'note' color CYAN (PR #66997)

2023-09-26 Thread Christopher Di Bella via cfe-commits

cjdb wrote:

> This is a one-liner that fixes the problem on terminals with a dark 
> background and the solution also works on light backgrounds. So, basically 
> all of them.

Before approving this change, I want confirmation that it doesn't adversely 
impact popular themes. The Tomorrow Night Blue theme that's in my Visual Studio 
Code client (not my theme, but one of the defaults, I think) does need to 
change the hue of its blue text.

If we can't detect the background, then I think it's extra important that we 
test this on as many themes as possible, and with colourblind filters as well.

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


[clang] [clang][Diagnostics] Make 'note' color CYAN (PR #66997)

2023-09-26 Thread Christopher Di Bella via cfe-commits

cjdb wrote:

> Not really, CYAN is only cyan if that's what your terminal decides to render 
> the color 6 as, you can configure it to be orange if you want.

Oh, interesting. In that case, I see no problems.

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


[clang] Recommit "Implement [[msvc::no_unique_address]] (#65675)" (PR #67199)

2023-09-28 Thread Christopher Di Bella via cfe-commits

cjdb wrote:

Thanks @amykhuang! 🎉 

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


[clang] [Sema] Use underlying type of scoped enum for -Wformat diagnostics (PR #67378)

2023-10-02 Thread Christopher Di Bella via cfe-commits

https://github.com/cjdb commented:

Thanks for working on this, it seems like an important fix. Would you mind 
updating the release notes please? I'll approve afterwards.

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


[clang-tools-extra] [Sema] Use underlying type of scoped enum for -Wformat diagnostics (PR #67378)

2023-10-02 Thread Christopher Di Bella via cfe-commits

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

LGTM, thanks! Do you require assistance committing?

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


[clang] [clang][Diagnostics] Add bitfield source range to zero width diags (PR #68312)

2023-10-05 Thread Christopher Di Bella via cfe-commits

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


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


[clang] 38e1c59 - [clang] adds `conceptDecl` as an ASTMatcher

2023-07-20 Thread Christopher Di Bella via cfe-commits

Author: Christopher Di Bella
Date: 2023-07-20T23:33:46Z
New Revision: 38e1c597033de0c7655abb39335b364408865d2a

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

LOG: [clang] adds `conceptDecl` as an ASTMatcher

Closes #63934

Differential Revision: https://reviews.llvm.org/D155549

Added: 


Modified: 
clang/docs/LibASTMatchersReference.html
clang/docs/ReleaseNotes.rst
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/lib/ASTMatchers/ASTMatchersInternal.cpp
clang/lib/ASTMatchers/Dynamic/Registry.cpp
clang/unittests/AST/DeclTest.cpp

Removed: 




diff  --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index b4f282fbf43816..4f2a1f9508baa2 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -682,6 +682,15 @@ Node Matchers
 
 
 
+MatcherDecl>conceptDeclMatcherConceptDecl>...
+Matches concept 
declarations.
+
+Example matches integral
+  template
+  concept integral = std::is_integral_v;
+
+
+
 MatcherDecl>cxxConstructorDeclMatcherCXXConstructorDecl>...
 Matches C++ 
constructor declarations.
 

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f1d098ef02f41d..bb9daddef8d198 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -262,6 +262,7 @@ Non-comprehensive list of changes in this release
 - Added ``__builtin_elementwise_nearbyint`` for floating point
   types. This allows access to ``llvm.nearbyint`` for arbitrary
   floating-point and vector of floating-point types.
+- Clang AST matcher now matches concept declarations with `conceptDecl`.
 
 New Compiler Flags
 --

diff  --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index a9313139226ca4..f49204a3d90626 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -1334,6 +1334,16 @@ extern const internal::VariadicDynCastAllOfMatcher
 extern const internal::VariadicDynCastAllOfMatcher
 cxxDeductionGuideDecl;
 
+/// Matches concept declarations.
+///
+/// Example matches integral
+/// \code
+///   template
+///   concept integral = std::is_integral_v;
+/// \endcode
+extern const internal::VariadicDynCastAllOfMatcher
+conceptDecl;
+
 /// Matches variable declarations.
 ///
 /// Note: this does not match declarations of member variables, which are

diff  --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp 
b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
index ad6b20f4fd2ff8..3470467112dd5f 100644
--- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -800,6 +800,7 @@ const internal::VariadicDynCastAllOfMatcher 
tagDecl;
 const internal::VariadicDynCastAllOfMatcher cxxMethodDecl;
 const internal::VariadicDynCastAllOfMatcher
 cxxConversionDecl;
+const internal::VariadicDynCastAllOfMatcher conceptDecl;
 const internal::VariadicDynCastAllOfMatcher varDecl;
 const internal::VariadicDynCastAllOfMatcher fieldDecl;
 const internal::VariadicDynCastAllOfMatcher

diff  --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp 
b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index d3594455b55a46..1098df032a64b9 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -172,6 +172,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(compoundLiteralExpr);
   REGISTER_MATCHER(compoundStmt);
   REGISTER_MATCHER(coawaitExpr);
+  REGISTER_MATCHER(conceptDecl);
   REGISTER_MATCHER(conditionalOperator);
   REGISTER_MATCHER(constantArrayType);
   REGISTER_MATCHER(constantExpr);

diff  --git a/clang/unittests/AST/DeclTest.cpp 
b/clang/unittests/AST/DeclTest.cpp
index 463f35c1cd08b7..54a1f2c5843548 100644
--- a/clang/unittests/AST/DeclTest.cpp
+++ b/clang/unittests/AST/DeclTest.cpp
@@ -12,9 +12,11 @@
 
 #include "clang/AST/Decl.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Mangle.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Lex/Lexer.h"
@@ -140,6 +142,22 @@ TEST(Decl, MangleDependentSizedArray) {
   ASSERT_TRUE(0 == MangleB.compare("_ZTSAT0__T_"));
 }
 
+TEST(Decl, ConceptDecl) {
+  llvm::StringRef Code(R"(
+template
+concept integral = __is_integral(T);
+  )");
+
+  auto 

[clang] [sema] Improve -Wsign-compare (PR #65684)

2023-10-06 Thread Christopher Di Bella via cfe-commits
=?utf-8?q?Félix?= Cloutier 
Message-ID:
In-Reply-To: 


https://github.com/cjdb commented:

Generally speaking, I'm in favour of this; thanks so much for identifying this 
problem!

When C++20 is available, we ought to suggest using `std:: is_lt` and friends 
instead. Possibly something like

```
note: C++20 provides 'std::is_lt(s, u)' for this use-case
```

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


[clang] e1bfeb6 - adds `__reference_constructs_from_temporary`

2023-09-11 Thread Christopher Di Bella via cfe-commits

Author: Christopher Di Bella
Date: 2023-09-11T23:14:08Z
New Revision: e1bfeb6bcc627a94c5ab3a5417d290c7dc516d54

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

LOG: adds `__reference_constructs_from_temporary`

This is information that the compiler already has, and should be exposed
so that the library doesn't need to reimplement the exact same
functionality.

Differential Revision: https://reviews.llvm.org/D135341

Added: 


Modified: 
clang/docs/LanguageExtensions.rst
clang/include/clang/Basic/TokenKinds.def
clang/lib/Lex/PPMacroExpansion.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Parse/ParseExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/test/SemaCXX/type-traits.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 11cbdca7a268fc3..b9466b5a0bc2087 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1621,6 +1621,10 @@ The following type trait primitives are supported by 
Clang. Those traits marked
   materialized temporary object. If ``T`` is not a reference type the result
   is false. Note this trait will also return false when the initialization of
   ``T`` from ``U`` is ill-formed.
+  Deprecated, use ``__reference_constructs_from_temporary``.
+* ``__reference_constructs_from_temporary(T, U)`` (C++)
+  Returns true if a reference ``T`` can be constructed from a temporary of type
+  a non-cv-qualified ``U``.
 * ``__underlying_type`` (C++, GNU, Microsoft)
 
 In addition, the following expression traits are supported:

diff  --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 45ebc200b168986..72e8df8c793a7b6 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -531,6 +531,7 @@ TYPE_TRAIT_1(__is_scoped_enum, IsScopedEnum, KEYCXX)
 TYPE_TRAIT_1(__is_referenceable, IsReferenceable, KEYCXX)
 TYPE_TRAIT_1(__can_pass_in_regs, CanPassInRegs, KEYCXX)
 TYPE_TRAIT_2(__reference_binds_to_temporary, ReferenceBindsToTemporary, KEYCXX)
+TYPE_TRAIT_2(__reference_constructs_from_temporary, 
ReferenceConstructsFromTemporary, KEYCXX)
 
 // Embarcadero Expression Traits
 EXPRESSION_TRAIT(__is_lvalue_expr, IsLValueExpr, KEYCXX)

diff  --git a/clang/lib/Lex/PPMacroExpansion.cpp 
b/clang/lib/Lex/PPMacroExpansion.cpp
index 775cbfafa999602..ec6a084f228f32d 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -1695,6 +1695,7 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
   .Case("__array_rank", true)
   .Case("__array_extent", true)
   .Case("__reference_binds_to_temporary", true)
+  .Case("__reference_constructs_from_temporary", true)
 #define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) .Case("__" #Trait, true)
 #include "clang/Basic/TransformTypeTraits.def"
   .Default(false);

diff  --git a/clang/lib/Parse/ParseDeclCXX.cpp 
b/clang/lib/Parse/ParseDeclCXX.cpp
index 730b6e55246d6b7..5fe9abb1fdcab30 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -1655,7 +1655,9 @@ void Parser::ParseClassSpecifier(tok::TokenKind 
TagTokKind,
   tok::kw___is_union,
   tok::kw___is_unsigned,
   tok::kw___is_void,
-  tok::kw___is_volatile))
+  tok::kw___is_volatile,
+  tok::kw___reference_binds_to_temporary,
+  tok::kw___reference_constructs_from_temporary))
 // GNU libstdc++ 4.2 and libc++ use certain intrinsic names as the
 // name of struct templates, but some are keywords in GCC >= 4.3
 // and Clang. Therefore, when we see the token sequence "struct

diff  --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index f8bf785da2896a3..74664c34abdbd89 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1128,6 +1128,8 @@ ExprResult Parser::ParseCastExpression(CastParseKind 
ParseKind,
   REVERTIBLE_TYPE_TRAIT(__is_unsigned);
   REVERTIBLE_TYPE_TRAIT(__is_void);
   REVERTIBLE_TYPE_TRAIT(__is_volatile);
+  REVERTIBLE_TYPE_TRAIT(__reference_binds_to_temporary);
+  REVERTIBLE_TYPE_TRAIT(__reference_constructs_from_temporary);
 #define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) 
\
   REVERTIBLE_TYPE_TRAIT(RTT_JOIN(__, Trait));
 #include "clang/Basic/TransformTypeTraits.def"

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index a7be01319a72393..65e8edc7806ecd8 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -30,6 +30,7 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TokenKinds.h"
 #inc

[clang] dfd1d8d - Revert "adds `__reference_constructs_from_temporary`"

2023-09-11 Thread Christopher Di Bella via cfe-commits

Author: Christopher Di Bella
Date: 2023-09-11T23:44:50Z
New Revision: dfd1d8d505d61c9b401a3cdd6a687848f1c37cc5

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

LOG: Revert "adds `__reference_constructs_from_temporary`"

I'm reverting this on principle, since it didn't get the Phabricator
approval I thought it had (only an informal LGTM). Will re-apply once
it has been properly approved.

This reverts commit e1bfeb6bcc627a94c5ab3a5417d290c7dc516d54.

Added: 


Modified: 
clang/docs/LanguageExtensions.rst
clang/include/clang/Basic/TokenKinds.def
clang/lib/Lex/PPMacroExpansion.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Parse/ParseExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/test/SemaCXX/type-traits.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index b9466b5a0bc2087..11cbdca7a268fc3 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1621,10 +1621,6 @@ The following type trait primitives are supported by 
Clang. Those traits marked
   materialized temporary object. If ``T`` is not a reference type the result
   is false. Note this trait will also return false when the initialization of
   ``T`` from ``U`` is ill-formed.
-  Deprecated, use ``__reference_constructs_from_temporary``.
-* ``__reference_constructs_from_temporary(T, U)`` (C++)
-  Returns true if a reference ``T`` can be constructed from a temporary of type
-  a non-cv-qualified ``U``.
 * ``__underlying_type`` (C++, GNU, Microsoft)
 
 In addition, the following expression traits are supported:

diff  --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 72e8df8c793a7b6..45ebc200b168986 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -531,7 +531,6 @@ TYPE_TRAIT_1(__is_scoped_enum, IsScopedEnum, KEYCXX)
 TYPE_TRAIT_1(__is_referenceable, IsReferenceable, KEYCXX)
 TYPE_TRAIT_1(__can_pass_in_regs, CanPassInRegs, KEYCXX)
 TYPE_TRAIT_2(__reference_binds_to_temporary, ReferenceBindsToTemporary, KEYCXX)
-TYPE_TRAIT_2(__reference_constructs_from_temporary, 
ReferenceConstructsFromTemporary, KEYCXX)
 
 // Embarcadero Expression Traits
 EXPRESSION_TRAIT(__is_lvalue_expr, IsLValueExpr, KEYCXX)

diff  --git a/clang/lib/Lex/PPMacroExpansion.cpp 
b/clang/lib/Lex/PPMacroExpansion.cpp
index ec6a084f228f32d..775cbfafa999602 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -1695,7 +1695,6 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
   .Case("__array_rank", true)
   .Case("__array_extent", true)
   .Case("__reference_binds_to_temporary", true)
-  .Case("__reference_constructs_from_temporary", true)
 #define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) .Case("__" #Trait, true)
 #include "clang/Basic/TransformTypeTraits.def"
   .Default(false);

diff  --git a/clang/lib/Parse/ParseDeclCXX.cpp 
b/clang/lib/Parse/ParseDeclCXX.cpp
index 5fe9abb1fdcab30..730b6e55246d6b7 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -1655,9 +1655,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind 
TagTokKind,
   tok::kw___is_union,
   tok::kw___is_unsigned,
   tok::kw___is_void,
-  tok::kw___is_volatile,
-  tok::kw___reference_binds_to_temporary,
-  tok::kw___reference_constructs_from_temporary))
+  tok::kw___is_volatile))
 // GNU libstdc++ 4.2 and libc++ use certain intrinsic names as the
 // name of struct templates, but some are keywords in GCC >= 4.3
 // and Clang. Therefore, when we see the token sequence "struct

diff  --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 74664c34abdbd89..f8bf785da2896a3 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1128,8 +1128,6 @@ ExprResult Parser::ParseCastExpression(CastParseKind 
ParseKind,
   REVERTIBLE_TYPE_TRAIT(__is_unsigned);
   REVERTIBLE_TYPE_TRAIT(__is_void);
   REVERTIBLE_TYPE_TRAIT(__is_volatile);
-  REVERTIBLE_TYPE_TRAIT(__reference_binds_to_temporary);
-  REVERTIBLE_TYPE_TRAIT(__reference_constructs_from_temporary);
 #define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) 
\
   REVERTIBLE_TYPE_TRAIT(RTT_JOIN(__, Trait));
 #include "clang/Basic/TransformTypeTraits.def"

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 65e8edc7806ecd8..a7be01319a72393 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -30,7 +30,6 @@
 #include "clang/Basic/TargetInfo.h"
 #includ

  1   2   >