[clang] 827ba67 - [Sema] Validate calls to GetExprRange.

2020-08-16 Thread Mark de Wever via cfe-commits

Author: Mark de Wever
Date: 2020-08-16T18:32:38+02:00
New Revision: 827ba67e383313b05e9b10c8215e501530d6c9e3

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

LOG: [Sema] Validate calls to GetExprRange.

When a conditional expression has a throw expression it called
GetExprRange with a void expression, which caused an assertion failure.

This approach was suggested by Richard Smith.

Fixes PR46484: Clang crash in clang/lib/Sema/SemaChecking.cpp:10028

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

Added: 


Modified: 
clang/lib/Sema/SemaChecking.cpp
clang/test/SemaCXX/conditional-expr.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index bbd856e9262e..4efd62f58d2e 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -10368,10 +10368,16 @@ static IntRange GetExprRange(ASTContext &C, const 
Expr *E, unsigned MaxWidth,
   MaxWidth, InConstantContext);
 
 // Otherwise, conservatively merge.
-IntRange L =
-GetExprRange(C, CO->getTrueExpr(), MaxWidth, InConstantContext);
-IntRange R =
-GetExprRange(C, CO->getFalseExpr(), MaxWidth, InConstantContext);
+// GetExprRange requires an integer expression, but a throw expression
+// results in a void type.
+Expr *E = CO->getTrueExpr();
+IntRange L = E->getType()->isVoidType()
+ ? IntRange{0, true}
+ : GetExprRange(C, E, MaxWidth, InConstantContext);
+E = CO->getFalseExpr();
+IntRange R = E->getType()->isVoidType()
+ ? IntRange{0, true}
+ : GetExprRange(C, E, MaxWidth, InConstantContext);
 return IntRange::join(L, R);
   }
 

diff  --git a/clang/test/SemaCXX/conditional-expr.cpp 
b/clang/test/SemaCXX/conditional-expr.cpp
index 8d0555ea5068..68e23a1f5727 100644
--- a/clang/test/SemaCXX/conditional-expr.cpp
+++ b/clang/test/SemaCXX/conditional-expr.cpp
@@ -409,3 +409,20 @@ namespace lifetime_extension {
 D d = b ? D{B()} : D{C()};
   }
 }
+
+namespace PR46484 {
+// expected-error@+4{{expected ':'}}
+// expected-note@+3{{to match this '?'}}
+// expected-warning@+2{{variable 'b' is uninitialized}}
+// expected-error@+1 2 {{expected ';' after top level declarator}}
+int a long b = a = b ? throw 0 1
+
+void g() {
+  extern int a;
+  extern long b;
+  long c = a = b ? throw 0 : 1;
+  long d = a = b ? 1 : throw 0;
+  // expected-error@+1 {{assigning to 'int' from incompatible type 'void'}}
+  long e = a = b ? throw 0 : throw 1;
+}
+} // namespace PR46484



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


[clang] fef2607 - [Sema] Use the proper cast for a fixed bool enum.

2020-08-16 Thread Mark de Wever via cfe-commits

Author: Mark de Wever
Date: 2020-08-16T18:40:08+02:00
New Revision: fef26071240711e8f7305715b5f22cfc7ad04bfe

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

LOG: [Sema] Use the proper cast for a fixed bool enum.

When casting an enumerate with a fixed bool type the casting should use
an IntegralToBoolean instead of an IntegralCast as is required per Core
Issue 2338.

Fixes PR47055: Incorrect codegen for enum with bool underlying type

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

Added: 
clang/test/CodeGen/enum-bool.cpp

