[clang] 0f501c3 - Revert "[C++20][Coroutines] Lambda-coroutine with operator new in promise_type (#84193)"
Chuanqi Xu via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 11 02:03:08 PDT 2024
Author: Chuanqi Xu
Date: 2024-03-11T17:02:43+08:00
New Revision: 0f501c30b9601627c236f9abca8a3befba5dc161
URL: https://github.com/llvm/llvm-project/commit/0f501c30b9601627c236f9abca8a3befba5dc161
DIFF: https://github.com/llvm/llvm-project/commit/0f501c30b9601627c236f9abca8a3befba5dc161.diff
LOG: Revert "[C++20][Coroutines] Lambda-coroutine with operator new in promise_type (#84193)"
This reverts commit 35d3b33ba5c9b90443ac985f2521b78f84b611fe.
See the comments in https://github.com/llvm/llvm-project/pull/84193 for
details
Added:
Modified:
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaCoroutine.cpp
clang/lib/Sema/SemaExprCXX.cpp
Removed:
clang/test/SemaCXX/gh84064-1.cpp
clang/test/SemaCXX/gh84064-2.cpp
################################################################################
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 00b3f53f5c1c66..267c79cc057cba 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -6752,18 +6752,10 @@ class Sema final {
SourceLocation RParenLoc);
//// ActOnCXXThis - Parse 'this' pointer.
- ///
- /// \param ThisRefersToClosureObject Whether to skip the 'this' check for a
- /// lambda because 'this' refers to the closure object.
- ExprResult ActOnCXXThis(SourceLocation loc,
- bool ThisRefersToClosureObject = false);
+ ExprResult ActOnCXXThis(SourceLocation loc);
/// Build a CXXThisExpr and mark it referenced in the current context.
- ///
- /// \param ThisRefersToClosureObject Whether to skip the 'this' check for a
- /// lambda because 'this' refers to the closure object.
- Expr *BuildCXXThisExpr(SourceLocation Loc, QualType Type, bool IsImplicit,
- bool ThisRefersToClosureObject = false);
+ Expr *BuildCXXThisExpr(SourceLocation Loc, QualType Type, bool IsImplicit);
void MarkThisReferenced(CXXThisExpr *This);
/// Try to retrieve the type of the 'this' pointer.
diff --git a/clang/lib/Sema/SemaCoroutine.cpp b/clang/lib/Sema/SemaCoroutine.cpp
index 5206fc7621c7cd..736632857efc36 100644
--- a/clang/lib/Sema/SemaCoroutine.cpp
+++ b/clang/lib/Sema/SemaCoroutine.cpp
@@ -25,7 +25,6 @@
#include "clang/Sema/Initialization.h"
#include "clang/Sema/Overload.h"
#include "clang/Sema/ScopeInfo.h"
-#include "clang/Sema/Sema.h"
#include "clang/Sema/SemaInternal.h"
#include "llvm/ADT/SmallSet.h"
@@ -1291,21 +1290,8 @@ bool CoroutineStmtBuilder::makeReturnOnAllocFailure() {
static bool collectPlacementArgs(Sema &S, FunctionDecl &FD, SourceLocation Loc,
SmallVectorImpl<Expr *> &PlacementArgs) {
if (auto *MD = dyn_cast<CXXMethodDecl>(&FD)) {
- if (MD->isImplicitObjectMemberFunction()) {
- ExprResult ThisExpr{};
-
- if (isLambdaCallOperator(MD) && !MD->isStatic()) {
- Qualifiers ThisQuals = MD->getMethodQualifiers();
- CXXRecordDecl *Record = MD->getParent();
-
- Sema::CXXThisScopeRAII ThisScope(S, Record, ThisQuals,
- Record != nullptr);
-
- ThisExpr = S.ActOnCXXThis(Loc, /*ThisRefersToClosureObject=*/true);
- } else {
- ThisExpr = S.ActOnCXXThis(Loc);
- }
-
+ if (MD->isImplicitObjectMemberFunction() && !isLambdaCallOperator(MD)) {
+ ExprResult ThisExpr = S.ActOnCXXThis(Loc);
if (ThisExpr.isInvalid())
return false;
ThisExpr = S.CreateBuiltinUnaryOp(Loc, UO_Deref, ThisExpr.get());
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 88e3d9ced044cb..c34a40fa7c81ac 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1414,8 +1414,7 @@ bool Sema::CheckCXXThisCapture(SourceLocation Loc, const bool Explicit,
return false;
}
-ExprResult Sema::ActOnCXXThis(SourceLocation Loc,
- bool ThisRefersToClosureObject) {
+ExprResult Sema::ActOnCXXThis(SourceLocation Loc) {
/// C++ 9.3.2: In the body of a non-static member function, the keyword this
/// is a non-lvalue expression whose value is the address of the object for
/// which the function is called.
@@ -1435,18 +1434,13 @@ ExprResult Sema::ActOnCXXThis(SourceLocation Loc,
return Diag(Loc, diag::err_invalid_this_use) << 0;
}
- return BuildCXXThisExpr(Loc, ThisTy, /*IsImplicit=*/false,
- ThisRefersToClosureObject);
+ return BuildCXXThisExpr(Loc, ThisTy, /*IsImplicit=*/false);
}
-Expr *Sema::BuildCXXThisExpr(SourceLocation Loc, QualType Type, bool IsImplicit,
- bool ThisRefersToClosureObject) {
+Expr *Sema::BuildCXXThisExpr(SourceLocation Loc, QualType Type,
+ bool IsImplicit) {
auto *This = CXXThisExpr::Create(Context, Loc, Type, IsImplicit);
-
- if (!ThisRefersToClosureObject) {
- MarkThisReferenced(This);
- }
-
+ MarkThisReferenced(This);
return This;
}
diff --git a/clang/test/SemaCXX/gh84064-1.cpp b/clang/test/SemaCXX/gh84064-1.cpp
deleted file mode 100644
index d9c2738a002b8d..00000000000000
--- a/clang/test/SemaCXX/gh84064-1.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -I%S/Inputs -std=c++20 %s
-
-// expected-no-diagnostics
-
-#include "std-coroutine.h"
-
-using size_t = decltype(sizeof(0));
-
-struct Generator {
- struct promise_type {
- int _val{};
-
- Generator get_return_object() noexcept
- {
- return {};
- }
-
- std::suspend_never initial_suspend() noexcept
- {
- return {};
- }
-
- std::suspend_always final_suspend() noexcept
- {
- return {};
- }
-
- void return_void() noexcept {}
- void unhandled_exception() noexcept {}
-
- template<typename This, typename... TheRest>
- static void*
- operator new(size_t size,
- This&,
- TheRest&&...) noexcept
- {
- return nullptr;
- }
-
- static void operator delete(void*, size_t)
- {
- }
- };
-};
-
-struct CapturingThisTest
-{
- int x{};
-
- void AsPointer()
- {
- auto lamb = [=,this]() -> Generator {
- int y = x;
- co_return;
- };
-
- static_assert(sizeof(decltype(lamb)) == sizeof(void*));
- }
-
- void AsStarThis()
- {
- auto lamb = [*this]() -> Generator {
- int y = x;
- co_return;
- };
-
- static_assert(sizeof(decltype(lamb)) == sizeof(int));
- }
-};
-
-int main()
-{
- auto lamb = []() -> Generator {
- co_return;
- };
-
- static_assert(sizeof(decltype(lamb)) == 1);
-}
-
diff --git a/clang/test/SemaCXX/gh84064-2.cpp b/clang/test/SemaCXX/gh84064-2.cpp
deleted file mode 100644
index 457de43eab6d9e..00000000000000
--- a/clang/test/SemaCXX/gh84064-2.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -I%S/Inputs -std=c++23 %s
-
-// expected-no-diagnostics
-
-#include "std-coroutine.h"
-
-using size_t = decltype(sizeof(0));
-
-struct GeneratorStatic {
- struct promise_type {
- int _val{};
-
- GeneratorStatic get_return_object() noexcept
- {
- return {};
- }
-
- std::suspend_never initial_suspend() noexcept
- {
- return {};
- }
-
- std::suspend_always final_suspend() noexcept
- {
- return {};
- }
-
- void return_void() noexcept {}
- void unhandled_exception() noexcept {}
-
- template<typename... TheRest>
- static void*
- operator new(size_t size,
- TheRest&&...) noexcept
- {
- return nullptr;
- }
-
- static void operator delete(void*, size_t)
- {
- }
- };
-};
-
-
-int main()
-{
- auto lambCpp23 = []() static -> GeneratorStatic {
- co_return;
- };
-
- static_assert(sizeof(decltype(lambCpp23)) == 1);
-}
More information about the cfe-commits
mailing list