clang  6.0.0svn
DynamicTypeMap.cpp
Go to the documentation of this file.
1 //==- DynamicTypeMap.cpp - Dynamic Type Info related APIs ----------*- C++ -*-//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines APIs that track and query dynamic type information. This
11 // information can be used to devirtualize calls during the symbolic execution
12 // or do type checking.
13 //
14 //===----------------------------------------------------------------------===//
15 
17 
18 namespace clang {
19 namespace ento {
20 
22  const MemRegion *Reg) {
23  Reg = Reg->StripCasts();
24 
25  // Look up the dynamic type in the GDM.
26  const DynamicTypeInfo *GDMType = State->get<DynamicTypeMap>(Reg);
27  if (GDMType)
28  return *GDMType;
29 
30  // Otherwise, fall back to what we know about the region.
31  if (const TypedRegion *TR = dyn_cast<TypedRegion>(Reg))
32  return DynamicTypeInfo(TR->getLocationType(), /*CanBeSubclass=*/false);
33 
34  if (const SymbolicRegion *SR = dyn_cast<SymbolicRegion>(Reg)) {
35  SymbolRef Sym = SR->getSymbol();
36  return DynamicTypeInfo(Sym->getType());
37  }
38 
39  return DynamicTypeInfo();
40 }
41 
43  DynamicTypeInfo NewTy) {
44  Reg = Reg->StripCasts();
45  ProgramStateRef NewState = State->set<DynamicTypeMap>(Reg, NewTy);
46  assert(NewState);
47  return NewState;
48 }
49 
50 } // namespace ento
51 } // namespace clang
MemRegion - The root abstract class for all memory regions.
Definition: MemRegion.h:79
Symbolic value.
Definition: SymExpr.h:29
The GDM component containing the dynamic type info.
LineState State
virtual QualType getType() const =0
SymbolicRegion - A special, "non-concrete" region.
Definition: MemRegion.h:742
Stores the currently inferred strictest bound on the runtime type of a region in a given state along ...
ProgramStateRef setDynamicTypeInfo(ProgramStateRef State, const MemRegion *Reg, DynamicTypeInfo NewTy)
Set dynamic type information of the region; return the new state.
const MemRegion * StripCasts(bool StripBaseCasts=true) const
Definition: MemRegion.cpp:1117
Dataflow Directional Tag Classes.
DynamicTypeInfo getDynamicTypeInfo(ProgramStateRef State, const MemRegion *Reg)
Get dynamic type information for a region.
TypedRegion - An abstract class representing regions that are typed.
Definition: MemRegion.h:487