]> granicus.if.org Git - clang/commitdiff
Added transfer function/value track logic for taking the address of a label.
authorTed Kremenek <kremenek@apple.com>
Tue, 12 Feb 2008 21:37:56 +0000 (21:37 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 12 Feb 2008 21:37:56 +0000 (21:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47030 91177308-0d34-0410-b5e6-96231b3b80d8

Analysis/RValues.cpp
Analysis/RValues.h
Analysis/ValueState.cpp

index f4b8a3d34067f039817c1e428a5d4071775b3eb1..5f361eebf834377127e65a5486aa565a7fab18b8 100644 (file)
@@ -491,14 +491,22 @@ RValue RValue::GetSymbolValue(SymbolManager& SymMgr, ParmVarDecl* D) {
     return nonlval::SymbolVal(SymMgr.getSymbol(D));
 }
 
-void RValue::print() const {
-  print(*llvm::cerr.stream());
+//===----------------------------------------------------------------------===//
+// Utility methods for constructing LValues.
+//===----------------------------------------------------------------------===//
+
+LValue LValue::GetValue(AddrLabelExpr* E) {
+  return lval::GotoLabel(E->getLabel());
 }
 
 //===----------------------------------------------------------------------===//
 // Pretty-Printing.
 //===----------------------------------------------------------------------===//
 
+void RValue::print() const {
+  print(*llvm::cerr.stream());
+}
+
 void RValue::print(std::ostream& Out) const {
   switch (getBaseKind()) {
     case UnknownKind:
@@ -577,6 +585,11 @@ void LValue::print(std::ostream& Out) const {
     case lval::SymbolValKind:
       Out << '$' << cast<lval::SymbolVal>(this)->getSymbol();
       break;
+      
+    case lval::GotoLabelKind:
+      Out << "&&"
+          << cast<lval::GotoLabel>(this)->getLabel()->getID()->getName();
+      break;
 
     case lval::DeclValKind:
       Out << '&' 
index 9aa2f11e1996e8e7ac5add7ffc4dd6abb7d5e5a4..ffc5e4a57d4630e25e418a1c7d59660d0f9629d6 100644 (file)
@@ -364,6 +364,8 @@ public:
   
   RValue EvalCast(ValueManager& ValMgr, Expr* CastExpr) const;
   
+  static LValue GetValue(AddrLabelExpr* E);
+  
   // Implement isa<T> support.
   static inline bool classof(const RValue* V) {
     return V->getBaseKind() != NonLValueKind;
@@ -445,6 +447,7 @@ namespace nonlval {
 namespace lval {
   
   enum Kind { SymbolValKind,
+              GotoLabelKind,
               DeclValKind,
               ConcreteIntKind,
               NumKind };
@@ -460,9 +463,31 @@ namespace lval {
     
     static inline bool classof(const RValue* V) {
       return isa<LValue>(V) && V->getSubKind() == SymbolValKind;
-    }  
+    }
+    
+    static inline bool classof(const LValue* V) {
+      return V->getSubKind() == SymbolValKind;
+    }
   };
   
+  class GotoLabel : public LValue {
+  public:
+    GotoLabel(LabelStmt* Label) : LValue(GotoLabelKind, Label) {}
+    
+    LabelStmt* getLabel() const {
+      return static_cast<LabelStmt*>(getRawPtr());
+    }
+    
+    static inline bool classof(const RValue* V) {
+      return isa<LValue>(V) && V->getSubKind() == GotoLabelKind;
+    }
+    
+    static inline bool classof(const LValue* V) {
+      return V->getSubKind() == GotoLabelKind;
+    }
+  };
+    
+  
   class DeclVal : public LValue {
   public:
     DeclVal(const ValueDecl* vd) : LValue(DeclValKind,vd) {}
@@ -483,6 +508,10 @@ namespace lval {
     static inline bool classof(const RValue* V) {
       return isa<LValue>(V) && V->getSubKind() == DeclValKind;
     }
+    
+    static inline bool classof(const LValue* V) {
+      return V->getSubKind() == DeclValKind;
+    }
   };
 
   class ConcreteInt : public LValue {
@@ -510,8 +539,7 @@ namespace lval {
     
   };  
 } // end clang::lval namespace
-  
-  
+
 } // end clang namespace  
 
 #endif
index d550716fd5f59f0920e0b3ea2dcb8512e1dd8a46..c74c876b5121fd718390ddd0a411d97ee0cc36cc 100644 (file)
@@ -168,6 +168,9 @@ ValueStateManager::AddEQ(ValueState St, SymbolID sym, const llvm::APSInt& V) {
 RValue ValueStateManager::GetValue(ValueState St, Expr* E, bool* hasVal) {
   for (;;) {
     switch (E->getStmtClass()) {
+
+      case Stmt::AddrLabelExprClass:
+        return LValue::GetValue(cast<AddrLabelExpr>(E));
         
         // ParenExprs are no-ops.