r353984 - Restore Check for Unreachable Exit Block in -Winfinite-recursion

Robert Widmann via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 13 14:22:23 PST 2019


Author: codafi
Date: Wed Feb 13 14:22:23 2019
New Revision: 353984

URL: http://llvm.org/viewvc/llvm-project?rev=353984&view=rev
Log:
Restore Check for Unreachable Exit Block in -Winfinite-recursion

Summary:
When this was rewritten in 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.

Reviewers: steven_wu, rtrieu

Reviewed By: steven_wu, rtrieu

Subscribers: cfe-commits, steven_wu

Tags: #clang

Differential Revision: https://reviews.llvm.org/D58122

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

Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=353984&r1=353983&r2=353984&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Wed Feb 13 14:22:23 2019
@@ -249,6 +249,10 @@ static void checkRecursiveFunction(Sema
   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);

Modified: cfe/trunk/test/SemaCXX/warn-infinite-recursion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-infinite-recursion.cpp?rev=353984&r1=353983&r2=353984&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-infinite-recursion.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-infinite-recursion.cpp Wed Feb 13 14:22:23 2019
@@ -53,19 +53,28 @@ int j() {  // expected-warning{{call its
   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();




More information about the cfe-commits mailing list