Skip to content

Commit 207aa88

Browse files
author
Igor S. Gerasimov
committed
Merge err_noreturn_has_return_expr
1 parent 8743f30 commit 207aa88

File tree

3 files changed

+16
-24
lines changed

3 files changed

+16
-24
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8396,8 +8396,6 @@ let CategoryName = "Lambda Issue" in {
83968396
"lambda expression in default argument cannot capture any entity">;
83978397
def err_lambda_incomplete_result : Error<
83988398
"incomplete result type %0 in lambda expression">;
8399-
def err_noreturn_lambda_has_return_expr : Error<
8400-
"lambda declared 'noreturn' should not return">;
84018399
def err_access_lambda_capture : Error<
84028400
// The ERRORs represent other special members that aren't constructors, in
84038401
// hopes that someone will bother noticing and reporting if they appear
@@ -10587,11 +10585,13 @@ def err_ctor_dtor_returns_void : Error<
1058710585
def warn_noreturn_function_has_return_expr : Warning<
1058810586
"function %0 declared 'noreturn' should not return">,
1058910587
InGroup<InvalidNoreturn>;
10590-
def warn_falloff_noreturn_function : Warning<
10591-
"function declared 'noreturn' should not return">,
10588+
def warn_noreturn_has_return_expr : Warning<
10589+
"%select{function|block|lambda|coroutine}0 "
10590+
"declared 'noreturn' should not return">,
1059210591
InGroup<InvalidNoreturn>;
10593-
def err_noreturn_block_has_return_expr : Error<
10594-
"block declared 'noreturn' should not return">;
10592+
def err_noreturn_has_return_expr : Error<
10593+
"%select{function|block|lambda|coroutine}0 "
10594+
"declared 'noreturn' should not return">;
1059510595
def err_carries_dependency_missing_on_first_decl : Error<
1059610596
"%select{function|parameter}0 declared '[[carries_dependency]]' "
1059710597
"after its first declaration">;

clang/lib/Sema/AnalysisBasedWarnings.cpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ struct CheckFallThroughDiagnostics {
553553
static CheckFallThroughDiagnostics MakeForFunction(const Decl *Func) {
554554
CheckFallThroughDiagnostics D;
555555
D.FuncLoc = Func->getLocation();
556-
D.diag_FallThrough_HasNoReturn = diag::warn_falloff_noreturn_function;
556+
D.diag_FallThrough_HasNoReturn = diag::warn_noreturn_has_return_expr;
557557
D.diag_FallThrough_ReturnsNonVoid = diag::warn_falloff_nonvoid;
558558

559559
// Don't suggest that virtual functions be marked "noreturn", since they
@@ -588,7 +588,7 @@ struct CheckFallThroughDiagnostics {
588588

589589
static CheckFallThroughDiagnostics MakeForBlock() {
590590
CheckFallThroughDiagnostics D;
591-
D.diag_FallThrough_HasNoReturn = diag::err_noreturn_block_has_return_expr;
591+
D.diag_FallThrough_HasNoReturn = diag::err_noreturn_has_return_expr;
592592
D.diag_FallThrough_ReturnsNonVoid = diag::err_falloff_nonvoid;
593593
D.diag_NeverFallThroughOrReturn = 0;
594594
D.funMode = Block;
@@ -597,7 +597,7 @@ struct CheckFallThroughDiagnostics {
597597

598598
static CheckFallThroughDiagnostics MakeForLambda() {
599599
CheckFallThroughDiagnostics D;
600-
D.diag_FallThrough_HasNoReturn = diag::err_noreturn_lambda_has_return_expr;
600+
D.diag_FallThrough_HasNoReturn = diag::err_noreturn_has_return_expr;
601601
D.diag_FallThrough_ReturnsNonVoid = diag::warn_falloff_nonvoid;
602602
D.diag_NeverFallThroughOrReturn = 0;
603603
D.funMode = Lambda;
@@ -610,7 +610,7 @@ struct CheckFallThroughDiagnostics {
610610
return (ReturnsVoid ||
611611
D.isIgnored(diag::warn_falloff_nonvoid, FuncLoc)) &&
612612
(!HasNoReturn ||
613-
D.isIgnored(diag::warn_noreturn_function_has_return_expr,
613+
D.isIgnored(diag::warn_noreturn_has_return_expr,
614614
FuncLoc)) &&
615615
(!ReturnsVoid ||
616616
D.isIgnored(diag::warn_suggest_noreturn_block, FuncLoc));
@@ -634,12 +634,10 @@ struct CheckFallThroughDiagnostics {
634634
static void CheckFallThroughForBody(Sema &S, const Decl *D, const Stmt *Body,
635635
QualType BlockType,
636636
const CheckFallThroughDiagnostics &CD,
637-
AnalysisDeclContext &AC,
638-
sema::FunctionScopeInfo *FSI) {
637+
AnalysisDeclContext &AC) {
639638

640639
bool ReturnsVoid = false;
641640
bool HasNoReturn = false;
642-
bool IsCoroutine = FSI->isCoroutine();
643641

644642
if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
645643
if (const auto *CBody = dyn_cast<CoroutineBodyStmt>(Body))
@@ -668,12 +666,6 @@ static void CheckFallThroughForBody(Sema &S, const Decl *D, const Stmt *Body,
668666
if (CD.checkDiagnostics(Diags, ReturnsVoid, HasNoReturn))
669667
return;
670668
SourceLocation LBrace = Body->getBeginLoc(), RBrace = Body->getEndLoc();
671-
auto EmitDiag = [&](SourceLocation Loc, unsigned DiagID) {
672-
if (IsCoroutine)
673-
S.Diag(Loc, DiagID) << FSI->CoroutinePromise->getType();
674-
else
675-
S.Diag(Loc, DiagID);
676-
};
677669

678670
// cpu_dispatch functions permit empty function bodies for ICC compatibility.
679671
if (D->getAsFunction() && D->getAsFunction()->isCPUDispatchMultiVersion())
@@ -686,13 +678,13 @@ static void CheckFallThroughForBody(Sema &S, const Decl *D, const Stmt *Body,
686678

687679
case MaybeFallThrough:
688680
if (HasNoReturn)
689-
EmitDiag(RBrace, CD.diag_FallThrough_HasNoReturn);
681+
S.Diag(RBrace, CD.diag_FallThrough_HasNoReturn) << CD.funMode;
690682
else if (!ReturnsVoid)
691683
S.Diag(RBrace, CD.diag_FallThrough_ReturnsNonVoid) << CD.funMode << 1;
692684
break;
693685
case AlwaysFallThrough:
694686
if (HasNoReturn)
695-
EmitDiag(RBrace, CD.diag_FallThrough_HasNoReturn);
687+
S.Diag(RBrace, CD.diag_FallThrough_HasNoReturn) << CD.funMode;
696688
else if (!ReturnsVoid)
697689
S.Diag(RBrace, CD.diag_FallThrough_ReturnsNonVoid) << CD.funMode << 0;
698690
break;
@@ -2735,7 +2727,7 @@ void clang::sema::AnalysisBasedWarnings::IssueWarnings(
27352727
: (fscope->isCoroutine()
27362728
? CheckFallThroughDiagnostics::MakeForCoroutine(D)
27372729
: CheckFallThroughDiagnostics::MakeForFunction(D)));
2738-
CheckFallThroughForBody(S, D, Body, BlockType, CD, AC, fscope);
2730+
CheckFallThroughForBody(S, D, Body, BlockType, CD, AC);
27392731
}
27402732

27412733
// Warning: check for unreachable code

clang/lib/Sema/SemaStmt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3590,7 +3590,7 @@ StmtResult Sema::ActOnCapScopeReturnStmt(SourceLocation ReturnLoc,
35903590

35913591
if (auto *CurBlock = dyn_cast<BlockScopeInfo>(CurCap)) {
35923592
if (CurBlock->FunctionType->castAs<FunctionType>()->getNoReturnAttr()) {
3593-
Diag(ReturnLoc, diag::err_noreturn_block_has_return_expr);
3593+
Diag(ReturnLoc, diag::err_noreturn_has_return_expr) << 1;
35943594
return StmtError();
35953595
}
35963596
} else if (auto *CurRegion = dyn_cast<CapturedRegionScopeInfo>(CurCap)) {
@@ -3601,7 +3601,7 @@ StmtResult Sema::ActOnCapScopeReturnStmt(SourceLocation ReturnLoc,
36013601
if (CurLambda->CallOperator->getType()
36023602
->castAs<FunctionType>()
36033603
->getNoReturnAttr()) {
3604-
Diag(ReturnLoc, diag::err_noreturn_lambda_has_return_expr);
3604+
Diag(ReturnLoc, diag::err_noreturn_has_return_expr) << 2;
36053605
return StmtError();
36063606
}
36073607
}

0 commit comments

Comments
 (0)