Coverage Report

Created: 2021-08-24 07:12

/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
5.86M
ExprDependence clang::computeDependence(FullExpr *E) {
25
5.86M
  return E->getSubExpr()->getDependence();
26
5.86M
}
27
28
708k
ExprDependence clang::computeDependence(OpaqueValueExpr *E) {
29
708k
  auto D = toExprDependence(E->getType()->getDependence());
30
708k
  if (auto *S = E->getSourceExpr())
31
7.41k
    D |= S->getDependence();
32
708k
  assert(!(D & ExprDependence::UnexpandedPack));
33
0
  return D;
34
708k
}
35
36
2.50M
ExprDependence clang::computeDependence(ParenExpr *E) {
37
2.50M
  return E->getSubExpr()->getDependence();
38
2.50M
}
39
40
ExprDependence clang::computeDependence(UnaryOperator *E,
41
2.72M
                                        const ASTContext &Ctx) {
42
2.72M
  ExprDependence Dep = toExprDependence(E->getType()->getDependence()) |
43
2.72M
                       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.72M
  if (Ctx.getLangOpts().CPlusPlus && 
E->getOpcode() == UO_AddrOf1.80M
&&
56
2.72M
      
!(Dep & ExprDependence::Value)128k
) {
57
75.0k
    Expr::EvalResult Result;
58
75.0k
    SmallVector<PartialDiagnosticAt, 8> Diag;
59
75.0k
    Result.Diag = &Diag;
60
    // FIXME: This doesn't enforce the C++98 constant expression rules.
61
75.0k
    if (E->getSubExpr()->EvaluateAsConstantExpr(Result, Ctx) && 
Diag.empty()15.8k
&&
62
75.0k
        
Result.Val.isLValue()15.5k
) {
63
15.5k
      auto *VD = Result.Val.getLValueBase().dyn_cast<const ValueDecl *>();
64
15.5k
      if (VD && 
VD->isTemplated()14.9k
) {
65
15
        auto *VarD = dyn_cast<VarDecl>(VD);
66
15
        if (!VarD || 
!VarD->hasLocalStorage()14
)
67
15
          Dep |= ExprDependence::Value;
68
15
      }
69
15.5k
    }
70
75.0k
  }
71
72
2.72M
  return Dep;
73
2.72M
}
74
75
122k
ExprDependence clang::computeDependence(UnaryExprOrTypeTraitExpr *E) {
76
  // Never type-dependent (C++ [temp.dep.expr]p3).
77
  // Value-dependent if the argument is type-dependent.
78
122k
  if (E->isArgumentType())
79
103k
    return turnTypeToValueDependence(
80
103k
        toExprDependence(E->getArgumentType()->getDependence()));
81
82
19.1k
  auto ArgDeps = E->getArgumentExpr()->getDependence();
83
19.1k
  auto Deps = ArgDeps & ~ExprDependence::TypeValue;
84
  // Value-dependent if the argument is type-dependent.
85
19.1k
  if (ArgDeps & ExprDependence::Type)
86
7.53k
    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.1k
  auto ExprKind = E->getKind();
90
19.1k
  if (ExprKind != UETT_AlignOf && 
ExprKind != UETT_PreferredAlignOf19.1k
)
91
19.0k
    return Deps;
92
175
  if ((Deps & ExprDependence::Value) && 
(Deps & ExprDependence::Instantiation)11
)
93
11
    return Deps;
94
95
164
  auto *NoParens = E->getArgumentExpr()->IgnoreParens();
96
164
  const ValueDecl *D = nullptr;
97
164
  if (const auto *DRE = dyn_cast<DeclRefExpr>(NoParens))
98
101
    D = DRE->getDecl();
99
63
  else if (const auto *ME = dyn_cast<MemberExpr>(NoParens))
100
26
    D = ME->getMemberDecl();
101
164
  if (!D)
102
37
    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
164
}
111
112
350k
ExprDependence clang::computeDependence(ArraySubscriptExpr *E) {
113
350k
  return E->getLHS()->getDependence() | E->getRHS()->getDependence();
114
350k
}
115
116
143
ExprDependence clang::computeDependence(MatrixSubscriptExpr *E) {
117
143
  return E->getBase()->getDependence() | E->getRowIdx()->getDependence() |
118
143
         (E->getColumnIdx() ? 
E->getColumnIdx()->getDependence()45
119
143
                            : 
ExprDependence::None98
);
120
143
}
121
122
62.1k
ExprDependence clang::computeDependence(CompoundLiteralExpr *E) {
123
62.1k
  return toExprDependence(E->getTypeSourceInfo()->getType()->getDependence()) |
124
62.1k
         turnTypeToValueDependence(E->getInitializer()->getDependence());
125
62.1k
}
126
127
27.1M
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
27.1M
  auto D = toExprDependence(E->getType()->getDependence());
