clang 20.0.0git
ComputeDependence.cpp
Go to the documentation of this file.
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
10#include "clang/AST/Attr.h"
11#include "clang/AST/DeclCXX.h"
14#include "clang/AST/Expr.h"
15#include "clang/AST/ExprCXX.h"
17#include "clang/AST/ExprObjC.h"
20#include "llvm/ADT/ArrayRef.h"
21
22using namespace clang;
23
25 return E->getSubExpr()->getDependence();
26}
27
30 if (auto *S = E->getSourceExpr())
31 D |= S->getDependence();
32 assert(!(D & ExprDependence::UnexpandedPack));
33 return D;
34}
35
37 return E->getSubExpr()->getDependence();
38}
39
41 const ASTContext &Ctx) {
42 ExprDependence Dep =
43 // FIXME: Do we need to look at the type?
45 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 if (Ctx.getLangOpts().CPlusPlus && E->getOpcode() == UO_AddrOf &&
58 !(Dep & ExprDependence::Value)) {
59 Expr::EvalResult Result;
61 Result.Diag = &Diag;
62 // FIXME: This doesn't enforce the C++98 constant expression rules.
63 if (E->getSubExpr()->EvaluateAsConstantExpr(Result, Ctx) && Diag.empty() &&
64 Result.Val.isLValue()) {
65 auto *VD = Result.Val.getLValueBase().dyn_cast<const ValueDecl *>();
66 if (VD && VD->isTemplated()) {
67 auto *VarD = dyn_cast<VarDecl>(VD);
68 if (!VarD || !VarD->hasLocalStorage())
69 Dep |= ExprDependence::Value;
70 }
71 }
72 }
73
74 return Dep;
75}
76
78 // Never type-dependent (C++ [temp.dep.expr]p3).
79 // Value-dependent if the argument is type-dependent.
80 if (E->isArgumentType())
82 toExprDependenceAsWritten(E->getArgumentType()->getDependence()));
83
84 auto ArgDeps = E->getArgumentExpr()->getDependence();
85 auto Deps = ArgDeps & ~ExprDependence::TypeValue;
86 // Value-dependent if the argument is type-dependent.
87 if (ArgDeps & ExprDependence::Type)
88 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 auto ExprKind = E->getKind();
92 if (ExprKind != UETT_AlignOf && ExprKind != UETT_PreferredAlignOf)
93 return Deps;
94 if ((Deps & ExprDependence::Value) && (Deps & ExprDependence::Instantiation))
95 return Deps;
96
97 auto *NoParens = E->getArgumentExpr()->IgnoreParens();
98 const ValueDecl *D = nullptr;
99 if (const auto *DRE = dyn_cast<DeclRefExpr>(NoParens))
100 D = DRE->getDecl();
101 else if (const auto *ME = dyn_cast<MemberExpr>(NoParens))
102 D = ME->getMemberDecl();
103 if (!D)
104 return Deps;
105 for (const auto *I : D->specific_attrs<AlignedAttr>()) {
106 if (I->isAlignmentErrorDependent())
107 Deps |= ExprDependence::Error;
108 if (I->isAlignmentDependent())
109 Deps |= ExprDependence::ValueInstantiation;
110 }
111 return Deps;
112}
113
115 return E->getLHS()->getDependence() | E->getRHS()->getDependence();
116}
117
119 return E->getBase()->getDependence() | E->getRowIdx()->getDependence() |
120 (E->getColumnIdx() ? E->getColumnIdx()->getDependence()
121 : ExprDependence::None);
122}
123
126 E->getTypeSourceInfo()->getType()->getDependence()) |
128 turnTypeToValueDependence(E->getInitializer()->getDependence());
129}
130
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.
137 if (auto *S = E->getSubExpr())
138 D |= S->getDependence() & ~ExprDependence::Type;
139 return D;
140}
141
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.
153 cast<ExplicitCastExpr>(E)->getTypeAsWritten()->getDependence()) |
155 if (auto *S = E->getSubExpr())
156 D |= S->getDependence() & ~ExprDependence::Type;
157 return D;
158}
159
161 return E->getLHS()->getDependence() | E->getRHS()->getDependence();
162}
163
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 that this should be dependent on ALL sub
168 // expressions.
169 return E->getCond()->getDependence() | E->getLHS()->getDependence() |
170 E->getRHS()->getDependence();
171}
172
174 return E->getCommon()->getDependence() | E->getFalseExpr()->getDependence();
175}
176
179 // Propagate dependence of the result.
180 if (const auto *CompoundExprResult =
181 dyn_cast_or_null<ValueStmt>(E->getSubStmt()->getStmtExprResult()))
182 if (const Expr *ResultExpr = CompoundExprResult->getExprStmt())
183 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 if (TemplateDepth)
188 D |= ExprDependence::ValueInstantiation;
189 // A param pack cannot be expanded over stmtexpr boundaries.
190 return D & ~ExprDependence::UnexpandedPack;
191}
192
195 E->getTypeSourceInfo()->getType()->getDependence()) |
196 E->getSrcExpr()->getDependence();
197 if (!E->getType()->isDependentType())
199 return D;
200}
201
203 if (E->isConditionDependent())
204 return ExprDependence::TypeValueInstantiation |
205 E->getCond()->getDependence() | E->getLHS()->getDependence() |
206 E->getRHS()->getDependence();
207
208 auto Cond = E->getCond()->getDependence();
209 auto Active = E->getLHS()->getDependence();
210 auto Inactive = E->getRHS()->getDependence();
211 if (!E->isConditionTrue())
212 std::swap(Active, Inactive);
213 // Take type- and value- dependency from the active branch. Propagate all
214 // other flags from all branches.
215 return (Active & ExprDependence::TypeValue) |
216 ((Cond | Active | Inactive) & ~ExprDependence::TypeValue);
217}
218
220 auto D = ExprDependence::None;
221 for (auto *E : P->exprs())
222 D |= E->getDependence();
223 return D;
224}
225
228 E->getWrittenTypeInfo()->getType()->getDependence()) |
229 (E->getSubExpr()->getDependence() & ~ExprDependence::Type);
230 return D;
231}
232
235 (ExprDependence::Instantiation | ExprDependence::Error);
236}
237
239 auto D = E->getCommonExpr()->getDependence() |
240 E->getSubExpr()->getDependence() | ExprDependence::Instantiation;
242 D &= ~ExprDependence::Instantiation;
244}
245
248 ExprDependence::Instantiation;
249}
250
252 return E->getBase()->getDependence();
253}
254
256 bool ContainsUnexpandedParameterPack) {
258 if (E->getBlockDecl()->isDependentContext())
259 D |= ExprDependence::Instantiation;
260 if (ContainsUnexpandedParameterPack)
261 D |= ExprDependence::UnexpandedPack;
262 return D;
263}
264
266 // FIXME: AsTypeExpr doesn't store the type as written. Assume the expression
267 // type has identical sugar for now, so is a type-as-written.
269 E->getSrcExpr()->getDependence();
270 if (!E->getType()->isDependentType())
272 return D;
273}
274
276 return E->getSemanticForm()->getDependence();
277}
278
280 auto D = turnTypeToValueDependence(E->getSubExpr()->getDependence());
282 return D;
283}
284
286 auto D = ExprDependence::None;
287 if (E->isTypeOperand())
289 E->getTypeOperandSourceInfo()->getType()->getDependence());
290 else
291 D = turnTypeToValueDependence(E->getExprOperand()->getDependence());
292 // typeid is never type-dependent (C++ [temp.dep.expr]p4)
293 return D & ~ExprDependence::Type;
294}
295
297 return E->getBaseExpr()->getDependence() & ~ExprDependence::Type;
298}
299
301 return E->getIdx()->getDependence();
302}
303
305 if (E->isTypeOperand())
307 E->getTypeOperandSourceInfo()->getType()->getDependence()));
308
309 return turnTypeToValueDependence(E->getExprOperand()->getDependence());
310}
311
313 // 'this' is type-dependent if the class type of the enclosing
314 // member function is dependent (C++ [temp.dep.expr]p2)
316
317 // If a lambda with an explicit object parameter captures '*this', then
318 // 'this' now refers to the captured copy of lambda, and if the lambda
319 // is type-dependent, so is the object and thus 'this'.
320 //
321 // Note: The standard does not mention this case explicitly, but we need
322 // to do this so we can mark NSDM accesses as dependent.
323 if (E->isCapturedByCopyInLambdaWithExplicitObjectParameter())
324 D |= ExprDependence::Type;
325
326 assert(!(D & ExprDependence::UnexpandedPack));
327 return D;
328}
329
331 auto *Op = E->getSubExpr();
332 if (!Op)
333 return ExprDependence::None;
334 return Op->getDependence() & ~ExprDependence::TypeValue;
335}
336
338 return E->getSubExpr()->getDependence();
339}
340
343 if (auto *TSI = E->getTypeSourceInfo())
344 D |= toExprDependenceAsWritten(TSI->getType()->getDependence());
345 return D;
346}
347
349 return turnTypeToValueDependence(E->getArgument()->getDependence());
350}
351
353 auto D = toExprDependenceAsWritten(E->getQueriedType()->getDependence());
354 if (auto *Dim = E->getDimensionExpression())
355 D |= Dim->getDependence();
357}
358
360 // Never type-dependent.
361 auto D = E->getQueriedExpression()->getDependence() & ~ExprDependence::Type;
362 // Value-dependent if the argument is type-dependent.
363 if (E->getQueriedExpression()->isTypeDependent())
364 D |= ExprDependence::Value;
365 return D;
366}
367
369 auto D = E->getOperand()->getDependence() & ~ExprDependence::TypeValue;
370 if (CT == CT_Dependent)
371 D |= ExprDependence::ValueInstantiation;
372 return D;
373}
374
376 return (E->getPattern()->getDependence() & ~ExprDependence::UnexpandedPack) |
377 ExprDependence::TypeValueInstantiation;
378}
379
381
382 ExprDependence PatternDep = E->getPackIdExpression()->getDependence() &
383 ~ExprDependence::UnexpandedPack;
384
385 ExprDependence D = E->getIndexExpr()->getDependence();
386 if (D & ExprDependence::TypeValueInstantiation)
387 D |= E->getIndexExpr()->getDependence() | PatternDep |
388 ExprDependence::Instantiation;
389
390 ArrayRef<Expr *> Exprs = E->getExpressions();
391 if (Exprs.empty() || !E->isFullySubstituted())
392 D |= PatternDep | ExprDependence::Instantiation;
393 else if (!E->getIndexExpr()->isInstantiationDependent()) {
394 std::optional<unsigned> Index = E->getSelectedIndex();
395 assert(Index && *Index < Exprs.size() && "pack index out of bound");
396 D |= Exprs[*Index]->getDependence();
397 }
398 return D;
399}
400
402 return E->getReplacement()->getDependence();
403}
404
406 if (auto *Resume = E->getResumeExpr())
407 return (Resume->getDependence() &
408 (ExprDependence::TypeValue | ExprDependence::Error)) |
409 (E->getCommonExpr()->getDependence() & ~ExprDependence::TypeValue);
410 return E->getCommonExpr()->getDependence() |
411 ExprDependence::TypeValueInstantiation;
412}
413
415 return E->getOperand()->getDependence() |
416 ExprDependence::TypeValueInstantiation;
417}
418
420 return E->getSubExpr()->getDependence();
421}
422
424 return toExprDependenceAsWritten(E->getEncodedType()->getDependence());
425}
426
428 return turnTypeToValueDependence(E->getBase()->getDependence());
429}
430
432 if (E->isObjectReceiver())
433 return E->getBase()->getDependence() & ~ExprDependence::Type;
434 if (E->isSuperReceiver())
436 E->getSuperReceiverType()->getDependence()) &
437 ~ExprDependence::TypeValue;
438 assert(E->isClassReceiver());
439 return ExprDependence::None;
440}
441
443 return E->getBaseExpr()->getDependence() | E->getKeyExpr()->getDependence();
444}
445
447 return E->getBase()->getDependence() & ~ExprDependence::Type &
448 ~ExprDependence::UnexpandedPack;
449}
450
452 return E->getSubExpr()->getDependence();
453}
454
456 auto D = E->getBase()->getDependence();
457 if (auto *LB = E->getLowerBound())
458 D |= LB->getDependence();
459 if (auto *Len = E->getLength())
460 D |= Len->getDependence();
461
462 if (E->isOMPArraySection()) {
463 if (auto *Stride = E->getStride())
464 D |= Stride->getDependence();
465 }
466 return D;
467}
468
470 auto D = E->getBase()->getDependence();
471 for (Expr *Dim: E->getDimensions())
472 if (Dim)
473 D |= turnValueToTypeDependence(Dim->getDependence());
474 return D;
475}
476
479 for (unsigned I = 0, End = E->numOfIterators(); I < End; ++I) {
480 if (auto *DD = cast_or_null<DeclaratorDecl>(E->getIteratorDecl(I))) {
481 // If the type is omitted, it's 'int', and is not dependent in any way.
482 if (auto *TSI = DD->getTypeSourceInfo()) {
483 D |= toExprDependenceAsWritten(TSI->getType()->getDependence());
484 }
485 }
486 OMPIteratorExpr::IteratorRange IR = E->getIteratorRange(I);
487 if (Expr *BE = IR.Begin)
488 D |= BE->getDependence();
489 if (Expr *EE = IR.End)
490 D |= EE->getDependence();
491 if (Expr *SE = IR.Step)
492 D |= SE->getDependence();
493 }
494 return D;
495}
496
497/// Compute the type-, value-, and instantiation-dependence of a
498/// declaration reference
499/// based on the declaration being referenced.
501 auto Deps = ExprDependence::None;
502
503 if (auto *NNS = E->getQualifier())
504 Deps |= toExprDependence(NNS->getDependence() &
505 ~NestedNameSpecifierDependence::Dependent);
506
507 if (auto *FirstArg = E->getTemplateArgs()) {
508 unsigned NumArgs = E->getNumTemplateArgs();
509 for (auto *Arg = FirstArg, *End = FirstArg + NumArgs; Arg < End; ++Arg)
510 Deps |= toExprDependence(Arg->getArgument().getDependence());
511 }
512
513 auto *Decl = E->getDecl();
514 auto Type = E->getType();
515
516 if (Decl->isParameterPack())
517 Deps |= ExprDependence::UnexpandedPack;
519 ExprDependence::Error;
520
521 // C++ [temp.dep.expr]p3:
522 // An id-expression is type-dependent if it contains:
523
524 // - an identifier associated by name lookup with one or more declarations
525 // declared with a dependent type
526 // - an identifier associated by name lookup with an entity captured by
527 // copy ([expr.prim.lambda.capture])
528 // in a lambda-expression that has an explicit object parameter whose
529 // type is dependent ([dcl.fct]),
530 //
531 // [The "or more" case is not modeled as a DeclRefExpr. There are a bunch
532 // more bullets here that we handle by treating the declaration as having a
533 // dependent type if they involve a placeholder type that can't be deduced.]
534 if (Type->isDependentType())
535 Deps |= ExprDependence::TypeValueInstantiation;
537 Deps |= ExprDependence::Instantiation;
538
539 // - an identifier associated by name lookup with an entity captured by
540 // copy ([expr.prim.lambda.capture])
541 if (E->isCapturedByCopyInLambdaWithExplicitObjectParameter())
542 Deps |= ExprDependence::Type;
543
544 // - a conversion-function-id that specifies a dependent type
545 if (Decl->getDeclName().getNameKind() ==
547 QualType T = Decl->getDeclName().getCXXNameType();
548 if (T->isDependentType())
549 return Deps | ExprDependence::TypeValueInstantiation;
550
552 Deps |= ExprDependence::Instantiation;
553 }
554
555 // - a template-id that is dependent,
556 // - a nested-name-specifier or a qualified-id that names a member of an
557 // unknown specialization
558 // [These are not modeled as DeclRefExprs.]
559
560 // or if it names a dependent member of the current instantiation that is a
561 // static data member of type "array of unknown bound of T" for some T
562 // [handled below].
563
564 // C++ [temp.dep.constexpr]p2:
565 // An id-expression is value-dependent if:
566
567 // - it is type-dependent [handled above]
568
569 // - it is the name of a non-type template parameter,
570 if (isa<NonTypeTemplateParmDecl>(Decl))
571 return Deps | ExprDependence::ValueInstantiation;
572
573 // - it names a potentially-constant variable that is initialized with an
574 // expression that is value-dependent
575 if (const auto *Var = dyn_cast<VarDecl>(Decl)) {
576 if (const Expr *Init = Var->getAnyInitializer()) {
577 if (Init->containsErrors())
578 Deps |= ExprDependence::Error;
579
580 if (Var->mightBeUsableInConstantExpressions(Ctx) &&
581 Init->isValueDependent())
582 Deps |= ExprDependence::ValueInstantiation;
583 }
584
585 // - it names a static data member that is a dependent member of the
586 // current instantiation and is not initialized in a member-declarator,
587 if (Var->isStaticDataMember() &&
588 Var->getDeclContext()->isDependentContext() &&
589 !Var->getFirstDecl()->hasInit()) {
590 const VarDecl *First = Var->getFirstDecl();
591 TypeSourceInfo *TInfo = First->getTypeSourceInfo();
592 if (TInfo->getType()->isIncompleteArrayType()) {
593 Deps |= ExprDependence::TypeValueInstantiation;
594 } else if (!First->hasInit()) {
595 Deps |= ExprDependence::ValueInstantiation;
596 }
597 }
598
599 return Deps;
600 }
601
602 // - it names a static member function that is a dependent member of the
603 // current instantiation
604 //
605 // FIXME: It's unclear that the restriction to static members here has any
606 // effect: any use of a non-static member function name requires either
607 // forming a pointer-to-member or providing an object parameter, either of
608 // which makes the overall expression value-dependent.
609 if (auto *MD = dyn_cast<CXXMethodDecl>(Decl)) {
610 if (MD->isStatic() && Decl->getDeclContext()->isDependentContext())
611 Deps |= ExprDependence::ValueInstantiation;
612 }
613
614 return Deps;
615}
616
618 // RecoveryExpr is
619 // - always value-dependent, and therefore instantiation dependent
620 // - contains errors (ExprDependence::Error), by definition
621 // - type-dependent if we don't know the type (fallback to an opaque
622 // dependent type), or the type is known and dependent, or it has
623 // type-dependent subexpressions.
625 ExprDependence::ErrorDependent;
626 // FIXME: remove the type-dependent bit from subexpressions, if the
627 // RecoveryExpr has a non-dependent type.
628 for (auto *S : E->subExpressions())
629 D |= S->getDependence();
630 return D;
631}
632
635 E->getTypeSourceInfo()->getType()->getDependence());
636}
637
640}
641
643 llvm::ArrayRef<Expr *> PreArgs) {
644 auto D = E->getCallee()->getDependence();
645 if (E->getType()->isDependentType())
646 D |= ExprDependence::Type;
647 for (auto *A : llvm::ArrayRef(E->getArgs(), E->getNumArgs())) {
648 if (A)
649 D |= A->getDependence();
650 }
651 for (auto *A : PreArgs)
652 D |= A->getDependence();
653 return D;
654}
655
658 E->getTypeSourceInfo()->getType()->getDependence()));
659 for (unsigned I = 0, N = E->getNumExpressions(); I < N; ++I)
660 D |= turnTypeToValueDependence(E->getIndexExpr(I)->getDependence());
661 return D;
662}
663
665 auto D = ExprDependence::None;
666 if (Name.isInstantiationDependent())
667 D |= ExprDependence::Instantiation;
668 if (Name.containsUnexpandedParameterPack())
669 D |= ExprDependence::UnexpandedPack;
670 return D;
671}
672
674 auto D = E->getBase()->getDependence();
675 D |= getDependenceInExpr(E->getMemberNameInfo());
676
677 if (auto *NNS = E->getQualifier())
678 D |= toExprDependence(NNS->getDependence() &
679 ~NestedNameSpecifierDependence::Dependent);
680
681 for (const auto &A : E->template_arguments())
682 D |= toExprDependence(A.getArgument().getDependence());
683
684 auto *MemberDecl = E->getMemberDecl();
685 if (FieldDecl *FD = dyn_cast<FieldDecl>(MemberDecl)) {
686 DeclContext *DC = MemberDecl->getDeclContext();
687 // dyn_cast_or_null is used to handle objC variables which do not
688 // have a declaration context.
689 CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(DC);
690 if (RD && RD->isDependentContext() && RD->isCurrentInstantiation(DC)) {
691 if (!E->getType()->isDependentType())
693 }
694
695 // Bitfield with value-dependent width is type-dependent.
696 if (FD && FD->isBitField() && FD->getBitWidth()->isValueDependent()) {
697 D |= ExprDependence::Type;
698 }
699 }
700 return D;
701}
702
704 auto D = ExprDependence::None;
705 for (auto *A : E->inits())
706 D |= A->getDependence();
707 return D;
708}
709
712 for (auto *C : llvm::ArrayRef(E->getSubExprs(), E->getNumSubExprs()))
713 D |= C->getDependence();
714 return D;
715}
716
718 bool ContainsUnexpandedPack) {
719 auto D = ContainsUnexpandedPack ? ExprDependence::UnexpandedPack
720 : ExprDependence::None;
721 for (auto *AE : E->getAssocExprs())
722 D |= AE->getDependence() & ExprDependence::Error;
723
724 if (E->isExprPredicate())
725 D |= E->getControllingExpr()->getDependence() & ExprDependence::Error;
726 else
728 E->getControllingType()->getType()->getDependence());
729
730 if (E->isResultDependent())
731 return D | ExprDependence::TypeValueInstantiation;
732 return D | (E->getResultExpr()->getDependence() &
733 ~ExprDependence::UnexpandedPack);
734}
735
737 auto Deps = E->getInit()->getDependence();
738 for (const auto &D : E->designators()) {
739 auto DesignatorDeps = ExprDependence::None;
740 if (D.isArrayDesignator())
741 DesignatorDeps |= E->getArrayIndex(D)->getDependence();
742 else if (D.isArrayRangeDesignator())
743 DesignatorDeps |= E->getArrayRangeStart(D)->getDependence() |
744 E->getArrayRangeEnd(D)->getDependence();
745 Deps |= DesignatorDeps;
746 if (DesignatorDeps & ExprDependence::TypeValue)
747 Deps |= ExprDependence::TypeValueInstantiation;
748 }
749 return Deps;
750}
751
753 auto D = O->getSyntacticForm()->getDependence();
754 for (auto *E : O->semantics())
755 D |= E->getDependence();
756 return D;
757}
758
760 auto D = ExprDependence::None;
761 for (auto *E : llvm::ArrayRef(A->getSubExprs(), A->getNumSubExprs()))
762 D |= E->getDependence();
763 return D;
764}
765
768 E->getAllocatedTypeSourceInfo()->getType()->getDependence());
769 D |= toExprDependenceForImpliedType(E->getAllocatedType()->getDependence());
770 auto Size = E->getArraySize();
771 if (Size && *Size)
772 D |= turnTypeToValueDependence((*Size)->getDependence());
773 if (auto *I = E->getInitializer())
774 D |= turnTypeToValueDependence(I->getDependence());
775 for (auto *A : E->placement_arguments())
776 D |= turnTypeToValueDependence(A->getDependence());
777 return D;
778}
779
781 auto D = E->getBase()->getDependence();
782 if (auto *TSI = E->getDestroyedTypeInfo())
783 D |= toExprDependenceAsWritten(TSI->getType()->getDependence());
784 if (auto *ST = E->getScopeTypeInfo())
786 toExprDependenceAsWritten(ST->getType()->getDependence()));
787 if (auto *Q = E->getQualifier())
788 D |= toExprDependence(Q->getDependence() &
789 ~NestedNameSpecifierDependence::Dependent);
790 return D;
791}
792
795 bool KnownInstantiationDependent,
796 bool KnownContainsUnexpandedParameterPack) {
797 auto Deps = ExprDependence::None;
798 if (KnownDependent)
799 Deps |= ExprDependence::TypeValue;
800 if (KnownInstantiationDependent)
801 Deps |= ExprDependence::Instantiation;
802 if (KnownContainsUnexpandedParameterPack)
803 Deps |= ExprDependence::UnexpandedPack;
804 Deps |= getDependenceInExpr(E->getNameInfo());
805 if (auto *Q = E->getQualifier())
806 Deps |= toExprDependence(Q->getDependence() &
807 ~NestedNameSpecifierDependence::Dependent);
808 for (auto *D : E->decls()) {
810 isa<UnresolvedUsingValueDecl>(D))
811 Deps |= ExprDependence::TypeValueInstantiation;
812 }
813 // If we have explicit template arguments, check for dependent
814 // template arguments and whether they contain any unexpanded pack
815 // expansions.
816 for (const auto &A : E->template_arguments())
817 Deps |= toExprDependence(A.getArgument().getDependence());
818 return Deps;
819}
820
822 auto D = ExprDependence::TypeValue;
823 D |= getDependenceInExpr(E->getNameInfo());
824 if (auto *Q = E->getQualifier())
825 D |= toExprDependence(Q->getDependence());
826 for (const auto &A : E->template_arguments())
827 D |= toExprDependence(A.getArgument().getDependence());
828 return D;
829}
830
834 for (auto *A : E->arguments())
835 D |= A->getDependence() & ~ExprDependence::Type;
836 return D;
837}
838
840 CXXConstructExpr *BaseE = E;
842 E->getTypeSourceInfo()->getType()->getDependence()) |
843 computeDependence(BaseE);
844}
845
847 return E->getExpr()->getDependence();
848}
849
851 return E->getExpr()->getDependence();
852}
853
855 bool ContainsUnexpandedParameterPack) {
857 if (ContainsUnexpandedParameterPack)
858 D |= ExprDependence::UnexpandedPack;
859 return D;
860}
861
863 auto D = ExprDependence::ValueInstantiation;
864 D |= toExprDependenceAsWritten(E->getTypeAsWritten()->getDependence());
866 for (auto *A : E->arguments())
867 D |= A->getDependence() &
868 (ExprDependence::UnexpandedPack | ExprDependence::Error);
869 return D;
870}
871
873 auto D = ExprDependence::TypeValueInstantiation;
874 if (!E->isImplicitAccess())
875 D |= E->getBase()->getDependence();
876 if (auto *Q = E->getQualifier())
877 D |= toExprDependence(Q->getDependence());
878 D |= getDependenceInExpr(E->getMemberNameInfo());
879 for (const auto &A : E->template_arguments())
880 D |= toExprDependence(A.getArgument().getDependence());
881 return D;
882}
883
885 return E->getSubExpr()->getDependence();
886}
887
889 auto D = ExprDependence::TypeValueInstantiation;
890 for (const auto *C : {E->getLHS(), E->getRHS()}) {
891 if (C)
892 D |= C->getDependence() & ~ExprDependence::UnexpandedPack;
893 }
894 return D;
895}
896
898 auto D = ExprDependence::None;
899 for (const auto *A : E->getInitExprs())
900 D |= A->getDependence();
901 return D;
902}
903
905 auto D = ExprDependence::None;
906 for (const auto *A : E->getArgs())
907 D |= toExprDependenceAsWritten(A->getType()->getDependence()) &
909 return D;
910}
911
913 bool ValueDependent) {
914 auto TA = TemplateArgumentDependence::None;
915 const auto InterestingDeps = TemplateArgumentDependence::Instantiation |
916 TemplateArgumentDependence::UnexpandedPack;
917 for (const TemplateArgumentLoc &ArgLoc :
918 E->getTemplateArgsAsWritten()->arguments()) {
919 TA |= ArgLoc.getArgument().getDependence() & InterestingDeps;
920 if (TA == InterestingDeps)
921 break;
922 }
923
925 ValueDependent ? ExprDependence::Value : ExprDependence::None;
926 auto Res = D | toExprDependence(TA);
927 if(!ValueDependent && E->getSatisfaction().ContainsErrors)
928 Res |= ExprDependence::Error;
929 return Res;
930}
931
933 auto D = ExprDependence::None;
934 Expr **Elements = E->getElements();
935 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I)
936 D |= turnTypeToValueDependence(Elements[I]->getDependence());
937 return D;
938}
939
941 auto Deps = ExprDependence::None;
942 for (unsigned I = 0, N = E->getNumElements(); I < N; ++I) {
943 auto KV = E->getKeyValueElement(I);
944 auto KVDeps = turnTypeToValueDependence(KV.Key->getDependence() |
945 KV.Value->getDependence());
946 if (KV.EllipsisLoc.isValid())
947 KVDeps &= ~ExprDependence::UnexpandedPack;
948 Deps |= KVDeps;
949 }
950 return Deps;
951}
952
954 auto D = ExprDependence::None;
955 if (auto *R = E->getInstanceReceiver())
956 D |= R->getDependence();
957 else
959 for (auto *A : E->arguments())
960 D |= A->getDependence();
961 return D;
962}
963
965 // This represents a simple asterisk as typed, so cannot be dependent in any
966 // way.
967 return ExprDependence::None;
968}
StringRef P
const Decl * D
Expr * E
static ExprDependence getDependenceInExpr(DeclarationNameInfo Name)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the ExceptionSpecificationType enumeration and various utility functions.
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines Expressions and AST nodes for C++2a concepts.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:188
const LangOptions & getLangOpts() const
Definition: ASTContext.h:834
Represents a loop initializing the elements of an array.
Definition: Expr.h:5752
This class represents BOTH the OpenMP Array Section and OpenACC 'subarray', with a boolean differenti...
Definition: Expr.h:6986
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition: Expr.h:2718
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
Definition: ExprCXX.h:2853
AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2] This AST node provides support ...
Definition: Expr.h:6475
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition: Expr.h:6678
Expr ** getSubExprs()
Definition: Expr.h:6755
static unsigned getNumSubExprs(AtomicOp Op)
Determine the number of arguments the specified atomic builtin should have.
Definition: Expr.cpp:5067
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Definition: Expr.h:4324
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3909
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition: Expr.h:6414
Represents binding an expression to a temporary.
Definition: ExprCXX.h:1491
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1546
A default argument (C++ [dcl.fct.default]).
Definition: ExprCXX.h:1268
A use of a default initializer in a constructor or in aggregate initialization.
Definition: ExprCXX.h:1375
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition: ExprCXX.h:2498
Represents a C++ member access expression where the actual member referenced could not be resolved be...
Definition: ExprCXX.h:3683
Represents a folding of a pack over an operator.
Definition: ExprCXX.h:4846
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition: ExprCXX.h:2241
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
Definition: ExprCXX.h:4126
Represents a list-initialization with parenthesis.
Definition: ExprCXX.h:4960
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Definition: ExprCXX.h:2617
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
bool isCurrentInstantiation(const DeclContext *CurContext) const
Determine whether this dependent class is a current instantiation, when viewed from within the given ...
A rewritten comparison expression that was originally written using operator syntax.
Definition: ExprCXX.h:283
An expression "T()" which creates an rvalue of a non-class type T.
Definition: ExprCXX.h:2182
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Definition: ExprCXX.h:797
Represents a C++ functional cast expression that builds a temporary object.
Definition: ExprCXX.h:1885
Represents the this expression in C++.
Definition: ExprCXX.h:1152
A C++ throw-expression (C++ [except.throw]).
Definition: ExprCXX.h:1206
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
Definition: ExprCXX.h:845
Describes an explicit type conversion that uses functional notion but could not be resolved because o...
Definition: ExprCXX.h:3557
A Microsoft C++ __uuidof expression, which gets the _GUID that corresponds to the supplied type or ex...
Definition: ExprCXX.h:1066
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2874
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Definition: Expr.h:4641
CompoundLiteralExpr - [C99 6.5.2.5].
Definition: Expr.h:3477
Represents the specialization of a concept - evaluates to a prvalue of type bool.
Definition: ExprConcepts.h:42
ConditionalOperator - The ?: ternary operator.
Definition: Expr.h:4262
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Definition: Expr.h:4582
Represents an expression that might suspend coroutine execution; either a co_await or co_yield expres...
Definition: ExprCXX.h:5077
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1435
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Definition: DeclBase.cpp:1334
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1265
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
bool isParameterPack() const
Whether this declaration is a parameter pack.
Definition: DeclBase.cpp:239
llvm::iterator_range< specific_attr_iterator< T > > specific_attrs() const
Definition: DeclBase.h:562
DeclContext * getDeclContext()
Definition: DeclBase.h:451
Represents a 'co_await' expression while the type of the promise is dependent.
Definition: ExprCXX.h:5223
A qualified reference to a name whose declaration cannot yet be resolved.
Definition: ExprCXX.h:3323
Represents a C99 designated initializer expression.
Definition: Expr.h:5333
ExplicitCastExpr - An explicit cast written in the source code.
Definition: Expr.h:3799
This represents one expression.
Definition: Expr.h:110
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition: Expr.h:192
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
Definition: Expr.cpp:3086
bool EvaluateAsConstantExpr(EvalResult &Result, const ASTContext &Ctx, ConstantExprKind Kind=ConstantExprKind::Normal) const
Evaluate an expression that is required to be a constant expression.
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on.
Definition: Expr.h:221
QualType getType() const
Definition: Expr.h:142
ExprDependence getDependence() const
Definition: Expr.h:162
An expression trait intrinsic.
Definition: ExprCXX.h:2924
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
Definition: Expr.h:6354
Represents a member of a struct/union/class.
Definition: Decl.h:3033
FullExpr - Represents a "full-expression" node.
Definition: Expr.h:1044
Represents a C11 generic selection.
Definition: Expr.h:5966
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:3724
Represents an implicitly-generated value initialization of an object of a given type.
Definition: Expr.h:5841
Describes an C or C++ initializer list.
Definition: Expr.h:5088
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition: ExprCXX.h:1954
A member reference to an MSPropertyDecl.
Definition: ExprCXX.h:933
MS property subscript expression.
Definition: ExprCXX.h:1004
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition: ExprCXX.h:4734
MatrixSubscriptExpr - Matrix subscript expression for the MatrixType extension.
Definition: Expr.h:2796
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:3236
Represents a place-holder for an object not to be initialized by anything.
Definition: Expr.h:5661
An explicit cast in C or a C-style cast in C++, which uses the syntax ([s1][s2]......
Definition: ExprOpenMP.h:24
OpenMP 5.0 [2.1.6 Iterators] Iterators are identifiers that expand to multiple values in the clause o...
Definition: ExprOpenMP.h:151
ObjCArrayLiteral - used for objective-c array containers; as in: @["Hello", NSApp,...
Definition: ExprObjC.h:191
ObjCBoxedExpr - used for generalized expression boxing.
Definition: ExprObjC.h:127
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
Definition: ExprObjC.h:309
ObjCEncodeExpr, used for @encode in Objective-C.
Definition: ExprObjC.h:410
ObjCIndirectCopyRestoreExpr - Represents the passing of a function argument by indirect copy-restore ...
Definition: ExprObjC.h:1571
ObjCIsaExpr - Represent X->isa and X.isa when X is an ObjC 'id' type.
Definition: ExprObjC.h:1487
ObjCIvarRefExpr - A reference to an ObjC instance variable.
Definition: ExprObjC.h:549
An expression that sends a message to the given Objective-C object or class.
Definition: ExprObjC.h:941
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
Definition: ExprObjC.h:617
ObjCSubscriptRefExpr - used for array and dictionary subscripting.
Definition: ExprObjC.h:840
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Definition: Expr.h:2519
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition: Expr.h:1173
This expression type represents an asterisk in an OpenACC Size-Expr, used in the 'tile' and 'gang' cl...
Definition: Expr.h:2078
A reference to an overloaded function set, either an UnresolvedLookupExpr or an UnresolvedMemberExpr.
Definition: ExprCXX.h:2983
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition: ExprCXX.h:4180
ParenExpr - This represents a parenthesized expression, e.g.
Definition: Expr.h:2170
[C99 6.4.2.2] - A predefined identifier such as func.
Definition: Expr.h:1991
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition: Expr.h:6546
ArrayRef< Expr * > semantics()
Definition: Expr.h:6625
Expr * getSyntacticForm()
Return the syntactic form of this expression, i.e.
Definition: Expr.h:6588
A (possibly-)qualified type.
Definition: Type.h:929
Frontend produces RecoveryExprs on semantic errors that prevent creating other well-formed expression...
Definition: Expr.h:7258
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
Definition: Expr.h:4514
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition: Expr.h:4466
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition: ExprCXX.h:4490
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:524
A container of type source information.
Definition: Type.h:7902
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:7913
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition: ExprCXX.h:2768
The base class of the type hierarchy.
Definition: Type.h:1828
bool isIncompleteArrayType() const
Definition: Type.h:8266
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
Definition: Type.h:2714
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2706
TypeDependence getDependence() const
Definition: Type.h:2695
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition: Expr.h:2622
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition: Expr.h:2232
Represents a call to the builtin function __builtin_va_arg.
Definition: Expr.h:4750
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:671
const Expr * getExprStmt() const
Definition: Stmt.cpp:402
Represents a variable declaration or definition.
Definition: Decl.h:882
The JSON file list parser is used to communicate input to InstallAPI.
ExprDependence toExprDependence(TemplateArgumentDependence TA)
Computes dependencies of a reference with the name having template arguments with TA dependencies.
CanThrowResult
Possible results from evaluation of a noexcept expression.
ExprDependence turnTypeToValueDependence(ExprDependence D)
ExprDependence toExprDependenceAsWritten(TypeDependence D)
ExprDependence computeDependence(FullExpr *E)
ExprDependence turnValueToTypeDependence(ExprDependence D)
ExprDependence toExprDependenceForImpliedType(TypeDependence D)
const FunctionProtoType * T
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
EvalResult is a struct with detailed info about an evaluated expression.
Definition: Expr.h:642
Iterator range representation begin:end[:step].
Definition: ExprOpenMP.h:154