clang  16.0.0git
SVals.h
Go to the documentation of this file.
1 //===- SVals.h - Abstract Values for Static Analysis ------------*- 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 SVal, Loc, and NonLoc, classes that represent
10 // abstract r-values for use with path-sensitive value tracking.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SVALS_H
15 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SVALS_H
16 
17 #include "clang/AST/Expr.h"
18 #include "clang/AST/Type.h"
19 #include "clang/Basic/LLVM.h"
21 #include "llvm/ADT/FoldingSet.h"
22 #include "llvm/ADT/ImmutableList.h"
23 #include "llvm/ADT/None.h"
24 #include "llvm/ADT/Optional.h"
25 #include "llvm/ADT/PointerUnion.h"
26 #include "llvm/Support/Casting.h"
27 #include <cassert>
28 #include <cstdint>
29 #include <utility>
30 
31 //==------------------------------------------------------------------------==//
32 // Base SVal types.
33 //==------------------------------------------------------------------------==//
34 
35 namespace clang {
36 
37 class CXXBaseSpecifier;
38 class FunctionDecl;
39 class LabelDecl;
40 
41 namespace ento {
42 
43 class CompoundValData;
44 class LazyCompoundValData;
45 class MemRegion;
46 class PointerToMemberData;
47 class SValBuilder;
48 class TypedValueRegion;
49 
50 namespace nonloc {
51 
52 /// Sub-kinds for NonLoc values.
53 enum Kind {
54 #define NONLOC_SVAL(Id, Parent) Id ## Kind,
55 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.def"
56 };
57 
58 } // namespace nonloc
59 
60 namespace loc {
61 
62 /// Sub-kinds for Loc values.
63 enum Kind {
64 #define LOC_SVAL(Id, Parent) Id ## Kind,
65 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.def"
66 };
67 
68 } // namespace loc
69 
70 /// SVal - This represents a symbolic expression, which can be either
71 /// an L-value or an R-value.
72 ///
73 class SVal {
74 public:
75  enum BaseKind {
76  // The enumerators must be representable using 2 bits.
77 #define BASIC_SVAL(Id, Parent) Id ## Kind,
78 #define ABSTRACT_SVAL_WITH_KIND(Id, Parent) Id ## Kind,
79 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.def"
80  };
81  enum { BaseBits = 2, BaseMask = 0b11 };
82 
83 protected:
84  const void *Data = nullptr;
85 
86  /// The lowest 2 bits are a BaseKind (0 -- 3).
87  /// The higher bits are an unsigned "kind" value.
88  unsigned Kind = 0;
89 
90  explicit SVal(const void *d, bool isLoc, unsigned ValKind)
91  : Data(d), Kind((isLoc ? LocKind : NonLocKind) | (ValKind << BaseBits)) {}
92 
93  explicit SVal(BaseKind k, const void *D = nullptr) : Data(D), Kind(k) {}
94 
95 public:
96  explicit SVal() = default;
97 
98  /// Convert to the specified SVal type, asserting that this SVal is of
99  /// the desired type.
100  template <typename T> T castAs() const { return llvm::cast<T>(*this); }
101 
102  /// Convert to the specified SVal type, returning None if this SVal is
103  /// not of the desired type.
104  template <typename T> Optional<T> getAs() const {
105  return llvm::dyn_cast<T>(*this);
106  }
107 
108  unsigned getRawKind() const { return Kind; }
109  BaseKind getBaseKind() const { return (BaseKind) (Kind & BaseMask); }
110  unsigned getSubKind() const { return Kind >> BaseBits; }
111 
112  // This method is required for using SVal in a FoldingSetNode. It
113  // extracts a unique signature for this SVal object.
114  void Profile(llvm::FoldingSetNodeID &ID) const {
115  ID.AddInteger((unsigned) getRawKind());
116  ID.AddPointer(Data);
117  }
118 
119  bool operator==(SVal R) const {
120  return getRawKind() == R.getRawKind() && Data == R.Data;
121  }
122 
123  bool operator!=(SVal R) const { return !(*this == R); }
124 
125  bool isUnknown() const {
126  return getRawKind() == UnknownValKind;
127  }
128 
129  bool isUndef() const {
130  return getRawKind() == UndefinedValKind;
131  }
132 
133  bool isUnknownOrUndef() const {
134  return getRawKind() <= UnknownValKind;
135  }
136 
137  bool isValid() const {
138  return getRawKind() > UnknownValKind;
139  }
140 
141  bool isConstant() const;
142 
143  bool isConstant(int I) const;
144 
145  bool isZeroConstant() const;
146 
147  /// getAsFunctionDecl - If this SVal is a MemRegionVal and wraps a
148  /// CodeTextRegion wrapping a FunctionDecl, return that FunctionDecl.
149  /// Otherwise return 0.
150  const FunctionDecl *getAsFunctionDecl() const;
151 
152  /// If this SVal is a location and wraps a symbol, return that
153  /// SymbolRef. Otherwise return 0.
154  ///
155  /// Casts are ignored during lookup.
156  /// \param IncludeBaseRegions The boolean that controls whether the search
157  /// should continue to the base regions if the region is not symbolic.
158  SymbolRef getAsLocSymbol(bool IncludeBaseRegions = false) const;
159 
160  /// Get the symbol in the SVal or its base region.
162 
163  /// If this SVal wraps a symbol return that SymbolRef.
164  /// Otherwise, return 0.
165  ///
166  /// Casts are ignored during lookup.
167  /// \param IncludeBaseRegions The boolean that controls whether the search
168  /// should continue to the base regions if the region is not symbolic.
169  SymbolRef getAsSymbol(bool IncludeBaseRegions = false) const;
170 
171  /// If this SVal is loc::ConcreteInt or nonloc::ConcreteInt,
172  /// return a pointer to APSInt which is held in it.
173  /// Otherwise, return nullptr.
174  const llvm::APSInt *getAsInteger() const;
175 
176  const MemRegion *getAsRegion() const;
177 
178  /// printJson - Pretty-prints in JSON format.
179  void printJson(raw_ostream &Out, bool AddQuotes) const;
180 
181  void dumpToStream(raw_ostream &OS) const;
182  void dump() const;
183 
185  const SymExpr *SE = getAsSymbol(/*IncludeBaseRegions=*/true);
186  if (SE)
187  return SE->symbol_begin();
188  else
189  return SymExpr::symbol_iterator();
190  }
191 
193  return SymExpr::symbol_end();
194  }
195 
196  /// Try to get a reasonable type for the given value.
197  ///
198  /// \returns The best approximation of the value type or Null.
199  /// In theory, all symbolic values should be typed, but this function
200  /// is still a WIP and might have a few blind spots.
201  ///
202  /// \note This function should not be used when the user has access to the
203  /// bound expression AST node as well, since AST always has exact types.
204  ///
205  /// \note Loc values are interpreted as pointer rvalues for the purposes of
206  /// this method.
207  QualType getType(const ASTContext &) const;
208 };
209 
210 inline raw_ostream &operator<<(raw_ostream &os, clang::ento::SVal V) {
211  V.dumpToStream(os);
212  return os;
213 }
214 
215 class UndefinedVal : public SVal {
216 public:
217  UndefinedVal() : SVal(UndefinedValKind) {}
218  static bool classof(SVal V) { return V.getBaseKind() == UndefinedValKind; }
219 };
220 
221 class DefinedOrUnknownSVal : public SVal {
222 public:
223  // We want calling these methods to be a compiler error since they are
224  // tautologically false.
225  bool isUndef() const = delete;
226  bool isValid() const = delete;
227 
228  static bool classof(SVal V) { return !V.isUndef(); }
229 
230 protected:
231  explicit DefinedOrUnknownSVal(const void *d, bool isLoc, unsigned ValKind)
232  : SVal(d, isLoc, ValKind) {}
233  explicit DefinedOrUnknownSVal(BaseKind k, void *D = nullptr) : SVal(k, D) {}
234 };
235 
237 public:
238  explicit UnknownVal() : DefinedOrUnknownSVal(UnknownValKind) {}
239 
240  static bool classof(SVal V) { return V.getBaseKind() == UnknownValKind; }
241 };
242 
244 public:
245  // We want calling these methods to be a compiler error since they are
246  // tautologically true/false.
247  bool isUnknown() const = delete;
248  bool isUnknownOrUndef() const = delete;
249  bool isValid() const = delete;
250 
251  static bool classof(SVal V) { return !V.isUnknownOrUndef(); }
252 
253 protected:
254  explicit DefinedSVal(const void *d, bool isLoc, unsigned ValKind)
255  : DefinedOrUnknownSVal(d, isLoc, ValKind) {}
256 };
257 
258 /// Represents an SVal that is guaranteed to not be UnknownVal.
259 class KnownSVal : public SVal {
260 public:
261  KnownSVal(const DefinedSVal &V) : SVal(V) {}
262  KnownSVal(const UndefinedVal &V) : SVal(V) {}
263  static bool classof(SVal V) { return !V.isUnknown(); }
264 };
265 
266 class NonLoc : public DefinedSVal {
267 protected:
268  explicit NonLoc(unsigned SubKind, const void *d)
269  : DefinedSVal(d, false, SubKind) {}
270 
271 public:
272  void dumpToStream(raw_ostream &Out) const;
273 
274  static bool isCompoundType(QualType T) {
275  return T->isArrayType() || T->isRecordType() ||
276  T->isAnyComplexType() || T->isVectorType();
277  }
278 
279  static bool classof(SVal V) { return V.getBaseKind() == NonLocKind; }
280 };
281 
282 class Loc : public DefinedSVal {
283 protected:
284  explicit Loc(unsigned SubKind, const void *D)
285  : DefinedSVal(const_cast<void *>(D), true, SubKind) {}
286 
287 public:
288  void dumpToStream(raw_ostream &Out) const;
289 
290  static bool isLocType(QualType T) {
291  return T->isAnyPointerType() || T->isBlockPointerType() ||
292  T->isReferenceType() || T->isNullPtrType();
293  }
294 
295  static bool classof(SVal V) { return V.getBaseKind() == LocKind; }
296 };
297 
298 //==------------------------------------------------------------------------==//
299 // Subclasses of NonLoc.
300 //==------------------------------------------------------------------------==//
301 
302 namespace nonloc {
303 
304 /// Represents symbolic expression that isn't a location.
305 class SymbolVal : public NonLoc {
306 public:
307  SymbolVal() = delete;
308  SymbolVal(SymbolRef sym) : NonLoc(SymbolValKind, sym) {
309  assert(sym);
310  assert(!Loc::isLocType(sym->getType()));
311  }
312 
313  LLVM_ATTRIBUTE_RETURNS_NONNULL
315  return (const SymExpr *) Data;
316  }
317 
318  bool isExpression() const {
319  return !isa<SymbolData>(getSymbol());
320  }
321 
322  static bool classof(SVal V) {
323  return V.getBaseKind() == NonLocKind && V.getSubKind() == SymbolValKind;
324  }
325 
326  static bool classof(NonLoc V) { return V.getSubKind() == SymbolValKind; }
327 };
328 
329 /// Value representing integer constant.
330 class ConcreteInt : public NonLoc {
331 public:
332  explicit ConcreteInt(const llvm::APSInt& V) : NonLoc(ConcreteIntKind, &V) {}
333 
334  const llvm::APSInt& getValue() const {
335  return *static_cast<const llvm::APSInt *>(Data);
336  }
337 
338  static bool classof(SVal V) {
339  return V.getBaseKind() == NonLocKind && V.getSubKind() == ConcreteIntKind;
340  }
341 
342  static bool classof(NonLoc V) { return V.getSubKind() == ConcreteIntKind; }
343 };
344 
345 class LocAsInteger : public NonLoc {
346  friend class ento::SValBuilder;
347 
348  explicit LocAsInteger(const std::pair<SVal, uintptr_t> &data)
349  : NonLoc(LocAsIntegerKind, &data) {
350  // We do not need to represent loc::ConcreteInt as LocAsInteger,
351  // as it'd collapse into a nonloc::ConcreteInt instead.
352  assert(data.first.getBaseKind() == LocKind &&
353  (data.first.getSubKind() == loc::MemRegionValKind ||
354  data.first.getSubKind() == loc::GotoLabelKind));
355  }
356 
357 public:
358  Loc getLoc() const {
359  const std::pair<SVal, uintptr_t> *D =
360  static_cast<const std::pair<SVal, uintptr_t> *>(Data);
361  return D->first.castAs<Loc>();
362  }
363 
364  unsigned getNumBits() const {
365  const std::pair<SVal, uintptr_t> *D =
366  static_cast<const std::pair<SVal, uintptr_t> *>(Data);
367  return D->second;
368  }
369 
370  static bool classof(SVal V) {
371  return V.getBaseKind() == NonLocKind && V.getSubKind() == LocAsIntegerKind;
372  }
373 
374  static bool classof(NonLoc V) { return V.getSubKind() == LocAsIntegerKind; }
375 };
376 
377 class CompoundVal : public NonLoc {
378  friend class ento::SValBuilder;
379 
380  explicit CompoundVal(const CompoundValData *D) : NonLoc(CompoundValKind, D) {
381  assert(D);
382  }
383 
384 public:
385  LLVM_ATTRIBUTE_RETURNS_NONNULL
386  const CompoundValData* getValue() const {
387  return static_cast<const CompoundValData *>(Data);
388  }
389 
390  using iterator = llvm::ImmutableList<SVal>::iterator;
391 
392  iterator begin() const;
393  iterator end() const;
394 
395  static bool classof(SVal V) {
396  return V.getBaseKind() == NonLocKind && V.getSubKind() == CompoundValKind;
397  }
398 
399  static bool classof(NonLoc V) { return V.getSubKind() == CompoundValKind; }
400 };
401 
402 class LazyCompoundVal : public NonLoc {
403  friend class ento::SValBuilder;
404 
405  explicit LazyCompoundVal(const LazyCompoundValData *D)
406  : NonLoc(LazyCompoundValKind, D) {
407  assert(D);
408  }
409 
410 public:
411  LLVM_ATTRIBUTE_RETURNS_NONNULL
413  return static_cast<const LazyCompoundValData *>(Data);
414  }
415 
416  /// It might return null.
417  const void *getStore() const;
418 
419  LLVM_ATTRIBUTE_RETURNS_NONNULL
420  const TypedValueRegion *getRegion() const;
421 
422  static bool classof(SVal V) {
423  return V.getBaseKind() == NonLocKind &&
424  V.getSubKind() == LazyCompoundValKind;
425  }
426 
427  static bool classof(NonLoc V) {
428  return V.getSubKind() == LazyCompoundValKind;
429  }
430 };
431 
432 /// Value representing pointer-to-member.
433 ///
434 /// This value is qualified as NonLoc because neither loading nor storing
435 /// operations are applied to it. Instead, the analyzer uses the L-value coming
436 /// from pointer-to-member applied to an object.
437 /// This SVal is represented by a NamedDecl which can be a member function
438 /// pointer or a member data pointer and an optional list of CXXBaseSpecifiers.
439 /// This list is required to accumulate the pointer-to-member cast history to
440 /// figure out the correct subobject field. In particular, implicit casts grow
441 /// this list and explicit casts like static_cast shrink this list.
442 class PointerToMember : public NonLoc {
443  friend class ento::SValBuilder;
444 
445 public:
446  using PTMDataType =
447  llvm::PointerUnion<const NamedDecl *, const PointerToMemberData *>;
448 
449  const PTMDataType getPTMData() const {
450  return PTMDataType::getFromOpaqueValue(const_cast<void *>(Data));
451  }
452 
453  bool isNullMemberPointer() const;
454 
455  const NamedDecl *getDecl() const;
456 
457  template<typename AdjustedDecl>
458  const AdjustedDecl *getDeclAs() const {
459  return dyn_cast_or_null<AdjustedDecl>(getDecl());
460  }
461 
462  using iterator = llvm::ImmutableList<const CXXBaseSpecifier *>::iterator;
463 
464  iterator begin() const;
465  iterator end() const;
466 
467  static bool classof(SVal V) {
468  return V.getBaseKind() == NonLocKind &&
469  V.getSubKind() == PointerToMemberKind;
470  }
471 
472  static bool classof(NonLoc V) {
473  return V.getSubKind() == PointerToMemberKind;
474  }
475 
476 private:
477  explicit PointerToMember(const PTMDataType D)
478  : NonLoc(PointerToMemberKind, D.getOpaqueValue()) {}
479 };
480 
481 } // namespace nonloc
482 
483 //==------------------------------------------------------------------------==//
484 // Subclasses of Loc.
485 //==------------------------------------------------------------------------==//
486 
487 namespace loc {
488 
489 class GotoLabel : public Loc {
490 public:
491  explicit GotoLabel(const LabelDecl *Label) : Loc(GotoLabelKind, Label) {
492  assert(Label);
493  }
494 
495  const LabelDecl *getLabel() const {
496  return static_cast<const LabelDecl *>(Data);
497  }
498 
499  static bool classof(SVal V) {
500  return V.getBaseKind() == LocKind && V.getSubKind() == GotoLabelKind;
501  }
502 
503  static bool classof(Loc V) { return V.getSubKind() == GotoLabelKind; }
504 };
505 
506 class MemRegionVal : public Loc {
507 public:
508  explicit MemRegionVal(const MemRegion* r) : Loc(MemRegionValKind, r) {
509  assert(r);
510  }
511 
512  /// Get the underlining region.
513  const MemRegion *getRegion() const {
514  return static_cast<const MemRegion *>(Data);
515  }
516 
517  /// Get the underlining region and strip casts.
518  const MemRegion* stripCasts(bool StripBaseCasts = true) const;
519 
520  template <typename REGION>
521  const REGION* getRegionAs() const {
522  return dyn_cast<REGION>(getRegion());
523  }
524 
525  bool operator==(const MemRegionVal &R) const {
526  return getRegion() == R.getRegion();
527  }
528 
529  bool operator!=(const MemRegionVal &R) const {
530  return getRegion() != R.getRegion();
531  }
532 
533  static bool classof(SVal V) {
534  return V.getBaseKind() == LocKind && V.getSubKind() == MemRegionValKind;
535  }
536 
537  static bool classof(Loc V) { return V.getSubKind() == MemRegionValKind; }
538 };
539 
540 class ConcreteInt : public Loc {
541 public:
542  explicit ConcreteInt(const llvm::APSInt& V) : Loc(ConcreteIntKind, &V) {}
543 
544  const llvm::APSInt &getValue() const {
545  return *static_cast<const llvm::APSInt *>(Data);
546  }
547 
548  static bool classof(SVal V) {
549  return V.getBaseKind() == LocKind && V.getSubKind() == ConcreteIntKind;
550  }
551 
552  static bool classof(Loc V) { return V.getSubKind() == ConcreteIntKind; }
553 };
554 
555 } // namespace loc
556 } // namespace ento
557 } // namespace clang
558 
559 namespace llvm {
560 template <typename To, typename From>
561 struct CastInfo<
562  To, From,
563  std::enable_if_t<std::is_base_of<::clang::ento::SVal, From>::value>>
564  : public CastIsPossible<To, ::clang::ento::SVal> {
565  using Self = CastInfo<
566  To, From,
567  std::enable_if_t<std::is_base_of<::clang::ento::SVal, From>::value>>;
568  static bool isPossible(const From &V) {
569  return To::classof(*static_cast<const ::clang::ento::SVal *>(&V));
570  }
571  static Optional<To> castFailed() { return Optional<To>{}; }
572  static To doCast(const From &f) {
573  return *static_cast<const To *>(cast<::clang::ento::SVal>(&f));
574  }
575  static Optional<To> doCastIfPossible(const From &f) {
576  if (!Self::isPossible(f))
577  return Self::castFailed();
578  return doCast(f);
579  }
580 };
581 } // namespace llvm
582 
583 #endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SVALS_H
clang::ento::nonloc::SymbolVal::SymbolVal
SymbolVal()=delete
clang::ento::SVal::isValid
bool isValid() const
Definition: SVals.h:137
clang::ento::nonloc::SymbolVal::isExpression
bool isExpression() const
Definition: SVals.h:318
clang::ento::DefinedSVal::isUnknownOrUndef
bool isUnknownOrUndef() const =delete
clang::ento::Loc::isLocType
static bool isLocType(QualType T)
Definition: SVals.h:290
clang::Type::isRecordType
bool isRecordType() const
Definition: Type.h:7026
clang::ento::UndefinedVal
Definition: SVals.h:215
clang::ento::SVal::dumpToStream
void dumpToStream(raw_ostream &OS) const
Definition: SVals.cpp:280
clang::ento::nonloc::LocAsInteger::getLoc
Loc getLoc() const
Definition: SVals.h:358
llvm
YAML serialization mapping.
Definition: Dominators.h:30
clang::ento::SVal::operator==
bool operator==(SVal R) const
Definition: SVals.h:119
clang::Type::isBlockPointerType
bool isBlockPointerType() const
Definition: Type.h:6944
clang::ento::SVal::SVal
SVal(const void *d, bool isLoc, unsigned ValKind)
Definition: SVals.h:90
clang::ento::SVal::BaseKind
BaseKind
Definition: SVals.h:75
clang::ento::LazyCompoundValData
Definition: BasicValueFactory.h:62
clang::ento::SVal::Profile
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: SVals.h:114
clang::ento::CompoundValData
Definition: BasicValueFactory.h:40
clang::ento::SymExpr::symbol_iterator
Iterator over symbols that the current symbol depends on.
Definition: SymExpr.h:70
clang::ento::nonloc::CompoundVal
Definition: SVals.h:377
clang::ento::loc::ConcreteInt::classof
static bool classof(Loc V)
Definition: SVals.h:552
clang::ento::SVal::getAsFunctionDecl
const FunctionDecl * getAsFunctionDecl() const
getAsFunctionDecl - If this SVal is a MemRegionVal and wraps a CodeTextRegion wrapping a FunctionDecl...
Definition: SVals.cpp:46
clang::ento::SVal::castAs
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
Definition: SVals.h:100
clang::ento::SVal::isConstant
bool isConstant() const
Definition: SVals.cpp:249
clang::ento::loc::MemRegionVal::stripCasts
const MemRegion * stripCasts(bool StripBaseCasts=true) const
Get the underlining region and strip casts.
Definition: SVals.cpp:189
clang::ento::SVal::isUndef
bool isUndef() const
Definition: SVals.h:129
clang::ento::SVal::getLocSymbolInBase
SymbolRef getLocSymbolInBase() const
Get the symbol in the SVal or its base region.
Definition: SVals.cpp:80
clang::ento::NonLoc
Definition: SVals.h:266
clang::ento::SVal::getAsRegion
const MemRegion * getAsRegion() const
Definition: SVals.cpp:120
clang::ento::DefinedOrUnknownSVal
Definition: SVals.h:221
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:247
clang::ento::loc::GotoLabel::getLabel
const LabelDecl * getLabel() const
Definition: SVals.h:495
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:737
clang::ento::SVal::isZeroConstant
bool isZeroConstant() const
Definition: SVals.cpp:261
clang::ento::loc::GotoLabel
Definition: SVals.h:489
clang::ento::nonloc::SymbolVal::classof
static bool classof(NonLoc V)
Definition: SVals.h:326
llvm::Optional
Definition: LLVM.h:40
clang::ento::nonloc::PointerToMember::begin
iterator begin() const
Definition: SVals.cpp:231
clang::ento::KnownSVal::KnownSVal
KnownSVal(const DefinedSVal &V)
Definition: SVals.h:261
clang::ento::SVal::printJson
void printJson(raw_ostream &Out, bool AddQuotes) const
printJson - Pretty-prints in JSON format.
Definition: SVals.cpp:271
clang::ento::nonloc::ConcreteInt
Value representing integer constant.
Definition: SVals.h:330
clang::ento::UnknownVal
Definition: SVals.h:236
clang::ento::SVal::dump
void dump() const
Definition: SVals.cpp:269
clang::ento::loc::MemRegionVal
Definition: SVals.h:506
clang::ento::loc::ConcreteInt
Definition: SVals.h:540
clang::ento::nonloc::CompoundVal::classof
static bool classof(NonLoc V)
Definition: SVals.h:399
clang::ento::nonloc::LocAsInteger::getNumBits
unsigned getNumBits() const
Definition: SVals.h:364
clang::ento::SVal::getAs
Optional< T > getAs() const
Convert to the specified SVal type, returning None if this SVal is not of the desired type.
Definition: SVals.h:104
clang::ento::Loc::dumpToStream
void dumpToStream(raw_ostream &Out) const
Definition: SVals.cpp:363
clang::ento::nonloc::PointerToMember::isNullMemberPointer
bool isNullMemberPointer() const
Definition: SVals.cpp:201
clang::ento::MemRegion
MemRegion - The root abstract class for all memory regions.
Definition: MemRegion.h:95
clang::ento::nonloc::SymbolVal::classof
static bool classof(SVal V)
Definition: SVals.h:322
APSInt
llvm::APSInt APSInt
Definition: ByteCodeEmitter.cpp:19
clang::ento::SVal::getAsLocSymbol
SymbolRef getAsLocSymbol(bool IncludeBaseRegions=false) const
If this SVal is a location and wraps a symbol, return that SymbolRef.
Definition: SVals.cpp:68
SymExpr.h
clang::Type::isReferenceType
bool isReferenceType() const
Definition: Type.h:6948
V
#define V(N, I)
Definition: ASTContext.h:3233
clang::ento::DefinedSVal
Definition: SVals.h:243
clang::ento::SVal::Data
const void * Data
Definition: SVals.h:84
clang::ento::NonLoc::isCompoundType
static bool isCompoundType(QualType T)
Definition: SVals.h:274
clang::ento::loc::ConcreteInt::classof
static bool classof(SVal V)
Definition: SVals.h:548
clang::ento::SymExpr::getType
virtual QualType getType() const =0
clang::ento::SVal::Kind
unsigned Kind
The lowest 2 bits are a BaseKind (0 – 3).
Definition: SVals.h:88
clang::Type::isNullPtrType
bool isNullPtrType() const
Definition: Type.h:7250
clang::ento::UndefinedVal::UndefinedVal
UndefinedVal()
Definition: SVals.h:217
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:209
clang::ento::SVal::SVal
SVal()=default
clang::ento::nonloc::CompoundVal::getValue
const LLVM_ATTRIBUTE_RETURNS_NONNULL CompoundValData * getValue() const
Definition: SVals.h:386
clang::ento::SymExpr
Symbolic value.
Definition: SymExpr.h:29
clang::ento::nonloc::Kind
Kind
Sub-kinds for NonLoc values.
Definition: SVals.h:53
clang::ento::Loc::classof
static bool classof(SVal V)
Definition: SVals.h:295
clang::ento::nonloc::LazyCompoundVal::getStore
const void * getStore() const
It might return null.
Definition: SVals.cpp:193
clang::ento::nonloc::PointerToMember
Value representing pointer-to-member.
Definition: SVals.h:442
clang::Type::isVectorType
bool isVectorType() const
Definition: Type.h:7038
clang::LabelDecl
Represents the declaration of a label.
Definition: Decl.h:494
clang::ento::nonloc::PointerToMember::getPTMData
const PTMDataType getPTMData() const
Definition: SVals.h:449
clang::ento::nonloc::PointerToMember::getDecl
const NamedDecl * getDecl() const
Definition: SVals.cpp:205
Type.h
clang::ento::DefinedOrUnknownSVal::DefinedOrUnknownSVal
DefinedOrUnknownSVal(const void *d, bool isLoc, unsigned ValKind)
Definition: SVals.h:231
Expr.h
clang::ento::nonloc::SymbolVal::SymbolVal
SymbolVal(SymbolRef sym)
Definition: SVals.h:308
clang::ento::nonloc::PointerToMember::iterator
llvm::ImmutableList< const CXXBaseSpecifier * >::iterator iterator
Definition: SVals.h:462
llvm::CastInfo< To, From, std::enable_if_t< std::is_base_of<::clang::ento::SVal, From >::value > >::castFailed
static Optional< To > castFailed()
Definition: SVals.h:571
clang::ento::nonloc::ConcreteInt::classof
static bool classof(SVal V)
Definition: SVals.h:338
clang::ento::NonLoc::dumpToStream
void dumpToStream(raw_ostream &Out) const
Definition: SVals.cpp:297
clang::ento::NonLoc::NonLoc
NonLoc(unsigned SubKind, const void *d)
Definition: SVals.h:268
clang::Type::isAnyComplexType
bool isAnyComplexType() const
Definition: Type.h:7034
Label
std::string Label
Definition: UsingDeclarationsSorter.cpp:69
clang::ento::nonloc::CompoundVal::classof
static bool classof(SVal V)
Definition: SVals.h:395
clang::ento::DefinedOrUnknownSVal::DefinedOrUnknownSVal
DefinedOrUnknownSVal(BaseKind k, void *D=nullptr)
Definition: SVals.h:233
clang::ento::nonloc::LazyCompoundVal
Definition: SVals.h:402
clang::ento::loc::GotoLabel::classof
static bool classof(SVal V)
Definition: SVals.h:499
clang::ento::KnownSVal
Represents an SVal that is guaranteed to not be UnknownVal.
Definition: SVals.h:259
clang::prec::PointerToMember
@ PointerToMember
Definition: OperatorPrecedence.h:42
clang::ento::loc::GotoLabel::GotoLabel
GotoLabel(const LabelDecl *Label)
Definition: SVals.h:491
clang::ento::Loc
Definition: SVals.h:282
clang::ento::UnknownVal::UnknownVal
UnknownVal()
Definition: SVals.h:238
clang::ento::SValBuilder
Definition: SValBuilder.h:53
clang::ento::DefinedSVal::DefinedSVal
DefinedSVal(const void *d, bool isLoc, unsigned ValKind)
Definition: SVals.h:254
clang::ento::loc::GotoLabel::classof
static bool classof(Loc V)
Definition: SVals.h:503
clang::ento::nonloc::PointerToMember::PTMDataType
llvm::PointerUnion< const NamedDecl *, const PointerToMemberData * > PTMDataType
Definition: SVals.h:447
clang::ento::DefinedSVal::isUnknown
bool isUnknown() const =delete
clang::ento::nonloc::CompoundVal::iterator
llvm::ImmutableList< SVal >::iterator iterator
Definition: SVals.h:390
clang::ento::DefinedSVal::isValid
bool isValid() const =delete
false
#define false
Definition: stdbool.h:22
clang::ento::DefinedOrUnknownSVal::classof
static bool classof(SVal V)
Definition: SVals.h:228
clang::ento::SVal::getAsInteger
const llvm::APSInt * getAsInteger() const
If this SVal is loc::ConcreteInt or nonloc::ConcreteInt, return a pointer to APSInt which is held in ...
Definition: SVals.cpp:112
clang::ento::nonloc::CompoundVal::end
iterator end() const
Definition: SVals.cpp:227
clang::ento::NonLoc::classof
static bool classof(SVal V)
Definition: SVals.h:279
clang::ento::nonloc::PointerToMember::classof
static bool classof(SVal V)
Definition: SVals.h:467
LLVM.h
clang::ento::SVal::BaseMask
@ BaseMask
Definition: SVals.h:81
clang::ento::nonloc::LazyCompoundVal::getRegion
const LLVM_ATTRIBUTE_RETURNS_NONNULL TypedValueRegion * getRegion() const
Definition: SVals.cpp:197
clang::ento::UndefinedVal::classof
static bool classof(SVal V)
Definition: SVals.h:218
clang::ento::SVal::getSubKind
unsigned getSubKind() const
Definition: SVals.h:110
clang::ento::nonloc::PointerToMember::getDeclAs
const AdjustedDecl * getDeclAs() const
Definition: SVals.h:458
clang::ento::nonloc::PointerToMember::end
iterator end() const
Definition: SVals.cpp:238
clang::ento::SVal::getRawKind
unsigned getRawKind() const
Definition: SVals.h:108
clang::ento::nonloc::ConcreteInt::getValue
const llvm::APSInt & getValue() const
Definition: SVals.h:334
clang::ento::loc::ConcreteInt::ConcreteInt
ConcreteInt(const llvm::APSInt &V)
Definition: SVals.h:542
clang::ento::nonloc::ConcreteInt::classof
static bool classof(NonLoc V)
Definition: SVals.h:342
clang::ento::nonloc::LazyCompoundVal::classof
static bool classof(SVal V)
Definition: SVals.h:422
clang::ento::nonloc::LazyCompoundVal::getCVData
const LLVM_ATTRIBUTE_RETURNS_NONNULL LazyCompoundValData * getCVData() const
Definition: SVals.h:412
clang::ento::UnknownVal::classof
static bool classof(SVal V)
Definition: SVals.h:240
clang::ento::nonloc::SymbolVal
Represents symbolic expression that isn't a location.
Definition: SVals.h:305
std
Definition: Format.h:4321
clang::ento::operator<<
raw_ostream & operator<<(raw_ostream &Out, const CheckerBase &Checker)
Dump checker name to stream.
Definition: Checker.cpp:35
clang::ento::SVal::symbol_begin
SymExpr::symbol_iterator symbol_begin() const
Definition: SVals.h:184
clang::Builtin::ID
ID
Definition: Builtins.h:52
clang::ento::nonloc::LazyCompoundVal::classof
static bool classof(NonLoc V)
Definition: SVals.h:427
clang::ento::nonloc::LocAsInteger
Definition: SVals.h:345
clang::ento::KnownSVal::classof
static bool classof(SVal V)
Definition: SVals.h:263
clang
Definition: CalledOnceCheck.h:17
clang::Type::isAnyPointerType
bool isAnyPointerType() const
Definition: Type.h:6940
clang::Type::isArrayType
bool isArrayType() const
Definition: Type.h:7002
clang::ento::nonloc::CompoundVal::begin
iterator begin() const
Definition: SVals.cpp:223
clang::ento::SVal::isUnknownOrUndef
bool isUnknownOrUndef() const
Definition: SVals.h:133
clang::ento::loc::MemRegionVal::operator!=
bool operator!=(const MemRegionVal &R) const
Definition: SVals.h:529
llvm::CastInfo< To, From, std::enable_if_t< std::is_base_of<::clang::ento::SVal, From >::value > >::isPossible
static bool isPossible(const From &V)
Definition: SVals.h:568
clang::ento::nonloc::ConcreteInt::ConcreteInt
ConcreteInt(const llvm::APSInt &V)
Definition: SVals.h:332
clang::ento::loc::MemRegionVal::classof
static bool classof(Loc V)
Definition: SVals.h:537
clang::ento::SVal::isUnknown
bool isUnknown() const
Definition: SVals.h:125
clang::ento::SymExpr::symbol_begin
symbol_iterator symbol_begin() const
Definition: SymExpr.h:86
clang::ento::SVal::operator!=
bool operator!=(SVal R) const
Definition: SVals.h:123
clang::ento::SVal::getBaseKind
BaseKind getBaseKind() const
Definition: SVals.h:109
clang::ento::nonloc::SymbolVal::getSymbol
LLVM_ATTRIBUTE_RETURNS_NONNULL SymbolRef getSymbol() const
Definition: SVals.h:314
clang::ento::loc::MemRegionVal::getRegionAs
const REGION * getRegionAs() const
Definition: SVals.h:521
clang::ento::SVal::BaseBits
@ BaseBits
Definition: SVals.h:81
clang::ento::nonloc::LocAsInteger::classof
static bool classof(SVal V)
Definition: SVals.h:370
clang::ento::DefinedOrUnknownSVal::isUndef
bool isUndef() const =delete
clang::ento::SVal
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
Definition: SVals.h:73
REGION
#define REGION(Id, Parent)
Definition: MemRegion.h:98
clang::ento::loc::MemRegionVal::MemRegionVal
MemRegionVal(const MemRegion *r)
Definition: SVals.h:508
clang::ento::SVal::symbol_end
SymExpr::symbol_iterator symbol_end() const
Definition: SVals.h:192
clang::ento::DefinedOrUnknownSVal::isValid
bool isValid() const =delete
clang::ento::TypedValueRegion
TypedValueRegion - An abstract class representing regions having a typed value.
Definition: MemRegion.h:531
clang::ento::loc::MemRegionVal::operator==
bool operator==(const MemRegionVal &R) const
Definition: SVals.h:525
clang::ento::SVal::SVal
SVal(BaseKind k, const void *D=nullptr)
Definition: SVals.h:93
true
#define true
Definition: stdbool.h:21
clang::ento::DefinedSVal::classof
static bool classof(SVal V)
Definition: SVals.h:251
clang::ento::SVal::getAsSymbol
SymbolRef getAsSymbol(bool IncludeBaseRegions=false) const
If this SVal wraps a symbol return that SymbolRef.
Definition: SVals.cpp:104
CastIsPossible
llvm::CastInfo< To, From, std::enable_if_t< std::is_base_of<::clang::ento::SVal, From >::value > >::doCast
static To doCast(const From &f)
Definition: SVals.h:572
clang::ento::Loc::Loc
Loc(unsigned SubKind, const void *D)
Definition: SVals.h:284
llvm::CastInfo< To, From, std::enable_if_t< std::is_base_of<::clang::ento::SVal, From >::value > >::doCastIfPossible
static Optional< To > doCastIfPossible(const From &f)
Definition: SVals.h:575
clang::ento::nonloc::LocAsInteger::classof
static bool classof(NonLoc V)
Definition: SVals.h:374
clang::ento::KnownSVal::KnownSVal
KnownSVal(const UndefinedVal &V)
Definition: SVals.h:262
clang::ento::nonloc::PointerToMember::classof
static bool classof(NonLoc V)
Definition: SVals.h:472
clang::FunctionDecl
Represents a function declaration or definition.
Definition: Decl.h:1877
clang::ento::loc::MemRegionVal::classof
static bool classof(SVal V)
Definition: SVals.h:533
clang::ento::SymExpr::symbol_end
static symbol_iterator symbol_end()
Definition: SymExpr.h:87
llvm::CastInfo< To, From, std::enable_if_t< std::is_base_of<::clang::ento::SVal, From >::value > >
Definition: SVals.h:561
clang::ento::SVal::getType
QualType getType(const ASTContext &) const
Try to get a reasonable type for the given value.
Definition: SVals.cpp:184
clang::ento::loc::ConcreteInt::getValue
const llvm::APSInt & getValue() const
Definition: SVals.h:544
clang::ento::loc::MemRegionVal::getRegion
const MemRegion * getRegion() const
Get the underlining region.
Definition: SVals.h:513
clang::ento::loc::Kind
Kind
Sub-kinds for Loc values.
Definition: SVals.h:63