Skip to content

Commit

Permalink
Merge err_noreturn_has_return_expr
Browse files Browse the repository at this point in the history
  • Loading branch information
foxtran committed Feb 18, 2025
1 parent 8743f30 commit 207aa88
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
12 changes: 6 additions & 6 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -8396,8 +8396,6 @@ let CategoryName = "Lambda Issue" in {
"lambda expression in default argument cannot capture any entity">;
def err_lambda_incomplete_result : Error<
"incomplete result type %0 in lambda expression">;
def err_noreturn_lambda_has_return_expr : Error<
"lambda declared 'noreturn' should not return">;
def err_access_lambda_capture : Error<
// The ERRORs represent other special members that aren't constructors, in
// hopes that someone will bother noticing and reporting if they appear
Expand Down Expand Up @@ -10587,11 +10585,13 @@ def err_ctor_dtor_returns_void : Error<
def warn_noreturn_function_has_return_expr : Warning<
"function %0 declared 'noreturn' should not return">,
InGroup<InvalidNoreturn>;
def warn_falloff_noreturn_function : Warning<
"function declared 'noreturn' should not return">,
def warn_noreturn_has_return_expr : Warning<
"%select{function|block|lambda|coroutine}0 "
"declared 'noreturn' should not return">,
InGroup<InvalidNoreturn>;
def err_noreturn_block_has_return_expr : Error<
"block declared 'noreturn' should not return">;
def err_noreturn_has_return_expr : Error<
"%select{function|block|lambda|coroutine}0 "
"declared 'noreturn' should not return">;
def err_carries_dependency_missing_on_first_decl : Error<
"%select{function|parameter}0 declared '[[carries_dependency]]' "
"after its first declaration">;
Expand Down
24 changes: 8 additions & 16 deletions clang/lib/Sema/AnalysisBasedWarnings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ struct CheckFallThroughDiagnostics {
static CheckFallThroughDiagnostics MakeForFunction(const Decl *Func) {
CheckFallThroughDiagnostics D;
D.FuncLoc = Func->getLocation();
D.diag_FallThrough_HasNoReturn = diag::warn_falloff_noreturn_function;
D.diag_FallThrough_HasNoReturn = diag::warn_noreturn_has_return_expr;
D.diag_FallThrough_ReturnsNonVoid = diag::warn_falloff_nonvoid;

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

static CheckFallThroughDiagnostics MakeForBlock() {
CheckFallThroughDiagnostics D;
D.diag_FallThrough_HasNoReturn = diag::err_noreturn_block_has_return_expr;
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;
Expand All @@ -597,7 +597,7 @@ struct CheckFallThroughDiagnostics {

static CheckFallThroughDiagnostics MakeForLambda() {
CheckFallThroughDiagnostics D;
D.diag_FallThrough_HasNoReturn = diag::err_noreturn_lambda_has_return_expr;
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;
Expand All @@ -610,7 +610,7 @@ struct CheckFallThroughDiagnostics {
return (ReturnsVoid ||
D.isIgnored(diag::warn_falloff_nonvoid, FuncLoc)) &&
(!HasNoReturn ||
D.isIgnored(diag::warn_noreturn_function_has_return_expr,
D.isIgnored(diag::warn_noreturn_has_return_expr,
FuncLoc)) &&
(!ReturnsVoid ||
D.isIgnored(diag::warn_suggest_noreturn_block, FuncLoc));
Expand All @@ -634,12 +634,10 @@ struct CheckFallThroughDiagnostics {
static void CheckFallThroughForBody(Sema &S, const Decl *D, const Stmt *Body,
QualType BlockType,
const CheckFallThroughDiagnostics &CD,
AnalysisDeclContext &AC,
sema::FunctionScopeInfo *FSI) {
AnalysisDeclContext &AC) {

bool ReturnsVoid = false;
bool HasNoReturn = false;
bool IsCoroutine = FSI->isCoroutine();

if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
if (const auto *CBody = dyn_cast<CoroutineBodyStmt>(Body))
Expand Down Expand Up @@ -668,12 +666,6 @@ static void CheckFallThroughForBody(Sema &S, const Decl *D, const Stmt *Body,
if (CD.checkDiagnostics(Diags, ReturnsVoid, HasNoReturn))
return;
SourceLocation LBrace = Body->getBeginLoc(), RBrace = Body->getEndLoc();
auto EmitDiag = [&](SourceLocation Loc, unsigned DiagID) {
if (IsCoroutine)
S.Diag(Loc, DiagID) << FSI->CoroutinePromise->getType();
else
S.Diag(Loc, DiagID);
};

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

case MaybeFallThrough:
if (HasNoReturn)
EmitDiag(RBrace, CD.diag_FallThrough_HasNoReturn);
S.Diag(RBrace, CD.diag_FallThrough_HasNoReturn) << CD.funMode;
else if (!ReturnsVoid)
S.Diag(RBrace, CD.diag_FallThrough_ReturnsNonVoid) << CD.funMode << 1;
break;
case AlwaysFallThrough:
if (HasNoReturn)
EmitDiag(RBrace, CD.diag_FallThrough_HasNoReturn);
S.Diag(RBrace, CD.diag_FallThrough_HasNoReturn) << CD.funMode;
else if (!ReturnsVoid)
S.Diag(RBrace, CD.diag_FallThrough_ReturnsNonVoid) << CD.funMode << 0;
break;
Expand Down Expand Up @@ -2735,7 +2727,7 @@ void clang::sema::AnalysisBasedWarnings::IssueWarnings(
: (fscope->isCoroutine()
? CheckFallThroughDiagnostics::MakeForCoroutine(D)
: CheckFallThroughDiagnostics::MakeForFunction(D)));
CheckFallThroughForBody(S, D, Body, BlockType, CD, AC, fscope);
CheckFallThroughForBody(S, D, Body, BlockType, CD, AC);
}

// Warning: check for unreachable code
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_block_has_return_expr);
Diag(ReturnLoc, diag::err_noreturn_has_return_expr) << 1;
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_lambda_has_return_expr);
Diag(ReturnLoc, diag::err_noreturn_has_return_expr) << 2;
return StmtError();
}
}
Expand Down

0 comments on commit 207aa88

Please sign in to comment.