Modified: 
clang/lib/Sema/SemaCast.cpp
clang/test/CXX/drs/dr23xx.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index 93752766f4a2..726900c59f20 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/lib/Sema/SemaCast.cpp
@@ -1243,7 +1243,13 @@ static TryCastResult TryStaticCast(Sema &Self, 
ExprResult &SrcExpr,
   return TC_Failed;
 }
 if (SrcType->isIntegralOrEnumerationType()) {
-  Kind = CK_IntegralCast;
+  // [expr.static.cast]p10 If the enumeration type has a fixed underlying
+  // type, the value is first converted to that type by integral conversion
+  const EnumType *Enum = DestType->getAs();
+  Kind = Enum->getDecl()->isFixed() &&
+ Enum->getDecl()->getIntegerType()->isBooleanType()
+ ? CK_IntegralToBoolean
+ : CK_IntegralCast;
   return TC_Success;
 } else if (SrcType->isRealFloatingType())   {
   Kind = CK_FloatingToIntegral;

diff  --git a/clang/test/CXX/drs/dr23xx.cpp b/clang/test/CXX/drs/dr23xx.cpp
index c265ebbe359c..a7ff2a5813ed 100644
--- a/clang/test/CXX/drs/dr23xx.cpp
+++ b/clang/test/CXX/drs/dr23xx.cpp
@@ -4,6 +4,19 @@
 // RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors 2>&1 | FileCheck %s
 // RUN: %clang_cc1 -std=c++2a %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors 2>&1 | FileCheck %s
 
+#if __cplusplus >= 201103L
+namespace dr2338 { // dr2338: 12
+namespace B {
+enum E : bool { Zero, One };
+static_assert((int)(E)2 == 1, "");
+} // namespace B
+namespace D {
+enum class E : bool { Zero, One };
+static_assert((int)(E)2 == 1, "");
+} // namespace D
+} // namespace dr2338
+#endif
+
 namespace dr2346 { // dr2346: 11
   void test() {
 const int i2 = 0;

diff  --git a/clang/test/CodeGen/enum-bool.cpp 
b/clang/test/CodeGen/enum-bool.cpp
new file mode 100644
index ..220baa3fd8b6
--- /dev/null
+++ b/clang/test/CodeGen/enum-bool.cpp
@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -S -emit-llvm -o - %s | 
FileCheck %s
+
+namespace dr2338 {
+namespace A {
+enum E { Zero, One };
+E a(int x) { return static_cast(x); }
+// CHECK-LABEL: define i32 @_ZN6dr23381A1aEi
+// CHECK: ret i32 %0
+
+E b(int x) { return (E)x; }
+// CHECK-LABEL: define i32 @_ZN6dr23381A1bEi
+// CHECK: ret i32 %0
+
+} // namespace A
+namespace B {
+enum E : bool { Zero, One };
+E a(int x) { return static_cast(x); }
+// CHECK-LABEL: define zeroext i1 @_ZN6dr23381B1aEi
+// CHECK: ret i1 %tobool
+
+E b(int x) { return (E)x; }
+// CHECK-LABEL: define zeroext i1 @_ZN6dr23381B1bEi
+// CHECK: ret i1 %tobool
+
+} // namespace B
+namespace C {
+enum class E { Zero, One };
+E a(int x) { return static_cast(x); }
+// CHECK-LABEL: define i32 @_ZN6dr23381C1aEi
+// CHECK: ret i32 %0
+
+E b(int x) { return (E)x; }
+// CHECK-LABEL: define i32 @_ZN6dr23381C1bEi
+// CHECK: ret i32 %0
+
+} // namespace C
+namespace D {
+enum class E : bool { Zero, One };
+E a(int x) { return static_cast(x); }
+// CHECK-LABEL: define zeroext i1 @_ZN6dr23381D1aEi
+// CHECK: ret i1 %tobool
+
+E b(int x) { return (E)x; }
+
+// CHECK-LABEL: define zeroext i1 @_ZN6dr23381D1bEi
+// CHECK: ret i1 %tobool
+
+} // namespace D
+} // namespace dr2338



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


[llvm] [clang-tools-extra] [libcxx] [clang] [libc++][span] P2821R5: span.at() (PR #74994)

2023-12-10 Thread Mark de Wever via cfe-commits

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


[clang-tools-extra] [clang] [llvm] [libcxx] [libc++][span] P2821R5: span.at() (PR #74994)

2023-12-10 Thread Mark de Wever via cfe-commits

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

Thanks for working in this.

I didn't start the CI jobs since I know they will fail.

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


[libcxx] [llvm] [clang-tools-extra] [clang] [libc++][span] P2821R5: span.at() (PR #74994)

2023-12-10 Thread Mark de Wever via cfe-commits


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

mordante wrote:

And `std::__throw_out_of_range()` for consistency.

I prefer not to use `data()[__idx]`. This differs from the wording in the paper.

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


[llvm] [libcxx] [clang-tools-extra] [clang] [libc++][span] P2821R5: span.at() (PR #74994)

2023-12-10 Thread Mark de Wever via cfe-commits


@@ -0,0 +1,136 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// 
+
+// constexpr reference at(size_type idx) const; // since C++26
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_macros.h"
+
+constexpr void testSpanAt(auto span, int idx, int expectedValue) {
+  // non-const
+  {
+std::same_as decltype(auto) elem = 
span.at(idx);
+assert(elem == expectedValue);
+  }
+
+  // const
+  {
+std::same_as decltype(auto) elem = 
std::as_const(span).at(idx);
+assert(elem == expectedValue);
+  }
+}
+
+constexpr bool test() {
+  // With static extent
+  {
+std::array arr{0, 1, 2, 3, 4, 5, 9084};
+std::span arrSpan{arr};
+
+assert(std::dynamic_extent != arrSpan.extent);
+
+testSpanAt(arrSpan, 0, 0);
+testSpanAt(arrSpan, 1, 1);
+testSpanAt(arrSpan, 6, 9084);
+  }
+
+  // With dynamic extent
+  {
+std::vector vec{0, 1, 2, 3, 4, 5, 9084};
+std::span vecSpan{vec};
+
+assert(std::dynamic_extent == vecSpan.extent);
+
+testSpanAt(vecSpan, 0, 0);
+testSpanAt(vecSpan, 1, 1);
+testSpanAt(vecSpan, 6, 9084);
+  }
+
+  return true;
+}
+
+void test_exceptions() {
+#ifndef TEST_HAS_NO_EXCEPTIONS
+  // With static extent
+  {
+std::array arr{1, 2, 3, 4};
+const std::span arrSpan{arr};
+
+try {
+  TEST_IGNORE_NODISCARD arrSpan.at(arr.size() + 1);
+  assert(false);
+} catch (std::out_of_range const&) {
+  // pass

mordante wrote:

For libc++ you can test for the expected message.

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


[libcxx] [clang] [llvm] [clang-tools-extra] [libc++][span] P2821R5: span.at() (PR #74994)

2023-12-10 Thread Mark de Wever via cfe-commits


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

mordante wrote:

You need to export this declaration from the `modules/span.inc` too.

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


[llvm] [libcxx] [clang] [clang-tools-extra] [libc++][span] P2821R5: span.at() (PR #74994)

2023-12-10 Thread Mark de Wever via cfe-commits


@@ -146,6 +147,9 @@ template
 #include <__utility/forward.h>
 #include // for array
 #include   // for byte
+#if _LIBCPP_STD_VER >= 26
+#  include 

mordante wrote:

Typically we unconditionally include headers.

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


[clang-tools-extra] [libcxx] [llvm] [clang] [libc++][span] P2821R5: span.at() (PR #74994)

2023-12-10 Thread Mark de Wever via cfe-commits


@@ -0,0 +1,136 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// 
+
+// constexpr reference at(size_type idx) const; // since C++26
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_macros.h"
+
+constexpr void testSpanAt(auto span, int idx, int expectedValue) {
+  // non-const
+  {
+std::same_as decltype(auto) elem = 
span.at(idx);
+assert(elem == expectedValue);
+  }
+
+  // const
+  {
+std::same_as decltype(auto) elem = 
std::as_const(span).at(idx);
+assert(elem == expectedValue);
+  }
+}
+
+constexpr bool test() {
+  // With static extent
+  {
+std::array arr{0, 1, 2, 3, 4, 5, 9084};
+std::span arrSpan{arr};
+
+assert(std::dynamic_extent != arrSpan.extent);
+
+testSpanAt(arrSpan, 0, 0);
+testSpanAt(arrSpan, 1, 1);
+testSpanAt(arrSpan, 6, 9084);
+  }
+
+  // With dynamic extent
+  {
+std::vector vec{0, 1, 2, 3, 4, 5, 9084};
+std::span vecSpan{vec};
+
+assert(std::dynamic_extent == vecSpan.extent);
+
+testSpanAt(vecSpan, 0, 0);
+testSpanAt(vecSpan, 1, 1);
+testSpanAt(vecSpan, 6, 9084);
+  }
+
+  return true;
+}
+
+void test_exceptions() {
+#ifndef TEST_HAS_NO_EXCEPTIONS
+  // With static extent
+  {
+std::array arr{1, 2, 3, 4};
+const std::span arrSpan{arr};
+
+try {
+  TEST_IGNORE_NODISCARD arrSpan.at(arr.size() + 1);

mordante wrote:

Why do you sugggest `TEST_IGNORE_NODISCARD` -> (void)? That macro has been 
added for a reason. 

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


[libcxx] [llvm] [clang] [clang-tools-extra] [libc++][span] P2821R5: span.at() (PR #74994)

2023-12-10 Thread Mark de Wever via cfe-commits


@@ -552,6 +578,10 @@ public:
 private:
 pointer   __data_;
 size_type __size_;
+
+#  if _LIBCPP_STD_VER >= 26
+_LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI void __throw_out_of_range() const { 
std::__throw_out_of_range("span"); }

mordante wrote:

Either remove the helper function and call `std::__throw_out_of_range("span");` 
directly or move it in the `std` namespace. We now add functions that are 
called once and use indirection for it.

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


[libcxx] [llvm] [clang] [clang-tools-extra] [libc++][span] P2821R5: span.at() (PR #74994)

2023-12-10 Thread Mark de Wever via cfe-commits

https://github.com/mordante commented:

I pressed submit too soon ;-)

You need to update the FTM as implemented too and update the generated files.

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


[libc] [clang-tools-extra] [llvm] [libcxx] [mlir] [clang] [libc++][span] P2821R5: span.at() (PR #74994)

2023-12-11 Thread Mark de Wever via cfe-commits


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

mordante wrote:

@philnik777 requested to remove these braces and I agree. This is the LLVM 
coding style.

https://github.com/llvm/llvm-project/pull/74994
___
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] [libunwind] [libc++] Allow running the test suite with optimizations (PR #68753)

2023-11-16 Thread Mark de Wever via cfe-commits

https://github.com/mordante commented:

In general I like the patch, some comments.

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


[libcxx] [llvm] [clang] [libunwind] [clang-tools-extra] [libc++] Allow running the test suite with optimizations (PR #68753)

2023-11-16 Thread Mark de Wever via cfe-commits


@@ -0,0 +1,4 @@
+set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
+set(LIBCXX_TEST_PARAMS "optimization=speed" CACHE STRING "")

mordante wrote:

Since it's possible to optimized for size too, I'd like "speed" in the name of 
the cache.

https://github.com/llvm/llvm-project/pull/68753
___
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] [libunwind] [libc++] Allow running the test suite with optimizations (PR #68753)

2023-11-16 Thread Mark de Wever via cfe-commits


@@ -0,0 +1,28 @@
+// -*- 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 SUPPORT_ESCAPE_H
+#define SUPPORT_ESCAPE_H
+
+#include "test_macros.h"
+
+namespace support {
+// This function can be used to hide some objects from compiler optimizations.
+//
+// For example, this is useful to hide the result of a call to `new` and ensure
+// ensure that the compiler doesn't elide the call to new/delete. Otherwise,
+// elliding calls to new/delete is allowed by the Standard and compilers 
actually
+// do it when optimizations are enabled.
+template 
+TEST_CONSTEXPR __attribute__((noinline)) T* escape(T* ptr) TEST_NOEXCEPT {

mordante wrote:

I'm not too fond of this name, it does not really tell me what it does. How 
about `do_not_optimized`, which is seen quite often in benchmark suites.

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


[llvm] [libcxx] [libunwind] [clang] [clang-tools-extra] [libc++] Allow running the test suite with optimizations (PR #68753)

2023-11-16 Thread Mark de Wever via cfe-commits

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


[libunwind] [libcxx] [clang] [clang-tools-extra] [llvm] [libc++] Allow running the test suite with optimizations (PR #68753)

2023-11-16 Thread Mark de Wever via cfe-commits


@@ -0,0 +1,28 @@
+// -*- 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 SUPPORT_ESCAPE_H
+#define SUPPORT_ESCAPE_H
+
+#include "test_macros.h"
+
+namespace support {
+// This function can be used to hide some objects from compiler optimizations.
+//
+// For example, this is useful to hide the result of a call to `new` and ensure
+// ensure that the compiler doesn't elide the call to new/delete. Otherwise,

mordante wrote:

```suggestion
// For example, this is useful to hide the result of a call to `new` and ensure
// that the compiler doesn't elide the call to new/delete. Otherwise,
```

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


[clang-tools-extra] df4cf0b - [clang-tidy] Fixes a typo in the help message.

2023-10-31 Thread Mark de Wever via cfe-commits

Author: Mark de Wever
Date: 2023-10-31T18:41:36+01:00
New Revision: df4cf0b937fdbcfad407883b74b56ded981b2d9c

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

LOG: [clang-tidy] Fixes a typo in the help message.

It contained 'thewarnings' without a space. It also fixes some odd
formatting in the text introduced by

commit dd3c26a045c081620375a878159f536758baba6e
Author: Tobias Hieta 
Date:   Wed May 17 10:56:49 2023 +0200

[NFC][Py Reformat] Reformat python files in clang and clang-tools-extra

Added: 


Modified: 
clang-tools-extra/clang-tidy/tool/run-clang-tidy.py

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py 
b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
index 179759216196f88..70f8cbcdcb2f11f 100755
--- a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+++ b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
@@ -257,7 +257,7 @@ def main():
 parser.add_argument(
 "-allow-enabling-alpha-checkers",
 action="store_true",
-help="allow alpha checkers from " "clang-analyzer.",
+help="allow alpha checkers from clang-analyzer.",
 )
 parser.add_argument(
 "-clang-tidy-binary", metavar="PATH", help="path to clang-tidy binary"
@@ -270,7 +270,7 @@ def main():
 parser.add_argument(
 "-checks",
 default=None,
-help="checks filter, when not specified, use clang-tidy " "default",
+help="checks filter, when not specified, use clang-tidy default",
 )
 config_group = parser.add_mutually_exclusive_group()
 config_group.add_argument(
@@ -303,7 +303,7 @@ def main():
 parser.add_argument(
 "-line-filter",
 default=None,
-help="List of files with line ranges to filter the" "warnings.",
+help="List of files with line ranges to filter the warnings.",
 )
 if yaml:
 parser.add_argument(
@@ -335,12 +335,12 @@ def main():
 )
 parser.add_argument("-fix", action="store_true", help="apply fix-its")
 parser.add_argument(
-"-format", action="store_true", help="Reformat code " "after applying 
fixes"
+"-format", action="store_true", help="Reformat code after applying 
fixes"
 )
 parser.add_argument(
 "-style",
 default="file",
-help="The style of reformat " "code after applying fixes",
+help="The style of reformat code after applying fixes",
 )
 parser.add_argument(
 "-use-color",
@@ -359,14 +359,14 @@ def main():
 dest="extra_arg",
 action="append",
 default=[],
-help="Additional argument to append to the compiler " "command line.",
+help="Additional argument to append to the compiler command line.",
 )
 parser.add_argument(
 "-extra-arg-before",
 dest="extra_arg_before",
 action="append",
 default=[],
-help="Additional argument to prepend to the compiler " "command line.",
+help="Additional argument to prepend to the compiler command line.",
 )
 parser.add_argument(
 "-quiet", action="store_true", help="Run clang-tidy in quiet mode"
@@ -381,7 +381,7 @@ def main():
 parser.add_argument(
 "-warnings-as-errors",
 default=None,
-help="Upgrades warnings to errors. Same format as " "'-checks'",
+help="Upgrades warnings to errors. Same format as '-checks'",
 )
 args = parser.parse_args()
 



___
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] [libc] [lldb] [flang] [openmp] [mlir] [compiler-rt] [libc++][span] P2821R5: span.at() (PR #74994)

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


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

mordante wrote:

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

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


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

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


@@ -0,0 +1,170 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// 
+
+// constexpr reference at(size_type idx) const; // since C++26
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_macros.h"
+
+template 
+constexpr void testSpanAt(auto&& anySpan, int index, int expectedValue) {
+  // non-const
+  {
+std::same_as decltype(auto) elem = anySpan.at(index);
+assert(elem == expectedValue);
+  }
+
+  // const
+  {
+std::same_as decltype(auto) elem = 
std::as_const(anySpan).at(index);
+assert(elem == expectedValue);
+  }
+}
+
+constexpr bool test() {
+  // With static extent
+  {
+std::array arr{0, 1, 2, 3, 4, 5, 9084};
+std::span arrSpan{arr};
+
+assert(std::dynamic_extent != arrSpan.extent);
+
+using ReferenceT = typename decltype(arrSpan)::reference;
+
+testSpanAt(arrSpan, 0, 0);
+testSpanAt(arrSpan, 1, 1);
+testSpanAt(arrSpan, 6, 9084);
+  }
+
+  // With dynamic extent
+  {
+std::vector vec{0, 1, 2, 3, 4, 5, 9084};
+std::span vecSpan{vec};
+
+assert(std::dynamic_extent == vecSpan.extent);
+
+using ReferenceT = typename decltype(vecSpan)::reference;
+
+testSpanAt(vecSpan, 0, 0);
+testSpanAt(vecSpan, 1, 1);
+testSpanAt(vecSpan, 6, 9084);
+  }
+
+  return true;
+}
+
+void test_exceptions() {
+#ifndef TEST_HAS_NO_EXCEPTIONS
+  using namespace std::string_literals;
+
+  // With static extent
+  {
+std::array arr{0, 1, 2, 3, 4, 5, 9084, std::numeric_limits::max()};
+const std::span arrSpan{arr};
+
+try {
+  std::ignore = arrSpan.at(arr.size());
+  assert(false);
+} catch (const std::out_of_range& e) {
+  // pass
+  assert(e.what() == "span"s);
+} catch (...) {
+  assert(false);
+}
+
+try {
+  std::ignore = arrSpan.at(arr.size() - 1);
+  // pass
+  assert(arrSpan.at(arr.size() - 1) == std::numeric_limits::max());
+} catch (const std::out_of_range&) {
+  assert(false);

mordante wrote:

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

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


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

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

https://github.com/mordante edited 
https://github.com/llvm/llvm-project/pull/74994
___
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] [libc] [lldb] [flang] [openmp] [mlir] [compiler-rt] [libc++][span] P2821R5: span.at() (PR #74994)

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

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

Mostly looks good, a few comments.

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


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

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




mordante wrote:

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

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


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

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


@@ -0,0 +1,145 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H
+#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H
+
+#include <__algorithm/ranges_search.h>
+#include <__config>
+#include <__functional/identity.h>
+#include <__functional/ranges_operations.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/indirectly_comparable.h>
+#include <__iterator/projected.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER >= 23
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace ranges {
+namespace __contains_subrange {
+struct __fn {
+  template  _Sent1,
+forward_iterator _Iter2,
+sentinel_for<_Iter2> _Sent2,
+class _Pred,
+class _Proj1,
+class _Proj2,
+class _Offset = int>
+  static _LIBCPP_HIDE_FROM_ABI constexpr bool __contains_subrange_fn_impl(
+  _Iter1 __first1,
+  _Sent1 __last1,
+  _Iter2 __first2,
+  _Sent2 __last2,
+  _Pred& __pred,
+  _Proj1& __proj1,
+  _Proj2& __proj2,
+  _Offset __offset) {
+if (__offset < 0)
+  return false;
+else {
+  auto result = ranges::search(
+  std::move(__first1),
+  std::move(__last1),
+  std::move(__first2),
+  std::move(__last2),
+  std::ref(__pred),
+  std::ref(__proj1),
+  std::ref(__proj2));
+  return result.empty() == false;
+}
+  }
+
+  template  _Sent1,
+forward_iterator _Iter2,
+sentinel_for<_Iter2> _Sent2,
+class _Pred  = ranges::equal_to,
+class _Proj1 = identity,
+class _Proj2 = identity>
+requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(
+  _Iter1 __first1,
+  _Sent1 __last1,
+  _Iter2 __first2,
+  _Sent2 __last2,
+  _Pred __pred   = {},
+  _Proj1 __proj1 = {},
+  _Proj2 __proj2 = {}) const {
+int __n1 = ranges::distance(__first1, __last1);
+int __n2 = ranges::distance(__first2, __last2);
+if (__n2 == 0)
+  return true;
+int __offset = __n1 - __n2;
+
+return __contains_subrange_fn_impl(
+std::move(__first1),
+std::move(__last1),
+std::move(__first2),
+std::move(__last2),
+__pred,
+__proj1,
+__proj2,
+std::move(__offset));
+  }
+
+  template 
+requires indirectly_comparable, iterator_t<_Range2>, 
_Pred, _Proj1, _Proj2>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(
+  _Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 
__proj1 = {}, _Proj2 __proj2 = {}) const {
+int __n1 = 0;
+int __n2 = 0;
+
+if constexpr (sized_range<_Range1> && sized_range<_Range2>) {
+  __n1 = ranges::size(__range1);
+  __n2 = ranges::size(__range2);
+} else {
+  __n1 = ranges::distance(__range1);
+  __n2 = ranges::distance(__range2);
+}
+
+if (__n2 == 0)
+  return true;
+int __offset = __n1 - __n2;
+return __contains_subrange_fn_impl(
+ranges::begin(__range1),
+ranges::end(__range1),
+ranges::begin(__range2),
+ranges::end(__range2),
+__pred,
+__proj1,
+__proj2,
+__offset);
+  }
+};
+} // namespace __contains_subrange
+
+inline namespace __cpo {
+inline constexpr auto contains_subrange = __contains_subrange::__fn{};

mordante wrote:

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

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


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

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

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


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

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

https://github.com/mordante commented:

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

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


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

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


@@ -0,0 +1,145 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H
+#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H
+
+#include <__algorithm/ranges_search.h>
+#include <__config>
+#include <__functional/identity.h>
+#include <__functional/ranges_operations.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/indirectly_comparable.h>
+#include <__iterator/projected.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER >= 23
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace ranges {
+namespace __contains_subrange {
+struct __fn {
+  template  _Sent1,
+forward_iterator _Iter2,
+sentinel_for<_Iter2> _Sent2,
+class _Pred,
+class _Proj1,
+class _Proj2,
+class _Offset = int>
+  static _LIBCPP_HIDE_FROM_ABI constexpr bool __contains_subrange_fn_impl(
+  _Iter1 __first1,
+  _Sent1 __last1,
+  _Iter2 __first2,
+  _Sent2 __last2,
+  _Pred& __pred,
+  _Proj1& __proj1,
+  _Proj2& __proj2,
+  _Offset __offset) {
+if (__offset < 0)
+  return false;
+else {
+  auto result = ranges::search(
+  std::move(__first1),
+  std::move(__last1),
+  std::move(__first2),
+  std::move(__last2),
+  std::ref(__pred),
+  std::ref(__proj1),
+  std::ref(__proj2));
+  return result.empty() == false;
+}
+  }
+
+  template  _Sent1,
+forward_iterator _Iter2,
+sentinel_for<_Iter2> _Sent2,
+class _Pred  = ranges::equal_to,
+class _Proj1 = identity,
+class _Proj2 = identity>
+requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(

mordante wrote:

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


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


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

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

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


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

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

https://github.com/mordante commented:

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

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

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


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

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


@@ -0,0 +1,168 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// 
+
+// constexpr reference at(size_type idx) const; // since C++26
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_macros.h"
+
+template 
+constexpr void testSpanAt(auto&& anySpan, int index, int expectedValue) {
+  // non-const
+  {
+std::same_as decltype(auto) elem = anySpan.at(index);
+assert(elem == expectedValue);
+  }
+
+  // const
+  {
+std::same_as decltype(auto) elem = 
std::as_const(anySpan).at(index);
+assert(elem == expectedValue);
+  }
+}
+
+constexpr bool test() {
+  // With static extent
+  {
+std::array arr{0, 1, 2, 3, 4, 5, 9084};
+std::span arrSpan{arr};
+
+assert(std::dynamic_extent != arrSpan.extent);
+
+using ReferenceT = typename decltype(arrSpan)::reference;
+
+testSpanAt(arrSpan, 0, 0);
+testSpanAt(arrSpan, 1, 1);
+testSpanAt(arrSpan, 6, 9084);
+  }
+
+  // With dynamic extent
+  {
+std::vector vec{0, 1, 2, 3, 4, 5, 9084};
+std::span vecSpan{vec};
+
+assert(std::dynamic_extent == vecSpan.extent);
+
+using ReferenceT = typename decltype(vecSpan)::reference;
+
+testSpanAt(vecSpan, 0, 0);
+testSpanAt(vecSpan, 1, 1);
+testSpanAt(vecSpan, 6, 9084);
+  }
+
+  return true;
+}
+
+void test_exceptions() {
+#ifndef TEST_HAS_NO_EXCEPTIONS
+  using namespace std::string_literals;
+
+  // With static extent
+  {
+std::array arr{0, 1, 2, 3, 4, 5, 9084, std::numeric_limits::max()};
+const std::span arrSpan{arr};
+
+try {
+  std::ignore = arrSpan.at(arr.size());
+  assert(false);
+} catch (const std::out_of_range& e) {
+  // pass
+  assert(e.what() == "span"s);
+} catch (...) {
+  assert(false);
+}
+
+try {
+  std::ignore = arrSpan.at(arr.size() - 1);
+  // pass
+  assert(arrSpan.at(arr.size() - 1) == std::numeric_limits::max());
+} catch (...) {
+  assert(false);
+}
+  }
+
+  {
+std::array arr{};
+const std::span arrSpan{arr};
+
+try {
+  std::ignore = arrSpan.at(0);
+  assert(false);
+} catch (const std::out_of_range& e) {
+  // pass
+  assert(e.what() == "span"s);

mordante wrote:

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

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


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

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


@@ -0,0 +1,168 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// 
+
+// constexpr reference at(size_type idx) const; // since C++26
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_macros.h"
+
+template 
+constexpr void testSpanAt(auto&& anySpan, int index, int expectedValue) {
+  // non-const
+  {
+std::same_as decltype(auto) elem = anySpan.at(index);
+assert(elem == expectedValue);
+  }
+
+  // const
+  {
+std::same_as decltype(auto) elem = 
std::as_const(anySpan).at(index);
+assert(elem == expectedValue);
+  }
+}
+
+constexpr bool test() {
+  // With static extent
+  {
+std::array arr{0, 1, 2, 3, 4, 5, 9084};
+std::span arrSpan{arr};
+
+assert(std::dynamic_extent != arrSpan.extent);
+
+using ReferenceT = typename decltype(arrSpan)::reference;
+
+testSpanAt(arrSpan, 0, 0);
+testSpanAt(arrSpan, 1, 1);
+testSpanAt(arrSpan, 6, 9084);
+  }
+
+  // With dynamic extent
+  {
+std::vector vec{0, 1, 2, 3, 4, 5, 9084};
+std::span vecSpan{vec};
+
+assert(std::dynamic_extent == vecSpan.extent);
+
+using ReferenceT = typename decltype(vecSpan)::reference;
+
+testSpanAt(vecSpan, 0, 0);
+testSpanAt(vecSpan, 1, 1);
+testSpanAt(vecSpan, 6, 9084);
+  }
+
+  return true;
+}
+
+void test_exceptions() {
+#ifndef TEST_HAS_NO_EXCEPTIONS
+  using namespace std::string_literals;
+
+  // With static extent
+  {
+std::array arr{0, 1, 2, 3, 4, 5, 9084, std::numeric_limits::max()};
+const std::span arrSpan{arr};
+
+try {
+  std::ignore = arrSpan.at(arr.size());
+  assert(false);
+} catch (const std::out_of_range& e) {
+  // pass
+  assert(e.what() == "span"s);
+} catch (...) {
+  assert(false);
+}
+
+try {
+  std::ignore = arrSpan.at(arr.size() - 1);
+  // pass
+  assert(arrSpan.at(arr.size() - 1) == std::numeric_limits::max());
+} catch (...) {

mordante wrote:

please apply this change to similar places too,

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


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

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

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

Thanks for the fixes, LGTM!

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


[libcxx] [libunwind] [llvm] [libc++] Allow running the test suite with optimizations (PR #68753)

2023-11-24 Thread Mark de Wever via cfe-commits

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

LGTM!

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


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread Mark de Wever via cfe-commits

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

This implements a way for the compiler to find the modules.json associated with 
the C++23 Standard library modules.

This is based on a discussion in SG15. At the moment no Standard library 
installs this manifest. #75741 adds this feature in libc++.

>From f3f0db64da4d341f8e4a2054f9f25c87f8eda829 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 27 Dec 2023 17:34:10 +0100
Subject: [PATCH] [clang][modules] Print library module manifest path.

This implements a way for the compiler to find the modules.json
associated with the C++23 Standard library modules.

This is based on a discussion in SG15. At the moment no Standard library
installs this manifest. #75741 adds this feature in libc++.
---
 clang/include/clang/Driver/Driver.h   | 10 +
 clang/include/clang/Driver/Options.td |  3 ++
 clang/lib/Driver/Driver.cpp   | 40 +++
 .../usr/lib/x86_64-linux-gnu/libc++.so|  0
 .../usr/lib/x86_64-linux-gnu/modules.json |  0
 ...dules-print-library-module-manifest-path.c | 15 +++
 ...arwin-print-library-module-manifest-path.c |  9 +
 7 files changed, 77 insertions(+)
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/libc++.so
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/modules.json
 create mode 100644 
clang/test/Driver/cxx23-modules-print-library-module-manifest-path.c
 create mode 100644 
clang/test/Driver/darwin-print-library-module-manifest-path.c

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 3ee1bcf2a69c9b..2e1e3b128744ff 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -602,6 +602,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain &TC) const;
 
+  /// GetModuleManifestPath - Lookup the name of the Standard library manifest.
+  ///
+  /// \param C - The compilation.
+  /// \param TC - The tool chain for additional information on
+  /// directories to search.
+  //
+  // FIXME: This should be in CompilationInfo.
+  std::string GetModuleManifestPath(const Compilation &C,
+const ToolChain &TC) const;
+
   /// HandleAutocompletions - Handle --autocomplete by searching and printing
   /// possible flags, descriptions, and its arguments.
   void HandleAutocompletions(StringRef PassedFlags) const;
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2b93ddf033499c..890257e11485b6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5280,6 +5280,9 @@ def print_resource_dir : Flag<["-", "--"], 
"print-resource-dir">,
 def print_search_dirs : Flag<["-", "--"], "print-search-dirs">,
   HelpText<"Print the paths used for finding libraries and programs">,
   Visibility<[ClangOption, CLOption]>;
+def print_library_module_manifest_path : Flag<["-", "--"], 
"print-library-module-manifest-path">,
+  HelpText<"Print the path for the C++ Standard library module manifest">,
+  Visibility<[ClangOption, CLOption]>;
 def print_targets : Flag<["-", "--"], "print-targets">,
   HelpText<"Print the registered targets">,
   Visibility<[ClangOption, CLOption]>;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index ff95c899c5f3d4..8d682f9238c6b8 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation &C) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="
+ << GetModuleManifestPath(C, C.getDefaultToolChain()) << '\n';
+return false;
+  }
+
   if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
 if (std::optional RuntimePath = TC.getRuntimePath())
   llvm::outs() << *RuntimePath << '\n';
@@ -6135,6 +6141,40 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain &TC) const {
   return std::string(Name);
 }
 
+std::string Driver::GetModuleManifestPath(const Compilation &C,
+  const ToolChain &TC) const {
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = "libc++.so";
+std::string path = GetFilePath(lib, TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+
+// For example
+/*
+const SanitizerArgs &Sanitize = TC.getSanitizerArgs(C.getArgs());
+if (Sanitize.needsAsanRt())
+  return path.replace(path.size() - lib.size(), lib.size(),
+  "modules-asan.json");
+*/
+
+path = path.replace(path.size() - lib.size(

[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread Mark de Wever via cfe-commits


@@ -0,0 +1,15 @@
+// Test that -print-library-module-manifest-path finds the correct file.
+
+// RUN: %clang -print-library-module-manifest-path \

mordante wrote:

They work with one or two dashes, `Flag<["-", "--"]`, in `Options.td` does 
that. This option does the same.

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


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread Mark de Wever via cfe-commits


@@ -602,6 +602,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain &TC) const;
 
+  /// GetModuleManifestPath - Lookup the name of the Standard library manifest.
+  ///
+  /// \param C - The compilation.
+  /// \param TC - The tool chain for additional information on
+  /// directories to search.
+  //
+  // FIXME: This should be in CompilationInfo.
+  std::string GetModuleManifestPath(const Compilation &C,

mordante wrote:

That is an option, I could do `` or something like that. I'm not 
sure what the tool vendors prefer. A magic string or an empty string.

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


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread Mark de Wever via cfe-commits


@@ -6135,6 +6141,40 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain &TC) const {
   return std::string(Name);
 }
 
+std::string Driver::GetModuleManifestPath(const Compilation &C,
+  const ToolChain &TC) const {
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = "libc++.so";
+std::string path = GetFilePath(lib, TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+
+// For example
+/*
+const SanitizerArgs &Sanitize = TC.getSanitizerArgs(C.getArgs());
+if (Sanitize.needsAsanRt())
+  return path.replace(path.size() - lib.size(), lib.size(),
+  "modules-asan.json");
+*/
+
+path = path.replace(path.size() - lib.size(), lib.size(), "modules.json");
+if (TC.getVFS().exists(path))
+  return path;
+
+return "";

mordante wrote:

I like one error value, the goal of the output is to be usable by tools. 

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


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread Mark de Wever via cfe-commits


@@ -0,0 +1,15 @@
+// Test that -print-library-module-manifest-path finds the correct file.
+
+// RUN: %clang -print-library-module-manifest-path \

mordante wrote:

I wasn't aware of that. I got used to using one dash using clang.

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


[libcxx] [clang] [libc++] Re-enable the clang_modules_include test for Objective-C++ (PR #66801)

2023-12-27 Thread Mark de Wever via cfe-commits

mordante wrote:

> @mordante I'm not certain what's going on here, I get
> 
> ```
> [...]/clang_modules_include.gen.py/__std_clang_module.compile.pass.mm:22:2: 
> error: import of module 'std' imported non C++20 importable modules
>22 | @import std;
>   |  ^
> 1 error generated.
> ```
> 
> Can you assist? It only happens with Clang trunk.

I tested this locally and indeed it works with clang-17 and fails with clang-18

@ChuanqiXu9 This seems to be introduced in 
574ee1c02ef73b66c5957cf93888234b0471695f.

This test uses a Objective-C++ file. Is it easy for you to fix or should I file 
a bug report?

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


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-28 Thread Mark de Wever via cfe-commits


@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation &C) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="

mordante wrote:

some places do some don't. Since I had an empty string as "error-code" it makes 
sense to print a prefix. If we use another error-code we could remove the 
prefix.

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


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-28 Thread Mark de Wever via cfe-commits


@@ -0,0 +1,15 @@
+// Test that -print-library-module-manifest-path finds the correct file.
+
+// RUN: %clang -print-library-module-manifest-path \
+// RUN: -stdlib=libc++ \
+// RUN: --sysroot=%S/Inputs/cxx23_modules \
+// RUN: --target=x86_64-linux-gnu 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-LIBCXX %s
+// CHECK-LIBCXX: module: 
={{.*}}/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/modules.json
+

mordante wrote:

not sure, I've never used --gcc-toolchain either.

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


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-28 Thread Mark de Wever via cfe-commits


@@ -602,6 +602,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain &TC) const;
 
+  /// GetModuleManifestPath - Lookup the name of the Standard library manifest.
+  ///
+  /// \param C - The compilation.
+  /// \param TC - The tool chain for additional information on
+  /// directories to search.
+  //
+  // FIXME: This should be in CompilationInfo.

mordante wrote:

I copied it from the functions above, I have not investigated why the FIXME is 
there.

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


[clang] [libcxx] [libc++] Re-enable the clang_modules_include test for Objective-C++ (PR #66801)

2023-12-28 Thread Mark de Wever via cfe-commits

mordante wrote:

> I tried to fix this in 
> [c2c840b](https://github.com/llvm/llvm-project/commit/c2c840bd92cfac155f6205ff7505b109b301d389).
>  Sorry for disturbing.

Thanks for the quick fix! I've tested the fix with this patch locally and it 
passes.

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


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-28 Thread Mark de Wever via cfe-commits


@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation &C) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="

mordante wrote:

returning an empty string gives an empty output. This feels wrong, returning an 
error value indicates the tool has done something with the request. No output 
may mean the request has been ignored.

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


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-29 Thread Mark de Wever via cfe-commits


@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation &C) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="

mordante wrote:

> I'd like there to be some distinction between "modules not present because 
> Clang was built without them" and "modules not present but expected to be 
> there" (maybe distro packagers split things and the modules package is 
> missing?).

However that is hard to do and might be wrong. Currently stdlibc++ does not 
ship modules. I don't know how clang-18 will ever find them stdlibc++-15 since 
it's unknown whether that version will have modules nor do I know the name of 
their manifest file.

Same for Clang and libc++,  Clang has no idea whether libc++ was build with or 
without modules. They are build independently. So it would need to look at the 
version information of libc++ to detect whether it's libc++-18 or earlier. 
Earlier never has the manifest.

IMO tool vendors should look at the output of this command; it either contains 
a path or a single error value. If it's the error value they should not attempt 
to build the std module.

What would be the benefit of different errors @mathstuf ? Especially 
considering the above that it's hard to determine the proper error message.

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


[clang] [clang][modules] Print library module manifest path. (PR #76451)

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

mordante wrote:

I had looked at `-print-search-dirs` but it seems buggy. For example, it 
ignores the `-stdlib` flag to the compiler invocation. Solving this seems a lot 
of work. So didn't want to add new features to that code.

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


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

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

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


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

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

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

Thanks for working on this!

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


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

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


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

mordante wrote:

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

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


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

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


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

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

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


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

mordante wrote:

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

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


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

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


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

mordante wrote:

For this file too.

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


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

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


@@ -0,0 +1,268 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// 
+
+// class variant;
+
+// template
+//   constexpr decltype(auto) visit(this Self&&, Visitor&&); // since C++26
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_macros.h"
+#include "variant_test_helpers.h"
+
+void test_call_operator_forwarding() {
+  using Fn = ForwardingCallObject;
+  Fn obj{};
+  const Fn& cobj = obj;
+
+  { // test call operator forwarding - no variant
+// non-member
+{
+  std::visit(obj);
+  assert(Fn::check_call<>(CT_NonConst | CT_LValue));

mordante wrote:

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

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


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

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


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

mordante wrote:

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

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


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

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


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

mordante wrote:

nowadays we prefer to write the body in the class.

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


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

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


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

mordante wrote:

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

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


[lld] [flang] [llvm] [libcxx] [clang] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-02 Thread Mark de Wever via cfe-commits


@@ -245,6 +267,18 @@ public:
 #  endif
   _LIBCPP_HIDE_FROM_ABI basic_filebuf* __open(int __fd, ios_base::openmode 
__mode);
   basic_filebuf* close();
+#  if _LIBCPP_STD_VER >= 26
+  _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() const noexcept {
+_LIBCPP_ASSERT_UNCATEGORIZED(this->is_open(), "File must be opened");

mordante wrote:

Yes, but we don't always write tests for it. If you write a test it should be 
new standalone test. This test won't be executed in all configurations. 
https://github.com/llvm/llvm-project/blob/main/libcxx/test/libcxx/containers/sequences/array/array.zero/assert.front.pass.cpp
 is a nice example how to test this.

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


[flang] [libcxx] [llvm] [clang] [lld] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-02 Thread Mark de Wever via cfe-commits

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


[libcxx] [lld] [llvm] [clang] [flang] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-02 Thread Mark de Wever via cfe-commits


@@ -245,6 +267,18 @@ public:
 #  endif
   _LIBCPP_HIDE_FROM_ABI basic_filebuf* __open(int __fd, ios_base::openmode 
__mode);
   basic_filebuf* close();
+#  if _LIBCPP_STD_VER >= 26
+  _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() const noexcept {
+_LIBCPP_ASSERT_UNCATEGORIZED(this->is_open(), "File must be opened");
+#if defined(_LIBCPP_WIN32API)
+return __filebuf_windows_native_handle(__file_);

mordante wrote:

```suggestion
return std::__filebuf_windows_native_handle(__file_);
```

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


[lld] [llvm] [libcxx] [flang] [clang] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-02 Thread Mark de Wever via cfe-commits


@@ -0,0 +1,81 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef TEST_STD_INPUT_OUTPUT_FILE_STREAMS_FSTREAMS_TEST_HELPERS_H
+#define TEST_STD_INPUT_OUTPUT_FILE_STREAMS_FSTREAMS_TEST_HELPERS_H
+
+#if _LIBCPP_STD_VER >= 26
+
+#  include 
+#  include 
+#  include 
+#  include 
+#  include 
+#  include 
+#  include 
+
+#  if defined(_LIBCPP_WIN32API)
+#define WIN32_LEAN_AND_MEAN
+#define NOMINMAX
+#include 
+#include 
+#  else
+#include 
+#  endif
+
+#  include "platform_support.h"
+
+#  if defined(_LIBCPP_WIN32API)
+using HandleT = void*; // HANDLE
+
+bool is_handle_valid(void* handle) {

mordante wrote:

```suggestion
inline bool is_handle_valid(void* handle) {
```
The same for the other functions in the header.

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


[libcxx] [lld] [flang] [llvm] [clang] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-02 Thread Mark de Wever via cfe-commits

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

I did a full review. There are a number of comments, once these are addressed 
the patch is ready.

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


[llvm] [lld] [flang] [libcxx] [clang] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-02 Thread Mark de Wever via cfe-commits


@@ -245,6 +267,18 @@ public:
 #  endif
   _LIBCPP_HIDE_FROM_ABI basic_filebuf* __open(int __fd, ios_base::openmode 
__mode);
   basic_filebuf* close();
+#  if _LIBCPP_STD_VER >= 26
+  _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() const noexcept {
+_LIBCPP_ASSERT_UNCATEGORIZED(this->is_open(), "File must be opened");
+#if defined(_LIBCPP_WIN32API)
+return __filebuf_windows_native_handle(__file_);
+#elif __has_include()
+return fileno(__file_);
+#else
+#  error "Provide a way to determine the file native handle!"
+#endif
+  }
+#  endif

mordante wrote:

```suggestion
#  endif //  _LIBCPP_STD_VER >= 26
```

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


[lld] [flang] [llvm] [libcxx] [clang] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-02 Thread Mark de Wever via cfe-commits


@@ -0,0 +1,81 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef TEST_STD_INPUT_OUTPUT_FILE_STREAMS_FSTREAMS_TEST_HELPERS_H
+#define TEST_STD_INPUT_OUTPUT_FILE_STREAMS_FSTREAMS_TEST_HELPERS_H
+
+#if _LIBCPP_STD_VER >= 26

mordante wrote:

I would remove this, it's only called from code that uses C++26.

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


[clang] [lld] [libcxx] [llvm] [flang] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-02 Thread Mark de Wever via cfe-commits


@@ -0,0 +1,58 @@
+//===--===//

mordante wrote:

Not related to this file. But I miss tests for the typedefs added to the 4 
classes. These are typically in the types tests. For example, 
libcxx/test/std/input.output/file.streams/fstreams/filebuf/types.pass.cpp. When 
adding the test make sure you test all the wording
```
The type native_handle_type represents a platform-specific native handle
to a file. It is trivially copyable and models semiregular.
```

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


[lld] [llvm] [clang] [libcxx] [flang] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-02 Thread Mark de Wever via cfe-commits


@@ -0,0 +1,58 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// 
+
+// class basic_filebuf;
+
+// native_handle_type native_handle() const noexcept;
+
+#include 
+#include 
+#include 
+#include 
+
+#include "platform_support.h"
+#include "test_macros.h"
+#include "../test_helpers.h"
+
+template 
+void test() {
+  HandleT native_handle{};
+  HandleT const_native_handle{};
+
+  {
+std::basic_filebuf f;
+assert(!f.is_open());

mordante wrote:

We don't need this assert, the second `is_open()` assert could be replaced by
`assert(f.open(p, std::ios_base::in) != nullptr);

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


[lld] [flang] [libcxx] [llvm] [clang] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-02 Thread Mark de Wever via cfe-commits


@@ -0,0 +1,81 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef TEST_STD_INPUT_OUTPUT_FILE_STREAMS_FSTREAMS_TEST_HELPERS_H
+#define TEST_STD_INPUT_OUTPUT_FILE_STREAMS_FSTREAMS_TEST_HELPERS_H
+
+#if _LIBCPP_STD_VER >= 26
+
+#  include 
+#  include 
+#  include 
+#  include 
+#  include 
+#  include 
+#  include 
+
+#  if defined(_LIBCPP_WIN32API)

mordante wrote:

We shouldn't use libc++ macro's in our tests. Other libraries can also use 
them. MSVC STL does. Use the appropriate macro from platform_support.h.

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


[llvm] [clang] [lld] [libcxx] [flang] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-02 Thread Mark de Wever via cfe-commits


@@ -210,6 +217,12 @@ _LIBCPP_PUSH_MACROS
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
+#  if _LIBCPP_STD_VER >= 26
+#if defined(_LIBCPP_WIN32API)

mordante wrote:

```suggestion
#  if _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_WIN32API)
```

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


[clang] [llvm] [lld] [libcxx] [flang] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-02 Thread Mark de Wever via cfe-commits


@@ -85,6 +85,7 @@ endif()
 if (LIBCXX_ENABLE_LOCALIZATION)
   list(APPEND LIBCXX_SOURCES
 include/sso_allocator.h
+fstream.cpp

mordante wrote:

```suggestion
fstream.cpp
include/sso_allocator.h
```
Let's keep it in alphabetic order.

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


[clang] [lld] [libcxx] [flang] [llvm] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-02 Thread Mark de Wever via cfe-commits


@@ -0,0 +1,58 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// 
+
+// class basic_filebuf;
+
+// native_handle_type native_handle() const noexcept;
+
+#include 
+#include 
+#include 
+#include 
+
+#include "platform_support.h"
+#include "test_macros.h"
+#include "../test_helpers.h"
+
+template 
+void test() {
+  HandleT native_handle{};
+  HandleT const_native_handle{};
+
+  {
+std::basic_filebuf f;
+assert(!f.is_open());
+std::filesystem::path p = get_temp_file_name();
+f.open(p, std::ios_base::in);
+assert(f.is_open());
+std::same_as decltype(auto) handle = f.native_handle();
+native_handle   = handle;
+assert(is_handle_valid(native_handle));

mordante wrote:

```suggestion
assert(is_handle_valid(handle));
f.close();
assert(!is_handle_valid(handle));
```
This also allows to remove the `HandleT native_handle{};` above. This keeps the 
code more local.




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


[flang] [lld] [llvm] [libcxx] [clang] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-02 Thread Mark de Wever via cfe-commits


@@ -0,0 +1,81 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef TEST_STD_INPUT_OUTPUT_FILE_STREAMS_FSTREAMS_TEST_HELPERS_H
+#define TEST_STD_INPUT_OUTPUT_FILE_STREAMS_FSTREAMS_TEST_HELPERS_H
+
+#if _LIBCPP_STD_VER >= 26
+
+#  include 
+#  include 
+#  include 
+#  include 
+#  include 
+#  include 
+#  include 
+
+#  if defined(_LIBCPP_WIN32API)
+#define WIN32_LEAN_AND_MEAN
+#define NOMINMAX
+#include 
+#include 
+#  else
+#include 
+#  endif
+
+#  include "platform_support.h"
+
+#  if defined(_LIBCPP_WIN32API)
+using HandleT = void*; // HANDLE
+
+bool is_handle_valid(void* handle) {
+  if (BY_HANDLE_FILE_INFORMATION fileInformation; 
!GetFileInformationByHandle(handle, &fileInformation))
+return false;
+  return true;
+};
+#  elif __has_include() // POSIX
+using HandleT = int; // POSIX file descriptor
+
+bool is_handle_valid(HandleT fd) { return fcntl(fd, F_GETFL) != -1 || errno != 
EBADF; };
+#  else
+#error "Provide a native file handle!"
+#  endif
+
+template 
+void test_native_handle() {
+  static_assert(
+  std::is_same_v::native_handle_type, 
typename StreamT::native_handle_type>);
+
+  HandleT native_handle{};

mordante wrote:

Please apply the comments to the filebuf test here too.

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


[clang] cba217a - Revert "Reapply "[Sema] Fix crash on invalid code with parenthesized aggregate initialization" (#76272)"

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

Author: Mark de Wever
Date: 2024-01-03T17:56:07+01:00
New Revision: cba217a9138aa8ea8d18111b648acde8f52ada8d

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

LOG: Revert "Reapply "[Sema] Fix crash on invalid code with parenthesized 
aggregate initialization" (#76272)"

This reverts commit 02347fc7191ff4d073f439dde6523add3f5496de.

These changes break the libc++ CI again.
I'll look at a better solution later.

Added: 


Modified: 
clang/lib/Sema/SemaInit.cpp
clang/test/SemaCXX/paren-list-agg-init.cpp

libcxx/test/libcxx/utilities/expected/expected.expected/transform_error.mandates.verify.cpp

libcxx/test/libcxx/utilities/expected/expected.void/transform_error.mandates.verify.cpp

Removed: 
clang/test/SemaCXX/crash-GH76228.cpp



diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index cc9db5ded1149a..61d244f3bb9798 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -5512,14 +5512,6 @@ static void TryOrBuildParenListInitialization(
   } else if (auto *RT = Entity.getType()->getAs()) {
 bool IsUnion = RT->isUnionType();
 const CXXRecordDecl *RD = cast(RT->getDecl());
-if (RD->isInvalidDecl()) {
-  // Exit early to avoid confusion when processing members.
-  // We do the same for braced list initialization in
-  // `CheckStructUnionTypes`.
-  Sequence.SetFailed(
-  clang::InitializationSequence::FK_ParenthesizedListInitFailed);
-  return;
-}
 
 if (!IsUnion) {
   for (const CXXBaseSpecifier &Base : RD->bases()) {

diff  --git a/clang/test/SemaCXX/crash-GH76228.cpp 
b/clang/test/SemaCXX/crash-GH76228.cpp
deleted file mode 100644
index 33a9395823127e..00
--- a/clang/test/SemaCXX/crash-GH76228.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
-// RUN: %clang_cc1 -std=c++20 -verify %s
-// Check we don't crash on incomplete members and bases when handling 
parenthesized initialization.
-class incomplete; // expected-note@-0 3  {{forward declaration of 
'incomplete'}}
-struct foo {
-  int a;
-  incomplete b;
-  // expected-error@-1 {{incomplete type}}
-};
-foo a1(0);
-
-struct one_int {
-int a;
-};
-struct bar : one_int, incomplete {};
-// expected-error@-1 {{incomplete type}}
-bar a2(0);
-
-incomplete a3[3](1,2,3);
-// expected-error@-1 {{incomplete type}}
-
-struct qux : foo {
-};
-qux a4(0);
-
-struct fred {
-foo a[3];
-};
-fred a5(0);

diff  --git a/clang/test/SemaCXX/paren-list-agg-init.cpp 
b/clang/test/SemaCXX/paren-list-agg-init.cpp
index c1964a5a9eb005..f60b20e0d46568 100644
--- a/clang/test/SemaCXX/paren-list-agg-init.cpp
+++ b/clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -289,7 +289,7 @@ int test() {
   // used to crash
   S a(0, 1);
   S b(0);
-  S c(0, 0, 1);
+  S c(0, 0, 1); // beforecxx20-warning {{aggregate initialization of type 'S' 
from a parenthesized list of values is a C++20 extension}}
 
   S d {0, 1};
   S e {0};

diff  --git 
a/libcxx/test/libcxx/utilities/expected/expected.expected/transform_error.mandates.verify.cpp
 
b/libcxx/test/libcxx/utilities/expected/expected.expected/transform_error.mandates.verify.cpp
index 3260a8cbc7f8e6..965e82a7b40346 100644
--- 
a/libcxx/test/libcxx/utilities/expected/expected.expected/transform_error.mandates.verify.cpp
+++ 
b/libcxx/test/libcxx/utilities/expected/expected.expected/transform_error.mandates.verify.cpp
@@ -46,9 +46,11 @@ void test() {
   {
 std::expected e;
 e.transform_error(return_unexpected); // expected-error-re@*:* 
{{static assertion failed {{.*}}The result of {{.*}} must be a valid template 
argument for unexpected}}
+// expected-error-re@*:* (excess elements in struct initializer|no 
matching constructor for initialization of)}}{{.*
 // expected-error-re@*:* {{static assertion failed 
{{.*}}[expected.object.general] A program that instantiates the definition of 
template expected for {{.*}} is ill-formed.}}
 
 e.transform_error(return_no_object); // expected-error-re@*:* 
{{static assertion failed {{.*}}The result of {{.*}} must be a valid template 
argument for unexpected}}
+// expected-error-re@*:* (excess elements in struct initializer|no 
matching constructor for initialization of)}}{{.*
 // expected-error-re@*:* {{static assertion failed 
{{.*}}[expected.object.general] A program that instantiates the definition of 
template expected for {{.*}} is ill-formed.}}
   }
 
@@ -56,21 +58,27 @@ void test() {
   {
 const std::expected e;
 e.transform_error(return_unexpected); // 
expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must 
be a valid template argument for unexpected}}
+// expected-error-re@*:* 2 (excess elements in struct initializer|no 
matching constructor for initialization of)}}{{.*
 e.t

[clang] [libcxx] "Reapply "[Sema] Fix crash on invalid code with parenthesized aggrega… (PR #76833)

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

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

…te initialization" (#76272)""

With updates the libc++ tests.

This reverts commit 2205d23 and relands
86dc6e1 and
7ab16fb.

Original commit was reverted because of failing libc++ tests, see #76232 for 
the discussion.

The errors in the tests are spurious in the first place (coming from 
initialization of invalid classes), so update the tests to match new behavior 
that does not show those errors.

>From 77abc737eebd5cf62b52248a6e35e4c74fbeca80 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 3 Jan 2024 18:00:43 +0100
Subject: [PATCH] "Reapply "[Sema] Fix crash on invalid code with parenthesized
 aggregate initialization" (#76272)""

With updates the libc++ tests.

This reverts commit 2205d23 and relands
86dc6e1 and
7ab16fb.

Original commit was reverted because of failing libc++ tests, see #76232 for
the discussion.

The errors in the tests are spurious in the first place (coming from 
initialization
of invalid classes), so update the tests to match new behavior that does
not show those errors.
---
 clang/lib/Sema/SemaInit.cpp   |  8 ++
 clang/test/SemaCXX/crash-GH76228.cpp  | 28 +++
 clang/test/SemaCXX/paren-list-agg-init.cpp|  2 +-
 .../transform_error.mandates.verify.cpp   |  8 --
 .../transform_error.mandates.verify.cpp   |  8 --
 5 files changed, 37 insertions(+), 17 deletions(-)
 create mode 100644 clang/test/SemaCXX/crash-GH76228.cpp

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 61d244f3bb9798..cc9db5ded1149a 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -5512,6 +5512,14 @@ static void TryOrBuildParenListInitialization(
   } else if (auto *RT = Entity.getType()->getAs()) {
 bool IsUnion = RT->isUnionType();
 const CXXRecordDecl *RD = cast(RT->getDecl());
+if (RD->isInvalidDecl()) {
+  // Exit early to avoid confusion when processing members.
+  // We do the same for braced list initialization in
+  // `CheckStructUnionTypes`.
+  Sequence.SetFailed(
+  clang::InitializationSequence::FK_ParenthesizedListInitFailed);
+  return;
+}
 
 if (!IsUnion) {
   for (const CXXBaseSpecifier &Base : RD->bases()) {
diff --git a/clang/test/SemaCXX/crash-GH76228.cpp 
b/clang/test/SemaCXX/crash-GH76228.cpp
new file mode 100644
index 00..33a9395823127e
--- /dev/null
+++ b/clang/test/SemaCXX/crash-GH76228.cpp
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+// Check we don't crash on incomplete members and bases when handling 
parenthesized initialization.
+class incomplete; // expected-note@-0 3  {{forward declaration of 
'incomplete'}}
+struct foo {
+  int a;
+  incomplete b;
+  // expected-error@-1 {{incomplete type}}
+};
+foo a1(0);
+
+struct one_int {
+int a;
+};
+struct bar : one_int, incomplete {};
+// expected-error@-1 {{incomplete type}}
+bar a2(0);
+
+incomplete a3[3](1,2,3);
+// expected-error@-1 {{incomplete type}}
+
+struct qux : foo {
+};
+qux a4(0);
+
+struct fred {
+foo a[3];
+};
+fred a5(0);
diff --git a/clang/test/SemaCXX/paren-list-agg-init.cpp 
b/clang/test/SemaCXX/paren-list-agg-init.cpp
index f60b20e0d46568..c1964a5a9eb005 100644
--- a/clang/test/SemaCXX/paren-list-agg-init.cpp
+++ b/clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -289,7 +289,7 @@ int test() {
   // used to crash
   S a(0, 1);
   S b(0);
-  S c(0, 0, 1); // beforecxx20-warning {{aggregate initialization of type 'S' 
from a parenthesized list of values is a C++20 extension}}
+  S c(0, 0, 1);
 
   S d {0, 1};
   S e {0};
diff --git 
a/libcxx/test/libcxx/utilities/expected/expected.expected/transform_error.mandates.verify.cpp
 
b/libcxx/test/libcxx/utilities/expected/expected.expected/transform_error.mandates.verify.cpp
index 965e82a7b40346..3260a8cbc7f8e6 100644
--- 
a/libcxx/test/libcxx/utilities/expected/expected.expected/transform_error.mandates.verify.cpp
+++ 
b/libcxx/test/libcxx/utilities/expected/expected.expected/transform_error.mandates.verify.cpp
@@ -46,11 +46,9 @@ void test() {
   {
 std::expected e;
 e.transform_error(return_unexpected); // expected-error-re@*:* 
{{static assertion failed {{.*}}The result of {{.*}} must be a valid template 
argument for unexpected}}
-// expected-error-re@*:* (excess elements in struct initializer|no 
matching constructor for initialization of)}}{{.*
 // expected-error-re@*:* {{static assertion failed 
{{.*}}[expected.object.general] A program that instantiates the definition of 
template expected for {{.*}} is ill-formed.}}
 
 e.transform_error(return_no_object); // expected-error-re@*:* 
{{static assertion failed {{.*}}The result of {{.*}} must be a valid template 
argument for unexpected}}
-// expected-error-re@*:* (excess elements in struct initializer|no 
matching constructor for initialization of)}}{{.*
 // expected-error-re@*:* {{static a

[clang] [libcxx] "Reapply "[Sema] Fix crash on invalid code with parenthesized aggrega… (PR #76833)

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

mordante wrote:

@ilya-biryukov this is the new attempt to land this patch, the version you 
committed breaks the libc++ CI. I'll try to fix it this week.


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


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

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

mordante wrote:

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

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

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


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

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

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

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

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


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

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

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


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

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


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

mordante wrote:

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

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


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

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


@@ -0,0 +1,30 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// REQUIRES: has-unix-headers
+// UNSUPPORTED: libcpp-hardening-mode=none
+// XFAIL: availability-verbose_abort-missing
+
+// 
+
+// class basic_filebuf;
+
+// native_handle_type native_handle() const noexcept;
+
+#include 
+
+#include "../native_handle_test_helpers.h"
+
+int main(int, char**) {
+  test_native_handle_assertion>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+  test_native_handle_assertion>();
+#endif

mordante wrote:

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

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


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

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


@@ -0,0 +1,58 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// 
+
+// class basic_filebuf;
+
+// native_handle_type native_handle() const noexcept;
+
+#include 
+#include 
+#include 
+#include 
+
+#include "platform_support.h"
+#include "test_macros.h"
+#include "../native_handle_test_helpers.h"
+
+template 
+void test() {
+  std::basic_filebuf f;
+  std::filesystem::path p = get_temp_file_name();
+
+  // non-const
+  {

mordante wrote:

Thanks I find this a lot more readable.

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


[llvm] [clang] [libcxx] "Reapply "[Sema] Fix crash on invalid code with parenthesized aggrega… (PR #76833)

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

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

>From 77abc737eebd5cf62b52248a6e35e4c74fbeca80 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 3 Jan 2024 18:00:43 +0100
Subject: [PATCH 1/2] "Reapply "[Sema] Fix crash on invalid code with
 parenthesized aggregate initialization" (#76272)""

With updates the libc++ tests.

This reverts commit 2205d23 and relands
86dc6e1 and
7ab16fb.

Original commit was reverted because of failing libc++ tests, see #76232 for
the discussion.

The errors in the tests are spurious in the first place (coming from 
initialization
of invalid classes), so update the tests to match new behavior that does
not show those errors.
---
 clang/lib/Sema/SemaInit.cpp   |  8 ++
 clang/test/SemaCXX/crash-GH76228.cpp  | 28 +++
 clang/test/SemaCXX/paren-list-agg-init.cpp|  2 +-
 .../transform_error.mandates.verify.cpp   |  8 --
 .../transform_error.mandates.verify.cpp   |  8 --
 5 files changed, 37 insertions(+), 17 deletions(-)
 create mode 100644 clang/test/SemaCXX/crash-GH76228.cpp

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 61d244f3bb9798a..cc9db5ded1149a0 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -5512,6 +5512,14 @@ static void TryOrBuildParenListInitialization(
   } else if (auto *RT = Entity.getType()->getAs()) {
 bool IsUnion = RT->isUnionType();
 const CXXRecordDecl *RD = cast(RT->getDecl());
+if (RD->isInvalidDecl()) {
+  // Exit early to avoid confusion when processing members.
+  // We do the same for braced list initialization in
+  // `CheckStructUnionTypes`.
+  Sequence.SetFailed(
+  clang::InitializationSequence::FK_ParenthesizedListInitFailed);
+  return;
+}
 
 if (!IsUnion) {
   for (const CXXBaseSpecifier &Base : RD->bases()) {
diff --git a/clang/test/SemaCXX/crash-GH76228.cpp 
b/clang/test/SemaCXX/crash-GH76228.cpp
new file mode 100644
index 000..33a9395823127ea
--- /dev/null
+++ b/clang/test/SemaCXX/crash-GH76228.cpp
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+// Check we don't crash on incomplete members and bases when handling 
parenthesized initialization.
+class incomplete; // expected-note@-0 3  {{forward declaration of 
'incomplete'}}
+struct foo {
+  int a;
+  incomplete b;
+  // expected-error@-1 {{incomplete type}}
+};
+foo a1(0);
+
+struct one_int {
+int a;
+};
+struct bar : one_int, incomplete {};
+// expected-error@-1 {{incomplete type}}
+bar a2(0);
+
+incomplete a3[3](1,2,3);
+// expected-error@-1 {{incomplete type}}
+
+struct qux : foo {
+};
+qux a4(0);
+
+struct fred {
+foo a[3];
+};
+fred a5(0);
diff --git a/clang/test/SemaCXX/paren-list-agg-init.cpp 
b/clang/test/SemaCXX/paren-list-agg-init.cpp
index f60b20e0d465685..c1964a5a9eb0058 100644
--- a/clang/test/SemaCXX/paren-list-agg-init.cpp
+++ b/clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -289,7 +289,7 @@ int test() {
   // used to crash
   S a(0, 1);
   S b(0);
-  S c(0, 0, 1); // beforecxx20-warning {{aggregate initialization of type 'S' 
from a parenthesized list of values is a C++20 extension}}
+  S c(0, 0, 1);
 
   S d {0, 1};
   S e {0};
diff --git 
a/libcxx/test/libcxx/utilities/expected/expected.expected/transform_error.mandates.verify.cpp
 
b/libcxx/test/libcxx/utilities/expected/expected.expected/transform_error.mandates.verify.cpp
index 965e82a7b403465..3260a8cbc7f8e68 100644
--- 
a/libcxx/test/libcxx/utilities/expected/expected.expected/transform_error.mandates.verify.cpp
+++ 
b/libcxx/test/libcxx/utilities/expected/expected.expected/transform_error.mandates.verify.cpp
@@ -46,11 +46,9 @@ void test() {
   {
 std::expected e;
 e.transform_error(return_unexpected); // expected-error-re@*:* 
{{static assertion failed {{.*}}The result of {{.*}} must be a valid template 
argument for unexpected}}
-// expected-error-re@*:* (excess elements in struct initializer|no 
matching constructor for initialization of)}}{{.*
 // expected-error-re@*:* {{static assertion failed 
{{.*}}[expected.object.general] A program that instantiates the definition of 
template expected for {{.*}} is ill-formed.}}
 
 e.transform_error(return_no_object); // expected-error-re@*:* 
{{static assertion failed {{.*}}The result of {{.*}} must be a valid template 
argument for unexpected}}
-// expected-error-re@*:* (excess elements in struct initializer|no 
matching constructor for initialization of)}}{{.*
 // expected-error-re@*:* {{static assertion failed 
{{.*}}[expected.object.general] A program that instantiates the definition of 
template expected for {{.*}} is ill-formed.}}
   }
 
@@ -58,27 +56,21 @@ void test() {
   {
 const std::expected e;
 e.transform_error(return_unexpected); // 
expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must 
be a valid template argument for unexpected}}
- 

[clang] [clang][modules] Print library module manifest path. (PR #76451)

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


@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation &C) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="

mordante wrote:

I removed the prefix and return "" when the manifest is not 
present.

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


[clang] [clang][modules] Print library module manifest path. (PR #76451)

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

mordante wrote:

> If this is the right thing to do (i.e., printing this information as part of 
> `-print-search-dirs`), then perhaps it's still worth it to try and fix? Once 
> you add a separate option, you will have to drag it forever (for backwards 
> compatibility).
I have a feeling how deep that rabbit hole is. This is not something I really 
want to dive into. Especially since I'm unfamiliar with this part of the code.



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


[clang] [clang][modules] Print library module manifest path. (PR #76451)

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

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


[clang] [clang][modules] Print library module manifest path. (PR #76451)

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

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

>From f3f0db64da4d341f8e4a2054f9f25c87f8eda829 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 27 Dec 2023 17:34:10 +0100
Subject: [PATCH 1/2] [clang][modules] Print library module manifest path.

This implements a way for the compiler to find the modules.json
associated with the C++23 Standard library modules.

This is based on a discussion in SG15. At the moment no Standard library
installs this manifest. #75741 adds this feature in libc++.
---
 clang/include/clang/Driver/Driver.h   | 10 +
 clang/include/clang/Driver/Options.td |  3 ++
 clang/lib/Driver/Driver.cpp   | 40 +++
 .../usr/lib/x86_64-linux-gnu/libc++.so|  0
 .../usr/lib/x86_64-linux-gnu/modules.json |  0
 ...dules-print-library-module-manifest-path.c | 15 +++
 ...arwin-print-library-module-manifest-path.c |  9 +
 7 files changed, 77 insertions(+)
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/libc++.so
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/modules.json
 create mode 100644 
clang/test/Driver/cxx23-modules-print-library-module-manifest-path.c
 create mode 100644 
clang/test/Driver/darwin-print-library-module-manifest-path.c

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 3ee1bcf2a69c9b..2e1e3b128744ff 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -602,6 +602,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain &TC) const;
 
+  /// GetModuleManifestPath - Lookup the name of the Standard library manifest.
+  ///
+  /// \param C - The compilation.
+  /// \param TC - The tool chain for additional information on
+  /// directories to search.
+  //
+  // FIXME: This should be in CompilationInfo.
+  std::string GetModuleManifestPath(const Compilation &C,
+const ToolChain &TC) const;
+
   /// HandleAutocompletions - Handle --autocomplete by searching and printing
   /// possible flags, descriptions, and its arguments.
   void HandleAutocompletions(StringRef PassedFlags) const;
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2b93ddf033499c..890257e11485b6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5280,6 +5280,9 @@ def print_resource_dir : Flag<["-", "--"], 
"print-resource-dir">,
 def print_search_dirs : Flag<["-", "--"], "print-search-dirs">,
   HelpText<"Print the paths used for finding libraries and programs">,
   Visibility<[ClangOption, CLOption]>;
+def print_library_module_manifest_path : Flag<["-", "--"], 
"print-library-module-manifest-path">,
+  HelpText<"Print the path for the C++ Standard library module manifest">,
+  Visibility<[ClangOption, CLOption]>;
 def print_targets : Flag<["-", "--"], "print-targets">,
   HelpText<"Print the registered targets">,
   Visibility<[ClangOption, CLOption]>;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index ff95c899c5f3d4..8d682f9238c6b8 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation &C) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="
+ << GetModuleManifestPath(C, C.getDefaultToolChain()) << '\n';
+return false;
+  }
+
   if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
 if (std::optional RuntimePath = TC.getRuntimePath())
   llvm::outs() << *RuntimePath << '\n';
@@ -6135,6 +6141,40 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain &TC) const {
   return std::string(Name);
 }
 
+std::string Driver::GetModuleManifestPath(const Compilation &C,
+  const ToolChain &TC) const {
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = "libc++.so";
+std::string path = GetFilePath(lib, TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+
+// For example
+/*
+const SanitizerArgs &Sanitize = TC.getSanitizerArgs(C.getArgs());
+if (Sanitize.needsAsanRt())
+  return path.replace(path.size() - lib.size(), lib.size(),
+  "modules-asan.json");
+*/
+
+path = path.replace(path.size() - lib.size(), lib.size(), "modules.json");
+if (TC.getVFS().exists(path))
+  return path;
+
+return "";
+  }
+
+  case ToolChain::CST_Libstdcxx:
+// libstdc++ does not provide Standard library modules yet.
+return "";
+  }
+
+  return "";
+

[llvm] [libcxx] [clang] "Reapply "[Sema] Fix crash on invalid code with parenthesized aggrega… (PR #76833)

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

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

>From 77abc737eebd5cf62b52248a6e35e4c74fbeca80 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 3 Jan 2024 18:00:43 +0100
Subject: [PATCH 1/4] "Reapply "[Sema] Fix crash on invalid code with
 parenthesized aggregate initialization" (#76272)""

With updates the libc++ tests.

This reverts commit 2205d23 and relands
86dc6e1 and
7ab16fb.

Original commit was reverted because of failing libc++ tests, see #76232 for
the discussion.

The errors in the tests are spurious in the first place (coming from 
initialization
of invalid classes), so update the tests to match new behavior that does
not show those errors.
---
 clang/lib/Sema/SemaInit.cpp   |  8 ++
 clang/test/SemaCXX/crash-GH76228.cpp  | 28 +++
 clang/test/SemaCXX/paren-list-agg-init.cpp|  2 +-
 .../transform_error.mandates.verify.cpp   |  8 --
 .../transform_error.mandates.verify.cpp   |  8 --
 5 files changed, 37 insertions(+), 17 deletions(-)
 create mode 100644 clang/test/SemaCXX/crash-GH76228.cpp

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 61d244f3bb9798..cc9db5ded1149a 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -5512,6 +5512,14 @@ static void TryOrBuildParenListInitialization(
   } else if (auto *RT = Entity.getType()->getAs()) {
 bool IsUnion = RT->isUnionType();
 const CXXRecordDecl *RD = cast(RT->getDecl());
+if (RD->isInvalidDecl()) {
+  // Exit early to avoid confusion when processing members.
+  // We do the same for braced list initialization in
+  // `CheckStructUnionTypes`.
+  Sequence.SetFailed(
+  clang::InitializationSequence::FK_ParenthesizedListInitFailed);
+  return;
+}
 
 if (!IsUnion) {
   for (const CXXBaseSpecifier &Base : RD->bases()) {
diff --git a/clang/test/SemaCXX/crash-GH76228.cpp 
b/clang/test/SemaCXX/crash-GH76228.cpp
new file mode 100644
index 00..33a9395823127e
--- /dev/null
+++ b/clang/test/SemaCXX/crash-GH76228.cpp
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+// Check we don't crash on incomplete members and bases when handling 
parenthesized initialization.
+class incomplete; // expected-note@-0 3  {{forward declaration of 
'incomplete'}}
+struct foo {
+  int a;
+  incomplete b;
+  // expected-error@-1 {{incomplete type}}
+};
+foo a1(0);
+
+struct one_int {
+int a;
+};
+struct bar : one_int, incomplete {};
+// expected-error@-1 {{incomplete type}}
+bar a2(0);
+
+incomplete a3[3](1,2,3);
+// expected-error@-1 {{incomplete type}}
+
+struct qux : foo {
+};
+qux a4(0);
+
+struct fred {
+foo a[3];
+};
+fred a5(0);
diff --git a/clang/test/SemaCXX/paren-list-agg-init.cpp 
b/clang/test/SemaCXX/paren-list-agg-init.cpp
index f60b20e0d46568..c1964a5a9eb005 100644
--- a/clang/test/SemaCXX/paren-list-agg-init.cpp
+++ b/clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -289,7 +289,7 @@ int test() {
   // used to crash
   S a(0, 1);
   S b(0);
-  S c(0, 0, 1); // beforecxx20-warning {{aggregate initialization of type 'S' 
from a parenthesized list of values is a C++20 extension}}
+  S c(0, 0, 1);
 
   S d {0, 1};
   S e {0};
diff --git 
a/libcxx/test/libcxx/utilities/expected/expected.expected/transform_error.mandates.verify.cpp
 
b/libcxx/test/libcxx/utilities/expected/expected.expected/transform_error.mandates.verify.cpp
index 965e82a7b40346..3260a8cbc7f8e6 100644
--- 
a/libcxx/test/libcxx/utilities/expected/expected.expected/transform_error.mandates.verify.cpp
+++ 
b/libcxx/test/libcxx/utilities/expected/expected.expected/transform_error.mandates.verify.cpp
@@ -46,11 +46,9 @@ void test() {
   {
 std::expected e;
 e.transform_error(return_unexpected); // expected-error-re@*:* 
{{static assertion failed {{.*}}The result of {{.*}} must be a valid template 
argument for unexpected}}
-// expected-error-re@*:* (excess elements in struct initializer|no 
matching constructor for initialization of)}}{{.*
 // expected-error-re@*:* {{static assertion failed 
{{.*}}[expected.object.general] A program that instantiates the definition of 
template expected for {{.*}} is ill-formed.}}
 
 e.transform_error(return_no_object); // expected-error-re@*:* 
{{static assertion failed {{.*}}The result of {{.*}} must be a valid template 
argument for unexpected}}
-// expected-error-re@*:* (excess elements in struct initializer|no 
matching constructor for initialization of)}}{{.*
 // expected-error-re@*:* {{static assertion failed 
{{.*}}[expected.object.general] A program that instantiates the definition of 
template expected for {{.*}} is ill-formed.}}
   }
 
@@ -58,27 +56,21 @@ void test() {
   {
 const std::expected e;
 e.transform_error(return_unexpected); // 
expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must 
be a valid template argument for unexpected}}
-// ex

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

2024-01-03 Thread Mark de Wever via 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
+//
+//===--===//
+
+#ifndef TEST_STD_INPUT_OUTPUT_FILE_STREAMS_FSTREAMS_TEST_HELPERS_H
+#define TEST_STD_INPUT_OUTPUT_FILE_STREAMS_FSTREAMS_TEST_HELPERS_H
+
+#include "test_macros.h"
+
+#if TEST_STD_VER >= 26
+
+#  include 
+#  include 
+#  include 
+#  include 
+#  include 
+#  include 
+#  include 
+
+#  if defined(_WIN32)
+#define WIN32_LEAN_AND_MEAN
+#define NOMINMAX
+#include 
+#include 
+#  else
+#include 
+#  endif
+
+#  include "check_assertion.h"
+#  include "platform_support.h"
+#  include "types.h"
+
+inline bool is_handle_valid(NativeHandleT handle) {

mordante wrote:

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

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


[llvm] [clang] [libcxx] "Reapply "[Sema] Fix crash on invalid code with parenthesized aggrega… (PR #76833)

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

mordante wrote:

> > @ilya-biryukov this is the new attempt to land this patch, the version you 
> > committed breaks the libc++ CI. I'll try to fix it this week.
> 
> Wow, I didn't expect that. Is libc++ ok with disabling this test until the 
> nightly build catches up? (The PR is in the Draft state, so it's hard to tell 
> if that's acceptable).

It's not ideal, but I can't think of a better solution. Typically nightly apt 
builds are built nightly so then we can update the Docker CI quickly. If the 
nightly builds are red it might take a bit longer.

The patch is in draft since I wanted to test with the bootstrap build which 
required temporary disabling other builds (the second commit). When the CI is 
green I'll do a final review and publish the patch.

> In the long-term, how should people land changes like this? Compiler 
> diagnostics are expected to change sometimes, so we should figure out some 
> way that allows landing these without reverts. Any thoughts?

Typically we work together with whom changes the tests. When there are libc++ 
changes it is visible in our review queue. For changes in diagnostics it's 
often possible to use a regex matcher. For example, the messages of 
`static_asserts` changed a while back. In general we prefer to minimize the 
tests depending on the compiler diagnostics.



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


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

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

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

Thanks LGTM!

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


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

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

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


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

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


@@ -0,0 +1,97 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef TEST_STD_INPUT_OUTPUT_FILE_STREAMS_FSTREAMS_TEST_HELPERS_H
+#define TEST_STD_INPUT_OUTPUT_FILE_STREAMS_FSTREAMS_TEST_HELPERS_H
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#if defined(_WIN32)
+#  include 
+#  include 
+#else
+#  include 
+#endif
+
+#include "platform_support.h"
+#include "test_macros.h"
+#include "types.h"
+
+#if TEST_STD_VER >= 26
+
+#  include "check_assertion.h"
+
+inline bool is_handle_valid(NativeHandleT handle) {
+#  if defined(_WIN32)
+  BY_HANDLE_FILE_INFORMATION fileInformation;
+  return GetFileInformationByHandle(handle, &fileInformation));
+#  elif __has_include() // POSIX
+  return fcntl(handle, F_GETFL) != -1 || errno != EBADF;
+#  else
+#error "Provide a native file handle!"
+#  endif
+}
+
+template 
+inline void test_native_handle() {
+  static_assert(
+  std::is_same_v::native_handle_type, 
typename StreamT::native_handle_type>);
+
+  StreamT f;
+  std::filesystem::path p = get_temp_file_name();
+
+  // non-const
+  {
+f.open(p);
+std::same_as decltype(auto) handle = f.native_handle();
+assert(is_handle_valid(handle));
+assert(f.rdbuf()->native_handle() == handle);
+assert(std::as_const(f).rdbuf()->native_handle() == handle);
+f.close();
+assert(!is_handle_valid(handle));
+static_assert(noexcept(f.native_handle()));
+  }
+  // const
+  {
+f.open(p);
+std::same_as decltype(auto) const_handle = 
std::as_const(f).native_handle();
+assert(is_handle_valid(const_handle));
+assert(f.rdbuf()->native_handle() == const_handle);
+assert(std::as_const(f).rdbuf()->native_handle() == const_handle);
+f.close();
+assert(!is_handle_valid(const_handle));
+static_assert(noexcept(std::as_const(f).native_handle()));
+  }
+}
+
+template 
+inline void test_native_handle_assertion() {
+  StreamT f;
+
+  // non-const
+  { TEST_LIBCPP_ASSERT_FAILURE(f.native_handle(), "File must be opened"); }

mordante wrote:

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

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


[libcxx] [llvm] [clang] "Reapply "[Sema] Fix crash on invalid code with parenthesized aggrega… (PR #76833)

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

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


[clang] [libcxx] [llvm] "Reapply "[Sema] Fix crash on invalid code with parenthesized aggrega… (PR #76833)

2024-01-05 Thread Mark de Wever via cfe-commits

mordante wrote:

> > It's not ideal, but I can't think of a better solution. Typically nightly 
> > apt builds are built nightly so then we can update the Docker CI quickly. 
> > If the nightly builds are red it might take a bit longer.
> > The patch is in draft since I wanted to test with the bootstrap build which 
> > required temporary disabling other builds (the second commit). When the CI 
> > is green I'll do a final review and publish the patch.
> 
> It's been 2 days, maybe we should just submit this and see if anything goes 
> wrong? Besides, the CI seems green now, so hopefully everything has already 
> been checked.

I'll land this soon. Yesterday evening I didn't have time.

> > > In the long-term, how should people land changes like this? Compiler 
> > > diagnostics are expected to change sometimes, so we should figure out 
> > > some way that allows landing these without reverts. Any thoughts?
> > 
> > 
> > Typically we work together with whom changes the tests. When there are 
> > libc++ changes it is visible in our review queue. For changes in 
> > diagnostics it's often possible to use a regex matcher. For example, the 
> > messages of `static_asserts` changed a while back. In general we prefer to 
> > minimize the tests depending on the compiler diagnostics.
> 
> This use-case is different, we need a way to change the set of reported 
> diagnostics in Clang even if the diagnostic is produced in libc++ tests. 
> Blocking changes to Clang because libc++ tests against nightly and head 
> builds looks too harsh.
> 
> I think we need to find some alternative solution that works here. The 
> obvious solution that I see is to run the nightly Clang as post-submits and 
> allow them to be broken for this reasons (as it will fix itself after nightly 
> Clang gets rebuilt).

All but one of the libc++ pre-commit CI jobs uses pre-built clang binaries. We 
heavily depend on a pre-commit CI to test changes on platforms we don't have 
access to. So changing it to a post-commit CI is not an option.

> @AaronBallman, @cor3ntin what are your thoughts as Clang maintainers? TLDR; 
> is that libc++ runs tests in CI with both head Clang and nightly Clang 
> builds. Therefore, if we happen to change the set of reported diagnostics in 
> Clang (in this case it was a spurious error in initialization of invalid 
> classes that got silenced with a Clang change), we cannot land this change 
> without breaking the libc++ CI.

Note that the original patch also breaks clang-16 and clang-17. So usually 
there's a regex matcher used and that works with clang-16, clang-17, clang-18 
nightly, and clang-18 ToT. This is a rare case where it's not possible to use a 
regex. (In general clang patches affecting libc++ are rare.) As mentioned 
before typically we work together with Clang to see how to fix this. As far as 
I can tell the changes to libc++ were not reviewed by the a libc++ reviewer and 
not tested in the pre-commit CI. Please correct me if I'm wrong.

After a previous breakage both @ldionne and I have discussed this with 
@AaronBallman and that resulted in 
[documentation](https://clang.llvm.org/hacking.html#testingLibc++) to create 
awareness and we helped to get a clang pre-commit CI up and running.

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


[clang] [libcxx] [llvm] "Reapply "[Sema] Fix crash on invalid code with parenthesized aggrega… (PR #76833)

2024-01-05 Thread Mark de Wever via cfe-commits

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


[libcxx] [llvm] [clang] "Reapply "[Sema] Fix crash on invalid code with parenthesized aggrega… (PR #76833)

2024-01-07 Thread Mark de Wever via cfe-commits

mordante wrote:

> @mordante The lines could be changed to `// expected-error-re@*:* 0-1 
> (excess elements in struct initializer|no matching constructor for 
> initialization of)}}{{.*` to still have coverage. FWIW the `{{.*}}` at 
> the end seems to be redundant too.

Totally forgot using 0 occurrences are valid in this syntax. I'll make a new 
patch. I'll keep the redundant part, the entire expected will be redundant in 
about a year. 

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


[flang] [llvm] [clang-tools-extra] [libc] [libcxx] [clang] [compiler-rt] [libc++] Implement LWG3940: std::expected::value() also needs E to be copy constructible (PR #71819)

2024-01-07 Thread Mark de Wever via cfe-commits


@@ -0,0 +1,51 @@
+//===--===//
+// 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
+// UNSUPPORTED: no-rtti
+// UNSUPPORTED: no-exceptions
+
+// constexpr void value() const &;
+// Mandates: is_copy_constructible_v is true.
+
+// constexpr void value() &&;
+// Mandates: is_copy_constructible_v is true and is_move_constructible_v 
is true.
+
+#include 
+
+#include "MoveOnly.h"
+
+struct CopyOnly {
+  CopyOnly()= default;
+  CopyOnly(const CopyOnly&) = default;
+  CopyOnly(CopyOnly&&)  = delete;
+};
+
+void test() {
+  // MoveOnly type as error_type
+  std::expected e(std::unexpect, 5);
+
+  e.value(); // expected-note {{in instantiation of member function 
'std::expected::value' requested here}}
+  // expected-error@*:* {{static assertion failed due to requirement 
'is_copy_constructible_v'}}
+
+  std::move(e)
+  .value(); // expected-note {{in instantiation of member function 
'std::expected::value' requested here}}
+  // expected-error@*:* {{static assertion failed due to requirement 
'is_copy_constructible_v': error_type has to be both copy 
constructible and move constructible}}
+
+  // CopyOnly type as error_type
+  std::expected e2(std::unexpect);
+
+  e2.value();
+
+  std::move(e2)
+  .value(); // expected-note {{in instantiation of member function 
'std::expected::value' requested here}}
+  // expected-error@*:* {{static assertion failed due to requirement 
'is_move_constructible_v': error_type has to be both copy 
constructible and move constructible}}
+
+  // expected-error@*:* {{call to deleted constructor of 'MoveOnly'}}
+  // expected-error@*:* {{call to deleted constructor of 'CopyOnly'}}
+  // expected-error@*:* {{call to deleted constructor of 'CopyOnly'}}

mordante wrote:

Can you move these expected-error's to the places where they are generated. We 
need the `@*:*` since they are in the headers, but for maintainability it's 
good to have them where they are generated. 

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


[compiler-rt] [flang] [llvm] [libcxx] [clang-tools-extra] [libc] [clang] [libc++] Implement LWG3940: std::expected::value() also needs E to be copy constructible (PR #71819)

2024-01-07 Thread Mark de Wever via cfe-commits


@@ -1150,12 +1150,15 @@ class expected<_Tp, _Err> {
   }
 
   _LIBCPP_HIDE_FROM_ABI constexpr void value() const& {
+static_assert(is_copy_constructible_v<_Err>);
 if (!__has_val_) {
   std::__throw_bad_expected_access<_Err>(__union_.__unex_);
 }
   }
 
   _LIBCPP_HIDE_FROM_ABI constexpr void value() && {
+static_assert(is_copy_constructible_v<_Err> && 
is_move_constructible_v<_Err>,
+  "error_type has to be both copy constructible and move 
constructible");

mordante wrote:

Since we don't require a message in `static_assert` anymore and this message 
adds no extra information, let's remove it.

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


[libcxx] [flang] [clang-tools-extra] [compiler-rt] [llvm] [libc] [clang] [libc++] Implement LWG3940: std::expected::value() also needs E to be copy constructible (PR #71819)

2024-01-07 Thread Mark de Wever via cfe-commits

https://github.com/mordante commented:

> The CI finally passed now : )

Great. A few minor comment and then it LGTM. I'll leave the final approval to 
@huixie90 

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


[compiler-rt] [libcxx] [llvm] [clang] [flang] [libc] [clang-tools-extra] [libc++] Implement LWG3940: std::expected::value() also needs E to be copy constructible (PR #71819)

2024-01-07 Thread Mark de Wever via cfe-commits

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


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

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

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

Thanks! LGTM!

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


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

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

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


  1   2   3   4   >