Coverage Report

Created: 2020-10-24 06:27

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/AST/ComputeDependence.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- ComputeDependence.cpp ----------------------------------------------===//
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
#include "clang/AST/ComputeDependence.h"
10
#include "clang/AST/Attr.h"
11
#include "clang/AST/DeclCXX.h"
12
#include "clang/AST/DeclarationName.h"
13
#include "clang/AST/DependenceFlags.h"
14
#include "clang/AST/Expr.h"
15
#include "clang/AST/ExprCXX.h"
16
#include "clang/AST/ExprConcepts.h"
17
#include "clang/AST/ExprObjC.h"
18
#include "clang/AST/ExprOpenMP.h"
19
#include "clang/Basic/ExceptionSpecificationType.h"
20
#include "llvm/ADT/ArrayRef.h"
21
22
using namespace clang;
23
24
6.99M
ExprDependence clang::computeDependence(FullExpr *E) {
25
6.99M
  return E->getSubExpr()->getDependence();
26
6.99M
}
27
28
647k
ExprDependence clang::computeDependence(OpaqueValueExpr *E) {
29
647k
  auto D = toExprDependence(E->getType()->getDependence());
30
647k
  if (auto *S = E->getSourceExpr())
31
6.53k
    D |= S->getDependence();
32
647k
  assert(!(D & ExprDependence::UnexpandedPack));
33
647k
  return D;
34
647k
}
35
36
2.41M
ExprDependence clang::computeDependence(ParenExpr *E) {
37
2.41M
  return E->getSubExpr()->getDependence();
38
2.41M
}
39
40
2.95M
ExprDependence clang::computeDependence(UnaryOperator *E) {
41
2.95M
  return toExprDependence(E->getType()->getDependence()) |
42
2.95M
         E->getSubExpr()->getDependence();
43
2.95M
}
44
45
124k
ExprDependence clang::computeDependence(UnaryExprOrTypeTraitExpr *E) {
46
  // Never type-dependent (C++ [temp.dep.expr]p3).
47
  // Value-dependent if the argument is type-dependent.
48
124k
  if (E->isArgumentType())
49
102k
    return turnTypeToValueDependence(
50
102k
        toExprDependence(E->getArgumentType()->getDependence()));
51
52
21.6k
  auto ArgDeps = E->getArgumentExpr()->getDependence();
53
21.6k
  auto Deps = ArgDeps & ~ExprDependence::TypeValue;
54
  // Value-dependent if the argument is type-dependent.
55
21.6k
  if (ArgDeps & ExprDependence::Type)
56
8.35k
    Deps |= ExprDependence::Value;
57
  // Check to see if we are in the situation where alignof(decl) should be
58
  // dependent because decl's alignment is dependent.
59
21.6k
  auto ExprKind = E->getKind();
60
21.6k
  if (ExprKind != UETT_AlignOf && 
ExprKind != UETT_PreferredAlignOf21.5k
)
61
21.4k
    return Deps;
62
161
  if ((Deps & ExprDependence::Value) && 
(Deps & ExprDependence::Instantiation)7
)
63
7
    return Deps;
64
65
154
  auto *NoParens = E->getArgumentExpr()->IgnoreParens();
66
154
  const ValueDecl *D = nullptr;
67
154
  if (const auto *DRE = dyn_cast<DeclRefExpr>(NoParens))
68
99
    D = DRE->getDecl();
69
55
  else if (const auto *ME = dyn_cast<MemberExpr>(NoParens))
70
26
    D = ME->getMemberDecl();
71
154
  if (!D)
72
29
    return Deps;
73
125
  for (const auto *I : D->specific_attrs<AlignedAttr>()) {
74
32
    if (I->isAlignmentErrorDependent())
75
0
      Deps |= ExprDependence::Error;
76
32
    if (I->isAlignmentDependent())
77
1
      Deps |= ExprDependence::ValueInstantiation;
78
32
  }
79
125
  return Deps;
80
125
}
81
82
324k
ExprDependence clang::computeDependence(ArraySubscriptExpr *E) {
83
324k
  return E->getLHS()->getDependence() | E->getRHS()->getDependence();
84
324k
}
85
86
143
ExprDependence clang::computeDependence(MatrixSubscriptExpr *E) {
87
143
  return E->getBase()->getDependence() | E->getRowIdx()->getDependence() |
88
45
         (E->getColumnIdx() ? E->getColumnIdx()->getDependence()
89
98
                            : ExprDependence::None);
90
143
}
91
92
59.9k
ExprDependence clang::computeDependence(CompoundLiteralExpr *E) {
93
59.9k
  return toExprDependence(E->getTypeSourceInfo()->getType()->getDependence()) |
94
59.9k
         turnTypeToValueDependence(E->getInitializer()->getDependence());
95
59.9k
}
96
97
23.5M
ExprDependence clang::computeDependence(CastExpr *E) {
98
  // Cast expressions are type-dependent if the type is
99
  // dependent (C++ [temp.dep.expr]p3).
100
  // Cast expressions are value-dependent if the type is
101
  // dependent or if the subexpression is value-dependent.
102
23.5M
  auto D = toExprDependence(E->getType()->getDependence());
103
23.5M
  if (E->getStmtClass() == Stmt::ImplicitCastExprClass) {
104
    // An implicit cast expression doesn't (lexically) contain an
105
    // unexpanded pack, even if its target type does.
106
19.0M
    D &= ~ExprDependence::UnexpandedPack;
107
19.0M
  }
108
23.5M
  if (auto *S = E->getSubExpr())
109
23.5M
    D |= S->getDependence() & ~ExprDependence::Type;
110
23.5M
  return D;
111
23.5M
}
112
113
7.33M
ExprDependence clang::computeDependence(BinaryOperator *E) {
114
7.33M
  return E->getLHS()->getDependence() | E->getRHS()->getDependence();
115
7.33M
}
116
117
254k
ExprDependence clang::computeDependence(ConditionalOperator *E) {
118
  // The type of the conditional operator depends on the type of the conditional
119
  // to support the GCC vector conditional extension. Additionally,
120
  // [temp.dep.expr] does specify state that this should be dependent on ALL sub
121
  // expressions.
122
254k
  return E->getCond()->getDependence() | E->getLHS()->getDependence() |
123
254k
         E->getRHS()->getDependence();
124
254k
}
125
126
249
ExprDependence clang::computeDependence(BinaryConditionalOperator *E) {
127
249
  return E->getCommon()->getDependence() | E->getFalseExpr()->getDependence();
128
249
}
129
130
8.76k
ExprDependence clang::computeDependence(StmtExpr *E, unsigned TemplateDepth) {
131
8.76k
  auto D = toExprDependence(E->getType()->getDependence());
132
  // Propagate dependence of the result.
133
8.76k
  if (const auto *CompoundExprResult =
134
7.48k
          dyn_cast_or_null<ValueStmt>(E->getSubStmt()->getStmtExprResult()))
135
7.48k
    if (const Expr *ResultExpr = CompoundExprResult->getExprStmt())
136
7.48k
      D |= ResultExpr->getDependence();
137
  // Note: we treat a statement-expression in a dependent context as always
138
  // being value- and instantiation-dependent. This matches the behavior of
139
  // lambda-expressions and GCC.
140
8.76k
  if (TemplateDepth)
141
20
    D |= ExprDependence::ValueInstantiation;
142
  // A param pack cannot be expanded over stmtexpr boundaries.
143
8.76k
  return D & ~ExprDependence::UnexpandedPack;
144
8.76k
}
145
146
19.4k
ExprDependence clang::computeDependence(ConvertVectorExpr *E) {
147
19.4k
  auto D = toExprDependence(E->getType()->getDependence()) |
148
19.4k
           E->getSrcExpr()->getDependence();
149
19.4k
  if (!E->getType()->isDependentType())
150
19.4k
    D &= ~ExprDependence::Type;
151
19.4k
  return D;
152
19.4k
}
153
154
76
ExprDependence clang::computeDependence(ChooseExpr *E) {
155
76
  if (E->isConditionDependent())
156
4
    return ExprDependence::TypeValueInstantiation |
157
4
           E->getCond()->getDependence() | E->getLHS()->getDependence() |
158
4
           E->getRHS()->getDependence();
159
160
72
  auto Cond = E->getCond()->getDependence();
161
72
  auto Active = E->getLHS()->getDependence();
162
72
  auto Inactive = E->getRHS()->getDependence();
163
72
  if (!E->isConditionTrue())
164
25
    std::swap(Active, Inactive);
165
  // Take type- and value- dependency from the active branch. Propagate all
166
  // other flags from all branches.
167
72
  return (Active & ExprDependence::TypeValue) |
168
72
         ((Cond | Active | Inactive) & ~ExprDependence::TypeValue);
169
72
}
170
171
709k
ExprDependence clang::computeDependence(ParenListExpr *P) {
172
709k
  auto D = ExprDependence::None;
173
709k
  for (auto *E : P->exprs())
174
961k
    D |= E->getDependence();
175
709k
  return D;
176
709k
}
177
178
971
ExprDependence clang::computeDependence(VAArgExpr *E) {
179
971
  auto D =
180
971
      toExprDependence(E->getWrittenTypeInfo()->getType()->getDependence()) |
181
971
      (E->getSubExpr()->getDependence() & ~ExprDependence::Type);
182
971
  return D & ~ExprDependence::Value;
183
971
}
184
185
64.7k
ExprDependence clang::computeDependence(NoInitExpr *E) {
186
64.7k
  return toExprDependence(E->getType()->getDependence()) &
187
64.7k
         (ExprDependence::Instantiation | ExprDependence::Error);
188
64.7k
}
189
190
902
ExprDependence clang::computeDependence(ArrayInitLoopExpr *E) {
191
902
  auto D = E->getCommonExpr()->getDependence() |
192
902
           E->getSubExpr()->getDependence() | ExprDependence::Instantiation;
193
902
  if (!E->getType()->isInstantiationDependentType())
194
902
    D &= ~ExprDependence::Instantiation;
195
902
  return turnTypeToValueDependence(D);
196
902
}
197
198
85.0k
ExprDependence clang::computeDependence(ImplicitValueInitExpr *E) {
199
85.0k
  return toExprDependence(E->getType()->getDependence()) &
200
85.0k
         ExprDependence::Instantiation;
201
85.0k
}
202
203
457
ExprDependence clang::computeDependence(ExtVectorElementExpr *E) {
204
457
  return E->getBase()->getDependence();
205
457
}
206
207
2.78k
ExprDependence clang::computeDependence(BlockExpr *E) {
208
2.78k
  auto D = toExprDependence(E->getType()->getDependence());
209
2.78k
  if (E->getBlockDecl()->isDependentContext())
210
74
    D |= ExprDependence::Instantiation;
211
2.78k
  return D & ~ExprDependence::UnexpandedPack;
212
2.78k
}
213
214
26
ExprDependence clang::computeDependence(AsTypeExpr *E) {
215
26
  auto D = toExprDependence(E->getType()->getDependence()) |
216
26
           E->getSrcExpr()->getDependence();
217
26
  if (!E->getType()->isDependentType())
218
26
    D &= ~ExprDependence::Type;
219
26
  return D;
220
26
}
221
222
126
ExprDependence clang::computeDependence(CXXRewrittenBinaryOperator *E) {
223
126
  return E->getSemanticForm()->getDependence();
224
126
}
225
226
633
ExprDependence clang::computeDependence(CXXStdInitializerListExpr *E) {
227
633
  auto D = turnTypeToValueDependence(E->getSubExpr()->getDependence());
228
633
  D |= toExprDependence(E->getType()->getDependence()) &
229
633
       (ExprDependence::Type | ExprDependence::Error);
230
633
  return D;
231
633
}
232
233
5.36k
ExprDependence clang::computeDependence(CXXTypeidExpr *E) {
234
5.36k
  auto D = ExprDependence::None;
235
5.36k
  if (E->isTypeOperand())
236
5.08k
    D = toExprDependence(
237
5.08k
        E->getTypeOperandSourceInfo()->getType()->getDependence());
238
281
  else
239
281
    D = turnTypeToValueDependence(E->getExprOperand()->getDependence());
240
  // typeid is never type-dependent (C++ [temp.dep.expr]p4)
241
5.36k
  return D & ~ExprDependence::Type;
242
5.36k
}
243
244
532
ExprDependence clang::computeDependence(MSPropertyRefExpr *E) {
245
532
  return E->getBaseExpr()->getDependence() & ~ExprDependence::Type;
246
532
}
247
248
312
ExprDependence clang::computeDependence(MSPropertySubscriptExpr *E) {
249
312
  return E->getIdx()->getDependence();
250
312
}
251
252
174
ExprDependence clang::computeDependence(CXXUuidofExpr *E) {
253
174
  if (E->isTypeOperand())
254
152
    return turnTypeToValueDependence(toExprDependence(
255
152
        E->getTypeOperandSourceInfo()->getType()->getDependence()));
256
257
22
  return turnTypeToValueDependence(E->getExprOperand()->getDependence());
258
22
}
259
260
1.19M
ExprDependence clang::computeDependence(CXXThisExpr *E) {
261
  // 'this' is type-dependent if the class type of the enclosing
262
  // member function is dependent (C++ [temp.dep.expr]p2)
263
1.19M
  auto D = toExprDependence(E->getType()->getDependence());
264
1.19M
  assert(!(D & ExprDependence::UnexpandedPack));
265
1.19M
  return D;
266
1.19M
}
267
268
13.2k
ExprDependence clang::computeDependence(CXXThrowExpr *E) {
269
13.2k
  auto *Op = E->getSubExpr();
270
13.2k
  if (!Op)
271
6.19k
    return ExprDependence::None;
272
7.02k
  return Op->getDependence() & ~ExprDependence::TypeValue;
273
7.02k
}
274
275
38.7k
ExprDependence clang::computeDependence(CXXBindTemporaryExpr *E) {
276
38.7k
  return E->getSubExpr()->getDependence();
277
38.7k
}
278
279
15.3k
ExprDependence clang::computeDependence(CXXScalarValueInitExpr *E) {
280
15.3k
  return toExprDependence(E->getType()->getDependence()) &
281
15.3k
         ~ExprDependence::TypeValue;
282
15.3k
}
283
284
4.70k
ExprDependence clang::computeDependence(CXXDeleteExpr *E) {
285
4.70k
  return turnTypeToValueDependence(E->getArgument()->getDependence());
286
4.70k
}
287
288
472
ExprDependence clang::computeDependence(ArrayTypeTraitExpr *E) {
289
472
  auto D = toExprDependence(E->getQueriedType()->getDependence());
290
472
  if (auto *Dim = E->getDimensionExpression())
291
461
    D |= Dim->getDependence();
292
472
  return turnTypeToValueDependence(D);
293
472
}
294
295
445
ExprDependence clang::computeDependence(ExpressionTraitExpr *E) {
296
  // Never type-dependent.
297
445
  auto D = E->getQueriedExpression()->getDependence() & ~ExprDependence::Type;
298
  // Value-dependent if the argument is type-dependent.
299
445
  if (E->getQueriedExpression()->isTypeDependent())
300
0
    D |= ExprDependence::Value;
301
445
  return D;
302
445
}
303
304
13.2k
ExprDependence clang::computeDependence(CXXNoexceptExpr *E, CanThrowResult CT) {
305
13.2k
  auto D = E->getOperand()->getDependence() & ~ExprDependence::TypeValue;
306
13.2k
  if (CT == CT_Dependent)
307
12.1k
    D |= ExprDependence::ValueInstantiation;
308
13.2k
  return D;
309
13.2k
}
310
311
165k
ExprDependence clang::computeDependence(PackExpansionExpr *E) {
312
165k
  return (E->getPattern()->getDependence() & ~ExprDependence::UnexpandedPack) |
313
165k
         ExprDependence::TypeValueInstantiation;
314
165k
}
315
316
770k
ExprDependence clang::computeDependence(SubstNonTypeTemplateParmExpr *E) {
317
770k
  return E->getReplacement()->getDependence();
318
770k
}
319
320
697
ExprDependence clang::computeDependence(CoroutineSuspendExpr *E) {
321
697
  if (auto *Resume = E->getResumeExpr())
322
562
    return (Resume->getDependence() &
323
562
            (ExprDependence::TypeValue | ExprDependence::Error)) |
324
562
           (E->getCommonExpr()->getDependence() & ~ExprDependence::TypeValue);
325
135
  return E->getCommonExpr()->getDependence() |
326
135
         ExprDependence::TypeValueInstantiation;
327
135
}
328
329
29
ExprDependence clang::computeDependence(DependentCoawaitExpr *E) {
330
29
  return E->getOperand()->getDependence() |
331
29
         ExprDependence::TypeValueInstantiation;
332
29
}
333
334
1.09k
ExprDependence clang::computeDependence(ObjCBoxedExpr *E) {
335
1.09k
  return E->getSubExpr()->getDependence();
336
1.09k
}
337
338
129
ExprDependence clang::computeDependence(ObjCEncodeExpr *E) {
339
129
  return toExprDependence(E->getEncodedType()->getDependence());
340
129
}
341
342
3.39k
ExprDependence clang::computeDependence(ObjCIvarRefExpr *E) {
343
3.39k
  return turnTypeToValueDependence(E->getBase()->getDependence());
344
3.39k
}
345
346
4.53k
ExprDependence clang::computeDependence(ObjCPropertyRefExpr *E) {
347
4.53k
  if (E->isObjectReceiver())
348
4.27k
    return E->getBase()->getDependence() & ~ExprDependence::Type;
349
259
  if (E->isSuperReceiver())
350
75
    return toExprDependence(E->getSuperReceiverType()->getDependence()) &
351
75
           ~ExprDependence::TypeValue;
352
184
  assert(E->isClassReceiver());
353
184
  return ExprDependence::None;
354
184
}
355
356
576
ExprDependence clang::computeDependence(ObjCSubscriptRefExpr *E) {
357
576
  return E->getBaseExpr()->getDependence() | E->getKeyExpr()->getDependence();
358
576
}
359
360
62
ExprDependence clang::computeDependence(ObjCIsaExpr *E) {
361
62
  return E->getBase()->getDependence() & ~ExprDependence::Type &
362
62
         ~ExprDependence::UnexpandedPack;
363
62
}
364
365
70
ExprDependence clang::computeDependence(ObjCIndirectCopyRestoreExpr *E) {
366
70
  return E->getSubExpr()->getDependence();
367
70
}
368
369
10.7k
ExprDependence clang::computeDependence(OMPArraySectionExpr *E) {
370
10.7k
  auto D = E->getBase()->getDependence();
371
10.7k
  if (auto *LB = E->getLowerBound())
372
4.21k
    D |= LB->getDependence();
373
10.7k
  if (auto *Len = E->getLength())
374
8.61k
    D |= Len->getDependence();
375
10.7k
  return D;
376
10.7k
}
377
378
157
ExprDependence clang::computeDependence(OMPArrayShapingExpr *E) {
379
157
  auto D = E->getBase()->getDependence() |
380
157
           toExprDependence(E->getType()->getDependence());
381
157
  for (Expr *Dim: E->getDimensions())
382
361
    if (Dim)
383
361
      D |= Dim->getDependence();
384
157
  return D;
385
157
}
386
387
50
ExprDependence clang::computeDependence(OMPIteratorExpr *E) {
388
50
  auto D = toExprDependence(E->getType()->getDependence());
389
120
  for (unsigned I = 0, End = E->numOfIterators(); I < End; 
++I70
) {
390
70
    if (auto *VD = cast_or_null<ValueDecl>(E->getIteratorDecl(I)))
391
70
      D |= toExprDependence(VD->getType()->getDependence());
392
70
    OMPIteratorExpr::IteratorRange IR = E->getIteratorRange(I);
393
70
    if (Expr *BE = IR.Begin)
394
70
      D |= BE->getDependence();
395
70
    if (Expr *EE = IR.End)
396
70
      D |= EE->getDependence();
397
70
    if (Expr *SE = IR.Step)
398
28
      D |= SE->getDependence();
399
70
  }
400
50
  return D;
401
50
}
402
403
/// Compute the type-, value-, and instantiation-dependence of a
404
/// declaration reference
405
/// based on the declaration being referenced.
406
20.9M
ExprDependence clang::computeDependence(DeclRefExpr *E, const ASTContext &Ctx) {
407
20.9M
  auto Deps = ExprDependence::None;
408
409
20.9M
  if (auto *NNS = E->getQualifier())
410
1.75M
    Deps |= toExprDependence(NNS->getDependence() &
411
1.75M
                             ~NestedNameSpecifierDependence::Dependent);
412
413
20.9M
  if (auto *FirstArg = E->getTemplateArgs()) {
414
151k
    unsigned NumArgs = E->getNumTemplateArgs();
415
320k
    for (auto *Arg = FirstArg, *End = FirstArg + NumArgs; Arg < End; 
++Arg168k
)
416
168k
      Deps |= toExprDependence(Arg->getArgument().getDependence());
417
151k
  }
418
419
20.9M
  auto *Decl = E->getDecl();
420
20.9M
  auto Type = E->getType();
421
422
20.9M
  if (Decl->isParameterPack())
423
84.3k
    Deps |= ExprDependence::UnexpandedPack;
424
20.9M
  Deps |= toExprDependence(Type->getDependence()) & ExprDependence::Error;
425
426
  // (TD) C++ [temp.dep.expr]p3:
427
  //   An id-expression is type-dependent if it contains:
428
  //
429
  // and
430
  //
431
  // (VD) C++ [temp.dep.constexpr]p2:
432
  //  An identifier is value-dependent if it is:
433
434
  //  (TD)  - an identifier that was declared with dependent type
435
  //  (VD)  - a name declared with a dependent type,
436
20.9M
  if (Type->isDependentType())
437
3.84M
    return Deps | ExprDependence::TypeValueInstantiation;
438
17.0M
  else if (Type->isInstantiationDependentType())
439
18
    Deps |= ExprDependence::Instantiation;
440
441
  //  (TD)  - a conversion-function-id that specifies a dependent type
442
17.0M
  if (Decl->getDeclName().getNameKind() ==
443
495k
      DeclarationName::CXXConversionFunctionName) {
444
495k
    QualType T = Decl->getDeclName().getCXXNameType();
445
495k
    if (T->isDependentType())
446
0
      return Deps | ExprDependence::TypeValueInstantiation;
447
448
495k
    if (T->isInstantiationDependentType())
449
0
      Deps |= ExprDependence::Instantiation;
450
495k
  }
451
452
  //  (VD)  - the name of a non-type template parameter,
453
17.0M
  if (isa<NonTypeTemplateParmDecl>(Decl))
454
466k
    return Deps | ExprDependence::ValueInstantiation;
455
456
  //  (VD) - a constant with integral or enumeration type and is
457
  //         initialized with an expression that is value-dependent.
458
  //  (VD) - a constant with literal type and is initialized with an
459
  //         expression that is value-dependent [C++11].
460
  //  (VD) - FIXME: Missing from the standard:
461
  //       -  an entity with reference type and is initialized with an
462
  //          expression that is value-dependent [C++11]
463
16.5M
  if (VarDecl *Var = dyn_cast<VarDecl>(Decl)) {
464
12.4M
    if ((Ctx.getLangOpts().CPlusPlus11
465
6.60M
             ? Var->getType()->isLiteralType(Ctx)
466
5.81M
             : Var->getType()->isIntegralOrEnumerationType()) &&
467
7.98M
        (Var->getType().isConstQualified() ||
468
5.85M
         Var->getType()->isReferenceType())) {
469
2.41M
      if (const Expr *Init = Var->getAnyInitializer()) {
470
2.10M
        if (Init->isValueDependent())
471
95.3k
          Deps |= ExprDependence::ValueInstantiation;
472
2.10M
        if (Init->containsErrors())
473
19
          Deps |= ExprDependence::Error;
474
2.10M
      }
475
2.41M
    }
476
477
    // (VD) - FIXME: Missing from the standard:
478
    //      -  a member function or a static data member of the current
479
    //         instantiation
480
12.4M
    if (Var->isStaticDataMember() &&
481
1.92M
        Var->getDeclContext()->isDependentContext()) {
482
82.6k
      Deps |= ExprDependence::ValueInstantiation;
483
82.6k
      TypeSourceInfo *TInfo = Var->getFirstDecl()->getTypeSourceInfo();
484
82.6k
      if (TInfo->getType()->isIncompleteArrayType())
485
18
        Deps |= ExprDependence::Type;
486
82.6k
    }
487
488
12.4M
    return Deps;
489
12.4M
  }
490
491
  // (VD) - FIXME: Missing from the standard:
492
  //      -  a member function or a static data member of the current
493
  //         instantiation
494
4.17M
  if (isa<CXXMethodDecl>(Decl) && 
Decl->getDeclContext()->isDependentContext()703k
)
495
1.37k
    Deps |= ExprDependence::ValueInstantiation;
496
4.17M
  return Deps;
497
4.17M
}
498
499
8.16k
ExprDependence clang::computeDependence(RecoveryExpr *E) {
500
  // RecoveryExpr is
501
  //   - always value-dependent, and therefore instantiation dependent
502
  //   - contains errors (ExprDependence::Error), by definition
503
  //   - type-dependent if we don't know the type (fallback to an opaque
504
  //     dependent type), or the type is known and dependent, or it has
505
  //     type-dependent subexpressions.
506
8.16k
  auto D = toExprDependence(E->getType()->getDependence()) |
507
8.16k
           ExprDependence::ErrorDependent;
508
  // FIXME: remove the type-dependent bit from subexpressions, if the
509
  // RecoveryExpr has a non-dependent type.
510
8.16k
  for (auto *S : E->subExpressions())
511
12.5k
    D |= S->getDependence();
512
8.16k
  return D;
513
8.16k
}
514
515
820
ExprDependence clang::computeDependence(PredefinedExpr *E) {
516
820
  return toExprDependence(E->getType()->getDependence()) &
517
820
         ~ExprDependence::UnexpandedPack;
518
820
}
519
520
ExprDependence clang::computeDependence(CallExpr *E,
521
6.63M
                                        llvm::ArrayRef<Expr *> PreArgs) {
522
6.63M
  auto D = E->getCallee()->getDependence();
523
10.5M
  for (auto *A : llvm::makeArrayRef(E->getArgs(), E->getNumArgs())) {
524
10.5M
    if (A)
525
10.5M
      D |= A->getDependence();
526
10.5M
  }
527
6.63M
  for (auto *A : PreArgs)
528
101
    D |= A->getDependence();
529
6.63M
  return D;
530
6.63M
}
531
532
327
ExprDependence clang::computeDependence(OffsetOfExpr *E) {
533
327
  auto D = turnTypeToValueDependence(
534
327
      toExprDependence(E->getTypeSourceInfo()->getType()->getDependence()));
535
368
  for (unsigned I = 0, N = E->getNumExpressions(); I < N; 
++I41
)
536
41
    D |= turnTypeToValueDependence(E->getIndexExpr(I)->getDependence());
537
327
  return D;
538
327
}
539
540
1.28M
ExprDependence clang::computeDependence(MemberExpr *E) {
541
1.28M
  auto *MemberDecl = E->getMemberDecl();
542
1.28M
  auto D = E->getBase()->getDependence();
543
1.28M
  if (FieldDecl *FD = dyn_cast<FieldDecl>(MemberDecl)) {
544
874k
    DeclContext *DC = MemberDecl->getDeclContext();
545
    // dyn_cast_or_null is used to handle objC variables which do not
546
    // have a declaration context.
547
874k
    CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(DC);
548
874k
    if (RD && 
RD->isDependentContext()750k
&&
RD->isCurrentInstantiation(DC)402k
) {
549
402k
      if (!E->getType()->isDependentType())
550
98.7k
        D &= ~ExprDependence::Type;
551
402k
    }
552
553
    // Bitfield with value-dependent width is type-dependent.
554
874k
    if (FD && FD->isBitField() && 
FD->getBitWidth()->isValueDependent()4.26k
) {
555
2
      D |= ExprDependence::Type;
556
2
    }
557
874k
  }
558
  // FIXME: move remaining dependence computation from MemberExpr::Create()
559
1.28M
  return D;
560
1.28M
}
561
562
265k
ExprDependence clang::computeDependence(InitListExpr *E) {
563
265k
  auto D = ExprDependence::None;
564
265k
  for (auto *A : E->inits())
565
536k
    D |= A->getDependence();
566
265k
  return D;
567
265k
}
568
569
145k
ExprDependence clang::computeDependence(ShuffleVectorExpr *E) {
570
145k
  auto D = toExprDependence(E->getType()->getDependence());
571
145k
  for (auto *C : llvm::makeArrayRef(E->getSubExprs(), E->getNumSubExprs()))
572
1.28M
    D |= C->getDependence();
573
145k
  return D;
574
145k
}
575
576
ExprDependence clang::computeDependence(GenericSelectionExpr *E,
577
381
                                        bool ContainsUnexpandedPack) {
578
1
  auto D = ContainsUnexpandedPack ? ExprDependence::UnexpandedPack
579
380
                                  : ExprDependence::None;
580
381
  for (auto *AE : E->getAssocExprs())
581
1.12k
    D |= AE->getDependence() & ExprDependence::Error;
582
381
  D |= E->getControllingExpr()->getDependence() & ExprDependence::Error;
583
584
381
  if (E->isResultDependent())
585
4
    return D | ExprDependence::TypeValueInstantiation;
586
377
  return D | (E->getResultExpr()->getDependence() &
587
377
              ~ExprDependence::UnexpandedPack);
588
377
}
589
590
1.92k
ExprDependence clang::computeDependence(DesignatedInitExpr *E) {
591
1.92k
  auto Deps = E->getInit()->getDependence();
592
2.26k
  for (auto D : E->designators()) {
593
2.26k
    auto DesignatorDeps = ExprDependence::None;
594
2.26k
    if (D.isArrayDesignator())
595
369
      DesignatorDeps |= E->getArrayIndex(D)->getDependence();
596
1.89k
    else if (D.isArrayRangeDesignator())
597
27
      DesignatorDeps |= E->getArrayRangeStart(D)->getDependence() |
598
27
                        E->getArrayRangeEnd(D)->getDependence();
599
2.26k
    Deps |= DesignatorDeps;
600
2.26k
    if (DesignatorDeps & ExprDependence::TypeValue)
601
10
      Deps |= ExprDependence::TypeValueInstantiation;
602
2.26k
  }
603
1.92k
  return Deps;
604
1.92k
}
605
606
6.12k
ExprDependence clang::computeDependence(PseudoObjectExpr *O) {
607
6.12k
  auto D = O->getSyntacticForm()->getDependence();
608
6.12k
  for (auto *E : O->semantics())
609
10.5k
    D |= E->getDependence();
610
6.12k
  return D;
611
6.12k
}
612
613
5.30k
ExprDependence clang::computeDependence(AtomicExpr *A) {
614
5.30k
  auto D = ExprDependence::None;
615
5.30k
  for (auto *E : llvm::makeArrayRef(A->getSubExprs(), A->getNumSubExprs()))
616
15.1k
    D |= E->getDependence();
617
5.30k
  return D;
618
5.30k
}
619
620
25.9k
ExprDependence clang::computeDependence(CXXNewExpr *E) {
621
25.9k
  auto D = toExprDependence(E->getType()->getDependence());
622
25.9k
  auto Size = E->getArraySize();
623
25.9k
  if (Size.hasValue() && 
*Size1.26k
)
624
1.25k
    D |= turnTypeToValueDependence((*Size)->getDependence());
625
25.9k
  if (auto *I = E->getInitializer())
626
24.2k
    D |= turnTypeToValueDependence(I->getDependence());
627
25.9k
  for (auto *A : E->placement_arguments())
628
18.8k
    D |= turnTypeToValueDependence(A->getDependence());
629
25.9k
  return D;
630
25.9k
}
631
632
7.52k
ExprDependence clang::computeDependence(CXXPseudoDestructorExpr *E) {
633
7.52k
  auto D = E->getBase()->getDependence();
634
7.52k
  if (!E->getDestroyedType().isNull())
635
7.51k
    D |= toExprDependence(E->getDestroyedType()->getDependence());
636
7.52k
  if (auto *ST = E->getScopeTypeInfo())
637
206
    D |= turnTypeToValueDependence(
638
206
        toExprDependence(ST->getType()->getDependence()));
639
7.52k
  if (auto *Q = E->getQualifier())
640
38
    D |= toExprDependence(Q->getDependence() &
641
38
                          ~NestedNameSpecifierDependence::Dependent);
642
7.52k
  return D;
643
7.52k
}
644
645
5.45M
static inline ExprDependence getDependenceInExpr(DeclarationNameInfo Name) {
646
5.45M
  auto D = ExprDependence::None;
647
5.45M
  if (Name.isInstantiationDependent())
648
10
    D |= ExprDependence::Instantiation;
649
5.45M
  if (Name.containsUnexpandedParameterPack())
650
0
    D |= ExprDependence::UnexpandedPack;
651
5.45M
  return D;
652
5.45M
}
653
654
ExprDependence
655
clang::computeDependence(OverloadExpr *E, bool KnownDependent,
656
                         bool KnownInstantiationDependent,
657
2.71M
                         bool KnownContainsUnexpandedParameterPack) {
658
2.71M
  auto Deps = ExprDependence::None;
659
2.71M
  if (KnownDependent)
660
147k
    Deps |= ExprDependence::TypeValue;
661
2.71M
  if (KnownInstantiationDependent)
662
148k
    Deps |= ExprDependence::Instantiation;
663
2.71M
  if (KnownContainsUnexpandedParameterPack)
664
0
    Deps |= ExprDependence::UnexpandedPack;
665
2.71M
  Deps |= getDependenceInExpr(E->getNameInfo());
666
2.71M
  if (auto *Q = E->getQualifier())
667
536k
    Deps |= toExprDependence(Q->getDependence() &
668
536k
                             ~NestedNameSpecifierDependence::Dependent);
669
14.6M
  for (auto *D : E->decls()) {
670
14.6M
    if (D->getDeclContext()->isDependentContext() ||
671
13.6M
        isa<UnresolvedUsingValueDecl>(D))
672
1.08M
      Deps |= ExprDependence::TypeValueInstantiation;
673
14.6M
  }
674
  // If we have explicit template arguments, check for dependent
675
  // template arguments and whether they contain any unexpanded pack
676
  // expansions.
677
2.71M
  for (auto A : E->template_arguments())
678
446k
    Deps |= toExprDependence(A.getArgument().getDependence());
679
2.71M
  return Deps;
680
2.71M
}
681
682
1.59M
ExprDependence clang::computeDependence(DependentScopeDeclRefExpr *E) {
683
1.59M
  auto D = ExprDependence::TypeValue;
684
1.59M
  D |= getDependenceInExpr(E->getNameInfo());
685
1.59M
  if (auto *Q = E->getQualifier())
686
1.08M
    D |= toExprDependence(Q->getDependence());
687
1.59M
  for (auto A : E->template_arguments())
688
55.5k
    D |= toExprDependence(A.getArgument().getDependence());
689
1.59M
  return D;
690
1.59M
}
691
692
356k
ExprDependence clang::computeDependence(CXXConstructExpr *E) {
693
356k
  auto D = toExprDependence(E->getType()->getDependence());
694
356k
  for (auto *A : E->arguments())
695
262k
    D |= A->getDependence() & ~ExprDependence::Type;
696
356k
  return D;
697
356k
}
698
699
2.07k
ExprDependence clang::computeDependence(CXXDefaultInitExpr *E) {
700
2.07k
  return E->getExpr()->getDependence();
701
2.07k
}
702
703
ExprDependence clang::computeDependence(LambdaExpr *E,
704
7.40k
                                        bool ContainsUnexpandedParameterPack) {
705
7.40k
  auto D = toExprDependence(E->getType()->getDependence());
706
7.40k
  if (ContainsUnexpandedParameterPack)
707
81
    D |= ExprDependence::UnexpandedPack;
708
7.40k
  return D;
709
7.40k
}
710
711
270k
ExprDependence clang::computeDependence(CXXUnresolvedConstructExpr *E) {
712
270k
  auto D = ExprDependence::ValueInstantiation;
713
270k
  D |= toExprDependence(E->getType()->getDependence());
714
270k
  for (auto *A : E->arguments())
715
195k
    D |= A->getDependence() &
716
195k
         (ExprDependence::UnexpandedPack | ExprDependence::Error);
717
270k
  return D;
718
270k
}
719
720
1.14M
ExprDependence clang::computeDependence(CXXDependentScopeMemberExpr *E) {
721
1.14M
  auto D = ExprDependence::TypeValueInstantiation;
722
1.14M
  if (!E->isImplicitAccess())
723
966k
    D |= E->getBase()->getDependence();
724
1.14M
  if (auto *Q = E->getQualifier())
725
178k
    D |= toExprDependence(Q->getDependence());
726
1.14M
  D |= getDependenceInExpr(E->getMemberNameInfo());
727
1.14M
  for (auto A : E->template_arguments())
728
2.38k
    D |= toExprDependence(A.getArgument().getDependence());
729
1.14M
  return D;
730
1.14M
}
731
732
144k
ExprDependence clang::computeDependence(MaterializeTemporaryExpr *E) {
733
144k
  return E->getSubExpr()->getDependence();
734
144k
}
735
736
219
ExprDependence clang::computeDependence(CXXFoldExpr *E) {
737
219
  auto D = ExprDependence::TypeValueInstantiation;
738
438
  for (const auto *C : {E->getLHS(), E->getRHS()}) {
739
438
    if (C)
740
297
      D |= C->getDependence() & ~ExprDependence::UnexpandedPack;
741
438
  }
742
219
  return D;
743
219
}
744
745
257k
ExprDependence clang::computeDependence(TypeTraitExpr *E) {
746
257k
  auto D = ExprDependence::None;
747
257k
  for (const auto *A : E->getArgs())
748
519k
    D |=
749
519k
        toExprDependence(A->getType()->getDependence()) & ~ExprDependence::Type;
750
257k
  return D;
751
257k
}
752
753
ExprDependence clang::computeDependence(ConceptSpecializationExpr *E,
754
812
                                        bool ValueDependent) {
755
812
  auto TA = TemplateArgumentDependence::None;
756
812
  const auto InterestingDeps = TemplateArgumentDependence::Instantiation |
757
812
                               TemplateArgumentDependence::UnexpandedPack;
758
812
  for (const TemplateArgumentLoc &ArgLoc :
759
1.15k
       E->getTemplateArgsAsWritten()->arguments()) {
760
1.15k
    TA |= ArgLoc.getArgument().getDependence() & InterestingDeps;
761
1.15k
    if (TA == InterestingDeps)
762
31
      break;
763
1.15k
  }
764
765
812
  ExprDependence D =
766
507
      ValueDependent ? 
ExprDependence::Value305
: ExprDependence::None;
767
812
  return D | toExprDependence(TA);
768
812
}
769
770
285
ExprDependence clang::computeDependence(ObjCArrayLiteral *E) {
771
285
  auto D = ExprDependence::None;
772
285
  Expr **Elements = E->getElements();
773
758
  for (unsigned I = 0, N = E->getNumElements(); I != N; 
++I473
)
774
473
    D |= turnTypeToValueDependence(Elements[I]->getDependence());
775
285
  return D;
776
285
}
777
778
213
ExprDependence clang::computeDependence(ObjCDictionaryLiteral *E) {
779
213
  auto Deps = ExprDependence::None;
780
540
  for (unsigned I = 0, N = E->getNumElements(); I < N; 
++I327
) {
781
327
    auto KV = E->getKeyValueElement(I);
782
327
    auto KVDeps = turnTypeToValueDependence(KV.Key->getDependence() |
783
327
                                            KV.Value->getDependence());
784
327
    if (KV.EllipsisLoc.isValid())
785
6
      KVDeps &= ~ExprDependence::UnexpandedPack;
786
327
    Deps |= KVDeps;
787
327
  }
788
213
  return Deps;
789
213
}
790
791
25.9k
ExprDependence clang::computeDependence(ObjCMessageExpr *E) {
792
25.9k
  auto D = ExprDependence::None;
793
25.9k
  if (auto *R = E->getInstanceReceiver())
794
16.8k
    D |= R->getDependence();
795
9.11k
  else
796
9.11k
    D |= toExprDependence(E->getType()->getDependence());
797
25.9k
  for (auto *A : E->arguments())
798
19.5k
    D |= A->getDependence();
799
25.9k
  return D;
800
25.9k
}