[PATCH] D58122: Restore Check for Unreachable Exit Block in -Winfinite-recursion

Robert Widmann via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 13 14:21:58 PST 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL353984: Restore Check for Unreachable Exit Block in -Winfinite-recursion (authored by CodaFi, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D58122?vs=186464&id=186745#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58122/new/

https://reviews.llvm.org/D58122

Files:
  cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
  cfe/trunk/test/SemaCXX/warn-infinite-recursion.cpp


Index: cfe/trunk/test/SemaCXX/warn-infinite-recursion.cpp
===================================================================
--- cfe/trunk/test/SemaCXX/warn-infinite-recursion.cpp
+++ cfe/trunk/test/SemaCXX/warn-infinite-recursion.cpp
@@ -53,19 +53,28 @@
   return 5 + j();
 }
 
-void k() {  // expected-warning{{call itself}}
+// Don't warn on infinite loops
+void k() {
   while(true) {
     k();
   }
 }
 
-// Don't warn on infinite loops
 void l() {
   while (true) {}
 
   l();
 }
 
+void m() {
+  static int count = 5;
+  if (count >0) {
+    count--;
+    l();
+  }
+  while (true) {}
+}
+
 class S {
   static void a();
   void b();
Index: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
===================================================================
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
@@ -249,6 +249,10 @@
   CFG *cfg = AC.getCFG();
   if (!cfg) return;
 
+  // If the exit block is unreachable, skip processing the function.
+  if (cfg->getExit().pred_empty())
+    return;
+
   // Emit diagnostic if a recursive function call is detected for all paths.
   if (checkForRecursiveFunctionCall(FD, cfg))
     S.Diag(Body->getBeginLoc(), diag::warn_infinite_recursive_function);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58122.186745.patch
Type: text/x-patch
Size: 1251 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190213/331ec59d/attachment.bin>


More information about the cfe-commits mailing list