[cfe-commits] r112312 - in /cfe/trunk: lib/Checker/SymbolManager.cpp test/Analysis/func.c test/Analysis/idempotent-operations.c test/Analysis/misc-ps-region-store.m test/Analysis/misc-ps.m test/Analysis/null-deref-ps-temp.c test/Analysis/null-deref-ps.c

Tom Care tcare at apple.com
Fri Aug 27 15:46:32 PDT 2010


Author: tcare
Date: Fri Aug 27 17:46:32 2010
New Revision: 112312

URL: http://llvm.org/viewvc/llvm-project?rev=112312&view=rev
Log:
Enabled relaxed LiveVariables analysis in the path-sensitive engine to increase the coverage of bugs. Primarily affects IdempotentOperationChecker.
- Migrated a temporarily separated test back to its original file (bug has been fixed, null-deref-ps-temp.c -> null-deref-ps.c)
- Changed SymbolManager to use relaxed LiveVariables
- Updated several test cases that the IdempotentOperationChecker class now flags
- Added test case to test relaxed LiveVariables use by the IdempotentOperationChecker

Removed:
    cfe/trunk/test/Analysis/null-deref-ps-temp.c
Modified:
    cfe/trunk/lib/Checker/SymbolManager.cpp
    cfe/trunk/test/Analysis/func.c
    cfe/trunk/test/Analysis/idempotent-operations.c
    cfe/trunk/test/Analysis/misc-ps-region-store.m
    cfe/trunk/test/Analysis/misc-ps.m
    cfe/trunk/test/Analysis/null-deref-ps.c

Modified: cfe/trunk/lib/Checker/SymbolManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/SymbolManager.cpp?rev=112312&r1=112311&r2=112312&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/SymbolManager.cpp (original)
+++ cfe/trunk/lib/Checker/SymbolManager.cpp Fri Aug 27 17:46:32 2010
@@ -324,7 +324,8 @@
 }
 
 bool SymbolReaper::isLive(const Stmt* ExprVal) const {
-  return LCtx->getLiveVariables()->isLive(Loc, ExprVal);
+  return LCtx->getAnalysisContext()->getRelaxedLiveVariables()->
+      isLive(Loc, ExprVal);
 }
 
 bool SymbolReaper::isLive(const VarRegion *VR) const {
@@ -332,7 +333,8 @@
   const StackFrameContext *CurrentContext = LCtx->getCurrentStackFrame();
 
   if (VarContext == CurrentContext)
-    return LCtx->getLiveVariables()->isLive(Loc, VR->getDecl());
+    return LCtx->getAnalysisContext()->getRelaxedLiveVariables()->
+        isLive(Loc, VR->getDecl());
 
   return VarContext->isParentOf(CurrentContext);
 }

Modified: cfe/trunk/test/Analysis/func.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/func.c?rev=112312&r1=112311&r2=112312&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/func.c (original)
+++ cfe/trunk/test/Analysis/func.c Fri Aug 27 17:46:32 2010
@@ -4,7 +4,7 @@
 void f(void) {
   void (*p)(void);
   p = f;
-  p = &f;
+  p = &f; // expected-warning{{Assigned value is always the same as the existing value}}
   p();
   (*p)();
 }

Modified: cfe/trunk/test/Analysis/idempotent-operations.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/idempotent-operations.c?rev=112312&r1=112311&r2=112312&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/idempotent-operations.c (original)
+++ cfe/trunk/test/Analysis/idempotent-operations.c Fri Aug 27 17:46:32 2010
@@ -78,6 +78,20 @@
   }
 }
 
+// Relaxed liveness - check that we don't kill liveness at assignments
+typedef unsigned uintptr_t;
+void kill_at_assign() {
+  short array[2];
+  uintptr_t x = array; // expected-warning{{incompatible pointer to integer conversion}}
+  short *p = x; // expected-warning{{incompatible integer to pointer conversion}}
+
+  // The following branch should be infeasible.
+  if (!(p = &array[0])) { // expected-warning{{Assigned value is always the same as the existing value}}
+    p = 0;
+    *p = 1; // no-warning
+  }
+}
+
 // False positive tests
 
 unsigned false1() {

Modified: cfe/trunk/test/Analysis/misc-ps-region-store.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-ps-region-store.m?rev=112312&r1=112311&r2=112312&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/misc-ps-region-store.m (original)
+++ cfe/trunk/test/Analysis/misc-ps-region-store.m Fri Aug 27 17:46:32 2010
@@ -253,7 +253,7 @@
   a = A;
   b = B;
   
-  n = *a++;
+  n = *a++; // expected-warning{{Assigned value is always the same as the existing value}}
   if (n)
     x += *b++; // no-warning
 }
