clang  3.9.0
SValBuilder.cpp
Go to the documentation of this file.
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 
16 #include "clang/AST/DeclCXX.h"
17 #include "clang/AST/ExprCXX.h"
22 
23 using namespace clang;
24 using namespace ento;
25 
26 //===----------------------------------------------------------------------===//
27 // Basic SVal creation.
28 //===----------------------------------------------------------------------===//
29 
30 void SValBuilder::anchor() { }
31 
33  if (Loc::isLocType(type))
34  return makeNull();
35 
36  if (type->isIntegralOrEnumerationType())
37  return makeIntVal(0, type);
38 
39  // FIXME: Handle floats.
40  // FIXME: Handle structs.
41  return UnknownVal();
42 }
43 
45  const llvm::APSInt& rhs, QualType type) {
46  // The Environment ensures we always get a persistent APSInt in
47  // BasicValueFactory, so we don't need to get the APSInt from
48  // BasicValueFactory again.
49  assert(lhs);
50  assert(!Loc::isLocType(type));
51  return nonloc::SymbolVal(SymMgr.getSymIntExpr(lhs, op, rhs, type));
52 }
53 
54 NonLoc SValBuilder::makeNonLoc(const llvm::APSInt& lhs,
55  BinaryOperator::Opcode op, const SymExpr *rhs,
56  QualType type) {
57  assert(rhs);
58  assert(!Loc::isLocType(type));
59  return nonloc::SymbolVal(SymMgr.getIntSymExpr(lhs, op, rhs, type));
60 }
61 
63  const SymExpr *rhs, QualType type) {
64  assert(lhs && rhs);
65  assert(!Loc::isLocType(type));
66  return nonloc::SymbolVal(SymMgr.getSymSymExpr(lhs, op, rhs, type));
67 }
68 
70  QualType fromTy, QualType toTy) {
71  assert(operand);
72  assert(!Loc::isLocType(toTy));
73  return nonloc::SymbolVal(SymMgr.getCastSymbol(operand, fromTy, toTy));
74 }
75 
77  if (val.isUnknownOrUndef())
78  return val;
79 
80  // Common case: we have an appropriately sized integer.
82  const llvm::APSInt& I = CI->getValue();
83  if (I.getBitWidth() == ArrayIndexWidth && I.isSigned())
84  return val;
85  }
86 
88 }
89 
91  return makeTruthVal(boolean->getValue());
92 }
93 
96  QualType T = region->getValueType();
97 
98  if (T->isNullPtrType())
99  return makeZeroVal(T);
100 
102  return UnknownVal();
103 
104  SymbolRef sym = SymMgr.getRegionValueSymbol(region);
105 
106  if (Loc::isLocType(T))
108 
109  return nonloc::SymbolVal(sym);
110 }
111 
113  const Expr *Ex,
114  const LocationContext *LCtx,
115  unsigned Count) {
116  QualType T = Ex->getType();
117 
118  if (T->isNullPtrType())
119  return makeZeroVal(T);
120 
121  // Compute the type of the result. If the expression is not an R-value, the
122  // result should be a location.
123  QualType ExType = Ex->getType();
124  if (Ex->isGLValue())
125  T = LCtx->getAnalysisDeclContext()->getASTContext().getPointerType(ExType);
126 
127  return conjureSymbolVal(SymbolTag, Ex, LCtx, T, Count);
128 }
129 
131  const Expr *expr,
132  const LocationContext *LCtx,
133  QualType type,
134  unsigned count) {
135  if (type->isNullPtrType())
136  return makeZeroVal(type);
137 
139  return UnknownVal();
140 
141  SymbolRef sym = SymMgr.conjureSymbol(expr, LCtx, type, count, symbolTag);
142 
143  if (Loc::isLocType(type))
145 
146  return nonloc::SymbolVal(sym);
147 }
148 
149 
151  const LocationContext *LCtx,
152  QualType type,
153  unsigned visitCount) {
154  if (type->isNullPtrType())
155  return makeZeroVal(type);
156 
158  return UnknownVal();
159 
160  SymbolRef sym = SymMgr.conjureSymbol(stmt, LCtx, type, visitCount);
161 
162  if (Loc::isLocType(type))
164 
165  return nonloc::SymbolVal(sym);
166 }
167 
170  const LocationContext *LCtx,
171  unsigned VisitCount) {
172  QualType T = E->getType();
173  assert(Loc::isLocType(T));
175  if (T->isNullPtrType())
176  return makeZeroVal(T);
177 
178  SymbolRef sym = SymMgr.conjureSymbol(E, LCtx, T, VisitCount);
180 }
181 
183  const MemRegion *region,
184  const Expr *expr, QualType type,
185  unsigned count) {
186  assert(SymbolManager::canSymbolicate(type) && "Invalid metadata symbol type");
187 
188  SymbolRef sym =
189  SymMgr.getMetadataSymbol(region, expr, type, count, symbolTag);
190 
191  if (Loc::isLocType(type))
193 
194  return nonloc::SymbolVal(sym);
195 }
196 
199  const TypedValueRegion *region) {
200  QualType T = region->getValueType();
201 
202  if (T->isNullPtrType())
203  return makeZeroVal(T);
204 
206  return UnknownVal();
207 
208  SymbolRef sym = SymMgr.getDerivedSymbol(parentSymbol, region);
209 
210  if (Loc::isLocType(T))
212 
213  return nonloc::SymbolVal(sym);
214 }
215 
218 }
219 
221  CanQualType locTy,
222  const LocationContext *locContext,
223  unsigned blockCount) {
224  const BlockCodeRegion *BC =
225  MemMgr.getBlockCodeRegion(block, locTy, locContext->getAnalysisDeclContext());
226  const BlockDataRegion *BD = MemMgr.getBlockDataRegion(BC, locContext,
227  blockCount);
228  return loc::MemRegionVal(BD);
229 }
230 
231 /// Return a memory region for the 'this' object reference.
233  const StackFrameContext *SFC) {
235  getCXXThisRegion(D->getThisType(getContext()), SFC));
236 }
237 
238 /// Return a memory region for the 'this' object reference.
240  const StackFrameContext *SFC) {
241  const Type *T = D->getTypeForDecl();
243  return loc::MemRegionVal(getRegionManager().getCXXThisRegion(PT, SFC));
244 }
245 
247  E = E->IgnoreParens();
248 
249  switch (E->getStmtClass()) {
250  // Handle expressions that we treat differently from the AST's constant
251  // evaluator.
252  case Stmt::AddrLabelExprClass:
253  return makeLoc(cast<AddrLabelExpr>(E));
254 
255  case Stmt::CXXScalarValueInitExprClass:
256  case Stmt::ImplicitValueInitExprClass:
257  return makeZeroVal(E->getType());
258 
259  case Stmt::ObjCStringLiteralClass: {
260  const ObjCStringLiteral *SL = cast<ObjCStringLiteral>(E);
261  return makeLoc(getRegionManager().getObjCStringRegion(SL));
262  }
263 
264  case Stmt::StringLiteralClass: {
265  const StringLiteral *SL = cast<StringLiteral>(E);
266  return makeLoc(getRegionManager().getStringRegion(SL));
267  }
268 
269  // Fast-path some expressions to avoid the overhead of going through the AST's
270  // constant evaluator
271  case Stmt::CharacterLiteralClass: {
272  const CharacterLiteral *C = cast<CharacterLiteral>(E);
273  return makeIntVal(C->getValue(), C->getType());
274  }
275 
276  case Stmt::CXXBoolLiteralExprClass:
277  return makeBoolVal(cast<CXXBoolLiteralExpr>(E));
278 
279  case Stmt::TypeTraitExprClass: {
280  const TypeTraitExpr *TE = cast<TypeTraitExpr>(E);
281  return makeTruthVal(TE->getValue(), TE->getType());
282  }
283 
284  case Stmt::IntegerLiteralClass:
285  return makeIntVal(cast<IntegerLiteral>(E));
286 
287  case Stmt::ObjCBoolLiteralExprClass:
288  return makeBoolVal(cast<ObjCBoolLiteralExpr>(E));
289 
290  case Stmt::CXXNullPtrLiteralExprClass:
291  return makeNull();
292 
293  case Stmt::ImplicitCastExprClass: {
294  const CastExpr *CE = cast<CastExpr>(E);
295  switch (CE->getCastKind()) {
296  default:
297  break;
298  case CK_ArrayToPointerDecay:
299  case CK_BitCast: {
300  const Expr *SE = CE->getSubExpr();
301  Optional<SVal> Val = getConstantVal(SE);
302  if (!Val)
303  return None;
304  return evalCast(*Val, CE->getType(), SE->getType());
305  }
306  }
307  // FALLTHROUGH
308  }
309 
310  // If we don't have a special case, fall back to the AST's constant evaluator.
311  default: {
312  // Don't try to come up with a value for materialized temporaries.
313  if (E->isGLValue())
314  return None;
315 
316  ASTContext &Ctx = getContext();
317  llvm::APSInt Result;
318  if (E->EvaluateAsInt(Result, Ctx))
319  return makeIntVal(Result);
320 
321  if (Loc::isLocType(E->getType()))
323  return makeNull();
324 
325  return None;
326  }
327  }
328 }
329 
330 //===----------------------------------------------------------------------===//
331 
334  NonLoc LHS, NonLoc RHS,
335  QualType ResultTy) {
336  if (!State->isTainted(RHS) && !State->isTainted(LHS))
337  return UnknownVal();
338 
339  const SymExpr *symLHS = LHS.getAsSymExpr();
340  const SymExpr *symRHS = RHS.getAsSymExpr();
341  // TODO: When the Max Complexity is reached, we should conjure a symbol
342  // instead of generating an Unknown value and propagate the taint info to it.
343  const unsigned MaxComp = 10000; // 100000 28X
344 
345  if (symLHS && symRHS &&
346  (symLHS->computeComplexity() + symRHS->computeComplexity()) < MaxComp)
347  return makeNonLoc(symLHS, Op, symRHS, ResultTy);
348 
349  if (symLHS && symLHS->computeComplexity() < MaxComp)
351  return makeNonLoc(symLHS, Op, rInt->getValue(), ResultTy);
352 
353  if (symRHS && symRHS->computeComplexity() < MaxComp)
355  return makeNonLoc(lInt->getValue(), Op, symRHS, ResultTy);
356 
357  return UnknownVal();
358 }
359 
360 
362  SVal lhs, SVal rhs, QualType type) {
363 
364  if (lhs.isUndef() || rhs.isUndef())
365  return UndefinedVal();
366 
367  if (lhs.isUnknown() || rhs.isUnknown())
368  return UnknownVal();
369 
370  if (lhs.getAs<nonloc::LazyCompoundVal>() ||
372  return UnknownVal();
373  }
374 
375  if (Optional<Loc> LV = lhs.getAs<Loc>()) {
376  if (Optional<Loc> RV = rhs.getAs<Loc>())
377  return evalBinOpLL(state, op, *LV, *RV, type);
378 
379  return evalBinOpLN(state, op, *LV, rhs.castAs<NonLoc>(), type);
380  }
381 
382  if (Optional<Loc> RV = rhs.getAs<Loc>()) {
383  // Support pointer arithmetic where the addend is on the left
384  // and the pointer on the right.
385  assert(op == BO_Add);
386 
387  // Commute the operands.
388  return evalBinOpLN(state, op, *RV, lhs.castAs<NonLoc>(), type);
389  }
390 
391  return evalBinOpNN(state, op, lhs.castAs<NonLoc>(), rhs.castAs<NonLoc>(),
392  type);
393 }
394 
397  DefinedOrUnknownSVal rhs) {
398  return evalBinOp(state, BO_EQ, lhs, rhs, getConditionType())
400 }
401 
402 /// Recursively check if the pointer types are equal modulo const, volatile,
403 /// and restrict qualifiers. Also, assume that all types are similar to 'void'.
404 /// Assumes the input types are canonical.
406  QualType FromTy) {
407  while (Context.UnwrapSimilarPointerTypes(ToTy, FromTy)) {
408  Qualifiers Quals1, Quals2;
409  ToTy = Context.getUnqualifiedArrayType(ToTy, Quals1);
410  FromTy = Context.getUnqualifiedArrayType(FromTy, Quals2);
411 
412  // Make sure that non-cvr-qualifiers the other qualifiers (e.g., address
413  // spaces) are identical.
414  Quals1.removeCVRQualifiers();
415  Quals2.removeCVRQualifiers();
416  if (Quals1 != Quals2)
417  return false;
418  }
419 
420  // If we are casting to void, the 'From' value can be used to represent the
421  // 'To' value.
422  if (ToTy->isVoidType())
423  return true;
424 
425  if (ToTy != FromTy)
426  return false;
427 
428  return true;
429 }
430 
431 // Handles casts of type CK_IntegralCast.
432 // At the moment, this function will redirect to evalCast, except when the range
433 // of the original value is known to be greater than the max of the target type.
435  QualType castTy, QualType originalTy) {
436 
437  // No truncations if target type is big enough.
438  if (getContext().getTypeSize(castTy) >= getContext().getTypeSize(originalTy))
439  return evalCast(val, castTy, originalTy);
440 
441  const SymExpr *se = val.getAsSymbolicExpression();
442  if (!se) // Let evalCast handle non symbolic expressions.
443  return evalCast(val, castTy, originalTy);
444 
445  // Find the maximum value of the target type.
446  APSIntType ToType(getContext().getTypeSize(castTy),
447  castTy->isUnsignedIntegerType());
448  llvm::APSInt ToTypeMax = ToType.getMaxValue();
449  NonLoc ToTypeMaxVal =
450  makeIntVal(ToTypeMax.isUnsigned() ? ToTypeMax.getZExtValue()
451  : ToTypeMax.getSExtValue(),
452  castTy)
453  .castAs<NonLoc>();
454  // Check the range of the symbol being casted against the maximum value of the
455  // target type.
456  NonLoc FromVal = val.castAs<NonLoc>();
457  QualType CmpTy = getConditionType();
458  NonLoc CompVal =
459  evalBinOpNN(state, BO_LE, FromVal, ToTypeMaxVal, CmpTy).castAs<NonLoc>();
460  ProgramStateRef IsNotTruncated, IsTruncated;
461  std::tie(IsNotTruncated, IsTruncated) = state->assume(CompVal);
462  if (!IsNotTruncated && IsTruncated) {
463  // Symbol is truncated so we evaluate it as a cast.
464  NonLoc CastVal = makeNonLoc(se, originalTy, castTy);
465  return CastVal;
466  }
467  return evalCast(val, castTy, originalTy);
468 }
469 
470 // FIXME: should rewrite according to the cast kind.
471 SVal SValBuilder::evalCast(SVal val, QualType castTy, QualType originalTy) {
472  castTy = Context.getCanonicalType(castTy);
473  originalTy = Context.getCanonicalType(originalTy);
474  if (val.isUnknownOrUndef() || castTy == originalTy)
475  return val;
476 
477  if (castTy->isBooleanType()) {
478  if (val.isUnknownOrUndef())
479  return val;
480  if (val.isConstant())
481  return makeTruthVal(!val.isZeroConstant(), castTy);
482  if (!Loc::isLocType(originalTy) &&
483  !originalTy->isIntegralOrEnumerationType() &&
484  !originalTy->isMemberPointerType())
485  return UnknownVal();
486  if (SymbolRef Sym = val.getAsSymbol(true)) {
488  // FIXME: If we had a state here, we could see if the symbol is known to
489  // be zero, but we don't.
490  return makeNonLoc(Sym, BO_NE, BVF.getValue(0, Sym->getType()), castTy);
491  }
492  // Loc values are not always true, they could be weakly linked functions.
493  if (Optional<Loc> L = val.getAs<Loc>())
494  return evalCastFromLoc(*L, castTy);
495 
496  Loc L = val.castAs<nonloc::LocAsInteger>().getLoc();
497  return evalCastFromLoc(L, castTy);
498  }
499 
500  // For const casts, casts to void, just propagate the value.
501  if (!castTy->isVariableArrayType() && !originalTy->isVariableArrayType())
503  Context.getPointerType(originalTy)))
504  return val;
505 
506  // Check for casts from pointers to integers.
507  if (castTy->isIntegralOrEnumerationType() && Loc::isLocType(originalTy))
508  return evalCastFromLoc(val.castAs<Loc>(), castTy);
509 
510  // Check for casts from integers to pointers.
511  if (Loc::isLocType(castTy) && originalTy->isIntegralOrEnumerationType()) {
513  if (const MemRegion *R = LV->getLoc().getAsRegion()) {
514  StoreManager &storeMgr = StateMgr.getStoreManager();
515  R = storeMgr.castRegion(R, castTy);
516  return R ? SVal(loc::MemRegionVal(R)) : UnknownVal();
517  }
518  return LV->getLoc();
519  }
520  return dispatchCast(val, castTy);
521  }
522 
523  // Just pass through function and block pointers.
524  if (originalTy->isBlockPointerType() || originalTy->isFunctionPointerType()) {
525  assert(Loc::isLocType(castTy));
526  return val;
527  }
528 
529  // Check for casts from array type to another type.
530  if (const ArrayType *arrayT =
531  dyn_cast<ArrayType>(originalTy.getCanonicalType())) {
532  // We will always decay to a pointer.
533  QualType elemTy = arrayT->getElementType();
534  val = StateMgr.ArrayToPointer(val.castAs<Loc>(), elemTy);
535 
536  // Are we casting from an array to a pointer? If so just pass on
537  // the decayed value.
538  if (castTy->isPointerType() || castTy->isReferenceType())
539  return val;
540 
541  // Are we casting from an array to an integer? If so, cast the decayed
542  // pointer value to an integer.
543  assert(castTy->isIntegralOrEnumerationType());
544 
545  // FIXME: Keep these here for now in case we decide soon that we
546  // need the original decayed type.
547  // QualType elemTy = cast<ArrayType>(originalTy)->getElementType();
548  // QualType pointerTy = C.getPointerType(elemTy);
549  return evalCastFromLoc(val.castAs<Loc>(), castTy);
550  }
551 
552  // Check for casts from a region to a specific type.
553  if (const MemRegion *R = val.getAsRegion()) {
554  // Handle other casts of locations to integers.
555  if (castTy->isIntegralOrEnumerationType())
556  return evalCastFromLoc(loc::MemRegionVal(R), castTy);
557 
558  // FIXME: We should handle the case where we strip off view layers to get
559  // to a desugared type.
560  if (!Loc::isLocType(castTy)) {
561  // FIXME: There can be gross cases where one casts the result of a function
562  // (that returns a pointer) to some other value that happens to fit
563  // within that pointer value. We currently have no good way to
564  // model such operations. When this happens, the underlying operation
565  // is that the caller is reasoning about bits. Conceptually we are
566  // layering a "view" of a location on top of those bits. Perhaps
567  // we need to be more lazy about mutual possible views, even on an
568  // SVal? This may be necessary for bit-level reasoning as well.
569  return UnknownVal();
570  }
571 
572  // We get a symbolic function pointer for a dereference of a function
573  // pointer, but it is of function type. Example:
574 
575  // struct FPRec {
576  // void (*my_func)(int * x);
577  // };
578  //
579  // int bar(int x);
580  //
581  // int f1_a(struct FPRec* foo) {
582  // int x;
583  // (*foo->my_func)(&x);
584  // return bar(x)+1; // no-warning
585  // }
586 
587  assert(Loc::isLocType(originalTy) || originalTy->isFunctionType() ||
588  originalTy->isBlockPointerType() || castTy->isReferenceType());
589 
590  StoreManager &storeMgr = StateMgr.getStoreManager();
591 
592  // Delegate to store manager to get the result of casting a region to a
593  // different type. If the MemRegion* returned is NULL, this expression
594  // Evaluates to UnknownVal.
595  R = storeMgr.castRegion(R, castTy);
596  return R ? SVal(loc::MemRegionVal(R)) : UnknownVal();
597  }
598 
599  return dispatchCast(val, castTy);
600 }
const SymExpr * getAsSymExpr() const
Definition: SVals.cpp:128
CastKind getCastKind() const
Definition: Expr.h:2680
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Definition: Decl.h:1561
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
Definition: ASTMatchers.h:1367
TypedValueRegion - An abstract class representing regions having a typed value.
Definition: MemRegion.h:494
nonloc::ConcreteInt makeIntVal(const IntegerLiteral *integer)
Definition: SValBuilder.h:237
bool isNullPtrType() const
Definition: Type.h:5693
DefinedSVal getBlockPointer(const BlockDecl *block, CanQualType locTy, const LocationContext *locContext, unsigned blockCount)
ASTContext & getASTContext() const
A (possibly-)qualified type.
Definition: Type.h:598
MemRegion - The root abstract class for all memory regions.
Definition: MemRegion.h:79
bool getValue() const
Definition: ExprCXX.h:483
bool isMemberPointerType() const
Definition: Type.h:5506
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition: ExprCXX.h:2272
const internal::VariadicAllOfMatcher< Stmt > stmt
Matches statements.
Definition: ASTMatchers.h:985
const IntSymExpr * getIntSymExpr(const llvm::APSInt &lhs, BinaryOperator::Opcode op, const SymExpr *rhs, QualType t)
BlockCodeRegion - A region that represents code texts of blocks (closures).
Definition: MemRegion.h:586
virtual QualType getValueType() const =0
SVal makeSymExprValNN(ProgramStateRef state, BinaryOperator::Opcode op, NonLoc lhs, NonLoc rhs, QualType resultTy)
Constructs a symbolic expression for two non-location values.
ProgramStateManager & StateMgr
Definition: SValBuilder.h:46
The base class of the type hierarchy.
Definition: Type.h:1281
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:2456
bool isBooleanType() const
Definition: Type.h:5743
bool isBlockPointerType() const
Definition: Type.h:5488
SVal evalCast(SVal val, QualType castTy, QualType originalType)
Value representing integer constant.
Definition: SVals.h:341
MemRegionManager MemMgr
Manages the creation of memory regions.
Definition: SValBuilder.h:44
virtual SVal dispatchCast(SVal val, QualType castTy)=0
loc::MemRegionVal getCXXThis(const CXXMethodDecl *D, const StackFrameContext *SFC)
Return a memory region for the 'this' object reference.
NonLoc makeNonLoc(const SymExpr *lhs, BinaryOperator::Opcode op, const llvm::APSInt &rhs, QualType type)
Definition: SValBuilder.cpp:44
QualType getThisType(ASTContext &C) const
Returns the type of the this pointer.
Definition: DeclCXX.cpp:1672
unsigned getValue() const
Definition: Expr.h:1338
NullPointerConstantKind isNullPointerConstant(ASTContext &Ctx, NullPointerConstantValueDependence NPC) const
isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to a Null pointer constant...
Definition: Expr.cpp:3132
bool isZeroConstant() const
Definition: SVals.cpp:186
Defines the clang::Expr interface and subclasses for C++ expressions.
bool isVoidType() const
Definition: Type.h:5680
The collection of all-type qualifiers we support.
Definition: Type.h:117
const MemRegion * castRegion(const MemRegion *region, QualType CastToTy)
castRegion - Used by ExprEngine::VisitCast to handle casts from a MemRegion* to a specific location t...
Definition: Store.cpp:62
Symbolic value.
Definition: SymExpr.h:29
const SymbolDerived * getDerivedSymbol(SymbolRef parentSymbol, const TypedValueRegion *R)
virtual SVal evalCastFromNonLoc(NonLoc val, QualType castTy)=0
virtual SVal evalBinOpLN(ProgramStateRef state, BinaryOperator::Opcode op, Loc lhs, NonLoc rhs, QualType resultTy)=0
Create a new value which represents a binary expression with a memory location and non-location opera...
MemRegionManager & getRegionManager()
Definition: SValBuilder.h:145
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:92
LineState State
unsigned computeComplexity() const
SVal evalIntegralCast(ProgramStateRef state, SVal val, QualType castTy, QualType originalType)
bool isReferenceType() const
Definition: Type.h:5491
static bool canSymbolicate(QualType T)
AnalysisDeclContext * getAnalysisDeclContext() const
DefinedOrUnknownSVal getDerivedRegionValueSymbolVal(SymbolRef parentSymbol, const TypedValueRegion *region)
Expr * getSubExpr()
Definition: Expr.h:2684
i32 captured_struct **param SharedsTy A type which contains references the shared variables *param Shareds Context with the list of shared variables from the p *TaskFunction *param Data Additional data for task generation like final * state
const SymbolicRegion * getSymbolicRegion(SymbolRef Sym)
Retrieve or create a "symbolic" memory region.
Definition: MemRegion.cpp:995
static bool isLocType(QualType T)
Definition: SVals.h:291
BinaryOperatorKind
BlockDataRegion - A region that represents a block instance.
Definition: MemRegion.h:627
bool UnwrapSimilarPointerTypes(QualType &T1, QualType &T2)
UnwrapSimilarPointerTypes - If T1 and T2 are pointer types that may be similar (C++ 4...
bool isUnknownOrUndef() const
Definition: SVals.h:125
const SymIntExpr * getSymIntExpr(const SymExpr *lhs, BinaryOperator::Opcode op, const llvm::APSInt &rhs, QualType t)
DefinedOrUnknownSVal getRegionValueSymbolVal(const TypedValueRegion *region)
Make a unique symbol for value of region.
Definition: SValBuilder.cpp:95
bool isUnsignedIntegerType() const
Return true if this is an integer type that is unsigned, according to C99 6.2.5p6 [which returns true...
Definition: Type.cpp:1746
A record of the "type" of an APSInt, used for conversions.
Definition: APSIntType.h:20
ObjCStringLiteral, used for Objective-C string literals i.e.
Definition: ExprObjC.h:29
DefinedSVal getFunctionPointer(const FunctionDecl *func)
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition: Expr.h:2632
bool isConstant() const
Definition: SVals.cpp:174
detail::InMemoryDirectory::const_iterator I
const BlockCodeRegion * getBlockCodeRegion(const BlockDecl *BD, CanQualType locTy, AnalysisDeclContext *AC)
Definition: MemRegion.cpp:988
ASTContext * Context
nonloc::ConcreteInt makeBoolVal(const ObjCBoolLiteralExpr *boolean)
Definition: SValBuilder.h:243
Loc makeLoc(SymbolRef sym)
Definition: SValBuilder.h:305
bool isFunctionPointerType() const
Definition: Type.h:5500
DefinedOrUnknownSVal makeZeroVal(QualType type)
Construct an SVal representing '0' for the specified type.
Definition: SValBuilder.cpp:32
const Type * getTypeForDecl() const
Definition: Decl.h:2590
BlockDecl - This represents a block literal declaration, which is like an unnamed FunctionDecl...
Definition: Decl.h:3456
Expr - This represents one expression.
Definition: Expr.h:105
bool getValue() const
Definition: ExprCXX.h:2311
Optional< T > getAs() const
Convert to the specified SVal type, returning None if this SVal is not of the desired type...
Definition: SVals.h:86
bool isVariableArrayType() const
Definition: Type.h:5530
const QualType ArrayIndexTy
The scalar type to use for array indices.
Definition: SValBuilder.h:49
virtual SVal evalBinOpLL(ProgramStateRef state, BinaryOperator::Opcode op, Loc lhs, Loc rhs, QualType resultTy)=0
Create a new value which represents a binary expression with two memory location operands.
bool EvaluateAsInt(llvm::APSInt &Result, const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects) const
EvaluateAsInt - Return true if this is a constant which we can fold and convert to an integer...
SVal evalBinOp(ProgramStateRef state, BinaryOperator::Opcode op, SVal lhs, SVal rhs, QualType type)
bool isGLValue() const
Definition: Expr.h:250
The result type of a method or function.
QualType getConditionType() const
Definition: SValBuilder.h:131
void removeCVRQualifiers(unsigned mask)
Definition: Type.h:263
const SymbolCast * getCastSymbol(const SymExpr *Operand, QualType From, QualType To)
llvm::APSInt getMaxValue() const LLVM_READONLY
Returns the maximum value for this type.
Definition: APSIntType.h:66
const SymSymExpr * getSymSymExpr(const SymExpr *lhs, BinaryOperator::Opcode op, const SymExpr *rhs, QualType t)
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
Definition: Type.h:5730
SymbolManager SymMgr
Manages the creation of symbols.
Definition: SValBuilder.h:41
DefinedOrUnknownSVal conjureSymbolVal(const void *symbolTag, const Expr *expr, const LocationContext *LCtx, unsigned count)
Create a new symbol with a unique 'name'.
virtual SVal evalCastFromLoc(Loc val, QualType castTy)=0
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:1736
ASTContext & getContext()
Definition: SValBuilder.h:126
const SymbolRegionValue * getRegionValueSymbol(const TypedValueRegion *R)
Make a unique symbol for MemRegion R according to its kind.
const SymbolMetadata * getMetadataSymbol(const MemRegion *R, const Stmt *S, QualType T, unsigned VisitCount, const void *SymbolTag=nullptr)
Creates a metadata symbol associated with a specific region.
SVal - This represents a symbolic expression, which can be either an L-value or an R-value...
Definition: SVals.h:46
Specifies that a value-dependent expression should be considered to never be a null pointer constant...
Definition: Expr.h:696
static bool shouldBeModeledWithNoOp(ASTContext &Context, QualType ToTy, QualType FromTy)
Recursively check if the pointer types are equal modulo const, volatile, and restrict qualifiers...
bool isUndef() const
Definition: SVals.h:121
DefinedOrUnknownSVal getConjuredHeapSymbolVal(const Expr *E, const LocationContext *LCtx, unsigned Count)
Conjure a symbol representing heap allocated memory region.
virtual SVal evalBinOpNN(ProgramStateRef state, BinaryOperator::Opcode op, NonLoc lhs, NonLoc rhs, QualType resultTy)=0
Create a new value which represents a binary expression with two non- location operands.
const unsigned ArrayIndexWidth
The width of the scalar type used for array indices.
Definition: SValBuilder.h:52
QualType getType() const
Definition: Expr.h:126
const SymbolicRegion * getSymbolicHeapRegion(SymbolRef sym)
Return a unique symbolic region belonging to heap memory space.
Definition: MemRegion.cpp:999
SVal ArrayToPointer(Loc Array, QualType ElementTy)
Definition: ProgramState.h:527
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
Definition: ASTMatchers.h:1983
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
DefinedSVal getMetadataSymbolVal(const void *symbolTag, const MemRegion *region, const Expr *expr, QualType type, unsigned count)
Represents symbolic expression.
Definition: SVals.h:315
detail::InMemoryDirectory::const_iterator E
const MemRegion * getAsRegion() const
Definition: SVals.cpp:135
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:1966
SVal convertToArrayIndex(SVal val)
Definition: SValBuilder.cpp:76
const SymbolConjured * conjureSymbol(const Stmt *E, const LocationContext *LCtx, QualType T, unsigned VisitCount, const void *SymbolTag=nullptr)
const FunctionCodeRegion * getFunctionCodeRegion(const NamedDecl *FD)
Definition: MemRegion.cpp:983
BasicValueFactory & getBasicValueFactory()
Definition: SValBuilder.h:139
QualType getCanonicalType() const
Definition: Type.h:5298
bool isUnknown() const
Definition: SVals.h:117
bool isFunctionType() const
Definition: Type.h:5479
const BlockDataRegion * getBlockDataRegion(const BlockCodeRegion *bc, const LocationContext *lc, unsigned blockCount)
getBlockDataRegion - Get the memory region associated with an instance of a block.
Definition: MemRegion.cpp:911
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
Represents a C++ struct/union/class.
Definition: DeclCXX.h:263
DefinedOrUnknownSVal evalEQ(ProgramStateRef state, DefinedOrUnknownSVal lhs, DefinedOrUnknownSVal rhs)
Optional< SVal > getConstantVal(const Expr *E)
Returns the value of E, if it can be determined in a non-path-sensitive manner.
SymbolRef getAsSymbol(bool IncludeBaseRegions=false) const
If this SVal wraps a symbol return that SymbolRef.
Definition: SVals.cpp:111
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1466
const SymExpr * getAsSymbolicExpression() const
getAsSymbolicExpression - If this Sval wraps a symbolic expression then return that expression...
Definition: SVals.cpp:121
nonloc::ConcreteInt makeTruthVal(bool b, QualType type)
Definition: SValBuilder.h:293
A boolean literal, per ([C++ lex.bool] Boolean literals).
Definition: ExprCXX.h:471
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
Definition: SVals.h:75
QualType getUnqualifiedArrayType(QualType T, Qualifiers &Quals)
Return this type as a completely-unqualified array type, capturing the qualifiers in Quals...
Expr * IgnoreParens() LLVM_READONLY
IgnoreParens - Ignore parentheses.
Definition: Expr.cpp:2295
bool isPointerType() const
Definition: Type.h:5482