Coverage Report

Created: 2022-01-22 13:19

/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.90M
ExprDependence clang::computeDependence(FullExpr *E) {
25
5.90M
  return E->getSubExpr()->getDependence();
26
5.90M
}
27
28
720k
ExprDependence clang::computeDependence(OpaqueValueExpr *E) {
29
720k
  auto D = toExprDependence(E->getType()->getDependence());
30
720k
  if (auto *S = E->getSourceExpr())
31
8.50k
    D |= S->getDependence();
32
720k
  assert(!(D & ExprDependence::UnexpandedPack));
33
0
  return D;
34
720k
}
35
36
2.36M
ExprDependence clang::computeDependence(ParenExpr *E) {
37
2.36M
  return E->getSubExpr()->getDependence();
38
2.36M
}
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.83M
&&
56
2.72M
      
!(Dep & ExprDependence::Value)128k
) {
57
74.7k
    Expr::EvalResult Result;
58
74.7k
    SmallVector<PartialDiagnosticAt, 8> Diag;
59
74.7k
    Result.Diag = &Diag;
60
    // FIXME: This doesn't enforce the C++98 constant expression rules.
61
74.7k
    if (E->getSubExpr()->EvaluateAsConstantExpr(Result, Ctx) && 
Diag.empty()15.8k
&&
62
74.7k
        
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
74.7k
  }
71
72
2.72M
  return Dep;
73
2.72M
}
74
75
130k
ExprDependence clang::computeDependence(UnaryExprOrTypeTraitExpr *E) {
76
  // Never type-dependent (C++ [temp.dep.expr]p3).
77
  // Value-dependent if the argument is type-dependent.
78
130k
  if (E->isArgumentType())
79
111k
    return turnTypeToValueDependence(
80
111k
        toExprDependence(E->getArgumentType()->getDependence()));
81
82
18.6k
  auto ArgDeps = E->getArgumentExpr()->getDependence();
83
18.6k
  auto Deps = ArgDeps & ~ExprDependence::TypeValue;
84
  // Value-dependent if the argument is type-dependent.
85
18.6k
  if (ArgDeps & ExprDependence::Type)
86
7.73k
    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
18.6k
  auto ExprKind = E->getKind();
90
18.6k
  if (ExprKind != UETT_AlignOf && 
ExprKind != UETT_PreferredAlignOf18.5k
)
91
18.4k
    return Deps;
92
179
  if ((Deps & ExprDependence::Value) && 
(Deps & ExprDependence::Instantiation)11
)
93
11
    return Deps;
94
95
168
  auto *NoParens = E->getArgumentExpr()->IgnoreParens();
96
168
  const ValueDecl *D = nullptr;
97
168
  if (const auto *DRE = dyn_cast<DeclRefExpr>(NoParens))
98
105
    D = DRE->getDecl();
99
63
  else if (const auto *ME = dyn_cast<MemberExpr>(NoParens))
100
26
    D = ME->getMemberDecl();
101
168
  if (!D)
102
37
    return Deps;
103
131
  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
131
  return Deps;
110
168
}
111
112
332k
ExprDependence clang::computeDependence(ArraySubscriptExpr *E) {
113
332k
  return E->getLHS()->getDependence() | E->getRHS()->getDependence();
114
332k
}
115
116
202
ExprDependence clang::computeDependence(MatrixSubscriptExpr *E) {
117
202
  return E->getBase()->getDependence() | E->getRowIdx()->getDependence() |
118
202
         (E->getColumnIdx() ? 
E->getColumnIdx()->getDependence()76
119
202
                            : 
ExprDependence::None126
);
120
202
}
121
122
53.1k
ExprDependence clang::computeDependence(CompoundLiteralExpr *E) {
123
53.1k
  return toExprDependence(E->getTypeSourceInfo()->getType()->getDependence()) |
124
53.1k
         turnTypeToValueDependence(E->getInitializer()->getDependence());
125
53.1k
}
126
127
24.2M
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
24.2M
  auto D = toExprDependence(E->getType()->getDependence());
133
24.2M
  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.5M
    D &= ~ExprDependence::UnexpandedPack;