133
27.1M
  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
22.3M
    D &= ~ExprDependence::UnexpandedPack;
137
22.3M
  }
138
27.1M
  if (auto *S = E->getSubExpr())
139
27.1M
    D |= S->getDependence() & ~ExprDependence::Type;
140
27.1M
  return D;
141
27.1M
}
142
143
7.22M
ExprDependence clang::computeDependence(BinaryOperator *E) {
144
7.22M
  return E->getLHS()->getDependence() | E->getRHS()->getDependence();
145
7.22M
}
146
147
248k
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
248k
  return E->getCond()->getDependence() | E->getLHS()->getDependence() |
153
248k
         E->getRHS()->getDependence();
154
248k
}
155
156
273
ExprDependence clang::computeDependence(BinaryConditionalOperator *E) {
157
273
  return E->getCommon()->getDependence() | E->getFalseExpr()->getDependence();
158
273
}
159
160
9.15k
ExprDependence clang::computeDependence(StmtExpr *E, unsigned TemplateDepth) {
161
9.15k
  auto D = toExprDependence(E->getType()->getDependence());
162
  // Propagate dependence of the result.
163
9.15k
  if (const auto *CompoundExprResult =
164
9.15k
          dyn_cast_or_null<ValueStmt>(E->getSubStmt()->getStmtExprResult()))
165
7.95k
    if (const Expr *ResultExpr = CompoundExprResult->getExprStmt())
166
7.94k
      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
9.15k
  if (TemplateDepth)
171
20
    D |= ExprDependence::ValueInstantiation;
172
  // A param pack cannot be expanded over stmtexpr boundaries.
173
9.15k
  return D & ~ExprDependence::UnexpandedPack;
174
9.15k
}
175
176
20.0k
ExprDependence clang::computeDependence(ConvertVectorExpr *E) {
177
20.0k
  auto D = toExprDependence(E->getType()->getDependence()) |
178
20.0k
           E->getSrcExpr()->getDependence();
179
20.0k
  if (!E->getType()->isDependentType())
180
20.0k
    D &= ~ExprDependence::Type;
181
20.0k
  return D;
182
20.0k
}
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
76
}
200
201
875k
ExprDependence clang::computeDependence(ParenListExpr *P) {
202
875k
  auto D = ExprDependence::None;
203
875k
  for (auto *E : P->exprs())
204
1.17M
    D |= E->getDependence();
205
875k
  return D;
206
875k
}
207
208
1.08k
ExprDependence clang::computeDependence(VAArgExpr *E) {
209
1.08k
  auto D =
210
1.08k
      toExprDependence(E->getWrittenTypeInfo()->getType()->getDependence()) |
211
1.08k
      (E->getSubExpr()->getDependence() & ~ExprDependence::Type);
212
1.08k
  return D & ~ExprDependence::Value;
213
1.08k
}
214
215
65.9k
ExprDependence clang::computeDependence(NoInitExpr *E) {
216
65.9k
  return toExprDependence(E->getType()->getDependence()) &
217
65.9k
         (ExprDependence::Instantiation | ExprDependence::Error);
218
65.9k
}
219
220
899
ExprDependence clang::computeDependence(ArrayInitLoopExpr *E) {
221
899
  auto D = E->getCommonExpr()->getDependence() |
222
899
           E->getSubExpr()->getDependence() | ExprDependence::Instantiation;
223
899
  if (!E->getType()->isInstantiationDependentType())
224
899
    D &= ~ExprDependence::Instantiation;
225
899
  return turnTypeToValueDependence(D);
226
899
}
227
228
93.3k
ExprDependence clang::computeDependence(ImplicitValueInitExpr *E) {
229
93.3k
  return toExprDependence(E->getType()->getDependence()) &
230
93.3k
         ExprDependence::Instantiation;
231
93.3k
}
232
233
499
ExprDependence clang::computeDependence(ExtVectorElementExpr *E) {
234
499
  return E->getBase()->getDependence();
235
499
}
236
237
2.95k
ExprDependence clang::computeDependence(BlockExpr *E) {
238
2.95k
  auto D = toExprDependence(E->getType()->getDependence());
239
2.95k
  if (E->getBlockDecl()->isDependentContext())
240
80
    D |= ExprDependence::Instantiation;
241
2.95k
  return D & ~ExprDependence::UnexpandedPack;
242
2.95k
}
243
244
36
ExprDependence clang::computeDependence(AsTypeExpr *E) {
245
36
  auto D = toExprDependence(E->getType()->getDependence()) |
246
36
           E->getSrcExpr()->getDependence();
247
36
  if (!E->getType()->isDependentType())
248
36
    D &= ~ExprDependence::Type;
249
36
  return D;
250
36
}
251
252
307
ExprDependence clang::computeDependence(CXXRewrittenBinaryOperator *E) {
253
307
  return E->getSemanticForm()->getDependence();
254
307
}
255
256
665
ExprDependence clang::computeDependence(CXXStdInitializerListExpr *E) {
257
665
  auto D = turnTypeToValueDependence(E->getSubExpr()->getDependence());
258
665
  D |= toExprDependence(E->getType()->getDependence()) &
259
665
       (ExprDependence::Type | ExprDependence::Error);
260
665
  return D;
261
665
}
262
263
5.76k
ExprDependence clang::computeDependence(CXXTypeidExpr *E) {
264
5.76k
  auto D = ExprDependence::None;
265
5.76k
  if (E->isTypeOperand())
266
5.45k
    D = toExprDependence(
267
5.45k
        E->getTypeOperandSourceInfo()->getType()->getDependence());
268
304
  else
269
304
    D = turnTypeToValueDependence(E->getExprOperand()->getDependence());
270
  // typeid is never type-dependent (C++ [temp.dep.expr]p4)
271
5.76k
  return D & ~ExprDependence::Type;
272
5.76k
}
273
274
628
ExprDependence clang::computeDependence(MSPropertyRefExpr *E) {
275
628
  return E->getBaseExpr()->getDependence() & ~ExprDependence::Type;
276
628
}
277
278
312
ExprDependence clang::computeDependence(MSPropertySubscriptExpr *E) {
279
312
  return E->getIdx()->getDependence();
280
312
}
281
282
182
ExprDependence clang::computeDependence(CXXUuidofExpr *E) {
283
182
  if (E->isTypeOperand())
284
152
    return turnTypeToValueDependence(toExprDependence(
285
152
        E->getTypeOperandSourceInfo()->getType()->getDependence()));
286
287
30
  return turnTypeToValueDependence(E->getExprOperand()->getDependence());
288
182
}
289
290
1.28M
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.28M
  auto D = toExprDependence(E->getType()->getDependence());
