Skip to content

Commit 80f3250

Browse files
author
Igor S. Gerasimov
committed
Merge {Maybe,Always}FallThrough_ReturnsNonVoid into FallThrough_ReturnsNonVoid
1 parent 5ecce45 commit 80f3250

File tree

2 files changed

+21
-50
lines changed

2 files changed

+21
-50
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -713,12 +713,8 @@ def err_thread_non_global : Error<
713713
def err_thread_unsupported : Error<
714714
"thread-local storage is not supported for the current target">;
715715

716-
// FIXME: Combine fallout warnings to just one warning.
717-
def warn_maybe_falloff_nonvoid_function : Warning<
718-
"non-void function does not return a value in all control paths">,
719-
InGroup<ReturnType>;
720716
def warn_falloff_nonvoid_function : Warning<
721-
"non-void function does not return a value">,
717+
"non-void function does not return a value%select{| in all control paths}0">,
722718
InGroup<ReturnType>;
723719
def warn_const_attr_with_pure_attr : Warning<
724720
"'const' attribute imposes more restrictions; 'pure' attribute ignored">,
@@ -727,15 +723,10 @@ def warn_pure_function_returns_void : Warning<
727723
"'%select{pure|const}0' attribute on function returning 'void'; attribute ignored">,
728724
InGroup<IgnoredAttributes>;
729725

