Skip to content

Commit

Permalink
Use FunctionKind instead FunModes
Browse files Browse the repository at this point in the history
  • Loading branch information
foxtran committed Feb 19, 2025
1 parent b92b4bb commit 466da73
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ def err_thread_unsupported : Error<

def warn_falloff_nonvoid : Warning<
"non-void "
"%enum_select<FunModes>{%Function{function}|%Block{block}|%Lambda{lambda}|%Coroutine{coroutine}}0"
"%enum_select<FunctionKind>{%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<
Expand Down
18 changes: 9 additions & 9 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 = 0;
unsigned diag_FallThrough_ReturnsNonVoid = 0;
unsigned diag_NeverFallThroughOrReturn = 0;
unsigned FunMode; // TODO: use diag::FunModes
unsigned FunKind; // TODO: use diag::FunctionKind
SourceLocation FuncLoc;

static CheckFallThroughDiagnostics MakeForFunction(const Decl *Func) {
Expand All @@ -570,45 +570,45 @@ struct CheckFallThroughDiagnostics {
if (!isVirtualMethod && !isTemplateInstantiation)
D.diag_NeverFallThroughOrReturn = diag::warn_suggest_noreturn_function;

D.FunMode = diag::FunModes::Function;
D.FunKind = diag::FunctionKind::Function;
return D;
}

static CheckFallThroughDiagnostics MakeForCoroutine(const Decl *Func) {
CheckFallThroughDiagnostics D;
D.FuncLoc = Func->getLocation();
D.diag_FallThrough_ReturnsNonVoid = diag::warn_falloff_nonvoid;
D.FunMode = diag::FunModes::Coroutine;
D.FunKind = diag::FunctionKind::Coroutine;
return D;
}

static CheckFallThroughDiagnostics MakeForBlock() {
CheckFallThroughDiagnostics D;
D.diag_FallThrough_HasNoReturn = diag::err_noreturn_has_return_expr;
D.diag_FallThrough_ReturnsNonVoid = diag::err_falloff_nonvoid;
D.FunMode = diag::FunModes::Block;
D.FunKind = diag::FunctionKind::Block;
return D;
}

static CheckFallThroughDiagnostics MakeForLambda() {
CheckFallThroughDiagnostics D;
D.diag_FallThrough_HasNoReturn = diag::err_noreturn_has_return_expr;
D.diag_FallThrough_ReturnsNonVoid = diag::warn_falloff_nonvoid;
D.FunMode = diag::FunModes::Lambda;
D.FunKind = diag::FunctionKind::Lambda;
return D;
}

bool checkDiagnostics(DiagnosticsEngine &D, bool ReturnsVoid,
bool HasNoReturn) const {
if (FunMode == diag::FunModes::Function) {
if (FunKind == diag::FunctionKind::Function) {
return (ReturnsVoid ||
D.isIgnored(diag::warn_falloff_nonvoid, FuncLoc)) &&
(!HasNoReturn ||
D.isIgnored(diag::warn_noreturn_has_return_expr, FuncLoc)) &&
(!ReturnsVoid ||
D.isIgnored(diag::warn_suggest_noreturn_block, FuncLoc));
}
if (FunMode == diag::FunModes::Coroutine) {
if (FunKind == diag::FunctionKind::Coroutine) {
return (ReturnsVoid ||
D.isIgnored(diag::warn_falloff_nonvoid, FuncLoc)) &&
(!HasNoReturn);
Expand Down Expand Up @@ -673,11 +673,11 @@ static void CheckFallThroughForBody(Sema &S, const Decl *D, const Stmt *Body,
case AlwaysFallThrough:
if (HasNoReturn) {
if (CD.diag_FallThrough_HasNoReturn)
S.Diag(RBrace, CD.diag_FallThrough_HasNoReturn) << CD.FunMode;
S.Diag(RBrace, CD.diag_FallThrough_HasNoReturn) << CD.FunKind;
} else if (!ReturnsVoid && CD.diag_FallThrough_ReturnsNonVoid) {
bool NotInAllControlPaths = FallThroughType == MaybeFallThrough;
S.Diag(RBrace, CD.diag_FallThrough_ReturnsNonVoid)
<< CD.FunMode << NotInAllControlPaths;
<< CD.FunKind << NotInAllControlPaths;
}
break;
case NeverFallThroughOrReturn:
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 @@ -3591,7 +3591,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)
<< diag::FunModes::Block;
<< diag::FunctionKind::Block;
return StmtError();
}
} else if (auto *CurRegion = dyn_cast<CapturedRegionScopeInfo>(CurCap)) {
Expand All @@ -3603,7 +3603,7 @@ StmtResult Sema::ActOnCapScopeReturnStmt(SourceLocation ReturnLoc,
->castAs<FunctionType>()
->getNoReturnAttr()) {
Diag(ReturnLoc, diag::err_noreturn_has_return_expr)
<< diag::FunModes::Lambda;
<< diag::FunctionKind::Lambda;
return StmtError();
}
}
Expand Down

0 comments on commit 466da73

Please sign in to comment.