clang 20.0.0git
SymbolManager.h
Go to the documentation of this file.
1//===- SymbolManager.h - Management of Symbolic Values ----------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines SymbolManager, a class that manages symbolic values
10// created for use by ExprEngine and related classes.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SYMBOLMANAGER_H
15#define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SYMBOLMANAGER_H
16
17#include "clang/AST/Expr.h"
18#include "clang/AST/Type.h"
20#include "clang/Basic/LLVM.h"
25#include "llvm/ADT/DenseMap.h"
26#include "llvm/ADT/DenseSet.h"
27#include "llvm/ADT/FoldingSet.h"
28#include "llvm/ADT/iterator_range.h"
29#include "llvm/Support/Allocator.h"
30#include <cassert>
31
32namespace clang {
33
34class ASTContext;
35class Stmt;
36
37namespace ento {
38
39class BasicValueFactory;
40class StoreManager;
41
42///A symbol representing the value stored at a MemRegion.
44 const TypedValueRegion *R;
45
46public:
48 : SymbolData(SymbolRegionValueKind, sym), R(r) {
49 assert(r);
51 }
52
53 LLVM_ATTRIBUTE_RETURNS_NONNULL
54 const TypedValueRegion* getRegion() const { return R; }
55
56 static void Profile(llvm::FoldingSetNodeID& profile, const TypedValueRegion* R) {
57 profile.AddInteger((unsigned) SymbolRegionValueKind);
58 profile.AddPointer(R);
59 }
60
61 void Profile(llvm::FoldingSetNodeID& profile) override {
62 Profile(profile, R);
63 }
64
65 StringRef getKindStr() const override;
66
67 void dumpToStream(raw_ostream &os) const override;
68 const MemRegion *getOriginRegion() const override { return getRegion(); }
69
70 QualType getType() const override;
71
72 // Implement isa<T> support.
73 static bool classof(const SymExpr *SE) {
74 return SE->getKind() == SymbolRegionValueKind;
75 }
76};
77
78/// A symbol representing the result of an expression in the case when we do
79/// not know anything about what the expression is.
80class SymbolConjured : public SymbolData {
81 const Stmt *S;
82 QualType T;
83 unsigned Count;
84 const LocationContext *LCtx;
85 const void *SymbolTag;
86
87public:
88 SymbolConjured(SymbolID sym, const Stmt *s, const LocationContext *lctx,
89 QualType t, unsigned count, const void *symbolTag)
90 : SymbolData(SymbolConjuredKind, sym), S(s), T(t), Count(count),
91 LCtx(lctx), SymbolTag(symbolTag) {
92 // FIXME: 's' might be a nullptr if we're conducting invalidation
93 // that was caused by a destructor call on a temporary object,
94 // which has no statement associated with it.
95 // Due to this, we might be creating the same invalidation symbol for
96 // two different invalidation passes (for two different temporaries).
97 assert(lctx);
98 assert(isValidTypeForSymbol(t));
99 }
100
101 /// It might return null.
102 const Stmt *getStmt() const { return S; }
103 unsigned getCount() const { return Count; }
104 /// It might return null.
105 const void *getTag() const { return SymbolTag; }
106
107 QualType getType() const override;
108
109 StringRef getKindStr() const override;
110
111 void dumpToStream(raw_ostream &os) const override;
112
113 static void Profile(llvm::FoldingSetNodeID& profile, const Stmt *S,
114 QualType T, unsigned Count, const LocationContext *LCtx,
115 const void *SymbolTag) {
116 profile.AddInteger((unsigned) SymbolConjuredKind);
117 profile.AddPointer(S);
118 profile.AddPointer(LCtx);
119 profile.Add(T);
120 profile.AddInteger(Count);
121 profile.AddPointer(SymbolTag);
122 }
123
124 void Profile(llvm::FoldingSetNodeID& profile) override {
125 Profile(profile, S, T, Count, LCtx, SymbolTag);
126 }
127
128 // Implement isa<T> support.
129 static bool classof(const SymExpr *SE) {
130 return SE->getKind() == SymbolConjuredKind;
131 }
132};
133
134/// A symbol representing the value of a MemRegion whose parent region has
135/// symbolic value.
136class SymbolDerived : public SymbolData {
137 SymbolRef parentSymbol;
138 const TypedValueRegion *R;
139
140public:
142 : SymbolData(SymbolDerivedKind, sym), parentSymbol(parent), R(r) {
143 assert(parent);
144 assert(r);
146 }
147
148 LLVM_ATTRIBUTE_RETURNS_NONNULL
149 SymbolRef getParentSymbol() const { return parentSymbol; }
150 LLVM_ATTRIBUTE_RETURNS_NONNULL
151 const TypedValueRegion *getRegion() const { return R; }
152
153 QualType getType() const override;
154
155 StringRef getKindStr() const override;
156
157 void dumpToStream(raw_ostream &os) const override;
158 const MemRegion *getOriginRegion() const override { return getRegion(); }
159
160 static void Profile(llvm::FoldingSetNodeID& profile, SymbolRef parent,
161 const TypedValueRegion *r) {
162 profile.AddInteger((unsigned) SymbolDerivedKind);
163 profile.AddPointer(r);
164 profile.AddPointer(parent);
165 }
166
167 void Profile(llvm::FoldingSetNodeID& profile) override {
168 Profile(profile, parentSymbol, R);
169 }
170
171 // Implement isa<T> support.
172 static bool classof(const SymExpr *SE) {
173 return SE->getKind() == SymbolDerivedKind;
174 }
175};
176
177/// SymbolExtent - Represents the extent (size in bytes) of a bounded region.
178/// Clients should not ask the SymbolManager for a region's extent. Always use
179/// SubRegion::getExtent instead -- the value returned may not be a symbol.
180class SymbolExtent : public SymbolData {
181 const SubRegion *R;
182
183public:
185 : SymbolData(SymbolExtentKind, sym), R(r) {
186 assert(r);
187 }
188
189 LLVM_ATTRIBUTE_RETURNS_NONNULL
190 const SubRegion *getRegion() const { return R; }
191
192 QualType getType() const override;
193
194 StringRef getKindStr() const override;
195
196 void dumpToStream(raw_ostream &os) const override;
197
198 static void Profile(llvm::FoldingSetNodeID& profile, const SubRegion *R) {
199 profile.AddInteger((unsigned) SymbolExtentKind);
200 profile.AddPointer(R);
201 }
202
203 void Profile(llvm::FoldingSetNodeID& profile) override {
204 Profile(profile, R);
205 }
206
207 // Implement isa<T> support.
208 static bool classof(const SymExpr *SE) {
209 return SE->getKind() == SymbolExtentKind;
210 }
211};
212
213/// SymbolMetadata - Represents path-dependent metadata about a specific region.
214/// Metadata symbols remain live as long as they are marked as in use before
215/// dead-symbol sweeping AND their associated regions are still alive.
216/// Intended for use by checkers.
218 const MemRegion* R;
219 const Stmt *S;
220 QualType T;
221 const LocationContext *LCtx;
222 unsigned Count;
223 const void *Tag;
224
225public:
226 SymbolMetadata(SymbolID sym, const MemRegion* r, const Stmt *s, QualType t,
227 const LocationContext *LCtx, unsigned count, const void *tag)
228 : SymbolData(SymbolMetadataKind, sym), R(r), S(s), T(t), LCtx(LCtx),
229 Count(count), Tag(tag) {
230 assert(r);
231 assert(s);
232 assert(isValidTypeForSymbol(t));
233 assert(LCtx);
234 assert(tag);
235 }
236
237 LLVM_ATTRIBUTE_RETURNS_NONNULL
238 const MemRegion *getRegion() const { return R; }
239
240 LLVM_ATTRIBUTE_RETURNS_NONNULL
241 const Stmt *getStmt() const { return S; }
242
243 LLVM_ATTRIBUTE_RETURNS_NONNULL
244 const LocationContext *getLocationContext() const { return LCtx; }
245
246 unsigned getCount() const { return Count; }
247
248 LLVM_ATTRIBUTE_RETURNS_NONNULL
249 const void *getTag() const { return Tag; }
250
251 QualType getType() const override;
252
253 StringRef getKindStr() const override;
254
255 void dumpToStream(raw_ostream &os) const override;
256
257 static void Profile(llvm::FoldingSetNodeID &profile, const MemRegion *R,
258 const Stmt *S, QualType T, const LocationContext *LCtx,
259 unsigned Count, const void *Tag) {
260 profile.AddInteger((unsigned)SymbolMetadataKind);
261 profile.AddPointer(R);
262 profile.AddPointer(S);
263 profile.Add(T);
264 profile.AddPointer(LCtx);
265 profile.AddInteger(Count);
266 profile.AddPointer(Tag);
267 }
268
269 void Profile(llvm::FoldingSetNodeID& profile) override {
270 Profile(profile, R, S, T, LCtx, Count, Tag);
271 }
272
273 // Implement isa<T> support.
274 static bool classof(const SymExpr *SE) {
275 return SE->getKind() == SymbolMetadataKind;
276 }
277};
278
279/// Represents a cast expression.
280class SymbolCast : public SymExpr {
281 const SymExpr *Operand;
282
283 /// Type of the operand.
284 QualType FromTy;
285
286 /// The type of the result.
287 QualType ToTy;
288
289public:
290 SymbolCast(const SymExpr *In, QualType From, QualType To)
291 : SymExpr(SymbolCastKind), Operand(In), FromTy(From), ToTy(To) {
292 assert(In);
293 assert(isValidTypeForSymbol(From));
294 // FIXME: GenericTaintChecker creates symbols of void type.
295 // Otherwise, 'To' should also be a valid type.
296 }
297
298 unsigned computeComplexity() const override {
299 if (Complexity == 0)
300 Complexity = 1 + Operand->computeComplexity();
301 return Complexity;
302 }
303
304 QualType getType() const override { return ToTy; }
305
306 LLVM_ATTRIBUTE_RETURNS_NONNULL
307 const SymExpr *getOperand() const { return Operand; }
308
309 void dumpToStream(raw_ostream &os) const override;
310
311 static void Profile(llvm::FoldingSetNodeID& ID,
312 const SymExpr *In, QualType From, QualType To) {
313 ID.AddInteger((unsigned) SymbolCastKind);
314 ID.AddPointer(In);
315 ID.Add(From);
316 ID.Add(To);
317 }
318
319 void Profile(llvm::FoldingSetNodeID& ID) override {
320 Profile(ID, Operand, FromTy, ToTy);
321 }
322
323 // Implement isa<T> support.
324 static bool classof(const SymExpr *SE) {
325 return SE->getKind() == SymbolCastKind;
326 }
327};
328
329/// Represents a symbolic expression involving a unary operator.
330class UnarySymExpr : public SymExpr {
331 const SymExpr *Operand;
333 QualType T;
334
335public:
337 : SymExpr(UnarySymExprKind), Operand(In), Op(Op), T(T) {
338 // Note, some unary operators are modeled as a binary operator. E.g. ++x is
339 // modeled as x + 1.
340 assert((Op == UO_Minus || Op == UO_Not) && "non-supported unary expression");
341 // Unary expressions are results of arithmetic. Pointer arithmetic is not
342 // handled by unary expressions, but it is instead handled by applying
343 // sub-regions to regions.
344 assert(isValidTypeForSymbol(T) && "non-valid type for unary symbol");
345 assert(!Loc::isLocType(T) && "unary symbol should be nonloc");
346 }
347
348 unsigned computeComplexity() const override {
349 if (Complexity == 0)
350 Complexity = 1 + Operand->computeComplexity();
351 return Complexity;
352 }
353
354 const SymExpr *getOperand() const { return Operand; }
355 UnaryOperator::Opcode getOpcode() const { return Op; }
356 QualType getType() const override { return T; }
357
358 void dumpToStream(raw_ostream &os) const override;
359
360 static void Profile(llvm::FoldingSetNodeID &ID, const SymExpr *In,
362 ID.AddInteger((unsigned)UnarySymExprKind);
363 ID.AddPointer(In);
364 ID.AddInteger(Op);
365 ID.Add(T);
366 }
367
368 void Profile(llvm::FoldingSetNodeID &ID) override {
369 Profile(ID, Operand, Op, T);
370 }
371
372 // Implement isa<T> support.
373 static bool classof(const SymExpr *SE) {
374 return SE->getKind() == UnarySymExprKind;
375 }
376};
377
378/// Represents a symbolic expression involving a binary operator
379class BinarySymExpr : public SymExpr {
381 QualType T;
382
383protected:
385 : SymExpr(k), Op(op), T(t) {
386 assert(classof(this));
387 // Binary expressions are results of arithmetic. Pointer arithmetic is not
388 // handled by binary expressions, but it is instead handled by applying
389 // sub-regions to regions.
390 assert(isValidTypeForSymbol(t) && !Loc::isLocType(t));
391 }
392
393public:
394 // FIXME: We probably need to make this out-of-line to avoid redundant
395 // generation of virtual functions.
396 QualType getType() const override { return T; }
397
398 BinaryOperator::Opcode getOpcode() const { return Op; }
399
400 // Implement isa<T> support.
401 static bool classof(const SymExpr *SE) {
402 Kind k = SE->getKind();
403 return k >= BEGIN_BINARYSYMEXPRS && k <= END_BINARYSYMEXPRS;
404 }
405
406protected:
407 static unsigned computeOperandComplexity(const SymExpr *Value) {
408 return Value->computeComplexity();
409 }
410 static unsigned computeOperandComplexity(const llvm::APSInt &Value) {
411 return 1;
412 }
413
414 static const llvm::APSInt *getPointer(APSIntPtr Value) { return Value.get(); }
415 static const SymExpr *getPointer(const SymExpr *Value) { return Value; }
416
417 static void dumpToStreamImpl(raw_ostream &os, const SymExpr *Value);
418 static void dumpToStreamImpl(raw_ostream &os, const llvm::APSInt &Value);
419 static void dumpToStreamImpl(raw_ostream &os, BinaryOperator::Opcode op);
420};
421
422/// Template implementation for all binary symbolic expressions
423template <class LHSTYPE, class RHSTYPE, SymExpr::Kind ClassKind>
425 LHSTYPE LHS;
426 RHSTYPE RHS;
427
428public:
429 BinarySymExprImpl(LHSTYPE lhs, BinaryOperator::Opcode op, RHSTYPE rhs,
430 QualType t)
431 : BinarySymExpr(ClassKind, op, t), LHS(lhs), RHS(rhs) {
432 assert(getPointer(lhs));
433 assert(getPointer(rhs));
434 }
435
436 void dumpToStream(raw_ostream &os) const override {
437 dumpToStreamImpl(os, LHS);
439 dumpToStreamImpl(os, RHS);
440 }
441
442 LHSTYPE getLHS() const { return LHS; }
443 RHSTYPE getRHS() const { return RHS; }
444
445 unsigned computeComplexity() const override {
446 if (Complexity == 0)
447 Complexity =
449 return Complexity;
450 }
451
452 static void Profile(llvm::FoldingSetNodeID &ID, LHSTYPE lhs,
453 BinaryOperator::Opcode op, RHSTYPE rhs, QualType t) {
454 ID.AddInteger((unsigned)ClassKind);
455 ID.AddPointer(getPointer(lhs));
456 ID.AddInteger(op);
457 ID.AddPointer(getPointer(rhs));
458 ID.Add(t);
459 }
460
461 void Profile(llvm::FoldingSetNodeID &ID) override {
462 Profile(ID, LHS, getOpcode(), RHS, getType());
463 }
464
465 // Implement isa<T> support.
466 static bool classof(const SymExpr *SE) { return SE->getKind() == ClassKind; }
467};
468
469/// Represents a symbolic expression like 'x' + 3.
471 SymExpr::Kind::SymIntExprKind>;
472
473/// Represents a symbolic expression like 3 - 'x'.
475 SymExpr::Kind::IntSymExprKind>;
476
477/// Represents a symbolic expression like 'x' + 'y'.
479 SymExpr::Kind::SymSymExprKind>;
480
482 using DataSetTy = llvm::FoldingSet<SymExpr>;
483 using SymbolDependTy =
484 llvm::DenseMap<SymbolRef, std::unique_ptr<SymbolRefSmallVectorTy>>;
485
486 DataSetTy DataSet;
487
488 /// Stores the extra dependencies between symbols: the data should be kept
489 /// alive as long as the key is live.
490 SymbolDependTy SymbolDependencies;
491
492 unsigned SymbolCounter = 0;
493 llvm::BumpPtrAllocator& BPAlloc;
495 ASTContext &Ctx;
496
497public:
499 llvm::BumpPtrAllocator& bpalloc)
500 : SymbolDependencies(16), BPAlloc(bpalloc), BV(bv), Ctx(ctx) {}
501
502 static bool canSymbolicate(QualType T);
503
504 /// Make a unique symbol for MemRegion R according to its kind.
506
507 const SymbolConjured* conjureSymbol(const Stmt *E,
508 const LocationContext *LCtx,
509 QualType T,
510 unsigned VisitCount,
511 const void *SymbolTag = nullptr);
512
514 const LocationContext *LCtx,
515 unsigned VisitCount,
516 const void *SymbolTag = nullptr) {
517 return conjureSymbol(E, LCtx, E->getType(), VisitCount, SymbolTag);
518 }
519
520 const SymbolDerived *getDerivedSymbol(SymbolRef parentSymbol,
521 const TypedValueRegion *R);
522
523 const SymbolExtent *getExtentSymbol(const SubRegion *R);
524
525 /// Creates a metadata symbol associated with a specific region.
526 ///
527 /// VisitCount can be used to differentiate regions corresponding to
528 /// different loop iterations, thus, making the symbol path-dependent.
529 const SymbolMetadata *getMetadataSymbol(const MemRegion *R, const Stmt *S,
530 QualType T,
531 const LocationContext *LCtx,
532 unsigned VisitCount,
533 const void *SymbolTag = nullptr);
534
535 const SymbolCast* getCastSymbol(const SymExpr *Operand,
536 QualType From, QualType To);
537
539 APSIntPtr rhs, QualType t);
540
542 APSIntPtr rhs, QualType t) {
543 return getSymIntExpr(&lhs, op, rhs, t);
544 }
545
547 const SymExpr *rhs, QualType t);
548
550 const SymExpr *rhs, QualType t);
551
552 const UnarySymExpr *getUnarySymExpr(const SymExpr *operand,
554
555 QualType getType(const SymExpr *SE) const {
556 return SE->getType();
557 }
558
559 /// Add artificial symbol dependency.
560 ///
561 /// The dependent symbol should stay alive as long as the primary is alive.
562 void addSymbolDependency(const SymbolRef Primary, const SymbolRef Dependent);
563
565
566 ASTContext &getContext() { return Ctx; }
568};
569
570/// A class responsible for cleaning up unused symbols.
572 enum SymbolStatus {
573 NotProcessed,
574 HaveMarkedDependents
575 };
576
577 using SymbolSetTy = llvm::DenseSet<SymbolRef>;
578 using SymbolMapTy = llvm::DenseMap<SymbolRef, SymbolStatus>;
579 using RegionSetTy = llvm::DenseSet<const MemRegion *>;
580
581 SymbolMapTy TheLiving;
582 SymbolSetTy MetadataInUse;
583
584 RegionSetTy LiveRegionRoots;
585 // The lazily copied regions are locations for which a program
586 // can access the value stored at that location, but not its address.
587 // These regions are constructed as a set of regions referred to by
588 // lazyCompoundVal.
589 RegionSetTy LazilyCopiedRegionRoots;
590
591 const StackFrameContext *LCtx;
592 const Stmt *Loc;
593 SymbolManager& SymMgr;
594 StoreRef reapedStore;
595 llvm::DenseMap<const MemRegion *, unsigned> includedRegionCache;
596
597public:
598 /// Construct a reaper object, which removes everything which is not
599 /// live before we execute statement s in the given location context.
600 ///
601 /// If the statement is NULL, everything is this and parent contexts is
602 /// considered live.
603 /// If the stack frame context is NULL, everything on stack is considered
604 /// dead.
606 SymbolManager &symmgr, StoreManager &storeMgr)
607 : LCtx(Ctx), Loc(s), SymMgr(symmgr), reapedStore(nullptr, storeMgr) {}
608
609 /// It might return null.
610 const LocationContext *getLocationContext() const { return LCtx; }
611
612 bool isLive(SymbolRef sym);
613 bool isLiveRegion(const MemRegion *region);
614 bool isLive(const Expr *ExprVal, const LocationContext *LCtx) const;
615 bool isLive(const VarRegion *VR, bool includeStoreBindings = false) const;
616
617 /// Unconditionally marks a symbol as live.
618 ///
619 /// This should never be
620 /// used by checkers, only by the state infrastructure such as the store and
621 /// environment. Checkers should instead use metadata symbols and markInUse.
622 void markLive(SymbolRef sym);
623
624 /// Marks a symbol as important to a checker.
625 ///
626 /// For metadata symbols,
627 /// this will keep the symbol alive as long as its associated region is also
628 /// live. For other symbols, this has no effect; checkers are not permitted
629 /// to influence the life of other symbols. This should be used before any
630 /// symbol marking has occurred, i.e. in the MarkLiveSymbols callback.
631 void markInUse(SymbolRef sym);
632
633 llvm::iterator_range<RegionSetTy::const_iterator> regions() const {
634 return LiveRegionRoots;
635 }
636
637 /// Returns whether or not a symbol has been confirmed dead.
638 ///
639 /// This should only be called once all marking of dead symbols has completed.
640 /// (For checkers, this means only in the checkDeadSymbols callback.)
641 bool isDead(SymbolRef sym) {
642 return !isLive(sym);
643 }
644
645 void markLive(const MemRegion *region);
646 void markLazilyCopied(const MemRegion *region);
647 void markElementIndicesLive(const MemRegion *region);
648
649 /// Set to the value of the symbolic store after
650 /// StoreManager::removeDeadBindings has been called.
651 void setReapedStore(StoreRef st) { reapedStore = st; }
652
653private:
654 bool isLazilyCopiedRegion(const MemRegion *region) const;
655 // A readable region is a region that live or lazily copied.
656 // Any symbols that refer to values in regions are alive if the region
657 // is readable.
658 bool isReadableRegion(const MemRegion *region);
659
660 /// Mark the symbols dependent on the input symbol as live.
661 void markDependentsLive(SymbolRef sym);
662};
663
665protected:
666 ~SymbolVisitor() = default;
667
668public:
669 SymbolVisitor() = default;
670 SymbolVisitor(const SymbolVisitor &) = default;
672
673 // The copy and move assignment operator is defined as deleted pending further
674 // motivation.
677
678 /// A visitor method invoked by ProgramStateManager::scanReachableSymbols.
679 ///
680 /// The method returns \c true if symbols should continue be scanned and \c
681 /// false otherwise.
682 virtual bool VisitSymbol(SymbolRef sym) = 0;
683 virtual bool VisitMemRegion(const MemRegion *) { return true; }
684};
685
686} // namespace ento
687
688} // namespace clang
689
690#endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SYMBOLMANAGER_H
This file defines AnalysisDeclContext, a class that manages the analysis context data for context sen...
static char ID
Definition: Arena.cpp:183
Expr * E
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
llvm::DenseMap< const CFGBlock *, unsigned > VisitCount
Definition: Logger.cpp:30
C Language Family Type Representation.
__device__ __2f16 float __ockl_bool s
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:188
This represents one expression.
Definition: Expr.h:110
It wraps the AnalysisDeclContext to represent both the call stack with the help of StackFrameContext ...
A (possibly-)qualified type.
Definition: Type.h:929
It represents a stack frame of the call stack (based on CallEvent).
Stmt - This represents one statement.
Definition: Stmt.h:84
A safe wrapper around APSInt objects allocated and owned by BasicValueFactory.
Definition: APSIntPtr.h:19
Template implementation for all binary symbolic expressions.
static void Profile(llvm::FoldingSetNodeID &ID, LHSTYPE lhs, BinaryOperator::Opcode op, RHSTYPE rhs, QualType t)
BinarySymExprImpl(LHSTYPE lhs, BinaryOperator::Opcode op, RHSTYPE rhs, QualType t)
void Profile(llvm::FoldingSetNodeID &ID) override
void dumpToStream(raw_ostream &os) const override
unsigned computeComplexity() const override
static bool classof(const SymExpr *SE)
Represents a symbolic expression involving a binary operator.
BinarySymExpr(Kind k, BinaryOperator::Opcode op, QualType t)
QualType getType() const override
BinaryOperator::Opcode getOpcode() const
static unsigned computeOperandComplexity(const SymExpr *Value)
static void dumpToStreamImpl(raw_ostream &os, const SymExpr *Value)
static bool classof(const SymExpr *SE)
static unsigned computeOperandComplexity(const llvm::APSInt &Value)
static const llvm::APSInt * getPointer(APSIntPtr Value)
static const SymExpr * getPointer(const SymExpr *Value)
static bool isLocType(QualType T)
Definition: SVals.h:262
MemRegion - The root abstract class for all memory regions.
Definition: MemRegion.h:97
SubRegion - A region that subsets another larger region.
Definition: MemRegion.h:446
Symbolic value.
Definition: SymExpr.h:30
static bool isValidTypeForSymbol(QualType T)
Definition: SymExpr.h:46
virtual QualType getType() const =0
Kind getKind() const
Definition: SymExpr.h:57
unsigned Complexity
Definition: SymExpr.h:52
Represents a cast expression.
static bool classof(const SymExpr *SE)
static void Profile(llvm::FoldingSetNodeID &ID, const SymExpr *In, QualType From, QualType To)
QualType getType() const override
void Profile(llvm::FoldingSetNodeID &ID) override
void dumpToStream(raw_ostream &os) const override
LLVM_ATTRIBUTE_RETURNS_NONNULL const SymExpr * getOperand() const
SymbolCast(const SymExpr *In, QualType From, QualType To)
unsigned computeComplexity() const override
A symbol representing the result of an expression in the case when we do not know anything about what...
Definition: SymbolManager.h:80
void Profile(llvm::FoldingSetNodeID &profile) override
static bool classof(const SymExpr *SE)
StringRef getKindStr() const override
Get a string representation of the kind of the region.
static void Profile(llvm::FoldingSetNodeID &profile, const Stmt *S, QualType T, unsigned Count, const LocationContext *LCtx, const void *SymbolTag)
const void * getTag() const
It might return null.
void dumpToStream(raw_ostream &os) const override
QualType getType() const override
const Stmt * getStmt() const
It might return null.
SymbolConjured(SymbolID sym, const Stmt *s, const LocationContext *lctx, QualType t, unsigned count, const void *symbolTag)
Definition: SymbolManager.h:88
A symbol representing data which can be stored in a memory location (region).
Definition: SymExpr.h:119
A symbol representing the value of a MemRegion whose parent region has symbolic value.
LLVM_ATTRIBUTE_RETURNS_NONNULL SymbolRef getParentSymbol() const
StringRef getKindStr() const override
Get a string representation of the kind of the region.
void dumpToStream(raw_ostream &os) const override
const MemRegion * getOriginRegion() const override
Find the region from which this symbol originates.
static void Profile(llvm::FoldingSetNodeID &profile, SymbolRef parent, const TypedValueRegion *r)
void Profile(llvm::FoldingSetNodeID &profile) override
QualType getType() const override
LLVM_ATTRIBUTE_RETURNS_NONNULL const TypedValueRegion * getRegion() const
static bool classof(const SymExpr *SE)
SymbolDerived(SymbolID sym, SymbolRef parent, const TypedValueRegion *r)
SymbolExtent - Represents the extent (size in bytes) of a bounded region.
static bool classof(const SymExpr *SE)
LLVM_ATTRIBUTE_RETURNS_NONNULL const SubRegion * getRegion() const
void dumpToStream(raw_ostream &os) const override
QualType getType() const override
static void Profile(llvm::FoldingSetNodeID &profile, const SubRegion *R)
StringRef getKindStr() const override
Get a string representation of the kind of the region.
void Profile(llvm::FoldingSetNodeID &profile) override
SymbolExtent(SymbolID sym, const SubRegion *r)
const SymbolExtent * getExtentSymbol(const SubRegion *R)
SymbolManager(ASTContext &ctx, BasicValueFactory &bv, llvm::BumpPtrAllocator &bpalloc)
const SymbolDerived * getDerivedSymbol(SymbolRef parentSymbol, const TypedValueRegion *R)
const SymIntExpr * getSymIntExpr(const SymExpr &lhs, BinaryOperator::Opcode op, APSIntPtr rhs, QualType t)
const SymbolMetadata * getMetadataSymbol(const MemRegion *R, const Stmt *S, QualType T, const LocationContext *LCtx, unsigned VisitCount, const void *SymbolTag=nullptr)
Creates a metadata symbol associated with a specific region.
const SymbolRegionValue * getRegionValueSymbol(const TypedValueRegion *R)
Make a unique symbol for MemRegion R according to its kind.
const SymIntExpr * getSymIntExpr(const SymExpr *lhs, BinaryOperator::Opcode op, APSIntPtr rhs, QualType t)
const SymbolConjured * conjureSymbol(const Stmt *E, const LocationContext *LCtx, QualType T, unsigned VisitCount, const void *SymbolTag=nullptr)
const IntSymExpr * getIntSymExpr(APSIntPtr lhs, BinaryOperator::Opcode op, const SymExpr *rhs, QualType t)
void addSymbolDependency(const SymbolRef Primary, const SymbolRef Dependent)
Add artificial symbol dependency.
BasicValueFactory & getBasicVals()
QualType getType(const SymExpr *SE) const
const SymbolCast * getCastSymbol(const SymExpr *Operand, QualType From, QualType To)
const SymbolConjured * conjureSymbol(const Expr *E, const LocationContext *LCtx, unsigned VisitCount, const void *SymbolTag=nullptr)
const UnarySymExpr * getUnarySymExpr(const SymExpr *operand, UnaryOperator::Opcode op, QualType t)
const SymbolRefSmallVectorTy * getDependentSymbols(const SymbolRef Primary)
static bool canSymbolicate(QualType T)
const SymSymExpr * getSymSymExpr(const SymExpr *lhs, BinaryOperator::Opcode op, const SymExpr *rhs, QualType t)
SymbolMetadata - Represents path-dependent metadata about a specific region.
SymbolMetadata(SymbolID sym, const MemRegion *r, const Stmt *s, QualType t, const LocationContext *LCtx, unsigned count, const void *tag)
void dumpToStream(raw_ostream &os) const override
LLVM_ATTRIBUTE_RETURNS_NONNULL const MemRegion * getRegion() const
LLVM_ATTRIBUTE_RETURNS_NONNULL const Stmt * getStmt() const
static void Profile(llvm::FoldingSetNodeID &profile, const MemRegion *R, const Stmt *S, QualType T, const LocationContext *LCtx, unsigned Count, const void *Tag)
StringRef getKindStr() const override
Get a string representation of the kind of the region.
QualType getType() const override
static bool classof(const SymExpr *SE)
void Profile(llvm::FoldingSetNodeID &profile) override
LLVM_ATTRIBUTE_RETURNS_NONNULL const void * getTag() const
LLVM_ATTRIBUTE_RETURNS_NONNULL const LocationContext * getLocationContext() const
A class responsible for cleaning up unused symbols.
void markLive(SymbolRef sym)
Unconditionally marks a symbol as live.
void markElementIndicesLive(const MemRegion *region)
SymbolReaper(const StackFrameContext *Ctx, const Stmt *s, SymbolManager &symmgr, StoreManager &storeMgr)
Construct a reaper object, which removes everything which is not live before we execute statement s i...
bool isDead(SymbolRef sym)
Returns whether or not a symbol has been confirmed dead.
void markInUse(SymbolRef sym)
Marks a symbol as important to a checker.
bool isLiveRegion(const MemRegion *region)
void markLazilyCopied(const MemRegion *region)
const LocationContext * getLocationContext() const
It might return null.
void setReapedStore(StoreRef st)
Set to the value of the symbolic store after StoreManager::removeDeadBindings has been called.
bool isLive(SymbolRef sym)
llvm::iterator_range< RegionSetTy::const_iterator > regions() const
A symbol representing the value stored at a MemRegion.
Definition: SymbolManager.h:43
void dumpToStream(raw_ostream &os) const override
const MemRegion * getOriginRegion() const override
Find the region from which this symbol originates.
Definition: SymbolManager.h:68
void Profile(llvm::FoldingSetNodeID &profile) override
Definition: SymbolManager.h:61
LLVM_ATTRIBUTE_RETURNS_NONNULL const TypedValueRegion * getRegion() const
Definition: SymbolManager.h:54
SymbolRegionValue(SymbolID sym, const TypedValueRegion *r)
Definition: SymbolManager.h:47
static void Profile(llvm::FoldingSetNodeID &profile, const TypedValueRegion *R)
Definition: SymbolManager.h:56
QualType getType() const override
StringRef getKindStr() const override
Get a string representation of the kind of the region.
static bool classof(const SymExpr *SE)
Definition: SymbolManager.h:73
virtual bool VisitMemRegion(const MemRegion *)
SymbolVisitor(const SymbolVisitor &)=default
SymbolVisitor(SymbolVisitor &&)
SymbolVisitor & operator=(SymbolVisitor &&)=delete
SymbolVisitor & operator=(const SymbolVisitor &)=delete
virtual bool VisitSymbol(SymbolRef sym)=0
A visitor method invoked by ProgramStateManager::scanReachableSymbols.
TypedValueRegion - An abstract class representing regions having a typed value.
Definition: MemRegion.h:535
virtual QualType getValueType() const =0
Represents a symbolic expression involving a unary operator.
void dumpToStream(raw_ostream &os) const override
void Profile(llvm::FoldingSetNodeID &ID) override
QualType getType() const override
static bool classof(const SymExpr *SE)
UnaryOperator::Opcode getOpcode() const
unsigned computeComplexity() const override
UnarySymExpr(const SymExpr *In, UnaryOperator::Opcode Op, QualType T)
static void Profile(llvm::FoldingSetNodeID &ID, const SymExpr *In, UnaryOperator::Opcode Op, QualType T)
const SymExpr * getOperand() const
The JSON file list parser is used to communicate input to InstallAPI.
BinaryOperatorKind
UnaryOperatorKind
const FunctionProtoType * T