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

Robert Widmann via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 12 07:39:58 PST 2019


CodaFi created this revision.
CodaFi added reviewers: steven_wu, rtrieu.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When this was rewritten in D43737 <https://reviews.llvm.org/D43737>, the logic changed to better explore infinite loops. The check for a reachable exit block was deleted which accidentally introduced false positives in case the exit node was unreachable.

We were testing for cases like this, but @steven_wu provided an additional test case that I've included in the regression tests for this patch.


Repository:
  rC Clang

https://reviews.llvm.org/D58122

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


Index: test/SemaCXX/warn-infinite-recursion.cpp
===================================================================
--- test/SemaCXX/warn-infinite-recursion.cpp
+++ 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: lib/Sema/AnalysisBasedWarnings.cpp
===================================================================
--- lib/Sema/AnalysisBasedWarnings.cpp
+++ 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.186464.patch
Type: text/x-patch
Size: 1191 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190212/f26d2bb4/attachment-0001.bin>


More information about the cfe-commits mailing list