[cfe-commits] r109527 - in /cfe/trunk: lib/Checker/IdempotentOperationChecker.cpp test/Analysis/constant-folding.c test/Analysis/dead-stores.c test/Analysis/idempotent-operations.c test/Analysis/misc-ps.m test/Analysis/null-deref-ps.c test/Analysis/rdar-6541136-region.c test/Analysis/rdar-6541136.c

Ted Kremenek kremenek at apple.com
Tue Jul 27 11:49:09 PDT 2010


Author: kremenek
Date: Tue Jul 27 13:49:08 2010
New Revision: 109527

URL: http://llvm.org/viewvc/llvm-project?rev=109527&view=rev
Log:
Finesse 'idempotent operations' analyzer issues to include the opcode of the binary operator for clearer error reporting.  Also remove the 'Idempotent operation' prefix in messages; it's redundant since the bug type is the same.

Modified:
    cfe/trunk/lib/Checker/IdempotentOperationChecker.cpp
    cfe/trunk/test/Analysis/constant-folding.c
    cfe/trunk/test/Analysis/dead-stores.c
    cfe/trunk/test/Analysis/idempotent-operations.c
    cfe/trunk/test/Analysis/misc-ps.m
    cfe/trunk/test/Analysis/null-deref-ps.c
    cfe/trunk/test/Analysis/rdar-6541136-region.c
    cfe/trunk/test/Analysis/rdar-6541136.c

Modified: cfe/trunk/lib/Checker/IdempotentOperationChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/IdempotentOperationChecker.cpp?rev=109527&r1=109526&r2=109527&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/IdempotentOperationChecker.cpp (original)
+++ cfe/trunk/lib/Checker/IdempotentOperationChecker.cpp Tue Jul 27 13:49:08 2010
@@ -310,7 +310,7 @@
 }
 
 void IdempotentOperationChecker::VisitEndAnalysis(ExplodedGraph &G,
-                                                  BugReporter &B,
+                                                  BugReporter &BR,
                                                   bool hasWorkRemaining) {
   // If there is any work remaining we cannot be 100% sure about our warnings
   if (hasWorkRemaining)
@@ -322,22 +322,29 @@
       hash.begin(); i != hash.end(); ++i) {
     if (i->second != Impossible) {
       // Select the error message.
-      const char *msg = 0;
+      const BinaryOperator *B = i->first;
+      llvm::SmallString<128> buf;
+      llvm::raw_svector_ostream os(buf);
+
       switch (i->second) {
       case Equal:
-        msg = "idempotent operation; both operands are always equal in value";
+        if (B->getOpcode() == BinaryOperator::Assign)
+          os << "Assigned value is always the same as the existing value";
+        else
+          os << "Both operands to '" << B->getOpcodeStr()
+             << "' always have the same value";
         break;
       case LHSis1:
-        msg = "idempotent operation; the left operand is always 1";
+        os << "The left operand to '" << B->getOpcodeStr() << "' is always 1";
         break;
       case RHSis1:
-        msg = "idempotent operation; the right operand is always 1";
+        os << "The right operand to '" << B->getOpcodeStr() << "' is always 1";
         break;
       case LHSis0:
-        msg = "idempotent operation; the left operand is always 0";
+        os << "The left operand to '" << B->getOpcodeStr() << "' is always 0";
         break;
       case RHSis0:
-        msg = "idempotent operation; the right operand is always 0";
+        os << "The right operand to '" << B->getOpcodeStr() << "' is always 0";
         break;
       case Possible:
         llvm_unreachable("Operation was never marked with an assumption");
@@ -348,9 +355,8 @@
       // Create the SourceRange Arrays
       SourceRange S[2] = { i->first->getLHS()->getSourceRange(),
                            i->first->getRHS()->getSourceRange() };
-      B.EmitBasicReport("Idempotent operation", "Dead code",
-                        msg, i->first->getOperatorLoc(),
-          S, 2);
+      BR.EmitBasicReport("Idempotent operation", "Dead code",
+                         os.str(), i->first->getOperatorLoc(), S, 2);
     }
   }
 }