137
19.5M
  }
138
24.2M
  if (auto *S = E->getSubExpr())
139
24.2M
    D |= S->getDependence() & ~ExprDependence::Type;
140
24.2M
  return D;
141
24.2M
}
142
143
7.18M
ExprDependence clang::computeDependence(BinaryOperator *E) {
144
7.18M
  return E->getLHS()->getDependence() | E->getRHS()->getDependence();
145
7.18M
}
146
147
249k
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
249k
  return E->getCond()->getDependence() | E->getLHS()->getDependence() |
153
249k
         E->getRHS()->getDependence();
154
249k
}
155
156
277
ExprDependence clang::computeDependence(BinaryConditionalOperator *E) {
157
277
  return E->getCommon()->getDependence() | E->getFalseExpr()->getDependence();
158
277
}
159
160
8.94k
ExprDependence clang::computeDependence(StmtExpr *E, unsigned TemplateDepth) {
161
8.94k
  auto D = toExprDependence(E->getType()->getDependence());
162
  // Propagate dependence of the result.
163
8.94k
  if (const auto *CompoundExprResult =
164
8.94k
          dyn_cast_or_null<ValueStmt>(E->getSubStmt()->getStmtExprResult()))
165
7.73k
    if (const Expr *ResultExpr = CompoundExprResult->getExprStmt())
166
7.73k
      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.94k
  if (TemplateDepth)
171
20
    D |= ExprDependence::ValueInstantiation;
172
  // A param pack cannot be expanded over stmtexpr boundaries.
173
8.94k
  return D & ~ExprDependence::UnexpandedPack;
174
8.94k
}
175
176
19.7k
ExprDependence clang::computeDependence(ConvertVectorExpr *E) {
177
19.7k
  auto D = toExprDependence(E->getType()->getDependence()) |
178
19.7k
           E->getSrcExpr()->getDependence();
179
19.7k
  if (!E->getType()->isDependentType())
180
19.7k
    D &= ~ExprDependence::Type;
181
19.7k
  return D;
182
19.7k
}
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
729k
ExprDependence clang::computeDependence(ParenListExpr *P) {
202
729k
  auto D = ExprDependence::None;
203
729k
  for (auto *E : P->exprs())
204
900k
    D |= E->getDependence();
205
729k
  return D;
206
729k
}
207
208
1.07k
ExprDependence clang::computeDependence(VAArgExpr *E) {
209
1.07k
  auto D =
210
1.07k
      toExprDependence(E->getWrittenTypeInfo()->getType()->getDependence()) |
211
1.07k
      (E->getSubExpr()->getDependence() & ~ExprDependence::Type);
212
1.07k
  return D & ~ExprDependence::Value;
213
1.07k
}
214
215
52.6k
ExprDependence clang::computeDependence(NoInitExpr *E) {
216
52.6k
  return toExprDependence(E->getType()->getDependence()) &
217
52.6k
         (ExprDependence::Instantiation | ExprDependence::Error);
218
52.6k
}
219
220
1.03k
ExprDependence clang::computeDependence(ArrayInitLoopExpr *E) {
221
1.03k
  auto D = E->getCommonExpr()->getDependence() |
222
1.03k
           E->getSubExpr()->getDependence() | ExprDependence::Instantiation;
223
1.03k
  if (!E->getType()->isInstantiationDependentType())
224
1.03k
    D &= ~ExprDependence::Instantiation;
225
1.03k
  return turnTypeToValueDependence(D);
226
1.03k
}
227
228
83.5k
ExprDependence clang::computeDependence(ImplicitValueInitExpr *E) {
229
83.5k
  return toExprDependence(E->getType()->getDependence()) &
230
83.5k
         ExprDependence::Instantiation;
231
83.5k
}
232
233
495
ExprDependence clang::computeDependence(ExtVectorElementExpr *E) {
234
495
  return E->getBase()->getDependence();
235
495
}
236
237
3.00k
ExprDependence clang::computeDependence(BlockExpr *E) {
238
3.00k
  auto D = toExprDependence(E->getType()->getDependence());
239
3.00k
  if (E->getBlockDecl()->isDependentContext())
240
80
    D |= ExprDependence::Instantiation;
241
3.00k
  return D & ~ExprDependence::UnexpandedPack;
242
3.00k
}
243
244
39
ExprDependence clang::computeDependence(AsTypeExpr *E) {
245
39
  auto D = toExprDependence(E->getType()->getDependence()) |
246
39
           E->getSrcExpr()->getDependence();
247
39
  if (!E->getType()->isDependentType())
248
39
    D &= ~ExprDependence::Type;
249
39
  return D;
250
39
}
251
252
321
ExprDependence clang::computeDependence(CXXRewrittenBinaryOperator *E) {
253
321
  return E->getSemanticForm()->getDependence();
254
321
}
255
256
672
ExprDependence clang::computeDependence(CXXStdInitializerListExpr *E) {
257
672
  auto D = turnTypeToValueDependence(E->getSubExpr()->getDependence());
258
672
  D |= toExprDependence(E->getType()->getDependence()) &
259
672
       (ExprDependence::Type | ExprDependence::Error);
260
672
  return D;
261
672
}
262
263
5.88k
ExprDependence clang::computeDependence(CXXTypeidExpr *E) {
264
5.88k
  auto D = ExprDependence::None;
265
5.88k
  if (E->isTypeOperand())
266
5.55k
    D = toExprDependence(
267
5.55k
        E->getTypeOperandSourceInfo()->getType()->getDependence());
268
335
  else
269
335
    D = turnTypeToValueDependence(E->getExprOperand()->getDependence());
270
  // typeid is never type-dependent (C++ [temp.dep.expr]p4)
271
5.88k
  return D & ~ExprDependence::Type;
272
5.88k
}
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
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.31M
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.31M
  auto D = toExprDependence(E->getType()->getDependence());
