Skip checking for infinite for-loops if there are global or static variables
in the conditional.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156148 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index 66ddbaa..2d03ab9 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -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() ||
diff --git a/test/SemaCXX/warn-loop-analysis.cpp b/test/SemaCXX/warn-loop-analysis.cpp
index a55ca6c..627bc51 100644
--- a/test/SemaCXX/warn-loop-analysis.cpp
+++ b/test/SemaCXX/warn-loop-analysis.cpp
@@ -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;);
+}