Modified: cfe/trunk/test/Analysis/constant-folding.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/constant-folding.c?rev=109527&r1=109526&r2=109527&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/constant-folding.c (original)
+++ cfe/trunk/test/Analysis/constant-folding.c Tue Jul 27 13:49:08 2010
@@ -18,10 +18,10 @@
 }
 
 void testSelfOperations (int a) {
-  if ((a|a) != a) WARN; // expected-warning{{idempotent operation}}
-  if ((a&a) != a) WARN; // expected-warning{{idempotent operation}}
-  if ((a^a) != 0) WARN; // expected-warning{{idempotent operation}}
-  if ((a-a) != 0) WARN; // expected-warning{{idempotent operation}}
+  if ((a|a) != a) WARN; // expected-warning{{Both operands to '|' always have the same value}}
+  if ((a&a) != a) WARN; // expected-warning{{Both operands to '&' always have the same value}}
+  if ((a^a) != 0) WARN; // expected-warning{{Both operands to '^' always have the same value}}
+  if ((a-a) != 0) WARN; // expected-warning{{Both operands to '-' always have the same value}}
 }
 
 void testIdempotent (int a) {
@@ -68,5 +68,5 @@
   if (b!=a) WARN;
   if (b>a) WARN;
   if (b<a) WARN;
-  if (b-a) WARN; // expected-warning{{idempotent operation}}
+  if (b-a) WARN; // expected-warning{{Both operands to '-' always have the same value}}
 }

Modified: cfe/trunk/test/Analysis/dead-stores.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/dead-stores.c?rev=109527&r1=109526&r2=109527&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/dead-stores.c (original)
+++ cfe/trunk/test/Analysis/dead-stores.c Tue Jul 27 13:49:08 2010
@@ -158,7 +158,7 @@
 // Self-assignments should not be flagged as dead stores.
 void f17() {
   int x = 1;
-  x = x; // expected-warning{{idempotent operation}}
+  x = x; // expected-warning{{Assigned value is always the same as the existing value}}
 }
 
 // <rdar://problem/6506065>
@@ -458,7 +458,7 @@
     // Note that the next value stored to 'i' is never executed
     // because the next statement to be executed is the 'break'
     // in the increment code of the first loop.
-    i = i * 3; // expected-warning{{Value stored to 'i' is never read}} expected-warning{{idempotent operation}}
+    i = i * 3; // expected-warning{{Value stored to 'i' is never read}} expected-warning{{The left operand to '*' is always 1}}
   }
 }
 

Modified: cfe/trunk/test/Analysis/idempotent-operations.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/idempotent-operations.c?rev=109527&r1=109526&r2=109527&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/idempotent-operations.c (original)
+++ cfe/trunk/test/Analysis/idempotent-operations.c Tue Jul 27 13:49:08 2010
@@ -9,47 +9,47 @@
   int x = 10, zero = 0, one = 1;
 
   // x op x
-  x = x;        // expected-warning {{idempotent operation; both operands are always equal in value}}
-  test(x - x);  // expected-warning {{idempotent operation; both operands are always equal in value}}
-  x -= x;       // expected-warning {{idempotent operation; both operands are always equal in value}}
+  x = x;        // expected-warning {{Assigned value is always the same as the existing value}}
+  test(x - x);  // expected-warning {{Both operands to '-' always have the same value}}
+  x -= x;       // expected-warning {{Both operands to '-=' always have the same value}}
   x = 10;       // no-warning
-  test(x / x);  // expected-warning {{idempotent operation; both operands are always equal in value}}
-  x /= x;       // expected-warning {{idempotent operation; both operands are always equal in value}}
+  test(x / x);  // expected-warning {{Both operands to '/' always have the same value}}
+  x /= x;       // expected-warning {{Both operands to '/=' always have the same value}}
   x = 10;       // no-warning
