Skip to content

Commit 973dde5

Browse files
author
Igor S. Gerasimov
committed
Use enum_select for generating diag::FunModes structure
1 parent 207aa88 commit 973dde5

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,8 +714,9 @@ def err_thread_unsupported : Error<
714714
"thread-local storage is not supported for the current target">;
715715

716716
def warn_falloff_nonvoid : Warning<
717-
"non-void %select{function|block|lambda|coroutine}0 "
718-
"does not return a value%select{| in all control paths}1">,
717+
"non-void "
718+
"%enum_select<FunModes>{%Function{function}|%Block{block}|%Lambda{lambda}|%Coroutine{coroutine}}0"
719+
" does not return a value%select{| in all control paths}1">,
719720
InGroup<ReturnType>;
720721
def err_falloff_nonvoid : Error<
721722
"non-void %select{function|block|lambda|coroutine}0 "

clang/lib/Sema/AnalysisBasedWarnings.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ struct CheckFallThroughDiagnostics {
547547
unsigned diag_FallThrough_HasNoReturn;
548548
unsigned diag_FallThrough_ReturnsNonVoid;
549549
unsigned diag_NeverFallThroughOrReturn;
550-
enum { Function = 0, Block, Lambda, Coroutine } funMode;
550+
unsigned funMode; // TODO: use diag::FunModes
551551
SourceLocation FuncLoc;
552552

553553
static CheckFallThroughDiagnostics MakeForFunction(const Decl *Func) {
@@ -572,7 +572,7 @@ struct CheckFallThroughDiagnostics {
572572
else
573573
D.diag_NeverFallThroughOrReturn = 0;
574574

575-
D.funMode = Function;
575+
D.funMode = diag::FunModes::Function;
576576
return D;
577577
}
578578

@@ -582,7 +582,7 @@ struct CheckFallThroughDiagnostics {
582582
D.diag_FallThrough_HasNoReturn = 0;
583583
D.diag_FallThrough_ReturnsNonVoid = diag::warn_falloff_nonvoid;
584584
D.diag_NeverFallThroughOrReturn = 0;
585-
D.funMode = Coroutine;
585+
D.funMode = diag::FunModes::Coroutine;
586586
return D;
587587
}
588588

@@ -591,7 +591,7 @@ struct CheckFallThroughDiagnostics {
591591
D.diag_FallThrough_HasNoReturn = diag::err_noreturn_has_return_expr;
592592
D.diag_FallThrough_ReturnsNonVoid = diag::err_falloff_nonvoid;
593593
D.diag_NeverFallThroughOrReturn = 0;
594-
D.funMode = Block;
594+
D.funMode = diag::FunModes::Block;
595595
return D;
596596
}
597597

@@ -600,13 +600,13 @@ struct CheckFallThroughDiagnostics {
600600
D.diag_FallThrough_HasNoReturn = diag::err_noreturn_has_return_expr;
601601
D.diag_FallThrough_ReturnsNonVoid = diag::warn_falloff_nonvoid;
602602
D.diag_NeverFallThroughOrReturn = 0;
603-
D.funMode = Lambda;
603+
D.funMode = diag::FunModes::Lambda;
604604
return D;
605605
}
606606

607607
bool checkDiagnostics(DiagnosticsEngine &D, bool ReturnsVoid,
608608
bool HasNoReturn) const {
609-
if (funMode == Function) {
609+
if (funMode == diag::FunModes::Function) {
610610
return (ReturnsVoid ||
611611
D.isIgnored(diag::warn_falloff_nonvoid, FuncLoc)) &&
612612
(!HasNoReturn ||
@@ -615,7 +615,7 @@ struct CheckFallThroughDiagnostics {
615615
(!ReturnsVoid ||
616616
D.isIgnored(diag::warn_suggest_noreturn_block, FuncLoc));
617617
}
618-
if (funMode == Coroutine) {
618+
if (funMode == diag::FunModes::Coroutine) {
619619
return (ReturnsVoid ||
620620
D.isIgnored(diag::warn_falloff_nonvoid, FuncLoc)) &&
621621
(!HasNoReturn);

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_has_return_expr) << 1;
3593+
Diag(ReturnLoc, diag::err_noreturn_has_return_expr) << diag::FunModes::Block;
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_has_return_expr) << 2;
3604+
Diag(ReturnLoc, diag::err_noreturn_has_return_expr) << diag::FunModes::Lambda;
36053605
return StmtError();
36063606
}
36073607
}

0 commit comments

Comments
 (0)