[cfe-commits] r156148 - in /cfe/trunk: lib/Sema/SemaStmt.cpp test/SemaCXX/warn-loop-analysis.cpp

Richard Trieu rtrieu at google.com
Thu May 3 20:01:54 PDT 2012


Author: rtrieu
Date: Thu May  3 22:01:54 2012
New Revision: 156148

URL: http://llvm.org/viewvc/llvm-project?rev=156148&view=rev
Log:
Skip checking for infinite for-loops if there are global or static variables
in the conditional.

Modified:
    cfe/trunk/lib/Sema/SemaStmt.cpp
    cfe/trunk/test/SemaCXX/warn-loop-analysis.cpp

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=156148&r1=156147&r2=156148&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Thu May  3 22:01:54 2012
@@ -1214,11 +1214,12 @@
     // No decls found.
     if (Decls.size() == 0) return;
 
-    // Don't warn on volatile decls.
+    // Don't warn on volatile, static, or global variables.
     for (llvm::SmallPtrSet<VarDecl*, 8>::iterator I = Decls.begin(),
                                                   E = Decls.end();
          I != E; ++I)
-      if ((*I)->getType().isVolatileQualified()) return;
+      if ((*I)->getType().isVolatileQualified() ||
+          (*I)->hasGlobalStorage()) return;
 
     if (DeclMatcher(S, Decls, Second).FoundDeclInUse() ||
         DeclMatcher(S, Decls, Third).FoundDeclInUse() ||

Modified: cfe/trunk/test/SemaCXX/warn-loop-analysis.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-loop-analysis.cpp?rev=156148&r1=156147&r2=156148&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-loop-analysis.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-loop-analysis.cpp Thu May  3 22:01:54 2012
@@ -144,3 +144,11 @@
   for (int a; a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a;);//\
    // expected-warning {{variable 'a' used in loop condition not modified in loop body}}
 }
+
+// Ignore global variables and static variables.
+int x6;
+void test6() {
+  static int y;
+  for (;x6;);
+  for (;y;);
+}





More information about the cfe-commits mailing list