[cfe-commits] r81830 - /cfe/trunk/lib/Analysis/GRExprEngine.cpp

Ted Kremenek kremenek at apple.com
Mon Sep 14 21:19:09 PDT 2009


Author: kremenek
Date: Mon Sep 14 23:19:09 2009
New Revision: 81830

URL: http://llvm.org/viewvc/llvm-project?rev=81830&view=rev
Log:
Per feedback from Eli, recognize in the transfer function logic for
__builtin_offsetof in the static analyzer that __builtin_offsetof is
not guaranteed to return an integer constant.  We will need to shore
this up later, but now at least we have correct support for when this
*is* an integer constant.

Modified:
    cfe/trunk/lib/Analysis/GRExprEngine.cpp

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

==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngine.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngine.cpp Mon Sep 14 23:19:09 2009
@@ -2431,12 +2431,18 @@
     }
 
     case UnaryOperator::OffsetOf: {
-      const APSInt &IV = U->EvaluateAsInt(getContext());
-      assert(IV.getBitWidth() == getContext().getTypeSize(U->getType()));
-      assert(U->getType()->isIntegerType());
-      assert(IV.isSigned() == U->getType()->isSignedIntegerType());
-      SVal X = ValMgr.makeIntVal(IV);      
-      MakeNode(Dst, U, Pred, GetState(Pred)->BindExpr(U, X));
+      Expr::EvalResult Res;
+      if (U->Evaluate(Res, getContext()) && Res.Val.isInt()) {
+        const APSInt &IV = Res.Val.getInt();
+        assert(IV.getBitWidth() == getContext().getTypeSize(U->getType()));
+        assert(U->getType()->isIntegerType());
+        assert(IV.isSigned() == U->getType()->isSignedIntegerType());
+        SVal X = ValMgr.makeIntVal(IV);      
+        MakeNode(Dst, U, Pred, GetState(Pred)->BindExpr(U, X));
+        return;
+      }
+      // FIXME: Handle the case where __builtin_offsetof is not a constant.
+      Dst.Add(Pred);
       return;
     }
 





More information about the cfe-commits mailing list