Skip to content

Commit

Permalink
Use enum_select for generating diag::FunModes structure
Browse files Browse the repository at this point in the history
  • Loading branch information
foxtran committed Feb 18, 2025
1 parent 207aa88 commit 973dde5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
5 changes: 3 additions & 2 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -714,8 +714,9 @@ def err_thread_unsupported : Error<
"thread-local storage is not supported for the current target">;

def warn_falloff_nonvoid : Warning<
"non-void %select{function|block|lambda|coroutine}0 "
"does not return a value%select{| in all control paths}1">,
"non-void "
"%enum_select<FunModes>{%Function{function}|%Block{block}|%Lambda{lambda}|%Coroutine{coroutine}}0"
" does not return a value%select{| in all control paths}1">,
InGroup<ReturnType>;
def err_falloff_nonvoid : Error<
"non-void %select{function|block|lambda|coroutine}0 "
Expand Down
14 changes: 7 additions & 7 deletions clang/lib/Sema/AnalysisBasedWarnings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ struct CheckFallThroughDiagnostics {
unsigned diag_FallThrough_HasNoReturn;
unsigned diag_FallThrough_ReturnsNonVoid;
unsigned diag_NeverFallThroughOrReturn;
enum { Function = 0, Block, Lambda, Coroutine } funMode;
unsigned funMode; // TODO: use diag::FunModes
SourceLocation FuncLoc;

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

D.funMode = Function;
D.funMode = diag::FunModes::Function;
return D;
}

Expand All @@ -582,7 +582,7 @@ struct CheckFallThroughDiagnostics {
D.diag_FallThrough_HasNoReturn = 0;
D.diag_FallThrough_ReturnsNonVoid = diag::warn_falloff_nonvoid;
D.diag_NeverFallThroughOrReturn = 0;
D.funMode = Coroutine;
D.funMode = diag::FunModes::Coroutine;
return D;
}

Expand All @@ -591,7 +591,7 @@ struct CheckFallThroughDiagnostics {
D.diag_FallThrough_HasNoReturn = diag::err_noreturn_has_return_expr;
D.diag_FallThrough_ReturnsNonVoid = diag::err_falloff_nonvoid;
D.diag_NeverFallThroughOrReturn = 0;
D.funMode = Block;
D.funMode = diag::FunModes::Block;
return D;
}

Expand All @@ -600,13 +600,13 @@ struct CheckFallThroughDiagnostics {
D.diag_FallThrough_HasNoReturn = diag::err_noreturn_has_return_expr;
D.diag_FallThrough_ReturnsNonVoid = diag::warn_falloff_nonvoid;
D.diag_NeverFallThroughOrReturn = 0;
D.funMode = Lambda;
D.funMode = diag::FunModes::Lambda;
return D;
}

bool checkDiagnostics(DiagnosticsEngine &D, bool ReturnsVoid,
bool HasNoReturn) const {
if (funMode == Function) {
if (funMode == diag::FunModes::Function) {
return (ReturnsVoid ||
D.isIgnored(diag::warn_falloff_nonvoid, FuncLoc)) &&
(!HasNoReturn ||
Expand All @@ -615,7 +615,7 @@ struct CheckFallThroughDiagnostics {
(!ReturnsVoid ||
D.isIgnored(diag::warn_suggest_noreturn_block, FuncLoc));
}
if (funMode == Coroutine) {
if (funMode == diag::FunModes::Coroutine) {
return (ReturnsVoid ||
D.isIgnored(diag::warn_falloff_nonvoid, FuncLoc)) &&
(!HasNoReturn);
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Sema/SemaStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3590,7 +3590,7 @@ StmtResult Sema::ActOnCapScopeReturnStmt(SourceLocation ReturnLoc,

if (auto *CurBlock = dyn_cast<BlockScopeInfo>(CurCap)) {
if (CurBlock->FunctionType->castAs<FunctionType>()->getNoReturnAttr()) {
Diag(ReturnLoc, diag::err_noreturn_has_return_expr) << 1;
Diag(ReturnLoc, diag::err_noreturn_has_return_expr) << diag::FunModes::Block;
return StmtError();
}
} else if (auto *CurRegion = dyn_cast<CapturedRegionScopeInfo>(CurCap)) {
Expand All @@ -3601,7 +3601,7 @@ StmtResult Sema::ActOnCapScopeReturnStmt(SourceLocation ReturnLoc,
if (CurLambda->CallOperator->getType()
->castAs<FunctionType>()
->getNoReturnAttr()) {
Diag(ReturnLoc, diag::err_noreturn_has_return_expr) << 2;
Diag(ReturnLoc, diag::err_noreturn_has_return_expr) << diag::FunModes::Lambda;
return StmtError();
}
}
Expand Down

0 comments on commit 973dde5

Please sign in to comment.