[cfe-commits] r82019 - in /cfe/trunk: lib/Analysis/GRExprEngineInternalChecks.cpp test/Analysis/uninit-vals-ps-region.c test/Analysis/uninit-vals-ps.c

Ted Kremenek kremenek at apple.com
Tue Sep 15 23:04:26 PDT 2009


Author: kremenek
Date: Wed Sep 16 01:04:26 2009
New Revision: 82019

URL: http://llvm.org/viewvc/llvm-project?rev=82019&view=rev
Log:
Have divide-by-zero checker not handled undefined denominators.  This is handled by the generic checking for undefined operands for BinaryOperators.

Modified:
    cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp
    cfe/trunk/test/Analysis/uninit-vals-ps-region.c
    cfe/trunk/test/Analysis/uninit-vals-ps.c

Modified: cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp?rev=82019&r1=82018&r2=82019&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp Wed Sep 16 01:04:26 2009
@@ -194,8 +194,7 @@
 class VISIBILITY_HIDDEN DivZero : public BuiltinBug {
 public:
   DivZero(GRExprEngine* eng = 0)
-    : BuiltinBug(eng,"Division-by-zero",
-                 "Division by zero or undefined value.") {}
+    : BuiltinBug(eng,"Division by zero") {}
 
   void registerInitialVisitors(BugReporterContext& BRC,
                                const ExplodedNode* N,
@@ -222,24 +221,26 @@
         llvm::SmallString<256> sbuf;
         llvm::raw_svector_ostream OS(sbuf);
         const GRState *ST = N->getState();
-        const Expr *Ex = NULL; 
+        const Expr *Ex = NULL;
+        bool isLeft = true;
 
         if (ST->getSVal(B->getLHS()).isUndef()) {
           Ex = B->getLHS()->IgnoreParenCasts();
-          OS << "The left operand of the '";
+          isLeft = true;
         }
         else if (ST->getSVal(B->getRHS()).isUndef()) {
           Ex = B->getRHS()->IgnoreParenCasts();
-          OS << "The right operand of the '";
+          isLeft = false;
         }
-      
-        if (Ex) {                  
-          OS << BinaryOperator::getOpcodeStr(B->getOpcode())
-             << "' expression is an undefined "
-                "or otherwise garbage value";
+                
+        if (Ex) {
+          OS << "The " << (isLeft ? "left" : "right")
+             << " operand of the '"
+             << BinaryOperator::getOpcodeStr(B->getOpcode())
+             << "' expression is a garbage value";
         }          
         else {
-          // We KNOW that the result was undefined.
+          // Neither operand was undefined, but the result is undefined.
           OS << "The result of the '"
              << BinaryOperator::getOpcodeStr(B->getOpcode())
              << "' expression is undefined";
@@ -268,8 +269,10 @@
     
     if (const BinaryOperator *B = dyn_cast<BinaryOperator>(S)) {
       const GRState *ST = N->getState();
-      X = ST->getSVal(B->getLHS()).isUndef()
-          ? B->getLHS()->IgnoreParenCasts() : B->getRHS()->IgnoreParenCasts();
+      if (ST->getSVal(B->getLHS()).isUndef())
+        X = B->getLHS();
+      else if (ST->getSVal(B->getRHS()).isUndef())
+        X = B->getRHS();
     }
     
     registerTrackNullOrUndefValue(BRC, X, N);
@@ -766,22 +769,11 @@
       !B->getRHS()->getType()->isScalarType())
     return;
 
-  // Check for divide by undefined.
   SVal Denom = C.getState()->getSVal(B->getRHS());
-
-  if (Denom.isUndef()) {
-    if (ExplodedNode *N = C.GenerateNode(B, true)) {
-      if (!BT)
-        BT = new DivZero();
-
-      C.EmitReport(new BuiltinBugReport(*BT, BT->getDescription().c_str(), N));
-    }
-    return;
-  }
-
-  // Handle the case where 'Denom' is UnknownVal.
   const DefinedSVal *DV = dyn_cast<DefinedSVal>(&Denom);
 
+  // Divide-by-undefined handled in the generic checking for uses of
+  // undefined values.
   if (!DV)
     return;
 

Modified: cfe/trunk/test/Analysis/uninit-vals-ps-region.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/uninit-vals-ps-region.c?rev=82019&r1=82018&r2=82019&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/uninit-vals-ps-region.c (original)
+++ cfe/trunk/test/Analysis/uninit-vals-ps-region.c Wed Sep 16 01:04:26 2009
@@ -25,7 +25,7 @@
   struct TestUninit v2 = test_uninit_aux();
   int z;
   v1.y = z;
-  test_unit_aux2(v2.x + v1.y);  // expected-warning{{The right operand of the '+' expression is an undefined or otherwise garbage value}}
+  test_unit_aux2(v2.x + v1.y);  // expected-warning{{The right operand of the '+' expression is a garbage value}}
 }
 void test_uninit_neg() {
   struct TestUninit v1 = { 0, 0 };

Modified: cfe/trunk/test/Analysis/uninit-vals-ps.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/uninit-vals-ps.c?rev=82019&r1=82018&r2=82019&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/uninit-vals-ps.c (original)
+++ cfe/trunk/test/Analysis/uninit-vals-ps.c Wed Sep 16 01:04:26 2009
@@ -22,7 +22,7 @@
   
   int x;
   
-  if (x+1)  // expected-warning{{The left operand of the '+' expression is an undefined or otherwise garbage value}}
+  if (x+1)  // expected-warning{{The left operand of the '+' expression is a garbage value}}
     return 1;
     
   return 2;  
@@ -31,13 +31,13 @@
 int f2_b() {
   int x;
   
-  return ((1+x)+2+((x))) + 1 ? 1 : 2; // expected-warning{{The right operand of the '+' expression is an undefined or otherwise garbage value}}
+  return ((1+x)+2+((x))) + 1 ? 1 : 2; // expected-warning{{The right operand of the '+' expression is a garbage value}}
 }
 
 int f3(void) {
   int i;
   int *p = &i;
-  if (*p > 0) // expected-warning{{The left operand of the '>' expression is an undefined or otherwise garbage value}}
+  if (*p > 0) // expected-warning{{The left operand of the '>' expression is a garbage value}}
     return 0;
   else
     return 1;





More information about the cfe-commits mailing list