From 0030f1dbc1ee166a2a7228712d07c3468c5500be Mon Sep 17 00:00:00 2001 From: Richard Trieu Date: Fri, 4 May 2012 03:01:54 +0000 Subject: [PATCH] Skip checking for infinite for-loops if there are global or static variables in the conditional. llvm-svn: 156148 --- clang/lib/Sema/SemaStmt.cpp | 5 +++-- clang/test/SemaCXX/warn-loop-analysis.cpp | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 66ddbaabf1c4..2d03ab99efca 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -1214,11 +1214,12 @@ public: // 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::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/clang/test/SemaCXX/warn-loop-analysis.cpp b/clang/test/SemaCXX/warn-loop-analysis.cpp index a55ca6c6eace..627bc51d1b0f 100644 --- a/clang/test/SemaCXX/warn-loop-analysis.cpp +++ b/clang/test/SemaCXX/warn-loop-analysis.cpp @@ -144,3 +144,11 @@ void test5() { 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;); +}