1//===- DynamicType.h - Dynamic type related APIs ----------------*- 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 APIs that track and query dynamic type information. This 10// information can be used to devirtualize calls during the symbolic execution 11// or do type checking. 12// 13//===----------------------------------------------------------------------===// 14 15#ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_DYNAMICTYPE_H 16#define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_DYNAMICTYPE_H 17 18#include "clang/AST/Type.h" 19#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicCastInfo.h" 20#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeInfo.h" 21#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h" 22#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h" 23#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h" 24#include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h" 25#include "llvm/ADT/ImmutableMap.h" 26#include "llvm/ADT/Optional.h" 27#include <utility> 28 29namespace clang { 30namespace ento { 31 32/// Get dynamic type information for the region \p MR. 33DynamicTypeInfo getDynamicTypeInfo(ProgramStateRef State, const MemRegion *MR); 34 35/// Get raw dynamic type information for the region \p MR. 36const DynamicTypeInfo *getRawDynamicTypeInfo(ProgramStateRef State, 37 const MemRegion *MR); 38 39/// Get dynamic cast information from \p CastFromTy to \p CastToTy of \p MR. 40const DynamicCastInfo *getDynamicCastInfo(ProgramStateRef State, 41 const MemRegion *MR, 42 QualType CastFromTy, 43 QualType CastToTy); 44 45/// Set dynamic type information of the region; return the new state. 46ProgramStateRef setDynamicTypeInfo(ProgramStateRef State, const MemRegion *MR, 47 DynamicTypeInfo NewTy); 48 49/// Set dynamic type information of the region; return the new state. 50ProgramStateRef setDynamicTypeInfo(ProgramStateRef State, const MemRegion *MR, 51 QualType NewTy, bool CanBeSubClassed = true); 52 53/// Set dynamic type and cast information of the region; return the new state. 54ProgramStateRef setDynamicTypeAndCastInfo(ProgramStateRef State, 55 const MemRegion *MR, 56 QualType CastFromTy, 57 QualType CastToTy, 58 bool IsCastSucceeds); 59 60/// Removes the dead type informations from \p State. 61ProgramStateRef removeDeadTypes(ProgramStateRef State, SymbolReaper &SR); 62 63/// Removes the dead cast informations from \p State. 64ProgramStateRef removeDeadCasts(ProgramStateRef State, SymbolReaper &SR); 65 66void printDynamicTypeInfoJson(raw_ostream &Out, ProgramStateRef State, 67 const char *NL = "\n", unsigned int Space = 0, 68 bool IsDot = false); 69 70} // namespace ento 71} // namespace clang 72 73#endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_DYNAMICTYPE_H 74