clang  14.0.0git
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();
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 }
clang::ento::Loc::isLocType
static bool isLocType(QualType T)
Definition: SVals.h:336
ConstraintManager.h
SVals.h
getLocFromSymbol
static DefinedSVal getLocFromSymbol(const ProgramStateRef &State, SymbolRef Sym)
Definition: ConstraintManager.cpp:25
clang::ento::ConstraintManager::ProgramStatePair
std::pair< ProgramStateRef, ProgramStateRef > ProgramStatePair
Definition: ConstraintManager.h:89
clang::ento::ProgramStateRef
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
Definition: ProgramState_Fwd.h:37
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:673
ProgramState_Fwd.h
clang::ento::SymbolRef
const SymExpr * SymbolRef
Definition: SymExpr.h:110
clang::ento::ConditionTruthVal
Definition: ConstraintManager.h:38
V
#define V(N, I)
Definition: ASTContext.h:3121
clang::ento::DefinedSVal
Definition: SVals.h:269
clang::ento::SymExpr::getType
virtual QualType getType() const =0
clang::ento::SymExpr
Symbolic value.
Definition: SymExpr.h:29
clang::ento::ConstraintManager::~ConstraintManager
virtual ~ConstraintManager()
Type.h
P
StringRef P
Definition: ASTMatchersInternal.cpp:563
State
LineState State
Definition: UnwrappedLineFormatter.cpp:986
ProgramState.h
clang::ento::nonloc::SymbolVal
Represents symbolic expression that isn't a location.
Definition: SVals.h:356
clang::ento::ConstraintManager::assumeDual
ProgramStatePair assumeDual(ProgramStateRef State, DefinedSVal Cond)
Returns a pair of states (StTrue, StFalse) where the given condition is assumed to be true or false,...
Definition: ConstraintManager.h:93
clang
Definition: CalledOnceCheck.h:17
clang::ento::ConstraintManager::checkNull
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"),...
Definition: ConstraintManager.cpp:32
MemRegion.h
llvm::IntrusiveRefCntPtr< const ProgramState >