Coverage Report

Created: 2021-01-23 06:44

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/AST/DependenceFlags.h
Line
Count
Source (jump to first uncovered line)
1
//===--- DependenceFlags.h ------------------------------------------------===//
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
#ifndef LLVM_CLANG_AST_DEPENDENCEFLAGS_H
9
#define LLVM_CLANG_AST_DEPENDENCEFLAGS_H
10
11
#include "clang/Basic/BitmaskEnum.h"
12
#include "llvm/ADT/BitmaskEnum.h"
13
#include <cstdint>
14
15
namespace clang {
16
struct ExprDependenceScope {
17
  enum ExprDependence : uint8_t {
18
    UnexpandedPack = 1,
19
    // This expr depends in any way on
20
    //   - a template parameter, it implies that the resolution of this expr may
21
    //     cause instantiation to fail
22
    //   - or an error (often in a non-template context)
23
    //
24
    // Note that C++ standard doesn't define the instantiation-dependent term,
25
    // we follow the formal definition coming from the Itanium C++ ABI, and
26
    // extend it to errors.
27
    Instantiation = 2,
28
    // The type of this expr depends on a template parameter, or an error.
29
    Type = 4,
30
    // The value of this expr depends on a template parameter, or an error.
31
    Value = 8,
32
33
    // clang extension: this expr contains or references an error, and is
34
    // considered dependent on how that error is resolved.
35
    Error = 16,
36
37
    None = 0,
38
    All = 31,
39
40
    TypeValue = Type | Value,
41
    TypeInstantiation = Type | Instantiation,
42
    ValueInstantiation = Value | Instantiation,
43
    TypeValueInstantiation = Type | Value | Instantiation,
44
    ErrorDependent = Error | ValueInstantiation,
45
46
    LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/Error)
47
  };
48
};
49
using ExprDependence = ExprDependenceScope::ExprDependence;
50
51
struct TypeDependenceScope {
52
  enum TypeDependence : uint8_t {
53
    /// Whether this type contains an unexpanded parameter pack
54
    /// (for C++11 variadic templates)
55
    UnexpandedPack = 1,
56
    /// Whether this type somehow involves
57
    ///   - a template parameter, even if the resolution of the type does not
58
    ///     depend on a template parameter.
59
    ///   - or an error.
60
    Instantiation = 2,
61
    /// Whether this type
62
    ///   - is a dependent type (C++ [temp.dep.type])
63
    ///   - or it somehow involves an error, e.g. decltype(recovery-expr)
64
    Dependent = 4,
65
    /// Whether this type is a variably-modified type (C99 6.7.5).
66
    VariablyModified = 8,
67
68
    /// Whether this type references an error, e.g. decltype(err-expression)
69
    /// yields an error type.
70
    Error = 16,
71
72
    None = 0,
73
    All = 31,
74
75
    DependentInstantiation = Dependent | Instantiation,
76
77
    LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/Error)
78
  };
79
};
80
using TypeDependence = TypeDependenceScope::TypeDependence;
81
82
#define LLVM_COMMON_DEPENDENCE(NAME)                                           \
83
  struct NAME##Scope {                                                         \
84
    enum NAME : uint8_t {                                                      \
85
      UnexpandedPack = 1,                                                      \
86
      Instantiation = 2,                                                       \
87
      Dependent = 4,                                                           \
88
      Error = 8,                                                               \
89
                                                                               \
90
      None = 0,                                                                \
91
      DependentInstantiation = Dependent | Instantiation,                      \
92
      All = 15,                                                                \
93
                                                                               \
94
      LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/Error)                        \
95
    };                                                                         \
96
  };                                                                           \
97
  using NAME = NAME##Scope::NAME;
98
99
LLVM_COMMON_DEPENDENCE(NestedNameSpecifierDependence)
100
LLVM_COMMON_DEPENDENCE(TemplateNameDependence)
101
LLVM_COMMON_DEPENDENCE(TemplateArgumentDependence)
102
#undef LLVM_COMMON_DEPENDENCE
103
104
// A combined space of all dependence concepts for all node types.
105
// Used when aggregating dependence of nodes of different types.
106
class Dependence {
107
public:
108
  enum Bits : uint8_t {
109
    None = 0,
110
111
    // Contains a template parameter pack that wasn't expanded.
112
    UnexpandedPack = 1,
113
    // Depends on a template parameter or an error in some way.
114
    // Validity depends on how the template is instantiated or the error is
115
    // resolved.
116
    Instantiation = 2,
117
    // Expression type depends on template context, or an error.
118
    // Value and Instantiation should also be set.
119
    Type = 4,
120
    // Expression value depends on template context, or an error.
121
    // Instantiation should also be set.
122
    Value = 8,
123
    // Depends on template context, or an error.
124
    // The type/value distinction is only meaningful for expressions.
125
    Dependent = Type | Value,
126
    // Includes an error, and depends on how it is resolved.
127
    Error = 16,
128
    // Type depends on a runtime value (variable-length array).
129
    VariablyModified = 32,
130
131
    LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/VariablyModified)
132
  };
