Coverage Report

Created: 2021-08-24 07:12

/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
    // Dependence that is propagated syntactically, regardless of semantics.
132
    Syntactic = UnexpandedPack | Instantiation | Error,
133
134
    LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/VariablyModified)
135
  };
136
137
0
  Dependence() : V(None) {}
138
139
  Dependence(TypeDependence D)
140
      : V(translate(D, TypeDependence::UnexpandedPack, UnexpandedPack) |
141
          translate(D, TypeDependence::Instantiation, Instantiation) |
142
          translate(D, TypeDependence::Dependent, Dependent) |
143
          translate(D, TypeDependence::Error, Error) |
144
106M
          translate(D, TypeDependence::VariablyModified, VariablyModified)) {}
145
146
  Dependence(ExprDependence D)
147
      : V(translate(D, ExprDependence::UnexpandedPack, UnexpandedPack) |
148
             translate(D, ExprDependence::Instantiation, Instantiation) |
149
             translate(D, ExprDependence::Type, Type) |
150
             translate(D, ExprDependence::Value, Value) |
151
5.17M
             translate(D, ExprDependence::Error, Error)) {}
152
153
  Dependence(NestedNameSpecifierDependence D) :
154
    V ( translate(D, NNSDependence::UnexpandedPack, UnexpandedPack) |
155
            translate(D, NNSDependence::Instantiation, Instantiation) |
156
            translate(D, NNSDependence::Dependent, Dependent) |
157
7.06M
            translate(D, NNSDependence::Error, Error)) {}
158
159
  Dependence(TemplateArgumentDependence D)
160
      : V(translate(D, TADependence::UnexpandedPack, UnexpandedPack) |
161
          translate(D, TADependence::Instantiation, Instantiation) |
162
          translate(D, TADependence::Dependent, Dependent) |
163
18.4M
          translate(D, TADependence::Error, Error)) {}
164
165
  Dependence(TemplateNameDependence D)
166
      : V(translate(D, TNDependence::UnexpandedPack, UnexpandedPack) |
167
             translate(D, TNDependence::Instantiation, Instantiation) |
168
             translate(D, TNDependence::Dependent, Dependent) |
169
10.5M
             translate(D, TNDependence::Error, Error)) {}
170
171
  /// Extract only the syntactic portions of this type's dependence.
172
945k
  Dependence syntactic() {
173
945k
    Dependence Result = *this;
174
945k
    Result.V &= Syntactic;
175
945k
    return Result;
176
945k
  }
177
178
32.3M
  TypeDependence type() const {
179
32.3M
    return translate(V, UnexpandedPack, TypeDependence::UnexpandedPack) |
180
32.3M
           translate(V, Instantiation, TypeDependence::Instantiation) |
181
32.3M
           translate(V, Dependent, TypeDependence::Dependent) |
182
32.3M
           translate(V, Error, TypeDependence::Error) |
183
32.3M
           translate(V, VariablyModified, TypeDependence::VariablyModified);
184
32.3M
  }
185
186
61.7M
  ExprDependence expr() const {
187
61.7M
    return translate(V, UnexpandedPack, ExprDependence::UnexpandedPack) |
188
61.7M
           translate(V, Instantiation, ExprDependence::Instantiation) |
189
61.7M
           translate(V, Type, ExprDependence::Type) |
190
61.7M
           translate(V, Value, ExprDependence::Value) |
191
61.7M
           translate(V, Error, ExprDependence::Error);
192
61.7M
  }
193
194
24.2M
  NestedNameSpecifierDependence nestedNameSpecifier() const {
195
24.2M
    return translate(V, UnexpandedPack, NNSDependence::UnexpandedPack) |
196
24.2M
           translate(V, Instantiation, NNSDependence::Instantiation) |
197
24.2M
           translate(V, Dependent, NNSDependence::Dependent) |
198
24.2M
           translate(V, Error, NNSDependence::Error);
199
24.2M
  }
200
201
29.1M
  TemplateArgumentDependence templateArgument() const {
202
29.1M
    return translate(V, UnexpandedPack, TADependence::UnexpandedPack) |
203
29.1M
           translate(V, Instantiation, TADependence::Instantiation) |
204
29.1M
           translate(V, Dependent, TADependence::Dependent) |
205
29.1M
           translate(V, Error, TADependence::Error);
206
29.1M
  }
207
208
96.5k
  TemplateNameDependence templateName() const {
209
96.5k
    return translate(V, UnexpandedPack, TNDependence::UnexpandedPack) |
210
96.5k
           translate(V, Instantiation, TNDependence::Instantiation) |
211
96.5k
           translate(V, Dependent, TNDependence::Dependent) |
212
96.5k
           translate(V, Error, TNDependence::Error);
213
96.5k
  }
