[cfe-commits] r50109 - in /cfe/trunk: include/clang/Analysis/PathSensitive/RValues.h lib/Analysis/CFRefCount.cpp lib/Analysis/GRExprEngine.cpp lib/Analysis/GRSimpleVals.cpp lib/Analysis/RValues.cpp lib/Analysis/ValueState.cpp test/Analysis/null-deref-ps.c

Ted Kremenek kremenek at apple.com
Tue Apr 22 14:39:21 PDT 2008


Author: kremenek
Date: Tue Apr 22 16:39:21 2008
New Revision: 50109

URL: http://llvm.org/viewvc/llvm-project?rev=50109&view=rev
Log:
Added lval type (and tracking) for StringLiterals.

Modified:
    cfe/trunk/include/clang/Analysis/PathSensitive/RValues.h
    cfe/trunk/lib/Analysis/CFRefCount.cpp
    cfe/trunk/lib/Analysis/GRExprEngine.cpp
    cfe/trunk/lib/Analysis/GRSimpleVals.cpp
    cfe/trunk/lib/Analysis/RValues.cpp
    cfe/trunk/lib/Analysis/ValueState.cpp
    cfe/trunk/test/Analysis/null-deref-ps.c

Modified: cfe/trunk/include/clang/Analysis/PathSensitive/RValues.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/RValues.h?rev=50109&r1=50108&r2=50109&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/RValues.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/RValues.h Tue Apr 22 16:39:21 2008
@@ -128,7 +128,7 @@
   static NonLVal MakeVal(BasicValueFactory& BasicVals, uint64_t X, QualType T);
   
   static NonLVal MakeVal(BasicValueFactory& BasicVals, IntegerLiteral* I);
-  
+    
   static NonLVal MakeIntTruthVal(BasicValueFactory& BasicVals, bool b);
     
   // Implement isa<T> support.
@@ -151,6 +151,8 @@
     
   static LVal MakeVal(AddrLabelExpr* E);
   
+  static LVal MakeVal(StringLiteral* S);
+  
   // Implement isa<T> support.
   static inline bool classof(const RVal* V) {
     return V->getBaseKind() == LValKind;
@@ -274,7 +276,7 @@
 namespace lval {
   
 enum Kind { SymbolValKind, GotoLabelKind, DeclValKind, FuncValKind,
-            ConcreteIntKind };
+            ConcreteIntKind, StringLiteralValKind };
 
 class SymbolVal : public LVal {
 public:
@@ -391,6 +393,24 @@
   }
 };
   
+class StringLiteralVal : public LVal {
+public:
+  StringLiteralVal(StringLiteral* L) : LVal(StringLiteralValKind, L) {}
+  
+  StringLiteral* getLiteral() const { return (StringLiteral*) Data; }
+  
+  // Implement isa<T> support.
+  static inline bool classof(const RVal* V) {
+    return V->getBaseKind() == LValKind &&
+           V->getSubKind() == StringLiteralValKind;
+  }
+  
+  static inline bool classof(const LVal* V) {
+    return V->getSubKind() == StringLiteralValKind;
+  }
+};  
+    
+  
 } // end clang::lval namespace
 } // end clang namespace  
 

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

==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Tue Apr 22 16:39:21 2008
@@ -826,6 +826,8 @@
       //  should compose behavior, not copy it.
       StateMgr.Unbind(StVals, cast<LVal>(V));
     }
+    else if (isa<nonlval::LValAsInteger>(V))
+      StateMgr.Unbind(StVals, cast<nonlval::LValAsInteger>(V).getLVal());
   }    
   
   St = StateMgr.getPersistentState(StVals);

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

==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngine.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngine.cpp Tue Apr 22 16:39:21 2008
@@ -2014,6 +2014,7 @@
     case lval::DeclValKind:
     case lval::FuncValKind:
     case lval::GotoLabelKind:
+    case lval::StringLiteralValKind:
       isFeasible = Assumption;
       return St;
 

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

==============================================================================
--- cfe/trunk/lib/Analysis/GRSimpleVals.cpp (original)
+++ cfe/trunk/lib/Analysis/GRSimpleVals.cpp Tue Apr 22 16:39:21 2008
@@ -572,6 +572,10 @@
     
     if (isa<LVal>(V))
       St = StateMgr.SetRVal(St, cast<LVal>(V), UnknownVal());
+    else if (isa<nonlval::LValAsInteger>(V))
+      St = StateMgr.SetRVal(St, cast<nonlval::LValAsInteger>(V).getLVal(),
+                            UnknownVal());
+    
   }
   
   // Make up a symbol for the return value of this function.

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

==============================================================================
--- cfe/trunk/lib/Analysis/RValues.cpp (original)
+++ cfe/trunk/lib/Analysis/RValues.cpp Tue Apr 22 16:39:21 2008
@@ -240,6 +240,10 @@
 
 LVal LVal::MakeVal(AddrLabelExpr* E) { return lval::GotoLabel(E->getLabel()); }
 
+LVal LVal::MakeVal(StringLiteral* S) {
+  return lval::StringLiteralVal(S);
+}
+
 //===----------------------------------------------------------------------===//
 // Utility methods for constructing RVals (both NonLVals and LVals).
 //===----------------------------------------------------------------------===//
@@ -392,6 +396,12 @@
           << cast<lval::FuncVal>(this)->getDecl()->getIdentifier()->getName();
       break;
       
+    case lval::StringLiteralValKind:
+      Out << "literal \""
+          << cast<lval::StringLiteralVal>(this)->getLiteral()->getStrData()
+          << "\"";
+      break;
+      
     default:
       assert (false && "Pretty-printing not implemented for this LVal.");
       break;

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

==============================================================================
--- cfe/trunk/lib/Analysis/ValueState.cpp (original)
+++ cfe/trunk/lib/Analysis/ValueState.cpp Tue Apr 22 16:39:21 2008
@@ -264,6 +264,9 @@
       case Stmt::IntegerLiteralClass: {
         return NonLVal::MakeVal(BasicVals, cast<IntegerLiteral>(E));
       }
+        
+      case Stmt::StringLiteralClass:
+        return LVal::MakeVal(cast<StringLiteral>(E));
 
         // Casts where the source and target type are the same
         // are no-ops.  We blast through these to get the descendant

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=50109&r1=50108&r2=50109&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/null-deref-ps.c (original)
+++ cfe/trunk/test/Analysis/null-deref-ps.c Tue Apr 22 16:39:21 2008
@@ -38,4 +38,11 @@
     
   int *q = (int*) x;
   return *q; // expected-warning{{Dereference of null pointer.}}
-}
\ No newline at end of file
+}
+
+int f5() {
+  
+  char *s = "hello world";
+  return s[0]; // no-warning
+}
+





More information about the cfe-commits mailing list