[cfe-commits] r116769 - in /cfe/trunk: lib/Frontend/CompilerInvocation.cpp test/Analysis/idempotent-operations-limited-loops.c

Ted Kremenek kremenek at apple.com
Mon Oct 18 16:36:05 PDT 2010


Author: kremenek
Date: Mon Oct 18 18:36:05 2010
New Revision: 116769

URL: http://llvm.org/viewvc/llvm-project?rev=116769&view=rev
Log:
"Fix" bogus idempotent operations warning due to loop unrolling not unrolling enough loops to show that an invariant
doesn't hold.  This fix is to increase the loop unrolling count to 4, which experiments show doesn't typically impact
analysis time.  The real fix is to modify the IdempotentOperationsChecker to suppress warnings where an analysis point
could be preceded by a point where we gave up due to loop unrolling.

Added:
    cfe/trunk/test/Analysis/idempotent-operations-limited-loops.c
Modified:
    cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=116769&r1=116768&r2=116769&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Mon Oct 18 18:36:05 2010
@@ -830,7 +830,7 @@
     Args.hasArg(OPT_analyzer_experimental_internal_checks);
   Opts.TrimGraph = Args.hasArg(OPT_trim_egraph);
   Opts.MaxNodes = Args.getLastArgIntValue(OPT_analyzer_max_nodes, 150000,Diags);
-  Opts.MaxLoop = Args.getLastArgIntValue(OPT_analyzer_max_loop, 3, Diags);
+  Opts.MaxLoop = Args.getLastArgIntValue(OPT_analyzer_max_loop, 4, Diags);
   Opts.InlineCall = Args.hasArg(OPT_analyzer_inline_call);
   Opts.IdempotentOps = Args.hasArg(OPT_analysis_WarnIdempotentOps);
 }

Added: cfe/trunk/test/Analysis/idempotent-operations-limited-loops.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/idempotent-operations-limited-loops.c?rev=116769&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/idempotent-operations-limited-loops.c (added)
+++ cfe/trunk/test/Analysis/idempotent-operations-limited-loops.c Mon Oct 18 18:36:05 2010
@@ -0,0 +1,29 @@
+void always_warning() { int *p = 0; *p = 0xDEADBEEF; }
+
+// FIXME: False positive due to loop unrolling.  This should be fixed.
+
+int pr8403()
+{
+        int i;
+        for(i=0; i<10; i++)
+        {
+                int j;
+                for(j=0; j+1<i; j++)
+                {
+                }
+        }
+        return 0;
+}
+
+// RUN: %clang_cc1 -analyze -analyzer-store=region -analyzer-constraints=range -fblocks -analyzer-opt-analyze-nested-blocks -analyzer-check-objc-mem -analyzer-check-idempotent-operations -analyzer-max-loop 3 %s 2>&1 | FileCheck --check-prefix=Loops3 %s
+// RUN: %clang_cc1 -analyze -analyzer-store=region -analyzer-constraints=range -fblocks -analyzer-opt-analyze-nested-blocks -analyzer-check-objc-mem -analyzer-check-idempotent-operations -analyzer-max-loop 4 %s 2>&1 | FileCheck --check-prefix=Loops4 %s
+// RUN: %clang_cc1 -analyze -analyzer-store=region -analyzer-constraints=range -fblocks -analyzer-opt-analyze-nested-blocks -analyzer-check-objc-mem -analyzer-check-idempotent-operations %s 2>&1 | FileCheck --check-prefix=LoopsDefault %s
+
+// CHECK-Loops3: :1:37: warning: Dereference of null pointer
+// CHECK-Loops3: :11:27: warning: The left operand to '+' is always 0
+// CHECK-Loops3: 2 warnings generated
+// CHECK-Loops4: :1:37: warning: Dereference of null pointer
+// CHECK-Loops4: 1 warning generated.
+// CHECK-LoopsDefault: :1:37: warning: Dereference of null pointer
+// CHECK-LoopsDefault: 1 warning generated.
+





More information about the cfe-commits mailing list