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