Coverage Report

Created: 2021-01-23 06:44

/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.95M
ExprDependence clang::computeDependence(FullExpr *E) {
25
6.95M
  return E->getSubExpr()->getDependence();
26
6.95M
}
27
28
648k
ExprDependence clang::computeDependence(OpaqueValueExpr *E) {
29
648k
  auto D = toExprDependence(E->getType()->getDependence());
30
648k
  if (auto *S = E->getSourceExpr())
31
6.52k
    D |= S->getDependence();
32
648k
  assert(!(D & ExprDependence::UnexpandedPack));
33
648k
  return D;
34
648k
}
35
36
2.40M
ExprDependence clang::computeDependence(ParenExpr *E) {
37
2.40M
  return E->getSubExpr()->getDependence();
38
2.40M
}
39
40
ExprDependence clang::computeDependence(UnaryOperator *E,
41
2.97M
                                        const ASTContext &Ctx) {
42
2.97M
  ExprDependence Dep = toExprDependence(E->getType()->getDependence()) |
43
2.97M
                       E->getSubExpr()->getDependence();
44
45
  // C++ [temp.dep.constexpr]p5:
46
  //   An expression of the form & qualified-id where the qualified-id names a
47
  //   dependent member of the current instantiation is value-dependent. An
48
  //   expression of the form & cast-expression is also value-dependent if
49
  //   evaluating cast-expression as a core constant expression succeeds and
50
  //   the result of the evaluation refers to a templated entity that is an
51
  //   object with static or thread storage duration or a member function.
52
  //
53
  // What this amounts to is: constant-evaluate the operand and check whether it
54
  // refers to a templated entity other than a variable with local storage.
55
2.97M
  if (Ctx.getLangOpts().CPlusPlus && 
E->getOpcode() == UO_AddrOf1.81M
&&
56
120k
      !(Dep & ExprDependence::Value)) {
57
66.1k
    Expr::EvalResult Result;
58
66.1k
    SmallVector<PartialDiagnosticAt, 8> Diag;
59
66.1k
    Result.Diag = &Diag;
60
    // FIXME: This doesn't enforce the C++98 constant expression rules.
61
66.1k
    if (E->getSubExpr()->EvaluateAsConstantExpr(Result, Ctx) && 
Diag.empty()14.6k
&&
62
14.3k
        Result.Val.isLValue()) {
63
14.3k
      auto *VD = Result.Val.getLValueBase().dyn_cast<const ValueDecl *>();
64
14.3k
      if (VD && 
VD->isTemplated()13.8k
) {
65
15
        auto *VarD = dyn_cast<VarDecl>(VD);
66
15
        if (!VarD || 
!VarD->hasLocalStorage()14
)
67
15
          Dep |= ExprDependence::Value;
68
15
      }
69
14.3k
    }
70
66.1k
  }
71
72
2.97M
  return Dep;
73
2.97M
}
74
75
124k
ExprDependence clang::computeDependence(UnaryExprOrTypeTraitExpr *E) {
76
  // Never type-dependent (C++ [temp.dep.expr]p3).
77
  // Value-dependent if the argument is type-dependent.
78
124k
  if (E->isArgumentType())
79
105k
    return turnTypeToValueDependence(
80
105k
        toExprDependence(E->getArgumentType()->getDependence()));
81
82
19.5k
  auto ArgDeps = E->getArgumentExpr()->getDependence();
83
19.5k
  auto Deps = ArgDeps & ~ExprDependence::TypeValue;
84
  // Value-dependent if the argument is type-dependent.
85
19.5k
  if (ArgDeps & ExprDependence::Type)
86
7.78k
    Deps |= ExprDependence::Value;
87
  // Check to see if we are in the situation where alignof(decl) should be
88
  // dependent because decl's alignment is dependent.
89
19.5k
  auto ExprKind = E->getKind();
90
19.5k
  if (ExprKind != UETT_AlignOf && 
ExprKind != UETT_PreferredAlignOf19.4k
)
91
19.3k
    return Deps;
92
163
  if ((Deps & ExprDependence::Value) && 
(Deps & ExprDependence::Instantiation)7
)
93
7
    return Deps;
94
95
156
  auto *NoParens = E->getArgumentExpr()->IgnoreParens();
96
156
  const ValueDecl *D = nullptr;
97
156
  if (const auto *DRE = dyn_cast<DeclRefExpr>(NoParens))
98
101
    D = DRE->getDecl();
99
55
  else if (const auto *ME = dyn_cast<MemberExpr>(NoParens))
100
26
    D = ME->getMemberDecl();
101
156
  if (!D)
102
29
    return Deps;
103
127
  for (const auto *I : D->specific_attrs<AlignedAttr>()) {
104
32
    if (I->isAlignmentErrorDependent())
105
0
      Deps |= ExprDependence::Error;
106
32
    if (I->isAlignmentDependent())
107
1
      Deps |= ExprDependence::ValueInstantiation;
108
32
  }
109
127
  return Deps;
110
127
}
111
112
324k
ExprDependence clang::computeDependence(ArraySubscriptExpr *E) {
113
324k
  return E->getLHS()->getDependence() | E->getRHS()->getDependence();
114
324k
}
115
116
143
ExprDependence clang::computeDependence(MatrixSubscriptExpr *E) {
117
143
  return E->getBase()->getDependence() | E->getRowIdx()->getDependence() |
118
45
         (E->getColumnIdx() ? E->getColumnIdx()->getDependence()
119
98
                            : ExprDependence::None);
120
143
}
121
122
60.2k
ExprDependence clang::computeDependence(CompoundLiteralExpr *E) {
123
60.2k
  return toExprDependence(E->getTypeSourceInfo()->getType()->getDependence()) |
124
60.2k
         turnTypeToValueDependence(E->getInitializer()->getDependence());
125
60.2k
}
126
127
23.6M
ExprDependence clang::computeDependence(CastExpr *E) {
128
  // Cast expressions are type-dependent if the type is
129
  // dependent (C++ [temp.dep.expr]p3).
130
  // Cast expressions are value-dependent if the type is
131
  // dependent or if the subexpression is value-dependent.
132
23.6M
  auto D = toExprDependence(E->getType()->getDependence());
133
23.6M
  if (E->getStmtClass() == Stmt::ImplicitCastExprClass) {
134
    // An implicit cast expression doesn't (lexically) contain an
135
    // unexpanded pack, even if its target type does.
136
19.1M
    D &= ~ExprDependence::UnexpandedPack;
137
19.1M
  }
138
23.6M
  if (auto *S = E->getSubExpr())
139
23.6M
    D |= S->getDependence() & ~ExprDependence::Type;
140
23.6M
  return D;
141
23.6M
}
142
143
7.31M
ExprDependence clang::computeDependence(BinaryOperator *E) {
144
7.31M
  return E->getLHS()->getDependence() | E->getRHS()->getDependence();
145
7.31M
}
146
147
254k
ExprDependence clang::computeDependence(ConditionalOperator *E) {
148
  // The type of the conditional operator depends on the type of the conditional
149
  // to support the GCC vector conditional extension. Additionally,
150
  // [temp.dep.expr] does specify state that this should be dependent on ALL sub
151
  // expressions.
152
254k
  return E->getCond()->getDependence() | E->getLHS()->getDependence() |
153
254k
         E->getRHS()->getDependence();
154
254k
}
155
156
252
ExprDependence clang::computeDependence(BinaryConditionalOperator *E) {
157
252
  return E->getCommon()->getDependence() | E->getFalseExpr()->getDependence();
158
252
}
159
160
8.89k
ExprDependence clang::computeDependence(StmtExpr *E, unsigned TemplateDepth) {
161
8.89k
  auto D = toExprDependence(E->getType()->getDependence());
162
  // Propagate dependence of the result.
163
8.89k
  if (const auto *CompoundExprResult =
164
7.70k
          dyn_cast_or_null<ValueStmt>(E->getSubStmt()->getStmtExprResult()))
165
7.70k
    if (const Expr *ResultExpr = CompoundExprResult->getExprStmt())
166
7.70k
      D |= ResultExpr->getDependence();
167
  // Note: we treat a statement-expression in a dependent context as always
168
  // being value- and instantiation-dependent. This matches the behavior of
169
  // lambda-expressions and GCC.
170
8.89k
  if (TemplateDepth)
171
20
    D |= ExprDependence::ValueInstantiation;
172
  // A param pack cannot be expanded over stmtexpr boundaries.
173
8.89k
  return D & ~ExprDependence::UnexpandedPack;
174
8.89k
}
175
176
19.6k
ExprDependence clang::computeDependence(ConvertVectorExpr *E) {
177
19.6k
  auto D = toExprDependence(E->getType()->getDependence()) |
178
19.6k
           E->getSrcExpr()->getDependence();
179
19.6k
  if (!E->getType()->isDependentType())
180
19.6k
    D &= ~ExprDependence::Type;
181
19.6k
  return D;
182
19.6k
}
183
184
76
ExprDependence clang::computeDependence(ChooseExpr *E) {
185
76
  if (E->isConditionDependent())
186
4
    return ExprDependence::TypeValueInstantiation |
187
4
           E->getCond()->getDependence() | E->getLHS()->getDependence() |
188
4
           E->getRHS()->getDependence();
189
190
72
  auto Cond = E->getCond()->getDependence();
191
72
  auto Active = E->getLHS()->getDependence();
192
72
  auto Inactive = E->getRHS()->getDependence();
193
72
  if (!E->isConditionTrue())
194
25
    std::swap(Active, Inactive);
195
  // Take type- and value- dependency from the active branch. Propagate all
196
  // other flags from all branches.
197
72
  return (Active & ExprDependence::TypeValue) |
198
72
         ((Cond | Active | Inactive) & ~ExprDependence::TypeValue);
199
72
}
200
201
718k
ExprDependence clang::computeDependence(ParenListExpr *P) {
202
718k
  auto D = ExprDependence::None;
203
718k
  for (auto *E : P->exprs())
204
971k
    D |= E->getDependence();
205
718k
  return D;
206
718k
}
207
208
995
ExprDependence clang::computeDependence(VAArgExpr *E) {
209
995
  auto D =
210
995
      toExprDependence(E->getWrittenTypeInfo()->getType()->getDependence()) |
211
995
      (E->getSubExpr()->getDependence() & ~ExprDependence::Type);
212
995
  return D & ~ExprDependence::Value;
213
995
}
214
215
64.7k
ExprDependence clang::computeDependence(NoInitExpr *E) {
216
64.7k
  return toExprDependence(E->getType()->getDependence()) &
217
64.7k
         (ExprDependence::Instantiation | ExprDependence::Error);
218
64.7k
}
219
220
875
ExprDependence clang::computeDependence(ArrayInitLoopExpr *E) {
221
875
  auto D = E->getCommonExpr()->getDependence() |
222
875
           E->getSubExpr()->getDependence() | ExprDependence::Instantiation;
223
875
  if (!E->getType()->isInstantiationDependentType())
224
875
    D &= ~ExprDependence::Instantiation;
225
875
  return turnTypeToValueDependence(D);
226
875
}
227
228
87.1k
ExprDependence clang::computeDependence(ImplicitValueInitExpr *E) {
229
87.1k
  return toExprDependence(E->getType()->getDependence()) &
230
87.1k
         ExprDependence::Instantiation;
231
87.1k
}
232
233
457
ExprDependence clang::computeDependence(ExtVectorElementExpr *E) {
234
457
  return E->getBase()->getDependence();
235
457
}
236
237
2.80k
ExprDependence clang::computeDependence(BlockExpr *E) {
238
2.80k
  auto D = toExprDependence(E->getType()->getDependence());
239
2.80k
  if (E->getBlockDecl()->isDependentContext())
240
74
    D |= ExprDependence::Instantiation;
241
2.80k
  return D & ~ExprDependence::UnexpandedPack;
242
2.80k
}
243
244
26
ExprDependence clang::computeDependence(AsTypeExpr *E) {
245
26
  auto D = toExprDependence(E->getType()->getDependence()) |
246
26
           E->getSrcExpr()->getDependence();
247
26
  if (!E->getType()->isDependentType())
248
26
    D &= ~ExprDependence::Type;
249
26
  return D;
250
26
}
251
252
299
ExprDependence clang::computeDependence(CXXRewrittenBinaryOperator *E) {
253
299
  return E->getSemanticForm()->getDependence();
254
299
}
255
256
646
ExprDependence clang::computeDependence(CXXStdInitializerListExpr *E) {
257
646
  auto D = turnTypeToValueDependence(E->getSubExpr()->getDependence());
258
646
  D |= toExprDependence(E->getType()->getDependence()) &
259
646
       (ExprDependence::Type | ExprDependence::Error);
260
646
  return D;
261
646
}
262
263
5.53k
ExprDependence clang::computeDependence(CXXTypeidExpr *E) {
264
5.53k
  auto D = ExprDependence::None;
265
5.53k
  if (E->isTypeOperand())
266
5.25k
    D = toExprDependence(
267
5.25k
        E->getTypeOperandSourceInfo()->getType()->getDependence());
268
281
  else
269
281
    D = turnTypeToValueDependence(E->getExprOperand()->getDependence());
270
  // typeid is never type-dependent (C++ [temp.dep.expr]p4)
271
5.53k
  return D & ~ExprDependence::Type;
272
5.53k
}
273
274
532
ExprDependence clang::computeDependence(MSPropertyRefExpr *E) {
275
532
  return E->getBaseExpr()->getDependence() & ~ExprDependence::Type;
276
532
}
277
278
312
ExprDependence clang::computeDependence(MSPropertySubscriptExpr *E) {
279
312
  return E->getIdx()->getDependence();
280
312
}
281
282
174
ExprDependence clang::computeDependence(CXXUuidofExpr *E) {
283
174
  if (E->isTypeOperand())
284
152
    return turnTypeToValueDependence(toExprDependence(
285
152
        E->getTypeOperandSourceInfo()->getType()->getDependence()));
286
287
22
  return turnTypeToValueDependence(E->getExprOperand()->getDependence());
288
22
}
289
290
1.21M
ExprDependence clang::computeDependence(CXXThisExpr *E) {
291
  // 'this' is type-dependent if the class type of the enclosing
292
  // member function is dependent (C++ [temp.dep.expr]p2)
293
1.21M
  auto D = toExprDependence(E->getType()->getDependence());
294
1.21M
  assert(!(D & ExprDependence::UnexpandedPack));
295
1.21M
  return D;
296
1.21M
}
297
298
13.6k
ExprDependence clang::computeDependence(CXXThrowExpr *E) {
299
13.6k
  auto *Op = E->getSubExpr();
300
13.6k
  if (!Op)
301
6.39k
    return ExprDependence::None;
302
7.22k
  return Op->getDependence() & ~ExprDependence::TypeValue;
303
7.22k
}
304
305
31.3k
ExprDependence clang::computeDependence(CXXBindTemporaryExpr *E) {
306
31.3k
  return E->getSubExpr()->getDependence();
307
31.3k
}
308
309
16.3k
ExprDependence clang::computeDependence(CXXScalarValueInitExpr *E) {
310
16.3k
  return toExprDependence(E->getType()->getDependence()) &
311
16.3k
         ~ExprDependence::TypeValue;
312
16.3k
}
313
314
4.83k
ExprDependence clang::computeDependence(CXXDeleteExpr *E) {
315
4.83k
  return turnTypeToValueDependence(E->getArgument()->getDependence());
316
4.83k
}
317
318
484
ExprDependence clang::computeDependence(ArrayTypeTraitExpr *E) {
319
484
  auto D = toExprDependence(E->getQueriedType()->getDependence());
320
484
  if (auto *Dim = E->getDimensionExpression())
321
473
    D |= Dim->getDependence();
322
484
  return turnTypeToValueDependence(D);
323
484
}
324
325
445
ExprDependence clang::computeDependence(ExpressionTraitExpr *E) {
326
  // Never type-dependent.
327
445
  auto D = E->getQueriedExpression()->getDependence() & ~ExprDependence::Type;
328
  // Value-dependent if the argument is type-dependent.
329
445
  if (E->getQueriedExpression()->isTypeDependent())
330
0
    D |= ExprDependence::Value;
331
445
  return D;
332
445
}
333
334
13.6k
ExprDependence clang::computeDependence(CXXNoexceptExpr *E, CanThrowResult CT) {
335
13.6k
  auto D = E->getOperand()->getDependence() & ~ExprDependence::TypeValue;
336
13.6k
  if (CT == CT_Dependent)
337
12.4k
    D |= ExprDependence::ValueInstantiation;
338
13.6k
  return D;
339
13.6k
}
340
341
164k
ExprDependence clang::computeDependence(PackExpansionExpr *E) {
342
164k
  return (E->getPattern()->getDependence() & ~ExprDependence::UnexpandedPack) |
343
164k
         ExprDependence::TypeValueInstantiation;
344
164k
}
345
346
789k
ExprDependence clang::computeDependence(SubstNonTypeTemplateParmExpr *E) {
347
789k
  return E->getReplacement()->getDependence();
348
789k
}
349
350
709
ExprDependence clang::computeDependence(CoroutineSuspendExpr *E) {
351
709
  if (auto *Resume = E->getResumeExpr())
352
574
    return (Resume->getDependence() &
353
574
            (ExprDependence::TypeValue | ExprDependence::Error)) |
354
574
           (E->getCommonExpr()->getDependence() & ~ExprDependence::TypeValue);
355
135
  return E->getCommonExpr()->getDependence() |
356
135
         ExprDependence::TypeValueInstantiation;
357
135
}
358
359
29
ExprDependence clang::computeDependence(DependentCoawaitExpr *E) {
360
29
  return E->getOperand()->getDependence() |
361
29
         ExprDependence::TypeValueInstantiation;
362
29
}
363
364
1.09k
ExprDependence clang::computeDependence(ObjCBoxedExpr *E) {
365
1.09k
  return E->getSubExpr()->getDependence();
366
1.09k
}
367
368
144
ExprDependence clang::computeDependence(ObjCEncodeExpr *E) {
369
144
  return toExprDependence(E->getEncodedType()->getDependence());
370
144
}
371
372
3.41k
ExprDependence clang::computeDependence(ObjCIvarRefExpr *E) {
373
3.41k
  return turnTypeToValueDependence(E->getBase()->getDependence());
374
3.41k
}
375
376
4.53k
ExprDependence clang::computeDependence(ObjCPropertyRefExpr *E) {
377
4.53k
  if (E->isObjectReceiver())
378
4.27k
    return E->getBase()->getDependence() & ~ExprDependence::Type;
379
259
  if (E->isSuperReceiver())
380
75
    return toExprDependence(E->getSuperReceiverType()->getDependence()) &
381
75
           ~ExprDependence::TypeValue;
382
184
  assert(E->isClassReceiver());
383
184
  return ExprDependence::None;
384
184
}
385
386
576
ExprDependence clang::computeDependence(ObjCSubscriptRefExpr *E) {
387
576
  return E->getBaseExpr()->getDependence() | E->getKeyExpr()->getDependence();
388
576
}
389
390
62
ExprDependence clang::computeDependence(ObjCIsaExpr *E) {
391
62
  return E->getBase()->getDependence() & ~ExprDependence::Type &
392
62
         ~ExprDependence::UnexpandedPack;
393
62
}
394
395
70
ExprDependence clang::computeDependence(ObjCIndirectCopyRestoreExpr *E) {
396
70
  return E->getSubExpr()->getDependence();
397
70
}
398
399
12.5k
ExprDependence clang::computeDependence(OMPArraySectionExpr *E) {
400
12.5k
  auto D = E->getBase()->getDependence();
401
12.5k
  if (auto *LB = E->getLowerBound())
402
5.00k
    D |= LB->getDependence();
403
12.5k
  if (auto *Len = E->getLength())
404
9.94k
    D |= Len->getDependence();
405
12.5k
  return D;
406
12.5k
}
407
408
157
ExprDependence clang::computeDependence(OMPArrayShapingExpr *E) {
409
157
  auto D = E->getBase()->getDependence() |
410
157
           toExprDependence(E->getType()->getDependence());
411
157
  for (Expr *Dim: E->getDimensions())
412
361
    if (Dim)
413
361
      D |= Dim->getDependence();
414
157
  return D;
415
157
}
416
417
50
ExprDependence clang::computeDependence(OMPIteratorExpr *E) {
418
50
  auto D = toExprDependence(E->getType()->getDependence());
419
120
  for (unsigned I = 0, End = E->numOfIterators(); I < End; 
++I70
) {
420
70
    if (auto *VD = cast_or_null<ValueDecl>(E->getIteratorDecl(I)))
421
70
      D |= toExprDependence(VD->getType()->getDependence());
422
70
    OMPIteratorExpr::IteratorRange IR = E->getIteratorRange(I);
423
70
    if (Expr *BE = IR.Begin)
424
70
      D |= BE->getDependence();
425
70
    if (Expr *EE = IR.End)
426
70
      D |= EE->getDependence();
427
70
    if (Expr *SE = IR.Step)
428
28
      D |= SE->getDependence();
429
70
  }
430
50
  return D;
431
50
}
432
433
/// Compute the type-, value-, and instantiation-dependence of a
434
/// declaration reference
435
/// based on the declaration being referenced.
436
21.8M
ExprDependence clang::computeDependence(DeclRefExpr *E, const ASTContext &Ctx) {
437
21.8M
  auto Deps = ExprDependence::None;
438
439
21.8M
  if (auto *NNS = E->getQualifier())
440
2.45M
    Deps |= toExprDependence(NNS->getDependence() &
441
2.45M
                             ~NestedNameSpecifierDependence::Dependent);
442
443
21.8M
  if (auto *FirstArg = E->getTemplateArgs()) {
444
142k
    unsigned NumArgs = E->getNumTemplateArgs();
445
302k
    for (auto *Arg = FirstArg, *End = FirstArg + NumArgs; Arg < End; 
++Arg159k
)
446
159k
      Deps |= toExprDependence(Arg->getArgument().getDependence());
447
142k
  }
448
449
21.8M
  auto *Decl = E->getDecl();
450
21.8M
  auto Type = E->getType();
451
452
21.8M
  if (Decl->isParameterPack())
453
83.1k
    Deps |= ExprDependence::UnexpandedPack;
454
21.8M
  Deps |= toExprDependence(Type->getDependence()) & ExprDependence::Error;
455
456
  // C++ [temp.dep.expr]p3:
457
  //   An id-expression is type-dependent if it contains:
458
459
  //    - an identifier associated by name lookup with one or more declarations
460
  //      declared with a dependent type
461
  //
462
  // [The "or more" case is not modeled as a DeclRefExpr. There are a bunch
463
  // more bullets here that we handle by treating the declaration as having a
464
  // dependent type if they involve a placeholder type that can't be deduced.]
465
21.8M
  if (Type->isDependentType())
466
3.91M
    return Deps | ExprDependence::TypeValueInstantiation;
467
17.9M
  else if (Type->isInstantiationDependentType())
468
415
    Deps |= ExprDependence::Instantiation;
469
470
  //    - a conversion-function-id that specifies a dependent type
471
17.9M
  if (Decl->getDeclName().getNameKind() ==
472
506k
      DeclarationName::CXXConversionFunctionName) {
473
506k
    QualType T = Decl->getDeclName().getCXXNameType();
474
506k
    if (T->isDependentType())
475
0
      return Deps | ExprDependence::TypeValueInstantiation;
476
477
506k
    if (T->isInstantiationDependentType())
478
0
      Deps |= ExprDependence::Instantiation;
479
506k
  }
480
481
  //   - a template-id that is dependent,
482
  //   - a nested-name-specifier or a qualified-id that names a member of an
483
  //     unknown specialization
484
  //   [These are not modeled as DeclRefExprs.]
485
486
  //   or if it names a dependent member of the current instantiation that is a
487
  //   static data member of type "array of unknown bound of T" for some T
488
  //   [handled below].
489
490
  // C++ [temp.dep.constexpr]p2:
491
  //  An id-expression is value-dependent if:
492
493
  //    - it is type-dependent [handled above]
494
495
  //    - it is the name of a non-type template parameter,
496
17.9M
  if (isa<NonTypeTemplateParmDecl>(Decl))
497
473k
    return Deps | ExprDependence::ValueInstantiation;
498
499
  //   - it names a potentially-constant variable that is initialized with an
500
  //     expression that is value-dependent
501
17.4M
  if (const auto *Var = dyn_cast<VarDecl>(Decl)) {
502
13.2M
    if (Var->mightBeUsableInConstantExpressions(Ctx)) {
503
3.01M
      if (const Expr *Init = Var->getAnyInitializer()) {
504
2.95M
        if (Init->isValueDependent())
505
97.2k
          Deps |= ExprDependence::ValueInstantiation;
506
2.95M
        if (Init->containsErrors())
507
23
          Deps |= ExprDependence::Error;
508
2.95M
      }
509
3.01M
    }
510
511
    // - it names a static data member that is a dependent member of the
512
    //   current instantiation and is not initialized in a member-declarator,
513
13.2M
    if (Var->isStaticDataMember() &&
514
2.77M
        Var->getDeclContext()->isDependentContext() &&
515
85.9k
        !Var->getFirstDecl()->hasInit()) {
516
155
      const VarDecl *First = Var->getFirstDecl();
517
155
      TypeSourceInfo *TInfo = First->getTypeSourceInfo();
518
155
      if (TInfo->getType()->isIncompleteArrayType()) {
519
24
        Deps |= ExprDependence::TypeValueInstantiation;
520
131
      } else if (!First->hasInit()) {
521
131
        Deps |= ExprDependence::ValueInstantiation;
522
131
      }
523
155
    }
524
525
13.2M
    return Deps;
526
13.2M
  }
527
528
  //   - it names a static member function that is a dependent member of the
529
  //     current instantiation
530
  //
531
  // FIXME: It's unclear that the restriction to static members here has any
532
  // effect: any use of a non-static member function name requires either
533
  // forming a pointer-to-member or providing an object parameter, either of
534
  // which makes the overall expression value-dependent.
535
4.18M
  if (auto *MD = dyn_cast<CXXMethodDecl>(Decl)) {
536
703k
    if (MD->isStatic() && 
Decl->getDeclContext()->isDependentContext()114k
)
537
1.42k
      Deps |= ExprDependence::ValueInstantiation;
538
703k
  }
539
540
4.18M
  return Deps;
541
4.18M
}
542
543
15.0k
ExprDependence clang::computeDependence(RecoveryExpr *E) {
544
  // RecoveryExpr is
545
  //   - always value-dependent, and therefore instantiation dependent
546
  //   - contains errors (ExprDependence::Error), by definition
547
  //   - type-dependent if we don't know the type (fallback to an opaque
548
  //     dependent type), or the type is known and dependent, or it has
549
  //     type-dependent subexpressions.
550
15.0k
  auto D = toExprDependence(E->getType()->getDependence()) |
551
15.0k
           ExprDependence::ErrorDependent;
552
  // FIXME: remove the type-dependent bit from subexpressions, if the
553
  // RecoveryExpr has a non-dependent type.
554
15.0k
  for (auto *S : E->subExpressions())
555
33.4k
    D |= S->getDependence();
556
15.0k
  return D;
557
15.0k
}
558
559
830
ExprDependence clang::computeDependence(PredefinedExpr *E) {
560
830
  return toExprDependence(E->getType()->getDependence()) &
561
830
         ~ExprDependence::UnexpandedPack;
562
830
}
563
564
ExprDependence clang::computeDependence(CallExpr *E,
565
6.68M
                                        llvm::ArrayRef<Expr *> PreArgs) {
566
6.68M
  auto D = E->getCallee()->getDependence();
567
10.6M
  for (auto *A : llvm::makeArrayRef(E->getArgs(), E->getNumArgs())) {
568
10.6M
    if (A)
569
10.6M
      D |= A->getDependence();
570
10.6M
  }
571
6.68M
  for (auto *A : PreArgs)
572
120
    D |= A->getDependence();
573
6.68M
  return D;
574
6.68M
}
575
576
327
ExprDependence clang::computeDependence(OffsetOfExpr *E) {
577
327
  auto D = turnTypeToValueDependence(
578
327
      toExprDependence(E->getTypeSourceInfo()->getType()->getDependence()));
579
368
  for (unsigned I = 0, N = E->getNumExpressions(); I < N; 
++I41
)
580
41
    D |= turnTypeToValueDependence(E->getIndexExpr(I)->getDependence());
581
327
  return D;
582
327
}
583
584
1.28M
ExprDependence clang::computeDependence(MemberExpr *E) {
585
1.28M
  auto *MemberDecl = E->getMemberDecl();
586
1.28M
  auto D = E->getBase()->getDependence();
587
1.28M
  if (FieldDecl *FD = dyn_cast<FieldDecl>(MemberDecl)) {
588
883k
    DeclContext *DC = MemberDecl->getDeclContext();
589
    // dyn_cast_or_null is used to handle objC variables which do not
590
    // have a declaration context.
591
883k
    CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(DC);
592
883k
    if (RD && 
RD->isDependentContext()756k
&&
RD->isCurrentInstantiation(DC)417k
) {
593
417k
      if (!E->getType()->isDependentType())
594
103k
        D &= ~ExprDependence::Type;
595
417k
    }
596
597
    // Bitfield with value-dependent width is type-dependent.
598
883k
    if (FD && FD->isBitField() && 
FD->getBitWidth()->isValueDependent()4.28k
) {
599
2
      D |= ExprDependence::Type;
600
2
    }
601
883k
  }
602
  // FIXME: move remaining dependence computation from MemberExpr::Create()
603
1.28M
  return D;
604
1.28M
}
605
606
266k
ExprDependence clang::computeDependence(InitListExpr *E) {
607
266k
  auto D = ExprDependence::None;
608
266k
  for (auto *A : E->inits())
609
538k
    D |= A->getDependence();
610
266k
  return D;
611
266k
}
612
613
143k
ExprDependence clang::computeDependence(ShuffleVectorExpr *E) {
614
143k
  auto D = toExprDependence(E->getType()->getDependence());
615
143k
  for (auto *C : llvm::makeArrayRef(E->getSubExprs(), E->getNumSubExprs()))
616
1.27M
    D |= C->getDependence();
617
143k
  return D;
618
143k
}
619
620
ExprDependence clang::computeDependence(GenericSelectionExpr *E,
621
447
                                        bool ContainsUnexpandedPack) {
622
1
  auto D = ContainsUnexpandedPack ? ExprDependence::UnexpandedPack
623
446
                                  : ExprDependence::None;
624
447
  for (auto *AE : E->getAssocExprs())
625
1.26k
    D |= AE->getDependence() & ExprDependence::Error;
626
447
  D |= E->getControllingExpr()->getDependence() & ExprDependence::Error;
627
628
447
  if (E->isResultDependent())
629
10
    return D | ExprDependence::TypeValueInstantiation;
630
437
  return D | (E->getResultExpr()->getDependence() &
631
437
              ~ExprDependence::UnexpandedPack);
632
437
}
633
634
1.93k
ExprDependence clang::computeDependence(DesignatedInitExpr *E) {
635
1.93k
  auto Deps = E->getInit()->getDependence();
636
2.27k
  for (auto D : E->designators()) {
637
2.27k
    auto DesignatorDeps = ExprDependence::None;
638
2.27k
    if (D.isArrayDesignator())
639
371
      DesignatorDeps |= E->getArrayIndex(D)->getDependence();
640
1.90k
    else if (D.isArrayRangeDesignator())
641
27
      DesignatorDeps |= E->getArrayRangeStart(D)->getDependence() |
642
27
                        E->getArrayRangeEnd(D)->getDependence();
643
2.27k
    Deps |= DesignatorDeps;
644
2.27k
    if (DesignatorDeps & ExprDependence::TypeValue)
645
10
      Deps |= ExprDependence::TypeValueInstantiation;
646
2.27k
  }
647
1.93k
  return Deps;
648
1.93k
}
649
650
6.28k
ExprDependence clang::computeDependence(PseudoObjectExpr *O) {
651
6.28k
  auto D = O->getSyntacticForm()->getDependence();
652
6.28k
  for (auto *E : O->semantics())
653
10.7k
    D |= E->getDependence();
654
6.28k
  return D;
655
6.28k
}
656
657
5.43k
ExprDependence clang::computeDependence(AtomicExpr *A) {
658
5.43k
  auto D = ExprDependence::None;
659
5.43k
  for (auto *E : llvm::makeArrayRef(A->getSubExprs(), A->getNumSubExprs()))
660
15.5k
    D |= E->getDependence();
661
5.43k
  return D;
662
5.43k
}
663
664
27.0k
ExprDependence clang::computeDependence(CXXNewExpr *E) {
665
27.0k
  auto D = toExprDependence(E->getType()->getDependence());
666
27.0k
  auto Size = E->getArraySize();
667
27.0k
  if (Size.hasValue() && 
*Size1.29k
)
668
1.28k
    D |= turnTypeToValueDependence((*Size)->getDependence());
669
27.0k
  if (auto *I = E->getInitializer())
670
25.3k
    D |= turnTypeToValueDependence(I->getDependence());
671
27.0k
  for (auto *A : E->placement_arguments())
672
19.8k
    D |= turnTypeToValueDependence(A->getDependence());
673
27.0k
  return D;
674
27.0k
}
675
676
8.08k
ExprDependence clang::computeDependence(CXXPseudoDestructorExpr *E) {
677
8.08k
  auto D = E->getBase()->getDependence();
678
8.08k
  if (!E->getDestroyedType().isNull())
679
8.07k
    D |= toExprDependence(E->getDestroyedType()->getDependence());
680
8.08k
  if (auto *ST = E->getScopeTypeInfo())
681
206
    D |= turnTypeToValueDependence(
682
206
        toExprDependence(ST->getType()->getDependence()));
683
8.08k
  if (auto *Q = E->getQualifier())
684
38
    D |= toExprDependence(Q->getDependence() &
685
38
                          ~NestedNameSpecifierDependence::Dependent);
686
8.08k
  return D;
687
8.08k
}
688
689
5.44M
static inline ExprDependence getDependenceInExpr(DeclarationNameInfo Name) {
690
5.44M
  auto D = ExprDependence::None;
691
5.44M
  if (Name.isInstantiationDependent())
692
10
    D |= ExprDependence::Instantiation;
693
5.44M
  if (Name.containsUnexpandedParameterPack())
694
0
    D |= ExprDependence::UnexpandedPack;
695
5.44M
  return D;
696
5.44M
}
697
698
ExprDependence
699
clang::computeDependence(OverloadExpr *E, bool KnownDependent,
700
                         bool KnownInstantiationDependent,
701
2.75M
                         bool KnownContainsUnexpandedParameterPack) {
702
2.75M
  auto Deps = ExprDependence::None;
703
2.75M
  if (KnownDependent)
704
150k
    Deps |= ExprDependence::TypeValue;
705
2.75M
  if (KnownInstantiationDependent)
706
151k
    Deps |= ExprDependence::Instantiation;
707
2.75M
  if (KnownContainsUnexpandedParameterPack)
708
0
    Deps |= ExprDependence::UnexpandedPack;
709
2.75M
  Deps |= getDependenceInExpr(E->getNameInfo());
710
2.75M
  if (auto *Q = E->getQualifier())
711
600k
    Deps |= toExprDependence(Q->getDependence() &
712
600k
                             ~NestedNameSpecifierDependence::Dependent);
713
14.8M
  for (auto *D : E->decls()) {
714
14.8M
    if (D->getDeclContext()->isDependentContext() ||
715
13.7M
        isa<UnresolvedUsingValueDecl>(D))
716
1.10M
      Deps |= ExprDependence::TypeValueInstantiation;
717
14.8M
  }
718
  // If we have explicit template arguments, check for dependent
719
  // template arguments and whether they contain any unexpanded pack
720
  // expansions.
721
2.75M
  for (auto A : E->template_arguments())
722
455k
    Deps |= toExprDependence(A.getArgument().getDependence());
723
2.75M
  return Deps;
724
2.75M
}
725
726
1.52M
ExprDependence clang::computeDependence(DependentScopeDeclRefExpr *E) {
727
1.52M
  auto D = ExprDependence::TypeValue;
728
1.52M
  D |= getDependenceInExpr(E->getNameInfo());
729
1.52M
  if (auto *Q = E->getQualifier())
730
1.08M
    D |= toExprDependence(Q->getDependence());
731
1.52M
  for (auto A : E->template_arguments())
732
48.0k
    D |= toExprDependence(A.getArgument().getDependence());
733
1.52M
  return D;
734
1.52M
}
735
736
339k
ExprDependence clang::computeDependence(CXXConstructExpr *E) {
737
339k
  auto D = toExprDependence(E->getType()->getDependence());
738
339k
  for (auto *A : E->arguments())
739
243k
    D |= A->getDependence() & ~ExprDependence::Type;
740
339k
  return D;
741
339k
}
742
743
2.17k
ExprDependence clang::computeDependence(CXXDefaultInitExpr *E) {
744
2.17k
  return E->getExpr()->getDependence();
745
2.17k
}
746
747
ExprDependence clang::computeDependence(LambdaExpr *E,
748
9.51k
                                        bool ContainsUnexpandedParameterPack) {
749
9.51k
  auto D = toExprDependence(E->getType()->getDependence());
750
9.51k
  if (ContainsUnexpandedParameterPack)
751
101
    D |= ExprDependence::UnexpandedPack;
752
9.51k
  return D;
753
9.51k
}
754
755
274k
ExprDependence clang::computeDependence(CXXUnresolvedConstructExpr *E) {
756
274k
  auto D = ExprDependence::ValueInstantiation;
757
274k
  D |= toExprDependence(E->getType()->getDependence());
758
274k
  for (auto *A : E->arguments())
759
198k
    D |= A->getDependence() &
760
198k
         (ExprDependence::UnexpandedPack | ExprDependence::Error);
761
274k
  return D;
762
274k
}
763
764
1.16M
ExprDependence clang::computeDependence(CXXDependentScopeMemberExpr *E) {
765
1.16M
  auto D = ExprDependence::TypeValueInstantiation;
766
1.16M
  if (!E->isImplicitAccess())
767
988k
    D |= E->getBase()->getDependence();
768
1.16M
  if (auto *Q = E->getQualifier())
769
179k
    D |= toExprDependence(Q->getDependence());
770
1.16M
  D |= getDependenceInExpr(E->getMemberNameInfo());
771
1.16M
  for (auto A : E->template_arguments())
772
2.47k
    D |= toExprDependence(A.getArgument().getDependence());
773
1.16M
  return D;
774
1.16M
}
775
776
1.99M
ExprDependence clang::computeDependence(MaterializeTemporaryExpr *E) {
777
1.99M
  return E->getSubExpr()->getDependence();
778
1.99M
}
779
780
261
ExprDependence clang::computeDependence(CXXFoldExpr *E) {
781
261
  auto D = ExprDependence::TypeValueInstantiation;
782
522
  for (const auto *C : {E->getLHS(), E->getRHS()}) {
783
522
    if (C)
784
355
      D |= C->getDependence() & ~ExprDependence::UnexpandedPack;
785
522
  }
786
261
  return D;
787
261
}
788
789
254k
ExprDependence clang::computeDependence(TypeTraitExpr *E) {
790
254k
  auto D = ExprDependence::None;
791
254k
  for (const auto *A : E->getArgs())
792
511k
    D |=
793
511k
        toExprDependence(A->getType()->getDependence()) & ~ExprDependence::Type;
794
254k
  return D;
795
254k
}
796
797
ExprDependence clang::computeDependence(ConceptSpecializationExpr *E,
798
821
                                        bool ValueDependent) {
799
821
  auto TA = TemplateArgumentDependence::None;
800
821
  const auto InterestingDeps = TemplateArgumentDependence::Instantiation |
801
821
                               TemplateArgumentDependence::UnexpandedPack;
802
821
  for (const TemplateArgumentLoc &ArgLoc :
803
1.16k
       E->getTemplateArgsAsWritten()->arguments()) {
804
1.16k
    TA |= ArgLoc.getArgument().getDependence() & InterestingDeps;
805
1.16k
    if (TA == InterestingDeps)
806
39
      break;
807
1.16k
  }
808
809
821
  ExprDependence D =
810
507
      ValueDependent ? 
ExprDependence::Value314
: ExprDependence::None;
811
821
  return D | toExprDependence(TA);
812
821
}
813
814
285
ExprDependence clang::computeDependence(ObjCArrayLiteral *E) {
815
285
  auto D = ExprDependence::None;
816
285
  Expr **Elements = E->getElements();
817
758
  for (unsigned I = 0, N = E->getNumElements(); I != N; 
++I473
)
818
473
    D |= turnTypeToValueDependence(Elements[I]->getDependence());
819
285
  return D;
820
285
}
821
822
213
ExprDependence clang::computeDependence(ObjCDictionaryLiteral *E) {
823
213
  auto Deps = ExprDependence::None;
824
540
  for (unsigned I = 0, N = E->getNumElements(); I < N; 
++I327
) {
825
327
    auto KV = E->getKeyValueElement(I);
826
327
    auto KVDeps = turnTypeToValueDependence(KV.Key->getDependence() |
827
327
                                            KV.Value->getDependence());
828
327
    if (KV.EllipsisLoc.isValid())
829
6
      KVDeps &= ~ExprDependence::UnexpandedPack;
830
327
    Deps |= KVDeps;
831
327
  }
832
213
  return Deps;
833
213
}
834
835
26.0k
ExprDependence clang::computeDependence(ObjCMessageExpr *E) {
836
26.0k
  auto D = ExprDependence::None;
837
26.0k
  if (auto *R = E->getInstanceReceiver())
838
16.9k
    D |= R->getDependence();
839
9.11k
  else
840
9.11k
    D |= toExprDependence(E->getType()->getDependence());
841
26.0k
  for (auto *A : E->arguments())
842
19.6k
    D |= A->getDependence();
843
26.0k
  return D;
844
26.0k
}