133
134
0
  Dependence() : V(None) {}
135
136
  Dependence(TypeDependence D)
137
      : V(translate(D, TypeDependence::UnexpandedPack, UnexpandedPack) |
138
          translate(D, TypeDependence::Instantiation, Instantiation) |
139
          translate(D, TypeDependence::Dependent, Dependent) |
140
          translate(D, TypeDependence::Error, Error) |
141
98.6M
          translate(D, TypeDependence::VariablyModified, VariablyModified)) {}
142
143
  Dependence(ExprDependence D)
144
      : V(translate(D, ExprDependence::UnexpandedPack, UnexpandedPack) |
145
             translate(D, ExprDependence::Instantiation, Instantiation) |
146
             translate(D, ExprDependence::Type, Type) |
147
             translate(D, ExprDependence::Value, Value) |
148
4.98M
             translate(D, ExprDependence::Error, Error)) {}
149
150
  Dependence(NestedNameSpecifierDependence D) :
151
    V ( translate(D, NNSDependence::UnexpandedPack, UnexpandedPack) |
152
            translate(D, NNSDependence::Instantiation, Instantiation) |
153
            translate(D, NNSDependence::Dependent, Dependent) |
154
7.17M
            translate(D, NNSDependence::Error, Error)) {}
155
156
  Dependence(TemplateArgumentDependence D)
157
      : V(translate(D, TADependence::UnexpandedPack, UnexpandedPack) |
158
          translate(D, TADependence::Instantiation, Instantiation) |
159
          translate(D, TADependence::Dependent, Dependent) |
160
17.5M
          translate(D, TADependence::Error, Error)) {}
161
162
  Dependence(TemplateNameDependence D)
163
      : V(translate(D, TNDependence::UnexpandedPack, UnexpandedPack) |
164
             translate(D, TNDependence::Instantiation, Instantiation) |
165
             translate(D, TNDependence::Dependent, Dependent) |
166
10.1M
             translate(D, TNDependence::Error, Error)) {}
167
168
30.1M
  TypeDependence type() const {
169
30.1M
    return translate(V, UnexpandedPack, TypeDependence::UnexpandedPack) |
170
30.1M
           translate(V, Instantiation, TypeDependence::Instantiation) |
171
30.1M
           translate(V, Dependent, TypeDependence::Dependent) |
172
30.1M
           translate(V, Error, TypeDependence::Error) |
173
30.1M
           translate(V, VariablyModified, TypeDependence::VariablyModified);
174
30.1M
  }
175
176
57.0M
  ExprDependence expr() const {
177
57.0M
    return translate(V, UnexpandedPack, ExprDependence::UnexpandedPack) |
178
57.0M
           translate(V, Instantiation, ExprDependence::Instantiation) |
179
57.0M
           translate(V, Type, ExprDependence::Type) |
180
57.0M
           translate(V, Value, ExprDependence::Value) |
181
57.0M
           translate(V, Error, ExprDependence::Error);
182
57.0M
  }
183
184
23.5M
  NestedNameSpecifierDependence nestedNameSpecifier() const {
185
23.5M
    return translate(V, UnexpandedPack, NNSDependence::UnexpandedPack) |
186
23.5M
           translate(V, Instantiation, NNSDependence::Instantiation) |
187
23.5M
           translate(V, Dependent, NNSDependence::Dependent) |
188
23.5M
           translate(V, Error, NNSDependence::Error);
189
23.5M
  }
190
191
27.7M
  TemplateArgumentDependence templateArgument() const {
192
27.7M
    return translate(V, UnexpandedPack, TADependence::UnexpandedPack) |
193
27.7M
           translate(V, Instantiation, TADependence::Instantiation) |
194
27.7M
           translate(V, Dependent, TADependence::Dependent) |
195
27.7M
           translate(V, Error, TADependence::Error);
196
27.7M
  }
197
198
107k
  TemplateNameDependence templateName() const {
199
107k
    return translate(V, UnexpandedPack, TNDependence::UnexpandedPack) |
200
107k
           translate(V, Instantiation, TNDependence::Instantiation) |
201
107k
           translate(V, Dependent, TNDependence::Dependent) |
202
107k
           translate(V, Error, TNDependence::Error);
203
107k
  }
