Skip to content

Commit 8570523

Browse files
committed
Remove isAwaitSuspendNoThrow
1 parent 7f767bc commit 8570523

File tree

4 files changed

+31
-87
lines changed

4 files changed

+31
-87
lines changed

clang/include/clang/AST/ExprCXX.h

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5035,19 +5035,18 @@ class CoroutineSuspendExpr : public Expr {
50355035
enum SubExpr { Operand, Common, Ready, Suspend, Resume, Count };
50365036

50375037
Stmt *SubExprs[SubExpr::Count];
5038-
bool IsSuspendNoThrow = false;
50395038
OpaqueValueExpr *OpaqueValue = nullptr;
50405039
OpaqueValueExpr *OpaqueFramePtr = nullptr;
50415040

50425041
public:
50435042
CoroutineSuspendExpr(StmtClass SC, SourceLocation KeywordLoc, Expr *Operand,
50445043
Expr *Common, Expr *Ready, Expr *Suspend, Expr *Resume,
5045-
bool IsSuspendNoThrow, OpaqueValueExpr *OpaqueValue,
5044+
OpaqueValueExpr *OpaqueValue,
50465045
OpaqueValueExpr *OpaqueFramePtr)
50475046
: Expr(SC, Resume->getType(), Resume->getValueKind(),
50485047
Resume->getObjectKind()),
5049-
KeywordLoc(KeywordLoc), IsSuspendNoThrow(IsSuspendNoThrow),
5050-
OpaqueValue(OpaqueValue), OpaqueFramePtr(OpaqueFramePtr) {
5048+
KeywordLoc(KeywordLoc), OpaqueValue(OpaqueValue),
5049+
OpaqueFramePtr(OpaqueFramePtr) {
50515050
SubExprs[SubExpr::Operand] = Operand;
50525051
SubExprs[SubExpr::Common] = Common;
50535052
SubExprs[SubExpr::Ready] = Ready;
@@ -5104,8 +5103,6 @@ class CoroutineSuspendExpr : public Expr {
51045103
return static_cast<Expr *>(SubExprs[SubExpr::Operand]);
51055104
}
51065105

5107-
bool isSuspendNoThrow() const { return IsSuspendNoThrow; }
5108-
51095106
SourceLocation getKeywordLoc() const { return KeywordLoc; }
51105107

51115108
SourceLocation getBeginLoc() const LLVM_READONLY { return KeywordLoc; }
@@ -5134,12 +5131,12 @@ class CoawaitExpr : public CoroutineSuspendExpr {
51345131

51355132
public:
51365133
CoawaitExpr(SourceLocation CoawaitLoc, Expr *Operand, Expr *Common,
5137-
Expr *Ready, Expr *Suspend, Expr *Resume, bool IsSuspendNoThrow,
5134+
Expr *Ready, Expr *Suspend, Expr *Resume,
51385135
OpaqueValueExpr *OpaqueValue, OpaqueValueExpr *OpaqueFramePtr,
51395136
bool IsImplicit = false)
51405137
: CoroutineSuspendExpr(CoawaitExprClass, CoawaitLoc, Operand, Common,
5141-
Ready, Suspend, Resume, IsSuspendNoThrow,
5142-
OpaqueValue, OpaqueFramePtr) {
5138+
Ready, Suspend, Resume, OpaqueValue,
5139+
OpaqueFramePtr) {
51435140
CoawaitBits.IsImplicit = IsImplicit;
51445141
}
51455142

@@ -5217,11 +5214,11 @@ class CoyieldExpr : public CoroutineSuspendExpr {
52175214

52185215
public:
52195216
CoyieldExpr(SourceLocation CoyieldLoc, Expr *Operand, Expr *Common,
5220-
Expr *Ready, Expr *Suspend, Expr *Resume, bool IsSuspendNoThrow,
5217+
Expr *Ready, Expr *Suspend, Expr *Resume,
52215218
OpaqueValueExpr *OpaqueValue, OpaqueValueExpr *OpaqueFramePtr)
52225219
: CoroutineSuspendExpr(CoyieldExprClass, CoyieldLoc, Operand, Common,
5223-
Ready, Suspend, Resume, IsSuspendNoThrow,
5224-
OpaqueValue, OpaqueFramePtr) {}
5220+
Ready, Suspend, Resume, OpaqueValue,
5221+
OpaqueFramePtr) {}
52255222
CoyieldExpr(SourceLocation CoyieldLoc, QualType Ty, Expr *Operand,
52265223
Expr *Common)
52275224
: CoroutineSuspendExpr(CoyieldExprClass, CoyieldLoc, Ty, Operand,

clang/lib/CodeGen/CGCoroutine.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ static bool ResumeStmtCanThrow(const Stmt *S) {
173173
return false;
174174
}
175175

176+
static bool AwaitSuspendStmtCanThrow(const Stmt *S) {
177+
return ResumeStmtCanThrow(S);
178+
}
179+
176180
// Emit suspend expression which roughly looks like:
177181
//
178182
// auto && x = CommonExpr();
@@ -233,8 +237,11 @@ static LValueOrRValue emitSuspendExpression(CodeGenFunction &CGF, CGCoroData &Co
233237
auto *NullPtr = llvm::ConstantPointerNull::get(CGF.CGM.Int8PtrTy);
234238
auto *SaveCall = Builder.CreateCall(CoroSave, {NullPtr});
235239

240+
const auto AwaitSuspendCanThrow =
241+
AwaitSuspendStmtCanThrow(S.getSuspendExpr());
242+
236243
auto SuspendHelper = CodeGenFunction(CGF.CGM).generateAwaitSuspendHelper(
237-
CGF.CurFn->getName(), Prefix, S);
244+
CGF.CurFn->getName(), Prefix, S, AwaitSuspendCanThrow);
238245

239246
llvm::CallBase *SuspendRet = nullptr;
240247

@@ -262,13 +269,12 @@ static LValueOrRValue emitSuspendExpression(CodeGenFunction &CGF, CGCoroData &Co
262269

263270
llvm::Function *AwaitSuspendIntrinsic = CGF.CGM.getIntrinsic(IID);
264271
// FIXME: add call attributes?
265-
if (S.isSuspendNoThrow()) {
266-
SuspendRet = CGF.EmitNounwindRuntimeCall(AwaitSuspendIntrinsic,
267-
SuspendHelperCallArgs);
268-
} else {
272+
if (AwaitSuspendCanThrow)
269273
SuspendRet =
270274
CGF.EmitCallOrInvoke(AwaitSuspendIntrinsic, SuspendHelperCallArgs);
271-
}
275+
else
276+
SuspendRet = CGF.EmitNounwindRuntimeCall(AwaitSuspendIntrinsic,
277+
SuspendHelperCallArgs);
272278

273279
CGF.CurCoro.InSuspendBlock = false;
274280
}
@@ -380,10 +386,9 @@ static QualType getCoroutineSuspendExprReturnType(const ASTContext &Ctx,
380386
}
381387
#endif
382388

383-
llvm::Function *
384-
CodeGenFunction::generateAwaitSuspendHelper(Twine const &CoroName,
385-
Twine const &SuspendPointName,
386-
CoroutineSuspendExpr const &S) {
389+
llvm::Function *CodeGenFunction::generateAwaitSuspendHelper(
390+
Twine const &CoroName, Twine const &SuspendPointName,
391+
CoroutineSuspendExpr const &S, bool CanThrow) {
387392
std::string FuncName = "__await_suspend_helper_";
388393
FuncName += CoroName.str();
389394
FuncName += '_';
@@ -424,7 +429,7 @@ CodeGenFunction::generateAwaitSuspendHelper(Twine const &CoroName,
424429
Fn->setMustProgress();
425430
Fn->addFnAttr(llvm::Attribute::AttrKind::AlwaysInline);
426431

427-
if (S.isSuspendNoThrow()) {
432+
if (!CanThrow) {
428433
Fn->addFnAttr(llvm::Attribute::AttrKind::NoUnwind);
429434
}
430435

clang/lib/CodeGen/CodeGenFunction.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,8 @@ class CodeGenFunction : public CodeGenTypeCache {
352352

353353
llvm::Function *generateAwaitSuspendHelper(Twine const &CoroName,
354354
Twine const &SuspendPointName,
355-
CoroutineSuspendExpr const &S);
355+
CoroutineSuspendExpr const &S,
356+
bool CanThrow);
356357

357358
/// CurGD - The GlobalDecl for the current function being compiled.
358359
GlobalDecl CurGD;

clang/lib/Sema/SemaCoroutine.cpp

Lines changed: 4 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
using namespace clang;
3232
using namespace sema;
3333

34-
static bool isNoThrow(Sema &S, const Stmt *E);
35-
3634
static LookupResult lookupMember(Sema &S, const char *Name, CXXRecordDecl *RD,
3735
SourceLocation Loc, bool &Res) {
3836
DeclarationName DN = S.PP.getIdentifierInfo(Name);
@@ -493,10 +491,6 @@ static ReadySuspendResumeResult buildCoawaitCalls(Sema &S, VarDecl *CoroPromise,
493491
}
494492
}
495493

496-
if (Calls.Results[ACT::ACT_Suspend]) {
497-
Calls.IsSuspendNoThrow = isNoThrow(S, Calls.Results[ACT::ACT_Suspend]);
498-
}
499-
500494
BuildSubExpr(ACT::ACT_Resume, "await_resume", std::nullopt);
501495

502496
// Make sure the awaiter object gets a chance to be cleaned up.
@@ -649,59 +643,6 @@ static FunctionScopeInfo *checkCoroutineContext(Sema &S, SourceLocation Loc,
649643
return ScopeInfo;
650644
}
651645

652-
/// Recursively check \p E and all its children to see if any call target
653-
/// (including constructor call) is declared noexcept. Also any value returned
654-
/// from the call has a noexcept destructor.
655-
static bool isNoThrow(Sema &S, const Stmt *E) {
656-
auto isDeclNoexcept = [&](const Decl *D, bool IsDtor = false) -> bool {
657-
// In the case of dtor, the call to dtor is implicit and hence we should
658-
// pass nullptr to canCalleeThrow.
659-
if (Sema::canCalleeThrow(S, IsDtor ? nullptr : cast<Expr>(E), D)) {
660-
return false;
661-
}
662-
return true;
663-
};
664-
665-
if (auto *CE = dyn_cast<CXXConstructExpr>(E)) {
666-
CXXConstructorDecl *Ctor = CE->getConstructor();
667-
if (!isDeclNoexcept(Ctor)) {
668-
return false;
669-
}
670-
// Check the corresponding destructor of the constructor.
671-
if (!isDeclNoexcept(Ctor->getParent()->getDestructor(), /*IsDtor=*/true)) {
672-
return false;
673-
}
674-
} else if (auto *CE = dyn_cast<CallExpr>(E)) {
675-
if (CE->isTypeDependent())
676-
return false;
677-
678-
if (!isDeclNoexcept(CE->getCalleeDecl())) {
679-
return false;
680-
}
681-
682-
QualType ReturnType = CE->getCallReturnType(S.getASTContext());
683-
// Check the destructor of the call return type, if any.
684-
if (ReturnType.isDestructedType() ==
685-
QualType::DestructionKind::DK_cxx_destructor) {
686-
const auto *T =
687-
cast<RecordType>(ReturnType.getCanonicalType().getTypePtr());
688-
if (!isDeclNoexcept(cast<CXXRecordDecl>(T->getDecl())->getDestructor(),
689-
/*IsDtor=*/true)) {
690-
return false;
691-
}
692-
}
693-
}
694-
for (const auto *Child : E->children()) {
695-
if (!Child)
696-
continue;
697-
if (!isNoThrow(S, Child)) {
698-
return false;
699-
}
700-
}
701-
702-
return true;
703-
}
704-
705646
/// Recursively check \p E and all its children to see if any call target
706647
/// (including constructor call) is declared noexcept. Also any value returned
707648
/// from the call has a noexcept destructor.
@@ -1002,7 +943,7 @@ ExprResult Sema::BuildResolvedCoawaitExpr(SourceLocation Loc, Expr *Operand,
1002943

1003944
Expr *Res = new (Context) CoawaitExpr(
1004945
Loc, Operand, Awaiter, RSS.Results[0], RSS.Results[1], RSS.Results[2],
1005-
RSS.IsSuspendNoThrow, RSS.OpaqueValue, RSS.OpaqueFramePtr, IsImplicit);
946+
RSS.OpaqueValue, RSS.OpaqueFramePtr, IsImplicit);
1006947

1007948
return Res;
1008949
}
@@ -1058,9 +999,9 @@ ExprResult Sema::BuildCoyieldExpr(SourceLocation Loc, Expr *E) {
1058999
if (RSS.IsInvalid)
10591000
return ExprError();
10601001

1061-
Expr *Res = new (Context) CoyieldExpr(
1062-
Loc, Operand, E, RSS.Results[0], RSS.Results[1], RSS.Results[2],
1063-
RSS.IsSuspendNoThrow, RSS.OpaqueValue, RSS.OpaqueFramePtr);
1002+
Expr *Res = new (Context)
1003+
CoyieldExpr(Loc, Operand, E, RSS.Results[0], RSS.Results[1],
1004+
RSS.Results[2], RSS.OpaqueValue, RSS.OpaqueFramePtr);
10641005

10651006
return Res;
10661007
}

0 commit comments

Comments
 (0)