294
1.31M
  assert(!(D & ExprDependence::UnexpandedPack));
295
0
  return D;
296
1.31M
}
297
298
14.9k
ExprDependence clang::computeDependence(CXXThrowExpr *E) {
299
14.9k
  auto *Op = E->getSubExpr();
300
14.9k
  if (!Op)
301
6.93k
    return ExprDependence::None;
302
8.05k
  return Op->getDependence() & ~ExprDependence::TypeValue;
303
14.9k
}
304
305
39.8k
ExprDependence clang::computeDependence(CXXBindTemporaryExpr *E) {
306
39.8k
  return E->getSubExpr()->getDependence();
307
39.8k
}
308
309
21.4k
ExprDependence clang::computeDependence(CXXScalarValueInitExpr *E) {
310
21.4k
  return toExprDependence(E->getType()->getDependence()) &
311
21.4k
         ~ExprDependence::TypeValue;
312
21.4k
}
313
314
7.77k
ExprDependence clang::computeDependence(CXXDeleteExpr *E) {
315
7.77k
  return turnTypeToValueDependence(E->getArgument()->getDependence());
316
7.77k
}
317
318
501
ExprDependence clang::computeDependence(ArrayTypeTraitExpr *E) {
319
501
  auto D = toExprDependence(E->getQueriedType()->getDependence());
320
501
  if (auto *Dim = E->getDimensionExpression())
321
490
    D |= Dim->getDependence();
322
501
  return turnTypeToValueDependence(D);
323
501
}
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
114k
ExprDependence clang::computeDependence(PackExpansionExpr *E) {
342
114k
  return (E->getPattern()->getDependence() & ~ExprDependence::UnexpandedPack) |
343
114k
         ExprDependence::TypeValueInstantiation;
344
114k
}
345
346
863k
ExprDependence clang::computeDependence(SubstNonTypeTemplateParmExpr *E) {
347
863k
  return E->getReplacement()->getDependence();
348
863k
}
349
350
2.78k
ExprDependence clang::computeDependence(CoroutineSuspendExpr *E) {
351
2.78k
  if (auto *Resume = E->getResumeExpr())
352
2.21k
    return (Resume->getDependence() &
353
2.21k
            (ExprDependence::TypeValue | ExprDependence::Error)) |
354
2.21k
           (E->getCommonExpr()->getDependence() & ~ExprDependence::TypeValue);
355
564
  return E->getCommonExpr()->getDependence() |
356
564
         ExprDependence::TypeValueInstantiation;
357
2.78k
}
358
359
111
ExprDependence clang::computeDependence(DependentCoawaitExpr *E) {
360
111
  return E->getOperand()->getDependence() |
361
111
         ExprDependence::TypeValueInstantiation;
362
111
}
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.39k
ExprDependence clang::computeDependence(ObjCIvarRefExpr *E) {
373
3.39k
  return turnTypeToValueDependence(E->getBase()->getDependence());
374
3.39k
}
375
376
4.60k
ExprDependence clang::computeDependence(ObjCPropertyRefExpr *E) {
377
4.60k
  if (E->isObjectReceiver())
378
4.33k
    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
71
ExprDependence clang::computeDependence(ObjCIndirectCopyRestoreExpr *E) {
396
71
  return E->getSubExpr()->getDependence();
397
71
}
398
399
14.7k
ExprDependence clang::computeDependence(OMPArraySectionExpr *E) {
400
14.7k
  auto D = E->getBase()->getDependence();
401
14.7k
  if (auto *LB = E->getLowerBound())
402
5.77k
    D |= LB->getDependence();
403
14.7k
  if (auto *Len = E->getLength())
404
11.6k
    D |= Len->getDependence();
405
14.7k
  return D;
406
14.7k
}
407
408
169
ExprDependence clang::computeDependence(OMPArrayShapingExpr *E) {
409
169
  auto D = E->getBase()->getDependence() |
410
169
           toExprDependence(E->getType()->getDependence());
411
169
  for (Expr *Dim: E->getDimensions())
412
385
    if (Dim)
413
385
      D |= Dim->getDependence();
414
169
  return D;
415
169
}
416
417
59
ExprDependence clang::computeDependence(OMPIteratorExpr *E) {
418
59
  auto D = toExprDependence(E->getType()->getDependence());
419
138
  for (unsigned I = 0, End = E->numOfIterators(); I < End; 
++I79
) {
420
79
    if (auto *VD = cast_or_null<ValueDecl>(E->getIteratorDecl(I)))
421
79
      D |= toExprDependence(VD->getType()->getDependence());
422
79
    OMPIteratorExpr::IteratorRange IR = E->getIteratorRange(I);
423
79
    if (Expr *BE = IR.Begin)
424
79
      D |= BE->getDependence();
425
79
    if (Expr *EE = IR.End)
426
79
      D |= EE->getDependence();
427
79
    if (Expr *SE = IR.Step)
428
28
      D |= SE->getDependence();
429
79
  }
430
59
  return D;
431
59
}
432
433
/// Compute the type-, value-, and instantiation-dependence of a
434
/// declaration reference
435
/// based on the declaration being referenced.
436
22.7M
ExprDependence clang::computeDependence(DeclRefExpr *E, const ASTContext &Ctx) {
437
22.7M
  auto Deps = ExprDependence::None;
438
439
22.7M
  if (auto *NNS = E->getQualifier())
440
2.57M
    Deps |= toExprDependence(NNS->getDependence() &
441
2.57M
                             ~NestedNameSpecifierDependence::Dependent);
442
443
22.7M
  if (auto *FirstArg = E->getTemplateArgs()) {
444
150k
    unsigned NumArgs = E->getNumTemplateArgs();
445
335k
    for (auto *Arg = FirstArg, *End = FirstArg + NumArgs; Arg < End; 
++Arg184k
)
446
184k
      Deps |= toExprDependence(Arg->getArgument().getDependence());
447
150k
  }
448
449
22.7M
  auto *Decl = E->getDecl();
450
22.7M
  auto Type = E->getType();
451
452
22.7M
  if (Decl->isParameterPack())
453
87.2k
    Deps |= ExprDependence::UnexpandedPack;
454
22.7M
  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
22.7M
  if (Type->isDependentType())
466
4.16M
    return Deps | ExprDependence::TypeValueInstantiation;
467
18.5M
  else if (Type->isInstantiationDependentType())
468
465
    Deps |= ExprDependence::Instantiation;
469
470
  //    - a conversion-function-id that specifies a dependent type
471
18.5M
  if (Decl->getDeclName().getNameKind() ==
472
18.5M
      DeclarationName::CXXConversionFunctionName) {
473
525k
    QualType T = Decl->getDeclName().getCXXNameType();
474
525k
    if (T->isDependentType())
475
0
      return Deps | ExprDependence::TypeValueInstantiation;
476
477
525k
    if (T->isInstantiationDependentType())
478
0
      Deps |= ExprDependence::Instantiation;
479
525k
  }
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
18.5M
  if (isa<NonTypeTemplateParmDecl>(Decl))
497
482k
    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.1M
  if (const auto *Var = dyn_cast<VarDecl>(Decl)) {
502
13.7M
    if (Var->mightBeUsableInConstantExpressions(Ctx)) {
503
3.11M
      if (const Expr *Init = Var->getAnyInitializer()) {
504
3.04M
        if (Init->isValueDependent())
505
102k
          Deps |= ExprDependence::ValueInstantiation;
506
3.04M
        if (Init->containsErrors())
507
53
          Deps |= ExprDependence::Error;
508
3.04M
      }
509
3.11M
    }
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.7M
    if (Var->isStaticDataMember() &&
514
13.7M
        
Var->getDeclContext()->isDependentContext()2.85M
&&
515
13.7M
        
!Var->getFirstDecl()->hasInit()88.2k
) {
516
212
      const VarDecl *First = Var->getFirstDecl();
517
212
      TypeSourceInfo *TInfo = First->getTypeSourceInfo();
518
212
      if (TInfo->getType()->isIncompleteArrayType()) {
519
24
        Deps |= ExprDependence::TypeValueInstantiation;
520
188
      } else if (!First->hasInit()) {
521
188
        Deps |= ExprDependence::ValueInstantiation;
522
188
      }
523
212
    }
524
525
13.7M
    return Deps;
526
13.7M
  }
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.35M
  if (auto *MD = dyn_cast<CXXMethodDecl>(Decl)) {
536
726k
    if (MD->isStatic() && 
Decl->getDeclContext()->isDependentContext()117k
)
537
1.49k
      Deps |= ExprDependence::ValueInstantiation;
538
726k
  }
539
540
4.35M
  return Deps;
541
18.1M
}
542
543
19.8k
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
19.8k
  auto D = toExprDependence(E->getType()->getDependence()) |
551
19.8k
           ExprDependence::ErrorDependent;
552
  // FIXME: remove the type-dependent bit from subexpressions, if the
553
  // RecoveryExpr has a non-dependent type.
554
19.8k
  for (auto *S : E->subExpressions())
555
36.3k
    D |= S->getDependence();
556
19.8k
  return D;
557
19.8k
}
558
559
84
ExprDependence clang::computeDependence(SYCLUniqueStableNameExpr *E) {
560
84
  return toExprDependence(E->getTypeSourceInfo()->getType()->getDependence());
561
84
}
562
563
896
ExprDependence clang::computeDependence(PredefinedExpr *E) {
564
896
  return toExprDependence(E->getType()->getDependence()) &
565
896
         ~ExprDependence::UnexpandedPack;
566
896
}
567
568
ExprDependence clang::computeDependence(CallExpr *E,
569
10.4M
                                        llvm::ArrayRef<Expr *> PreArgs) {
570
10.4M
  auto D = E->getCallee()->getDependence();
571
16.8M
  for (auto *A : llvm::makeArrayRef(E->getArgs(), E->getNumArgs())) {
572
16.8M
    if (A)
573
16.8M
      D |= A->getDependence();
574
16.8M
  }
575
10.4M
  for (auto *A : PreArgs)
576
325
    D |= A->getDependence();
577
10.4M
  return D;
578
10.4M
}
579
580
339
ExprDependence clang::computeDependence(OffsetOfExpr *E) {
581
339
  auto D = turnTypeToValueDependence(
582
339
      toExprDependence(E->getTypeSourceInfo()->getType()->getDependence()));
583
380
  for (unsigned I = 0, N = E->getNumExpressions(); I < N; 
++I41
)
584
41
    D |= turnTypeToValueDependence(E->getIndexExpr(I)->getDependence());
585
339
  return D;
586
339
}
587
588
1.40M
ExprDependence clang::computeDependence(MemberExpr *E) {
589
1.40M
  auto *MemberDecl = E->getMemberDecl();
590
1.40M
  auto D = E->getBase()->getDependence();
591
1.40M
  if (FieldDecl *FD = dyn_cast<FieldDecl>(MemberDecl)) {
592
969k
    DeclContext *DC = MemberDecl->getDeclContext();
593
    // dyn_cast_or_null is used to handle objC variables which do not
594
    // have a declaration context.
595
969k
    CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(DC);
596
969k
    if (RD && 
RD->isDependentContext()851k
&&
RD->isCurrentInstantiation(DC)437k
) {
597
437k
      if (!E->getType()->isDependentType())
598
109k
        D &= ~ExprDependence::Type;
599
437k
    }
600
601
    // Bitfield with value-dependent width is type-dependent.
602
969k
    if (FD && FD->isBitField() && 
FD->getBitWidth()->isValueDependent()9.17k
) {
603
2
      D |= ExprDependence::Type;
604
2
    }
605
969k
  }
606
  // FIXME: move remaining dependence computation from MemberExpr::Create()
607
1.40M
  return D;
608
1.40M
}
609
610
234k
ExprDependence clang::computeDependence(InitListExpr *E) {
611
234k
  auto D = ExprDependence::None;
612
234k
  for (auto *A : E->inits())
613
413k
    D |= A->getDependence();
614
234k
  return D;
615
234k
}
616
617
149k
ExprDependence clang::computeDependence(ShuffleVectorExpr *E) {
618
149k
  auto D = toExprDependence(E->getType()->getDependence());
619
149k
  for (auto *C : llvm::makeArrayRef(E->getSubExprs(), E->getNumSubExprs()))
620
1.34M
    D |= C->getDependence();
621
149k
  return D;
622
149k
}
623
624
ExprDependence clang::computeDependence(GenericSelectionExpr *E,
625
200
                                        bool ContainsUnexpandedPack) {
626
200
  auto D = ContainsUnexpandedPack ? 
ExprDependence::UnexpandedPack1
627
200
                                  : 
ExprDependence::None199
;
628
200
  for (auto *AE : E->getAssocExprs())
629
449
    D |= AE->getDependence() & ExprDependence::Error;
630
200
  D |= E->getControllingExpr()->getDependence() & ExprDependence::Error;
631
632
200
  if (E->isResultDependent())
633
10
    return D | ExprDependence::TypeValueInstantiation;
634
190
  return D | (E->getResultExpr()->getDependence() &
635
190
              ~ExprDependence::UnexpandedPack);
636
200
}
637
638
2.17k
ExprDependence clang::computeDependence(DesignatedInitExpr *E) {
639
2.17k
  auto Deps = E->getInit()->getDependence();
640
2.51k
  for (auto D : E->designators()) {
641
2.51k
    auto DesignatorDeps = ExprDependence::None;
642
2.51k
    if (D.isArrayDesignator())
643
386
      DesignatorDeps |= E->getArrayIndex(D)->getDependence();
644
2.12k
    else if (D.isArrayRangeDesignator())
645
27
      DesignatorDeps |= E->getArrayRangeStart(D)->getDependence() |
646
27
                        E->getArrayRangeEnd(D)->getDependence();
647
2.51k
    Deps |= DesignatorDeps;
648
2.51k
    if (DesignatorDeps & ExprDependence::TypeValue)
649
10
      Deps |= ExprDependence::TypeValueInstantiation;
650
2.51k
  }
651
2.17k
  return Deps;
652
2.17k
}
653
654
5.14k
ExprDependence clang::computeDependence(PseudoObjectExpr *O) {
655
5.14k
  auto D = O->getSyntacticForm()->getDependence();
656
5.14k
  for (auto *E : O->semantics())
657
9.59k
    D |= E->getDependence();
658
5.14k
  return D;
659
5.14k
}
660
661
6.78k
ExprDependence clang::computeDependence(AtomicExpr *A) {
662
6.78k
  auto D = ExprDependence::None;
663
6.78k
  for (auto *E : llvm::makeArrayRef(A->getSubExprs(), A->getNumSubExprs()))
664
20.0k
    D |= E->getDependence();
665
6.78k
  return D;
666
6.78k
}
667
668
29.6k
ExprDependence clang::computeDependence(CXXNewExpr *E) {
669
29.6k
  auto D = toExprDependence(E->getType()->getDependence());
670
29.6k
  auto Size = E->getArraySize();
671
29.6k
  if (Size.hasValue() && 
*Size2.36k
)
672
2.35k
    D |= turnTypeToValueDependence((*Size)->getDependence());
673
29.6k
  if (auto *I = E->getInitializer())
674
26.8k
    D |= turnTypeToValueDependence(I->getDependence());
675
29.6k
  for (auto *A : E->placement_arguments())
676
21.0k
    D |= turnTypeToValueDependence(A->getDependence());
677
29.6k
  return D;
678
29.6k
}
679
680
7.23k
ExprDependence clang::computeDependence(CXXPseudoDestructorExpr *E) {
681
7.23k
  auto D = E->getBase()->getDependence();
682
7.23k
  if (!E->getDestroyedType().isNull())
683
7.23k
    D |= toExprDependence(E->getDestroyedType()->getDependence());
684
7.23k
  if (auto *ST = E->getScopeTypeInfo())
685
206
    D |= turnTypeToValueDependence(
686
206
        toExprDependence(ST->getType()->getDependence()));
687
7.23k
  if (auto *Q = E->getQualifier())
688
38
    D |= toExprDependence(Q->getDependence() &
689
38
                          ~NestedNameSpecifierDependence::Dependent);
690
7.23k
  return D;
691
7.23k
}
692
693
5.72M
static inline ExprDependence getDependenceInExpr(DeclarationNameInfo Name) {
694
5.72M
  auto D = ExprDependence::None;
695
5.72M
  if (Name.isInstantiationDependent())
696
16
    D |= ExprDependence::Instantiation;
697
5.72M
  if (Name.containsUnexpandedParameterPack())
698
0
    D |= ExprDependence::UnexpandedPack;
699
5.72M
  return D;
700
5.72M
}
701
702
ExprDependence
703
clang::computeDependence(OverloadExpr *E, bool KnownDependent,
704
                         bool KnownInstantiationDependent,
705
2.99M
                         bool KnownContainsUnexpandedParameterPack) {
706
2.99M
  auto Deps = ExprDependence::None;
707
2.99M
  if (KnownDependent)
708
156k
    Deps |= ExprDependence::TypeValue;
709
2.99M
  if (KnownInstantiationDependent)
710
156k
    Deps |= ExprDependence::Instantiation;
711
2.99M
  if (KnownContainsUnexpandedParameterPack)
712
0
    Deps |= ExprDependence::UnexpandedPack;
713
2.99M
  Deps |= getDependenceInExpr(E->getNameInfo());
714
2.99M
  if (auto *Q = E->getQualifier())
715
596k
    Deps |= toExprDependence(Q->getDependence() &
716
596k
                             ~NestedNameSpecifierDependence::Dependent);
717
15.6M
  for (auto *D : E->decls()) {
718
15.6M
    if (D->getDeclContext()->isDependentContext() ||
719
15.6M
        
isa<UnresolvedUsingValueDecl>(D)14.5M
)
720
1.15M
      Deps |= ExprDependence::TypeValueInstantiation;
721
15.6M
  }
722
  // If we have explicit template arguments, check for dependent
723
  // template arguments and whether they contain any unexpanded pack
724
  // expansions.
725
2.99M
  for (auto A : E->template_arguments())
726
578k
    Deps |= toExprDependence(A.getArgument().getDependence());
727
2.99M
  return Deps;
728
2.99M
}
729
730
1.51M
ExprDependence clang::computeDependence(DependentScopeDeclRefExpr *E) {
731
1.51M
  auto D = ExprDependence::TypeValue;
732
1.51M
  D |= getDependenceInExpr(E->getNameInfo());
733
1.51M
  if (auto *Q = E->getQualifier())
734
1.07M
    D |= toExprDependence(Q->getDependence());
735
1.51M
  for (auto A : E->template_arguments())
736
24.3k
    D |= toExprDependence(A.getArgument().getDependence());
737
1.51M
  return D;
738
1.51M
}
739
740
358k
ExprDependence clang::computeDependence(CXXConstructExpr *E) {
741
358k
  auto D = toExprDependence(E->getType()->getDependence());
742
358k
  for (auto *A : E->arguments())
743
248k
    D |= A->getDependence() & ~ExprDependence::Type;
744
358k
  return D;
745
358k
}
746
747
2.40k
ExprDependence clang::computeDependence(CXXDefaultInitExpr *E) {
748
2.40k
  return E->getExpr()->getDependence();
749
2.40k
}
750
751
29.9k
ExprDependence clang::computeDependence(CXXDefaultArgExpr *E) {
752
29.9k
  return E->getExpr()->getDependence();
753
29.9k
}
754
755
ExprDependence clang::computeDependence(LambdaExpr *E,
756
10.5k
                                        bool ContainsUnexpandedParameterPack) {
757
10.5k
  auto D = toExprDependence(E->getType()->getDependence());
758
10.5k
  if (ContainsUnexpandedParameterPack)
759
107
    D |= ExprDependence::UnexpandedPack;
760
10.5k
  return D;
761
10.5k
}
762
763
293k
ExprDependence clang::computeDependence(CXXUnresolvedConstructExpr *E) {
764
293k
  auto D = ExprDependence::ValueInstantiation;
765
293k
  D |= toExprDependence(E->getType()->getDependence());
766
293k
  for (auto *A : E->arguments())
767
220k
    D |= A->getDependence() &
768
220k
         (ExprDependence::UnexpandedPack | ExprDependence::Error);
769
293k
  return D;
770
293k
}
771
772
1.21M
ExprDependence clang::computeDependence(CXXDependentScopeMemberExpr *E) {
773
1.21M
  auto D = ExprDependence::TypeValueInstantiation;
774
1.21M
  if (!E->isImplicitAccess())
775
1.03M
    D |= E->getBase()->getDependence();
776
1.21M
  if (auto *Q = E->getQualifier())
777
174k
    D |= toExprDependence(Q->getDependence());
778
1.21M
  D |= getDependenceInExpr(E->getMemberNameInfo());
779
1.21M
  for (auto A : E->template_arguments())
780
2.70k
    D |= toExprDependence(A.getArgument().getDependence());
781
1.21M
  return D;
782
1.21M
}
783
784
2.06M
ExprDependence clang::computeDependence(MaterializeTemporaryExpr *E) {
785
2.06M
  return E->getSubExpr()->getDependence();
786
2.06M
}
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
246k
ExprDependence clang::computeDependence(TypeTraitExpr *E) {
798
246k
  auto D = ExprDependence::None;
799
246k
  for (const auto *A : E->getArgs())
800
478k
    D |=
801
478k
        toExprDependence(A->getType()->getDependence()) & ~ExprDependence::Type;
802
246k
  return D;
803
246k
}
804
805
ExprDependence clang::computeDependence(ConceptSpecializationExpr *E,
806
950
                                        bool ValueDependent) {
807
950
  auto TA = TemplateArgumentDependence::None;
808
950
  const auto InterestingDeps = TemplateArgumentDependence::Instantiation |
809
950
                               TemplateArgumentDependence::UnexpandedPack;
810
950
  for (const TemplateArgumentLoc &ArgLoc :
811
1.34k
       E->getTemplateArgsAsWritten()->arguments()) {
812
1.34k
    TA |= ArgLoc.getArgument().getDependence() & InterestingDeps;
813
1.34k
    if (TA == InterestingDeps)
814
46
      break;
815
1.34k
  }
816
817
950
  ExprDependence D =
818
950
      ValueDependent ? 
ExprDependence::Value400
:
ExprDependence::None550
;
819
950
  return D | toExprDependence(TA);
820
950
}
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.82k
  else
848
8.82k
    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
}