]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
Update clang to trunk r290819 and resolve conflicts.
[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   return nonloc::PointerToMember(DD);
222 }
223
224 DefinedSVal SValBuilder::getFunctionPointer(const FunctionDecl *func) {
225   return loc::MemRegionVal(MemMgr.getFunctionCodeRegion(func));
226 }
227
228 DefinedSVal SValBuilder::getBlockPointer(const BlockDecl *block,
229                                          CanQualType locTy,
230                                          const LocationContext *locContext,
231                                          unsigned blockCount) {
232   const BlockCodeRegion *BC =
233     MemMgr.getBlockCodeRegion(block, locTy, locContext->getAnalysisDeclContext());
234   const BlockDataRegion *BD = MemMgr.getBlockDataRegion(BC, locContext,
235                                                         blockCount);
236   return loc::MemRegionVal(BD);
237 }
238
239 /// Return a memory region for the 'this' object reference.
240 loc::MemRegionVal SValBuilder::getCXXThis(const CXXMethodDecl *D,
241                                           const StackFrameContext *SFC) {
242   return loc::MemRegionVal(getRegionManager().
243                            getCXXThisRegion(D->getThisType(getContext()), SFC));
244 }
245
246 /// Return a memory region for the 'this' object reference.
247 loc::MemRegionVal SValBuilder::getCXXThis(const CXXRecordDecl *D,
248                                           const StackFrameContext *SFC) {
249   const Type *T = D->getTypeForDecl();
250   QualType PT = getContext().getPointerType(QualType(T, 0));
251   return loc::MemRegionVal(getRegionManager().getCXXThisRegion(PT, SFC));
252 }
253
254 Optional<SVal> SValBuilder::getConstantVal(const Expr *E) {
255   E = E->IgnoreParens();
256
257   switch (E->getStmtClass()) {
258   // Handle expressions that we treat differently from the AST's constant
259   // evaluator.
260   case Stmt::AddrLabelExprClass:
261     return makeLoc(cast<AddrLabelExpr>(E));
262
263   case Stmt::CXXScalarValueInitExprClass:
264   case Stmt::ImplicitValueInitExprClass:
265     return makeZeroVal(E->getType());
266
267   case Stmt::ObjCStringLiteralClass: {
268     const ObjCStringLiteral *SL = cast<ObjCStringLiteral>(E);
269     return makeLoc(getRegionManager().getObjCStringRegion(SL));
270   }
271
272   case Stmt::StringLiteralClass: {
273     const StringLiteral *SL = cast<StringLiteral>(E);
274     return makeLoc(getRegionManager().getStringRegion(SL));
275   }
276
277   // Fast-path some expressions to avoid the overhead of going through the AST's
278   // constant evaluator
279   case Stmt::CharacterLiteralClass: {
280     const CharacterLiteral *C = cast<CharacterLiteral>(E);
281     return makeIntVal(C->getValue(), C->getType());
282   }
283
284   case Stmt::CXXBoolLiteralExprClass:
285     return makeBoolVal(cast<CXXBoolLiteralExpr>(E));
286
287   case Stmt::TypeTraitExprClass: {
288     const TypeTraitExpr *TE = cast<TypeTraitExpr>(E);
289     return makeTruthVal(TE->getValue(), TE->getType());
290   }
291
292   case Stmt::IntegerLiteralClass:
293     return makeIntVal(cast<IntegerLiteral>(E));
294
295   case Stmt::ObjCBoolLiteralExprClass:
296     return makeBoolVal(cast<ObjCBoolLiteralExpr>(E));
297
298   case Stmt::CXXNullPtrLiteralExprClass:
299     return makeNull();
300
301   case Stmt::ImplicitCastExprClass: {
302     const CastExpr *CE = cast<CastExpr>(E);
303     switch (CE->getCastKind()) {
304     default:
305       break;
306     case CK_ArrayToPointerDecay:
307     case CK_BitCast: {
308       const Expr *SE = CE->getSubExpr();
309       Optional<SVal> Val = getConstantVal(SE);
310       if (!Val)
311         return None;
312       return evalCast(*Val, CE->getType(), SE->getType());
313     }
314     }
315     // FALLTHROUGH
316   }
317
318   // If we don't have a special case, fall back to the AST's constant evaluator.
319   default: {
320     // Don't try to come up with a value for materialized temporaries.
321     if (E->isGLValue())
322       return None;
323
324     ASTContext &Ctx = getContext();
325     llvm::APSInt Result;
326     if (E->EvaluateAsInt(Result, Ctx))
327       return makeIntVal(Result);
328
329     if (Loc::isLocType(E->getType()))
330       if (E->isNullPointerConstant(Ctx, Expr::NPC_ValueDependentIsNotNull))
331         return makeNull();
332
333     return None;
334   }
335   }
336 }
337
338 //===----------------------------------------------------------------------===//
339
340 SVal SValBuilder::makeSymExprValNN(ProgramStateRef State,
341                                    BinaryOperator::Opcode Op,
342                                    NonLoc LHS, NonLoc RHS,
343                                    QualType ResultTy) {
344   if (!State->isTainted(RHS) && !State->isTainted(LHS))
345     return UnknownVal();
346
347   const SymExpr *symLHS = LHS.getAsSymExpr();
348   const SymExpr *symRHS = RHS.getAsSymExpr();
349   // TODO: When the Max Complexity is reached, we should conjure a symbol
350   // instead of generating an Unknown value and propagate the taint info to it.
351   const unsigned MaxComp = 10000; // 100000 28X
352
353   if (symLHS && symRHS &&
354       (symLHS->computeComplexity() + symRHS->computeComplexity()) <  MaxComp)
355     return makeNonLoc(symLHS, Op, symRHS, ResultTy);
356
357   if (symLHS && symLHS->computeComplexity() < MaxComp)
358     if (Optional<nonloc::ConcreteInt> rInt = RHS.getAs<nonloc::ConcreteInt>())
359       return makeNonLoc(symLHS, Op, rInt->getValue(), ResultTy);
360
361   if (symRHS && symRHS->computeComplexity() < MaxComp)
362     if (Optional<nonloc::ConcreteInt> lInt = LHS.getAs<nonloc::ConcreteInt>())
363       return makeNonLoc(lInt->getValue(), Op, symRHS, ResultTy);
364
365   return UnknownVal();
366 }
367
368
369 SVal SValBuilder::evalBinOp(ProgramStateRef state, BinaryOperator::Opcode op,
370                             SVal lhs, SVal rhs, QualType type) {
371
372   if (lhs.isUndef() || rhs.isUndef())
373     return UndefinedVal();
374
375   if (lhs.isUnknown() || rhs.isUnknown())
376     return UnknownVal();
377
378   if (lhs.getAs<nonloc::LazyCompoundVal>() ||
379       rhs.getAs<nonloc::LazyCompoundVal>()) {
380     return UnknownVal();
381   }
382
383   if (Optional<Loc> LV = lhs.getAs<Loc>()) {
384     if (Optional<Loc> RV = rhs.getAs<Loc>())
385       return evalBinOpLL(state, op, *LV, *RV, type);
386
387     return evalBinOpLN(state, op, *LV, rhs.castAs<NonLoc>(), type);
388   }
389
390   if (Optional<Loc> RV = rhs.getAs<Loc>()) {
391     // Support pointer arithmetic where the addend is on the left
392     // and the pointer on the right.
393     assert(op == BO_Add);
394
395     // Commute the operands.
396     return evalBinOpLN(state, op, *RV, lhs.castAs<NonLoc>(), type);
397   }
398
399   return evalBinOpNN(state, op, lhs.castAs<NonLoc>(), rhs.castAs<NonLoc>(),
400                      type);
401 }
402
403 DefinedOrUnknownSVal SValBuilder::evalEQ(ProgramStateRef state,
404                                          DefinedOrUnknownSVal lhs,
405                                          DefinedOrUnknownSVal rhs) {
406   return evalBinOp(state, BO_EQ, lhs, rhs, getConditionType())
407       .castAs<DefinedOrUnknownSVal>();
408 }
409
410 /// Recursively check if the pointer types are equal modulo const, volatile,
411 /// and restrict qualifiers. Also, assume that all types are similar to 'void'.
412 /// Assumes the input types are canonical.
413 static bool shouldBeModeledWithNoOp(ASTContext &Context, QualType ToTy,
414                                                          QualType FromTy) {
415   while (Context.UnwrapSimilarPointerTypes(ToTy, FromTy)) {
416     Qualifiers Quals1, Quals2;
417     ToTy = Context.getUnqualifiedArrayType(ToTy, Quals1);
418     FromTy = Context.getUnqualifiedArrayType(FromTy, Quals2);
419
420     // Make sure that non-cvr-qualifiers the other qualifiers (e.g., address
421     // spaces) are identical.
422     Quals1.removeCVRQualifiers();
423     Quals2.removeCVRQualifiers();
424     if (Quals1 != Quals2)
425       return false;
426   }
427
428   // If we are casting to void, the 'From' value can be used to represent the
429   // 'To' value.
430   if (ToTy->isVoidType())
431     return true;
432
433   if (ToTy != FromTy)
434     return false;
435
436   return true;
437 }
438
439 // Handles casts of type CK_IntegralCast.
440 // At the moment, this function will redirect to evalCast, except when the range
441 // of the original value is known to be greater than the max of the target type.
442 SVal SValBuilder::evalIntegralCast(ProgramStateRef state, SVal val,
443                                    QualType castTy, QualType originalTy) {
444
445   // No truncations if target type is big enough.
446   if (getContext().getTypeSize(castTy) >= getContext().getTypeSize(originalTy))
447     return evalCast(val, castTy, originalTy);
448
449   const SymExpr *se = val.getAsSymbolicExpression();
450   if (!se) // Let evalCast handle non symbolic expressions.
451     return evalCast(val, castTy, originalTy);
452
453   // Find the maximum value of the target type.
454   APSIntType ToType(getContext().getTypeSize(castTy),
455                     castTy->isUnsignedIntegerType());
456   llvm::APSInt ToTypeMax = ToType.getMaxValue();
457   NonLoc ToTypeMaxVal =
458       makeIntVal(ToTypeMax.isUnsigned() ? ToTypeMax.getZExtValue()
459                                         : ToTypeMax.getSExtValue(),
460                  castTy)
461           .castAs<NonLoc>();
462   // Check the range of the symbol being casted against the maximum value of the
463   // target type.
464   NonLoc FromVal = val.castAs<NonLoc>();
465   QualType CmpTy = getConditionType();
466   NonLoc CompVal =
467       evalBinOpNN(state, BO_LE, FromVal, ToTypeMaxVal, CmpTy).castAs<NonLoc>();
468   ProgramStateRef IsNotTruncated, IsTruncated;
469   std::tie(IsNotTruncated, IsTruncated) = state->assume(CompVal);
470   if (!IsNotTruncated && IsTruncated) {
471     // Symbol is truncated so we evaluate it as a cast.
472     NonLoc CastVal = makeNonLoc(se, originalTy, castTy);
473     return CastVal;
474   }
475   return evalCast(val, castTy, originalTy);
476 }
477
478 // FIXME: should rewrite according to the cast kind.
479 SVal SValBuilder::evalCast(SVal val, QualType castTy, QualType originalTy) {
480   castTy = Context.getCanonicalType(castTy);
481   originalTy = Context.getCanonicalType(originalTy);
482   if (val.isUnknownOrUndef() || castTy == originalTy)
483     return val;
484
485   if (castTy->isBooleanType()) {
486     if (val.isUnknownOrUndef())
487       return val;
488     if (val.isConstant())
489       return makeTruthVal(!val.isZeroConstant(), castTy);
490     if (!Loc::isLocType(originalTy) &&
491         !originalTy->isIntegralOrEnumerationType() &&
492         !originalTy->isMemberPointerType())
493       return UnknownVal();
494     if (SymbolRef Sym = val.getAsSymbol(true)) {
495       BasicValueFactory &BVF = getBasicValueFactory();
496       // FIXME: If we had a state here, we could see if the symbol is known to
497       // be zero, but we don't.
498       return makeNonLoc(Sym, BO_NE, BVF.getValue(0, Sym->getType()), castTy);
499     }
500     // Loc values are not always true, they could be weakly linked functions.
501     if (Optional<Loc> L = val.getAs<Loc>())
502       return evalCastFromLoc(*L, castTy);
503
504     Loc L = val.castAs<nonloc::LocAsInteger>().getLoc();
505     return evalCastFromLoc(L, castTy);
506   }
507
508   // For const casts, casts to void, just propagate the value.
509   if (!castTy->isVariableArrayType() && !originalTy->isVariableArrayType())
510     if (shouldBeModeledWithNoOp(Context, Context.getPointerType(castTy),
511                                          Context.getPointerType(originalTy)))
512       return val;
513
514   // Check for casts from pointers to integers.
515   if (castTy->isIntegralOrEnumerationType() && Loc::isLocType(originalTy))
516     return evalCastFromLoc(val.castAs<Loc>(), castTy);
517
518   // Check for casts from integers to pointers.
519   if (Loc::isLocType(castTy) && originalTy->isIntegralOrEnumerationType()) {
520     if (Optional<nonloc::LocAsInteger> LV = val.getAs<nonloc::LocAsInteger>()) {
521       if (const MemRegion *R = LV->getLoc().getAsRegion()) {
522         StoreManager &storeMgr = StateMgr.getStoreManager();
523         R = storeMgr.castRegion(R, castTy);
524         return R ? SVal(loc::MemRegionVal(R)) : UnknownVal();
525       }
526       return LV->getLoc();
527     }
528     return dispatchCast(val, castTy);
529   }
530
531   // Just pass through function and block pointers.
532   if (originalTy->isBlockPointerType() || originalTy->isFunctionPointerType()) {
533     assert(Loc::isLocType(castTy));
534     return val;
535   }
536
537   // Check for casts from array type to another type.
538   if (const ArrayType *arrayT =
539                       dyn_cast<ArrayType>(originalTy.getCanonicalType())) {
540     // We will always decay to a pointer.
541     QualType elemTy = arrayT->getElementType();
542     val = StateMgr.ArrayToPointer(val.castAs<Loc>(), elemTy);
543
544     // Are we casting from an array to a pointer?  If so just pass on
545     // the decayed value.
546     if (castTy->isPointerType() || castTy->isReferenceType())
547       return val;
548
549     // Are we casting from an array to an integer?  If so, cast the decayed
550     // pointer value to an integer.
551     assert(castTy->isIntegralOrEnumerationType());
552
553     // FIXME: Keep these here for now in case we decide soon that we
554     // need the original decayed type.
555     //    QualType elemTy = cast<ArrayType>(originalTy)->getElementType();
556     //    QualType pointerTy = C.getPointerType(elemTy);
557     return evalCastFromLoc(val.castAs<Loc>(), castTy);
558   }
559
560   // Check for casts from a region to a specific type.
561   if (const MemRegion *R = val.getAsRegion()) {
562     // Handle other casts of locations to integers.
563     if (castTy->isIntegralOrEnumerationType())
564       return evalCastFromLoc(loc::MemRegionVal(R), castTy);
565
566     // FIXME: We should handle the case where we strip off view layers to get
567     //  to a desugared type.
568     if (!Loc::isLocType(castTy)) {
569       // FIXME: There can be gross cases where one casts the result of a function
570       // (that returns a pointer) to some other value that happens to fit
571       // within that pointer value.  We currently have no good way to
572       // model such operations.  When this happens, the underlying operation
573       // is that the caller is reasoning about bits.  Conceptually we are
574       // layering a "view" of a location on top of those bits.  Perhaps
575       // we need to be more lazy about mutual possible views, even on an
576       // SVal?  This may be necessary for bit-level reasoning as well.
577       return UnknownVal();
578     }
579
580     // We get a symbolic function pointer for a dereference of a function
581     // pointer, but it is of function type. Example:
582
583     //  struct FPRec {
584     //    void (*my_func)(int * x);
585     //  };
586     //
587     //  int bar(int x);
588     //
589     //  int f1_a(struct FPRec* foo) {
590     //    int x;
591     //    (*foo->my_func)(&x);
592     //    return bar(x)+1; // no-warning
593     //  }
594
595     assert(Loc::isLocType(originalTy) || originalTy->isFunctionType() ||
596            originalTy->isBlockPointerType() || castTy->isReferenceType());
597
598     StoreManager &storeMgr = StateMgr.getStoreManager();
599
600     // Delegate to store manager to get the result of casting a region to a
601     // different type.  If the MemRegion* returned is NULL, this expression
602     // Evaluates to UnknownVal.
603     R = storeMgr.castRegion(R, castTy);
604     return R ? SVal(loc::MemRegionVal(R)) : UnknownVal();
605   }
606
607   return dispatchCast(val, castTy);
608 }