llvm-project
960 строк · 34.8 Кб
1//===- ComputeDependence.cpp ----------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "clang/AST/ComputeDependence.h"10#include "clang/AST/Attr.h"11#include "clang/AST/DeclCXX.h"12#include "clang/AST/DeclarationName.h"13#include "clang/AST/DependenceFlags.h"14#include "clang/AST/Expr.h"15#include "clang/AST/ExprCXX.h"16#include "clang/AST/ExprConcepts.h"17#include "clang/AST/ExprObjC.h"18#include "clang/AST/ExprOpenMP.h"19#include "clang/Basic/ExceptionSpecificationType.h"20#include "llvm/ADT/ArrayRef.h"21
22using namespace clang;23
24ExprDependence clang::computeDependence(FullExpr *E) {25return E->getSubExpr()->getDependence();26}
27
28ExprDependence clang::computeDependence(OpaqueValueExpr *E) {29auto D = toExprDependenceForImpliedType(E->getType()->getDependence());30if (auto *S = E->getSourceExpr())31D |= S->getDependence();32assert(!(D & ExprDependence::UnexpandedPack));33return D;34}
35
36ExprDependence clang::computeDependence(ParenExpr *E) {37return E->getSubExpr()->getDependence();38}
39
40ExprDependence clang::computeDependence(UnaryOperator *E,41const ASTContext &Ctx) {42ExprDependence Dep =43// FIXME: Do we need to look at the type?44toExprDependenceForImpliedType(E->getType()->getDependence()) |45E->getSubExpr()->getDependence();46
47// C++ [temp.dep.constexpr]p5:48// An expression of the form & qualified-id where the qualified-id names a49// dependent member of the current instantiation is value-dependent. An50// expression of the form & cast-expression is also value-dependent if51// evaluating cast-expression as a core constant expression succeeds and52// the result of the evaluation refers to a templated entity that is an53// 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 it56// refers to a templated entity other than a variable with local storage.57if (Ctx.getLangOpts().CPlusPlus && E->getOpcode() == UO_AddrOf &&58!(Dep & ExprDependence::Value)) {59Expr::EvalResult Result;60SmallVector<PartialDiagnosticAt, 8> Diag;61Result.Diag = &Diag;62// FIXME: This doesn't enforce the C++98 constant expression rules.63if (E->getSubExpr()->EvaluateAsConstantExpr(Result, Ctx) && Diag.empty() &&64Result.Val.isLValue()) {65auto *VD = Result.Val.getLValueBase().dyn_cast<const ValueDecl *>();66if (VD && VD->isTemplated()) {67auto *VarD = dyn_cast<VarDecl>(VD);68if (!VarD || !VarD->hasLocalStorage())69Dep |= ExprDependence::Value;70}71}72}73
74return Dep;75}
76
77ExprDependence clang::computeDependence(UnaryExprOrTypeTraitExpr *E) {78// Never type-dependent (C++ [temp.dep.expr]p3).79// Value-dependent if the argument is type-dependent.80if (E->isArgumentType())81return turnTypeToValueDependence(82toExprDependenceAsWritten(E->getArgumentType()->getDependence()));83
84auto ArgDeps = E->getArgumentExpr()->getDependence();85auto Deps = ArgDeps & ~ExprDependence::TypeValue;86// Value-dependent if the argument is type-dependent.87if (ArgDeps & ExprDependence::Type)88Deps |= ExprDependence::Value;89// Check to see if we are in the situation where alignof(decl) should be90// dependent because decl's alignment is dependent.91auto ExprKind = E->getKind();92if (ExprKind != UETT_AlignOf && ExprKind != UETT_PreferredAlignOf)93return Deps;94if ((Deps & ExprDependence::Value) && (Deps & ExprDependence::Instantiation))95return Deps;96
97auto *NoParens = E->getArgumentExpr()->IgnoreParens();98const ValueDecl *D = nullptr;99if (const auto *DRE = dyn_cast<DeclRefExpr>(NoParens))100D = DRE->getDecl();101else if (const auto *ME = dyn_cast<MemberExpr>(NoParens))102D = ME->getMemberDecl();103if (!D)104return Deps;105for (const auto *I : D->specific_attrs<AlignedAttr>()) {106if (I->isAlignmentErrorDependent())107Deps |= ExprDependence::Error;108if (I->isAlignmentDependent())109Deps |= ExprDependence::ValueInstantiation;110}111return Deps;112}
113
114ExprDependence clang::computeDependence(ArraySubscriptExpr *E) {115return E->getLHS()->getDependence() | E->getRHS()->getDependence();116}
117
118ExprDependence clang::computeDependence(MatrixSubscriptExpr *E) {119return E->getBase()->getDependence() | E->getRowIdx()->getDependence() |120(E->getColumnIdx() ? E->getColumnIdx()->getDependence()121: ExprDependence::None);122}
123
124ExprDependence clang::computeDependence(CompoundLiteralExpr *E) {125return toExprDependenceAsWritten(126E->getTypeSourceInfo()->getType()->getDependence()) |127toExprDependenceForImpliedType(E->getType()->getDependence()) |128turnTypeToValueDependence(E->getInitializer()->getDependence());129}
130
131ExprDependence clang::computeDependence(ImplicitCastExpr *E) {132// We model implicit conversions as combining the dependence of their133// subexpression, apart from its type, with the semantic portion of the134// target type.135ExprDependence D =136toExprDependenceForImpliedType(E->getType()->getDependence());137if (auto *S = E->getSubExpr())138D |= S->getDependence() & ~ExprDependence::Type;139return D;140}
141
142ExprDependence clang::computeDependence(ExplicitCastExpr *E) {143// Cast expressions are type-dependent if the type is144// dependent (C++ [temp.dep.expr]p3).145// Cast expressions are value-dependent if the type is146// 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 not150// dependent, but it may be deduced as a dependent type.151ExprDependence D =152toExprDependenceAsWritten(153cast<ExplicitCastExpr>(E)->getTypeAsWritten()->getDependence()) |154toExprDependenceForImpliedType(E->getType()->getDependence());155if (auto *S = E->getSubExpr())156D |= S->getDependence() & ~ExprDependence::Type;157return D;158}
159
160ExprDependence clang::computeDependence(BinaryOperator *E) {161return E->getLHS()->getDependence() | E->getRHS()->getDependence();162}
163
164ExprDependence clang::computeDependence(ConditionalOperator *E) {165// The type of the conditional operator depends on the type of the conditional166// to support the GCC vector conditional extension. Additionally,167// [temp.dep.expr] does specify state that this should be dependent on ALL sub168// expressions.169return E->getCond()->getDependence() | E->getLHS()->getDependence() |170E->getRHS()->getDependence();171}
172
173ExprDependence clang::computeDependence(BinaryConditionalOperator *E) {174return E->getCommon()->getDependence() | E->getFalseExpr()->getDependence();175}
176
177ExprDependence clang::computeDependence(StmtExpr *E, unsigned TemplateDepth) {178auto D = toExprDependenceForImpliedType(E->getType()->getDependence());179// Propagate dependence of the result.180if (const auto *CompoundExprResult =181dyn_cast_or_null<ValueStmt>(E->getSubStmt()->getStmtExprResult()))182if (const Expr *ResultExpr = CompoundExprResult->getExprStmt())183D |= ResultExpr->getDependence();184// Note: we treat a statement-expression in a dependent context as always185// being value- and instantiation-dependent. This matches the behavior of186// lambda-expressions and GCC.187if (TemplateDepth)188D |= ExprDependence::ValueInstantiation;189// A param pack cannot be expanded over stmtexpr boundaries.190return D & ~ExprDependence::UnexpandedPack;191}
192
193ExprDependence clang::computeDependence(ConvertVectorExpr *E) {194auto D = toExprDependenceAsWritten(195E->getTypeSourceInfo()->getType()->getDependence()) |196E->getSrcExpr()->getDependence();197if (!E->getType()->isDependentType())198D &= ~ExprDependence::Type;199return D;200}
201
202ExprDependence clang::computeDependence(ChooseExpr *E) {203if (E->isConditionDependent())204return ExprDependence::TypeValueInstantiation |205E->getCond()->getDependence() | E->getLHS()->getDependence() |206E->getRHS()->getDependence();207
208auto Cond = E->getCond()->getDependence();209auto Active = E->getLHS()->getDependence();210auto Inactive = E->getRHS()->getDependence();211if (!E->isConditionTrue())212std::swap(Active, Inactive);213// Take type- and value- dependency from the active branch. Propagate all214// other flags from all branches.215return (Active & ExprDependence::TypeValue) |216((Cond | Active | Inactive) & ~ExprDependence::TypeValue);217}
218
219ExprDependence clang::computeDependence(ParenListExpr *P) {220auto D = ExprDependence::None;221for (auto *E : P->exprs())222D |= E->getDependence();223return D;224}
225
226ExprDependence clang::computeDependence(VAArgExpr *E) {227auto D = toExprDependenceAsWritten(228E->getWrittenTypeInfo()->getType()->getDependence()) |229(E->getSubExpr()->getDependence() & ~ExprDependence::Type);230return D;231}
232
233ExprDependence clang::computeDependence(NoInitExpr *E) {234return toExprDependenceForImpliedType(E->getType()->getDependence()) &235(ExprDependence::Instantiation | ExprDependence::Error);236}
237
238ExprDependence clang::computeDependence(ArrayInitLoopExpr *E) {239auto D = E->getCommonExpr()->getDependence() |240E->getSubExpr()->getDependence() | ExprDependence::Instantiation;241if (!E->getType()->isInstantiationDependentType())242D &= ~ExprDependence::Instantiation;243return turnTypeToValueDependence(D);244}
245
246ExprDependence clang::computeDependence(ImplicitValueInitExpr *E) {247return toExprDependenceForImpliedType(E->getType()->getDependence()) &248ExprDependence::Instantiation;249}
250
251ExprDependence clang::computeDependence(ExtVectorElementExpr *E) {252return E->getBase()->getDependence();253}
254
255ExprDependence clang::computeDependence(BlockExpr *E) {256auto D = toExprDependenceForImpliedType(E->getType()->getDependence());257if (E->getBlockDecl()->isDependentContext())258D |= ExprDependence::Instantiation;259return D;260}
261
262ExprDependence clang::computeDependence(AsTypeExpr *E) {263// FIXME: AsTypeExpr doesn't store the type as written. Assume the expression264// type has identical sugar for now, so is a type-as-written.265auto D = toExprDependenceAsWritten(E->getType()->getDependence()) |266E->getSrcExpr()->getDependence();267if (!E->getType()->isDependentType())268D &= ~ExprDependence::Type;269return D;270}
271
272ExprDependence clang::computeDependence(CXXRewrittenBinaryOperator *E) {273return E->getSemanticForm()->getDependence();274}
275
276ExprDependence clang::computeDependence(CXXStdInitializerListExpr *E) {277auto D = turnTypeToValueDependence(E->getSubExpr()->getDependence());278D |= toExprDependenceForImpliedType(E->getType()->getDependence());279return D;280}
281
282ExprDependence clang::computeDependence(CXXTypeidExpr *E) {283auto D = ExprDependence::None;284if (E->isTypeOperand())285D = toExprDependenceAsWritten(286E->getTypeOperandSourceInfo()->getType()->getDependence());287else288D = turnTypeToValueDependence(E->getExprOperand()->getDependence());289// typeid is never type-dependent (C++ [temp.dep.expr]p4)290return D & ~ExprDependence::Type;291}
292
293ExprDependence clang::computeDependence(MSPropertyRefExpr *E) {294return E->getBaseExpr()->getDependence() & ~ExprDependence::Type;295}
296
297ExprDependence clang::computeDependence(MSPropertySubscriptExpr *E) {298return E->getIdx()->getDependence();299}
300
301ExprDependence clang::computeDependence(CXXUuidofExpr *E) {302if (E->isTypeOperand())303return turnTypeToValueDependence(toExprDependenceAsWritten(304E->getTypeOperandSourceInfo()->getType()->getDependence()));305
306return turnTypeToValueDependence(E->getExprOperand()->getDependence());307}
308
309ExprDependence clang::computeDependence(CXXThisExpr *E) {310// 'this' is type-dependent if the class type of the enclosing311// member function is dependent (C++ [temp.dep.expr]p2)312auto D = toExprDependenceForImpliedType(E->getType()->getDependence());313
314// If a lambda with an explicit object parameter captures '*this', then315// 'this' now refers to the captured copy of lambda, and if the lambda316// is type-dependent, so is the object and thus 'this'.317//318// Note: The standard does not mention this case explicitly, but we need319// to do this so we can mark NSDM accesses as dependent.320if (E->isCapturedByCopyInLambdaWithExplicitObjectParameter())321D |= ExprDependence::Type;322
323assert(!(D & ExprDependence::UnexpandedPack));324return D;325}
326
327ExprDependence clang::computeDependence(CXXThrowExpr *E) {328auto *Op = E->getSubExpr();329if (!Op)330return ExprDependence::None;331return Op->getDependence() & ~ExprDependence::TypeValue;332}
333
334ExprDependence clang::computeDependence(CXXBindTemporaryExpr *E) {335return E->getSubExpr()->getDependence();336}
337
338ExprDependence clang::computeDependence(CXXScalarValueInitExpr *E) {339auto D = toExprDependenceForImpliedType(E->getType()->getDependence());340if (auto *TSI = E->getTypeSourceInfo())341D |= toExprDependenceAsWritten(TSI->getType()->getDependence());342return D;343}
344
345ExprDependence clang::computeDependence(CXXDeleteExpr *E) {346return turnTypeToValueDependence(E->getArgument()->getDependence());347}
348
349ExprDependence clang::computeDependence(ArrayTypeTraitExpr *E) {350auto D = toExprDependenceAsWritten(E->getQueriedType()->getDependence());351if (auto *Dim = E->getDimensionExpression())352D |= Dim->getDependence();353return turnTypeToValueDependence(D);354}
355
356ExprDependence clang::computeDependence(ExpressionTraitExpr *E) {357// Never type-dependent.358auto D = E->getQueriedExpression()->getDependence() & ~ExprDependence::Type;359// Value-dependent if the argument is type-dependent.360if (E->getQueriedExpression()->isTypeDependent())361D |= ExprDependence::Value;362return D;363}
364
365ExprDependence clang::computeDependence(CXXNoexceptExpr *E, CanThrowResult CT) {366auto D = E->getOperand()->getDependence() & ~ExprDependence::TypeValue;367if (CT == CT_Dependent)368D |= ExprDependence::ValueInstantiation;369return D;370}
371
372ExprDependence clang::computeDependence(PackExpansionExpr *E) {373return (E->getPattern()->getDependence() & ~ExprDependence::UnexpandedPack) |374ExprDependence::TypeValueInstantiation;375}
376
377ExprDependence clang::computeDependence(PackIndexingExpr *E) {378
379ExprDependence PatternDep = E->getPackIdExpression()->getDependence() &380~ExprDependence::UnexpandedPack;381
382ExprDependence D = E->getIndexExpr()->getDependence();383if (D & ExprDependence::TypeValueInstantiation)384D |= E->getIndexExpr()->getDependence() | PatternDep |385ExprDependence::Instantiation;386
387ArrayRef<Expr *> Exprs = E->getExpressions();388if (Exprs.empty())389D |= PatternDep | ExprDependence::Instantiation;390
391else if (!E->getIndexExpr()->isInstantiationDependent()) {392std::optional<unsigned> Index = E->getSelectedIndex();393assert(Index && *Index < Exprs.size() && "pack index out of bound");394D |= Exprs[*Index]->getDependence();395}396return D;397}
398
399ExprDependence clang::computeDependence(SubstNonTypeTemplateParmExpr *E) {400return E->getReplacement()->getDependence();401}
402
403ExprDependence clang::computeDependence(CoroutineSuspendExpr *E) {404if (auto *Resume = E->getResumeExpr())405return (Resume->getDependence() &406(ExprDependence::TypeValue | ExprDependence::Error)) |407(E->getCommonExpr()->getDependence() & ~ExprDependence::TypeValue);408return E->getCommonExpr()->getDependence() |409ExprDependence::TypeValueInstantiation;410}
411
412ExprDependence clang::computeDependence(DependentCoawaitExpr *E) {413return E->getOperand()->getDependence() |414ExprDependence::TypeValueInstantiation;415}
416
417ExprDependence clang::computeDependence(ObjCBoxedExpr *E) {418return E->getSubExpr()->getDependence();419}
420
421ExprDependence clang::computeDependence(ObjCEncodeExpr *E) {422return toExprDependenceAsWritten(E->getEncodedType()->getDependence());423}
424
425ExprDependence clang::computeDependence(ObjCIvarRefExpr *E) {426return turnTypeToValueDependence(E->getBase()->getDependence());427}
428
429ExprDependence clang::computeDependence(ObjCPropertyRefExpr *E) {430if (E->isObjectReceiver())431return E->getBase()->getDependence() & ~ExprDependence::Type;432if (E->isSuperReceiver())433return toExprDependenceForImpliedType(434E->getSuperReceiverType()->getDependence()) &435~ExprDependence::TypeValue;436assert(E->isClassReceiver());437return ExprDependence::None;438}
439
440ExprDependence clang::computeDependence(ObjCSubscriptRefExpr *E) {441return E->getBaseExpr()->getDependence() | E->getKeyExpr()->getDependence();442}
443
444ExprDependence clang::computeDependence(ObjCIsaExpr *E) {445return E->getBase()->getDependence() & ~ExprDependence::Type &446~ExprDependence::UnexpandedPack;447}
448
449ExprDependence clang::computeDependence(ObjCIndirectCopyRestoreExpr *E) {450return E->getSubExpr()->getDependence();451}
452
453ExprDependence clang::computeDependence(ArraySectionExpr *E) {454auto D = E->getBase()->getDependence();455if (auto *LB = E->getLowerBound())456D |= LB->getDependence();457if (auto *Len = E->getLength())458D |= Len->getDependence();459
460if (E->isOMPArraySection()) {461if (auto *Stride = E->getStride())462D |= Stride->getDependence();463}464return D;465}
466
467ExprDependence clang::computeDependence(OMPArrayShapingExpr *E) {468auto D = E->getBase()->getDependence();469for (Expr *Dim: E->getDimensions())470if (Dim)471D |= turnValueToTypeDependence(Dim->getDependence());472return D;473}
474
475ExprDependence clang::computeDependence(OMPIteratorExpr *E) {476auto D = toExprDependenceForImpliedType(E->getType()->getDependence());477for (unsigned I = 0, End = E->numOfIterators(); I < End; ++I) {478if (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.480if (auto *TSI = DD->getTypeSourceInfo()) {481D |= toExprDependenceAsWritten(TSI->getType()->getDependence());482}483}484OMPIteratorExpr::IteratorRange IR = E->getIteratorRange(I);485if (Expr *BE = IR.Begin)486D |= BE->getDependence();487if (Expr *EE = IR.End)488D |= EE->getDependence();489if (Expr *SE = IR.Step)490D |= SE->getDependence();491}492return D;493}
494
495/// Compute the type-, value-, and instantiation-dependence of a
496/// declaration reference
497/// based on the declaration being referenced.
498ExprDependence clang::computeDependence(DeclRefExpr *E, const ASTContext &Ctx) {499auto Deps = ExprDependence::None;500
501if (auto *NNS = E->getQualifier())502Deps |= toExprDependence(NNS->getDependence() &503~NestedNameSpecifierDependence::Dependent);504
505if (auto *FirstArg = E->getTemplateArgs()) {506unsigned NumArgs = E->getNumTemplateArgs();507for (auto *Arg = FirstArg, *End = FirstArg + NumArgs; Arg < End; ++Arg)508Deps |= toExprDependence(Arg->getArgument().getDependence());509}510
511auto *Decl = E->getDecl();512auto Type = E->getType();513
514if (Decl->isParameterPack())515Deps |= ExprDependence::UnexpandedPack;516Deps |= toExprDependenceForImpliedType(Type->getDependence()) &517ExprDependence::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 declarations523// declared with a dependent type524// - an identifier associated by name lookup with an entity captured by525// copy ([expr.prim.lambda.capture])526// in a lambda-expression that has an explicit object parameter whose527// type is dependent ([dcl.fct]),528//529// [The "or more" case is not modeled as a DeclRefExpr. There are a bunch530// more bullets here that we handle by treating the declaration as having a531// dependent type if they involve a placeholder type that can't be deduced.]532if (Type->isDependentType())533Deps |= ExprDependence::TypeValueInstantiation;534else if (Type->isInstantiationDependentType())535Deps |= ExprDependence::Instantiation;536
537// - an identifier associated by name lookup with an entity captured by538// copy ([expr.prim.lambda.capture])539if (E->isCapturedByCopyInLambdaWithExplicitObjectParameter())540Deps |= ExprDependence::Type;541
542// - a conversion-function-id that specifies a dependent type543if (Decl->getDeclName().getNameKind() ==544DeclarationName::CXXConversionFunctionName) {545QualType T = Decl->getDeclName().getCXXNameType();546if (T->isDependentType())547return Deps | ExprDependence::TypeValueInstantiation;548
549if (T->isInstantiationDependentType())550Deps |= 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 an555// unknown specialization556// [These are not modeled as DeclRefExprs.]557
558// or if it names a dependent member of the current instantiation that is a559// static data member of type "array of unknown bound of T" for some T560// [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,568if (isa<NonTypeTemplateParmDecl>(Decl))569return Deps | ExprDependence::ValueInstantiation;570
571// - it names a potentially-constant variable that is initialized with an572// expression that is value-dependent573if (const auto *Var = dyn_cast<VarDecl>(Decl)) {574if (const Expr *Init = Var->getAnyInitializer()) {575if (Init->containsErrors())576Deps |= ExprDependence::Error;577
578if (Var->mightBeUsableInConstantExpressions(Ctx) &&579Init->isValueDependent())580Deps |= ExprDependence::ValueInstantiation;581}582
583// - it names a static data member that is a dependent member of the584// current instantiation and is not initialized in a member-declarator,585if (Var->isStaticDataMember() &&586Var->getDeclContext()->isDependentContext() &&587!Var->getFirstDecl()->hasInit()) {588const VarDecl *First = Var->getFirstDecl();589TypeSourceInfo *TInfo = First->getTypeSourceInfo();590if (TInfo->getType()->isIncompleteArrayType()) {591Deps |= ExprDependence::TypeValueInstantiation;592} else if (!First->hasInit()) {593Deps |= ExprDependence::ValueInstantiation;594}595}596
597return Deps;598}599
600// - it names a static member function that is a dependent member of the601// current instantiation602//603// FIXME: It's unclear that the restriction to static members here has any604// effect: any use of a non-static member function name requires either605// forming a pointer-to-member or providing an object parameter, either of606// which makes the overall expression value-dependent.607if (auto *MD = dyn_cast<CXXMethodDecl>(Decl)) {608if (MD->isStatic() && Decl->getDeclContext()->isDependentContext())609Deps |= ExprDependence::ValueInstantiation;610}611
612return Deps;613}
614
615ExprDependence clang::computeDependence(RecoveryExpr *E) {616// RecoveryExpr is617// - always value-dependent, and therefore instantiation dependent618// - contains errors (ExprDependence::Error), by definition619// - type-dependent if we don't know the type (fallback to an opaque620// dependent type), or the type is known and dependent, or it has621// type-dependent subexpressions.622auto D = toExprDependenceAsWritten(E->getType()->getDependence()) |623ExprDependence::ErrorDependent;624// FIXME: remove the type-dependent bit from subexpressions, if the625// RecoveryExpr has a non-dependent type.626for (auto *S : E->subExpressions())627D |= S->getDependence();628return D;629}
630
631ExprDependence clang::computeDependence(SYCLUniqueStableNameExpr *E) {632return toExprDependenceAsWritten(633E->getTypeSourceInfo()->getType()->getDependence());634}
635
636ExprDependence clang::computeDependence(PredefinedExpr *E) {637return toExprDependenceForImpliedType(E->getType()->getDependence());638}
639
640ExprDependence clang::computeDependence(CallExpr *E,641llvm::ArrayRef<Expr *> PreArgs) {642auto D = E->getCallee()->getDependence();643if (E->getType()->isDependentType())644D |= ExprDependence::Type;645for (auto *A : llvm::ArrayRef(E->getArgs(), E->getNumArgs())) {646if (A)647D |= A->getDependence();648}649for (auto *A : PreArgs)650D |= A->getDependence();651return D;652}
653
654ExprDependence clang::computeDependence(OffsetOfExpr *E) {655auto D = turnTypeToValueDependence(toExprDependenceAsWritten(656E->getTypeSourceInfo()->getType()->getDependence()));657for (unsigned I = 0, N = E->getNumExpressions(); I < N; ++I)658D |= turnTypeToValueDependence(E->getIndexExpr(I)->getDependence());659return D;660}
661
662static inline ExprDependence getDependenceInExpr(DeclarationNameInfo Name) {663auto D = ExprDependence::None;664if (Name.isInstantiationDependent())665D |= ExprDependence::Instantiation;666if (Name.containsUnexpandedParameterPack())667D |= ExprDependence::UnexpandedPack;668return D;669}
670
671ExprDependence clang::computeDependence(MemberExpr *E) {672auto D = E->getBase()->getDependence();673D |= getDependenceInExpr(E->getMemberNameInfo());674
675if (auto *NNS = E->getQualifier())676D |= toExprDependence(NNS->getDependence() &677~NestedNameSpecifierDependence::Dependent);678
679for (const auto &A : E->template_arguments())680D |= toExprDependence(A.getArgument().getDependence());681
682auto *MemberDecl = E->getMemberDecl();683if (FieldDecl *FD = dyn_cast<FieldDecl>(MemberDecl)) {684DeclContext *DC = MemberDecl->getDeclContext();685// dyn_cast_or_null is used to handle objC variables which do not686// have a declaration context.687CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(DC);688if (RD && RD->isDependentContext() && RD->isCurrentInstantiation(DC)) {689if (!E->getType()->isDependentType())690D &= ~ExprDependence::Type;691}692
693// Bitfield with value-dependent width is type-dependent.694if (FD && FD->isBitField() && FD->getBitWidth()->isValueDependent()) {695D |= ExprDependence::Type;696}697}698return D;699}
700
701ExprDependence clang::computeDependence(InitListExpr *E) {702auto D = ExprDependence::None;703for (auto *A : E->inits())704D |= A->getDependence();705return D;706}
707
708ExprDependence clang::computeDependence(ShuffleVectorExpr *E) {709auto D = toExprDependenceForImpliedType(E->getType()->getDependence());710for (auto *C : llvm::ArrayRef(E->getSubExprs(), E->getNumSubExprs()))711D |= C->getDependence();712return D;713}
714
715ExprDependence clang::computeDependence(GenericSelectionExpr *E,716bool ContainsUnexpandedPack) {717auto D = ContainsUnexpandedPack ? ExprDependence::UnexpandedPack718: ExprDependence::None;719for (auto *AE : E->getAssocExprs())720D |= AE->getDependence() & ExprDependence::Error;721
722if (E->isExprPredicate())723D |= E->getControllingExpr()->getDependence() & ExprDependence::Error;724else725D |= toExprDependenceAsWritten(726E->getControllingType()->getType()->getDependence());727
728if (E->isResultDependent())729return D | ExprDependence::TypeValueInstantiation;730return D | (E->getResultExpr()->getDependence() &731~ExprDependence::UnexpandedPack);732}
733
734ExprDependence clang::computeDependence(DesignatedInitExpr *E) {735auto Deps = E->getInit()->getDependence();736for (const auto &D : E->designators()) {737auto DesignatorDeps = ExprDependence::None;738if (D.isArrayDesignator())739DesignatorDeps |= E->getArrayIndex(D)->getDependence();740else if (D.isArrayRangeDesignator())741DesignatorDeps |= E->getArrayRangeStart(D)->getDependence() |742E->getArrayRangeEnd(D)->getDependence();743Deps |= DesignatorDeps;744if (DesignatorDeps & ExprDependence::TypeValue)745Deps |= ExprDependence::TypeValueInstantiation;746}747return Deps;748}
749
750ExprDependence clang::computeDependence(PseudoObjectExpr *O) {751auto D = O->getSyntacticForm()->getDependence();752for (auto *E : O->semantics())753D |= E->getDependence();754return D;755}
756
757ExprDependence clang::computeDependence(AtomicExpr *A) {758auto D = ExprDependence::None;759for (auto *E : llvm::ArrayRef(A->getSubExprs(), A->getNumSubExprs()))760D |= E->getDependence();761return D;762}
763
764ExprDependence clang::computeDependence(CXXNewExpr *E) {765auto D = toExprDependenceAsWritten(766E->getAllocatedTypeSourceInfo()->getType()->getDependence());767D |= toExprDependenceForImpliedType(E->getAllocatedType()->getDependence());768auto Size = E->getArraySize();769if (Size && *Size)770D |= turnTypeToValueDependence((*Size)->getDependence());771if (auto *I = E->getInitializer())772D |= turnTypeToValueDependence(I->getDependence());773for (auto *A : E->placement_arguments())774D |= turnTypeToValueDependence(A->getDependence());775return D;776}
777
778ExprDependence clang::computeDependence(CXXPseudoDestructorExpr *E) {779auto D = E->getBase()->getDependence();780if (auto *TSI = E->getDestroyedTypeInfo())781D |= toExprDependenceAsWritten(TSI->getType()->getDependence());782if (auto *ST = E->getScopeTypeInfo())783D |= turnTypeToValueDependence(784toExprDependenceAsWritten(ST->getType()->getDependence()));785if (auto *Q = E->getQualifier())786D |= toExprDependence(Q->getDependence() &787~NestedNameSpecifierDependence::Dependent);788return D;789}
790
791ExprDependence
792clang::computeDependence(OverloadExpr *E, bool KnownDependent,793bool KnownInstantiationDependent,794bool KnownContainsUnexpandedParameterPack) {795auto Deps = ExprDependence::None;796if (KnownDependent)797Deps |= ExprDependence::TypeValue;798if (KnownInstantiationDependent)799Deps |= ExprDependence::Instantiation;800if (KnownContainsUnexpandedParameterPack)801Deps |= ExprDependence::UnexpandedPack;802Deps |= getDependenceInExpr(E->getNameInfo());803if (auto *Q = E->getQualifier())804Deps |= toExprDependence(Q->getDependence() &805~NestedNameSpecifierDependence::Dependent);806for (auto *D : E->decls()) {807if (D->getDeclContext()->isDependentContext() ||808isa<UnresolvedUsingValueDecl>(D))809Deps |= ExprDependence::TypeValueInstantiation;810}811// If we have explicit template arguments, check for dependent812// template arguments and whether they contain any unexpanded pack813// expansions.814for (const auto &A : E->template_arguments())815Deps |= toExprDependence(A.getArgument().getDependence());816return Deps;817}
818
819ExprDependence clang::computeDependence(DependentScopeDeclRefExpr *E) {820auto D = ExprDependence::TypeValue;821D |= getDependenceInExpr(E->getNameInfo());822if (auto *Q = E->getQualifier())823D |= toExprDependence(Q->getDependence());824for (const auto &A : E->template_arguments())825D |= toExprDependence(A.getArgument().getDependence());826return D;827}
828
829ExprDependence clang::computeDependence(CXXConstructExpr *E) {830ExprDependence D =831toExprDependenceForImpliedType(E->getType()->getDependence());832for (auto *A : E->arguments())833D |= A->getDependence() & ~ExprDependence::Type;834return D;835}
836
837ExprDependence clang::computeDependence(CXXTemporaryObjectExpr *E) {838CXXConstructExpr *BaseE = E;839return toExprDependenceAsWritten(840E->getTypeSourceInfo()->getType()->getDependence()) |841computeDependence(BaseE);842}
843
844ExprDependence clang::computeDependence(CXXDefaultInitExpr *E) {845return E->getExpr()->getDependence();846}
847
848ExprDependence clang::computeDependence(CXXDefaultArgExpr *E) {849return E->getExpr()->getDependence();850}
851
852ExprDependence clang::computeDependence(LambdaExpr *E,853bool ContainsUnexpandedParameterPack) {854auto D = toExprDependenceForImpliedType(E->getType()->getDependence());855if (ContainsUnexpandedParameterPack)856D |= ExprDependence::UnexpandedPack;857return D;858}
859
860ExprDependence clang::computeDependence(CXXUnresolvedConstructExpr *E) {861auto D = ExprDependence::ValueInstantiation;862D |= toExprDependenceAsWritten(E->getTypeAsWritten()->getDependence());863D |= toExprDependenceForImpliedType(E->getType()->getDependence());864for (auto *A : E->arguments())865D |= A->getDependence() &866(ExprDependence::UnexpandedPack | ExprDependence::Error);867return D;868}
869
870ExprDependence clang::computeDependence(CXXDependentScopeMemberExpr *E) {871auto D = ExprDependence::TypeValueInstantiation;872if (!E->isImplicitAccess())873D |= E->getBase()->getDependence();874if (auto *Q = E->getQualifier())875D |= toExprDependence(Q->getDependence());876D |= getDependenceInExpr(E->getMemberNameInfo());877for (const auto &A : E->template_arguments())878D |= toExprDependence(A.getArgument().getDependence());879return D;880}
881
882ExprDependence clang::computeDependence(MaterializeTemporaryExpr *E) {883return E->getSubExpr()->getDependence();884}
885
886ExprDependence clang::computeDependence(CXXFoldExpr *E) {887auto D = ExprDependence::TypeValueInstantiation;888for (const auto *C : {E->getLHS(), E->getRHS()}) {889if (C)890D |= C->getDependence() & ~ExprDependence::UnexpandedPack;891}892return D;893}
894
895ExprDependence clang::computeDependence(CXXParenListInitExpr *E) {896auto D = ExprDependence::None;897for (const auto *A : E->getInitExprs())898D |= A->getDependence();899return D;900}
901
902ExprDependence clang::computeDependence(TypeTraitExpr *E) {903auto D = ExprDependence::None;904for (const auto *A : E->getArgs())905D |= toExprDependenceAsWritten(A->getType()->getDependence()) &906~ExprDependence::Type;907return D;908}
909
910ExprDependence clang::computeDependence(ConceptSpecializationExpr *E,911bool ValueDependent) {912auto TA = TemplateArgumentDependence::None;913const auto InterestingDeps = TemplateArgumentDependence::Instantiation |914TemplateArgumentDependence::UnexpandedPack;915for (const TemplateArgumentLoc &ArgLoc :916E->getTemplateArgsAsWritten()->arguments()) {917TA |= ArgLoc.getArgument().getDependence() & InterestingDeps;918if (TA == InterestingDeps)919break;920}921
922ExprDependence D =923ValueDependent ? ExprDependence::Value : ExprDependence::None;924auto Res = D | toExprDependence(TA);925if(!ValueDependent && E->getSatisfaction().ContainsErrors)926Res |= ExprDependence::Error;927return Res;928}
929
930ExprDependence clang::computeDependence(ObjCArrayLiteral *E) {931auto D = ExprDependence::None;932Expr **Elements = E->getElements();933for (unsigned I = 0, N = E->getNumElements(); I != N; ++I)934D |= turnTypeToValueDependence(Elements[I]->getDependence());935return D;936}
937
938ExprDependence clang::computeDependence(ObjCDictionaryLiteral *E) {939auto Deps = ExprDependence::None;940for (unsigned I = 0, N = E->getNumElements(); I < N; ++I) {941auto KV = E->getKeyValueElement(I);942auto KVDeps = turnTypeToValueDependence(KV.Key->getDependence() |943KV.Value->getDependence());944if (KV.EllipsisLoc.isValid())945KVDeps &= ~ExprDependence::UnexpandedPack;946Deps |= KVDeps;947}948return Deps;949}
950
951ExprDependence clang::computeDependence(ObjCMessageExpr *E) {952auto D = ExprDependence::None;953if (auto *R = E->getInstanceReceiver())954D |= R->getDependence();955else956D |= toExprDependenceForImpliedType(E->getType()->getDependence());957for (auto *A : E->arguments())958D |= A->getDependence();959return D;960}
961