[clang] [clang][Sema] Combine fallout warnings to just one warning (PR #127546)

via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 17 14:39:41 PST 2025


https://github.com/foxtran created https://github.com/llvm/llvm-project/pull/127546

This PR fixes `FIXME: Combine fallout warnings to just one warning.` at `DiagnosticssSemaKinds.td`.

Changes:
- `warn_maybe_falloff_nonvoid_function` and `warn_falloff_nonvoid_function`, `warn_maybe_falloff_nonvoid_block` and `warn_falloff_nonvoid_block`, `warn_maybe_falloff_nonvoid_coroutine` and `warn_falloff_nonvoid_coroutine`, `warn_maybe_falloff_nonvoid_lambda` and `warn_falloff_nonvoid_lambda` were combined into `warn_falloff_nonvoid`,
- `err_maybe_falloff_nonvoid_block` and `err_falloff_nonvoid_block` were combined into `err_falloff_nonvoid`.

It looks like current tests does not check these cases properly.

>From fbdd55feb53bfbcc07af39dc9fa1bf77311f5e45 Mon Sep 17 00:00:00 2001
From: "Igor S. Gerasimov" <i.s.ger at ya.ru>
Date: Mon, 17 Feb 2025 22:39:31 +0100
Subject: [PATCH 1/4] Merge {Maybe,Always}FallThrough_ReturnsNonVoid into
 FallThrough_ReturnsNonVoid

---
 .../clang/Basic/DiagnosticSemaKinds.td        | 20 ++------
 clang/lib/Sema/AnalysisBasedWarnings.cpp      | 51 +++++++------------
 2 files changed, 21 insertions(+), 50 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index f10af8f5bd6b2..ff00c76c5e492 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -713,12 +713,8 @@ def err_thread_non_global : Error<
 def err_thread_unsupported : Error<
   "thread-local storage is not supported for the current target">;
 
-// FIXME: Combine fallout warnings to just one warning.
-def warn_maybe_falloff_nonvoid_function : Warning<
-  "non-void function does not return a value in all control paths">,
-  InGroup<ReturnType>;
 def warn_falloff_nonvoid_function : Warning<
-  "non-void function does not return a value">,
+  "non-void function does not return a value%select{| in all control paths}0">,
   InGroup<ReturnType>;
 def warn_const_attr_with_pure_attr : Warning<
   "'const' attribute imposes more restrictions; 'pure' attribute ignored">,
@@ -727,15 +723,10 @@ def warn_pure_function_returns_void : Warning<
   "'%select{pure|const}0' attribute on function returning 'void'; attribute ignored">,
   InGroup<IgnoredAttributes>;
 
-def err_maybe_falloff_nonvoid_block : Error<
-  "non-void block does not return a value in all control paths">;
 def err_falloff_nonvoid_block : Error<
-  "non-void block does not return a value">;
-def warn_maybe_falloff_nonvoid_coroutine : Warning<
-  "non-void coroutine does not return a value in all control paths">,
-  InGroup<ReturnType>;
+  "non-void block does not return a value%select{| in all control paths}0">;
 def warn_falloff_nonvoid_coroutine : Warning<
-  "non-void coroutine does not return a value">,
+  "non-void coroutine does not return a value%select{| in all control paths}0">,
   InGroup<ReturnType>;
 def warn_suggest_noreturn_function : Warning<
   "%select{function|method}0 %1 could be declared with attribute 'noreturn'">,
@@ -8408,11 +8399,8 @@ let CategoryName = "Lambda Issue" in {
     "incomplete result type %0 in lambda expression">;
   def err_noreturn_lambda_has_return_expr : Error<
     "lambda declared 'noreturn' should not return">;
-  def warn_maybe_falloff_nonvoid_lambda : Warning<
-    "non-void lambda does not return a value in all control paths">,
-    InGroup<ReturnType>;
   def warn_falloff_nonvoid_lambda : Warning<
-    "non-void lambda does not return a value">,
+    "non-void lambda does not return a value%select{| in all control paths}0">,
     InGroup<ReturnType>;
   def err_access_lambda_capture : Error<
     // The ERRORs represent other special members that aren't constructors, in
diff --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp b/clang/lib/Sema/AnalysisBasedWarnings.cpp
index 589869d018657..7b28781ede0ca 100644
--- a/clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -544,10 +544,8 @@ static ControlFlowKind CheckFallThrough(AnalysisDeclContext &AC) {
 namespace {
 
 struct CheckFallThroughDiagnostics {
-  unsigned diag_MaybeFallThrough_HasNoReturn;
-  unsigned diag_MaybeFallThrough_ReturnsNonVoid;
-  unsigned diag_AlwaysFallThrough_HasNoReturn;
-  unsigned diag_AlwaysFallThrough_ReturnsNonVoid;
+  unsigned diag_FallThrough_HasNoReturn;
+  unsigned diag_FallThrough_ReturnsNonVoid;
   unsigned diag_NeverFallThroughOrReturn;
   enum { Function, Block, Lambda, Coroutine } funMode;
   SourceLocation FuncLoc;
@@ -555,13 +553,9 @@ struct CheckFallThroughDiagnostics {
   static CheckFallThroughDiagnostics MakeForFunction(const Decl *Func) {
     CheckFallThroughDiagnostics D;
     D.FuncLoc = Func->getLocation();
-    D.diag_MaybeFallThrough_HasNoReturn =
+    D.diag_FallThrough_HasNoReturn =
       diag::warn_falloff_noreturn_function;
-    D.diag_MaybeFallThrough_ReturnsNonVoid =
-      diag::warn_maybe_falloff_nonvoid_function;
-    D.diag_AlwaysFallThrough_HasNoReturn =
-      diag::warn_falloff_noreturn_function;
-    D.diag_AlwaysFallThrough_ReturnsNonVoid =
+    D.diag_FallThrough_ReturnsNonVoid =
       diag::warn_falloff_nonvoid_function;
 
     // Don't suggest that virtual functions be marked "noreturn", since they
@@ -588,11 +582,8 @@ struct CheckFallThroughDiagnostics {
   static CheckFallThroughDiagnostics MakeForCoroutine(const Decl *Func) {
     CheckFallThroughDiagnostics D;
     D.FuncLoc = Func->getLocation();
-    D.diag_MaybeFallThrough_HasNoReturn = 0;
-    D.diag_MaybeFallThrough_ReturnsNonVoid =
-        diag::warn_maybe_falloff_nonvoid_coroutine;
-    D.diag_AlwaysFallThrough_HasNoReturn = 0;
-    D.diag_AlwaysFallThrough_ReturnsNonVoid =
+    D.diag_FallThrough_HasNoReturn = 0;
+    D.diag_FallThrough_ReturnsNonVoid =
         diag::warn_falloff_nonvoid_coroutine;
     D.diag_NeverFallThroughOrReturn = 0;
     D.funMode = Coroutine;
@@ -601,13 +592,9 @@ struct CheckFallThroughDiagnostics {
 
   static CheckFallThroughDiagnostics MakeForBlock() {
     CheckFallThroughDiagnostics D;
-    D.diag_MaybeFallThrough_HasNoReturn =
-      diag::err_noreturn_block_has_return_expr;
-    D.diag_MaybeFallThrough_ReturnsNonVoid =
-      diag::err_maybe_falloff_nonvoid_block;
-    D.diag_AlwaysFallThrough_HasNoReturn =
+    D.diag_FallThrough_HasNoReturn =
       diag::err_noreturn_block_has_return_expr;
-    D.diag_AlwaysFallThrough_ReturnsNonVoid =
+    D.diag_FallThrough_ReturnsNonVoid =
       diag::err_falloff_nonvoid_block;
     D.diag_NeverFallThroughOrReturn = 0;
     D.funMode = Block;
@@ -616,13 +603,9 @@ struct CheckFallThroughDiagnostics {
 
   static CheckFallThroughDiagnostics MakeForLambda() {
     CheckFallThroughDiagnostics D;
-    D.diag_MaybeFallThrough_HasNoReturn =
-      diag::err_noreturn_lambda_has_return_expr;
-    D.diag_MaybeFallThrough_ReturnsNonVoid =
-      diag::warn_maybe_falloff_nonvoid_lambda;
-    D.diag_AlwaysFallThrough_HasNoReturn =
+    D.diag_FallThrough_HasNoReturn =
       diag::err_noreturn_lambda_has_return_expr;
-    D.diag_AlwaysFallThrough_ReturnsNonVoid =
+    D.diag_FallThrough_ReturnsNonVoid =
       diag::warn_falloff_nonvoid_lambda;
     D.diag_NeverFallThroughOrReturn = 0;
     D.funMode = Lambda;
@@ -633,7 +616,7 @@ struct CheckFallThroughDiagnostics {
                         bool HasNoReturn) const {
     if (funMode == Function) {
       return (ReturnsVoid ||
-              D.isIgnored(diag::warn_maybe_falloff_nonvoid_function,
+              D.isIgnored(diag::warn_falloff_nonvoid_function,
                           FuncLoc)) &&
              (!HasNoReturn ||
               D.isIgnored(diag::warn_noreturn_function_has_return_expr,
@@ -643,8 +626,8 @@ struct CheckFallThroughDiagnostics {
     }
     if (funMode == Coroutine) {
       return (ReturnsVoid ||
-              D.isIgnored(diag::warn_maybe_falloff_nonvoid_function, FuncLoc) ||
-              D.isIgnored(diag::warn_maybe_falloff_nonvoid_coroutine,
+              D.isIgnored(diag::warn_falloff_nonvoid_function, FuncLoc) ||
+              D.isIgnored(diag::warn_falloff_nonvoid_coroutine,
                           FuncLoc)) &&
              (!HasNoReturn);
     }
@@ -714,15 +697,15 @@ static void CheckFallThroughForBody(Sema &S, const Decl *D, const Stmt *Body,
 
     case MaybeFallThrough:
       if (HasNoReturn)
-        EmitDiag(RBrace, CD.diag_MaybeFallThrough_HasNoReturn);
+        EmitDiag(RBrace, CD.diag_FallThrough_HasNoReturn);
       else if (!ReturnsVoid)
-        EmitDiag(RBrace, CD.diag_MaybeFallThrough_ReturnsNonVoid);
+        S.Diag(RBrace, CD.diag_FallThrough_ReturnsNonVoid) << 1;
       break;
     case AlwaysFallThrough:
       if (HasNoReturn)
-        EmitDiag(RBrace, CD.diag_AlwaysFallThrough_HasNoReturn);
+        EmitDiag(RBrace, CD.diag_FallThrough_HasNoReturn);
       else if (!ReturnsVoid)
-        EmitDiag(RBrace, CD.diag_AlwaysFallThrough_ReturnsNonVoid);
+        S.Diag(RBrace, CD.diag_FallThrough_ReturnsNonVoid) << 0;
       break;
     case NeverFallThroughOrReturn:
       if (ReturnsVoid && !HasNoReturn && CD.diag_NeverFallThroughOrReturn) {

>From 19a1884343699e8122f4e58b7ce6c63cc83731f3 Mon Sep 17 00:00:00 2001
From: "Igor S. Gerasimov" <i.s.ger at ya.ru>
Date: Mon, 17 Feb 2025 22:41:29 +0100
Subject: [PATCH 2/4] Format source code

---
 clang/lib/Sema/AnalysisBasedWarnings.cpp | 82 +++++++++++-------------
 1 file changed, 36 insertions(+), 46 deletions(-)

diff --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp b/clang/lib/Sema/AnalysisBasedWarnings.cpp
index 7b28781ede0ca..da44ff6f08ff7 100644
--- a/clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -553,10 +553,8 @@ 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_ReturnsNonVoid =
-      diag::warn_falloff_nonvoid_function;
+    D.diag_FallThrough_HasNoReturn = diag::warn_falloff_noreturn_function;
+    D.diag_FallThrough_ReturnsNonVoid = diag::warn_falloff_nonvoid_function;
 
     // Don't suggest that virtual functions be marked "noreturn", since they
     // might be overridden by non-noreturn functions.
@@ -570,8 +568,7 @@ struct CheckFallThroughDiagnostics {
       isTemplateInstantiation = Function->isTemplateInstantiation();
 
     if (!isVirtualMethod && !isTemplateInstantiation)
-      D.diag_NeverFallThroughOrReturn =
-        diag::warn_suggest_noreturn_function;
+      D.diag_NeverFallThroughOrReturn = diag::warn_suggest_noreturn_function;
     else
       D.diag_NeverFallThroughOrReturn = 0;
 
@@ -583,8 +580,7 @@ struct CheckFallThroughDiagnostics {
     CheckFallThroughDiagnostics D;
     D.FuncLoc = Func->getLocation();
     D.diag_FallThrough_HasNoReturn = 0;
-    D.diag_FallThrough_ReturnsNonVoid =
-        diag::warn_falloff_nonvoid_coroutine;
+    D.diag_FallThrough_ReturnsNonVoid = diag::warn_falloff_nonvoid_coroutine;
     D.diag_NeverFallThroughOrReturn = 0;
     D.funMode = Coroutine;
     return D;
@@ -592,10 +588,8 @@ struct CheckFallThroughDiagnostics {
 
   static CheckFallThroughDiagnostics MakeForBlock() {
     CheckFallThroughDiagnostics D;
-    D.diag_FallThrough_HasNoReturn =
-      diag::err_noreturn_block_has_return_expr;
-    D.diag_FallThrough_ReturnsNonVoid =
-      diag::err_falloff_nonvoid_block;
+    D.diag_FallThrough_HasNoReturn = diag::err_noreturn_block_has_return_expr;
+    D.diag_FallThrough_ReturnsNonVoid = diag::err_falloff_nonvoid_block;
     D.diag_NeverFallThroughOrReturn = 0;
     D.funMode = Block;
     return D;
@@ -603,10 +597,8 @@ struct CheckFallThroughDiagnostics {
 
   static CheckFallThroughDiagnostics MakeForLambda() {
     CheckFallThroughDiagnostics D;
-    D.diag_FallThrough_HasNoReturn =
-      diag::err_noreturn_lambda_has_return_expr;
-    D.diag_FallThrough_ReturnsNonVoid =
-      diag::warn_falloff_nonvoid_lambda;
+    D.diag_FallThrough_HasNoReturn = diag::err_noreturn_lambda_has_return_expr;
+    D.diag_FallThrough_ReturnsNonVoid = diag::warn_falloff_nonvoid_lambda;
     D.diag_NeverFallThroughOrReturn = 0;
     D.funMode = Lambda;
     return D;
@@ -616,8 +608,7 @@ struct CheckFallThroughDiagnostics {
                         bool HasNoReturn) const {
     if (funMode == Function) {
       return (ReturnsVoid ||
-              D.isIgnored(diag::warn_falloff_nonvoid_function,
-                          FuncLoc)) &&
+              D.isIgnored(diag::warn_falloff_nonvoid_function, FuncLoc)) &&
              (!HasNoReturn ||
               D.isIgnored(diag::warn_noreturn_function_has_return_expr,
                           FuncLoc)) &&
@@ -627,8 +618,7 @@ struct CheckFallThroughDiagnostics {
     if (funMode == Coroutine) {
       return (ReturnsVoid ||
               D.isIgnored(diag::warn_falloff_nonvoid_function, FuncLoc) ||
-              D.isIgnored(diag::warn_falloff_nonvoid_coroutine,
-                          FuncLoc)) &&
+              D.isIgnored(diag::warn_falloff_nonvoid_coroutine, FuncLoc)) &&
              (!HasNoReturn);
     }
     // For blocks / lambdas.
@@ -692,34 +682,34 @@ static void CheckFallThroughForBody(Sema &S, const Decl *D, const Stmt *Body,
 
   // Either in a function body compound statement, or a function-try-block.
   switch (CheckFallThrough(AC)) {
-    case UnknownFallThrough:
-      break;
+  case UnknownFallThrough:
+    break;
 
-    case MaybeFallThrough:
-      if (HasNoReturn)
-        EmitDiag(RBrace, CD.diag_FallThrough_HasNoReturn);
-      else if (!ReturnsVoid)
-        S.Diag(RBrace, CD.diag_FallThrough_ReturnsNonVoid) << 1;
-      break;
-    case AlwaysFallThrough:
-      if (HasNoReturn)
-        EmitDiag(RBrace, CD.diag_FallThrough_HasNoReturn);
-      else if (!ReturnsVoid)
-        S.Diag(RBrace, CD.diag_FallThrough_ReturnsNonVoid) << 0;
-      break;
-    case NeverFallThroughOrReturn:
-      if (ReturnsVoid && !HasNoReturn && CD.diag_NeverFallThroughOrReturn) {
-        if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
-          S.Diag(LBrace, CD.diag_NeverFallThroughOrReturn) << 0 << FD;
-        } else if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) {
-          S.Diag(LBrace, CD.diag_NeverFallThroughOrReturn) << 1 << MD;
-        } else {
-          S.Diag(LBrace, CD.diag_NeverFallThroughOrReturn);
-        }
+  case MaybeFallThrough:
+    if (HasNoReturn)
+      EmitDiag(RBrace, CD.diag_FallThrough_HasNoReturn);
+    else if (!ReturnsVoid)
+      S.Diag(RBrace, CD.diag_FallThrough_ReturnsNonVoid) << 1;
+    break;
+  case AlwaysFallThrough:
+    if (HasNoReturn)
+      EmitDiag(RBrace, CD.diag_FallThrough_HasNoReturn);
+    else if (!ReturnsVoid)
+      S.Diag(RBrace, CD.diag_FallThrough_ReturnsNonVoid) << 0;
+    break;
+  case NeverFallThroughOrReturn:
+    if (ReturnsVoid && !HasNoReturn && CD.diag_NeverFallThroughOrReturn) {
+      if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
+        S.Diag(LBrace, CD.diag_NeverFallThroughOrReturn) << 0 << FD;
+      } else if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) {
+        S.Diag(LBrace, CD.diag_NeverFallThroughOrReturn) << 1 << MD;
+      } else {
+        S.Diag(LBrace, CD.diag_NeverFallThroughOrReturn);
       }
-      break;
-    case NeverFallThrough:
-      break;
+    }
+    break;
+  case NeverFallThrough:
+    break;
   }
 }
 

>From b4fc33028ad21b7e966d311e82e94b618c107660 Mon Sep 17 00:00:00 2001
From: "Igor S. Gerasimov" <i.s.ger at ya.ru>
Date: Mon, 17 Feb 2025 23:22:51 +0100
Subject: [PATCH 3/4] Merge warn_falloff_nonvoid_* into warn_falloff_nonvoid

---
 .../clang/Basic/DiagnosticSemaKinds.td        | 17 +++++++----------
 clang/lib/Sema/AnalysisBasedWarnings.cpp      | 19 +++++++++----------
 2 files changed, 16 insertions(+), 20 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index ff00c76c5e492..5f53adc2f15c8 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -713,8 +713,13 @@ def err_thread_non_global : Error<
 def err_thread_unsupported : Error<
   "thread-local storage is not supported for the current target">;
 
-def warn_falloff_nonvoid_function : Warning<
-  "non-void function does not return a value%select{| in all control paths}0">,
+def warn_falloff_nonvoid : Warning<
+  "non-void %select{function|block|lambda|coroutine}0 "
+  "does not return a value%select{| in all control paths}1">,
+  InGroup<ReturnType>;
+def err_falloff_nonvoid : Warning<
+  "non-void %select{function|block|lambda|coroutine}0 "
+  "does not return a value%select{| in all control paths}1">,
   InGroup<ReturnType>;
 def warn_const_attr_with_pure_attr : Warning<
   "'const' attribute imposes more restrictions; 'pure' attribute ignored">,
@@ -723,11 +728,6 @@ def warn_pure_function_returns_void : Warning<
   "'%select{pure|const}0' attribute on function returning 'void'; attribute ignored">,
   InGroup<IgnoredAttributes>;
 
-def err_falloff_nonvoid_block : Error<
-  "non-void block does not return a value%select{| in all control paths}0">;
-def warn_falloff_nonvoid_coroutine : Warning<
-  "non-void coroutine does not return a value%select{| in all control paths}0">,
-  InGroup<ReturnType>;
 def warn_suggest_noreturn_function : Warning<
   "%select{function|method}0 %1 could be declared with attribute 'noreturn'">,
   InGroup<MissingNoreturn>, DefaultIgnore;
@@ -8399,9 +8399,6 @@ let CategoryName = "Lambda Issue" in {
     "incomplete result type %0 in lambda expression">;
   def err_noreturn_lambda_has_return_expr : Error<
     "lambda declared 'noreturn' should not return">;
-  def warn_falloff_nonvoid_lambda : Warning<
-    "non-void lambda does not return a value%select{| in all control paths}0">,
-    InGroup<ReturnType>;
   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
diff --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp b/clang/lib/Sema/AnalysisBasedWarnings.cpp
index da44ff6f08ff7..ef527374b811f 100644
--- a/clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -547,14 +547,14 @@ struct CheckFallThroughDiagnostics {
   unsigned diag_FallThrough_HasNoReturn;
   unsigned diag_FallThrough_ReturnsNonVoid;
   unsigned diag_NeverFallThroughOrReturn;
-  enum { Function, Block, Lambda, Coroutine } funMode;
+  enum { Function = 0, Block, Lambda, Coroutine } funMode;
   SourceLocation FuncLoc;
 
   static CheckFallThroughDiagnostics MakeForFunction(const Decl *Func) {
     CheckFallThroughDiagnostics D;
     D.FuncLoc = Func->getLocation();
     D.diag_FallThrough_HasNoReturn = diag::warn_falloff_noreturn_function;
-    D.diag_FallThrough_ReturnsNonVoid = diag::warn_falloff_nonvoid_function;
+    D.diag_FallThrough_ReturnsNonVoid = diag::warn_falloff_nonvoid;
 
     // Don't suggest that virtual functions be marked "noreturn", since they
     // might be overridden by non-noreturn functions.
@@ -580,7 +580,7 @@ struct CheckFallThroughDiagnostics {
     CheckFallThroughDiagnostics D;
     D.FuncLoc = Func->getLocation();
     D.diag_FallThrough_HasNoReturn = 0;
-    D.diag_FallThrough_ReturnsNonVoid = diag::warn_falloff_nonvoid_coroutine;
+    D.diag_FallThrough_ReturnsNonVoid = diag::warn_falloff_nonvoid;
     D.diag_NeverFallThroughOrReturn = 0;
     D.funMode = Coroutine;
     return D;
@@ -589,7 +589,7 @@ struct CheckFallThroughDiagnostics {
   static CheckFallThroughDiagnostics MakeForBlock() {
     CheckFallThroughDiagnostics D;
     D.diag_FallThrough_HasNoReturn = diag::err_noreturn_block_has_return_expr;
-    D.diag_FallThrough_ReturnsNonVoid = diag::err_falloff_nonvoid_block;
+    D.diag_FallThrough_ReturnsNonVoid = diag::err_falloff_nonvoid;
     D.diag_NeverFallThroughOrReturn = 0;
     D.funMode = Block;
     return D;
@@ -598,7 +598,7 @@ struct CheckFallThroughDiagnostics {
   static CheckFallThroughDiagnostics MakeForLambda() {
     CheckFallThroughDiagnostics D;
     D.diag_FallThrough_HasNoReturn = diag::err_noreturn_lambda_has_return_expr;
-    D.diag_FallThrough_ReturnsNonVoid = diag::warn_falloff_nonvoid_lambda;
+    D.diag_FallThrough_ReturnsNonVoid = diag::warn_falloff_nonvoid;
     D.diag_NeverFallThroughOrReturn = 0;
     D.funMode = Lambda;
     return D;
@@ -608,7 +608,7 @@ struct CheckFallThroughDiagnostics {
                         bool HasNoReturn) const {
     if (funMode == Function) {
       return (ReturnsVoid ||
-              D.isIgnored(diag::warn_falloff_nonvoid_function, FuncLoc)) &&
+              D.isIgnored(diag::warn_falloff_nonvoid, FuncLoc)) &&
              (!HasNoReturn ||
               D.isIgnored(diag::warn_noreturn_function_has_return_expr,
                           FuncLoc)) &&
@@ -617,8 +617,7 @@ struct CheckFallThroughDiagnostics {
     }
     if (funMode == Coroutine) {
       return (ReturnsVoid ||
-              D.isIgnored(diag::warn_falloff_nonvoid_function, FuncLoc) ||
-              D.isIgnored(diag::warn_falloff_nonvoid_coroutine, FuncLoc)) &&
+              D.isIgnored(diag::warn_falloff_nonvoid, FuncLoc)) &&
              (!HasNoReturn);
     }
     // For blocks / lambdas.
@@ -689,13 +688,13 @@ static void CheckFallThroughForBody(Sema &S, const Decl *D, const Stmt *Body,
     if (HasNoReturn)
       EmitDiag(RBrace, CD.diag_FallThrough_HasNoReturn);
     else if (!ReturnsVoid)
-      S.Diag(RBrace, CD.diag_FallThrough_ReturnsNonVoid) << 1;
+      S.Diag(RBrace, CD.diag_FallThrough_ReturnsNonVoid) << CD.funMode << 1;
     break;
   case AlwaysFallThrough:
     if (HasNoReturn)
       EmitDiag(RBrace, CD.diag_FallThrough_HasNoReturn);
     else if (!ReturnsVoid)
-      S.Diag(RBrace, CD.diag_FallThrough_ReturnsNonVoid) << 0;
+      S.Diag(RBrace, CD.diag_FallThrough_ReturnsNonVoid) << CD.funMode << 0;
     break;
   case NeverFallThroughOrReturn:
     if (ReturnsVoid && !HasNoReturn && CD.diag_NeverFallThroughOrReturn) {

>From fee6ce8117385095594f103925c31c12a2db9494 Mon Sep 17 00:00:00 2001
From: "Igor S. Gerasimov" <i.s.ger at ya.ru>
Date: Mon, 17 Feb 2025 23:37:14 +0100
Subject: [PATCH 4/4] err_falloff_nonvoid should be Error

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 5f53adc2f15c8..4a7b33ebd01f4 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -717,10 +717,9 @@ def warn_falloff_nonvoid : Warning<
   "non-void %select{function|block|lambda|coroutine}0 "
   "does not return a value%select{| in all control paths}1">,
   InGroup<ReturnType>;
-def err_falloff_nonvoid : Warning<
+def err_falloff_nonvoid : Error<
   "non-void %select{function|block|lambda|coroutine}0 "
-  "does not return a value%select{| in all control paths}1">,
-  InGroup<ReturnType>;
+  "does not return a value%select{| in all control paths}1">;
 def warn_const_attr_with_pure_attr : Warning<
   "'const' attribute imposes more restrictions; 'pure' attribute ignored">,
   InGroup<IgnoredAttributes>;



More information about the cfe-commits mailing list