204
205
private:
206
  Bits V;
207
208
  template <typename T, typename U>
209
1.29G
  static U translate(T Bits, T FromBit, U ToBit) {
210
1.07G
    return (Bits & FromBit) ? 
ToBit228M
: static_cast<U>(0);
211
1.29G
  }
clang::Dependence::Bits clang::Dependence::translate<clang::TypeDependenceScope::TypeDependence, clang::Dependence::Bits>(clang::TypeDependenceScope::TypeDependence, clang::TypeDependenceScope::TypeDependence, clang::Dependence::Bits)
Line
Count
Source
209
493M
  static U translate(T Bits, T FromBit, U ToBit) {
210
420M
    return (Bits & FromBit) ? 
ToBit73.3M
: static_cast<U>(0);
211
493M
  }
clang::Dependence::Bits clang::Dependence::translate<clang::ExprDependenceScope::ExprDependence, clang::Dependence::Bits>(clang::ExprDependenceScope::ExprDependence, clang::ExprDependenceScope::ExprDependence, clang::Dependence::Bits)
Line
Count
Source
209
24.9M
  static U translate(T Bits, T FromBit, U ToBit) {
210
17.4M
    return (Bits & FromBit) ? 
ToBit7.51M
: static_cast<U>(0);
211
24.9M
  }
clang::Dependence::Bits clang::Dependence::translate<clang::NestedNameSpecifierDependenceScope::NestedNameSpecifierDependence, clang::Dependence::Bits>(clang::NestedNameSpecifierDependenceScope::NestedNameSpecifierDependence, clang::NestedNameSpecifierDependenceScope::NestedNameSpecifierDependence, clang::Dependence::Bits)
Line
Count
Source
209
28.6M
  static U translate(T Bits, T FromBit, U ToBit) {
210
22.4M
    return (Bits & FromBit) ? 
ToBit6.29M
: static_cast<U>(0);
211
28.6M
  }
clang::Dependence::Bits clang::Dependence::translate<clang::TemplateArgumentDependenceScope::TemplateArgumentDependence, clang::Dependence::Bits>(clang::TemplateArgumentDependenceScope::TemplateArgumentDependence, clang::TemplateArgumentDependenceScope::TemplateArgumentDependence, clang::Dependence::Bits)
Line
Count
Source
209
70.3M
  static U translate(T Bits, T FromBit, U ToBit) {
210
47.3M
    return (Bits & FromBit) ? 
ToBit23.0M
: static_cast<U>(0);
211
70.3M
  }
clang::Dependence::Bits clang::Dependence::translate<clang::TemplateNameDependenceScope::TemplateNameDependence, clang::Dependence::Bits>(clang::TemplateNameDependenceScope::TemplateNameDependence, clang::TemplateNameDependenceScope::TemplateNameDependence, clang::Dependence::Bits)
Line
Count
Source
209
40.6M
  static U translate(T Bits, T FromBit, U ToBit) {
210
40.2M
    return (Bits & FromBit) ? 
ToBit331k
: static_cast<U>(0);
211
40.6M
  }
clang::TypeDependenceScope::TypeDependence clang::Dependence::translate<clang::Dependence::Bits, clang::TypeDependenceScope::TypeDependence>(clang::Dependence::Bits, clang::Dependence::Bits, clang::TypeDependenceScope::TypeDependence)
Line
Count
Source
209
150M
  static U translate(T Bits, T FromBit, U ToBit) {
210
123M
    return (Bits & FromBit) ? 
ToBit26.9M
: static_cast<U>(0);
211
150M
  }
clang::ExprDependenceScope::ExprDependence clang::Dependence::translate<clang::Dependence::Bits, clang::ExprDependenceScope::ExprDependence>(clang::Dependence::Bits, clang::Dependence::Bits, clang::ExprDependenceScope::ExprDependence)
Line
Count
Source
209
285M
  static U translate(T Bits, T FromBit, U ToBit) {
210
260M
    return (Bits & FromBit) ? 
ToBit24.5M
: static_cast<U>(0);
211
285M
  }
clang::NestedNameSpecifierDependenceScope::NestedNameSpecifierDependence clang::Dependence::translate<clang::Dependence::Bits, clang::NestedNameSpecifierDependenceScope::NestedNameSpecifierDependence>(clang::Dependence::Bits, clang::Dependence::Bits, clang::NestedNameSpecifierDependenceScope::NestedNameSpecifierDependence)
Line
Count
Source
209
94.3M
  static U translate(T Bits, T FromBit, U ToBit) {
210
59.6M
    return (Bits & FromBit) ? 
ToBit34.6M
: static_cast<U>(0);
211
94.3M
  }
