1 //==- DynamicTypeMap.cpp - Dynamic Type Info related APIs ----------*- C++ -*-//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines APIs that track and query dynamic type information. This
11 // information can be used to devirtualize calls during the symbolic exection
12 // or do type checking.
14 //===----------------------------------------------------------------------===//
16 #include "clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h"
21 DynamicTypeInfo getDynamicTypeInfo(ProgramStateRef State,
22 const MemRegion *Reg) {
23 Reg = Reg->StripCasts();
25 // Look up the dynamic type in the GDM.
26 const DynamicTypeInfo *GDMType = State->get<DynamicTypeMap>(Reg);
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);
34 if (const SymbolicRegion *SR = dyn_cast<SymbolicRegion>(Reg)) {
35 SymbolRef Sym = SR->getSymbol();
36 return DynamicTypeInfo(Sym->getType());
39 return DynamicTypeInfo();
42 ProgramStateRef setDynamicTypeInfo(ProgramStateRef State, const MemRegion *Reg,
43 DynamicTypeInfo NewTy) {
44 Reg = Reg->StripCasts();
45 ProgramStateRef NewState = State->set<DynamicTypeMap>(Reg, NewTy);