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