Coverage Report

Created: 2022-07-16 07:03

/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
    // Dependence that is propagated semantically, even in cases where the
134
    // type doesn't syntactically appear. This currently excludes only
135
    // UnexpandedPack. Even though Instantiation dependence is also notionally
136
    // syntactic, we also want to propagate it semantically because anything
137
    // that semantically depends on an instantiation-dependent entity should
138
    // always be instantiated when that instantiation-dependent entity is.
139
    Semantic =
140
        Instantiation | Type | Value | Dependent | Error | VariablyModified,
141
142
    LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/VariablyModified)
143
  };
144
145
0
  Dependence() : V(None) {}
146
147
  Dependence(TypeDependence D)
148
      : V(translate(D, TypeDependence::UnexpandedPack, UnexpandedPack) |
149
          translate(D, TypeDependence::Instantiation, Instantiation) |
150
          translate(D, TypeDependence::Dependent, Dependent) |
151
          translate(D, TypeDependence::Error, Error) |
152
147M
          translate(D, TypeDependence::VariablyModified, VariablyModified)) {}
153
154
  Dependence(ExprDependence D)
155
      : V(translate(D, ExprDependence::UnexpandedPack, UnexpandedPack) |
156
             translate(D, ExprDependence::Instantiation, Instantiation) |
157
             translate(D, ExprDependence::Type, Type) |
158
             translate(D, ExprDependence::Value, Value) |
159
6.57M
             translate(D, ExprDependence::Error, Error)) {}
160
161
  Dependence(NestedNameSpecifierDependence D) :
162
    V ( translate(D, NNSDependence::UnexpandedPack, UnexpandedPack) |
163
            translate(D, NNSDependence::Instantiation, Instantiation) |
164
            translate(D, NNSDependence::Dependent, Dependent) |
165
10.1M
            translate(D, NNSDependence::Error, Error)) {}
166
167
  Dependence(TemplateArgumentDependence D)
168
      : V(translate(D, TADependence::UnexpandedPack, UnexpandedPack) |
169
          translate(D, TADependence::Instantiation, Instantiation) |
170
          translate(D, TADependence::Dependent, Dependent) |
171
25.3M
          translate(D, TADependence::Error, Error)) {}
172
173
  Dependence(TemplateNameDependence D)
174
      : V(translate(D, TNDependence::UnexpandedPack, UnexpandedPack) |
175
             translate(D, TNDependence::Instantiation, Instantiation) |
176
             translate(D, TNDependence::Dependent, Dependent) |
177
14.3M
             translate(D, TNDependence::Error, Error)) {}
178
179
  /// Extract only the syntactic portions of this type's dependence.
180
1.32M
  Dependence syntactic() {
181
1.32M
    Dependence Result = *this;
182
1.32M
    Result.V &= Syntactic;
183
1.32M
    return Result;
184
1.32M
  }
185
186
  /// Extract the semantic portions of this type's dependence that apply even
187
  /// to uses where the type does not appear syntactically.
188
75.7M
  Dependence semantic() {
189
75.7M
    Dependence Result = *this;
190
75.7M
    Result.V &= Semantic;
191
75.7M
    return Result;
192
75.7M
  }
193
194
59.6M
  TypeDependence type() const {
195
59.6M
    return translate(V, UnexpandedPack, TypeDependence::UnexpandedPack) |
196
59.6M
           translate(V, Instantiation, TypeDependence::Instantiation) |
197
59.6M
           translate(V, Dependent, TypeDependence::Dependent) |
198
59.6M
           translate(V, Error, TypeDependence::Error) |
199
59.6M
           translate(V, VariablyModified, TypeDependence::VariablyModified);
200
59.6M
  }
201
202
74.2M
  ExprDependence expr() const {
203
74.2M
    return translate(V, UnexpandedPack, ExprDependence::UnexpandedPack) |
204
74.2M
           translate(V, Instantiation, ExprDependence::Instantiation) |
205
74.2M
           translate(V, Type, ExprDependence::Type) |
206
74.2M
           translate(V, Value, ExprDependence::Value) |
207
74.2M
           translate(V, Error, ExprDependence::Error);
208
74.2M
  }
209
210
31.0M
  NestedNameSpecifierDependence nestedNameSpecifier() const {
211
31.0M
    return translate(V, UnexpandedPack, NNSDependence::UnexpandedPack) |
212
31.0M
           translate(V, Instantiation, NNSDependence::Instantiation) |
213
31.0M
           translate(V, Dependent, NNSDependence::Dependent) |
214
31.0M
           translate(V, Error, NNSDependence::Error);
215
31.0M
  }