214
215
private:
216
  Bits V;
217
218
  template <typename T, typename U>
219
1.38G
  static U translate(T Bits, T FromBit, U ToBit) {
220
1.38G
    return (Bits & FromBit) ? 
ToBit238M
:
static_cast<U>(0)1.14G
;
221
1.38G
  }
clang::Dependence::Bits clang::Dependence::translate<clang::TypeDependenceScope::TypeDependence, clang::Dependence::Bits>(clang::TypeDependenceScope::TypeDependence, clang::TypeDependenceScope::TypeDependence, clang::Dependence::Bits)
Line
Count
Source
219
531M
  static U translate(T Bits, T FromBit, U ToBit) {
220
531M
    return (Bits & FromBit) ? 
ToBit76.7M
:
static_cast<U>(0)454M
;
221
531M
  }
clang::Dependence::Bits clang::Dependence::translate<clang::ExprDependenceScope::ExprDependence, clang::Dependence::Bits>(clang::ExprDependenceScope::ExprDependence, clang::ExprDependenceScope::ExprDependence, clang::Dependence::Bits)
Line
Count
Source
219
25.8M
  static U translate(T Bits, T FromBit, U ToBit) {
220
25.8M
    return (Bits & FromBit) ? 
ToBit7.83M
:
static_cast<U>(0)18.0M
;
221
25.8M
  }
clang::Dependence::Bits clang::Dependence::translate<clang::NestedNameSpecifierDependenceScope::NestedNameSpecifierDependence, clang::Dependence::Bits>(clang::NestedNameSpecifierDependenceScope::NestedNameSpecifierDependence, clang::NestedNameSpecifierDependenceScope::NestedNameSpecifierDependence, clang::Dependence::Bits)
Line
Count
Source
219
28.2M
  static U translate(T Bits, T FromBit, U ToBit) {
220
28.2M
    return (Bits & FromBit) ? 
ToBit6.22M
:
static_cast<U>(0)22.0M
;
221
28.2M
  }
clang::Dependence::Bits clang::Dependence::translate<clang::TemplateArgumentDependenceScope::TemplateArgumentDependence, clang::Dependence::Bits>(clang::TemplateArgumentDependenceScope::TemplateArgumentDependence, clang::TemplateArgumentDependenceScope::TemplateArgumentDependence, clang::Dependence::Bits)
Line
Count
Source
219
73.9M
  static U translate(T Bits, T FromBit, U ToBit) {
220
73.9M
    return (Bits & FromBit) ? 
ToBit24.2M
:
static_cast<U>(0)49.6M
;
221
73.9M
  }
clang::Dependence::Bits clang::Dependence::translate<clang::TemplateNameDependenceScope::TemplateNameDependence, clang::Dependence::Bits>(clang::TemplateNameDependenceScope::TemplateNameDependence, clang::TemplateNameDependenceScope::TemplateNameDependence, clang::Dependence::Bits)
Line
Count
Source
219
42.1M
  static U translate(T Bits, T FromBit, U ToBit) {
220
42.1M
    return (Bits & FromBit) ? 
ToBit421k
:
static_cast<U>(0)41.7M
;
221
42.1M
  }
clang::TypeDependenceScope::TypeDependence clang::Dependence::translate<clang::Dependence::Bits, clang::TypeDependenceScope::TypeDependence>(clang::Dependence::Bits, clang::Dependence::Bits, clang::TypeDependenceScope::TypeDependence)
Line
Count
Source
219
161M
  static U translate(T Bits, T FromBit, U ToBit) {
220
161M
    return (Bits & FromBit) ? 
ToBit28.5M
:
static_cast<U>(0)133M
;
221
161M
  }
clang::ExprDependenceScope::ExprDependence clang::Dependence::translate<clang::Dependence::Bits, clang::ExprDependenceScope::ExprDependence>(clang::Dependence::Bits, clang::Dependence::Bits, clang::ExprDependenceScope::ExprDependence)
Line
Count
Source
219
308M
  static U translate(T Bits, T FromBit, U ToBit) {
220
308M
    return (Bits & FromBit) ? 
ToBit25.1M
:
static_cast<U>(0)283M
;
221
308M
  }
clang::NestedNameSpecifierDependenceScope::NestedNameSpecifierDependence clang::Dependence::translate<clang::Dependence::Bits, clang::NestedNameSpecifierDependenceScope::NestedNameSpecifierDependence>(clang::Dependence::Bits, clang::Dependence::Bits, clang::NestedNameSpecifierDependenceScope::NestedNameSpecifierDependence)
Line
Count
Source
219
96.9M
  static U translate(T Bits, T FromBit, U ToBit) {
220
96.9M
    return (Bits & FromBit) ? 
ToBit35.7M
:
static_cast<U>(0)61.1M
;
221
96.9M
  }