-  test(x & x);  // expected-warning {{idempotent operation; both operands are always equal in value}}
-  x &= x;       // expected-warning {{idempotent operation; both operands are always equal in value}}
-  test(x | x);  // expected-warning {{idempotent operation; both operands are always equal in value}}
-  x |= x;       // expected-warning {{idempotent operation; both operands are always equal in value}}
+  test(x & x);  // expected-warning {{Both operands to '&' always have the same value}}
+  x &= x;       // expected-warning {{Both operands to '&=' always have the same value}}
+  test(x | x);  // expected-warning {{Both operands to '|' always have the same value}}
+  x |= x;       // expected-warning {{Both operands to '|=' always have the same value}}
 
   // x op 1
-  test(x * one);  // expected-warning {{idempotent operation; the right operand is always 1}}
-  x *= one;       // expected-warning {{idempotent operation; the right operand is always 1}}
-  test(x / one);  // expected-warning {{idempotent operation; the right operand is always 1}}
-  x /= one;       // expected-warning {{idempotent operation; the right operand is always 1}}
+  test(x * one);  // expected-warning {{The right operand to '*' is always 1}}
+  x *= one;       // expected-warning {{The right operand to '*=' is always 1}}
+  test(x / one);  // expected-warning {{The right operand to '/' is always 1}}
+  x /= one;       // expected-warning {{The right operand to '/=' is always 1}}
 
   // 1 op x
-  test(one * x);   // expected-warning {{idempotent operation; the left operand is always 1}}
+  test(one * x);   // expected-warning {{The left operand to '*' is always 1}}
 
   // x op 0
-  test(x + zero);  // expected-warning {{idempotent operation; the right operand is always 0}}
-  test(x - zero);  // expected-warning {{idempotent operation; the right operand is always 0}}
-  test(x * zero);  // expected-warning {{idempotent operation; the right operand is always 0}}
-  test(x & zero);  // expected-warning {{idempotent operation; the right operand is always 0}}
-  test(x | zero);  // expected-warning {{idempotent operation; the right operand is always 0}}
-  test(x ^ zero);  // expected-warning {{idempotent operation; the right operand is always 0}}
-  test(x << zero); // expected-warning {{idempotent operation; the right operand is always 0}}
-  test(x >> zero); // expected-warning {{idempotent operation; the right operand is always 0}}
+  test(x + zero);  // expected-warning {{The right operand to '+' is always 0}}
+  test(x - zero);  // expected-warning {{The right operand to '-' is always 0}}
+  test(x * zero);  // expected-warning {{The right operand to '*' is always 0}}
+  test(x & zero);  // expected-warning {{The right operand to '&' is always 0}}
+  test(x | zero);  // expected-warning {{The right operand to '|' is always 0}}
+  test(x ^ zero);  // expected-warning {{The right operand to '^' is always 0}}
+  test(x << zero); // expected-warning {{The right operand to '<<' is always 0}}
+  test(x >> zero); // expected-warning {{The right operand to '>>' is always 0}}
 
   // 0 op x
