Coverage Report

Created: 2022-07-16 07:03

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