Add static analyzer transfer function support for __builtin_offsetof.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81820 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/GRExprEngine.cpp b/lib/Analysis/GRExprEngine.cpp
index 8214199..0e08cd2 100644
--- a/lib/Analysis/GRExprEngine.cpp
+++ b/lib/Analysis/GRExprEngine.cpp
@@ -2430,10 +2430,15 @@
return;
}
- // FIXME: Just report "Unknown" for OffsetOf.
- case UnaryOperator::OffsetOf:
- Dst.Add(Pred);
+ 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));
return;
+ }
case UnaryOperator::Plus: assert (!asLValue); // FALL-THROUGH.
case UnaryOperator::Extension: {