[PATCH] D142430: [Clang] Treat `std::forward_like` as builtin

2023-01-28 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0fd9c37d8cf2: [Clang] Treat `std::forward_like` as builtin 
(authored by alexander-shaposhnikov).

Changed prior to commit:
  https://reviews.llvm.org/D142430?vs=491598=493042#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142430/new/

https://reviews.llvm.org/D142430

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Builtins.def
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Analysis/BodyFarm.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CodeGenCXX/builtin-std-move.cpp
  clang/test/SemaCXX/attr-lifetimebound.cpp
  clang/test/SemaCXX/builtin-std-move-nobuiltin.cpp
  clang/test/SemaCXX/builtin-std-move.cpp

Index: clang/test/SemaCXX/builtin-std-move.cpp
===
--- clang/test/SemaCXX/builtin-std-move.cpp
+++ clang/test/SemaCXX/builtin-std-move.cpp
@@ -43,6 +43,33 @@
 return static_cast(x);
   }
 
+  template  struct is_const { static constexpr bool value = false; };
+  template  struct is_const { static constexpr bool value = true; };
+
+  template  struct conditional { using type = T; };
+  template  struct conditional { using type = F; };
+
+  template 
+  using CopyConst = typename conditional<
+  is_const>::value,
+  const T, T>::type;
+
+  template 
+  using OverrideRef = typename conditional<
+  is_lvalue_reference::value,
+  typename remove_reference::type &,
+  typename remove_reference::type &&>::type;
+
+  template 
+  using ForwardLikeRetType = OverrideRef>;
+
+  template 
+  CONSTEXPR auto forward_like(T &) -> ForwardLikeRetType {
+using TT = typename remove_reference::type;
+static_assert(TT::moveable, "instantiated as_const"); // expected-error {{no member named 'moveable' in 'B'}}
+return static_cast>(t);
+  }
+
   template CONSTEXPR const T _const(T ) {
 static_assert(T::moveable, "instantiated as_const"); // expected-error {{no member named 'moveable' in 'B'}}
 return x;
@@ -92,14 +119,15 @@
 B &&(*pMove)(B&) = std::move; // #1 expected-note {{instantiation of}}
 B &&(*pMoveIfNoexcept)(B&) = ::move_if_noexcept; // #2 expected-note {{instantiation of}}
 B &&(*pForward)(B&) = ::forward; // #3 expected-note {{instantiation of}}
-const B &(*pAsConst)(B&) = ::as_const; // #4 expected-note {{instantiation of}}
-B *(*pAddressof)(B&) = ::addressof; // #5 expected-note {{instantiation of}}
-B *(*pUnderUnderAddressof)(B&) = ::__addressof; // #6 expected-note {{instantiation of}}
+B &&(*pForwardLike)(B&) = ::forward_like; // #4 expected-note {{instantiation of}}
+const B &(*pAsConst)(B&) = ::as_const; // #5 expected-note {{instantiation of}}
+B *(*pAddressof)(B&) = ::addressof; // #6 expected-note {{instantiation of}}
+B *(*pUnderUnderAddressof)(B&) = ::__addressof; // #7 expected-note {{instantiation of}}
 int (*pUnrelatedMove)(B, B) = std::move;
 
 struct C {};
-C &&()(C&) = std::move; // #7 expected-note {{instantiation of}}
-C &&()(C&) = std::forward; // #8 expected-note {{instantiation of}}
+C &&()(C&) = std::move; // #8 expected-note {{instantiation of}}
+C &&()(C&) = std::forward; // #9 expected-note {{instantiation of}}
 int ()(B, B) = std::move;
 
 #if __cplusplus <= 201703L
@@ -111,6 +139,7 @@
 // expected-warning@#6 {{non-addressable}}
 // expected-warning@#7 {{non-addressable}}
 // expected-warning@#8 {{non-addressable}}
+// expected-warning@#9 {{non-addressable}}
 #else
 // expected-error@#1 {{non-addressable}}
 // expected-error@#2 {{non-addressable}}
@@ -120,6 +149,7 @@
 // expected-error@#6 {{non-addressable}}
 // expected-error@#7 {{non-addressable}}
 // expected-error@#8 {{non-addressable}}
+// expected-error@#9 {{non-addressable}}
 #endif
 
 void attribute_const() {
@@ -127,6 +157,7 @@
   std::move(n); // expected-warning {{ignoring return value}}
   std::move_if_noexcept(n); // expected-warning {{ignoring return value}}
   std::forward(n); // expected-warning {{ignoring return value}}
+  std::forward_like(n); // expected-warning {{ignoring return value}}
   std::addressof(n); // expected-warning {{ignoring return value}}
   std::__addressof(n); // expected-warning {{ignoring return value}}
   std::as_const(n); // expected-warning {{ignoring return value}}
Index: clang/test/SemaCXX/builtin-std-move-nobuiltin.cpp
===
--- clang/test/SemaCXX/builtin-std-move-nobuiltin.cpp
+++ clang/test/SemaCXX/builtin-std-move-nobuiltin.cpp
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -std=c++20 -verify %s -DBUILTIN=builtin
 // RUN: %clang_cc1 -std=c++20 -verify %s -DBUILTIN=nobuiltin -fno-builtin
-// RUN: %clang_cc1 -std=c++20 -verify %s -DBUILTIN=nobuiltin -fno-builtin-std-move -fno-builtin-std-move_if_noexcept -fno-builtin-std-forward
+// RUN: 

[PATCH] D142430: [Clang] Treat `std::forward_like` as builtin

2023-01-27 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
alexander-shaposhnikov added a comment.

gentle ping )


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142430/new/

https://reviews.llvm.org/D142430

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


[PATCH] D142430: [Clang] Treat `std::forward_like` as builtin

2023-01-23 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
alexander-shaposhnikov created this revision.
alexander-shaposhnikov added reviewers: rsmith, aaron.ballman.
alexander-shaposhnikov created this object with visibility "All Users".
Herald added a reviewer: NoQ.
Herald added a project: All.
alexander-shaposhnikov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This diff extends D123345  by adding support 
for std::forward_like.

Test plan: ninja check-clang check-clang-tools check-llvm


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142430

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Builtins.def
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Analysis/BodyFarm.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CodeGenCXX/builtin-std-move.cpp
  clang/test/SemaCXX/attr-lifetimebound.cpp
  clang/test/SemaCXX/builtin-std-move-nobuiltin.cpp
  clang/test/SemaCXX/builtin-std-move.cpp

Index: clang/test/SemaCXX/builtin-std-move.cpp
===
--- clang/test/SemaCXX/builtin-std-move.cpp
+++ clang/test/SemaCXX/builtin-std-move.cpp
@@ -43,6 +43,33 @@
 return static_cast(x);
   }
 
