Coverage Report

Created: 2020-02-25 14:32

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/AST/GlobalDecl.h
Line
Count
Source (jump to first uncovered line)
1
//===- GlobalDecl.h - Global declaration holder -----------------*- 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
// A GlobalDecl can hold either a regular variable/function or a C++ ctor/dtor
10
// together with its type.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CLANG_AST_GLOBALDECL_H
15
#define LLVM_CLANG_AST_GLOBALDECL_H
16
17
#include "clang/AST/DeclCXX.h"
18
#include "clang/AST/DeclObjC.h"
19
#include "clang/AST/DeclOpenMP.h"
20
#include "clang/Basic/ABI.h"
21
#include "clang/Basic/LLVM.h"
22
#include "llvm/ADT/DenseMapInfo.h"
23
#include "llvm/ADT/PointerIntPair.h"
24
#include "llvm/Support/Casting.h"
25
#include "llvm/Support/type_traits.h"
26
#include <cassert>
27
28
namespace clang {
29
30
enum class DynamicInitKind : unsigned {
31
  NoStub = 0,
32
  Initializer,
33
  AtExit,
34
};
35
36
/// GlobalDecl - represents a global declaration. This can either be a
37
/// CXXConstructorDecl and the constructor type (Base, Complete).
38
/// a CXXDestructorDecl and the destructor type (Base, Complete) or
39
/// a VarDecl, a FunctionDecl or a BlockDecl.
40
class GlobalDecl {
41
  llvm::PointerIntPair<const Decl *, 2> Value;
42
  unsigned MultiVersionIndex = 0;
43
44
8.16M
  void Init(const Decl *D) {
45
8.16M
    assert(!isa<CXXConstructorDecl>(D) && "Use other ctor with ctor decls!");
46
8.16M
    assert(!isa<CXXDestructorDecl>(D) && "Use other ctor with dtor decls!");
47
8.16M
48
8.16M
    Value.setPointer(D);
49
8.16M
  }
50
51
public:
52
26.5M
  GlobalDecl() = default;
53
1.89M
  GlobalDecl(const VarDecl *D) { Init(D);}
54
  GlobalDecl(const FunctionDecl *D, unsigned MVIndex = 0)
55
6.18M
      : MultiVersionIndex(MVIndex) {
56
6.18M
    Init(D);
57
6.18M
  }
58
4.20k
  GlobalDecl(const BlockDecl *D) { Init(D); }
59
47.0k
  GlobalDecl(const CapturedDecl *D) { Init(D); }
60
25.6k
  GlobalDecl(const ObjCMethodDecl *D) { Init(D); }
61
8
  GlobalDecl(const OMPDeclareReductionDecl *D) { Init(D); }
62
0
  GlobalDecl(const OMPDeclareMapperDecl *D) { Init(D); }
63
284k
  GlobalDecl(const CXXConstructorDecl *D, CXXCtorType Type) : Value(D, Type) {}
64
57.4k
  GlobalDecl(const CXXDestructorDecl *D, CXXDtorType Type) : Value(D, Type) {}
65
  GlobalDecl(const VarDecl *D, DynamicInitKind StubKind)
66
4.36k
      : Value(D, unsigned(StubKind)) {}
67
68
3.67M
  GlobalDecl getCanonicalDecl() const {
69
3.67M
    GlobalDecl CanonGD;
70
3.67M
    CanonGD.Value.setPointer(Value.getPointer()->getCanonicalDecl());
71
3.67M
    CanonGD.Value.setInt(Value.getInt());
72
3.67M
    CanonGD.MultiVersionIndex = MultiVersionIndex;
73
3.67M
74
3.67M
    return CanonGD;
75
3.67M
  }
76
77
28.0M
  const Decl *getDecl() const { return Value.getPointer(); }
78
79
339k
  CXXCtorType getCtorType() const {
80
339k
    assert(isa<CXXConstructorDecl>(getDecl()) && "Decl is not a ctor!");
81
339k
    return static_cast<CXXCtorType>(Value.getInt());
82
339k
  }
83
84
237k
  CXXDtorType getDtorType() const {
85
237k
    assert(isa<CXXDestructorDecl>(getDecl()) && "Decl is not a dtor!");
86
237k
    return static_cast<CXXDtorType>(Value.getInt());
87
237k
  }
88
89
831
  DynamicInitKind getDynamicInitKind() const {
90
831
    assert(isa<VarDecl>(getDecl()) &&
91
831
           cast<VarDecl>(getDecl())->hasGlobalStorage() &&
92
831
           "Decl is not a global variable!");
93
831
    return static_cast<DynamicInitKind>(Value.getInt());
94
831
  }
95
96
84
  unsigned getMultiVersionIndex() const {
97
84
    assert(isa<FunctionDecl>(getDecl()) &&
98
84
           !isa<CXXConstructorDecl>(getDecl()) &&
99
84
           !isa<CXXDestructorDecl>(getDecl()) &&
100
84
           "Decl is not a plain FunctionDecl!");
101
84
    return MultiVersionIndex;
102
84
  }
103
104
78.7M
  friend bool operator==(const GlobalDecl &LHS, const GlobalDecl &RHS) {
105
78.7M
    return LHS.Value == RHS.Value &&
106
78.7M
           
LHS.MultiVersionIndex == RHS.MultiVersionIndex16.6M
;
107
78.7M
  }
108
109
9.10M
  void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
110
111
9.17M
  static GlobalDecl getFromOpaquePtr(void *P) {
112
9.17M
    GlobalDecl GD;
113
9.17M
    GD.Value.setFromOpaqueValue(P);
114
9.17M
    return GD;
115
9.17M
  }
116
117
43.0k
  GlobalDecl getWithDecl(const Decl *D) {
118
43.0k
    GlobalDecl Result(*this);
119
43.0k
    Result.Value.setPointer(D);
120
43.0k
    return Result;
121
43.0k
  }
122
123
15.6k
  GlobalDecl getWithCtorType(CXXCtorType Type) {
124
15.6k
    assert(isa<CXXConstructorDecl>(getDecl()));
125
15.6k
    GlobalDecl Result(*this);
126
15.6k
    Result.Value.setInt(Type);
127
15.6k
    return Result;
128
15.6k
  }
129
130
6.22k
  GlobalDecl getWithDtorType(CXXDtorType Type) {
131
6.22k
    assert(isa<CXXDestructorDecl>(getDecl()));
132
6.22k
    GlobalDecl Result(*this);
133
6.22k
    Result.Value.setInt(Type);
134
6.22k
    return Result;
135
6.22k
  }
136
137
70
  GlobalDecl getWithMultiVersionIndex(unsigned Index) {
138
70
    assert(isa<FunctionDecl>(getDecl()) &&
139
70
           !isa<CXXConstructorDecl>(getDecl()) &&
140
70
           !isa<CXXDestructorDecl>(getDecl()) &&
141
70
           "Decl is not a plain FunctionDecl!");
142
70
    GlobalDecl Result(*this);
143
70
    Result.MultiVersionIndex = Index;
144
70
    return Result;
145
70
  }
146
};
147
148
} // namespace clang
149
150
namespace llvm {
151
152
  template<> struct DenseMapInfo<clang::GlobalDecl> {
153
11.5M
    static inline clang::GlobalDecl getEmptyKey() {
154
11.5M
      return clang::GlobalDecl();
155
11.5M
    }
156
157
9.17M
    static inline clang::GlobalDecl getTombstoneKey() {
158
9.17M
      return clang::GlobalDecl::
159
9.17M
        getFromOpaquePtr(reinterpret_cast<void*>(-1));
160
9.17M
    }
161
162
9.10M
    static unsigned getHashValue(clang::GlobalDecl GD) {
163
9.10M
      return DenseMapInfo<void*>::getHashValue(GD.getAsOpaquePtr());
164
9.10M
    }
165
166
    static bool isEqual(clang::GlobalDecl LHS,
167
78.7M
                        clang::GlobalDecl RHS) {
168
78.7M
      return LHS == RHS;
169
78.7M
    }
170
  };
171
172
} // namespace llvm
173
174
#endif // LLVM_CLANG_AST_GLOBALDECL_H