1 //===- DynamicType.h - Dynamic type related APIs ----------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
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.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_DYNAMICTYPE_H
16 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_DYNAMICTYPE_H
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"
32 /// Get dynamic type information for the region \p MR.
33 DynamicTypeInfo getDynamicTypeInfo(ProgramStateRef State, const MemRegion *MR);
35 /// Get raw dynamic type information for the region \p MR.
36 const DynamicTypeInfo *getRawDynamicTypeInfo(ProgramStateRef State,
39 /// Get dynamic cast information from \p CastFromTy to \p CastToTy of \p MR.
40 const DynamicCastInfo *getDynamicCastInfo(ProgramStateRef State,
45 /// Set dynamic type information of the region; return the new state.
46 ProgramStateRef setDynamicTypeInfo(ProgramStateRef State, const MemRegion *MR,
47 DynamicTypeInfo NewTy);
49 /// Set dynamic type information of the region; return the new state.
50 ProgramStateRef setDynamicTypeInfo(ProgramStateRef State, const MemRegion *MR,
51 QualType NewTy, bool CanBeSubClassed = true);
53 /// Set dynamic type and cast information of the region; return the new state.
54 ProgramStateRef setDynamicTypeAndCastInfo(ProgramStateRef State,
60 /// Removes the dead type informations from \p State.
61 ProgramStateRef removeDeadTypes(ProgramStateRef State, SymbolReaper &SR);
63 /// Removes the dead cast informations from \p State.
64 ProgramStateRef removeDeadCasts(ProgramStateRef State, SymbolReaper &SR);
66 void printDynamicTypeInfoJson(raw_ostream &Out, ProgramStateRef State,
67 const char *NL = "\n", unsigned int Space = 0,
73 #endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_DYNAMICTYPE_H