mirror of
https://github.com/llvm/llvm-project.git
synced 2025-05-02 17:46:06 +00:00
Skip checking for infinite for-loops if there are global or static variables
in the conditional. llvm-svn: 156148
This commit is contained in:
parent
75fbe90839
commit
0030f1dbc1
@ -1214,11 +1214,12 @@ public:
|
|||||||
// No decls found.
|
// No decls found.
|
||||||
if (Decls.size() == 0) return;
|
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(),
|
for (llvm::SmallPtrSet<VarDecl*, 8>::iterator I = Decls.begin(),
|
||||||
E = Decls.end();
|
E = Decls.end();
|
||||||
I != E; ++I)
|
I != E; ++I)
|
||||||
if ((*I)->getType().isVolatileQualified()) return;
|
if ((*I)->getType().isVolatileQualified() ||
|
||||||
|
(*I)->hasGlobalStorage()) return;
|
||||||
|
|
||||||
if (DeclMatcher(S, Decls, Second).FoundDeclInUse() ||
|
if (DeclMatcher(S, Decls, Second).FoundDeclInUse() ||
|
||||||
DeclMatcher(S, Decls, Third).FoundDeclInUse() ||
|
DeclMatcher(S, Decls, Third).FoundDeclInUse() ||
|
||||||
|
@ -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;);//\
|
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}}
|
// 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;);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user