[PATCH] D132945: [clang] Skip re-building lambda expressions in parameters to consteval fns.
Utkarsh Saxena via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 30 08:00:25 PDT 2022
usaxena95 created this revision.
Herald added a project: All.
usaxena95 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Fixes: https://github.com/llvm/llvm-project/issues/56183
Fixes: https://github.com/llvm/llvm-project/issues/51695
Fixes: https://github.com/llvm/llvm-project/issues/50455
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D132945
Files:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/cxx2a-consteval.cpp
Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===================================================================
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -939,3 +939,63 @@
static_assert(max(1,2)==2);
static_assert(mid(1,2,3)==2);
} // namespace GH51182
+
+// https://github.com/llvm/llvm-project/issues/56183
+namespace GH56183 {
+consteval auto Foo(auto c) { return c; }
+consteval auto Bar(auto f) { return f(); }
+void test() {
+ constexpr auto x = Foo(Bar([] { return 'a'; }));
+ static_assert(x == 'a');
+}
+} // namespace GH56183
+
+// https://github.com/llvm/llvm-project/issues/51695
+namespace GH51695 {
+// Original ========================================
+template <typename T>
+struct type_t {};
+
+template <typename...>
+struct list_t {};
+
+template <typename T, typename... Ts>
+consteval auto pop_front(list_t<T, Ts...>) -> auto {
+ return list_t<Ts...>{};
+}
+
+template <typename... Ts, typename F>
+consteval auto apply(list_t<Ts...>, F fn) -> auto {
+ return fn(type_t<Ts>{}...);
+}
+
+void test1() {
+ constexpr auto x = apply(pop_front(list_t<char, char>{}),
+ []<typename... Us>(type_t<Us>...) { return 42; });
+ static_assert(x == 42);
+}
+// Reduced ========================================
+consteval bool zero() { return false; }
+
+template <typename F>
+consteval bool foo(bool, F f) {
+ return f();
+}
+
+void test2() {
+ constexpr auto x = foo(zero(), []() { return true; });
+ static_assert(x);
+}
+} // namespace GH51695
+
+// https://github.com/llvm/llvm-project/issues/50455
+namespace GH50455 {
+void f() {
+ []() consteval { int i{}; }();
+ []() consteval { int i{}; ++i; }();
+}
+void g() {
+ (void)[](int i) consteval { return i; }(0);
+ (void)[](int i) consteval { return i; }(0);
+}
+} // namespace GH50455
\ No newline at end of file
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -17598,6 +17598,7 @@
DRSet.erase(E);
return E;
}
+ ExprResult TransformLambdaExpr(LambdaExpr *E) { return E; }
bool AlwaysRebuild() { return false; }
bool ReplacingOriginal() { return true; }
bool AllowSkippingCXXConstructExpr() {
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -191,8 +191,12 @@
- Correctly set expression evaluation context as 'immediate function context' in
consteval functions.
- This fixes `GH51182 <https://github.com/llvm/llvm-project/issues/51182>`
+ This fixes `GH51182 <https://github.com/llvm/llvm-project/issues/51182>`_.
+- Skip re-building lambda expressions when they appear as parameters to an immediate invocation.
+ This fixes `GH56183 <https://github.com/llvm/llvm-project/issues/56183>`_,
+ `GH51695 <https://github.com/llvm/llvm-project/issues/51695>`_,
+ `GH50455 <https://github.com/llvm/llvm-project/issues/50455>`_.
C++2b Feature Support
^^^^^^^^^^^^^^^^^^^^^
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132945.456677.patch
Type: text/x-patch
Size: 3121 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220830/8a163ac0/attachment.bin>
More information about the cfe-commits
mailing list