Coverage Report

Created: 2020-10-24 06:27

/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.0M
          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
6.48M
             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
5.43M
            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.4M
          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
28.9M
  TypeDependence type() const {
169
28.9M
    return translate(V, UnexpandedPack, TypeDependence::UnexpandedPack) |
170
28.9M
           translate(V, Instantiation, TypeDependence::Instantiation) |
171
28.9M
           translate(V, Dependent, TypeDependence::Dependent) |
172
28.9M
           translate(V, Error, TypeDependence::Error) |
173
28.9M
           translate(V, VariablyModified, TypeDependence::VariablyModified);
174
28.9M
  }
175
176
55.2M
  ExprDependence expr() const {
177
55.2M
    return translate(V, UnexpandedPack, ExprDependence::UnexpandedPack) |
178
55.2M
           translate(V, Instantiation, ExprDependence::Instantiation) |
179
55.2M
           translate(V, Type, ExprDependence::Type) |
180
55.2M
           translate(V, Value, ExprDependence::Value) |
181
55.2M
           translate(V, Error, ExprDependence::Error);
182
55.2M
  }
183
184
21.4M
  NestedNameSpecifierDependence nestedNameSpecifier() const {
185
21.4M
    return translate(V, UnexpandedPack, NNSDependence::UnexpandedPack) |
186
21.4M
           translate(V, Instantiation, NNSDependence::Instantiation) |
187
21.4M
           translate(V, Dependent, NNSDependence::Dependent) |
188
21.4M
           translate(V, Error, NNSDependence::Error);
189
21.4M
  }
190
191
31.8M
  TemplateArgumentDependence templateArgument() const {
192
31.8M
    return translate(V, UnexpandedPack, TADependence::UnexpandedPack) |
193
31.8M
           translate(V, Instantiation, TADependence::Instantiation) |
194
31.8M
           translate(V, Dependent, TADependence::Dependent) |
195
31.8M
           translate(V, Error, TADependence::Error);
196
31.8M
  }
197
198
133k
  TemplateNameDependence templateName() const {
199
133k
    return translate(V, UnexpandedPack, TNDependence::UnexpandedPack) |
200
133k
           translate(V, Instantiation, TNDependence::Instantiation) |
201
133k
           translate(V, Dependent, TNDependence::Dependent) |
202
133k
           translate(V, Error, TNDependence::Error);
203
133k
  }
204
205
private:
206
  Bits V;
207
208
  template <typename T, typename U>
209
1.28G
  static U translate(T Bits, T FromBit, U ToBit) {
210
1.06G
    return (Bits & FromBit) ? 
ToBit222M
: static_cast<U>(0);
211
1.28G
  }
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
490M
  static U translate(T Bits, T FromBit, U ToBit) {
210
419M
    return (Bits & FromBit) ? 
ToBit71.0M
: static_cast<U>(0);
211
490M
  }
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
32.4M
  static U translate(T Bits, T FromBit, U ToBit) {
210
24.9M
    return (Bits & FromBit) ? 
ToBit7.44M
: static_cast<U>(0);
211
32.4M
  }
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
21.7M
  static U translate(T Bits, T FromBit, U ToBit) {
210
15.6M
    return (Bits & FromBit) ? 
ToBit6.07M
: static_cast<U>(0);
211
21.7M
  }
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
69.9M
  static U translate(T Bits, T FromBit, U ToBit) {
210
47.4M
    return (Bits & FromBit) ? 
ToBit22.5M
: static_cast<U>(0);
211
69.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
209
40.4M
  static U translate(T Bits, T FromBit, U ToBit) {
210
40.1M
    return (Bits & FromBit) ? 
ToBit314k
: static_cast<U>(0);
211
40.4M
  }
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
144M
  static U translate(T Bits, T FromBit, U ToBit) {
210
118M
    return (Bits & FromBit) ? 
ToBit26.2M
: static_cast<U>(0);
211
144M
  }
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
276M
  static U translate(T Bits, T FromBit, U ToBit) {
210
252M
    return (Bits & FromBit) ? 
ToBit24.0M
: static_cast<U>(0);
211
276M
  }
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
85.6M
  static U translate(T Bits, T FromBit, U ToBit) {
210
52.4M
    return (Bits & FromBit) ? 
ToBit33.2M
: static_cast<U>(0);
211
85.6M
  }
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
127M
  static U translate(T Bits, T FromBit, U ToBit) {
210
96.0M
    return (Bits & FromBit) ? 
ToBit31.2M
: static_cast<U>(0);
211
127M
  }
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
534k
  static U translate(T Bits, T FromBit, U ToBit) {
210
529k
    return (Bits & FromBit) ? 
ToBit4.31k
: static_cast<U>(0);
211
534k
  }
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
674k
inline ExprDependence toExprDependence(TemplateArgumentDependence TA) {
222
674k
  return Dependence(TA).expr();
223
674k
}
224
51.0M
inline ExprDependence toExprDependence(TypeDependence D) {
225
51.0M
  return Dependence(D).expr();
226
51.0M
}
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
3.55M
inline ExprDependence toExprDependence(NestedNameSpecifierDependence D) {
231
3.55M
  return Dependence(D).expr();
232
3.55M
}
233
219k
inline ExprDependence turnTypeToValueDependence(ExprDependence D) {
234
  // Type-dependent expressions are always be value-dependent, so we simply drop
235
  // type dependency.
236
219k
  return D & ~ExprDependence::Type;
237
219k
}
238
32.2k
inline ExprDependence turnValueToTypeDependence(ExprDependence D) {
239
  // Type-dependent expressions are always be value-dependent.
240
32.2k
  if (D & ExprDependence::Value)
241
22.7k
    D |= ExprDependence::Type;
242
32.2k
  return D;
243
32.2k
}
244
245
// Returned type-dependence will never have VariablyModified set.
246
399k
inline TypeDependence toTypeDependence(ExprDependence D) {
247
399k
  return Dependence(D).type();
248
399k
}
249
1.74M
inline TypeDependence toTypeDependence(NestedNameSpecifierDependence D) {
250
1.74M
  return Dependence(D).type();
251
1.74M
}
252
10.0M
inline TypeDependence toTypeDependence(TemplateNameDependence D) {
253
10.0M
  return Dependence(D).type();
254
10.0M
}
255
16.8M
inline TypeDependence toTypeDependence(TemplateArgumentDependence D) {
256
16.8M
  return Dependence(D).type();
257
16.8M
}
258
259
inline NestedNameSpecifierDependence
260
21.4M
toNestedNameSpecifierDependendence(TypeDependence D) {
261
21.4M
  return Dependence(D).nestedNameSpecifier();
262
21.4M
}
263
264
inline TemplateArgumentDependence
265
25.6M
toTemplateArgumentDependence(TypeDependence D) {
266
25.6M
  return Dependence(D).templateArgument();
267
25.6M
}
268
inline TemplateArgumentDependence
269
110k
toTemplateArgumentDependence(TemplateNameDependence D) {
270
110k
  return Dependence(D).templateArgument();
271
110k
}
272
inline TemplateArgumentDependence
273
6.08M
toTemplateArgumentDependence(ExprDependence D) {
274
6.08M
  return Dependence(D).templateArgument();
275
6.08M
}
276
277
inline TemplateNameDependence
278
133k
toTemplateNameDependence(NestedNameSpecifierDependence D) {
279
133k
  return Dependence(D).templateName();
280
133k
}
281
282
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
283
284
} // namespace clang
285
#endif