294
1.28M
  assert(!(D & ExprDependence::UnexpandedPack));
295
0
  return D;
296
1.28M
}
297
298
14.3k
ExprDependence clang::computeDependence(CXXThrowExpr *E) {
299
14.3k
  auto *Op = E->getSubExpr();
300
14.3k
  if (!Op)
301
6.89k
    return ExprDependence::None;
302
7.47k
  return Op->getDependence() & ~ExprDependence::TypeValue;
303
14.3k
}
304
305
39.8k
ExprDependence clang::computeDependence(CXXBindTemporaryExpr *E) {
306
39.8k
  return E->getSubExpr()->getDependence();
307
39.8k
}
308
309
18.3k
ExprDependence clang::computeDependence(CXXScalarValueInitExpr *E) {
310
18.3k
  return toExprDependence(E->getType()->getDependence()) &
311
18.3k
         ~ExprDependence::TypeValue;
312
18.3k
}
313
314
6.67k
ExprDependence clang::computeDependence(CXXDeleteExpr *E) {
315
6.67k
  return turnTypeToValueDependence(E->getArgument()->getDependence());
316
6.67k
}
317
318
493
ExprDependence clang::computeDependence(ArrayTypeTraitExpr *E) {
319
493
  auto D = toExprDependence(E->getQueriedType()->getDependence());
320
493
  if (auto *Dim = E->getDimensionExpression())
321
482
    D |= Dim->getDependence();
322
493
  return turnTypeToValueDependence(D);
323
493
}
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.5k
ExprDependence clang::computeDependence(CXXNoexceptExpr *E, CanThrowResult CT) {
335
13.5k
  auto D = E->getOperand()->getDependence() & ~ExprDependence::TypeValue;
336
13.5k
  if (CT == CT_Dependent)
337
12.3k
    D |= ExprDependence::ValueInstantiation;
338
13.5k
  return D;
339
13.5k
}
340
341
129k
ExprDependence clang::computeDependence(PackExpansionExpr *E) {
342
129k
  return (E->getPattern()->getDependence() & ~ExprDependence::UnexpandedPack) |
343
129k
         ExprDependence::TypeValueInstantiation;
344
129k
}
345
346
848k
ExprDependence clang::computeDependence(SubstNonTypeTemplateParmExpr *E) {
347
848k
  return E->getReplacement()->getDependence();
348
848k
}
349
350
1.61k
ExprDependence clang::computeDependence(CoroutineSuspendExpr *E) {
351
1.61k
  if (auto *Resume = E->getResumeExpr())
352
1.27k
    return (Resume->getDependence() &
353
1.27k
            (ExprDependence::TypeValue | ExprDependence::Error)) |
354
1.27k
           (E->getCommonExpr()->getDependence() & ~ExprDependence::TypeValue);
355
343
  return E->getCommonExpr()->getDependence() |
356
343
         ExprDependence::TypeValueInstantiation;
357
1.61k
}
358
359
69
ExprDependence clang::computeDependence(DependentCoawaitExpr *E) {
360
69
  return E->getOperand()->getDependence() |
361
69
         ExprDependence::TypeValueInstantiation;
362
69
}
363
364
1.31k
ExprDependence clang::computeDependence(ObjCBoxedExpr *E) {
365
1.31k
  return E->getSubExpr()->getDependence();
366
1.31k
}
367
368
204
ExprDependence clang::computeDependence(ObjCEncodeExpr *E) {
369
204
  return toExprDependence(E->getEncodedType()->getDependence());
370
204
}
371
372
3.38k
ExprDependence clang::computeDependence(ObjCIvarRefExpr *E) {
373
3.38k
  return turnTypeToValueDependence(E->getBase()->getDependence());
374
3.38k
}
375
376
4.59k
ExprDependence clang::computeDependence(ObjCPropertyRefExpr *E) {
377
4.59k
  if (E->isObjectReceiver())
378
4.32k
    return E->getBase()->getDependence() & ~ExprDependence::Type;
379
267
  if (E->isSuperReceiver())
380
75
    return toExprDependence(E->getSuperReceiverType()->getDependence()) &
381
75
           ~ExprDependence::TypeValue;
382
192
  assert(E->isClassReceiver());
383
0
  return ExprDependence::None;
384
267
}
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.6k
ExprDependence clang::computeDependence(OMPArraySectionExpr *E) {
400
12.6k
  auto D = E->getBase()->getDependence();
401
12.6k
  if (auto *LB = E->getLowerBound())
402
5.07k
    D |= LB->getDependence();
403
12.6k
  if (auto *Len = E->getLength())
404
10.0k
    D |= Len->getDependence();
405
12.6k
  return D;
406
12.6k
}
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
52
ExprDependence clang::computeDependence(OMPIteratorExpr *E) {
418
52
  auto D = toExprDependence(E->getType()->getDependence());
419
124
  for (unsigned I = 0, End = E->numOfIterators(); I < End; 
++I72
) {
420
72
    if (auto *VD = cast_or_null<ValueDecl>(E->getIteratorDecl(I)))
421
72
      D |= toExprDependence(VD->getType()->getDependence());
422
72
    OMPIteratorExpr::IteratorRange IR = E->getIteratorRange(I);
423
72
    if (Expr *BE = IR.Begin)
424
72
      D |= BE->getDependence();
425
72
    if (Expr *EE = IR.End)
426
72
      D |= EE->getDependence();
427
72
    if (Expr *SE = IR.Step)
428
28
      D |= SE->getDependence();
429
72
  }
430
52
  return D;
431
52
}
432
433
/// Compute the type-, value-, and instantiation-dependence of a
434
/// declaration reference
435
/// based on the declaration being referenced.
436
23.1M
ExprDependence clang::computeDependence(DeclRefExpr *E, const ASTContext &Ctx) {
437
23.1M
  auto Deps = ExprDependence::None;
438
439
23.1M
  if (auto *NNS = E->getQualifier())
440
2.44M
    Deps |= toExprDependence(NNS->getDependence() &
441
2.44M
                             ~NestedNameSpecifierDependence::Dependent);
442
443
23.1M
  if (auto *FirstArg = E->getTemplateArgs()) {
444
151k
    unsigned NumArgs = E->getNumTemplateArgs();
445
336k
    for (auto *Arg = FirstArg, *End = FirstArg + NumArgs; Arg < End; 
++Arg184k
)
446
184k
      Deps |= toExprDependence(Arg->getArgument().getDependence());
447
151k
  }
448
449
23.1M
  auto *Decl = E->getDecl();
450
23.1M
  auto Type = E->getType();
451
452
23.1M
  if (Decl->isParameterPack())
453
85.3k
    Deps |= ExprDependence::UnexpandedPack;
454
23.1M
  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
23.1M
  if (Type->isDependentType())
466
4.05M
    return Deps | ExprDependence::TypeValueInstantiation;
467
19.1M
  else if (Type->isInstantiationDependentType())
468
457
    Deps |= ExprDependence::Instantiation;
469
470
  //    - a conversion-function-id that specifies a dependent type
471
19.1M
  if (Decl->getDeclName().getNameKind() ==
472
19.1M
      DeclarationName::CXXConversionFunctionName) {
473
523k
    QualType T = Decl->getDeclName().getCXXNameType();
474
523k
    if (T->isDependentType())
475
0
      return Deps | ExprDependence::TypeValueInstantiation;
476
477
523k
    if (T->isInstantiationDependentType())
478
0
      Deps |= ExprDependence::Instantiation;
479
523k
  }
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
19.1M
  if (isa<NonTypeTemplateParmDecl>(Decl))
497
475k
    return Deps | ExprDependence::ValueInstantiation;
498
499
  //   - it names a potentially-constant variable that is initialized with an
500
  //     expression that is value-dependent
501
18.6M
  if (const auto *Var = dyn_cast<VarDecl>(Decl)) {
502
14.2M
    if (Var->mightBeUsableInConstantExpressions(Ctx)) {
503
3.05M
      if (const Expr *Init = Var->getAnyInitializer()) {
504
2.99M
        if (Init->isValueDependent())
505
97.8k
          Deps |= ExprDependence::ValueInstantiation;
506
2.99M
        if (Init->containsErrors())
507
51
          Deps |= ExprDependence::Error;
508
2.99M
      }
509
3.05M
    }
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
14.2M
    if (Var->isStaticDataMember() &&
514
14.2M
        
Var->getDeclContext()->isDependentContext()2.80M
&&
515
14.2M
        
!Var->getFirstDecl()->hasInit()86.9k
) {
516
196
      const VarDecl *First = Var->getFirstDecl();
517
196
      TypeSourceInfo *TInfo = First->getTypeSourceInfo();
518
196
      if (TInfo->getType()->isIncompleteArrayType()) {
519
24
        Deps |= ExprDependence::TypeValueInstantiation;
520
172
      } else if (!First->hasInit()) {
521
172
        Deps |= ExprDependence::ValueInstantiation;
522
172
      }
523
196
    }
524
525
14.2M
    return Deps;
526
14.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.41M
  if (auto *MD = dyn_cast<CXXMethodDecl>(Decl)) {
536
721k
    if (MD->isStatic() && 
Decl->getDeclContext()->isDependentContext()113k
)
537
1.46k
      Deps |= ExprDependence::ValueInstantiation;
538
721k
  }
539
540
4.41M
  return Deps;
541
18.6M
}
542
543
16.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
16.0k
  auto D = toExprDependence(E->getType()->getDependence()) |
551
16.0k
           ExprDependence::ErrorDependent;
552
  // FIXME: remove the type-dependent bit from subexpressions, if the
553
  // RecoveryExpr has a non-dependent type.
554
16.0k
  for (auto *S : E->subExpressions())
555
35.7k
    D |= S->getDependence();
556
16.0k
  return D;
557
16.0k
}
558
559
82
ExprDependence clang::computeDependence(SYCLUniqueStableNameExpr *E) {
560
82
  return toExprDependence(E->getTypeSourceInfo()->getType()->getDependence());
561
82
}
562
563
839
ExprDependence clang::computeDependence(PredefinedExpr *E) {
564
839
  return toExprDependence(E->getType()->getDependence()) &
565
839
         ~ExprDependence::UnexpandedPack;
566
839
}
567
568
ExprDependence clang::computeDependence(CallExpr *E,
569
10.5M
                                        llvm::ArrayRef<Expr *> PreArgs) {
570
10.5M
  auto D = E->getCallee()->getDependence();
571
17.6M
  for (auto *A : llvm::makeArrayRef(E->getArgs(), E->getNumArgs())) {
572
17.6M
    if (A)
573
17.6M
      D |= A->getDependence();
574
17.6M
  }
575
10.5M
  for (auto *A : PreArgs)
576
241
    D |= A->getDependence();
577
10.5M
  return D;
578
10.5M
}
579
580
327
ExprDependence clang::computeDependence(OffsetOfExpr *E) {
581
327
  auto D = turnTypeToValueDependence(
582
327
      toExprDependence(E->getTypeSourceInfo()->getType()->getDependence()));
583
368
  for (unsigned I = 0, N = E->getNumExpressions(); I < N; 
++I41
)
584
41
    D |= turnTypeToValueDependence(E->getIndexExpr(I)->getDependence());
585
327
  return D;
586
327
}
587
588
1.38M
ExprDependence clang::computeDependence(MemberExpr *E) {
589
1.38M
  auto *MemberDecl = E->getMemberDecl();
590
1.38M
  auto D = E->getBase()->getDependence();
591
1.38M
  if (FieldDecl *FD = dyn_cast<FieldDecl>(MemberDecl)) {
592
958k
    DeclContext *DC = MemberDecl->getDeclContext();
593
    // dyn_cast_or_null is used to handle objC variables which do not
594
    // have a declaration context.
595
958k
    CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(DC);
596
958k
    if (RD && 
RD->isDependentContext()841k
&&
RD->isCurrentInstantiation(DC)441k
) {
597
441k
      if (!E->getType()->isDependentType())
598
107k
        D &= ~ExprDependence::Type;
599
441k
    }
600
601
    // Bitfield with value-dependent width is type-dependent.
602
958k
    if (FD && FD->isBitField() && 
FD->getBitWidth()->isValueDependent()9.26k
) {
603
2
      D |= ExprDependence::Type;
604
2
    }
605
958k
  }
606
  // FIXME: move remaining dependence computation from MemberExpr::Create()
607
1.38M
  return D;
608
1.38M
}
609
610
270k
ExprDependence clang::computeDependence(InitListExpr *E) {
611
270k
  auto D = ExprDependence::None;
612
270k
  for (auto *A : E->inits())
613
582k
    D |= A->getDependence();
614
270k
  return D;
615
270k
}
616
617
145k
ExprDependence clang::computeDependence(ShuffleVectorExpr *E) {
618
145k
  auto D = toExprDependence(E->getType()->getDependence());
619
145k
  for (auto *C : llvm::makeArrayRef(E->getSubExprs(), E->getNumSubExprs()))
620
1.31M
    D |= C->getDependence();
621
145k
  return D;
622
145k
}
623
624
ExprDependence clang::computeDependence(GenericSelectionExpr *E,
625
525
                                        bool ContainsUnexpandedPack) {
626
525
  auto D = ContainsUnexpandedPack ? 
ExprDependence::UnexpandedPack1
627
525
                                  : 
ExprDependence::None524
;
628
525
  for (auto *AE : E->getAssocExprs())
629
1.48k
    D |= AE->getDependence() & ExprDependence::Error;
630
525
  D |= E->getControllingExpr()->getDependence() & ExprDependence::Error;
631
632
525
  if (E->isResultDependent())
633
10
    return D | ExprDependence::TypeValueInstantiation;
634
515
  return D | (E->getResultExpr()->getDependence() &
635
515
              ~ExprDependence::UnexpandedPack);
636
525
}
637
638
2.13k
ExprDependence clang::computeDependence(DesignatedInitExpr *E) {
639
2.13k
  auto Deps = E->getInit()->getDependence();
640
2.47k
  for (auto D : E->designators()) {
641
2.47k
    auto DesignatorDeps = ExprDependence::None;
642
2.47k
    if (D.isArrayDesignator())
643
376
      DesignatorDeps |= E->getArrayIndex(D)->getDependence();
644
2.10k
    else if (D.isArrayRangeDesignator())
645
27
      DesignatorDeps |= E->getArrayRangeStart(D)->getDependence() |
646
27
                        E->getArrayRangeEnd(D)->getDependence();
647
2.47k
    Deps |= DesignatorDeps;
648
2.47k
    if (DesignatorDeps & ExprDependence::TypeValue)
649
10
      Deps |= ExprDependence::TypeValueInstantiation;
650
2.47k
  }
651
2.13k
  return Deps;
652
2.13k
}
653
654
6.84k
ExprDependence clang::computeDependence(PseudoObjectExpr *O) {
655
6.84k
  auto D = O->getSyntacticForm()->getDependence();
656
6.84k
  for (auto *E : O->semantics())
657
11.3k
    D |= E->getDependence();
658
6.84k
  return D;
659
6.84k
}
660
661
6.50k
ExprDependence clang::computeDependence(AtomicExpr *A) {
662
6.50k
  auto D = ExprDependence::None;
663
6.50k
  for (auto *E : llvm::makeArrayRef(A->getSubExprs(), A->getNumSubExprs()))
664
19.0k
    D |= E->getDependence();
665
6.50k
  return D;
666
6.50k
}
667
668
28.1k
ExprDependence clang::computeDependence(CXXNewExpr *E) {
669
28.1k
  auto D = toExprDependence(E->getType()->getDependence());
670
28.1k
  auto Size = E->getArraySize();
671
28.1k
  if (Size.hasValue() && 
*Size1.32k
)
672
1.31k
    D |= turnTypeToValueDependence((*Size)->getDependence());
673
28.1k
  if (auto *I = E->getInitializer())
674
26.4k
    D |= turnTypeToValueDependence(I->getDependence());
675
28.1k
  for (auto *A : E->placement_arguments())
676
20.6k
    D |= turnTypeToValueDependence(A->getDependence());
677
28.1k
  return D;
678
28.1k
}
679
680
8.35k
ExprDependence clang::computeDependence(CXXPseudoDestructorExpr *E) {
681
8.35k
  auto D = E->getBase()->getDependence();
682
8.35k
  if (!E->getDestroyedType().isNull())
683
8.34k
    D |= toExprDependence(E->getDestroyedType()->getDependence());
684
8.35k
  if (auto *ST = E->getScopeTypeInfo())
685
206
    D |= turnTypeToValueDependence(
686
206
        toExprDependence(ST->getType()->getDependence()));
687
8.35k
  if (auto *Q = E->getQualifier())
688
38
    D |= toExprDependence(Q->getDependence() &
689
38
                          ~NestedNameSpecifierDependence::Dependent);
690
8.35k
  return D;
691
8.35k
}
692
693
5.65M
static inline ExprDependence getDependenceInExpr(DeclarationNameInfo Name) {
694
5.65M
  auto D = ExprDependence::None;
695
5.65M
  if (Name.isInstantiationDependent())
696
16
    D |= ExprDependence::Instantiation;
697
5.65M
  if (Name.containsUnexpandedParameterPack())
698
0
    D |= ExprDependence::UnexpandedPack;
699
5.65M
  return D;
700
5.65M
}
701
702
ExprDependence
703
clang::computeDependence(OverloadExpr *E, bool KnownDependent,
704
                         bool KnownInstantiationDependent,
705
3.01M
                         bool KnownContainsUnexpandedParameterPack) {
706
3.01M
  auto Deps = ExprDependence::None;
707
3.01M
  if (KnownDependent)
708
159k
    Deps |= ExprDependence::TypeValue;
709
3.01M
  if (KnownInstantiationDependent)
710
159k
    Deps |= ExprDependence::Instantiation;
711
3.01M
  if (KnownContainsUnexpandedParameterPack)
712
0
    Deps |= ExprDependence::UnexpandedPack;
713
3.01M
  Deps |= getDependenceInExpr(E->getNameInfo());
714
3.01M
  if (auto *Q = E->getQualifier())
715
548k
    Deps |= toExprDependence(Q->getDependence() &
716
548k
                             ~NestedNameSpecifierDependence::Dependent);
717
18.1M
  for (auto *D : E->decls()) {
718
18.1M
    if (D->getDeclContext()->isDependentContext() ||
719
18.1M
        
isa<UnresolvedUsingValueDecl>(D)16.9M
)
720
1.15M
      Deps |= ExprDependence::TypeValueInstantiation;
721
18.1M
  }
722
  // If we have explicit template arguments, check for dependent
723
  // template arguments and whether they contain any unexpanded pack
724
  // expansions.
725
3.01M
  for (auto A : E->template_arguments())
726
570k
    Deps |= toExprDependence(A.getArgument().getDependence());
727
3.01M
  return Deps;
728
3.01M
}
729
730
1.43M
ExprDependence clang::computeDependence(DependentScopeDeclRefExpr *E) {
731
1.43M
  auto D = ExprDependence::TypeValue;
732
1.43M
  D |= getDependenceInExpr(E->getNameInfo());
733
1.43M
  if (auto *Q = E->getQualifier())
734
1.01M
    D |= toExprDependence(Q->getDependence());
735
1.43M
  for (auto A : E->template_arguments())
736
24.1k
    D |= toExprDependence(A.getArgument().getDependence());
737
1.43M
  return D;
738
1.43M
}
739
740
353k
ExprDependence clang::computeDependence(CXXConstructExpr *E) {
741
353k
  auto D = toExprDependence(E->getType()->getDependence());
742
353k
  for (auto *A : E->arguments())
743
248k
    D |= A->getDependence() & ~ExprDependence::Type;
744
353k
  return D;
745
353k
}
746
747
2.35k
ExprDependence clang::computeDependence(CXXDefaultInitExpr *E) {
748
2.35k
  return E->getExpr()->getDependence();
749
2.35k
}
750
751
31.2k
ExprDependence clang::computeDependence(CXXDefaultArgExpr *E) {
752
31.2k
  return E->getExpr()->getDependence();
753
31.2k
}
754
755
ExprDependence clang::computeDependence(LambdaExpr *E,
756
10.1k
                                        bool ContainsUnexpandedParameterPack) {
757
10.1k
  auto D = toExprDependence(E->getType()->getDependence());
758
10.1k
  if (ContainsUnexpandedParameterPack)
759
107
    D |= ExprDependence::UnexpandedPack;
760
10.1k
  return D;
761
10.1k
}
762
763
287k
ExprDependence clang::computeDependence(CXXUnresolvedConstructExpr *E) {
764
287k
  auto D = ExprDependence::ValueInstantiation;
765
287k
  D |= toExprDependence(E->getType()->getDependence());
766
287k
  for (auto *A : E->arguments())
767
206k
    D |= A->getDependence() &
768
206k
         (ExprDependence::UnexpandedPack | ExprDependence::Error);
769
287k
  return D;
770
287k
}
771
772
1.20M
ExprDependence clang::computeDependence(CXXDependentScopeMemberExpr *E) {
773
1.20M
  auto D = ExprDependence::TypeValueInstantiation;
774
1.20M
  if (!E->isImplicitAccess())
775
1.02M
    D |= E->getBase()->getDependence();
776
1.20M
  if (auto *Q = E->getQualifier())
777
183k
    D |= toExprDependence(Q->getDependence());
778
1.20M
  D |= getDependenceInExpr(E->getMemberNameInfo());
779
1.20M
  for (auto A : E->template_arguments())
780
2.61k
    D |= toExprDependence(A.getArgument().getDependence());
781
1.20M
  return D;
782
1.20M
}
783
784
2.03M
ExprDependence clang::computeDependence(MaterializeTemporaryExpr *E) {
785
2.03M
  return E->getSubExpr()->getDependence();
786
2.03M
}
787
788
274
ExprDependence clang::computeDependence(CXXFoldExpr *E) {
789
274
  auto D = ExprDependence::TypeValueInstantiation;
790
548
  for (const auto *C : {E->getLHS(), E->getRHS()}) {
791
548
    if (C)
792
368
      D |= C->getDependence() & ~ExprDependence::UnexpandedPack;
793
548
  }
794
274
  return D;
795
274
}
796
797
231k
ExprDependence clang::computeDependence(TypeTraitExpr *E) {
798
231k
  auto D = ExprDependence::None;
799
231k
  for (const auto *A : E->getArgs())
800
458k
    D |=
801
458k
        toExprDependence(A->getType()->getDependence()) & ~ExprDependence::Type;
802
231k
  return D;
803
231k
}
804
805
ExprDependence clang::computeDependence(ConceptSpecializationExpr *E,
806
921
                                        bool ValueDependent) {
807
921
  auto TA = TemplateArgumentDependence::None;
808
921
  const auto InterestingDeps = TemplateArgumentDependence::Instantiation |
809
921
                               TemplateArgumentDependence::UnexpandedPack;
810
921
  for (const TemplateArgumentLoc &ArgLoc :
811
1.29k
       E->getTemplateArgsAsWritten()->arguments()) {
812
1.29k
    TA |= ArgLoc.getArgument().getDependence() & InterestingDeps;
813
1.29k
    if (TA == InterestingDeps)
814
46
      break;
815
1.29k
  }
816
817
921
  ExprDependence D =
818
921
      ValueDependent ? 
ExprDependence::Value382
:
ExprDependence::None539
;
819
921
  return D | toExprDependence(TA);
820
921
}
821
822
282
ExprDependence clang::computeDependence(ObjCArrayLiteral *E) {
823
282
  auto D = ExprDependence::None;
824
282
  Expr **Elements = E->getElements();
825
746
  for (unsigned I = 0, N = E->getNumElements(); I != N; 
++I464
)
826
464
    D |= turnTypeToValueDependence(Elements[I]->getDependence());
827
282
  return D;
828
282
}
829
830
210
ExprDependence clang::computeDependence(ObjCDictionaryLiteral *E) {
831
210
  auto Deps = ExprDependence::None;
832
531
  for (unsigned I = 0, N = E->getNumElements(); I < N; 
++I321
) {
833
321
    auto KV = E->getKeyValueElement(I);
834
321
    auto KVDeps = turnTypeToValueDependence(KV.Key->getDependence() |
835
321
                                            KV.Value->getDependence());
836
321
    if (KV.EllipsisLoc.isValid())
837
6
      KVDeps &= ~ExprDependence::UnexpandedPack;
838
321
    Deps |= KVDeps;
839
321
  }
840
210
  return Deps;
841
210
}
842
843
25.3k
ExprDependence clang::computeDependence(ObjCMessageExpr *E) {
844
25.3k
  auto D = ExprDependence::None;
845
25.3k
  if (auto *R = E->getInstanceReceiver())
846
16.5k
    D |= R->getDependence();
847
8.83k
  else
848
8.83k
    D |= toExprDependence(E->getType()->getDependence());
849
25.3k
  for (auto *A : E->arguments())
850
18.8k
    D |= A->getDependence();
851
25.3k
  return D;
852
25.3k
}