clang 8.0.0

Store.cpp
Go to the documentation of this file.
1 //===- Store.cpp - Interface for maps from Locations to Values ------------===//
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 defined the types Store and StoreManager.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "clang/StaticAnalyzer/Core/PathSensitive/Store.h"
15 #include "clang/AST/ASTContext.h"
16 #include "clang/AST/CXXInheritance.h"
17 #include "clang/AST/CharUnits.h"
18 #include "clang/AST/Decl.h"
19 #include "clang/AST/DeclCXX.h"
20 #include "clang/AST/DeclObjC.h"
21 #include "clang/AST/Expr.h"
22 #include "clang/AST/Type.h"
23 #include "clang/Basic/LLVM.h"
24 #include "clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h"
25 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
26 #include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h"
27 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
28 #include "clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h"
29 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
30 #include "clang/StaticAnalyzer/Core/PathSensitive/StoreRef.h"
31 #include "clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h"
32 #include "llvm/ADT/APSInt.h"
33 #include "llvm/ADT/Optional.h"
34 #include "llvm/ADT/SmallVector.h"
35 #include "llvm/Support/Casting.h"
36 #include "llvm/Support/ErrorHandling.h"
37 #include <cassert>
38 #include <cstdint>
39
40 using namespace clang;
41 using namespace ento;
42
43 StoreManager::StoreManager(ProgramStateManager &stateMgr)
44 : svalBuilder(stateMgr.getSValBuilder()), StateMgr(stateMgr),
45 MRMgr(svalBuilder.getRegionManager()), Ctx(stateMgr.getContext()) {}
46
47 StoreRef StoreManager::enterStackFrame(Store OldStore,
48 const CallEvent &Call,
49 const StackFrameContext *LCtx) {
50 StoreRef Store = StoreRef(OldStore, *this);
51
52 SmallVector<CallEvent::FrameBindingTy, 16> InitialBindings;
53 Call.getInitialStackFrameContents(LCtx, InitialBindings);
54
55 for (const auto &I : InitialBindings)
56 Store = Bind(Store.getStore(), I.first, I.second);
57
58 return Store;
59 }
60
61 const ElementRegion *StoreManager::MakeElementRegion(const SubRegion *Base,
62 QualType EleTy,
63 uint64_t index) {
64 NonLoc idx = svalBuilder.makeArrayIndex(index);
65 return MRMgr.getElementRegion(EleTy, idx, Base, svalBuilder.getContext());
66 }
67
68 const ElementRegion *StoreManager::GetElementZeroRegion(const SubRegion *R,
69 QualType T) {
70 NonLoc idx = svalBuilder.makeZeroArrayIndex();
71 assert(!T.isNull());
72 return MRMgr.getElementRegion(T, idx, R, Ctx);
73 }
74
75 const MemRegion *StoreManager::castRegion(const MemRegion *R, QualType CastToTy) {
76 ASTContext &Ctx = StateMgr.getContext();
77
78 // Handle casts to Objective-C objects.
79 if (CastToTy->isObjCObjectPointerType())
80 return R->StripCasts();
81
82 if (CastToTy->isBlockPointerType()) {
83 // FIXME: We may need different solutions, depending on the symbol
84 // involved. Blocks can be casted to/from 'id', as they can be treated
85 // as Objective-C objects. This could possibly be handled by enhancing
86 // our reasoning of downcasts of symbolic objects.
87 if (isa<CodeTextRegion>(R) || isa<SymbolicRegion>(R))
88 return R;
89
90 // We don't know what to make of it. Return a NULL region, which
91 // will be interpreted as UnknownVal.
92 return nullptr;
93 }
94
95 // Now assume we are casting from pointer to pointer. Other cases should
96 // already be handled.
97 QualType PointeeTy = CastToTy->getPointeeType();
98 QualType CanonPointeeTy = Ctx.getCanonicalType(PointeeTy);
99
100 // Handle casts to void*. We just pass the region through.
101 if (CanonPointeeTy.getLocalUnqualifiedType() == Ctx.VoidTy)
102 return R;
103
104 // Handle casts from compatible types.
105 if (R->isBoundable())
106 if (const auto *TR = dyn_cast<TypedValueRegion>(R)) {
107 QualType ObjTy = Ctx.getCanonicalType(TR->getValueType());
108 if (CanonPointeeTy == ObjTy)
109 return R;
110 }
111
112 // Process region cast according to the kind of the region being cast.
113 switch (R->getKind()) {
114 case MemRegion::CXXThisRegionKind:
115 case MemRegion::CodeSpaceRegionKind:
116 case MemRegion::StackLocalsSpaceRegionKind:
117 case MemRegion::StackArgumentsSpaceRegionKind:
118 case MemRegion::HeapSpaceRegionKind:
119 case MemRegion::UnknownSpaceRegionKind:
120 case MemRegion::StaticGlobalSpaceRegionKind:
121 case MemRegion::GlobalInternalSpaceRegionKind:
122 case MemRegion::GlobalSystemSpaceRegionKind:
123 case MemRegion::GlobalImmutableSpaceRegionKind: {
124 llvm_unreachable("Invalid region cast");
125 }
126
127 case MemRegion::FunctionCodeRegionKind:
128 case MemRegion::BlockCodeRegionKind:
129 case MemRegion::BlockDataRegionKind:
130 case MemRegion::StringRegionKind:
131 // FIXME: Need to handle arbitrary downcasts.
132 case MemRegion::SymbolicRegionKind:
133 case MemRegion::AllocaRegionKind:
134 case MemRegion::CompoundLiteralRegionKind:
135 case MemRegion::FieldRegionKind:
136 case MemRegion::ObjCIvarRegionKind:
137 case MemRegion::ObjCStringRegionKind:
138 case MemRegion::VarRegionKind:
139 case MemRegion::CXXTempObjectRegionKind:
140 case MemRegion::CXXBaseObjectRegionKind:
141 case MemRegion::CXXDerivedObjectRegionKind:
142 return MakeElementRegion(cast<SubRegion>(R), PointeeTy);
143
144 case MemRegion::ElementRegionKind: {
145 // If we are casting from an ElementRegion to another type, the
146 // algorithm is as follows:
147 //
148 // (1) Compute the "raw offset" of the ElementRegion from the
149 // base region. This is done by calling 'getAsRawOffset()'.
150 //
151 // (2a) If we get a 'RegionRawOffset' after calling
152 // 'getAsRawOffset()', determine if the absolute offset
153 // can be exactly divided into chunks of the size of the
154 // casted-pointee type. If so, create a new ElementRegion with
155 // the pointee-cast type as the new ElementType and the index
156 // being the offset divded by the chunk size. If not, create
157 // a new ElementRegion at offset 0 off the raw offset region.
158 //
159 // (2b) If we don't a get a 'RegionRawOffset' after calling
160 // 'getAsRawOffset()', it means that we are at offset 0.
161 //
162 // FIXME: Handle symbolic raw offsets.
163
164 const ElementRegion *elementR = cast<ElementRegion>(R);
165 const RegionRawOffset &rawOff = elementR->getAsArrayOffset();
166 const MemRegion *baseR = rawOff.getRegion();
167
168 // If we cannot compute a raw offset, throw up our hands and return
169 // a NULL MemRegion*.
170 if (!baseR)
171 return nullptr;
172
173 CharUnits off = rawOff.getOffset();
174
175 if (off.isZero()) {
176 // Edge case: we are at 0 bytes off the beginning of baseR. We
177 // check to see if type we are casting to is the same as the base
178 // region. If so, just return the base region.
179 if (const auto *TR = dyn_cast<TypedValueRegion>(baseR)) {
180 QualType ObjTy = Ctx.getCanonicalType(TR->getValueType());
181 QualType CanonPointeeTy = Ctx.getCanonicalType(PointeeTy);
182 if (CanonPointeeTy == ObjTy)
183 return baseR;
184 }
185
186 // Otherwise, create a new ElementRegion at offset 0.
187 return MakeElementRegion(cast<SubRegion>(baseR), PointeeTy);
188 }
189
190 // We have a non-zero offset from the base region. We want to determine
191 // if the offset can be evenly divided by sizeof(PointeeTy). If so,
192 // we create an ElementRegion whose index is that value. Otherwise, we
193 // create two ElementRegions, one that reflects a raw offset and the other
194 // that reflects the cast.
195
196 // Compute the index for the new ElementRegion.
197 int64_t newIndex = 0;
198 const MemRegion *newSuperR = nullptr;
199
200 // We can only compute sizeof(PointeeTy) if it is a complete type.
201 if (!PointeeTy->isIncompleteType()) {
202 // Compute the size in **bytes**.
203 CharUnits pointeeTySize = Ctx.getTypeSizeInChars(PointeeTy);
204 if (!pointeeTySize.isZero()) {
205 // Is the offset a multiple of the size? If so, we can layer the
206 // ElementRegion (with elementType == PointeeTy) directly on top of
207 // the base region.
208 if (off % pointeeTySize == 0) {
209 newIndex = off / pointeeTySize;
210 newSuperR = baseR;
211 }
212 }
213 }
214
215 if (!newSuperR) {
216 // Create an intermediate ElementRegion to represent the raw byte.
217 // This will be the super region of the final ElementRegion.
218 newSuperR = MakeElementRegion(cast<SubRegion>(baseR), Ctx.CharTy,
219 off.getQuantity());
220 }
221
222 return MakeElementRegion(cast<SubRegion>(newSuperR), PointeeTy, newIndex);
223 }
224 }
225
226 llvm_unreachable("unreachable");
227 }
228
229 static bool regionMatchesCXXRecordType(SVal V, QualType Ty) {
230 const MemRegion *MR = V.getAsRegion();
231 if (!MR)
232 return true;
233
234 const auto *TVR = dyn_cast<TypedValueRegion>(MR);
235 if (!TVR)
236 return true;
237
238 const CXXRecordDecl *RD = TVR->getValueType()->getAsCXXRecordDecl();
239 if (!RD)
240 return true;
241
242 const CXXRecordDecl *Expected = Ty->getPointeeCXXRecordDecl();
243 if (!Expected)
244 Expected = Ty->getAsCXXRecordDecl();
245
246 return Expected->getCanonicalDecl() == RD->getCanonicalDecl();
247 }
248
249 SVal StoreManager::evalDerivedToBase(SVal Derived, const CastExpr *Cast) {
250 // Sanity check to avoid doing the wrong thing in the face of
251 // reinterpret_cast.
252 if (!regionMatchesCXXRecordType(Derived, Cast->getSubExpr()->getType()))
253 return UnknownVal();
254
255 // Walk through the cast path to create nested CXXBaseRegions.
256 SVal Result = Derived;
257 for (CastExpr::path_const_iterator I = Cast->path_begin(),
258 E = Cast->path_end();
259 I != E; ++I) {
260 Result = evalDerivedToBase(Result, (*I)->getType(), (*I)->isVirtual());
261 }
262 return Result;
263 }
264
265 SVal StoreManager::evalDerivedToBase(SVal Derived, const CXXBasePath &Path) {
266 // Walk through the path to create nested CXXBaseRegions.
267 SVal Result = Derived;
268 for (const auto &I : Path)
269 Result = evalDerivedToBase(Result, I.Base->getType(),
270 I.Base->isVirtual());
271 return Result;
272 }
273
274 SVal StoreManager::evalDerivedToBase(SVal Derived, QualType BaseType,
275 bool IsVirtual) {
276 const MemRegion *DerivedReg = Derived.getAsRegion();
277 if (!DerivedReg)
278 return Derived;
279
280 const CXXRecordDecl *BaseDecl = BaseType->getPointeeCXXRecordDecl();
281 if (!BaseDecl)
282 BaseDecl = BaseType->getAsCXXRecordDecl();
283 assert(BaseDecl && "not a C++ object?");
284
285 if (const auto *AlreadyDerivedReg =
286 dyn_cast<CXXDerivedObjectRegion>(DerivedReg)) {
287 if (const auto *SR =
288 dyn_cast<SymbolicRegion>(AlreadyDerivedReg->getSuperRegion()))
289 if (SR->getSymbol()->getType()->getPointeeCXXRecordDecl() == BaseDecl)
290 return loc::MemRegionVal(SR);
291
292 DerivedReg = AlreadyDerivedReg->getSuperRegion();
293 }
294
295 const MemRegion *BaseReg = MRMgr.getCXXBaseObjectRegion(
296 BaseDecl, cast<SubRegion>(DerivedReg), IsVirtual);
297
298 return loc::MemRegionVal(BaseReg);
299 }
300
301 /// Returns the static type of the given region, if it represents a C++ class
302 /// object.
303 ///
304 /// This handles both fully-typed regions, where the dynamic type is known, and
305 /// symbolic regions, where the dynamic type is merely bounded (and even then,
306 /// only ostensibly!), but does not take advantage of any dynamic type info.
307 static const CXXRecordDecl *getCXXRecordType(const MemRegion *MR) {
308 if (const auto *TVR = dyn_cast<TypedValueRegion>(MR))
309 return TVR->getValueType()->getAsCXXRecordDecl();
310 if (const auto *SR = dyn_cast<SymbolicRegion>(MR))
311 return SR->getSymbol()->getType()->getPointeeCXXRecordDecl();
312 return nullptr;
313 }
314
315 SVal StoreManager::attemptDownCast(SVal Base, QualType TargetType,
316 bool &Failed) {
317 Failed = false;
318
319 const MemRegion *MR = Base.getAsRegion();
320 if (!MR)
321 return UnknownVal();
322
323 // Assume the derived class is a pointer or a reference to a CXX record.
324 TargetType = TargetType->getPointeeType();
325 assert(!TargetType.isNull());
326 const CXXRecordDecl *TargetClass = TargetType->getAsCXXRecordDecl();
327 if (!TargetClass && !TargetType->isVoidType())
328 return UnknownVal();
329
330 // Drill down the CXXBaseObject chains, which represent upcasts (casts from
331 // derived to base).
332 while (const CXXRecordDecl *MRClass = getCXXRecordType(MR)) {
333 // If found the derived class, the cast succeeds.
334 if (MRClass == TargetClass)
335 return loc::MemRegionVal(MR);
336
337 // We skip over incomplete types. They must be the result of an earlier
338 // reinterpret_cast, as one can only dynamic_cast between types in the same
339 // class hierarchy.
340 if (!TargetType->isVoidType() && MRClass->hasDefinition()) {
341 // Static upcasts are marked as DerivedToBase casts by Sema, so this will
342 // only happen when multiple or virtual inheritance is involved.
343 CXXBasePaths Paths(/*FindAmbiguities=*/false, /*RecordPaths=*/true,
344 /*DetectVirtual=*/false);
345 if (MRClass->isDerivedFrom(TargetClass, Paths))
346 return evalDerivedToBase(loc::MemRegionVal(MR), Paths.front());
347 }
348
349 if (const auto *BaseR = dyn_cast<CXXBaseObjectRegion>(MR)) {
350 // Drill down the chain to get the derived classes.
351 MR = BaseR->getSuperRegion();
352 continue;
353 }
354
355 // If this is a cast to void*, return the region.
356 if (TargetType->isVoidType())
357 return loc::MemRegionVal(MR);
358
359 // Strange use of reinterpret_cast can give us paths we don't reason
360 // about well, by putting in ElementRegions where we'd expect
361 // CXXBaseObjectRegions. If it's a valid reinterpret_cast (i.e. if the
362 // derived class has a zero offset from the base class), then it's safe
363 // to strip the cast; if it's invalid, -Wreinterpret-base-class should
364 // catch it. In the interest of performance, the analyzer will silently
365 // do the wrong thing in the invalid case (because offsets for subregions
366 // will be wrong).
367 const MemRegion *Uncasted = MR->StripCasts(/*IncludeBaseCasts=*/false);
368 if (Uncasted == MR) {
369 // We reached the bottom of the hierarchy and did not find the derived
370 // class. We must be casting the base to derived, so the cast should
371 // fail.
372 break;
373 }
374
375 MR = Uncasted;
376 }
377
378 // If we're casting a symbolic base pointer to a derived class, use
379 // CXXDerivedObjectRegion to represent the cast. If it's a pointer to an
380 // unrelated type, it must be a weird reinterpret_cast and we have to
381 // be fine with ElementRegion. TODO: Should we instead make
382 // Derived{TargetClass, Element{SourceClass, SR}}?
383 if (const auto *SR = dyn_cast<SymbolicRegion>(MR)) {
384 QualType T = SR->getSymbol()->getType();
385 const CXXRecordDecl *SourceClass = T->getPointeeCXXRecordDecl();
386 if (TargetClass && SourceClass && TargetClass->isDerivedFrom(SourceClass))
387 return loc::MemRegionVal(
388 MRMgr.getCXXDerivedObjectRegion(TargetClass, SR));
389 return loc::MemRegionVal(GetElementZeroRegion(SR, TargetType));
390 }
391
392 // We failed if the region we ended up with has perfect type info.
393 Failed = isa<TypedValueRegion>(MR);
394 return UnknownVal();
395 }
396
397 /// CastRetrievedVal - Used by subclasses of StoreManager to implement
398 /// implicit casts that arise from loads from regions that are reinterpreted
399 /// as another region.
400 SVal StoreManager::CastRetrievedVal(SVal V, const TypedValueRegion *R,
401 QualType castTy) {
402 if (castTy.isNull() || V.isUnknownOrUndef())
403 return V;
404
405 // The dispatchCast() call below would convert the int into a float.
406 // What we want, however, is a bit-by-bit reinterpretation of the int
407 // as a float, which usually yields nothing garbage. For now skip casts
408 // from ints to floats.
409 // TODO: What other combinations of types are affected?
410 if (castTy->isFloatingType()) {
411 SymbolRef Sym = V.getAsSymbol();
412 if (Sym && !Sym->getType()->isFloatingType())
413 return UnknownVal();
414 }
415
416 // When retrieving symbolic pointer and expecting a non-void pointer,
417 // wrap them into element regions of the expected type if necessary.
418 // SValBuilder::dispatchCast() doesn't do that, but it is necessary to
419 // make sure that the retrieved value makes sense, because there's no other
420 // cast in the AST that would tell us to cast it to the correct pointer type.
421 // We might need to do that for non-void pointers as well.
422 // FIXME: We really need a single good function to perform casts for us
423 // correctly every time we need it.
424 if (castTy->isPointerType() && !castTy->isVoidPointerType())
425 if (const auto *SR = dyn_cast_or_null<SymbolicRegion>(V.getAsRegion()))
426 if (SR->getSymbol()->getType().getCanonicalType() !=
427 castTy.getCanonicalType())
428 return loc::MemRegionVal(castRegion(SR, castTy));
429
430 return svalBuilder.dispatchCast(V, castTy);
431 }
432
433 SVal StoreManager::getLValueFieldOrIvar(const Decl *D, SVal Base) {
434 if (Base.isUnknownOrUndef())
435 return Base;
436
437 Loc BaseL = Base.castAs<Loc>();
438 const SubRegion* BaseR = nullptr;
439
440 switch (BaseL.getSubKind()) {
441 case loc::MemRegionValKind:
442 BaseR = cast<SubRegion>(BaseL.castAs<loc::MemRegionVal>().getRegion());
443 break;
444
445 case loc::GotoLabelKind:
446 // These are anormal cases. Flag an undefined value.
447 return UndefinedVal();
448
449 case loc::ConcreteIntKind:
450 // While these seem funny, this can happen through casts.
451 // FIXME: What we should return is the field offset, not base. For example,
452 // add the field offset to the integer value. That way things
453 // like this work properly: &(((struct foo *) 0xa)->f)
454 // However, that's not easy to fix without reducing our abilities
455 // to catch null pointer dereference. Eg., ((struct foo *)0x0)->f = 7
456 // is a null dereference even though we're dereferencing offset of f
457 // rather than null. Coming up with an approach that computes offsets
458 // over null pointers properly while still being able to catch null
459 // dereferences might be worth it.
460 return Base;
461
462 default:
463 llvm_unreachable("Unhandled Base.");
464 }
465
466 // NOTE: We must have this check first because ObjCIvarDecl is a subclass
467 // of FieldDecl.
468 if (const auto *ID = dyn_cast<ObjCIvarDecl>(D))
469 return loc::MemRegionVal(MRMgr.getObjCIvarRegion(ID, BaseR));
470
471 return loc::MemRegionVal(MRMgr.getFieldRegion(cast<FieldDecl>(D), BaseR));
472 }
473
474 SVal StoreManager::getLValueIvar(const ObjCIvarDecl *decl, SVal base) {
475 return getLValueFieldOrIvar(decl, base);
476 }
477
478 SVal StoreManager::getLValueElement(QualType elementType, NonLoc Offset,
479 SVal Base) {
480 // If the base is an unknown or undefined value, just return it back.
481 // FIXME: For absolute pointer addresses, we just return that value back as
482 // well, although in reality we should return the offset added to that
483 // value. See also the similar FIXME in getLValueFieldOrIvar().
484 if (Base.isUnknownOrUndef() || Base.getAs<loc::ConcreteInt>())
485 return Base;
486
487 if (Base.getAs<loc::GotoLabel>())
488 return UnknownVal();
489
490 const SubRegion *BaseRegion =
491 Base.castAs<loc::MemRegionVal>().getRegionAs<SubRegion>();
492
493 // Pointer of any type can be cast and used as array base.
494 const auto *ElemR = dyn_cast<ElementRegion>(BaseRegion);
495
496 // Convert the offset to the appropriate size and signedness.
497 Offset = svalBuilder.convertToArrayIndex(Offset).castAs<NonLoc>();
498
499 if (!ElemR) {
500 // If the base region is not an ElementRegion, create one.
501 // This can happen in the following example:
502 //
503 // char *p = __builtin_alloc(10);
504 // p[1] = 8;
505 //
506 // Observe that 'p' binds to an AllocaRegion.
507 return loc::MemRegionVal(MRMgr.getElementRegion(elementType, Offset,
508 BaseRegion, Ctx));
509 }
510
511 SVal BaseIdx = ElemR->getIndex();
512
513 if (!BaseIdx.getAs<nonloc::ConcreteInt>())
514 return UnknownVal();
515
516 const llvm::APSInt &BaseIdxI =
517 BaseIdx.castAs<nonloc::ConcreteInt>().getValue();
518
519 // Only allow non-integer offsets if the base region has no offset itself.
520 // FIXME: This is a somewhat arbitrary restriction. We should be using
521 // SValBuilder here to add the two offsets without checking their types.
522 if (!Offset.getAs<nonloc::ConcreteInt>()) {
523 if (isa<ElementRegion>(BaseRegion->StripCasts()))
524 return UnknownVal();
525
526 return loc::MemRegionVal(MRMgr.getElementRegion(
527 elementType, Offset, cast<SubRegion>(ElemR->getSuperRegion()), Ctx));
528 }
529
530 const llvm::APSInt& OffI = Offset.castAs<nonloc::ConcreteInt>().getValue();
531 assert(BaseIdxI.isSigned());
532
533 // Compute the new index.
534 nonloc::ConcreteInt NewIdx(svalBuilder.getBasicValueFactory().getValue(BaseIdxI +
535 OffI));
536
537 // Construct the new ElementRegion.
538 const SubRegion *ArrayR = cast<SubRegion>(ElemR->getSuperRegion());
539 return loc::MemRegionVal(MRMgr.getElementRegion(elementType, NewIdx, ArrayR,
540 Ctx));
541 }
542
543 StoreManager::BindingsHandler::~BindingsHandler() = default;
544
545 bool StoreManager::FindUniqueBinding::HandleBinding(StoreManager& SMgr,
546 Store store,
547 const MemRegion* R,
548 SVal val) {
549 SymbolRef SymV = val.getAsLocSymbol();
550 if (!SymV || SymV != Sym)
551 return true;
552
553 if (Binding) {
554 First = false;
555 return false;
556 }
557 else
558 Binding = R;
559
560 return true;
561 }
StoreRef.h
clang::Builtin::ID
ID
Definition: Builtins.h:49
ASTContext.h
Defines the clang::ASTContext interface.
ento
clang::ento::StoreManager::attemptDownCast
SVal attemptDownCast(SVal Base, QualType DerivedPtrType, bool &Failed)
Attempts to do a down cast.
Definition: Store.cpp:315
SVals.h
clang::ento::TypedValueRegion
TypedValueRegion - An abstract class representing regions having a typed value.
Definition: MemRegion.h:530
clang::ento::StoreManager::evalDerivedToBase
SVal evalDerivedToBase(SVal Derived, const CastExpr *Cast)
Evaluates a chain of derived-to-base casts through the path specified in Cast.
Definition: Store.cpp:249
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:638
clang::ento::MemRegion
MemRegion - The root abstract class for all memory regions.
Definition: MemRegion.h:95
clang::Type::isBlockPointerType
bool isBlockPointerType() const
Definition: Type.h:6304
clang::ento::StoreRef::getStore
Store getStore() const
Definition: StoreRef.h:47
clang::Type::getPointeeType
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
Definition: Type.cpp:505
Base
Type.h
C Language Family Type Representation.
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:87
clang::CXXRecordDecl::isDerivedFrom
bool isDerivedFrom(const CXXRecordDecl *Base) const
Determine whether this class is derived from the class Base.
Definition: CXXInheritance.cpp:92
CXXInheritance.h
clang::CharUnits::isZero
bool isZero() const
isZero - Test whether the quantity equals zero.
Definition: CharUnits.h:116
DeclObjC.h
MemRegion.h
clang::CXXBasePath
Represents a path from a specific derived class (which is not represented as part of the path) to a p...
Definition: CXXInheritance.h:71
clang::ento::nonloc::ConcreteInt
Value representing integer constant.
Definition: SVals.h:377
clang::ento::MemRegionManager::getObjCIvarRegion
const ObjCIvarRegion * getObjCIvarRegion(const ObjCIvarDecl *ivd, const SubRegion *superRegion)
getObjCIvarRegion - Retrieve or create the memory region associated with a specified Objective-c inst...
Definition: MemRegion.cpp:1036
clang::CastExpr::path_const_iterator
const CXXBaseSpecifier *const * path_const_iterator
Definition: Expr.h:3067
clang::ento::SVal::getAsLocSymbol
SymbolRef getAsLocSymbol(bool IncludeBaseRegions=false) const
If this SVal is a location and wraps a symbol, return that SymbolRef.
Definition: SVals.cpp:85
clang::ento::SValBuilder::dispatchCast
virtual SVal dispatchCast(SVal val, QualType castTy)=0
clang::ento::Store
const void * Store
Store - This opaque type encapsulates an immutable mapping from locations to values.
Definition: StoreRef.h:28
clang::ento::SValBuilder::makeArrayIndex
NonLoc makeArrayIndex(uint64_t idx)
Definition: SValBuilder.h:273
clang::ento::UndefinedVal
Definition: SVals.h:215
clang::ento::StoreManager::GetElementZeroRegion
const ElementRegion * GetElementZeroRegion(const SubRegion *R, QualType T)
Definition: Store.cpp:68
clang::QualType::getLocalUnqualifiedType
QualType getLocalUnqualifiedType() const
Return this type with all of the instance-specific qualifiers removed, but without removing any quali...
Definition: Type.h:877
clang::ento::StoreManager::castRegion
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:75
clang::ento::StoreManager::Ctx
ASTContext & Ctx
Definition: Store.h:61
clang::ento::SymExpr
Symbolic value.
Definition: SymExpr.h:30
clang::ento::StoreManager::FindUniqueBinding::HandleBinding
bool HandleBinding(StoreManager &SMgr, Store store, const MemRegion *R, SVal val) override
Definition: Store.cpp:545
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:155
regionMatchesCXXRecordType
static bool regionMatchesCXXRecordType(SVal V, QualType Ty)
Definition: Store.cpp:229
Store.h
clang::CastExpr::getSubExpr
Expr * getSubExpr()
Definition: Expr.h:3050
CharUnits.h
llvm::Expected
Definition: LLVM.h:39
clang::CharUnits
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
LLVM.h
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
clang::ComparisonCategoryType::First
clang::CastExpr::path_begin
path_iterator path_begin()
Definition: Expr.h:3070
clang::CXXRecordDecl::getCanonicalDecl
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclCXX.h:728
clang::CastExpr
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition: Expr.h:2998
BasicValueFactory.h
clang::ento::StoreManager::enterStackFrame
StoreRef enterStackFrame(Store store, const CallEvent &Call, const StackFrameContext *CalleeCtx)
enterStackFrame - Let the StoreManager to do something when execution engine is about to execute into...
Definition: Store.cpp:47
clang::ento::loc::GotoLabel
Definition: SVals.h:572
clang::ento::SymExpr::getType
virtual QualType getType() const =0
clang::ento::StoreManager::getLValueIvar
virtual SVal getLValueIvar(const ObjCIvarDecl *decl, SVal base)
Definition: Store.cpp:474
clang::ento::SVal::getAsSymbol
SymbolRef getAsSymbol(bool IncludeBaseRegions=false) const
If this SVal wraps a symbol return that SymbolRef.
Definition: SVals.cpp:127
clang::Type::getAsCXXRecordDecl
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1613
clang::ento::SVal::getSubKind
unsigned getSubKind() const
Definition: SVals.h:120
clang::ento::StoreManager
Definition: Store.h:54
clang::CharUnits::getQuantity
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Definition: CharUnits.h:179
Offset
unsigned Offset
Definition: Format.cpp:1631
clang::ento::StoreManager::svalBuilder
SValBuilder & svalBuilder
Definition: Store.h:56
clang::Type::getPointeeCXXRecordDecl
const CXXRecordDecl * getPointeeCXXRecordDecl() const
If this is a pointer or reference to a RecordType, return the CXXRecordDecl that the type refers to...
Definition: Type.cpp:1598
clang::ast_matchers::decl
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
Definition: ASTMatchersInternal.cpp:561
ProgramState.h
clang::ento::StoreRef
Definition: StoreRef.h:30
getValue
static SVal getValue(SVal val, SValBuilder &svalBuilder)
Definition: ArrayBoundCheckerV2.cpp:276
clang::Expr::getType
QualType getType() const
Definition: Expr.h:128
clang::ento::StoreManager::StateMgr
ProgramStateManager & StateMgr
Definition: Store.h:57
clang::ento::StoreManager::Bind
virtual StoreRef Bind(Store store, Loc loc, SVal val)=0
Return a store with the specified value bound to the given location.
clang::ento::NonLoc
Definition: SVals.h:296
clang::QualType::isNull
bool isNull() const
Return true if this QualType doesn&#39;t point to a type yet.
Definition: Type.h:703
clang::ento::SValBuilder::makeZeroArrayIndex
NonLoc makeZeroArrayIndex()
Definition: SValBuilder.h:269
clang::ento::SVal::getAs
Optional< T > getAs() const
Convert to the specified SVal type, returning None if this SVal is not of the desired type...
Definition: SVals.h:112
clang::ento::MemRegion::isBoundable
virtual bool isBoundable() const
Definition: MemRegion.h:174
clang::Type::isVoidPointerType
bool isVoidPointerType() const
Definition: Type.cpp:469
clang::ento::loc::ConcreteInt
Definition: SVals.h:638
clang::ento::MemRegion::getKind
Kind getKind() const
Definition: MemRegion.h:170
clang::QualType::getCanonicalType
QualType getCanonicalType() const
Definition: Type.h:6111
clang::ento::Loc
Definition: SVals.h:318
clang::ento::CallEvent::getInitialStackFrameContents
virtual void getInitialStackFrameContents(const StackFrameContext *CalleeCtx, BindingsTy &Bindings) const =0
Populates the given SmallVector with the bindings in the callee&#39;s stack frame at the start of this ca...
clang::ento::SVal::getAsRegion
const MemRegion * getAsRegion() const
Definition: SVals.cpp:151
clang::ento::SValBuilder::getContext
ASTContext & getContext()
Definition: SValBuilder.h:156
clang::ento::SVal
SVal - This represents a symbolic expression, which can be either an L-value or an R-value...
Definition: SVals.h:76
clang::ASTContext::VoidTy
CanQualType VoidTy
Definition: ASTContext.h:1016
clang::ento::MemRegionManager::getCXXDerivedObjectRegion
const CXXDerivedObjectRegion * getCXXDerivedObjectRegion(const CXXRecordDecl *BaseClass, const SubRegion *Super)
Create a CXXDerivedObjectRegion with the given derived class for region Super.
Definition: MemRegion.cpp:1092
llvm::SmallVector
Definition: LLVM.h:36
clang::Type::isObjCObjectPointerType
bool isObjCObjectPointerType() const
Definition: Type.h:6393
clang::ento::StoreManager::BindingsHandler::~BindingsHandler
virtual ~BindingsHandler()
clang::ento::ProgramStateManager
Definition: ProgramState.h:491
SValBuilder.h
clang::ento::ElementRegion::getAsArrayOffset
RegionRawOffset getAsArrayOffset() const
Compute the offset within the array. The array might also be a subobject.
Definition: MemRegion.cpp:1228
clang::ento::MemRegionManager::getCXXBaseObjectRegion
const CXXBaseObjectRegion * getCXXBaseObjectRegion(const CXXRecordDecl *BaseClass, const SubRegion *Super, bool IsVirtual)
Create a CXXBaseObjectRegion with the given base class for region Super.
Definition: MemRegion.cpp:1072
clang::ASTContext::CharTy
CanQualType CharTy
Definition: ASTContext.h:1018
Decl.h
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::ento::RegionRawOffset
Definition: MemRegion.h:1067
clang::ento::MemRegionManager::getElementRegion
const ElementRegion * getElementRegion(QualType elementType, NonLoc Idx, const SubRegion *superRegion, ASTContext &Ctx)
getElementRegion - Retrieve the memory region associated with the associated element type...
Definition: MemRegion.cpp:988
clang::ento::MemRegion::StripCasts
const MemRegion * StripCasts(bool StripBaseAndDerivedCasts=true) const
Definition: MemRegion.cpp:1194
clang::ento::CallEvent
Represents an abstract call to a function or method along a particular path.
Definition: CallEvent.h:171
clang::ento::SValBuilder::convertToArrayIndex
SVal convertToArrayIndex(SVal val)
Definition: SValBuilder.cpp:100
clang::ento::ProgramStateManager::getContext
ASTContext & getContext()
Definition: ProgramState.h:535
clang::CastExpr::path_end
path_iterator path_end()
Definition: Expr.h:3071
clang::ento::SVal::castAs
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
Definition: SVals.h:104
clang::ento::SValBuilder::getBasicValueFactory
BasicValueFactory & getBasicValueFactory()
Definition: SValBuilder.h:169
SymExpr.h
clang::ento::SubRegion
SubRegion - A region that subsets another larger region.
Definition: MemRegion.h:436
clang::ento::StoreManager::MakeElementRegion
const ElementRegion * MakeElementRegion(const SubRegion *baseRegion, QualType pointeeTy, uint64_t index=0)
Definition: Store.cpp:61
clang::ento::StoreManager::CastRetrievedVal
SVal CastRetrievedVal(SVal val, const TypedValueRegion *region, QualType castTy)
CastRetrievedVal - Used by subclasses of StoreManager to implement implicit casts that arise from loa...
Definition: Store.cpp:400
clang::CXXBasePaths::front
CXXBasePath & front()
Definition: CXXInheritance.h:197
clang::ento::StoreManager::MRMgr
MemRegionManager & MRMgr
MRMgr - Manages region objects associated with this StoreManager.
Definition: Store.h:60
clang::StackFrameContext
Definition: AnalysisDeclContext.h:292
clang::Type::isIncompleteType
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types...
Definition: Type.cpp:2031
clang::ento::StoreManager::getLValueElement
virtual SVal getLValueElement(QualType elementType, NonLoc offset, SVal Base)
Definition: Store.cpp:478
clang::ASTContext::getCanonicalType
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2253
DeclCXX.h
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
getCXXRecordType
static const CXXRecordDecl * getCXXRecordType(const MemRegion *MR)
Returns the static type of the given region, if it represents a C++ class object. ...
Definition: Store.cpp:307
clang::CXXRecordDecl
Represents a C++ struct/union/class.
Definition: DeclCXX.h:300
clang::Type::isVoidType
bool isVoidType() const
Definition: Type.h:6544
clang::ObjCIvarDecl
ObjCIvarDecl - Represents an ObjC instance variable.
Definition: DeclObjC.h:1945
Expr.h
clang::ento::UnknownVal
Definition: SVals.h:248
clang::ento::ElementRegion
ElementRegion is used to represent both array elements and casts.
Definition: MemRegion.h:1086
clang::Type::isPointerType
bool isPointerType() const
Definition: Type.h:6296
clang::CXXBasePaths
BasePaths - Represents the set of paths from a derived class to one of its (direct or indirect) bases...
Definition: CXXInheritance.h:119
clang::ASTContext::getTypeSizeInChars
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
Definition: ASTContext.cpp:2167
clang::Type::isFloatingType
bool isFloatingType() const
Definition: Type.cpp:1921
clang::ento::StoreManager::StoreManager
StoreManager(ProgramStateManager &stateMgr)
Definition: Store.cpp:43
clang::ento::loc::MemRegionVal
Definition: SVals.h:596
CallEvent.h
clang::ento::MemRegionManager::getFieldRegion
const FieldRegion * getFieldRegion(const FieldDecl *fd, const SubRegion *superRegion)
getFieldRegion - Retrieve or create the memory region associated with a specified FieldDecl...
Definition: MemRegion.cpp:1030
clang::ento::SVal::isUnknownOrUndef
bool isUnknownOrUndef() const
Definition: SVals.h:145