clang::TemplateArgumentDependenceScope::TemplateArgumentDependence clang::Dependence::translate<clang::Dependence::Bits, clang::TemplateArgumentDependenceScope::TemplateArgumentDependence>(clang::Dependence::Bits, clang::Dependence::Bits, clang::TemplateArgumentDependenceScope::TemplateArgumentDependence)
Line
Count
Source
209
110M
  static U translate(T Bits, T FromBit, U ToBit) {
210
78.9M
    return (Bits & FromBit) ? 
ToBit31.9M
: static_cast<U>(0);
211
110M
  }
clang::TemplateNameDependenceScope::TemplateNameDependence clang::Dependence::translate<clang::Dependence::Bits, clang::TemplateNameDependenceScope::TemplateNameDependence>(clang::Dependence::Bits, clang::Dependence::Bits, clang::TemplateNameDependenceScope::TemplateNameDependence)
Line
Count
Source
209
428k
  static U translate(T Bits, T FromBit, U ToBit) {
210
423k
    return (Bits & FromBit) ? 
ToBit4.45k
: static_cast<U>(0);
211
428k
  }
212
213
  // Abbreviations to make conversions more readable.
214
  using NNSDependence = NestedNameSpecifierDependence;
215
  using TADependence = TemplateArgumentDependence;
216
  using TNDependence = TemplateNameDependence;
217
};
218
219
/// Computes dependencies of a reference with the name having template arguments
220
/// with \p TA dependencies.
221
666k
inline ExprDependence toExprDependence(TemplateArgumentDependence TA) {
222
666k
  return Dependence(TA).expr();
223
666k
}
224
52.1M
inline ExprDependence toExprDependence(TypeDependence D) {
225
52.1M
  return Dependence(D).expr();
226
52.1M
}
227
// Note: it's often necessary to strip `Dependent` from qualifiers.
228
// If V<T>:: refers to the current instantiation, NNS is considered dependent
229
// but the containing V<T>::foo likely isn't.
230
4.31M
inline ExprDependence toExprDependence(NestedNameSpecifierDependence D) {
231
4.31M
  return Dependence(D).expr();
232
4.31M
}
233
224k
inline ExprDependence turnTypeToValueDependence(ExprDependence D) {
234
  // Type-dependent expressions are always be value-dependent, so we simply drop
235
  // type dependency.
236
224k
  return D & ~ExprDependence::Type;
237
224k
}
238
33.0k
inline ExprDependence turnValueToTypeDependence(ExprDependence D) {
239
  // Type-dependent expressions are always be value-dependent.
240
33.0k
  if (D & ExprDependence::Value)
241
23.2k
    D |= ExprDependence::Type;
242
33.0k
  return D;
243
33.0k
}
244
245
// Returned type-dependence will never have VariablyModified set.
246
385k
inline TypeDependence toTypeDependence(ExprDependence D) {
247
385k
  return Dependence(D).type();
248
385k
}
249
2.74M
inline TypeDependence toTypeDependence(NestedNameSpecifierDependence D) {
250
2.74M
  return Dependence(D).type();
251
2.74M
}
252
10.0M
inline TypeDependence toTypeDependence(TemplateNameDependence D) {
253
10.0M
  return Dependence(D).type();
254
10.0M
}
255
16.9M
inline TypeDependence toTypeDependence(TemplateArgumentDependence D) {
256
16.9M
  return Dependence(D).type();
257
16.9M
}
258
259
inline NestedNameSpecifierDependence
260
23.5M
toNestedNameSpecifierDependendence(TypeDependence D) {
261
23.5M
  return Dependence(D).nestedNameSpecifier();
262
23.5M
}
263
264
inline TemplateArgumentDependence
265
23.0M
toTemplateArgumentDependence(TypeDependence D) {
266
23.0M
  return Dependence(D).templateArgument();
267
23.0M
}
268
inline TemplateArgumentDependence
269
90.1k
toTemplateArgumentDependence(TemplateNameDependence D) {
270
90.1k
  return Dependence(D).templateArgument();
271
90.1k
}
272
inline TemplateArgumentDependence
273
4.60M
toTemplateArgumentDependence(ExprDependence D) {
274
4.60M
  return Dependence(D).templateArgument();
275
4.60M
}
276
277
inline TemplateNameDependence
278
107k
toTemplateNameDependence(NestedNameSpecifierDependence D) {
279
107k
  return Dependence(D).templateName();
280
107k
}
281
282
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
283
284
} // namespace clang
285
#endif