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