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 26 namespace clang { 27 namespace ento { 28 29 /// Get dynamic type information for the region \p MR. 30 DynamicTypeInfo getDynamicTypeInfo(ProgramStateRef State, const MemRegion *MR); 31 32 /// Get raw dynamic type information for the region \p MR. 33 /// It might return null. 34 const DynamicTypeInfo *getRawDynamicTypeInfo(ProgramStateRef State, 35 const MemRegion *MR); 36 37 /// Get dynamic type information stored in a class object represented by \p Sym. 38 DynamicTypeInfo getClassObjectDynamicTypeInfo(ProgramStateRef State, 39 SymbolRef Sym); 40 41 /// Get dynamic cast information from \p CastFromTy to \p CastToTy of \p MR. 42 const DynamicCastInfo *getDynamicCastInfo(ProgramStateRef State, 43 const MemRegion *MR, 44 QualType CastFromTy, 45 QualType CastToTy); 46 47 /// Set dynamic type information of the region; return the new state. 48 ProgramStateRef setDynamicTypeInfo(ProgramStateRef State, const MemRegion *MR, 49 DynamicTypeInfo NewTy); 50 51 /// Set dynamic type information of the region; return the new state. 52 ProgramStateRef setDynamicTypeInfo(ProgramStateRef State, const MemRegion *MR, 53 QualType NewTy, bool CanBeSubClassed = true); 54 55 /// Set constraint on a type contained in a class object; return the new state. 56 ProgramStateRef setClassObjectDynamicTypeInfo(ProgramStateRef State, 57 SymbolRef Sym, 58 DynamicTypeInfo NewTy); 59 60 /// Set constraint on a type contained in a class object; return the new state. 61 ProgramStateRef setClassObjectDynamicTypeInfo(ProgramStateRef State, 62 SymbolRef Sym, QualType NewTy, 63 bool CanBeSubClassed = true); 64 65 /// Set dynamic type and cast information of the region; return the new state. 66 ProgramStateRef setDynamicTypeAndCastInfo(ProgramStateRef State, 67 const MemRegion *MR, 68 QualType CastFromTy, 69 QualType CastToTy, 70 bool IsCastSucceeds); 71 72 /// Removes the dead type informations from \p State. 73 ProgramStateRef removeDeadTypes(ProgramStateRef State, SymbolReaper &SR); 74 75 /// Removes the dead cast informations from \p State. 76 ProgramStateRef removeDeadCasts(ProgramStateRef State, SymbolReaper &SR); 77 78 /// Removes the dead Class object type informations from \p State. 79 ProgramStateRef removeDeadClassObjectTypes(ProgramStateRef State, 80 SymbolReaper &SR); 81 82 void printDynamicTypeInfoJson(raw_ostream &Out, ProgramStateRef State, 83 const char *NL = "\n", unsigned int Space = 0, 84 bool IsDot = false); 85 86 } // namespace ento 87 } // namespace clang 88 89 #endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_DYNAMICTYPE_H 90