-  test(zero + x);  // expected-warning {{idempotent operation; the left operand is always 0}}
-  test(zero - x);  // expected-warning {{idempotent operation; the left operand is always 0}}
-  test(zero / x);  // expected-warning {{idempotent operation; the left operand is always 0}}
-  test(zero * x);  // expected-warning {{idempotent operation; the left operand is always 0}}
-  test(zero & x);  // expected-warning {{idempotent operation; the left operand is always 0}}
-  test(zero | x);  // expected-warning {{idempotent operation; the left operand is always 0}}
-  test(zero ^ x);  // expected-warning {{idempotent operation; the left operand is always 0}}
-  test(zero << x); // expected-warning {{idempotent operation; the left operand is always 0}}
-  test(zero >> x); // expected-warning {{idempotent operation; the left operand is always 0}}
+  test(zero + x);  // expected-warning {{The left operand to '+' is always 0}}
+  test(zero - x);  // expected-warning {{The left operand to '-' is always 0}}
+  test(zero / x);  // expected-warning {{The left operand to '/' is always 0}}
+  test(zero * x);  // expected-warning {{The left operand to '*' is always 0}}
+  test(zero & x);  // expected-warning {{The left operand to '&' is always 0}}
+  test(zero | x);  // expected-warning {{The left operand to '|' is always 0}}
+  test(zero ^ x);  // expected-warning {{The left operand to '^' is always 0}}
+  test(zero << x); // expected-warning {{The left operand to '<<' is always 0}}
+  test(zero >> x); // expected-warning {{The left operand to '>>' is always 0}}
 }
 
 void floats(float x) {

Modified: cfe/trunk/test/Analysis/misc-ps.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-ps.m?rev=109527&r1=109526&r2=109527&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/misc-ps.m (original)
+++ cfe/trunk/test/Analysis/misc-ps.m Tue Jul 27 13:49:08 2010
@@ -86,11 +86,11 @@
 
 void r6268365() {
   unsigned x = 0;
-  x &= r6268365Aux(); // expected-warning{{idempotent operation}}
+  x &= r6268365Aux(); // expected-warning{{The left operand to '&=' is always 0}}
   unsigned j = 0;
     
   if (x == 0) ++j;
-  if (x == 0) x = x / j; // expected-warning{{idempotent operation}} expected-warning{{idempotent operation}}
+  if (x == 0) x = x / j; // expected-warning{{Assigned value is always the same as the existing value}} expected-warning{{The right operand to '/' is always 1}}
 }
 
 void divzeroassume(unsigned x, unsigned j) {  

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=109527&r1=109526&r2=109527&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/null-deref-ps.c (original)
+++ cfe/trunk/test/Analysis/null-deref-ps.c Tue Jul 27 13:49:08 2010
@@ -280,7 +280,7 @@
 // Test handling of translating between integer "pointers" and back.
 void f13() {
   int *x = 0;
-  if (((((int) x) << 2) + 1) >> 1) *x = 1; // expected-warning{{idempotent operation}}
+  if (((((int) x) << 2) + 1) >> 1) *x = 1; // expected-warning{{he left operand to '<<' is always 0}}
 }
 
 // PR 4759 - Attribute non-null checking by the analyzer was not correctly

Modified: cfe/trunk/test/Analysis/rdar-6541136-region.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/rdar-6541136-region.c?rev=109527&r1=109526&r2=109527&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/rdar-6541136-region.c (original)
+++ cfe/trunk/test/Analysis/rdar-6541136-region.c Tue Jul 27 13:49:08 2010
@@ -9,7 +9,7 @@
 void test1( void ) {
   kernel_tea_cheese_t *wonky = &_wonky_gesticulate_cheese;
   struct load_wine *cmd = (void*) &wonky[1];
-  cmd = cmd; // expected-warning{{idempotent operation}}
+  cmd = cmd; // expected-warning{{Assigned value is always the same as the existing value}}
   char *p = (void*) &wonky[1];
   kernel_tea_cheese_t *q = &wonky[1];
   // This test case tests both the RegionStore logic (doesn't crash) and
@@ -21,7 +21,7 @@
 void test1_b( void ) {
   kernel_tea_cheese_t *wonky = &_wonky_gesticulate_cheese;
   struct load_wine *cmd = (void*) &wonky[1];
-  cmd = cmd; // expected-warning{{idempotent operation}}
+  cmd = cmd; // expected-warning{{Assigned value is always the same as the existing value}}
   char *p = (void*) &wonky[1];
   *p = 1;  // expected-warning{{Access out-of-bound array element (buffer overflow)}}
 }

Modified: cfe/trunk/test/Analysis/rdar-6541136.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/rdar-6541136.c?rev=109527&r1=109526&r2=109527&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/rdar-6541136.c (original)
+++ cfe/trunk/test/Analysis/rdar-6541136.c Tue Jul 27 13:49:08 2010
@@ -12,7 +12,7 @@
 {
   kernel_tea_cheese_t *wonky = &_wonky_gesticulate_cheese;
   struct load_wine *cmd = (void*) &wonky[1];
-  cmd = cmd; // expected-warning{{idempotent operation}}
+  cmd = cmd; // expected-warning{{Assigned value is always the same as the existing value}}
   char *p = (void*) &wonky[1];
   *p = 1;
   kernel_tea_cheese_t *q = &wonky[1];





More information about the cfe-commits mailing list