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