clang 24.0.0git
VirtualMethodFamily.h
Go to the documentation of this file.
1//===- VirtualMethodFamily.h ------------------------------------*- 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#ifndef LLVM_CLANG_SCALABLESTATICANALYSIS_ANALYSES_VIRTUALMETHODFAMILY_VIRTUALMETHODFAMILY_H
10#define LLVM_CLANG_SCALABLESTATICANALYSIS_ANALYSES_VIRTUALMETHODFAMILY_VIRTUALMETHODFAMILY_H
11
17#include "llvm/ADT/DenseMap.h"
18#include "llvm/ADT/StringRef.h"
19#include "llvm/Support/raw_ostream.h"
20#include <optional>
21#include <tuple>
22#include <vector>
23
24namespace clang::ssaf {
25
26struct VirtualMethodSummary final : public EntitySummary {
27 static constexpr llvm::StringLiteral Name = "VirtualMethod";
28
29 static SummaryName summaryName() { return SummaryName(Name.str()); }
30
31 SummaryName getSummaryName() const override { return summaryName(); }
32
33 /// EntityIds of each ParmVarDecl, in source order.
34 std::vector<EntityId> ParamEntities;
35
36 /// EntityId of the synthetic return-slot entity for this method.
37 std::optional<EntityId> ReturnEntity;
38
39 /// The result of \c CXXMethodDecl::overridden_methods().
40 std::vector<EntityId> OverriddenMethods;
41
43 return std::tie(ParamEntities, ReturnEntity, OverriddenMethods) ==
44 std::tie(Other.ParamEntities, Other.ReturnEntity,
45 Other.OverriddenMethods);
46 }
47
49 return !(*this == Other);
50 }
51};
52
53/// Prints \p S as
54/// "VirtualMethodSummary { params=[...], return=..., overridden=[...] }".
55llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
56 const VirtualMethodSummary &S);
57
60 return AnalysisName("VirtualMethodFamilyAnalysisResult");
61 }
62
63 /// Maps each parameter or return slot to the ID of the family it belongs to.
64 /// The family ID is the smallest slot ID in the family.
65 llvm::DenseMap<EntityId, EntityId> RetAndParamData;
66
68 return RetAndParamData == Other.RetAndParamData;
69 }
70
72 return !(*this == Other);
73 }
74};
75
76/// Prints \p R as one "<param/return id> -> <family id>" line per entry,
77/// ordered by the param/return id so that the output is stable across runs.
78llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
79 const VirtualMethodFamilyAnalysisResult &R);
80
81} // namespace clang::ssaf
82
83#endif // LLVM_CLANG_SCALABLESTATICANALYSIS_ANALYSES_VIRTUALMETHODFAMILY_VIRTUALMETHODFAMILY_H
Uniquely identifies a whole-program analysis and the AnalysisResult it produces.
Base class for whole-program analysis results.
Base class for analysis-specific summary data.
Uniquely identifies an analysis summary.
Definition SummaryName.h:22
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const VirtualMethodSummary &S)
Prints S as "VirtualMethodSummary { params=[...], return=..., overridden=[...] }".
@ Other
Other implicit parameter.
Definition Decl.h:1775
bool operator!=(const VirtualMethodFamilyAnalysisResult &Other) const
bool operator==(const VirtualMethodFamilyAnalysisResult &Other) const
llvm::DenseMap< EntityId, EntityId > RetAndParamData
Maps each parameter or return slot to the ID of the family it belongs to.
static constexpr llvm::StringLiteral Name
bool operator!=(const VirtualMethodSummary &Other) const
bool operator==(const VirtualMethodSummary &Other) const
std::vector< EntityId > ParamEntities
EntityIds of each ParmVarDecl, in source order.
SummaryName getSummaryName() const override
std::optional< EntityId > ReturnEntity
EntityId of the synthetic return-slot entity for this method.
std::vector< EntityId > OverriddenMethods
The result of CXXMethodDecl::overridden_methods().