+  template  struct is_const { static constexpr bool value = false; };
+  template  struct is_const { static constexpr bool value = true; };
+
+  template  struct conditional { using type = T; };
+  template  struct conditional { using type = F; };
+
+  template 
+  using CopyConst = typename conditional<
+  is_const>::value,
+  const T, T>::type;
+
+  template 
+  using OverrideRef = typename conditional<
+  is_lvalue_reference::value,
+  typename remove_reference::type &,
+  typename remove_reference::type &&>::type;
+
+  template 
+  using ForwardLikeRetType = OverrideRef>;
+
+  template 
+  CONSTEXPR auto forward_like(T &) -> ForwardLikeRetType {
+using TT = typename remove_reference::type;
+static_assert(TT::moveable, "instantiated as_const"); // expected-error {{no member named 'moveable' in 'B'}}
+return static_cast>(t);
+  }
+
   template CONSTEXPR const T _const(T ) {
 static_assert(T::moveable, "instantiated as_const"); // expected-error {{no member named 'moveable' in 'B'}}
 return x;
@@ -92,14 +119,15 @@
 B &&(*pMove)(B&) = std::move; // #1 expected-note {{instantiation of}}
 B &&(*pMoveIfNoexcept)(B&) = ::move_if_noexcept; // #2 expected-note {{instantiation of}}
 B &&(*pForward)(B&) = ::forward; // #3 expected-note {{instantiation of}}
-const B &(*pAsConst)(B&) = ::as_const; // #4 expected-note {{instantiation of}}
-B *(*pAddressof)(B&) = ::addressof; // #5 expected-note {{instantiation of}}
-B *(*pUnderUnderAddressof)(B&) = ::__addressof; // #6 expected-note {{instantiation of}}
+B &&(*pForwardLike)(B&) = ::forward_like; // #4 expected-note {{instantiation of}}
+const B &(*pAsConst)(B&) = ::as_const; // #5 expected-note {{instantiation of}}
+B *(*pAddressof)(B&) = ::addressof; // #6 expected-note {{instantiation of}}
+B *(*pUnderUnderAddressof)(B&) = ::__addressof; // #7 expected-note {{instantiation of}}
 int (*pUnrelatedMove)(B, B) = std::move;
 
 struct C {};
-C &&()(C&) = std::move; // #7 expected-note {{instantiation of}}
-C &&()(C&) = std::forward; // #8 expected-note {{instantiation of}}
+C &&()(C&) = std::move; // #8 expected-note {{instantiation of}}
+C &&()(C&) = std::forward; // #9 expected-note {{instantiation of}}
 int ()(B, B) = std::move;
 
 #if __cplusplus <= 201703L
@@ -111,6 +139,7 @@
 // expected-warning@#6 {{non-addressable}}
 // expected-warning@#7 {{non-addressable}}
 // expected-warning@#8 {{non-addressable}}
+// expected-warning@#9 {{non-addressable}}
 #else
 // expected-error@#1 {{non-addressable}}
 // expected-error@#2 {{non-addressable}}
@@ -120,6 +149,7 @@
 // expected-error@#6 {{non-addressable}}
 // expected-error@#7 {{non-addressable}}
 // expected-error@#8 {{non-addressable}}
+// expected-error@#9 {{non-addressable}}
 #endif
 
 void attribute_const() {
@@ -127,6 +157,7 @@
   std::move(n); // expected-warning {{ignoring return value}}
   std::move_if_noexcept(n); // expected-warning {{ignoring return value}}
   std::forward(n); // expected-warning {{ignoring return value}}
+  std::forward_like(n); // expected-warning {{ignoring return value}}
   std::addressof(n); // expected-warning {{ignoring return value}}
   std::__addressof(n); // expected-warning {{ignoring return value}}
   std::as_const(n); // expected-warning {{ignoring return value}}
Index: clang/test/SemaCXX/builtin-std-move-nobuiltin.cpp
===
--- clang/test/SemaCXX/builtin-std-move-nobuiltin.cpp
+++ clang/test/SemaCXX/builtin-std-move-nobuiltin.cpp
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -std=c++20 -verify %s -DBUILTIN=builtin
 // RUN: %clang_cc1 -std=c++20 -verify %s -DBUILTIN=nobuiltin -fno-builtin
-// RUN: