clang  9.0.0svn
ConstraintManager.cpp
Go to the documentation of this file.
1 //===- ConstraintManager.cpp - Constraints on symbolic values. ------------===//
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 defined the interface to manage constraints on symbolic values.
10 //
11 //===----------------------------------------------------------------------===//
12 
14 #include "clang/AST/Type.h"
19 
20 using namespace clang;
21 using namespace ento;
22 
24 
25 static DefinedSVal getLocFromSymbol(const ProgramStateRef &State,
26  SymbolRef Sym) {
27  const MemRegion *R =
28  State->getStateManager().getRegionManager().getSymbolicRegion(Sym);
29  return loc::MemRegionVal(R);
30 }
31 
33  SymbolRef Sym) {
34  QualType Ty = Sym->getType();
35  DefinedSVal V = Loc::isLocType(Ty) ? getLocFromSymbol(State, Sym)
36  : nonloc::SymbolVal(Sym);
37  const ProgramStatePair &P = assumeDual(State, V);
38  if (P.first && !P.second)
39  return ConditionTruthVal(false);
40  if (!P.first && P.second)
41  return ConditionTruthVal(true);
42  return {};
43 }
A (possibly-)qualified type.
Definition: Type.h:639
const SymExpr * SymbolRef
C Language Family Type Representation.
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
StringRef P
virtual ConditionTruthVal checkNull(ProgramStateRef State, SymbolRef Sym)
Returns whether or not a symbol is known to be null ("true"), known to be non-null ("false")...
Symbolic value.
Definition: SymExpr.h:29
LineState State
static bool isLocType(QualType T)
Definition: SVals.h:326
virtual QualType getType() const =0
ProgramStatePair assumeDual(ProgramStateRef State, DefinedSVal Cond)
Returns a pair of states (StTrue, StFalse) where the given condition is assumed to be true or false...
#define V(N, I)
Definition: ASTContext.h:2906
static DefinedSVal getLocFromSymbol(const ProgramStateRef &State, SymbolRef Sym)
Dataflow Directional Tag Classes.
Represents symbolic expression that isn&#39;t a location.
Definition: SVals.h:346
std::pair< ProgramStateRef, ProgramStateRef > ProgramStatePair