clang 23.0.0git
UnsafeBufferUsage.h
Go to the documentation of this file.
1//===- UnsafeBufferUsage.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_SCALABLESTATICANALYSISFRAMEWORK_ANALYSES_UNSAFEBUFFERUSAGE_UNSAFEBUFFERUSAGE_H
10#define LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_ANALYSES_UNSAFEBUFFERUSAGE_UNSAFEBUFFERUSAGE_H
11
15#include <set>
16
17namespace clang::ssaf {
18
19/// An EntityPointerLevel represents a level of the declared pointer/array
20/// type of an entity. In the fully-expanded spelling of the declared type, a
21/// EntityPointerLevel is associated with a '*' (or a '[]`) in that declaration.
22///
23/// For example, for 'int *p[10];', there are two EntityPointerLevels. One
24/// is associated with 'int *[10]' of 'p' and the other is associated with 'int
25/// *' of 'p'.
26///
27/// An EntityPointerLevel can be identified by an EntityId and an unsigned
28/// integer indicating the pointer level: '(EntityId, PointerLevel)'.
29/// An EntityPointerLevel 'P' is valid iff 'P.EntityId' has a pointer type with
30/// at least 'P.PointerLevel' levels (This implies 'P.PointerLevel > 0').
31///
32/// For the same example 'int *p[10];', the EntityPointerLevels below are valid:
33/// - '(p, 2)' is associated with the 'int *' part of the declared type of 'p';
34/// - '(p, 1)' is associated with the 'int *[10]' part of the declared type of
35/// 'p'.
36class EntityPointerLevel {
37 EntityId Entity;
38 unsigned PointerLevel;
39
41
42 EntityPointerLevel(EntityId Entity, unsigned PointerLevel)
43 : Entity(Entity), PointerLevel(PointerLevel) {}
44
45public:
46 EntityId getEntity() const { return Entity; }
47 unsigned getPointerLevel() const { return PointerLevel; }
48
49 bool operator==(const EntityPointerLevel &Other) const {
50 return std::tie(Entity, PointerLevel) ==
51 std::tie(Other.Entity, Other.PointerLevel);
52 }
53
54 bool operator!=(const EntityPointerLevel &Other) const {
55 return !(*this == Other);
56 }
57
58 bool operator<(const EntityPointerLevel &Other) const {
59 return std::tie(Entity, PointerLevel) <
60 std::tie(Other.Entity, Other.PointerLevel);
61 }
62
63 /// Compares `EntityPointerLevel`s; additionally, partially compares
64 /// `EntityPointerLevel` with `EntityId`.
65 struct Comparator {
66 using is_transparent = void;
67 bool operator()(const EntityPointerLevel &L,
68 const EntityPointerLevel &R) const {
69 return L < R;
70 }
71 bool operator()(const EntityId &L, const EntityPointerLevel &R) const {
72 return L < R.getEntity();
73 }
74 bool operator()(const EntityPointerLevel &L, const EntityId &R) const {
75 return L.getEntity() < R;
76 }
77 };
78};
79
81 std::set<EntityPointerLevel, EntityPointerLevel::Comparator>;
82
83/// An UnsafeBufferUsageEntitySummary is an immutable set of unsafe buffers, in
84/// the form of EntityPointerLevel.
85class UnsafeBufferUsageEntitySummary final : public EntitySummary {
86 const EntityPointerLevelSet UnsafeBuffers;
87
89
90 UnsafeBufferUsageEntitySummary(EntityPointerLevelSet UnsafeBuffers)
91 : EntitySummary(), UnsafeBuffers(std::move(UnsafeBuffers)) {}
92
93public:
94 SummaryName getSummaryName() const override {
95 return SummaryName{"UnsafeBufferUsage"};
96 };
97
98 bool operator==(const EntityPointerLevelSet &Other) const {
99 return UnsafeBuffers == Other;
100 }
101};
102} // namespace clang::ssaf
103
104#endif // LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_ANALYSES_UNSAFEBUFFERUSAGE_UNSAFEBUFFERUSAGE_H
std::set< EntityPointerLevel, EntityPointerLevel::Comparator > EntityPointerLevelSet
SummaryName getSummaryName() const override
bool operator==(const EntityPointerLevelSet &Other) const
Lightweight opaque handle representing an entity in an EntityIdTable.
Definition EntityId.h:31
bool operator==(const CallGraphNode::CallRecord &LHS, const CallGraphNode::CallRecord &RHS)
Definition CallGraph.h:206
bool operator<(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
bool operator!=(CanQual< T > x, CanQual< U > y)
@ Other
Other implicit parameter.
Definition Decl.h:1746
An EntityPointerLevel represents a level of the declared pointer/array type of an entity.
bool operator()(const EntityPointerLevel &L, const EntityPointerLevel &R) const
bool operator()(const EntityPointerLevel &L, const EntityId &R) const
bool operator()(const EntityId &L, const EntityPointerLevel &R) const