]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r302069, and update
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / lib / StaticAnalyzer / Core / SValBuilder.cpp
1 // SValBuilder.cpp - Basic class for all SValBuilder implementations -*- C++ -*-
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 //  This file defines SValBuilder, the base class for all (complete) SValBuilder
11 //  implementations.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h"
16 #include "clang/AST/DeclCXX.h"
17 #include "clang/AST/ExprCXX.h"
18 #include "clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h"
19 #include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h"
20 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
21 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
22
23 using namespace clang;
24 using namespace ento;
25
26 //===----------------------------------------------------------------------===//
27 // Basic SVal creation.
28 //===----------------------------------------------------------------------===//
29
30 void SValBuilder::anchor() { }
31
32 DefinedOrUnknownSVal SValBuilder::makeZeroVal(QualType type) {
33   if (Loc::isLocType(type))
34     return makeNull();
35
36   if (type->isIntegralOrEnumerationType())
37     return makeIntVal(0, type);
38
39   if (type->isArrayType() || type->isRecordType() || type->isVectorType() ||
40       type->isAnyComplexType())
41     return makeCompoundVal(type, BasicVals.getEmptySValList());
42
43   // FIXME: Handle floats.
44   return UnknownVal();
45 }
46
47 NonLoc SValBuilder::makeNonLoc(const SymExpr *lhs, BinaryOperator::Opcode op,
48                                 const llvm::APSInt& rhs, QualType type) {
49   // The Environment ensures we always get a persistent APSInt in
50   // BasicValueFactory, so we don't need to get the APSInt from
51   // BasicValueFactory again.
52   assert(lhs);
53   assert(!Loc::isLocType(type));
54   return nonloc::SymbolVal(SymMgr.getSymIntExpr(lhs, op, rhs, type));
55 }
56
57 NonLoc SValBuilder::makeNonLoc(const llvm::APSInt& lhs,
58                                BinaryOperator::Opcode op, const SymExpr *rhs,
59                                QualType type) {
60   assert(rhs);
61   assert(!Loc::isLocType(type));
62   return nonloc::SymbolVal(SymMgr.getIntSymExpr(lhs, op, rhs, type));
63 }
64
65 NonLoc SValBuilder::makeNonLoc(const SymExpr *lhs, BinaryOperator::Opcode op,
66                                const SymExpr *rhs, QualType type) {
67   assert(lhs && rhs);
68   assert(!Loc::isLocType(type));
69   return nonloc::SymbolVal(SymMgr.getSymSymExpr(lhs, op, rhs, type));
70 }
71
72 NonLoc SValBuilder::makeNonLoc(const SymExpr *operand,
73                                QualType fromTy, QualType toTy) {
74   assert(operand);
75   assert(!Loc::isLocType(toTy));
76   return nonloc::SymbolVal(SymMgr.getCastSymbol(operand, fromTy, toTy));
77 }
78
79 SVal SValBuilder::convertToArrayIndex(SVal val) {
80   if (val.isUnknownOrUndef())
81     return val;
82
83   // Common case: we have an appropriately sized integer.
84   if (Optional<nonloc::ConcreteInt> CI = val.getAs<nonloc::ConcreteInt>()) {
85     const llvm::APSInt& I = CI->getValue();
86     if (I.getBitWidth() == ArrayIndexWidth && I.isSigned())
87       return val;
88   }
89
90   return evalCastFromNonLoc(val.castAs<NonLoc>(), ArrayIndexTy);
91 }
92
93 nonloc::ConcreteInt SValBuilder::makeBoolVal(const CXXBoolLiteralExpr *boolean){
94   return makeTruthVal(boolean->getValue());
95 }
96
97 DefinedOrUnknownSVal
98 SValBuilder::getRegionValueSymbolVal(const TypedValueRegion* region) {
99   QualType T = region->getValueType();
100
101   if (T->isNullPtrType())
102     return makeZeroVal(T);
103   
104   if (!SymbolManager::canSymbolicate(T))
105     return UnknownVal();
106
107   SymbolRef sym = SymMgr.getRegionValueSymbol(region);
108
109   if (Loc::isLocType(T))
110     return loc::MemRegionVal(MemMgr.getSymbolicRegion(sym));
111
112   return nonloc::SymbolVal(sym);
113 }
114
115 DefinedOrUnknownSVal SValBuilder::conjureSymbolVal(const void *SymbolTag,
116                                                    const Expr *Ex,
117                                                    const LocationContext *LCtx,
118                                                    unsigned Count) {
119   QualType T = Ex->getType();
120
121   if (T->isNullPtrType())
122     return makeZeroVal(T);
123
124   // Compute the type of the result. If the expression is not an R-value, the
125   // result should be a location.
126   QualType ExType = Ex->getType();
127   if (Ex->isGLValue())
128     T = LCtx->getAnalysisDeclContext()->getASTContext().getPointerType(ExType);
129
130   return conjureSymbolVal(SymbolTag, Ex, LCtx, T, Count);
131 }
132
133 DefinedOrUnknownSVal SValBuilder::conjureSymbolVal(const void *symbolTag,
134                                                    const Expr *expr,
135                                                    const LocationContext *LCtx,
136                                                    QualType type,
137                                                    unsigned count) {
138   if (type->isNullPtrType())
139     return makeZeroVal(type);
140
141   if (!SymbolManager::canSymbolicate(type))
142     return UnknownVal();
143
144   SymbolRef sym = SymMgr.conjureSymbol(expr, LCtx, type, count, symbolTag);
145
146   if (Loc::isLocType(type))
147     return loc::MemRegionVal(MemMgr.getSymbolicRegion(sym));
148
149   return nonloc::SymbolVal(sym);
150 }
151
152
153 DefinedOrUnknownSVal SValBuilder::conjureSymbolVal(const Stmt *stmt,
154                                                    const LocationContext *LCtx,
155                                                    QualType type,
156                                                    unsigned visitCount) {
157   if (type->isNullPtrType())
158     return makeZeroVal(type);
159
160   if (!SymbolManager::canSymbolicate(type))
161     return UnknownVal();
162
163   SymbolRef sym = SymMgr.conjureSymbol(stmt, LCtx, type, visitCount);
164
165   if (Loc::isLocType(type))
166     return loc::MemRegionVal(MemMgr.getSymbolicRegion(sym));
167
168   return nonloc::SymbolVal(sym);
169 }
170
171 DefinedOrUnknownSVal
172 SValBuilder::getConjuredHeapSymbolVal(const Expr *E,
173                                       const LocationContext *LCtx,
174                                       unsigned VisitCount) {
175   QualType T = E->getType();
176   assert(Loc::isLocType(T));
177   assert(SymbolManager::canSymbolicate(T));
178   if (T->isNullPtrType())
179     return makeZeroVal(T);
180
181   SymbolRef sym = SymMgr.conjureSymbol(E, LCtx, T, VisitCount);
182   return loc::MemRegionVal(MemMgr.getSymbolicHeapRegion(sym));
183 }
184
185 DefinedSVal SValBuilder::getMetadataSymbolVal(const void *symbolTag,
186                                               const MemRegion *region,
187                                               const Expr *expr, QualType type,
188                                               const LocationContext *LCtx,
189                                               unsigned count) {
190   assert(SymbolManager::canSymbolicate(type) && "Invalid metadata symbol type");
191
192   SymbolRef sym =
193       SymMgr.getMetadataSymbol(region, expr, type, LCtx, count, symbolTag);
194
195   if (Loc::isLocType(type))
196     return loc::MemRegionVal(MemMgr.getSymbolicRegion(sym));
197
198   return nonloc::SymbolVal(sym);
199 }
200
201 DefinedOrUnknownSVal
202 SValBuilder::getDerivedRegionValueSymbolVal(SymbolRef parentSymbol,
203                                              const TypedValueRegion *region) {
204   QualType T = region->getValueType();
205
206   if (T->isNullPtrType())
207     return makeZeroVal(T);
208
209   if (!SymbolManager::canSymbolicate(T))
210     return UnknownVal();
211
212   SymbolRef sym = SymMgr.getDerivedSymbol(parentSymbol, region);
213
214   if (Loc::isLocType(T))
215     return loc::MemRegionVal(MemMgr.getSymbolicRegion(sym));
216
217   return nonloc::SymbolVal(sym);
218 }
219
220 DefinedSVal SValBuilder::getMemberPointer(const DeclaratorDecl* DD) {
221   assert(!DD || isa<CXXMethodDecl>(DD) || isa<FieldDecl>(DD));
222
223   if (auto *MD = dyn_cast_or_null<CXXMethodDecl>(DD)) {
224     // Sema treats pointers to static member functions as have function pointer
225     // type, so return a function pointer for the method.
226     // We don't need to play a similar trick for static member fields
227     // because these are represented as plain VarDecls and not FieldDecls
228     // in the AST.
229     if (MD->isStatic())
230       return getFunctionPointer(MD);
231   }
232
233   return nonloc::PointerToMember(DD);
234 }
235
236 DefinedSVal SValBuilder::getFunctionPointer(const FunctionDecl *func) {
237   return loc::MemRegionVal(MemMgr.getFunctionCodeRegion(func));
238 }
239
240 DefinedSVal SValBuilder::getBlockPointer(const BlockDecl *block,
241                                          CanQualType locTy,
242                                          const LocationContext *locContext,
243                                          unsigned blockCount) {
244   const BlockCodeRegion *BC =
245     MemMgr.getBlockCodeRegion(block, locTy, locContext->getAnalysisDeclContext());
246   const BlockDataRegion *BD = MemMgr.getBlockDataRegion(BC, locContext,
247                                                         blockCount);
248   return loc::MemRegionVal(BD);
249 }
250
251 /// Return a memory region for the 'this' object reference.
252 loc::MemRegionVal SValBuilder::getCXXThis(const CXXMethodDecl *D,
253                                           const StackFrameContext *SFC) {
254   return loc::MemRegionVal(getRegionManager().
255                            getCXXThisRegion(D->getThisType(getContext()), SFC));
256 }
257
258 /// Return a memory region for the 'this' object reference.
259 loc::MemRegionVal SValBuilder::getCXXThis(const CXXRecordDecl *D,
260                                           const StackFrameContext *SFC) {
261   const Type *T = D->getTypeForDecl();
262   QualType PT = getContext().getPointerType(QualType(T, 0));
263   return loc::MemRegionVal(getRegionManager().getCXXThisRegion(PT, SFC));
264 }
265
266 Optional<SVal> SValBuilder::getConstantVal(const Expr *E) {
267   E = E->IgnoreParens();
268
269   switch (E->getStmtClass()) {
270   // Handle expressions that we treat differently from the AST's constant
271   // evaluator.
272   case Stmt::AddrLabelExprClass:
273     return makeLoc(cast<AddrLabelExpr>(E));
274
275   case Stmt::CXXScalarValueInitExprClass:
276   case Stmt::ImplicitValueInitExprClass:
277     return makeZeroVal(E->getType());
278
279   case Stmt::ObjCStringLiteralClass: {
280     const ObjCStringLiteral *SL = cast<ObjCStringLiteral>(E);
281     return makeLoc(getRegionManager().getObjCStringRegion(SL));
282   }
283
284   case Stmt::StringLiteralClass: {
285     const StringLiteral *SL = cast<StringLiteral>(E);
286     return makeLoc(getRegionManager().getStringRegion(SL));
287   }
288
289   // Fast-path some expressions to avoid the overhead of going through the AST's
290   // constant evaluator
291   case Stmt::CharacterLiteralClass: {
292     const CharacterLiteral *C = cast<CharacterLiteral>(E);
293     return makeIntVal(C->getValue(), C->getType());
294   }
295
296   case Stmt::CXXBoolLiteralExprClass:
297     return makeBoolVal(cast<CXXBoolLiteralExpr>(E));
298
299   case Stmt::TypeTraitExprClass: {
300     const TypeTraitExpr *TE = cast<TypeTraitExpr>(E);
301     return makeTruthVal(TE->getValue(), TE->getType());
302   }
303
304   case Stmt::IntegerLiteralClass:
305     return makeIntVal(cast<IntegerLiteral>(E));
306
307   case Stmt::ObjCBoolLiteralExprClass:
308     return makeBoolVal(cast<ObjCBoolLiteralExpr>(E));
309
310   case Stmt::CXXNullPtrLiteralExprClass:
311     return makeNull();
312
313   case Stmt::ImplicitCastExprClass: {
314     const CastExpr *CE = cast<CastExpr>(E);
315     switch (CE->getCastKind()) {
316     default:
317       break;
318     case CK_ArrayToPointerDecay:
319     case CK_BitCast: {
320       const Expr *SE = CE->getSubExpr();
321       Optional<SVal> Val = getConstantVal(SE);
322       if (!Val)
323         return None;
324       return evalCast(*Val, CE->getType(), SE->getType());
325     }
326     }
327     // FALLTHROUGH
328   }
329
330   // If we don't have a special case, fall back to the AST's constant evaluator.
331   default: {
332     // Don't try to come up with a value for materialized temporaries.
333     if (E->isGLValue())
334       return None;
335
336     ASTContext &Ctx = getContext();
337     llvm::APSInt Result;
338     if (E->EvaluateAsInt(Result, Ctx))
339       return makeIntVal(Result);
340
341     if (Loc::isLocType(E->getType()))
342       if (E->isNullPointerConstant(Ctx, Expr::NPC_ValueDependentIsNotNull))
343         return makeNull();
344
345     return None;
346   }
347   }
348 }
349
350 //===----------------------------------------------------------------------===//
351
352 SVal SValBuilder::makeSymExprValNN(ProgramStateRef State,
353                                    BinaryOperator::Opcode Op,
354                                    NonLoc LHS, NonLoc RHS,
355                                    QualType ResultTy) {
356   if (!State->isTainted(RHS) && !State->isTainted(LHS))
357     return UnknownVal();
358
359   const SymExpr *symLHS = LHS.getAsSymExpr();
360   const SymExpr *symRHS = RHS.getAsSymExpr();
361   // TODO: When the Max Complexity is reached, we should conjure a symbol
362   // instead of generating an Unknown value and propagate the taint info to it.
363   const unsigned MaxComp = 10000; // 100000 28X
364
365   if (symLHS && symRHS &&
366       (symLHS->computeComplexity() + symRHS->computeComplexity()) <  MaxComp)
367     return makeNonLoc(symLHS, Op, symRHS, ResultTy);
368
369   if (symLHS && symLHS->computeComplexity() < MaxComp)
370     if (Optional<nonloc::ConcreteInt> rInt = RHS.getAs<nonloc::ConcreteInt>())
371       return makeNonLoc(symLHS, Op, rInt->getValue(), ResultTy);
372
373   if (symRHS && symRHS->computeComplexity() < MaxComp)
374     if (Optional<nonloc::ConcreteInt> lInt = LHS.getAs<nonloc::ConcreteInt>())
375       return makeNonLoc(lInt->getValue(), Op, symRHS, ResultTy);
376
377   return UnknownVal();
378 }
379
380
381 SVal SValBuilder::evalBinOp(ProgramStateRef state, BinaryOperator::Opcode op,
382                             SVal lhs, SVal rhs, QualType type) {
383
384   if (lhs.isUndef() || rhs.isUndef())
385     return UndefinedVal();
386
387   if (lhs.isUnknown() || rhs.isUnknown())
388     return UnknownVal();
389
390   if (lhs.getAs<nonloc::LazyCompoundVal>() ||
391       rhs.getAs<nonloc::LazyCompoundVal>()) {
392     return UnknownVal();
393   }
394
395   if (Optional<Loc> LV = lhs.getAs<Loc>()) {
396     if (Optional<Loc> RV = rhs.getAs<Loc>())
397       return evalBinOpLL(state, op, *LV, *RV, type);
398
399     return evalBinOpLN(state, op, *LV, rhs.castAs<NonLoc>(), type);
400   }
401
402   if (Optional<Loc> RV = rhs.getAs<Loc>()) {
403     // Support pointer arithmetic where the addend is on the left
404     // and the pointer on the right.
405     assert(op == BO_Add);
406
407     // Commute the operands.
408     return evalBinOpLN(state, op, *RV, lhs.castAs<NonLoc>(), type);
409   }
410
411   return evalBinOpNN(state, op, lhs.castAs<NonLoc>(), rhs.castAs<NonLoc>(),
412                      type);
413 }
414
415 DefinedOrUnknownSVal SValBuilder::evalEQ(ProgramStateRef state,
416                                          DefinedOrUnknownSVal lhs,
417                                          DefinedOrUnknownSVal rhs) {
418   return evalBinOp(state, BO_EQ, lhs, rhs, getConditionType())
419       .castAs<DefinedOrUnknownSVal>();
420 }
421
422 /// Recursively check if the pointer types are equal modulo const, volatile,
423 /// and restrict qualifiers. Also, assume that all types are similar to 'void'.
424 /// Assumes the input types are canonical.
425 static bool shouldBeModeledWithNoOp(ASTContext &Context, QualType ToTy,
426                                                          QualType FromTy) {
427   while (Context.UnwrapSimilarPointerTypes(ToTy, FromTy)) {
428     Qualifiers Quals1, Quals2;
429     ToTy = Context.getUnqualifiedArrayType(ToTy, Quals1);
430     FromTy = Context.getUnqualifiedArrayType(FromTy, Quals2);
431
432     // Make sure that non-cvr-qualifiers the other qualifiers (e.g., address
433     // spaces) are identical.
434     Quals1.removeCVRQualifiers();
435     Quals2.removeCVRQualifiers();
436     if (Quals1 != Quals2)
437       return false;
438   }
439
440   // If we are casting to void, the 'From' value can be used to represent the
441   // 'To' value.
442   if (ToTy->isVoidType())
443     return true;
444
445   if (ToTy != FromTy)
446     return false;
447
448   return true;
449 }
450
451 // Handles casts of type CK_IntegralCast.
452 // At the moment, this function will redirect to evalCast, except when the range
453 // of the original value is known to be greater than the max of the target type.
454 SVal SValBuilder::evalIntegralCast(ProgramStateRef state, SVal val,
455                                    QualType castTy, QualType originalTy) {
456
457   // No truncations if target type is big enough.
458   if (getContext().getTypeSize(castTy) >= getContext().getTypeSize(originalTy))
459     return evalCast(val, castTy, originalTy);
460
461   const SymExpr *se = val.getAsSymbolicExpression();
462   if (!se) // Let evalCast handle non symbolic expressions.
463     return evalCast(val, castTy, originalTy);
464
465   // Find the maximum value of the target type.
466   APSIntType ToType(getContext().getTypeSize(castTy),
467                     castTy->isUnsignedIntegerType());
468   llvm::APSInt ToTypeMax = ToType.getMaxValue();
469   NonLoc ToTypeMaxVal =
470       makeIntVal(ToTypeMax.isUnsigned() ? ToTypeMax.getZExtValue()
471                                         : ToTypeMax.getSExtValue(),
472                  castTy)
473           .castAs<NonLoc>();
474   // Check the range of the symbol being casted against the maximum value of the
475   // target type.
476   NonLoc FromVal = val.castAs<NonLoc>();
477   QualType CmpTy = getConditionType();
478   NonLoc CompVal =
479       evalBinOpNN(state, BO_LE, FromVal, ToTypeMaxVal, CmpTy).castAs<NonLoc>();
480   ProgramStateRef IsNotTruncated, IsTruncated;
481   std::tie(IsNotTruncated, IsTruncated) = state->assume(CompVal);
482   if (!IsNotTruncated && IsTruncated) {
483     // Symbol is truncated so we evaluate it as a cast.
484     NonLoc CastVal = makeNonLoc(se, originalTy, castTy);
485     return CastVal;
486   }
487   return evalCast(val, castTy, originalTy);
488 }
489
490 // FIXME: should rewrite according to the cast kind.
491 SVal SValBuilder::evalCast(SVal val, QualType castTy, QualType originalTy) {
492   castTy = Context.getCanonicalType(castTy);
493   originalTy = Context.getCanonicalType(originalTy);
494   if (val.isUnknownOrUndef() || castTy == originalTy)
495     return val;
496
497   if (castTy->isBooleanType()) {
498     if (val.isUnknownOrUndef())
499       return val;
500     if (val.isConstant())
501       return makeTruthVal(!val.isZeroConstant(), castTy);
502     if (!Loc::isLocType(originalTy) &&
503         !originalTy->isIntegralOrEnumerationType() &&
504         !originalTy->isMemberPointerType())
505       return UnknownVal();
506     if (SymbolRef Sym = val.getAsSymbol(true)) {
507       BasicValueFactory &BVF = getBasicValueFactory();
508       // FIXME: If we had a state here, we could see if the symbol is known to
509       // be zero, but we don't.
510       return makeNonLoc(Sym, BO_NE, BVF.getValue(0, Sym->getType()), castTy);
511     }
512     // Loc values are not always true, they could be weakly linked functions.
513     if (Optional<Loc> L = val.getAs<Loc>())
514       return evalCastFromLoc(*L, castTy);
515
516     Loc L = val.castAs<nonloc::LocAsInteger>().getLoc();
517     return evalCastFromLoc(L, castTy);
518   }
519
520   // For const casts, casts to void, just propagate the value.
521   if (!castTy->isVariableArrayType() && !originalTy->isVariableArrayType())
522     if (shouldBeModeledWithNoOp(Context, Context.getPointerType(castTy),
523                                          Context.getPointerType(originalTy)))
524       return val;
525
526   // Check for casts from pointers to integers.
527   if (castTy->isIntegralOrEnumerationType() && Loc::isLocType(originalTy))
528     return evalCastFromLoc(val.castAs<Loc>(), castTy);
529
530   // Check for casts from integers to pointers.
531   if (Loc::isLocType(castTy) && originalTy->isIntegralOrEnumerationType()) {
532     if (Optional<nonloc::LocAsInteger> LV = val.getAs<nonloc::LocAsInteger>()) {
533       if (const MemRegion *R = LV->getLoc().getAsRegion()) {
534         StoreManager &storeMgr = StateMgr.getStoreManager();
535         R = storeMgr.castRegion(R, castTy);
536         return R ? SVal(loc::MemRegionVal(R)) : UnknownVal();
537       }
538       return LV->getLoc();
539     }
540     return dispatchCast(val, castTy);
541   }
542
543   // Just pass through function and block pointers.
544   if (originalTy->isBlockPointerType() || originalTy->isFunctionPointerType()) {
545     assert(Loc::isLocType(castTy));
546     return val;
547   }
548
549   // Check for casts from array type to another type.
550   if (const ArrayType *arrayT =
551                       dyn_cast<ArrayType>(originalTy.getCanonicalType())) {
552     // We will always decay to a pointer.
553     QualType elemTy = arrayT->getElementType();
554     val = StateMgr.ArrayToPointer(val.castAs<Loc>(), elemTy);
555
556     // Are we casting from an array to a pointer?  If so just pass on
557     // the decayed value.
558     if (castTy->isPointerType() || castTy->isReferenceType())
559       return val;
560
561     // Are we casting from an array to an integer?  If so, cast the decayed
562     // pointer value to an integer.
563     assert(castTy->isIntegralOrEnumerationType());
564
565     // FIXME: Keep these here for now in case we decide soon that we
566     // need the original decayed type.
567     //    QualType elemTy = cast<ArrayType>(originalTy)->getElementType();
568     //    QualType pointerTy = C.getPointerType(elemTy);
569     return evalCastFromLoc(val.castAs<Loc>(), castTy);
570   }
571
572   // Check for casts from a region to a specific type.
573   if (const MemRegion *R = val.getAsRegion()) {
574     // Handle other casts of locations to integers.
575     if (castTy->isIntegralOrEnumerationType())
576       return evalCastFromLoc(loc::MemRegionVal(R), castTy);
577
578     // FIXME: We should handle the case where we strip off view layers to get
579     //  to a desugared type.
580     if (!Loc::isLocType(castTy)) {
581       // FIXME: There can be gross cases where one casts the result of a function
582       // (that returns a pointer) to some other value that happens to fit
583       // within that pointer value.  We currently have no good way to
584       // model such operations.  When this happens, the underlying operation
585       // is that the caller is reasoning about bits.  Conceptually we are
586       // layering a "view" of a location on top of those bits.  Perhaps
587       // we need to be more lazy about mutual possible views, even on an
588       // SVal?  This may be necessary for bit-level reasoning as well.
589       return UnknownVal();
590     }
591
592     // We get a symbolic function pointer for a dereference of a function
593     // pointer, but it is of function type. Example:
594
595     //  struct FPRec {
596     //    void (*my_func)(int * x);
597     //  };
598     //
599     //  int bar(int x);
600     //
601     //  int f1_a(struct FPRec* foo) {
602     //    int x;
603     //    (*foo->my_func)(&x);
604     //    return bar(x)+1; // no-warning
605     //  }
606
607     assert(Loc::isLocType(originalTy) || originalTy->isFunctionType() ||
608            originalTy->isBlockPointerType() || castTy->isReferenceType());
609
610     StoreManager &storeMgr = StateMgr.getStoreManager();
611
612     // Delegate to store manager to get the result of casting a region to a
613     // different type.  If the MemRegion* returned is NULL, this expression
614     // Evaluates to UnknownVal.
615     R = storeMgr.castRegion(R, castTy);
616     return R ? SVal(loc::MemRegionVal(R)) : UnknownVal();
617   }
618
619   return dispatchCast(val, castTy);
620 }