clang 22.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 UnsignedOrNone 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 Deps |= toExprDependence(E->getQualifier().getDependence() &
504 ~NestedNameSpecifierDependence::Dependent);
505
506 if (auto *FirstArg = E->getTemplateArgs()) {
507 unsigned NumArgs = E->getNumTemplateArgs();
508 for (auto *Arg = FirstArg, *End = FirstArg + NumArgs; Arg < End; ++Arg)
509 Deps |= toExprDependence(Arg->getArgument().getDependence());
510 }
511
512 auto *Decl = E->getDecl();
513 auto Type = E->getType();
514
515 if (Decl->isParameterPack())
516 Deps |= ExprDependence::UnexpandedPack;
518 ExprDependence::Error;
519
520 // C++ [temp.dep.expr]p3:
521 // An id-expression is type-dependent if it contains:
522
523 // - an identifier associated by name lookup with one or more declarations
524 // declared with a dependent type
525 // - an identifier associated by name lookup with an entity captured by
526 // copy ([expr.prim.lambda.capture])
527 // in a lambda-expression that has an explicit object parameter whose
528 // type is dependent ([dcl.fct]),
529 //
530 // [The "or more" case is not modeled as a DeclRefExpr. There are a bunch
531 // more bullets here that we handle by treating the declaration as having a
532 // dependent type if they involve a placeholder type that can't be deduced.]
533 if (Type->isDependentType())
534 Deps |= ExprDependence::TypeValueInstantiation;
536 Deps |= ExprDependence::Instantiation;
537
538 // - an identifier associated by name lookup with an entity captured by
539 // copy ([expr.prim.lambda.capture])
540 if (E->isCapturedByCopyInLambdaWithExplicitObjectParameter())
541 Deps |= ExprDependence::Type;
542
543 // - a conversion-function-id that specifies a dependent type
544 if (Decl->getDeclName().getNameKind() ==
546 QualType T = Decl->getDeclName().getCXXNameType();
547 if (T->isDependentType())
548 return Deps | ExprDependence::TypeValueInstantiation;
549
551 Deps |= ExprDependence::Instantiation;
552 }
553
554 // - a template-id that is dependent,
555 // - a nested-name-specifier or a qualified-id that names a member of an
556 // unknown specialization
557 // [These are not modeled as DeclRefExprs.]
558
559 // or if it names a dependent member of the current instantiation that is a
560 // static data member of type "array of unknown bound of T" for some T
561 // [handled below].
562
563 // C++ [temp.dep.constexpr]p2:
564 // An id-expression is value-dependent if:
565
566 // - it is type-dependent [handled above]
567
568 // - it is the name of a non-type template parameter,
569 if (isa<NonTypeTemplateParmDecl>(Decl))
570 return Deps | ExprDependence::ValueInstantiation;
571
572 // - it names a potentially-constant variable that is initialized with an
573 // expression that is value-dependent
574 if (const auto *Var = dyn_cast<VarDecl>(Decl)) {
575 if (const Expr *Init = Var->getAnyInitializer()) {
576 if (Init->containsErrors())
577 Deps |= ExprDependence::Error;
578
579 if (Var->mightBeUsableInConstantExpressions(Ctx) &&
580 Init->isValueDependent())
581 Deps |= ExprDependence::ValueInstantiation;
582 }
583
584 // - it names a static data member that is a dependent member of the
585 // current instantiation and is not initialized in a member-declarator,
586 if (Var->isStaticDataMember() &&
587 Var->getDeclContext()->isDependentContext() &&
588 !Var->getFirstDecl()->hasInit()) {
589 const VarDecl *First = Var->getFirstDecl();
590 TypeSourceInfo *TInfo = First->getTypeSourceInfo();
591 if (TInfo->getType()->isIncompleteArrayType()) {
592 Deps |= ExprDependence::TypeValueInstantiation;
593 } else if (!First->hasInit()) {
594 Deps |= ExprDependence::ValueInstantiation;
595 }
596 }
597
598 return Deps;
599 }
600
601 // - it names a static member function that is a dependent member of the
602 // current instantiation
603 //
604 // FIXME: It's unclear that the restriction to static members here has any
605 // effect: any use of a non-static member function name requires either
606 // forming a pointer-to-member or providing an object parameter, either of
607 // which makes the overall expression value-dependent.
608 if (auto *MD = dyn_cast<CXXMethodDecl>(Decl)) {
609 if (MD->isStatic() && Decl->getDeclContext()->isDependentContext())
610 Deps |= ExprDependence::ValueInstantiation;
611 }
612
613 return Deps;
614}
615
617 // RecoveryExpr is
618 // - always value-dependent, and therefore instantiation dependent
619 // - contains errors (ExprDependence::Error), by definition
620 // - type-dependent if we don't know the type (fallback to an opaque
621 // dependent type), or the type is known and dependent, or it has
622 // type-dependent subexpressions.
624 ExprDependence::ErrorDependent;
625 // FIXME: remove the type-dependent bit from subexpressions, if the
626 // RecoveryExpr has a non-dependent type.
627 for (auto *S : E->subExpressions())
628 D |= S->getDependence();
629 return D;
630}
631
634 E->getTypeSourceInfo()->getType()->getDependence());
635}
636
639}
640
642 auto D = E->getCallee()->getDependence();
643 if (E->getType()->isDependentType())
644 D |= ExprDependence::Type;
645 for (auto *A : ArrayRef(E->getArgs(), E->getNumArgs())) {
646 if (A)
647 D |= A->getDependence();
648 }
649 for (auto *A : PreArgs)
650 D |= A->getDependence();
651 return D;
652}
653
656 E->getTypeSourceInfo()->getType()->getDependence()));
657 for (unsigned I = 0, N = E->getNumExpressions(); I < N; ++I)
658 D |= turnTypeToValueDependence(E->getIndexExpr(I)->getDependence());
659 return D;
660}
661
663 auto D = ExprDependence::None;
664 if (Name.isInstantiationDependent())
665 D |= ExprDependence::Instantiation;
666 if (Name.containsUnexpandedParameterPack())
667 D |= ExprDependence::UnexpandedPack;
668 return D;
669}
670
672 auto D = E->getBase()->getDependence();
673 D |= getDependenceInExpr(E->getMemberNameInfo());
674
675 D |= toExprDependence(E->getQualifier().getDependence() &
676 ~NestedNameSpecifierDependence::Dependent);
677
678 for (const auto &A : E->template_arguments())
679 D |= toExprDependence(A.getArgument().getDependence());
680
681 auto *MemberDecl = E->getMemberDecl();
682 if (FieldDecl *FD = dyn_cast<FieldDecl>(MemberDecl)) {
683 DeclContext *DC = MemberDecl->getDeclContext();
684 // dyn_cast_or_null is used to handle objC variables which do not
685 // have a declaration context.
686 CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(DC);
687 if (RD && RD->isDependentContext() && RD->isCurrentInstantiation(DC)) {
688 if (!E->getType()->isDependentType())
690 }
691
692 // Bitfield with value-dependent width is type-dependent.
693 if (FD && FD->isBitField() && FD->getBitWidth()->isValueDependent()) {
694 D |= ExprDependence::Type;
695 }
696 }
697 return D;
698}
699
701 auto D = ExprDependence::None;
702 for (auto *A : E->inits())
703 D |= A->getDependence();
704 return D;
705}
706
709 for (auto *C : ArrayRef(E->getSubExprs(), E->getNumSubExprs()))
710 D |= C->getDependence();
711 return D;
712}
713
715 bool ContainsUnexpandedPack) {
716 auto D = ContainsUnexpandedPack ? ExprDependence::UnexpandedPack
717 : ExprDependence::None;
718 for (auto *AE : E->getAssocExprs())
719 D |= AE->getDependence() & ExprDependence::Error;
720
721 if (E->isExprPredicate())
722 D |= E->getControllingExpr()->getDependence() & ExprDependence::Error;
723 else
725 E->getControllingType()->getType()->getDependence());
726
727 if (E->isResultDependent())
728 return D | ExprDependence::TypeValueInstantiation;
729 return D | (E->getResultExpr()->getDependence() &
730 ~ExprDependence::UnexpandedPack);
731}
732
734 auto Deps = E->getInit()->getDependence();
735 for (const auto &D : E->designators()) {
736 auto DesignatorDeps = ExprDependence::None;
737 if (D.isArrayDesignator())
738 DesignatorDeps |= E->getArrayIndex(D)->getDependence();
739 else if (D.isArrayRangeDesignator())
740 DesignatorDeps |= E->getArrayRangeStart(D)->getDependence() |
741 E->getArrayRangeEnd(D)->getDependence();
742 Deps |= DesignatorDeps;
743 if (DesignatorDeps & ExprDependence::TypeValue)
744 Deps |= ExprDependence::TypeValueInstantiation;
745 }
746 return Deps;
747}
748
750 auto D = O->getSyntacticForm()->getDependence();
751 for (auto *E : O->semantics())
752 D |= E->getDependence();
753 return D;
754}
755
757 auto D = ExprDependence::None;
758 for (auto *E : ArrayRef(A->getSubExprs(), A->getNumSubExprs()))
759 D |= E->getDependence();
760 return D;
761}
762
765 E->getAllocatedTypeSourceInfo()->getType()->getDependence());
766 D |= toExprDependenceForImpliedType(E->getAllocatedType()->getDependence());
767 auto Size = E->getArraySize();
768 if (Size && *Size)
769 D |= turnTypeToValueDependence((*Size)->getDependence());
770 if (auto *I = E->getInitializer())
771 D |= turnTypeToValueDependence(I->getDependence());
772 for (auto *A : E->placement_arguments())
773 D |= turnTypeToValueDependence(A->getDependence());
774 return D;
775}
776
778 auto D = E->getBase()->getDependence();
779 if (auto *TSI = E->getDestroyedTypeInfo())
780 D |= toExprDependenceAsWritten(TSI->getType()->getDependence());
781 if (auto *ST = E->getScopeTypeInfo())
783 toExprDependenceAsWritten(ST->getType()->getDependence()));
784 D |= toExprDependence(E->getQualifier().getDependence() &
785 ~NestedNameSpecifierDependence::Dependent);
786 return D;
787}
788
791 bool KnownInstantiationDependent,
792 bool KnownContainsUnexpandedParameterPack) {
793 auto Deps = ExprDependence::None;
794 if (KnownDependent)
795 Deps |= ExprDependence::TypeValue;
796 if (KnownInstantiationDependent)
797 Deps |= ExprDependence::Instantiation;
798 if (KnownContainsUnexpandedParameterPack)
799 Deps |= ExprDependence::UnexpandedPack;
800 Deps |= getDependenceInExpr(E->getNameInfo());
801 Deps |= toExprDependence(E->getQualifier().getDependence() &
802 ~NestedNameSpecifierDependence::Dependent);
803 for (auto *D : E->decls()) {
805 isa<UnresolvedUsingValueDecl>(D) || isa<TemplateTemplateParmDecl>(D))
806 Deps |= ExprDependence::TypeValueInstantiation;
807 }
808 // If we have explicit template arguments, check for dependent
809 // template arguments and whether they contain any unexpanded pack
810 // expansions.
811 for (const auto &A : E->template_arguments())
812 Deps |= toExprDependence(A.getArgument().getDependence());
813 return Deps;
814}
815
817 auto D = ExprDependence::TypeValue;
818 D |= getDependenceInExpr(E->getNameInfo());
819 D |= toExprDependence(E->getQualifier().getDependence());
820 for (const auto &A : E->template_arguments())
821 D |= toExprDependence(A.getArgument().getDependence());
822 return D;
823}
824
828 for (auto *A : E->arguments())
829 D |= A->getDependence() & ~ExprDependence::Type;
830 return D;
831}
832
834 CXXConstructExpr *BaseE = E;
836 E->getTypeSourceInfo()->getType()->getDependence()) |
837 computeDependence(BaseE);
838}
839
841 return E->getExpr()->getDependence();
842}
843
845 return E->getExpr()->getDependence();
846}
847
849 bool ContainsUnexpandedParameterPack) {
851 if (ContainsUnexpandedParameterPack)
852 D |= ExprDependence::UnexpandedPack;
853 return D;
854}
855
857 auto D = ExprDependence::ValueInstantiation;
858 D |= toExprDependenceAsWritten(E->getTypeAsWritten()->getDependence());
860 for (auto *A : E->arguments())
861 D |= A->getDependence() &
862 (ExprDependence::UnexpandedPack | ExprDependence::Error);
863 return D;
864}
865
867 auto D = ExprDependence::TypeValueInstantiation;
868 if (!E->isImplicitAccess())
869 D |= E->getBase()->getDependence();
870 D |= toExprDependence(E->getQualifier().getDependence());
871 D |= getDependenceInExpr(E->getMemberNameInfo());
872 for (const auto &A : E->template_arguments())
873 D |= toExprDependence(A.getArgument().getDependence());
874 return D;
875}
876
878 return E->getSubExpr()->getDependence();
879}
880
882 auto D = ExprDependence::TypeValueInstantiation;
883 for (const auto *C : {E->getLHS(), E->getRHS()}) {
884 if (C)
885 D |= C->getDependence() & ~ExprDependence::UnexpandedPack;
886 }
887 return D;
888}
889
891 auto D = ExprDependence::None;
892 for (const auto *A : E->getInitExprs())
893 D |= A->getDependence();
894 return D;
895}
896
898 auto D = ExprDependence::None;
899 for (const auto *A : E->getArgs())
900 D |= toExprDependenceAsWritten(A->getType()->getDependence()) &
902 return D;
903}
904
906 bool ValueDependent) {
907 auto TA = TemplateArgumentDependence::None;
908 const auto InterestingDeps = TemplateArgumentDependence::Instantiation |
909 TemplateArgumentDependence::UnexpandedPack;
910 for (const TemplateArgumentLoc &ArgLoc :
911 E->getTemplateArgsAsWritten()->arguments()) {
912 TA |= ArgLoc.getArgument().getDependence() & InterestingDeps;
913 if (TA == InterestingDeps)
914 break;
915 }
916
918 ValueDependent ? ExprDependence::Value : ExprDependence::None;
919 auto Res = D | toExprDependence(TA);
920 if(!ValueDependent && E->getSatisfaction().ContainsErrors)
921 Res |= ExprDependence::Error;
922 return Res;
923}
924
926 auto D = ExprDependence::None;
927 Expr **Elements = E->getElements();
928 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I)
929 D |= turnTypeToValueDependence(Elements[I]->getDependence());
930 return D;
931}
932
934 auto Deps = ExprDependence::None;
935 for (unsigned I = 0, N = E->getNumElements(); I < N; ++I) {
936 auto KV = E->getKeyValueElement(I);
937 auto KVDeps = turnTypeToValueDependence(KV.Key->getDependence() |
938 KV.Value->getDependence());
939 if (KV.EllipsisLoc.isValid())
940 KVDeps &= ~ExprDependence::UnexpandedPack;
941 Deps |= KVDeps;
942 }
943 return Deps;
944}
945
947 auto D = ExprDependence::None;
948 if (auto *R = E->getInstanceReceiver())
949 D |= R->getDependence();
950 else
952 for (auto *A : E->arguments())
953 D |= A->getDependence();
954 return D;
955}
956
958 // This represents a simple asterisk as typed, so cannot be dependent in any
959 // way.
960 return ExprDependence::None;
961}
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:894
Represents a loop initializing the elements of an array.
Definition: Expr.h:5904
This class represents BOTH the OpenMP Array Section and OpenACC 'subarray', with a boolean differenti...
Definition: Expr.h:7092
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition: Expr.h:2723
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
Definition: ExprCXX.h:2990
AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2] This AST node provides support ...
Definition: Expr.h:6621
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition: Expr.h:6816
Expr ** getSubExprs()
Definition: Expr.h:6891
static unsigned getNumSubExprs(AtomicOp Op)
Determine the number of arguments the specified atomic builtin should have.
Definition: Expr.cpp:5112
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Definition: Expr.h:4389
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3974
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition: Expr.h:6560
Represents binding an expression to a temporary.
Definition: ExprCXX.h:1494
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1549
A default argument (C++ [dcl.fct.default]).
Definition: ExprCXX.h:1271
A use of a default initializer in a constructor or in aggregate initialization.
Definition: ExprCXX.h:1378
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition: ExprCXX.h:2620
Represents a C++ member access expression where the actual member referenced could not be resolved be...
Definition: ExprCXX.h:3864
Represents a folding of a pack over an operator.
Definition: ExprCXX.h:5026
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition: ExprCXX.h:2349
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
Definition: ExprCXX.h:4303
Represents a list-initialization with parenthesis.
Definition: ExprCXX.h:5135
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Definition: ExprCXX.h:2739
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:286
An expression "T()" which creates an rvalue of a non-class type T.
Definition: ExprCXX.h:2198
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Definition: ExprCXX.h:800
Represents a C++ functional cast expression that builds a temporary object.
Definition: ExprCXX.h:1901
Represents the this expression in C++.
Definition: ExprCXX.h:1155
A C++ throw-expression (C++ [except.throw]).
Definition: ExprCXX.h:1209
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
Definition: ExprCXX.h:848
Describes an explicit type conversion that uses functional notion but could not be resolved because o...
Definition: ExprCXX.h:3738
A Microsoft C++ __uuidof expression, which gets the _GUID that corresponds to the supplied type or ex...
Definition: ExprCXX.h:1069
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2879
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Definition: Expr.h:4784
CompoundLiteralExpr - [C99 6.5.2.5].
Definition: Expr.h:3541
Represents the specialization of a concept - evaluates to a prvalue of type bool.
Definition: ExprConcepts.h:42
ConditionalOperator - The ?: ternary operator.
Definition: Expr.h:4327
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Definition: Expr.h:4655
Represents an expression that might suspend coroutine execution; either a co_await or co_yield expres...
Definition: ExprCXX.h:5249
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1449
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Definition: DeclBase.cpp:1358
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1272
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:244
llvm::iterator_range< specific_attr_iterator< T > > specific_attrs() const
Definition: DeclBase.h:559
DeclContext * getDeclContext()
Definition: DeclBase.h:448
Represents a 'co_await' expression while the type of the promise is dependent.
Definition: ExprCXX.h:5395
A qualified reference to a name whose declaration cannot yet be resolved.
Definition: ExprCXX.h:3504
Represents a C99 designated initializer expression.
Definition: Expr.h:5487
ExplicitCastExpr - An explicit cast written in the source code.
Definition: Expr.h:3864
This represents one expression.
Definition: Expr.h:112
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition: Expr.h:194
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
Definition: Expr.cpp:3069
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:223
QualType getType() const
Definition: Expr.h:144
ExprDependence getDependence() const
Definition: Expr.h:164
An expression trait intrinsic.
Definition: ExprCXX.h:3063
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
Definition: Expr.h:6500
Represents a member of a struct/union/class.
Definition: Decl.h:3157
FullExpr - Represents a "full-expression" node.
Definition: Expr.h:1051
Represents a C11 generic selection.
Definition: Expr.h:6114
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:3789
Represents an implicitly-generated value initialization of an object of a given type.
Definition: Expr.h:5993
Describes an C or C++ initializer list.
Definition: Expr.h:5235
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition: ExprCXX.h:1970
A member reference to an MSPropertyDecl.
Definition: ExprCXX.h:936
MS property subscript expression.
Definition: ExprCXX.h:1007
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition: ExprCXX.h:4914
MatrixSubscriptExpr - Matrix subscript expression for the MatrixType extension.
Definition: Expr.h:2801
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:3300
Represents a place-holder for an object not to be initialized by anything.
Definition: Expr.h:5813
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:192
ObjCBoxedExpr - used for generalized expression boxing.
Definition: ExprObjC.h:128
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
Definition: ExprObjC.h:308
ObjCEncodeExpr, used for @encode in Objective-C.
Definition: ExprObjC.h:409
ObjCIndirectCopyRestoreExpr - Represents the passing of a function argument by indirect copy-restore ...
Definition: ExprObjC.h:1582
ObjCIsaExpr - Represent X->isa and X.isa when X is an ObjC 'id' type.
Definition: ExprObjC.h:1498
ObjCIvarRefExpr - A reference to an ObjC instance variable.
Definition: ExprObjC.h:548
An expression that sends a message to the given Objective-C object or class.
Definition: ExprObjC.h:940
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
Definition: ExprObjC.h:616
ObjCSubscriptRefExpr - used for array and dictionary subscripting.
Definition: ExprObjC.h:839
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Definition: Expr.h:2529
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition: Expr.h:1180
This expression type represents an asterisk in an OpenACC Size-Expr, used in the 'tile' and 'gang' cl...
Definition: Expr.h:2092
A reference to an overloaded function set, either an UnresolvedLookupExpr or an UnresolvedMemberExpr.
Definition: ExprCXX.h:3122
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition: ExprCXX.h:4357
ParenExpr - This represents a parenthesized expression, e.g.
Definition: Expr.h:2184
[C99 6.4.2.2] - A predefined identifier such as func.
Definition: Expr.h:2007
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition: Expr.h:6692
ArrayRef< Expr * > semantics()
Definition: Expr.h:6764
Expr * getSyntacticForm()
Return the syntactic form of this expression, i.e.
Definition: Expr.h:6729
A (possibly-)qualified type.
Definition: TypeBase.h:937
Frontend produces RecoveryExprs on semantic errors that prevent creating other well-formed expression...
Definition: Expr.h:7364
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
Definition: Expr.h:4579
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition: Expr.h:4531
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition: ExprCXX.h:4658
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:528
A container of type source information.
Definition: TypeBase.h:8314
QualType getType() const
Return the type wrapped by this type source info.
Definition: TypeBase.h:8325
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition: ExprCXX.h:2890
The base class of the type hierarchy.
Definition: TypeBase.h:1833
bool isIncompleteArrayType() const
Definition: TypeBase.h:8687
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
Definition: TypeBase.h:2808
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: TypeBase.h:2800
TypeDependence getDependence() const
Definition: TypeBase.h:2789
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition: Expr.h:2627
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition: Expr.h:2246
Represents a call to the builtin function __builtin_va_arg.
Definition: Expr.h:4893
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:711
const Expr * getExprStmt() const
Definition: Stmt.cpp:411
Represents a variable declaration or definition.
Definition: Decl.h:925
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:645
Iterator range representation begin:end[:step].
Definition: ExprOpenMP.h:154