216
217
38.6M
  TemplateArgumentDependence templateArgument() const {
218
38.6M
    return translate(V, UnexpandedPack, TADependence::UnexpandedPack) |
219
38.6M
           translate(V, Instantiation, TADependence::Instantiation) |
220
38.6M
           translate(V, Dependent, TADependence::Dependent) |
221
38.6M
           translate(V, Error, TADependence::Error);
222
38.6M
  }
223
224
222k
  TemplateNameDependence templateName() const {
225
222k
    return translate(V, UnexpandedPack, TNDependence::UnexpandedPack) |
226
222k
           translate(V, Instantiation, TNDependence::Instantiation) |
227
222k
           translate(V, Dependent, TNDependence::Dependent) |
228
222k
           translate(V, Error, TNDependence::Error);
229
222k
  }
230
231
private:
232
  Bits V;
233
234
  template <typename T, typename U>
235
1.91G
  static U translate(T Bits, T FromBit, U ToBit) {
236
1.91G
    return (Bits & FromBit) ? 
ToBit363M
:
static_cast<U>(0)1.55G
;
237
1.91G
  }
clang::Dependence::Bits clang::Dependence::translate<clang::TypeDependenceScope::TypeDependence, clang::Dependence::Bits>(clang::TypeDependenceScope::TypeDependence, clang::TypeDependenceScope::TypeDependence, clang::Dependence::Bits)
Line
Count
Source
235
736M
  static U translate(T Bits, T FromBit, U ToBit) {
236
736M
    return (Bits & FromBit) ? 
ToBit122M
:
static_cast<U>(0)614M
;
237
736M
  }
