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