@@ -708,7 +708,7 @@
   long long *z = (long long *) (intptr_t) src;
   long long w = 0;
   int n = 0;
-  for (n = 0; n < y; ++n) {
+  for (n = 0; n < y; ++n) { // expected-warning{{Assigned value is always the same as the existing value}}
     // Previously we crashed analyzing this statement.
     w = *z++;
   }

Modified: cfe/trunk/test/Analysis/misc-ps.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-ps.m?rev=112312&r1=112311&r2=112312&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/misc-ps.m (original)
+++ cfe/trunk/test/Analysis/misc-ps.m Fri Aug 27 17:46:32 2010
@@ -458,7 +458,7 @@
 // ElementRegion is created.
 unsigned char test_array_index_bitwidth(const unsigned char *p) {
   unsigned short i = 0;
-  for (i = 0; i < 2; i++) p = &p[i];  
+  for (i = 0; i < 2; i++) p = &p[i]; // expected-warning{{Assigned value is always the same as the existing value}}
   return p[i+1];
 }
 

Removed: cfe/trunk/test/Analysis/null-deref-ps-temp.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/null-deref-ps-temp.c?rev=112311&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/null-deref-ps-temp.c (original)
+++ cfe/trunk/test/Analysis/null-deref-ps-temp.c (removed)
@@ -1,31 +0,0 @@
-// RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -std=gnu99 -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -analyzer-no-purge-dead -verify %s -Wreturn-type
-
-// This is a temporary file to isolate a test case that would cause a failure
-// only some of the time in null-deref-ps.c. The idempotent operations checker
-// has revealed a bug on line 18 ('=' instead of '==') when the
-// -analyzer-no-purge-dead flag is passed to cc1. Some fundamental design
-// changes are needed to make this work without the -analyzer-no-purge-dead flag
-// and this test will be integrated back into the main file when this happens.
-
-typedef unsigned uintptr_t;
-
-int f4_b() {
-  short array[2];
-  uintptr_t x = array; // expected-warning{{incompatible pointer to integer conversion}}
-  short *p = x; // expected-warning{{incompatible integer to pointer conversion}}
-
-  // The following branch should be infeasible.
-  if (!(p = &array[0])) { // expected-warning{{Assigned value is always the same as the existing value}}
-    p = 0;
-    *p = 1; // no-warning
-  }
-
-  if (p) {
-    *p = 5; // no-warning
-    p = 0;
-  }
-  else return; // expected-warning {{non-void function 'f4_b' should return a value}}
-
-  *p += 10; // expected-warning{{Dereference of null pointer}}
-  return 0;
-}

Modified: cfe/trunk/test/Analysis/null-deref-ps.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/null-deref-ps.c?rev=112312&r1=112311&r2=112312&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/null-deref-ps.c (original)
+++ cfe/trunk/test/Analysis/null-deref-ps.c Fri Aug 27 17:46:32 2010
@@ -60,7 +60,26 @@
   return *q; // expected-warning{{Dereference of null pointer (loaded from variable 'q')}}
 }
 
-// Placeholder for f4_b, temporarily moved to null-deref-ps-temp.c
+int f4_b() {
+  short array[2];
+  uintptr_t x = array; // expected-warning{{incompatible pointer to integer conversion}}
+  short *p = x; // expected-warning{{incompatible integer to pointer conversion}}
+
+  // The following branch should be infeasible.
+  if (!(p == &array[0])) {
+    p = 0;
+    *p = 1; // no-warning
+  }
+
+  if (p) {
+    *p = 5; // no-warning
+    p = 0;
+  }
+  else return; // expected-warning {{non-void function 'f4_b' should return a value}}
+
+  *p += 10; // expected-warning{{Dereference of null pointer}}
+  return 0;
+}
 
 int f5() {
   





More information about the cfe-commits mailing list