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 state 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
257 if (E->getBlockDecl()->isDependentContext())
258 D |= ExprDependence::Instantiation;
259 return D;
260}
261
263 // FIXME: AsTypeExpr doesn't store the type as written. Assume the expression
264 // type has identical sugar for now, so is a type-as-written.
266 E->getSrcExpr()->getDependence();
267 if (!E->getType()->isDependentType())
269 return D;
270}
271
273 return E->getSemanticForm()->getDependence();
274}
275
277 auto D = turnTypeToValueDependence(E->getSubExpr()->getDependence());
279 return D;
280}
281
283 auto D = ExprDependence::None;
284 if (E->isTypeOperand())
286 E->getTypeOperandSourceInfo()->getType()->getDependence());
287 else
288 D = turnTypeToValueDependence(E->getExprOperand()->getDependence());
289 // typeid is never type-dependent (C++ [temp.dep.expr]p4)
290 return D & ~ExprDependence::Type;
291}
292
294 return E->getBaseExpr()->getDependence() & ~ExprDependence::Type;
295}
296
298 return E->getIdx()->getDependence();
299}
300
302 if (E->isTypeOperand())
304 E->getTypeOperandSourceInfo()->getType()->getDependence()));
305
306 return turnTypeToValueDependence(E->getExprOperand()->getDependence());
307}
308
310 // 'this' is type-dependent if the class type of the enclosing
311 // member function is dependent (C++ [temp.dep.expr]p2)
313
314 // If a lambda with an explicit object parameter captures '*this', then
315 // 'this' now refers to the captured copy of lambda, and if the lambda
316 // is type-dependent, so is the object and thus 'this'.
317 //
318 // Note: The standard does not mention this case explicitly, but we need
319 // to do this so we can mark NSDM accesses as dependent.
320 if (E->isCapturedByCopyInLambdaWithExplicitObjectParameter())
321 D |= ExprDependence::Type;
322
323 assert(!(D & ExprDependence::UnexpandedPack));
324 return D;
325}
326
328 auto *Op = E->getSubExpr();
329 if (!Op)
330 return ExprDependence::None;
331 return Op->getDependence() & ~ExprDependence::TypeValue;
332}
333
335 return E->getSubExpr()->getDependence();
336}
337
340 if (auto *TSI = E->getTypeSourceInfo())
341 D |= toExprDependenceAsWritten(TSI->getType()->getDependence());
342 return D;
343}
344
346 return turnTypeToValueDependence(E->getArgument()->getDependence());
347}
348
350 auto D = toExprDependenceAsWritten(E->getQueriedType()->getDependence());
351 if (auto *Dim = E->getDimensionExpression())
352 D |= Dim->getDependence();
354}
355
357 // Never type-dependent.
358 auto D = E->getQueriedExpression()->getDependence() & ~ExprDependence::Type;
359 // Value-dependent if the argument is type-dependent.
360 if (E->getQueriedExpression()->isTypeDependent())
361 D |= ExprDependence::Value;
362 return D;
363}
364
366 auto D = E->getOperand()->getDependence() & ~ExprDependence::TypeValue;
367 if (CT == CT_Dependent)
368 D |= ExprDependence::ValueInstantiation;
369 return D;
370}
371
373 return (E->getPattern()->getDependence() & ~ExprDependence::UnexpandedPack) |
374 ExprDependence::TypeValueInstantiation;
375}
376
378
379 ExprDependence PatternDep = E->getPackIdExpression()->getDependence() &
380 ~ExprDependence::UnexpandedPack;
381
382 ExprDependence D = E->getIndexExpr()->getDependence();
383 if (D & ExprDependence::TypeValueInstantiation)
384 D |= E->getIndexExpr()->getDependence() | PatternDep |
385 ExprDependence::Instantiation;
386
387 ArrayRef<Expr *> Exprs = E->getExpressions();
388 if (Exprs.empty())
389 D |= PatternDep | ExprDependence::Instantiation;
390
391 else if (!E->getIndexExpr()->isInstantiationDependent()) {
392 std::optional<unsigned> Index = E->getSelectedIndex();
393 assert(Index && *Index < Exprs.size() && "pack index out of bound");
394 D |= Exprs[*Index]->getDependence();
395 }
396 return D;
397}
398
400 return E->getReplacement()->getDependence();
401}
402
404 if (auto *Resume = E->getResumeExpr())
405 return (Resume->getDependence() &
406 (ExprDependence::TypeValue | ExprDependence::Error)) |
407 (E->getCommonExpr()->getDependence() & ~ExprDependence::TypeValue);
408 return E->getCommonExpr()->getDependence() |
409 ExprDependence::TypeValueInstantiation;
410}
411
413 return E->getOperand()->getDependence() |
414 ExprDependence::TypeValueInstantiation;
415}
416
418 return E->getSubExpr()->getDependence();
419}
420
422 return toExprDependenceAsWritten(E->getEncodedType()->getDependence());
423}
424
426 return turnTypeToValueDependence(E->getBase()->getDependence());
427}
428
430 if (E->isObjectReceiver())
431 return E->getBase()->getDependence() & ~ExprDependence::Type;
432 if (E->isSuperReceiver())
434 E->getSuperReceiverType()->getDependence()) &
435 ~ExprDependence::TypeValue;
436 assert(E->isClassReceiver());
437 return ExprDependence::None;
438}
439
441 return E->getBaseExpr()->getDependence() | E->getKeyExpr()->getDependence();
442}
443
445 return E->getBase()->getDependence() & ~ExprDependence::Type &
446 ~ExprDependence::UnexpandedPack;
447}
448
450 return E->getSubExpr()->getDependence();
451}
452
454 auto D = E->getBase()->getDependence();
455 if (auto *LB = E->getLowerBound())
456 D |= LB->getDependence();
457 if (auto *Len = E->getLength())
458 D |= Len->getDependence();
459
460 if (E->isOMPArraySection()) {
461 if (auto *Stride = E->getStride())
462 D |= Stride->getDependence();
463 }
464 return D;
465}
466
468 auto D = E->getBase()->getDependence();
469 for (Expr *Dim: E->getDimensions())
470 if (Dim)
471 D |= turnValueToTypeDependence(Dim->getDependence());
472 return D;
473}
474
477 for (unsigned I = 0, End = E->numOfIterators(); I < End; ++I) {
478 if (auto *DD = cast_or_null<DeclaratorDecl>(E->getIteratorDecl(I))) {
479 // If the type is omitted, it's 'int', and is not dependent in any way.
480 if (auto *TSI = DD->getTypeSourceInfo()) {
481 D |= toExprDependenceAsWritten(TSI->getType()->getDependence());
482 }
483 }
484 OMPIteratorExpr::IteratorRange IR = E->getIteratorRange(I);
485 if (Expr *BE = IR.Begin)
486 D |= BE->getDependence();
487 if (Expr *EE = IR.End)
488 D |= EE->getDependence();
489 if (Expr *SE = IR.Step)
490 D |= SE->getDependence();
491 }
492 return D;
493}
494
495/// Compute the type-, value-, and instantiation-dependence of a
496/// declaration reference
497/// based on the declaration being referenced.
499 auto Deps = ExprDependence::None;
500
501 if (auto *NNS = E->getQualifier())
502 Deps |= toExprDependence(NNS->getDependence() &
503 ~NestedNameSpecifierDependence::Dependent);
504
505 if (auto *FirstArg = E->getTemplateArgs()) {
506 unsigned NumArgs = E->getNumTemplateArgs();
507 for (auto *Arg = FirstArg, *End = FirstArg + NumArgs; Arg < End; ++Arg)
508 Deps |= toExprDependence(Arg->getArgument().getDependence());
509 }
510
511 auto *Decl = E->getDecl();
512 auto Type = E->getType();
513
514 if (Decl->isParameterPack())
515 Deps |= ExprDependence::UnexpandedPack;
517 ExprDependence::Error;
518
519 // C++ [temp.dep.expr]p3:
520 // An id-expression is type-dependent if it contains:
521
522 // - an identifier associated by name lookup with one or more declarations
523 // declared with a dependent type
524 // - an identifier associated by name lookup with an entity captured by
525 // copy ([expr.prim.lambda.capture])
526 // in a lambda-expression that has an explicit object parameter whose
527 // type is dependent ([dcl.fct]),
528 //
529 // [The "or more" case is not modeled as a DeclRefExpr. There are a bunch
530 // more bullets here that we handle by treating the declaration as having a
531 // dependent type if they involve a placeholder type that can't be deduced.]
532 if (Type->isDependentType())
533 Deps |= ExprDependence::TypeValueInstantiation;
535 Deps |= ExprDependence::Instantiation;
536
537 // - an identifier associated by name lookup with an entity captured by
538 // copy ([expr.prim.lambda.capture])
539 if (E->isCapturedByCopyInLambdaWithExplicitObjectParameter())
540 Deps |= ExprDependence::Type;
541
542 // - a conversion-function-id that specifies a dependent type
543 if (Decl->getDeclName().getNameKind() ==
545 QualType T = Decl->getDeclName().getCXXNameType();
546 if (T->isDependentType())
547 return Deps | ExprDependence::TypeValueInstantiation;
548
550 Deps |= ExprDependence::Instantiation;
551 }
552
553 // - a template-id that is dependent,
554 // - a nested-name-specifier or a qualified-id that names a member of an
555 // unknown specialization
556 // [These are not modeled as DeclRefExprs.]
557
558 // or if it names a dependent member of the current instantiation that is a
559 // static data member of type "array of unknown bound of T" for some T
560 // [handled below].
561
562 // C++ [temp.dep.constexpr]p2:
563 // An id-expression is value-dependent if:
564
565 // - it is type-dependent [handled above]
566
567 // - it is the name of a non-type template parameter,
568 if (isa<NonTypeTemplateParmDecl>(Decl))
569 return Deps | ExprDependence::ValueInstantiation;
570
571 // - it names a potentially-constant variable that is initialized with an
572 // expression that is value-dependent
573 if (const auto *Var = dyn_cast<VarDecl>(Decl)) {
574 if (const Expr *Init = Var->getAnyInitializer()) {
575 if (Init->containsErrors())
576 Deps |= ExprDependence::Error;
577
578 if (Var->mightBeUsableInConstantExpressions(Ctx) &&
579 Init->isValueDependent())
580 Deps |= ExprDependence::ValueInstantiation;
581 }
582
583 // - it names a static data member that is a dependent member of the
584 // current instantiation and is not initialized in a member-declarator,
585 if (Var->isStaticDataMember() &&
586 Var->getDeclContext()->isDependentContext() &&
587 !Var->getFirstDecl()->hasInit()) {
588 const VarDecl *First = Var->getFirstDecl();
589 TypeSourceInfo *TInfo = First->getTypeSourceInfo();
590 if (TInfo->getType()->isIncompleteArrayType()) {
591 Deps |= ExprDependence::TypeValueInstantiation;
592 } else if (!First->hasInit()) {
593 Deps |= ExprDependence::ValueInstantiation;
594 }
595 }
596
597 return Deps;
598 }
599
600 // - it names a static member function that is a dependent member of the
601 // current instantiation
602 //
603 // FIXME: It's unclear that the restriction to static members here has any
604 // effect: any use of a non-static member function name requires either
605 // forming a pointer-to-member or providing an object parameter, either of
606 // which makes the overall expression value-dependent.
607 if (auto *MD = dyn_cast<CXXMethodDecl>(Decl)) {
608 if (MD->isStatic() && Decl->getDeclContext()->isDependentContext())
609 Deps |= ExprDependence::ValueInstantiation;
610 }
611
612 return Deps;
613}
614
616 // RecoveryExpr is
617 // - always value-dependent, and therefore instantiation dependent
618 // - contains errors (ExprDependence::Error), by definition
619 // - type-dependent if we don't know the type (fallback to an opaque
620 // dependent type), or the type is known and dependent, or it has
621 // type-dependent subexpressions.
623 ExprDependence::ErrorDependent;
624 // FIXME: remove the type-dependent bit from subexpressions, if the
625 // RecoveryExpr has a non-dependent type.
626 for (auto *S : E->subExpressions())
627 D |= S->getDependence();
628 return D;
629}
630
633 E->getTypeSourceInfo()->getType()->getDependence());
634}
635
638}
639
641 llvm::ArrayRef<Expr *> PreArgs) {
642 auto D = E->getCallee()->getDependence();
643 if (E->getType()->isDependentType())
644 D |= ExprDependence::Type;
645 for (auto *A : llvm::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 if (auto *NNS = E->getQualifier())
676 D |= toExprDependence(NNS->getDependence() &
677 ~NestedNameSpecifierDependence::Dependent);
678
679 for (const auto &A : E->template_arguments())
680 D |= toExprDependence(A.getArgument().getDependence());
681
682 auto *MemberDecl = E->getMemberDecl();
683 if (FieldDecl *FD = dyn_cast<FieldDecl>(MemberDecl)) {
684 DeclContext *DC = MemberDecl->getDeclContext();
685 // dyn_cast_or_null is used to handle objC variables which do not
686 // have a declaration context.
687 CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(DC);
688 if (RD && RD->isDependentContext() && RD->isCurrentInstantiation(DC)) {
689 if (!E->getType()->isDependentType())
691 }
692
693 // Bitfield with value-dependent width is type-dependent.
694 if (FD && FD->isBitField() && FD->getBitWidth()->isValueDependent()) {
695 D |= ExprDependence::Type;
696 }
697 }
698 return D;
699}
700
702 auto D = ExprDependence::None;
703 for (auto *A : E->inits())
704 D |= A->getDependence();
705 return D;
706}
707
710 for (auto *C : llvm::ArrayRef(E->getSubExprs(), E->getNumSubExprs()))
711 D |= C->getDependence();
712 return D;
713}
714
716 bool ContainsUnexpandedPack) {
717 auto D = ContainsUnexpandedPack ? ExprDependence::UnexpandedPack
718 : ExprDependence::None;
719 for (auto *AE : E->getAssocExprs())
720 D |= AE->getDependence() & ExprDependence::Error;
721
722 if (E->isExprPredicate())
723 D |= E->getControllingExpr()->getDependence() & ExprDependence::Error;
724 else
726 E->getControllingType()->getType()->getDependence());
727
728 if (E->isResultDependent())
729 return D | ExprDependence::TypeValueInstantiation;
730 return D | (E->getResultExpr()->getDependence() &
731 ~ExprDependence::UnexpandedPack);
732}
733
735 auto Deps = E->getInit()->getDependence();
736 for (const auto &D : E->designators()) {
737 auto DesignatorDeps = ExprDependence::None;
738 if (D.isArrayDesignator())
739 DesignatorDeps |= E->getArrayIndex(D)->getDependence();
740 else if (D.isArrayRangeDesignator())
741 DesignatorDeps |= E->getArrayRangeStart(D)->getDependence() |
742 E->getArrayRangeEnd(D)->getDependence();
743 Deps |= DesignatorDeps;
744 if (DesignatorDeps & ExprDependence::TypeValue)
745 Deps |= ExprDependence::TypeValueInstantiation;
746 }
747 return Deps;
748}
749
751 auto D = O->getSyntacticForm()->getDependence();
752 for (auto *E : O->semantics())
753 D |= E->getDependence();
754 return D;
755}
756
758 auto D = ExprDependence::None;
759 for (auto *E : llvm::ArrayRef(A->getSubExprs(), A->getNumSubExprs()))
760 D |= E->getDependence();
761 return D;
762}
763
766 E->getAllocatedTypeSourceInfo()->getType()->getDependence());
767 D |= toExprDependenceForImpliedType(E->getAllocatedType()->getDependence());
768 auto Size = E->getArraySize();
769 if (Size && *Size)
770 D |= turnTypeToValueDependence((*Size)->getDependence());
771 if (auto *I = E->getInitializer())
772 D |= turnTypeToValueDependence(I->getDependence());
773 for (auto *A : E->placement_arguments())
774 D |= turnTypeToValueDependence(A->getDependence());
775 return D;
776}
777
779 auto D = E->getBase()->getDependence();
780 if (auto *TSI = E->getDestroyedTypeInfo())
781 D |= toExprDependenceAsWritten(TSI->getType()->getDependence());
782 if (auto *ST = E->getScopeTypeInfo())
784 toExprDependenceAsWritten(ST->getType()->getDependence()));
785 if (auto *Q = E->getQualifier())
786 D |= toExprDependence(Q->getDependence() &
787 ~NestedNameSpecifierDependence::Dependent);
788 return D;
789}
790
793 bool KnownInstantiationDependent,
794 bool KnownContainsUnexpandedParameterPack) {
795 auto Deps = ExprDependence::None;
796 if (KnownDependent)
797 Deps |= ExprDependence::TypeValue;
798 if (KnownInstantiationDependent)
799 Deps |= ExprDependence::Instantiation;
800 if (KnownContainsUnexpandedParameterPack)
801 Deps |= ExprDependence::UnexpandedPack;
802 Deps |= getDependenceInExpr(E->getNameInfo());
803 if (auto *Q = E->getQualifier())
804 Deps |= toExprDependence(Q->getDependence() &
805 ~NestedNameSpecifierDependence::Dependent);
806 for (auto *D : E->decls()) {
808 isa<UnresolvedUsingValueDecl>(D))
809 Deps |= ExprDependence::TypeValueInstantiation;
810 }
811 // If we have explicit template arguments, check for dependent
812 // template arguments and whether they contain any unexpanded pack
813 // expansions.
814 for (const auto &A : E->template_arguments())
815 Deps |= toExprDependence(A.getArgument().getDependence());
816 return Deps;
817}
818
820 auto D = ExprDependence::TypeValue;
821 D |= getDependenceInExpr(E->getNameInfo());
822 if (auto *Q = E->getQualifier())
823 D |= toExprDependence(Q->getDependence());
824 for (const auto &A : E->template_arguments())
825 D |= toExprDependence(A.getArgument().getDependence());
826 return D;
827}
828
832 for (auto *A : E->arguments())
833 D |= A->getDependence() & ~ExprDependence::Type;
834 return D;
835}
836
838 CXXConstructExpr *BaseE = E;
840 E->getTypeSourceInfo()->getType()->getDependence()) |
841 computeDependence(BaseE);
842}
843
845 return E->getExpr()->getDependence();
846}
847
849 return E->getExpr()->getDependence();
850}
851
853 bool ContainsUnexpandedParameterPack) {
855 if (ContainsUnexpandedParameterPack)
856 D |= ExprDependence::UnexpandedPack;
857 return D;
858}
859
861 auto D = ExprDependence::ValueInstantiation;
862 D |= toExprDependenceAsWritten(E->getTypeAsWritten()->getDependence());
864 for (auto *A : E->arguments())
865 D |= A->getDependence() &
866 (ExprDependence::UnexpandedPack | ExprDependence::Error);
867 return D;
868}
869
871 auto D = ExprDependence::TypeValueInstantiation;
872 if (!E->isImplicitAccess())
873 D |= E->getBase()->getDependence();
874 if (auto *Q = E->getQualifier())
875 D |= toExprDependence(Q->getDependence());
876 D |= getDependenceInExpr(E->getMemberNameInfo());
877 for (const auto &A : E->template_arguments())
878 D |= toExprDependence(A.getArgument().getDependence());
879 return D;
880}
881
883 return E->getSubExpr()->getDependence();
884}
885
887 auto D = ExprDependence::TypeValueInstantiation;
888 for (const auto *C : {E->getLHS(), E->getRHS()}) {
889 if (C)
890 D |= C->getDependence() & ~ExprDependence::UnexpandedPack;
891 }
892 return D;
893}
894
896 auto D = ExprDependence::None;
897 for (const auto *A : E->getInitExprs())
898 D |= A->getDependence();
899 return D;
900}
901
903 auto D = ExprDependence::None;
904 for (const auto *A : E->getArgs())
905 D |= toExprDependenceAsWritten(A->getType()->getDependence()) &
907 return D;
908}
909
911 bool ValueDependent) {
912 auto TA = TemplateArgumentDependence::None;
913 const auto InterestingDeps = TemplateArgumentDependence::Instantiation |
914 TemplateArgumentDependence::UnexpandedPack;
915 for (const TemplateArgumentLoc &ArgLoc :
916 E->getTemplateArgsAsWritten()->arguments()) {
917 TA |= ArgLoc.getArgument().getDependence() & InterestingDeps;
918 if (TA == InterestingDeps)
919 break;
920 }
921
923 ValueDependent ? ExprDependence::Value : ExprDependence::None;
924 auto Res = D | toExprDependence(TA);
925 if(!ValueDependent && E->getSatisfaction().ContainsErrors)
926 Res |= ExprDependence::Error;
927 return Res;
928}
929
931 auto D = ExprDependence::None;
932 Expr **Elements = E->getElements();
933 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I)
934 D |= turnTypeToValueDependence(Elements[I]->getDependence());
935 return D;
936}
937
939 auto Deps = ExprDependence::None;
940 for (unsigned I = 0, N = E->getNumElements(); I < N; ++I) {
941 auto KV = E->getKeyValueElement(I);
942 auto KVDeps = turnTypeToValueDependence(KV.Key->getDependence() |
943 KV.Value->getDependence());
944 if (KV.EllipsisLoc.isValid())
945 KVDeps &= ~ExprDependence::UnexpandedPack;
946 Deps |= KVDeps;
947 }
948 return Deps;
949}
950
952 auto D = ExprDependence::None;
953 if (auto *R = E->getInstanceReceiver())
954 D |= R->getDependence();
955 else
957 for (auto *A : E->arguments())
958 D |= A->getDependence();
959 return D;
960}
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:187
const LangOptions & getLangOpts() const
Definition: ASTContext.h:797
Represents a loop initializing the elements of an array.
Definition: Expr.h:5693
This class represents BOTH the OpenMP Array Section and OpenACC 'subarray', with a boolean differenti...
Definition: Expr.h:6916
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition: Expr.h:2674
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
Definition: ExprCXX.h:2852
AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2] This AST node provides support ...
Definition: Expr.h:6416
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition: Expr.h:6619
Expr ** getSubExprs()
Definition: Expr.h:6696
static unsigned getNumSubExprs(AtomicOp Op)
Determine the number of arguments the specified atomic builtin should have.
Definition: Expr.cpp:4976
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Definition: Expr.h:4265
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3860
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition: Expr.h:6355
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:2497
Represents a C++ member access expression where the actual member referenced could not be resolved be...
Definition: ExprCXX.h:3682
Represents a folding of a pack over an operator.
Definition: ExprCXX.h:4839
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition: ExprCXX.h:2240
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
Definition: ExprCXX.h:4125
Represents a list-initialization with parenthesis.
Definition: ExprCXX.h:4953
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Definition: ExprCXX.h:2616
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 a value-initialized rvalue of type T, which is a non-class type.
Definition: ExprCXX.h:2181
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:3556
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:2830
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Definition: Expr.h:4582
CompoundLiteralExpr - [C99 6.5.2.5].
Definition: Expr.h:3428
Represents the specialization of a concept - evaluates to a prvalue of type bool.
Definition: ExprConcepts.h:42
ConditionalOperator - The ?: ternary operator.
Definition: Expr.h:4203
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Definition: Expr.h:4523
Represents an expression that might suspend coroutine execution; either a co_await or co_yield expres...
Definition: ExprCXX.h:5070
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1436
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Definition: DeclBase.cpp:1333
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:242
llvm::iterator_range< specific_attr_iterator< T > > specific_attrs() const
Definition: DeclBase.h:566
DeclContext * getDeclContext()
Definition: DeclBase.h:455
Represents a 'co_await' expression while the type of the promise is dependent.
Definition: ExprCXX.h:5216
A qualified reference to a name whose declaration cannot yet be resolved.
Definition: ExprCXX.h:3322
Represents a C99 designated initializer expression.
Definition: Expr.h:5274
ExplicitCastExpr - An explicit cast written in the source code.
Definition: Expr.h:3750
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:3066
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:2923
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
Definition: Expr.h:6295
Represents a member of a struct/union/class.
Definition: Decl.h:3030
FullExpr - Represents a "full-expression" node.
Definition: Expr.h:1044
Represents a C11 generic selection.
Definition: Expr.h:5907
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:3675
Represents an implicitly-generated value initialization of an object of a given type.
Definition: Expr.h:5782
Describes an C or C++ initializer list.
Definition: Expr.h:5029
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:4727
MatrixSubscriptExpr - Matrix subscript expression for the MatrixType extension.
Definition: Expr.h:2752
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:3187
Represents a place-holder for an object not to be initialized by anything.
Definition: Expr.h:5602
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:1575
ObjCIsaExpr - Represent X->isa and X.isa when X is an ObjC 'id' type.
Definition: ExprObjC.h:1491
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:945
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
Definition: ExprObjC.h:617
ObjCSubscriptRefExpr - used for array and dictionary subscripting.
Definition: ExprObjC.h:844
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Definition: Expr.h:2475
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition: Expr.h:1173
A reference to an overloaded function set, either an UnresolvedLookupExpr or an UnresolvedMemberExpr.
Definition: ExprCXX.h:2982
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition: ExprCXX.h:4179
ParenExpr - This represents a parenthesized expression, e.g.
Definition: Expr.h:2135
[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:6487
ArrayRef< Expr * > semantics()
Definition: Expr.h:6566
Expr * getSyntacticForm()
Return the syntactic form of this expression, i.e.
Definition: Expr.h:6529
A (possibly-)qualified type.
Definition: Type.h:941
Frontend produces RecoveryExprs on semantic errors that prevent creating other well-formed expression...
Definition: Expr.h:7091
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
Definition: Expr.h:4455
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition: Expr.h:4407
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition: ExprCXX.h:4483
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:524
A container of type source information.
Definition: Type.h:7721
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:7732
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition: ExprCXX.h:2767
The base class of the type hierarchy.
Definition: Type.h:1829
bool isIncompleteArrayType() const
Definition: Type.h:8083
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
Definition: Type.h:2703
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2695
TypeDependence getDependence() const
Definition: Type.h:2684
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition: Expr.h:2578
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition: Expr.h:2188
Represents a call to the builtin function __builtin_va_arg.
Definition: Expr.h:4691
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:667
const Expr * getExprStmt() const
Definition: Stmt.cpp:404
Represents a variable declaration or definition.
Definition: Decl.h:879
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