clang::TemplateArgumentDependenceScope::TemplateArgumentDependence clang::Dependence::translate<clang::Dependence::Bits, clang::TemplateArgumentDependenceScope::TemplateArgumentDependence>(clang::Dependence::Bits, clang::Dependence::Bits, clang::TemplateArgumentDependenceScope::TemplateArgumentDependence)
Line
Count
Source
219
116M
  static U translate(T Bits, T FromBit, U ToBit) {
220
116M
    return (Bits & FromBit) ? 
ToBit33.7M
:
static_cast<U>(0)82.7M
;
221
116M
  }
clang::TemplateNameDependenceScope::TemplateNameDependence clang::Dependence::translate<clang::Dependence::Bits, clang::TemplateNameDependenceScope::TemplateNameDependence>(clang::Dependence::Bits, clang::Dependence::Bits, clang::TemplateNameDependenceScope::TemplateNameDependence)
Line
Count
Source
219
386k
  static U translate(T Bits, T FromBit, U ToBit) {
220
386k
    return (Bits & FromBit) ? 
ToBit2.40k
:
static_cast<U>(0)383k
;
221
386k
  }
222
223
  // Abbreviations to make conversions more readable.
224
  using NNSDependence = NestedNameSpecifierDependence;
225
  using TADependence = TemplateArgumentDependence;
226
  using TNDependence = TemplateNameDependence;
227
};
228
229
/// Computes dependencies of a reference with the name having template arguments
230
/// with \p TA dependencies.
231
783k
inline ExprDependence toExprDependence(TemplateArgumentDependence TA) {
232
783k
  return Dependence(TA).expr();
233
783k
}
234
56.7M
inline ExprDependence toExprDependence(TypeDependence D) {
235
56.7M
  return Dependence(D).expr();
236
56.7M
}
237
// Note: it's often necessary to strip `Dependent` from qualifiers.
238
// If V<T>:: refers to the current instantiation, NNS is considered dependent
239
// but the containing V<T>::foo likely isn't.
240
4.18M
inline ExprDependence toExprDependence(NestedNameSpecifierDependence D) {
241
4.18M
  return Dependence(D).expr();
242
4.18M
}
243
228k
inline ExprDependence turnTypeToValueDependence(ExprDependence D) {
244
  // Type-dependent expressions are always be value-dependent, so we simply drop
245
  // type dependency.
246
228k
  return D & ~ExprDependence::Type;
247
228k
}
248
32.5k
inline ExprDependence turnValueToTypeDependence(ExprDependence D) {
249
  // Type-dependent expressions are always be value-dependent.
250
32.5k
  if (D & ExprDependence::Value)
251
25.2k
    D |= ExprDependence::Type;
252
32.5k
  return D;
253
32.5k
}
254
255
// Returned type-dependence will never have VariablyModified set.
256
508k
inline TypeDependence toTypeDependence(ExprDependence D) {
257
508k
  return Dependence(D).type();
258
508k
}
259
2.78M
inline TypeDependence toTypeDependence(NestedNameSpecifierDependence D) {
260
2.78M
  return Dependence(D).type();
261
2.78M
}
262
10.4M
inline TypeDependence toTypeDependence(TemplateNameDependence D) {
263
10.4M
  return Dependence(D).type();
264
10.4M
}
265
17.6M
inline TypeDependence toTypeDependence(TemplateArgumentDependence D) {
266
17.6M
  return Dependence(D).type();
267
17.6M
}
268
269
945k
inline TypeDependence toSyntacticDependence(TypeDependence D) {
270
945k
  return Dependence(D).syntactic().type();
271
945k
}
272
273
inline NestedNameSpecifierDependence
274
24.2M
toNestedNameSpecifierDependendence(TypeDependence D) {
275
24.2M
  return Dependence(D).nestedNameSpecifier();
276
24.2M
}
277
278
inline TemplateArgumentDependence
279
24.3M
toTemplateArgumentDependence(TypeDependence D) {
280
24.3M
  return Dependence(D).templateArgument();
281
24.3M
}
282
inline TemplateArgumentDependence
283
117k
toTemplateArgumentDependence(TemplateNameDependence D) {
284
117k
  return Dependence(D).templateArgument();
285
117k
}
286
inline TemplateArgumentDependence
287
4.67M
toTemplateArgumentDependence(ExprDependence D) {
288
4.67M
  return Dependence(D).templateArgument();
289
4.67M
}
290
291
inline TemplateNameDependence
292
96.5k
toTemplateNameDependence(NestedNameSpecifierDependence D) {
293
96.5k
  return Dependence(D).templateName();
294
96.5k
}
295
296
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
297
298
} // namespace clang
299
#endif