730-
def err_maybe_falloff_nonvoid_block : Error<
731-
"non-void block does not return a value in all control paths">;
732726
def err_falloff_nonvoid_block : Error<
733-
"non-void block does not return a value">;
734-
def warn_maybe_falloff_nonvoid_coroutine : Warning<
735-
"non-void coroutine does not return a value in all control paths">,
736-
InGroup<ReturnType>;
727+
"non-void block does not return a value%select{| in all control paths}0">;
737728
def warn_falloff_nonvoid_coroutine : Warning<
738-
"non-void coroutine does not return a value">,
729+
"non-void coroutine does not return a value%select{| in all control paths}0">,
739730
InGroup<ReturnType>;
740731
def warn_suggest_noreturn_function : Warning<
741732
"%select{function|method}0 %1 could be declared with attribute 'noreturn'">,
@@ -8408,11 +8399,8 @@ let CategoryName = "Lambda Issue" in {
84088399
"incomplete result type %0 in lambda expression">;
84098400
def err_noreturn_lambda_has_return_expr : Error<
84108401
"lambda declared 'noreturn' should not return">;
8411-
def warn_maybe_falloff_nonvoid_lambda : Warning<
8412-
"non-void lambda does not return a value in all control paths">,
8413-
InGroup<ReturnType>;
84148402
def warn_falloff_nonvoid_lambda : Warning<
8415-
"non-void lambda does not return a value">,
8403+
"non-void lambda does not return a value%select{| in all control paths}0">,
84168404
InGroup<ReturnType>;
84178405
def err_access_lambda_capture : Error<
84188406
// The ERRORs represent other special members that aren't constructors, in

clang/lib/Sema/AnalysisBasedWarnings.cpp

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -544,24 +544,18 @@ static ControlFlowKind CheckFallThrough(AnalysisDeclContext &AC) {
544544
namespace {
545545

546546
struct CheckFallThroughDiagnostics {
547-
unsigned diag_MaybeFallThrough_HasNoReturn;
548-
unsigned diag_MaybeFallThrough_ReturnsNonVoid;
549-
unsigned diag_AlwaysFallThrough_HasNoReturn;
550-
unsigned diag_AlwaysFallThrough_ReturnsNonVoid;
547+
unsigned diag_FallThrough_HasNoReturn;
548+
unsigned diag_FallThrough_ReturnsNonVoid;
551549
unsigned diag_NeverFallThroughOrReturn;
552550
enum { Function, Block, Lambda, Coroutine } funMode;
553551
SourceLocation FuncLoc;
554552

555553
static CheckFallThroughDiagnostics MakeForFunction(const Decl *Func) {
556554
CheckFallThroughDiagnostics D;
557555
D.FuncLoc = Func->getLocation();
558-
D.diag_MaybeFallThrough_HasNoReturn =
556+
D.diag_FallThrough_HasNoReturn =
559557
diag::warn_falloff_noreturn_function;
560-
D.diag_MaybeFallThrough_ReturnsNonVoid =
561-
diag::warn_maybe_falloff_nonvoid_function;
562-
D.diag_AlwaysFallThrough_HasNoReturn =
563-
diag::warn_falloff_noreturn_function;
564-
D.diag_AlwaysFallThrough_ReturnsNonVoid =
558+
D.diag_FallThrough_ReturnsNonVoid =
565559
diag::warn_falloff_nonvoid_function;
566560

567561
// Don't suggest that virtual functions be marked "noreturn", since they
@@ -588,11 +582,8 @@ struct CheckFallThroughDiagnostics {
588582
static CheckFallThroughDiagnostics MakeForCoroutine(const Decl *Func) {
589583
CheckFallThroughDiagnostics D;
590584
D.FuncLoc = Func->getLocation();
591-
D.diag_MaybeFallThrough_HasNoReturn = 0;
592-
D.diag_MaybeFallThrough_ReturnsNonVoid =
593-
diag::warn_maybe_falloff_nonvoid_coroutine;
594-
D.diag_AlwaysFallThrough_HasNoReturn = 0;
595-
D.diag_AlwaysFallThrough_ReturnsNonVoid =
585+
D.diag_FallThrough_HasNoReturn = 0;
586+
D.diag_FallThrough_ReturnsNonVoid =
596587
diag::warn_falloff_nonvoid_coroutine;
597588
D.diag_NeverFallThroughOrReturn = 0;
598589
D.funMode = Coroutine;
@@ -601,13 +592,9 @@ struct CheckFallThroughDiagnostics {
601592

602593
static CheckFallThroughDiagnostics MakeForBlock() {
603594
CheckFallThroughDiagnostics D;
604-
D.diag_MaybeFallThrough_HasNoReturn =
605-
diag::err_noreturn_block_has_return_expr;
606-
D.diag_MaybeFallThrough_ReturnsNonVoid =
607-
diag::err_maybe_falloff_nonvoid_block;
608-
D.diag_AlwaysFallThrough_HasNoReturn =
595+
D.diag_FallThrough_HasNoReturn =
609596
diag::err_noreturn_block_has_return_expr;
610-
D.diag_AlwaysFallThrough_ReturnsNonVoid =
597+
D.diag_FallThrough_ReturnsNonVoid =
611598
diag::err_falloff_nonvoid_block;
612599
D.diag_NeverFallThroughOrReturn = 0;
613600
D.funMode = Block;
@@ -616,13 +603,9 @@ struct CheckFallThroughDiagnostics {
616603

617604
static CheckFallThroughDiagnostics MakeForLambda() {
618605
CheckFallThroughDiagnostics D;
619-
D.diag_MaybeFallThrough_HasNoReturn =
620-
diag::err_noreturn_lambda_has_return_expr;
621-
D.diag_MaybeFallThrough_ReturnsNonVoid =
622-
diag::warn_maybe_falloff_nonvoid_lambda;
623-
D.diag_AlwaysFallThrough_HasNoReturn =
606+
D.diag_FallThrough_HasNoReturn =
624607
diag::err_noreturn_lambda_has_return_expr;
625-
D.diag_AlwaysFallThrough_ReturnsNonVoid =
608+
D.diag_FallThrough_ReturnsNonVoid =
626609
diag::warn_falloff_nonvoid_lambda;
627610
D.diag_NeverFallThroughOrReturn = 0;
628611
D.funMode = Lambda;
@@ -633,7 +616,7 @@ struct CheckFallThroughDiagnostics {
633616
bool HasNoReturn) const {
634617
if (funMode == Function) {
635618
return (ReturnsVoid ||
636-
D.isIgnored(diag::warn_maybe_falloff_nonvoid_function,
619+
D.isIgnored(diag::warn_falloff_nonvoid_function,
637620
FuncLoc)) &&
638621
(!HasNoReturn ||
639622
D.isIgnored(diag::warn_noreturn_function_has_return_expr,
@@ -643,8 +626,8 @@ struct CheckFallThroughDiagnostics {
643626
}
644627
if (funMode == Coroutine) {
645628
return (ReturnsVoid ||
646-
D.isIgnored(diag::warn_maybe_falloff_nonvoid_function, FuncLoc) ||
647-
D.isIgnored(diag::warn_maybe_falloff_nonvoid_coroutine,
629+
D.isIgnored(diag::warn_falloff_nonvoid_function, FuncLoc) ||
630+
D.isIgnored(diag::warn_falloff_nonvoid_coroutine,
648631
FuncLoc)) &&
649632
(!HasNoReturn);
650633
}
@@ -714,15 +697,15 @@ static void CheckFallThroughForBody(Sema &S, const Decl *D, const Stmt *Body,
714697

715698
case MaybeFallThrough:
716699
if (HasNoReturn)
717-
EmitDiag(RBrace, CD.diag_MaybeFallThrough_HasNoReturn);
700+
EmitDiag(RBrace, CD.diag_FallThrough_HasNoReturn);
718701
else if (!ReturnsVoid)
719-
EmitDiag(RBrace, CD.diag_MaybeFallThrough_ReturnsNonVoid);
702+
S.Diag(RBrace, CD.diag_FallThrough_ReturnsNonVoid) << 1;
720703
break;
721704
case AlwaysFallThrough:
722705
if (HasNoReturn)
723-
EmitDiag(RBrace, CD.diag_AlwaysFallThrough_HasNoReturn);
706+
EmitDiag(RBrace, CD.diag_FallThrough_HasNoReturn);
724707
else if (!ReturnsVoid)
725-
EmitDiag(RBrace, CD.diag_AlwaysFallThrough_ReturnsNonVoid);
708+
S.Diag(RBrace, CD.diag_FallThrough_ReturnsNonVoid) << 0;
726709
break;
727710
case NeverFallThroughOrReturn:
728711
if (ReturnsVoid && !HasNoReturn && CD.diag_NeverFallThroughOrReturn) {

0 commit comments

Comments
 (0)