[cfe-commits] r156148 - in /cfe/trunk: lib/Sema/SemaStmt.cpp test/SemaCXX/warn-loop-analysis.cpp
Jordy Rose
jediknil at belkadan.com
Thu May 3 20:53:11 PDT 2012
Should static local variables be excepted from this exception? I can contrive a case where it wouldn't be a problem, but in general it's probably just as bad.
> void bad() {
> static int x = 5;
> for (;x;) { printf("hi"); }
> x = 0;
> }
>
> void okay() {
> static int x = 5;
> --x;
> for (;x;) { printf("hi"); okay(); }
> }
>
> void badButHardToCatch() {
> static int x = 5;
> for (;x;) { printf("hi"); badButHardToCatch(); }
> --x;
> }
Jordy
On May 3, 2012, at 23:01, Richard Trieu wrote:
> 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;);
> +}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list