clang::Dependence::Bits clang::Dependence::translate<clang::ExprDependenceScope::ExprDependence, clang::Dependence::Bits>(clang::ExprDependenceScope::ExprDependence, clang::ExprDependenceScope::ExprDependence, clang::Dependence::Bits)
Line
Count
Source
235
32.8M
  static U translate(T Bits, T FromBit, U ToBit) {
236
32.8M
    return (Bits & FromBit) ? 
ToBit10.1M
:
static_cast<U>(0)22.7M
;
237
32.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
235
40.6M
  static U translate(T Bits, T FromBit, U ToBit) {
236
40.6M
    return (Bits & FromBit) ? 
ToBit8.81M
:
static_cast<U>(0)31.8M
;
237
40.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
235
101M
  static U translate(T Bits, T FromBit, U ToBit) {
236
101M
    return (Bits & FromBit) ? 
ToBit33.8M
:
static_cast<U>(0)67.6M
;
237
101M
  }
clang::Dependence::Bits clang::Dependence::translate<clang::TemplateNameDependenceScope::TemplateNameDependence, clang::Dependence::Bits>(clang::TemplateNameDependenceScope::TemplateNameDependence, clang::TemplateNameDependenceScope::TemplateNameDependence, clang::Dependence::Bits)
Line
Count
Source
235
57.2M
  static U translate(T Bits, T FromBit, U ToBit) {
236
57.2M
    return (Bits & FromBit) ? 
ToBit528k
:
static_cast<U>(0)56.6M
;
237
57.2M
  }
clang::TypeDependenceScope::TypeDependence clang::Dependence::translate<clang::Dependence::Bits, clang::TypeDependenceScope::TypeDependence>(clang::Dependence::Bits, clang::Dependence::Bits, clang::TypeDependenceScope::TypeDependence)
Line
Count
Source
235
298M
  static U translate(T Bits, T FromBit, U ToBit) {
236
298M
    return (Bits & FromBit) ? 
ToBit57.6M
:
static_cast<U>(0)240M
;
237
298M
  }
clang::ExprDependenceScope::ExprDependence clang::Dependence::translate<clang::Dependence::Bits, clang::ExprDependenceScope::ExprDependence>(clang::Dependence::Bits, clang::Dependence::Bits, clang::ExprDependenceScope::ExprDependence)
Line
Count
Source
235
371M
  static U translate(T Bits, T FromBit, U ToBit) {
236
371M
    return (Bits & FromBit) ? 
ToBit38.3M
:
static_cast<U>(0)332M
;
237
371M
  }
clang::NestedNameSpecifierDependenceScope::NestedNameSpecifierDependence clang::Dependence::translate<clang::Dependence::Bits, clang::NestedNameSpecifierDependenceScope::NestedNameSpecifierDependence>(clang::Dependence::Bits, clang::Dependence::Bits, clang::NestedNameSpecifierDependenceScope::NestedNameSpecifierDependence)
Line
Count
Source
235
124M
  static U translate(T Bits, T FromBit, U ToBit) {
236
124M
    return (Bits & FromBit) ? 
ToBit45.6M
:
static_cast<U>(0)78.3M
;
237
124M
  }
clang::TemplateArgumentDependenceScope::TemplateArgumentDependence clang::Dependence::translate<clang::Dependence::Bits, clang::TemplateArgumentDependenceScope::TemplateArgumentDependence>(clang::Dependence::Bits, clang::Dependence::Bits, clang::TemplateArgumentDependenceScope::TemplateArgumentDependence)
Line
Count
Source
235
154M
  static U translate(T Bits, T FromBit, U ToBit) {
236
154M
    return (Bits & FromBit) ? 
ToBit45.7M
:
static_cast<U>(0)108M
;
237
154M
  }
clang::TemplateNameDependenceScope::TemplateNameDependence clang::Dependence::translate<clang::Dependence::Bits, clang::TemplateNameDependenceScope::TemplateNameDependence>(clang::Dependence::Bits, clang::Dependence::Bits, clang::TemplateNameDependenceScope::TemplateNameDependence)
Line
Count
Source
235
890k
  static U translate(T Bits, T FromBit, U ToBit) {
236
890k
    return (Bits & FromBit) ? 
ToBit2.68k
:
static_cast<U>(0)887k
;
237
890k
  }
238
239
  // Abbreviations to make conversions more readable.
240
  using NNSDependence = NestedNameSpecifierDependence;
241
  using TADependence = TemplateArgumentDependence;
242
  using TNDependence = TemplateNameDependence;
243
};
244
245
/// Computes dependencies of a reference with the name having template arguments
246
/// with \p TA dependencies.
247
1.16M
inline ExprDependence toExprDependence(TemplateArgumentDependence TA) {
248
1.16M
  return Dependence(TA).expr();
249
1.16M
}
250
60.4M
inline ExprDependence toExprDependenceForImpliedType(TypeDependence D) {
251
60.4M
  return Dependence(D).semantic().expr();
252
60.4M
}
253
6.60M
inline ExprDependence toExprDependenceAsWritten(TypeDependence D) {
254
6.60M
  return Dependence(D).expr();
255
6.60M
}
256
// Note: it's often necessary to strip `Dependent` from qualifiers.
257
// If V<T>:: refers to the current instantiation, NNS is considered dependent
258
// but the containing V<T>::foo likely isn't.
259
5.99M
inline ExprDependence toExprDependence(NestedNameSpecifierDependence D) {
260
5.99M
  return Dependence(D).expr();
261
5.99M
}
262
267k
inline ExprDependence turnTypeToValueDependence(ExprDependence D) {
263
  // Type-dependent expressions are always be value-dependent, so we simply drop
264
  // type dependency.
265
267k
  return D & ~ExprDependence::Type;
266
267k
}
267
42.1k
inline ExprDependence turnValueToTypeDependence(ExprDependence D) {
268
  // Type-dependent expressions are always be value-dependent.
269
42.1k
  if (D & ExprDependence::Value)
270
33.9k
    D |= ExprDependence::Type;
271
42.1k
  return D;
272
42.1k
}
273
274
// Returned type-dependence will never have VariablyModified set.
275
727k
inline TypeDependence toTypeDependence(ExprDependence D) {
276
727k
  return Dependence(D).type();
277
727k
}
278
3.94M
inline TypeDependence toTypeDependence(NestedNameSpecifierDependence D) {
279
3.94M
  return Dependence(D).type();
280
3.94M
}
281
14.1M
inline TypeDependence toTypeDependence(TemplateNameDependence D) {
282
14.1M
  return Dependence(D).type();
283
14.1M
}
284
24.2M
inline TypeDependence toTypeDependence(TemplateArgumentDependence D) {
285
24.2M
  return Dependence(D).type();
286
24.2M
}
287
288
1.32M
inline TypeDependence toSyntacticDependence(TypeDependence D) {
289
1.32M
  return Dependence(D).syntactic().type();
290
1.32M
}
291
15.2M
inline TypeDependence toSemanticDependence(TypeDependence D) {
292
15.2M
  return Dependence(D).semantic().type();
293
15.2M
}
294
295
inline NestedNameSpecifierDependence
296
31.0M
toNestedNameSpecifierDependendence(TypeDependence D) {
297
31.0M
  return Dependence(D).nestedNameSpecifier();
298
31.0M
}
299
300
inline TemplateArgumentDependence
301
32.6M
toTemplateArgumentDependence(TypeDependence D) {
302
32.6M
  return Dependence(D).templateArgument();
303
32.6M
}
304
inline TemplateArgumentDependence
305
138k
toTemplateArgumentDependence(TemplateNameDependence D) {
306
138k
  return Dependence(D).templateArgument();
307
138k
}
308
inline TemplateArgumentDependence
309
5.84M
toTemplateArgumentDependence(ExprDependence D) {
310
5.84M
  return Dependence(D).templateArgument();
311
5.84M
}
312
313
inline TemplateNameDependence
314
222k
toTemplateNameDependence(NestedNameSpecifierDependence D) {
315
222k
  return Dependence(D).templateName();
316
222k
}
317
318
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
319
320
} // namespace clang
321
#endif