xref: /freebsd-src/contrib/llvm-project/clang/lib/AST/ComputeDependence.cpp (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
15ffd83dbSDimitry Andric //===- ComputeDependence.cpp ----------------------------------------------===//
25ffd83dbSDimitry Andric //
35ffd83dbSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45ffd83dbSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55ffd83dbSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65ffd83dbSDimitry Andric //
75ffd83dbSDimitry Andric //===----------------------------------------------------------------------===//
85ffd83dbSDimitry Andric 
95ffd83dbSDimitry Andric #include "clang/AST/ComputeDependence.h"
105ffd83dbSDimitry Andric #include "clang/AST/Attr.h"
115ffd83dbSDimitry Andric #include "clang/AST/DeclCXX.h"
125ffd83dbSDimitry Andric #include "clang/AST/DeclarationName.h"
135ffd83dbSDimitry Andric #include "clang/AST/DependenceFlags.h"
145ffd83dbSDimitry Andric #include "clang/AST/Expr.h"
155ffd83dbSDimitry Andric #include "clang/AST/ExprCXX.h"
165ffd83dbSDimitry Andric #include "clang/AST/ExprConcepts.h"
175ffd83dbSDimitry Andric #include "clang/AST/ExprObjC.h"
185ffd83dbSDimitry Andric #include "clang/AST/ExprOpenMP.h"
195ffd83dbSDimitry Andric #include "clang/Basic/ExceptionSpecificationType.h"
205ffd83dbSDimitry Andric #include "llvm/ADT/ArrayRef.h"
215ffd83dbSDimitry Andric 
225ffd83dbSDimitry Andric using namespace clang;
235ffd83dbSDimitry Andric 
245ffd83dbSDimitry Andric ExprDependence clang::computeDependence(FullExpr *E) {
255ffd83dbSDimitry Andric   return E->getSubExpr()->getDependence();
265ffd83dbSDimitry Andric }
275ffd83dbSDimitry Andric 
285ffd83dbSDimitry Andric ExprDependence clang::computeDependence(OpaqueValueExpr *E) {
293b7f365eSDimitry Andric   auto D = toExprDependenceForImpliedType(E->getType()->getDependence());
305ffd83dbSDimitry Andric   if (auto *S = E->getSourceExpr())
315ffd83dbSDimitry Andric     D |= S->getDependence();
325ffd83dbSDimitry Andric   assert(!(D & ExprDependence::UnexpandedPack));
335ffd83dbSDimitry Andric   return D;
345ffd83dbSDimitry Andric }
355ffd83dbSDimitry Andric 
365ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ParenExpr *E) {
375ffd83dbSDimitry Andric   return E->getSubExpr()->getDependence();
385ffd83dbSDimitry Andric }
395ffd83dbSDimitry Andric 
40e8d8bef9SDimitry Andric ExprDependence clang::computeDependence(UnaryOperator *E,
41e8d8bef9SDimitry Andric                                         const ASTContext &Ctx) {
423b7f365eSDimitry Andric   ExprDependence Dep =
433b7f365eSDimitry Andric       // FIXME: Do we need to look at the type?
443b7f365eSDimitry Andric       toExprDependenceForImpliedType(E->getType()->getDependence()) |
455ffd83dbSDimitry Andric       E->getSubExpr()->getDependence();
46e8d8bef9SDimitry Andric 
47e8d8bef9SDimitry Andric   // C++ [temp.dep.constexpr]p5:
48e8d8bef9SDimitry Andric   //   An expression of the form & qualified-id where the qualified-id names a
49e8d8bef9SDimitry Andric   //   dependent member of the current instantiation is value-dependent. An
50e8d8bef9SDimitry Andric   //   expression of the form & cast-expression is also value-dependent if
51e8d8bef9SDimitry Andric   //   evaluating cast-expression as a core constant expression succeeds and
52e8d8bef9SDimitry Andric   //   the result of the evaluation refers to a templated entity that is an
53e8d8bef9SDimitry Andric   //   object with static or thread storage duration or a member function.
54e8d8bef9SDimitry Andric   //
55e8d8bef9SDimitry Andric   // What this amounts to is: constant-evaluate the operand and check whether it
56e8d8bef9SDimitry Andric   // refers to a templated entity other than a variable with local storage.
57e8d8bef9SDimitry Andric   if (Ctx.getLangOpts().CPlusPlus && E->getOpcode() == UO_AddrOf &&
58e8d8bef9SDimitry Andric       !(Dep & ExprDependence::Value)) {
59e8d8bef9SDimitry Andric     Expr::EvalResult Result;
60e8d8bef9SDimitry Andric     SmallVector<PartialDiagnosticAt, 8> Diag;
61e8d8bef9SDimitry Andric     Result.Diag = &Diag;
62e8d8bef9SDimitry Andric     // FIXME: This doesn't enforce the C++98 constant expression rules.
63e8d8bef9SDimitry Andric     if (E->getSubExpr()->EvaluateAsConstantExpr(Result, Ctx) && Diag.empty() &&
64e8d8bef9SDimitry Andric         Result.Val.isLValue()) {
65e8d8bef9SDimitry Andric       auto *VD = Result.Val.getLValueBase().dyn_cast<const ValueDecl *>();
66e8d8bef9SDimitry Andric       if (VD && VD->isTemplated()) {
67e8d8bef9SDimitry Andric         auto *VarD = dyn_cast<VarDecl>(VD);
68e8d8bef9SDimitry Andric         if (!VarD || !VarD->hasLocalStorage())
69e8d8bef9SDimitry Andric           Dep |= ExprDependence::Value;
70e8d8bef9SDimitry Andric       }
71e8d8bef9SDimitry Andric     }
72e8d8bef9SDimitry Andric   }
73e8d8bef9SDimitry Andric 
74e8d8bef9SDimitry Andric   return Dep;
755ffd83dbSDimitry Andric }
765ffd83dbSDimitry Andric 
775ffd83dbSDimitry Andric ExprDependence clang::computeDependence(UnaryExprOrTypeTraitExpr *E) {
785ffd83dbSDimitry Andric   // Never type-dependent (C++ [temp.dep.expr]p3).
795ffd83dbSDimitry Andric   // Value-dependent if the argument is type-dependent.
805ffd83dbSDimitry Andric   if (E->isArgumentType())
815ffd83dbSDimitry Andric     return turnTypeToValueDependence(
823b7f365eSDimitry Andric         toExprDependenceAsWritten(E->getArgumentType()->getDependence()));
835ffd83dbSDimitry Andric 
845ffd83dbSDimitry Andric   auto ArgDeps = E->getArgumentExpr()->getDependence();
855ffd83dbSDimitry Andric   auto Deps = ArgDeps & ~ExprDependence::TypeValue;
865ffd83dbSDimitry Andric   // Value-dependent if the argument is type-dependent.
875ffd83dbSDimitry Andric   if (ArgDeps & ExprDependence::Type)
885ffd83dbSDimitry Andric     Deps |= ExprDependence::Value;
895ffd83dbSDimitry Andric   // Check to see if we are in the situation where alignof(decl) should be
905ffd83dbSDimitry Andric   // dependent because decl's alignment is dependent.
915ffd83dbSDimitry Andric   auto ExprKind = E->getKind();
925ffd83dbSDimitry Andric   if (ExprKind != UETT_AlignOf && ExprKind != UETT_PreferredAlignOf)
935ffd83dbSDimitry Andric     return Deps;
945ffd83dbSDimitry Andric   if ((Deps & ExprDependence::Value) && (Deps & ExprDependence::Instantiation))
955ffd83dbSDimitry Andric     return Deps;
965ffd83dbSDimitry Andric 
975ffd83dbSDimitry Andric   auto *NoParens = E->getArgumentExpr()->IgnoreParens();
985ffd83dbSDimitry Andric   const ValueDecl *D = nullptr;
995ffd83dbSDimitry Andric   if (const auto *DRE = dyn_cast<DeclRefExpr>(NoParens))
1005ffd83dbSDimitry Andric     D = DRE->getDecl();
1015ffd83dbSDimitry Andric   else if (const auto *ME = dyn_cast<MemberExpr>(NoParens))
1025ffd83dbSDimitry Andric     D = ME->getMemberDecl();
1035ffd83dbSDimitry Andric   if (!D)
1045ffd83dbSDimitry Andric     return Deps;
1055ffd83dbSDimitry Andric   for (const auto *I : D->specific_attrs<AlignedAttr>()) {
1065ffd83dbSDimitry Andric     if (I->isAlignmentErrorDependent())
1075ffd83dbSDimitry Andric       Deps |= ExprDependence::Error;
1085ffd83dbSDimitry Andric     if (I->isAlignmentDependent())
1095ffd83dbSDimitry Andric       Deps |= ExprDependence::ValueInstantiation;
1105ffd83dbSDimitry Andric   }
1115ffd83dbSDimitry Andric   return Deps;
1125ffd83dbSDimitry Andric }
1135ffd83dbSDimitry Andric 
1145ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ArraySubscriptExpr *E) {
1155ffd83dbSDimitry Andric   return E->getLHS()->getDependence() | E->getRHS()->getDependence();
1165ffd83dbSDimitry Andric }
1175ffd83dbSDimitry Andric 
1185ffd83dbSDimitry Andric ExprDependence clang::computeDependence(MatrixSubscriptExpr *E) {
1195ffd83dbSDimitry Andric   return E->getBase()->getDependence() | E->getRowIdx()->getDependence() |
1205ffd83dbSDimitry Andric          (E->getColumnIdx() ? E->getColumnIdx()->getDependence()
1215ffd83dbSDimitry Andric                             : ExprDependence::None);
1225ffd83dbSDimitry Andric }
1235ffd83dbSDimitry Andric 
1245ffd83dbSDimitry Andric ExprDependence clang::computeDependence(CompoundLiteralExpr *E) {
1253b7f365eSDimitry Andric   return toExprDependenceAsWritten(
1263b7f365eSDimitry Andric              E->getTypeSourceInfo()->getType()->getDependence()) |
1273b7f365eSDimitry Andric          toExprDependenceForImpliedType(E->getType()->getDependence()) |
1285ffd83dbSDimitry Andric          turnTypeToValueDependence(E->getInitializer()->getDependence());
1295ffd83dbSDimitry Andric }
1305ffd83dbSDimitry Andric 
1313b7f365eSDimitry Andric ExprDependence clang::computeDependence(ImplicitCastExpr *E) {
1323b7f365eSDimitry Andric   // We model implicit conversions as combining the dependence of their
1333b7f365eSDimitry Andric   // subexpression, apart from its type, with the semantic portion of the
1343b7f365eSDimitry Andric   // target type.
1353b7f365eSDimitry Andric   ExprDependence D =
1363b7f365eSDimitry Andric       toExprDependenceForImpliedType(E->getType()->getDependence());
1373b7f365eSDimitry Andric   if (auto *S = E->getSubExpr())
1383b7f365eSDimitry Andric     D |= S->getDependence() & ~ExprDependence::Type;
1393b7f365eSDimitry Andric   return D;
1403b7f365eSDimitry Andric }
1413b7f365eSDimitry Andric 
1423b7f365eSDimitry Andric ExprDependence clang::computeDependence(ExplicitCastExpr *E) {
1435ffd83dbSDimitry Andric   // Cast expressions are type-dependent if the type is
1445ffd83dbSDimitry Andric   // dependent (C++ [temp.dep.expr]p3).
1455ffd83dbSDimitry Andric   // Cast expressions are value-dependent if the type is
1465ffd83dbSDimitry Andric   // dependent or if the subexpression is value-dependent.
1473b7f365eSDimitry Andric   //
1483b7f365eSDimitry Andric   // Note that we also need to consider the dependence of the actual type here,
1493b7f365eSDimitry Andric   // because when the type as written is a deduced type, that type is not
1503b7f365eSDimitry Andric   // dependent, but it may be deduced as a dependent type.
1513b7f365eSDimitry Andric   ExprDependence D =
1523b7f365eSDimitry Andric       toExprDependenceAsWritten(
1533b7f365eSDimitry Andric           cast<ExplicitCastExpr>(E)->getTypeAsWritten()->getDependence()) |
1543b7f365eSDimitry Andric       toExprDependenceForImpliedType(E->getType()->getDependence());
1555ffd83dbSDimitry Andric   if (auto *S = E->getSubExpr())
1565ffd83dbSDimitry Andric     D |= S->getDependence() & ~ExprDependence::Type;
1575ffd83dbSDimitry Andric   return D;
1585ffd83dbSDimitry Andric }
1595ffd83dbSDimitry Andric 
1605ffd83dbSDimitry Andric ExprDependence clang::computeDependence(BinaryOperator *E) {
1615ffd83dbSDimitry Andric   return E->getLHS()->getDependence() | E->getRHS()->getDependence();
1625ffd83dbSDimitry Andric }
1635ffd83dbSDimitry Andric 
1645ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ConditionalOperator *E) {
1655ffd83dbSDimitry Andric   // The type of the conditional operator depends on the type of the conditional
1665ffd83dbSDimitry Andric   // to support the GCC vector conditional extension. Additionally,
1675ffd83dbSDimitry Andric   // [temp.dep.expr] does specify state that this should be dependent on ALL sub
1685ffd83dbSDimitry Andric   // expressions.
1695ffd83dbSDimitry Andric   return E->getCond()->getDependence() | E->getLHS()->getDependence() |
1705ffd83dbSDimitry Andric          E->getRHS()->getDependence();
1715ffd83dbSDimitry Andric }
1725ffd83dbSDimitry Andric 
1735ffd83dbSDimitry Andric ExprDependence clang::computeDependence(BinaryConditionalOperator *E) {
1745ffd83dbSDimitry Andric   return E->getCommon()->getDependence() | E->getFalseExpr()->getDependence();
1755ffd83dbSDimitry Andric }
1765ffd83dbSDimitry Andric 
1775ffd83dbSDimitry Andric ExprDependence clang::computeDependence(StmtExpr *E, unsigned TemplateDepth) {
1783b7f365eSDimitry Andric   auto D = toExprDependenceForImpliedType(E->getType()->getDependence());
1795ffd83dbSDimitry Andric   // Propagate dependence of the result.
1805ffd83dbSDimitry Andric   if (const auto *CompoundExprResult =
1815ffd83dbSDimitry Andric           dyn_cast_or_null<ValueStmt>(E->getSubStmt()->getStmtExprResult()))
1825ffd83dbSDimitry Andric     if (const Expr *ResultExpr = CompoundExprResult->getExprStmt())
1835ffd83dbSDimitry Andric       D |= ResultExpr->getDependence();
1845ffd83dbSDimitry Andric   // Note: we treat a statement-expression in a dependent context as always
1855ffd83dbSDimitry Andric   // being value- and instantiation-dependent. This matches the behavior of
1865ffd83dbSDimitry Andric   // lambda-expressions and GCC.
1875ffd83dbSDimitry Andric   if (TemplateDepth)
1885ffd83dbSDimitry Andric     D |= ExprDependence::ValueInstantiation;
1895ffd83dbSDimitry Andric   // A param pack cannot be expanded over stmtexpr boundaries.
1905ffd83dbSDimitry Andric   return D & ~ExprDependence::UnexpandedPack;
1915ffd83dbSDimitry Andric }
1925ffd83dbSDimitry Andric 
1935ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ConvertVectorExpr *E) {
1943b7f365eSDimitry Andric   auto D = toExprDependenceAsWritten(
1953b7f365eSDimitry Andric                E->getTypeSourceInfo()->getType()->getDependence()) |
1965ffd83dbSDimitry Andric            E->getSrcExpr()->getDependence();
1975ffd83dbSDimitry Andric   if (!E->getType()->isDependentType())
1985ffd83dbSDimitry Andric     D &= ~ExprDependence::Type;
1995ffd83dbSDimitry Andric   return D;
2005ffd83dbSDimitry Andric }
2015ffd83dbSDimitry Andric 
2025ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ChooseExpr *E) {
2035ffd83dbSDimitry Andric   if (E->isConditionDependent())
2045ffd83dbSDimitry Andric     return ExprDependence::TypeValueInstantiation |
2055ffd83dbSDimitry Andric            E->getCond()->getDependence() | E->getLHS()->getDependence() |
2065ffd83dbSDimitry Andric            E->getRHS()->getDependence();
2075ffd83dbSDimitry Andric 
2085ffd83dbSDimitry Andric   auto Cond = E->getCond()->getDependence();
2095ffd83dbSDimitry Andric   auto Active = E->getLHS()->getDependence();
2105ffd83dbSDimitry Andric   auto Inactive = E->getRHS()->getDependence();
2115ffd83dbSDimitry Andric   if (!E->isConditionTrue())
2125ffd83dbSDimitry Andric     std::swap(Active, Inactive);
2135ffd83dbSDimitry Andric   // Take type- and value- dependency from the active branch. Propagate all
2145ffd83dbSDimitry Andric   // other flags from all branches.
2155ffd83dbSDimitry Andric   return (Active & ExprDependence::TypeValue) |
2165ffd83dbSDimitry Andric          ((Cond | Active | Inactive) & ~ExprDependence::TypeValue);
2175ffd83dbSDimitry Andric }
2185ffd83dbSDimitry Andric 
2195ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ParenListExpr *P) {
2205ffd83dbSDimitry Andric   auto D = ExprDependence::None;
2215ffd83dbSDimitry Andric   for (auto *E : P->exprs())
2225ffd83dbSDimitry Andric     D |= E->getDependence();
2235ffd83dbSDimitry Andric   return D;
2245ffd83dbSDimitry Andric }
2255ffd83dbSDimitry Andric 
2265ffd83dbSDimitry Andric ExprDependence clang::computeDependence(VAArgExpr *E) {
2273b7f365eSDimitry Andric   auto D = toExprDependenceAsWritten(
2283b7f365eSDimitry Andric                E->getWrittenTypeInfo()->getType()->getDependence()) |
2295ffd83dbSDimitry Andric            (E->getSubExpr()->getDependence() & ~ExprDependence::Type);
23006c3fb27SDimitry Andric   return D;
2315ffd83dbSDimitry Andric }
2325ffd83dbSDimitry Andric 
2335ffd83dbSDimitry Andric ExprDependence clang::computeDependence(NoInitExpr *E) {
2343b7f365eSDimitry Andric   return toExprDependenceForImpliedType(E->getType()->getDependence()) &
2355ffd83dbSDimitry Andric          (ExprDependence::Instantiation | ExprDependence::Error);
2365ffd83dbSDimitry Andric }
2375ffd83dbSDimitry Andric 
2385ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ArrayInitLoopExpr *E) {
2395ffd83dbSDimitry Andric   auto D = E->getCommonExpr()->getDependence() |
2405ffd83dbSDimitry Andric            E->getSubExpr()->getDependence() | ExprDependence::Instantiation;
2415ffd83dbSDimitry Andric   if (!E->getType()->isInstantiationDependentType())
2425ffd83dbSDimitry Andric     D &= ~ExprDependence::Instantiation;
2435ffd83dbSDimitry Andric   return turnTypeToValueDependence(D);
2445ffd83dbSDimitry Andric }
2455ffd83dbSDimitry Andric 
2465ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ImplicitValueInitExpr *E) {
2473b7f365eSDimitry Andric   return toExprDependenceForImpliedType(E->getType()->getDependence()) &
2485ffd83dbSDimitry Andric          ExprDependence::Instantiation;
2495ffd83dbSDimitry Andric }
2505ffd83dbSDimitry Andric 
2515ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ExtVectorElementExpr *E) {
2525ffd83dbSDimitry Andric   return E->getBase()->getDependence();
2535ffd83dbSDimitry Andric }
2545ffd83dbSDimitry Andric 
2555ffd83dbSDimitry Andric ExprDependence clang::computeDependence(BlockExpr *E) {
2563b7f365eSDimitry Andric   auto D = toExprDependenceForImpliedType(E->getType()->getDependence());
2575ffd83dbSDimitry Andric   if (E->getBlockDecl()->isDependentContext())
2585ffd83dbSDimitry Andric     D |= ExprDependence::Instantiation;
2593b7f365eSDimitry Andric   return D;
2605ffd83dbSDimitry Andric }
2615ffd83dbSDimitry Andric 
2625ffd83dbSDimitry Andric ExprDependence clang::computeDependence(AsTypeExpr *E) {
2633b7f365eSDimitry Andric   // FIXME: AsTypeExpr doesn't store the type as written. Assume the expression
2643b7f365eSDimitry Andric   // type has identical sugar for now, so is a type-as-written.
2653b7f365eSDimitry Andric   auto D = toExprDependenceAsWritten(E->getType()->getDependence()) |
2665ffd83dbSDimitry Andric            E->getSrcExpr()->getDependence();
2675ffd83dbSDimitry Andric   if (!E->getType()->isDependentType())
2685ffd83dbSDimitry Andric     D &= ~ExprDependence::Type;
2695ffd83dbSDimitry Andric   return D;
2705ffd83dbSDimitry Andric }
2715ffd83dbSDimitry Andric 
2725ffd83dbSDimitry Andric ExprDependence clang::computeDependence(CXXRewrittenBinaryOperator *E) {
2735ffd83dbSDimitry Andric   return E->getSemanticForm()->getDependence();
2745ffd83dbSDimitry Andric }
2755ffd83dbSDimitry Andric 
2765ffd83dbSDimitry Andric ExprDependence clang::computeDependence(CXXStdInitializerListExpr *E) {
2775ffd83dbSDimitry Andric   auto D = turnTypeToValueDependence(E->getSubExpr()->getDependence());
2783b7f365eSDimitry Andric   D |= toExprDependenceForImpliedType(E->getType()->getDependence());
2795ffd83dbSDimitry Andric   return D;
2805ffd83dbSDimitry Andric }
2815ffd83dbSDimitry Andric 
2825ffd83dbSDimitry Andric ExprDependence clang::computeDependence(CXXTypeidExpr *E) {
2835ffd83dbSDimitry Andric   auto D = ExprDependence::None;
2845ffd83dbSDimitry Andric   if (E->isTypeOperand())
2853b7f365eSDimitry Andric     D = toExprDependenceAsWritten(
2865ffd83dbSDimitry Andric         E->getTypeOperandSourceInfo()->getType()->getDependence());
2875ffd83dbSDimitry Andric   else
2885ffd83dbSDimitry Andric     D = turnTypeToValueDependence(E->getExprOperand()->getDependence());
2895ffd83dbSDimitry Andric   // typeid is never type-dependent (C++ [temp.dep.expr]p4)
2905ffd83dbSDimitry Andric   return D & ~ExprDependence::Type;
2915ffd83dbSDimitry Andric }
2925ffd83dbSDimitry Andric 
2935ffd83dbSDimitry Andric ExprDependence clang::computeDependence(MSPropertyRefExpr *E) {
2945ffd83dbSDimitry Andric   return E->getBaseExpr()->getDependence() & ~ExprDependence::Type;
2955ffd83dbSDimitry Andric }
2965ffd83dbSDimitry Andric 
2975ffd83dbSDimitry Andric ExprDependence clang::computeDependence(MSPropertySubscriptExpr *E) {
2985ffd83dbSDimitry Andric   return E->getIdx()->getDependence();
2995ffd83dbSDimitry Andric }
3005ffd83dbSDimitry Andric 
3015ffd83dbSDimitry Andric ExprDependence clang::computeDependence(CXXUuidofExpr *E) {
3025ffd83dbSDimitry Andric   if (E->isTypeOperand())
3033b7f365eSDimitry Andric     return turnTypeToValueDependence(toExprDependenceAsWritten(
3045ffd83dbSDimitry Andric         E->getTypeOperandSourceInfo()->getType()->getDependence()));
3055ffd83dbSDimitry Andric 
3065ffd83dbSDimitry Andric   return turnTypeToValueDependence(E->getExprOperand()->getDependence());
3075ffd83dbSDimitry Andric }
3085ffd83dbSDimitry Andric 
3095ffd83dbSDimitry Andric ExprDependence clang::computeDependence(CXXThisExpr *E) {
3105ffd83dbSDimitry Andric   // 'this' is type-dependent if the class type of the enclosing
3115ffd83dbSDimitry Andric   // member function is dependent (C++ [temp.dep.expr]p2)
3123b7f365eSDimitry Andric   auto D = toExprDependenceForImpliedType(E->getType()->getDependence());
313*0fca6ea1SDimitry Andric 
314*0fca6ea1SDimitry Andric   // If a lambda with an explicit object parameter captures '*this', then
315*0fca6ea1SDimitry Andric   // 'this' now refers to the captured copy of lambda, and if the lambda
316*0fca6ea1SDimitry Andric   // is type-dependent, so is the object and thus 'this'.
317*0fca6ea1SDimitry Andric   //
318*0fca6ea1SDimitry Andric   // Note: The standard does not mention this case explicitly, but we need
319*0fca6ea1SDimitry Andric   // to do this so we can mark NSDM accesses as dependent.
320*0fca6ea1SDimitry Andric   if (E->isCapturedByCopyInLambdaWithExplicitObjectParameter())
321*0fca6ea1SDimitry Andric     D |= ExprDependence::Type;
322*0fca6ea1SDimitry Andric 
3235ffd83dbSDimitry Andric   assert(!(D & ExprDependence::UnexpandedPack));
3245ffd83dbSDimitry Andric   return D;
3255ffd83dbSDimitry Andric }
3265ffd83dbSDimitry Andric 
3275ffd83dbSDimitry Andric ExprDependence clang::computeDependence(CXXThrowExpr *E) {
3285ffd83dbSDimitry Andric   auto *Op = E->getSubExpr();
3295ffd83dbSDimitry Andric   if (!Op)
3305ffd83dbSDimitry Andric     return ExprDependence::None;
3315ffd83dbSDimitry Andric   return Op->getDependence() & ~ExprDependence::TypeValue;
3325ffd83dbSDimitry Andric }
3335ffd83dbSDimitry Andric 
3345ffd83dbSDimitry Andric ExprDependence clang::computeDependence(CXXBindTemporaryExpr *E) {
3355ffd83dbSDimitry Andric   return E->getSubExpr()->getDependence();
3365ffd83dbSDimitry Andric }
3375ffd83dbSDimitry Andric 
3385ffd83dbSDimitry Andric ExprDependence clang::computeDependence(CXXScalarValueInitExpr *E) {
3393b7f365eSDimitry Andric   auto D = toExprDependenceForImpliedType(E->getType()->getDependence());
3403b7f365eSDimitry Andric   if (auto *TSI = E->getTypeSourceInfo())
3413b7f365eSDimitry Andric     D |= toExprDependenceAsWritten(TSI->getType()->getDependence());
3423b7f365eSDimitry Andric   return D;
3435ffd83dbSDimitry Andric }
3445ffd83dbSDimitry Andric 
3455ffd83dbSDimitry Andric ExprDependence clang::computeDependence(CXXDeleteExpr *E) {
3465ffd83dbSDimitry Andric   return turnTypeToValueDependence(E->getArgument()->getDependence());
3475ffd83dbSDimitry Andric }
3485ffd83dbSDimitry Andric 
3495ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ArrayTypeTraitExpr *E) {
3503b7f365eSDimitry Andric   auto D = toExprDependenceAsWritten(E->getQueriedType()->getDependence());
3515ffd83dbSDimitry Andric   if (auto *Dim = E->getDimensionExpression())
3525ffd83dbSDimitry Andric     D |= Dim->getDependence();
3535ffd83dbSDimitry Andric   return turnTypeToValueDependence(D);
3545ffd83dbSDimitry Andric }
3555ffd83dbSDimitry Andric 
3565ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ExpressionTraitExpr *E) {
3575ffd83dbSDimitry Andric   // Never type-dependent.
3585ffd83dbSDimitry Andric   auto D = E->getQueriedExpression()->getDependence() & ~ExprDependence::Type;
3595ffd83dbSDimitry Andric   // Value-dependent if the argument is type-dependent.
3605ffd83dbSDimitry Andric   if (E->getQueriedExpression()->isTypeDependent())
3615ffd83dbSDimitry Andric     D |= ExprDependence::Value;
3625ffd83dbSDimitry Andric   return D;
3635ffd83dbSDimitry Andric }
3645ffd83dbSDimitry Andric 
3655ffd83dbSDimitry Andric ExprDependence clang::computeDependence(CXXNoexceptExpr *E, CanThrowResult CT) {
3665ffd83dbSDimitry Andric   auto D = E->getOperand()->getDependence() & ~ExprDependence::TypeValue;
3675ffd83dbSDimitry Andric   if (CT == CT_Dependent)
3685ffd83dbSDimitry Andric     D |= ExprDependence::ValueInstantiation;
3695ffd83dbSDimitry Andric   return D;
3705ffd83dbSDimitry Andric }
3715ffd83dbSDimitry Andric 
3725ffd83dbSDimitry Andric ExprDependence clang::computeDependence(PackExpansionExpr *E) {
3735ffd83dbSDimitry Andric   return (E->getPattern()->getDependence() & ~ExprDependence::UnexpandedPack) |
3745ffd83dbSDimitry Andric          ExprDependence::TypeValueInstantiation;
3755ffd83dbSDimitry Andric }
3765ffd83dbSDimitry Andric 
377*0fca6ea1SDimitry Andric ExprDependence clang::computeDependence(PackIndexingExpr *E) {
378*0fca6ea1SDimitry Andric 
379*0fca6ea1SDimitry Andric   ExprDependence PatternDep = E->getPackIdExpression()->getDependence() &
380*0fca6ea1SDimitry Andric                               ~ExprDependence::UnexpandedPack;
381*0fca6ea1SDimitry Andric 
382*0fca6ea1SDimitry Andric   ExprDependence D = E->getIndexExpr()->getDependence();
383*0fca6ea1SDimitry Andric   if (D & ExprDependence::TypeValueInstantiation)
384*0fca6ea1SDimitry Andric     D |= E->getIndexExpr()->getDependence() | PatternDep |
385*0fca6ea1SDimitry Andric          ExprDependence::Instantiation;
386*0fca6ea1SDimitry Andric 
387*0fca6ea1SDimitry Andric   ArrayRef<Expr *> Exprs = E->getExpressions();
388*0fca6ea1SDimitry Andric   if (Exprs.empty())
389*0fca6ea1SDimitry Andric     D |= PatternDep | ExprDependence::Instantiation;
390*0fca6ea1SDimitry Andric 
391*0fca6ea1SDimitry Andric   else if (!E->getIndexExpr()->isInstantiationDependent()) {
392*0fca6ea1SDimitry Andric     std::optional<unsigned> Index = E->getSelectedIndex();
393*0fca6ea1SDimitry Andric     assert(Index && *Index < Exprs.size() && "pack index out of bound");
394*0fca6ea1SDimitry Andric     D |= Exprs[*Index]->getDependence();
395*0fca6ea1SDimitry Andric   }
396*0fca6ea1SDimitry Andric   return D;
397*0fca6ea1SDimitry Andric }
398*0fca6ea1SDimitry Andric 
3995ffd83dbSDimitry Andric ExprDependence clang::computeDependence(SubstNonTypeTemplateParmExpr *E) {
4005ffd83dbSDimitry Andric   return E->getReplacement()->getDependence();
4015ffd83dbSDimitry Andric }
4025ffd83dbSDimitry Andric 
4035ffd83dbSDimitry Andric ExprDependence clang::computeDependence(CoroutineSuspendExpr *E) {
4045ffd83dbSDimitry Andric   if (auto *Resume = E->getResumeExpr())
4055ffd83dbSDimitry Andric     return (Resume->getDependence() &
4065ffd83dbSDimitry Andric             (ExprDependence::TypeValue | ExprDependence::Error)) |
4075ffd83dbSDimitry Andric            (E->getCommonExpr()->getDependence() & ~ExprDependence::TypeValue);
4085ffd83dbSDimitry Andric   return E->getCommonExpr()->getDependence() |
4095ffd83dbSDimitry Andric          ExprDependence::TypeValueInstantiation;
4105ffd83dbSDimitry Andric }
4115ffd83dbSDimitry Andric 
4125ffd83dbSDimitry Andric ExprDependence clang::computeDependence(DependentCoawaitExpr *E) {
4135ffd83dbSDimitry Andric   return E->getOperand()->getDependence() |
4145ffd83dbSDimitry Andric          ExprDependence::TypeValueInstantiation;
4155ffd83dbSDimitry Andric }
4165ffd83dbSDimitry Andric 
4175ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ObjCBoxedExpr *E) {
4185ffd83dbSDimitry Andric   return E->getSubExpr()->getDependence();
4195ffd83dbSDimitry Andric }
4205ffd83dbSDimitry Andric 
4215ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ObjCEncodeExpr *E) {
4223b7f365eSDimitry Andric   return toExprDependenceAsWritten(E->getEncodedType()->getDependence());
4235ffd83dbSDimitry Andric }
4245ffd83dbSDimitry Andric 
4255ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ObjCIvarRefExpr *E) {
4265ffd83dbSDimitry Andric   return turnTypeToValueDependence(E->getBase()->getDependence());
4275ffd83dbSDimitry Andric }
4285ffd83dbSDimitry Andric 
4295ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ObjCPropertyRefExpr *E) {
4305ffd83dbSDimitry Andric   if (E->isObjectReceiver())
4315ffd83dbSDimitry Andric     return E->getBase()->getDependence() & ~ExprDependence::Type;
4325ffd83dbSDimitry Andric   if (E->isSuperReceiver())
4333b7f365eSDimitry Andric     return toExprDependenceForImpliedType(
4343b7f365eSDimitry Andric                E->getSuperReceiverType()->getDependence()) &
4355ffd83dbSDimitry Andric            ~ExprDependence::TypeValue;
4365ffd83dbSDimitry Andric   assert(E->isClassReceiver());
4375ffd83dbSDimitry Andric   return ExprDependence::None;
4385ffd83dbSDimitry Andric }
4395ffd83dbSDimitry Andric 
4405ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ObjCSubscriptRefExpr *E) {
4415ffd83dbSDimitry Andric   return E->getBaseExpr()->getDependence() | E->getKeyExpr()->getDependence();
4425ffd83dbSDimitry Andric }
4435ffd83dbSDimitry Andric 
4445ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ObjCIsaExpr *E) {
4455ffd83dbSDimitry Andric   return E->getBase()->getDependence() & ~ExprDependence::Type &
4465ffd83dbSDimitry Andric          ~ExprDependence::UnexpandedPack;
4475ffd83dbSDimitry Andric }
4485ffd83dbSDimitry Andric 
4495ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ObjCIndirectCopyRestoreExpr *E) {
4505ffd83dbSDimitry Andric   return E->getSubExpr()->getDependence();
4515ffd83dbSDimitry Andric }
4525ffd83dbSDimitry Andric 
453*0fca6ea1SDimitry Andric ExprDependence clang::computeDependence(ArraySectionExpr *E) {
4545ffd83dbSDimitry Andric   auto D = E->getBase()->getDependence();
4555ffd83dbSDimitry Andric   if (auto *LB = E->getLowerBound())
4565ffd83dbSDimitry Andric     D |= LB->getDependence();
4575ffd83dbSDimitry Andric   if (auto *Len = E->getLength())
4585ffd83dbSDimitry Andric     D |= Len->getDependence();
459*0fca6ea1SDimitry Andric 
460*0fca6ea1SDimitry Andric   if (E->isOMPArraySection()) {
461*0fca6ea1SDimitry Andric     if (auto *Stride = E->getStride())
462*0fca6ea1SDimitry Andric       D |= Stride->getDependence();
463*0fca6ea1SDimitry Andric   }
4645ffd83dbSDimitry Andric   return D;
4655ffd83dbSDimitry Andric }
4665ffd83dbSDimitry Andric 
4675ffd83dbSDimitry Andric ExprDependence clang::computeDependence(OMPArrayShapingExpr *E) {
4683b7f365eSDimitry Andric   auto D = E->getBase()->getDependence();
4695ffd83dbSDimitry Andric   for (Expr *Dim: E->getDimensions())
4705ffd83dbSDimitry Andric     if (Dim)
4713b7f365eSDimitry Andric       D |= turnValueToTypeDependence(Dim->getDependence());
4725ffd83dbSDimitry Andric   return D;
4735ffd83dbSDimitry Andric }
4745ffd83dbSDimitry Andric 
4755ffd83dbSDimitry Andric ExprDependence clang::computeDependence(OMPIteratorExpr *E) {
4763b7f365eSDimitry Andric   auto D = toExprDependenceForImpliedType(E->getType()->getDependence());
4775ffd83dbSDimitry Andric   for (unsigned I = 0, End = E->numOfIterators(); I < End; ++I) {
4783b7f365eSDimitry Andric     if (auto *DD = cast_or_null<DeclaratorDecl>(E->getIteratorDecl(I))) {
4793b7f365eSDimitry Andric       // If the type is omitted, it's 'int', and is not dependent in any way.
4803b7f365eSDimitry Andric       if (auto *TSI = DD->getTypeSourceInfo()) {
4813b7f365eSDimitry Andric         D |= toExprDependenceAsWritten(TSI->getType()->getDependence());
4823b7f365eSDimitry Andric       }
4833b7f365eSDimitry Andric     }
4845ffd83dbSDimitry Andric     OMPIteratorExpr::IteratorRange IR = E->getIteratorRange(I);
4855ffd83dbSDimitry Andric     if (Expr *BE = IR.Begin)
4865ffd83dbSDimitry Andric       D |= BE->getDependence();
4875ffd83dbSDimitry Andric     if (Expr *EE = IR.End)
4885ffd83dbSDimitry Andric       D |= EE->getDependence();
4895ffd83dbSDimitry Andric     if (Expr *SE = IR.Step)
4905ffd83dbSDimitry Andric       D |= SE->getDependence();
4915ffd83dbSDimitry Andric   }
4925ffd83dbSDimitry Andric   return D;
4935ffd83dbSDimitry Andric }
4945ffd83dbSDimitry Andric 
4955ffd83dbSDimitry Andric /// Compute the type-, value-, and instantiation-dependence of a
4965ffd83dbSDimitry Andric /// declaration reference
4975ffd83dbSDimitry Andric /// based on the declaration being referenced.
4985ffd83dbSDimitry Andric ExprDependence clang::computeDependence(DeclRefExpr *E, const ASTContext &Ctx) {
4995ffd83dbSDimitry Andric   auto Deps = ExprDependence::None;
5005ffd83dbSDimitry Andric 
5015ffd83dbSDimitry Andric   if (auto *NNS = E->getQualifier())
5025ffd83dbSDimitry Andric     Deps |= toExprDependence(NNS->getDependence() &
5035ffd83dbSDimitry Andric                              ~NestedNameSpecifierDependence::Dependent);
5045ffd83dbSDimitry Andric 
5055ffd83dbSDimitry Andric   if (auto *FirstArg = E->getTemplateArgs()) {
5065ffd83dbSDimitry Andric     unsigned NumArgs = E->getNumTemplateArgs();
5075ffd83dbSDimitry Andric     for (auto *Arg = FirstArg, *End = FirstArg + NumArgs; Arg < End; ++Arg)
5085ffd83dbSDimitry Andric       Deps |= toExprDependence(Arg->getArgument().getDependence());
5095ffd83dbSDimitry Andric   }
5105ffd83dbSDimitry Andric 
5115ffd83dbSDimitry Andric   auto *Decl = E->getDecl();
5125ffd83dbSDimitry Andric   auto Type = E->getType();
5135ffd83dbSDimitry Andric 
5145ffd83dbSDimitry Andric   if (Decl->isParameterPack())
5155ffd83dbSDimitry Andric     Deps |= ExprDependence::UnexpandedPack;
5163b7f365eSDimitry Andric   Deps |= toExprDependenceForImpliedType(Type->getDependence()) &
5173b7f365eSDimitry Andric           ExprDependence::Error;
5185ffd83dbSDimitry Andric 
519e8d8bef9SDimitry Andric   // C++ [temp.dep.expr]p3:
5205ffd83dbSDimitry Andric   //   An id-expression is type-dependent if it contains:
5215ffd83dbSDimitry Andric 
522e8d8bef9SDimitry Andric   //    - an identifier associated by name lookup with one or more declarations
523e8d8bef9SDimitry Andric   //      declared with a dependent type
5245f757f3fSDimitry Andric   //    - an identifier associated by name lookup with an entity captured by
5255f757f3fSDimitry Andric   //    copy ([expr.prim.lambda.capture])
5265f757f3fSDimitry Andric   //      in a lambda-expression that has an explicit object parameter whose
5275f757f3fSDimitry Andric   //      type is dependent ([dcl.fct]),
528e8d8bef9SDimitry Andric   //
529e8d8bef9SDimitry Andric   // [The "or more" case is not modeled as a DeclRefExpr. There are a bunch
530e8d8bef9SDimitry Andric   // more bullets here that we handle by treating the declaration as having a
531e8d8bef9SDimitry Andric   // dependent type if they involve a placeholder type that can't be deduced.]
5325ffd83dbSDimitry Andric   if (Type->isDependentType())
5338d0cab88SDimitry Andric     Deps |= ExprDependence::TypeValueInstantiation;
5345ffd83dbSDimitry Andric   else if (Type->isInstantiationDependentType())
5355ffd83dbSDimitry Andric     Deps |= ExprDependence::Instantiation;
5365ffd83dbSDimitry Andric 
5375f757f3fSDimitry Andric   //    - an identifier associated by name lookup with an entity captured by
5385f757f3fSDimitry Andric   //    copy ([expr.prim.lambda.capture])
5395f757f3fSDimitry Andric   if (E->isCapturedByCopyInLambdaWithExplicitObjectParameter())
5405f757f3fSDimitry Andric     Deps |= ExprDependence::Type;
5415f757f3fSDimitry Andric 
542e8d8bef9SDimitry Andric   //    - a conversion-function-id that specifies a dependent type
5435ffd83dbSDimitry Andric   if (Decl->getDeclName().getNameKind() ==
5445ffd83dbSDimitry Andric       DeclarationName::CXXConversionFunctionName) {
5455ffd83dbSDimitry Andric     QualType T = Decl->getDeclName().getCXXNameType();
5465ffd83dbSDimitry Andric     if (T->isDependentType())
5475ffd83dbSDimitry Andric       return Deps | ExprDependence::TypeValueInstantiation;
5485ffd83dbSDimitry Andric 
5495ffd83dbSDimitry Andric     if (T->isInstantiationDependentType())
5505ffd83dbSDimitry Andric       Deps |= ExprDependence::Instantiation;
5515ffd83dbSDimitry Andric   }
5525ffd83dbSDimitry Andric 
553e8d8bef9SDimitry Andric   //   - a template-id that is dependent,
554e8d8bef9SDimitry Andric   //   - a nested-name-specifier or a qualified-id that names a member of an
555e8d8bef9SDimitry Andric   //     unknown specialization
556e8d8bef9SDimitry Andric   //   [These are not modeled as DeclRefExprs.]
557e8d8bef9SDimitry Andric 
558e8d8bef9SDimitry Andric   //   or if it names a dependent member of the current instantiation that is a
559e8d8bef9SDimitry Andric   //   static data member of type "array of unknown bound of T" for some T
560e8d8bef9SDimitry Andric   //   [handled below].
561e8d8bef9SDimitry Andric 
562e8d8bef9SDimitry Andric   // C++ [temp.dep.constexpr]p2:
563e8d8bef9SDimitry Andric   //  An id-expression is value-dependent if:
564e8d8bef9SDimitry Andric 
565e8d8bef9SDimitry Andric   //    - it is type-dependent [handled above]
566e8d8bef9SDimitry Andric 
567e8d8bef9SDimitry Andric   //    - it is the name of a non-type template parameter,
5685ffd83dbSDimitry Andric   if (isa<NonTypeTemplateParmDecl>(Decl))
5695ffd83dbSDimitry Andric     return Deps | ExprDependence::ValueInstantiation;
5705ffd83dbSDimitry Andric 
571e8d8bef9SDimitry Andric   //   - it names a potentially-constant variable that is initialized with an
572e8d8bef9SDimitry Andric   //     expression that is value-dependent
573e8d8bef9SDimitry Andric   if (const auto *Var = dyn_cast<VarDecl>(Decl)) {
574e8d8bef9SDimitry Andric     if (const Expr *Init = Var->getAnyInitializer()) {
575e8d8bef9SDimitry Andric       if (Init->containsErrors())
576e8d8bef9SDimitry Andric         Deps |= ExprDependence::Error;
5778d0cab88SDimitry Andric 
5788d0cab88SDimitry Andric       if (Var->mightBeUsableInConstantExpressions(Ctx) &&
5798d0cab88SDimitry Andric           Init->isValueDependent())
5808d0cab88SDimitry Andric         Deps |= ExprDependence::ValueInstantiation;
5815ffd83dbSDimitry Andric     }
5825ffd83dbSDimitry Andric 
583e8d8bef9SDimitry Andric     // - it names a static data member that is a dependent member of the
584e8d8bef9SDimitry Andric     //   current instantiation and is not initialized in a member-declarator,
5855ffd83dbSDimitry Andric     if (Var->isStaticDataMember() &&
586e8d8bef9SDimitry Andric         Var->getDeclContext()->isDependentContext() &&
587e8d8bef9SDimitry Andric         !Var->getFirstDecl()->hasInit()) {
588e8d8bef9SDimitry Andric       const VarDecl *First = Var->getFirstDecl();
589e8d8bef9SDimitry Andric       TypeSourceInfo *TInfo = First->getTypeSourceInfo();
590e8d8bef9SDimitry Andric       if (TInfo->getType()->isIncompleteArrayType()) {
591e8d8bef9SDimitry Andric         Deps |= ExprDependence::TypeValueInstantiation;
592e8d8bef9SDimitry Andric       } else if (!First->hasInit()) {
5935ffd83dbSDimitry Andric         Deps |= ExprDependence::ValueInstantiation;
594e8d8bef9SDimitry Andric       }
5955ffd83dbSDimitry Andric     }
5965ffd83dbSDimitry Andric 
5975ffd83dbSDimitry Andric     return Deps;
5985ffd83dbSDimitry Andric   }
5995ffd83dbSDimitry Andric 
600e8d8bef9SDimitry Andric   //   - it names a static member function that is a dependent member of the
601e8d8bef9SDimitry Andric   //     current instantiation
602e8d8bef9SDimitry Andric   //
603e8d8bef9SDimitry Andric   // FIXME: It's unclear that the restriction to static members here has any
604e8d8bef9SDimitry Andric   // effect: any use of a non-static member function name requires either
605e8d8bef9SDimitry Andric   // forming a pointer-to-member or providing an object parameter, either of
606e8d8bef9SDimitry Andric   // which makes the overall expression value-dependent.
607e8d8bef9SDimitry Andric   if (auto *MD = dyn_cast<CXXMethodDecl>(Decl)) {
608e8d8bef9SDimitry Andric     if (MD->isStatic() && Decl->getDeclContext()->isDependentContext())
6095ffd83dbSDimitry Andric       Deps |= ExprDependence::ValueInstantiation;
610e8d8bef9SDimitry Andric   }
611e8d8bef9SDimitry Andric 
6125ffd83dbSDimitry Andric   return Deps;
6135ffd83dbSDimitry Andric }
6145ffd83dbSDimitry Andric 
6155ffd83dbSDimitry Andric ExprDependence clang::computeDependence(RecoveryExpr *E) {
6165ffd83dbSDimitry Andric   // RecoveryExpr is
6175ffd83dbSDimitry Andric   //   - always value-dependent, and therefore instantiation dependent
6185ffd83dbSDimitry Andric   //   - contains errors (ExprDependence::Error), by definition
6195ffd83dbSDimitry Andric   //   - type-dependent if we don't know the type (fallback to an opaque
6205ffd83dbSDimitry Andric   //     dependent type), or the type is known and dependent, or it has
6215ffd83dbSDimitry Andric   //     type-dependent subexpressions.
622bdd1243dSDimitry Andric   auto D = toExprDependenceAsWritten(E->getType()->getDependence()) |
623e8d8bef9SDimitry Andric            ExprDependence::ErrorDependent;
6245ffd83dbSDimitry Andric   // FIXME: remove the type-dependent bit from subexpressions, if the
6255ffd83dbSDimitry Andric   // RecoveryExpr has a non-dependent type.
6265ffd83dbSDimitry Andric   for (auto *S : E->subExpressions())
6275ffd83dbSDimitry Andric     D |= S->getDependence();
6285ffd83dbSDimitry Andric   return D;
6295ffd83dbSDimitry Andric }
6305ffd83dbSDimitry Andric 
631fe6060f1SDimitry Andric ExprDependence clang::computeDependence(SYCLUniqueStableNameExpr *E) {
6323b7f365eSDimitry Andric   return toExprDependenceAsWritten(
6333b7f365eSDimitry Andric       E->getTypeSourceInfo()->getType()->getDependence());
634fe6060f1SDimitry Andric }
635fe6060f1SDimitry Andric 
6365ffd83dbSDimitry Andric ExprDependence clang::computeDependence(PredefinedExpr *E) {
6373b7f365eSDimitry Andric   return toExprDependenceForImpliedType(E->getType()->getDependence());
6385ffd83dbSDimitry Andric }
6395ffd83dbSDimitry Andric 
6405ffd83dbSDimitry Andric ExprDependence clang::computeDependence(CallExpr *E,
6415ffd83dbSDimitry Andric                                         llvm::ArrayRef<Expr *> PreArgs) {
6425ffd83dbSDimitry Andric   auto D = E->getCallee()->getDependence();
6431db9f3b2SDimitry Andric   if (E->getType()->isDependentType())
6441db9f3b2SDimitry Andric     D |= ExprDependence::Type;
645bdd1243dSDimitry Andric   for (auto *A : llvm::ArrayRef(E->getArgs(), E->getNumArgs())) {
6465ffd83dbSDimitry Andric     if (A)
6475ffd83dbSDimitry Andric       D |= A->getDependence();
6485ffd83dbSDimitry Andric   }
6495ffd83dbSDimitry Andric   for (auto *A : PreArgs)
6505ffd83dbSDimitry Andric     D |= A->getDependence();
6515ffd83dbSDimitry Andric   return D;
6525ffd83dbSDimitry Andric }
6535ffd83dbSDimitry Andric 
6545ffd83dbSDimitry Andric ExprDependence clang::computeDependence(OffsetOfExpr *E) {
6553b7f365eSDimitry Andric   auto D = turnTypeToValueDependence(toExprDependenceAsWritten(
6563b7f365eSDimitry Andric       E->getTypeSourceInfo()->getType()->getDependence()));
6575ffd83dbSDimitry Andric   for (unsigned I = 0, N = E->getNumExpressions(); I < N; ++I)
6585ffd83dbSDimitry Andric     D |= turnTypeToValueDependence(E->getIndexExpr(I)->getDependence());
6595ffd83dbSDimitry Andric   return D;
6605ffd83dbSDimitry Andric }
6615ffd83dbSDimitry Andric 
66206c3fb27SDimitry Andric static inline ExprDependence getDependenceInExpr(DeclarationNameInfo Name) {
66306c3fb27SDimitry Andric   auto D = ExprDependence::None;
66406c3fb27SDimitry Andric   if (Name.isInstantiationDependent())
66506c3fb27SDimitry Andric     D |= ExprDependence::Instantiation;
66606c3fb27SDimitry Andric   if (Name.containsUnexpandedParameterPack())
66706c3fb27SDimitry Andric     D |= ExprDependence::UnexpandedPack;
66806c3fb27SDimitry Andric   return D;
66906c3fb27SDimitry Andric }
67006c3fb27SDimitry Andric 
6715ffd83dbSDimitry Andric ExprDependence clang::computeDependence(MemberExpr *E) {
6725ffd83dbSDimitry Andric   auto D = E->getBase()->getDependence();
67306c3fb27SDimitry Andric   D |= getDependenceInExpr(E->getMemberNameInfo());
67406c3fb27SDimitry Andric 
67506c3fb27SDimitry Andric   if (auto *NNS = E->getQualifier())
67606c3fb27SDimitry Andric     D |= toExprDependence(NNS->getDependence() &
67706c3fb27SDimitry Andric                           ~NestedNameSpecifierDependence::Dependent);
67806c3fb27SDimitry Andric 
679*0fca6ea1SDimitry Andric   for (const auto &A : E->template_arguments())
680*0fca6ea1SDimitry Andric     D |= toExprDependence(A.getArgument().getDependence());
681*0fca6ea1SDimitry Andric 
68206c3fb27SDimitry Andric   auto *MemberDecl = E->getMemberDecl();
6835ffd83dbSDimitry Andric   if (FieldDecl *FD = dyn_cast<FieldDecl>(MemberDecl)) {
6845ffd83dbSDimitry Andric     DeclContext *DC = MemberDecl->getDeclContext();
6855ffd83dbSDimitry Andric     // dyn_cast_or_null is used to handle objC variables which do not
6865ffd83dbSDimitry Andric     // have a declaration context.
6875ffd83dbSDimitry Andric     CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(DC);
6885ffd83dbSDimitry Andric     if (RD && RD->isDependentContext() && RD->isCurrentInstantiation(DC)) {
6895ffd83dbSDimitry Andric       if (!E->getType()->isDependentType())
6905ffd83dbSDimitry Andric         D &= ~ExprDependence::Type;
6915ffd83dbSDimitry Andric     }
6925ffd83dbSDimitry Andric 
6935ffd83dbSDimitry Andric     // Bitfield with value-dependent width is type-dependent.
6945ffd83dbSDimitry Andric     if (FD && FD->isBitField() && FD->getBitWidth()->isValueDependent()) {
6955ffd83dbSDimitry Andric       D |= ExprDependence::Type;
6965ffd83dbSDimitry Andric     }
6975ffd83dbSDimitry Andric   }
6985ffd83dbSDimitry Andric   return D;
6995ffd83dbSDimitry Andric }
7005ffd83dbSDimitry Andric 
7015ffd83dbSDimitry Andric ExprDependence clang::computeDependence(InitListExpr *E) {
7025ffd83dbSDimitry Andric   auto D = ExprDependence::None;
7035ffd83dbSDimitry Andric   for (auto *A : E->inits())
7045ffd83dbSDimitry Andric     D |= A->getDependence();
7055ffd83dbSDimitry Andric   return D;
7065ffd83dbSDimitry Andric }
7075ffd83dbSDimitry Andric 
7085ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ShuffleVectorExpr *E) {
7093b7f365eSDimitry Andric   auto D = toExprDependenceForImpliedType(E->getType()->getDependence());
710bdd1243dSDimitry Andric   for (auto *C : llvm::ArrayRef(E->getSubExprs(), E->getNumSubExprs()))
7115ffd83dbSDimitry Andric     D |= C->getDependence();
7125ffd83dbSDimitry Andric   return D;
7135ffd83dbSDimitry Andric }
7145ffd83dbSDimitry Andric 
7155ffd83dbSDimitry Andric ExprDependence clang::computeDependence(GenericSelectionExpr *E,
7165ffd83dbSDimitry Andric                                         bool ContainsUnexpandedPack) {
7175ffd83dbSDimitry Andric   auto D = ContainsUnexpandedPack ? ExprDependence::UnexpandedPack
7185ffd83dbSDimitry Andric                                   : ExprDependence::None;
7195ffd83dbSDimitry Andric   for (auto *AE : E->getAssocExprs())
7205ffd83dbSDimitry Andric     D |= AE->getDependence() & ExprDependence::Error;
72106c3fb27SDimitry Andric 
72206c3fb27SDimitry Andric   if (E->isExprPredicate())
7235ffd83dbSDimitry Andric     D |= E->getControllingExpr()->getDependence() & ExprDependence::Error;
72406c3fb27SDimitry Andric   else
72506c3fb27SDimitry Andric     D |= toExprDependenceAsWritten(
72606c3fb27SDimitry Andric         E->getControllingType()->getType()->getDependence());
7275ffd83dbSDimitry Andric 
7285ffd83dbSDimitry Andric   if (E->isResultDependent())
7295ffd83dbSDimitry Andric     return D | ExprDependence::TypeValueInstantiation;
7305ffd83dbSDimitry Andric   return D | (E->getResultExpr()->getDependence() &
7315ffd83dbSDimitry Andric               ~ExprDependence::UnexpandedPack);
7325ffd83dbSDimitry Andric }
7335ffd83dbSDimitry Andric 
7345ffd83dbSDimitry Andric ExprDependence clang::computeDependence(DesignatedInitExpr *E) {
7355ffd83dbSDimitry Andric   auto Deps = E->getInit()->getDependence();
73606c3fb27SDimitry Andric   for (const auto &D : E->designators()) {
7375ffd83dbSDimitry Andric     auto DesignatorDeps = ExprDependence::None;
7385ffd83dbSDimitry Andric     if (D.isArrayDesignator())
7395ffd83dbSDimitry Andric       DesignatorDeps |= E->getArrayIndex(D)->getDependence();
7405ffd83dbSDimitry Andric     else if (D.isArrayRangeDesignator())
7415ffd83dbSDimitry Andric       DesignatorDeps |= E->getArrayRangeStart(D)->getDependence() |
7425ffd83dbSDimitry Andric                         E->getArrayRangeEnd(D)->getDependence();
7435ffd83dbSDimitry Andric     Deps |= DesignatorDeps;
7445ffd83dbSDimitry Andric     if (DesignatorDeps & ExprDependence::TypeValue)
7455ffd83dbSDimitry Andric       Deps |= ExprDependence::TypeValueInstantiation;
7465ffd83dbSDimitry Andric   }
7475ffd83dbSDimitry Andric   return Deps;
7485ffd83dbSDimitry Andric }
7495ffd83dbSDimitry Andric 
7505ffd83dbSDimitry Andric ExprDependence clang::computeDependence(PseudoObjectExpr *O) {
7515ffd83dbSDimitry Andric   auto D = O->getSyntacticForm()->getDependence();
7525ffd83dbSDimitry Andric   for (auto *E : O->semantics())
7535ffd83dbSDimitry Andric     D |= E->getDependence();
7545ffd83dbSDimitry Andric   return D;
7555ffd83dbSDimitry Andric }
7565ffd83dbSDimitry Andric 
7575ffd83dbSDimitry Andric ExprDependence clang::computeDependence(AtomicExpr *A) {
7585ffd83dbSDimitry Andric   auto D = ExprDependence::None;
759bdd1243dSDimitry Andric   for (auto *E : llvm::ArrayRef(A->getSubExprs(), A->getNumSubExprs()))
7605ffd83dbSDimitry Andric     D |= E->getDependence();
7615ffd83dbSDimitry Andric   return D;
7625ffd83dbSDimitry Andric }
7635ffd83dbSDimitry Andric 
7645ffd83dbSDimitry Andric ExprDependence clang::computeDependence(CXXNewExpr *E) {
7653b7f365eSDimitry Andric   auto D = toExprDependenceAsWritten(
7663b7f365eSDimitry Andric       E->getAllocatedTypeSourceInfo()->getType()->getDependence());
7673b7f365eSDimitry Andric   D |= toExprDependenceForImpliedType(E->getAllocatedType()->getDependence());
7685ffd83dbSDimitry Andric   auto Size = E->getArraySize();
76981ad6265SDimitry Andric   if (Size && *Size)
7705ffd83dbSDimitry Andric     D |= turnTypeToValueDependence((*Size)->getDependence());
7715ffd83dbSDimitry Andric   if (auto *I = E->getInitializer())
7725ffd83dbSDimitry Andric     D |= turnTypeToValueDependence(I->getDependence());
7735ffd83dbSDimitry Andric   for (auto *A : E->placement_arguments())
7745ffd83dbSDimitry Andric     D |= turnTypeToValueDependence(A->getDependence());
7755ffd83dbSDimitry Andric   return D;
7765ffd83dbSDimitry Andric }
7775ffd83dbSDimitry Andric 
7785ffd83dbSDimitry Andric ExprDependence clang::computeDependence(CXXPseudoDestructorExpr *E) {
7795ffd83dbSDimitry Andric   auto D = E->getBase()->getDependence();
7803b7f365eSDimitry Andric   if (auto *TSI = E->getDestroyedTypeInfo())
7813b7f365eSDimitry Andric     D |= toExprDependenceAsWritten(TSI->getType()->getDependence());
7825ffd83dbSDimitry Andric   if (auto *ST = E->getScopeTypeInfo())
7835ffd83dbSDimitry Andric     D |= turnTypeToValueDependence(
7843b7f365eSDimitry Andric         toExprDependenceAsWritten(ST->getType()->getDependence()));
7855ffd83dbSDimitry Andric   if (auto *Q = E->getQualifier())
7865ffd83dbSDimitry Andric     D |= toExprDependence(Q->getDependence() &
7875ffd83dbSDimitry Andric                           ~NestedNameSpecifierDependence::Dependent);
7885ffd83dbSDimitry Andric   return D;
7895ffd83dbSDimitry Andric }
7905ffd83dbSDimitry Andric 
7915ffd83dbSDimitry Andric ExprDependence
7925ffd83dbSDimitry Andric clang::computeDependence(OverloadExpr *E, bool KnownDependent,
7935ffd83dbSDimitry Andric                          bool KnownInstantiationDependent,
7945ffd83dbSDimitry Andric                          bool KnownContainsUnexpandedParameterPack) {
7955ffd83dbSDimitry Andric   auto Deps = ExprDependence::None;
7965ffd83dbSDimitry Andric   if (KnownDependent)
7975ffd83dbSDimitry Andric     Deps |= ExprDependence::TypeValue;
7985ffd83dbSDimitry Andric   if (KnownInstantiationDependent)
7995ffd83dbSDimitry Andric     Deps |= ExprDependence::Instantiation;
8005ffd83dbSDimitry Andric   if (KnownContainsUnexpandedParameterPack)
8015ffd83dbSDimitry Andric     Deps |= ExprDependence::UnexpandedPack;
8025ffd83dbSDimitry Andric   Deps |= getDependenceInExpr(E->getNameInfo());
8035ffd83dbSDimitry Andric   if (auto *Q = E->getQualifier())
8045ffd83dbSDimitry Andric     Deps |= toExprDependence(Q->getDependence() &
8055ffd83dbSDimitry Andric                              ~NestedNameSpecifierDependence::Dependent);
8065ffd83dbSDimitry Andric   for (auto *D : E->decls()) {
8075ffd83dbSDimitry Andric     if (D->getDeclContext()->isDependentContext() ||
8085ffd83dbSDimitry Andric         isa<UnresolvedUsingValueDecl>(D))
8095ffd83dbSDimitry Andric       Deps |= ExprDependence::TypeValueInstantiation;
8105ffd83dbSDimitry Andric   }
8115ffd83dbSDimitry Andric   // If we have explicit template arguments, check for dependent
8125ffd83dbSDimitry Andric   // template arguments and whether they contain any unexpanded pack
8135ffd83dbSDimitry Andric   // expansions.
81406c3fb27SDimitry Andric   for (const auto &A : E->template_arguments())
8155ffd83dbSDimitry Andric     Deps |= toExprDependence(A.getArgument().getDependence());
8165ffd83dbSDimitry Andric   return Deps;
8175ffd83dbSDimitry Andric }
8185ffd83dbSDimitry Andric 
8195ffd83dbSDimitry Andric ExprDependence clang::computeDependence(DependentScopeDeclRefExpr *E) {
8205ffd83dbSDimitry Andric   auto D = ExprDependence::TypeValue;
8215ffd83dbSDimitry Andric   D |= getDependenceInExpr(E->getNameInfo());
8225ffd83dbSDimitry Andric   if (auto *Q = E->getQualifier())
8235ffd83dbSDimitry Andric     D |= toExprDependence(Q->getDependence());
82406c3fb27SDimitry Andric   for (const auto &A : E->template_arguments())
8255ffd83dbSDimitry Andric     D |= toExprDependence(A.getArgument().getDependence());
8265ffd83dbSDimitry Andric   return D;
8275ffd83dbSDimitry Andric }
8285ffd83dbSDimitry Andric 
8295ffd83dbSDimitry Andric ExprDependence clang::computeDependence(CXXConstructExpr *E) {
8303b7f365eSDimitry Andric   ExprDependence D =
8313b7f365eSDimitry Andric       toExprDependenceForImpliedType(E->getType()->getDependence());
8325ffd83dbSDimitry Andric   for (auto *A : E->arguments())
8335ffd83dbSDimitry Andric     D |= A->getDependence() & ~ExprDependence::Type;
8345ffd83dbSDimitry Andric   return D;
8355ffd83dbSDimitry Andric }
8365ffd83dbSDimitry Andric 
8373b7f365eSDimitry Andric ExprDependence clang::computeDependence(CXXTemporaryObjectExpr *E) {
8383b7f365eSDimitry Andric   CXXConstructExpr *BaseE = E;
8393b7f365eSDimitry Andric   return toExprDependenceAsWritten(
8403b7f365eSDimitry Andric              E->getTypeSourceInfo()->getType()->getDependence()) |
8413b7f365eSDimitry Andric          computeDependence(BaseE);
8423b7f365eSDimitry Andric }
8433b7f365eSDimitry Andric 
844e8d8bef9SDimitry Andric ExprDependence clang::computeDependence(CXXDefaultInitExpr *E) {
845e8d8bef9SDimitry Andric   return E->getExpr()->getDependence();
846e8d8bef9SDimitry Andric }
847e8d8bef9SDimitry Andric 
848fe6060f1SDimitry Andric ExprDependence clang::computeDependence(CXXDefaultArgExpr *E) {
849fe6060f1SDimitry Andric   return E->getExpr()->getDependence();
850fe6060f1SDimitry Andric }
851fe6060f1SDimitry Andric 
8525ffd83dbSDimitry Andric ExprDependence clang::computeDependence(LambdaExpr *E,
8535ffd83dbSDimitry Andric                                         bool ContainsUnexpandedParameterPack) {
8543b7f365eSDimitry Andric   auto D = toExprDependenceForImpliedType(E->getType()->getDependence());
8555ffd83dbSDimitry Andric   if (ContainsUnexpandedParameterPack)
8565ffd83dbSDimitry Andric     D |= ExprDependence::UnexpandedPack;
8575ffd83dbSDimitry Andric   return D;
8585ffd83dbSDimitry Andric }
8595ffd83dbSDimitry Andric 
8605ffd83dbSDimitry Andric ExprDependence clang::computeDependence(CXXUnresolvedConstructExpr *E) {
8615ffd83dbSDimitry Andric   auto D = ExprDependence::ValueInstantiation;
8623b7f365eSDimitry Andric   D |= toExprDependenceAsWritten(E->getTypeAsWritten()->getDependence());
8633b7f365eSDimitry Andric   D |= toExprDependenceForImpliedType(E->getType()->getDependence());
8645ffd83dbSDimitry Andric   for (auto *A : E->arguments())
8655ffd83dbSDimitry Andric     D |= A->getDependence() &
8665ffd83dbSDimitry Andric          (ExprDependence::UnexpandedPack | ExprDependence::Error);
8675ffd83dbSDimitry Andric   return D;
8685ffd83dbSDimitry Andric }
8695ffd83dbSDimitry Andric 
8705ffd83dbSDimitry Andric ExprDependence clang::computeDependence(CXXDependentScopeMemberExpr *E) {
8715ffd83dbSDimitry Andric   auto D = ExprDependence::TypeValueInstantiation;
8725ffd83dbSDimitry Andric   if (!E->isImplicitAccess())
8735ffd83dbSDimitry Andric     D |= E->getBase()->getDependence();
8745ffd83dbSDimitry Andric   if (auto *Q = E->getQualifier())
8755ffd83dbSDimitry Andric     D |= toExprDependence(Q->getDependence());
8765ffd83dbSDimitry Andric   D |= getDependenceInExpr(E->getMemberNameInfo());
87706c3fb27SDimitry Andric   for (const auto &A : E->template_arguments())
8785ffd83dbSDimitry Andric     D |= toExprDependence(A.getArgument().getDependence());
8795ffd83dbSDimitry Andric   return D;
8805ffd83dbSDimitry Andric }
8815ffd83dbSDimitry Andric 
8825ffd83dbSDimitry Andric ExprDependence clang::computeDependence(MaterializeTemporaryExpr *E) {
8835ffd83dbSDimitry Andric   return E->getSubExpr()->getDependence();
8845ffd83dbSDimitry Andric }
8855ffd83dbSDimitry Andric 
8865ffd83dbSDimitry Andric ExprDependence clang::computeDependence(CXXFoldExpr *E) {
8875ffd83dbSDimitry Andric   auto D = ExprDependence::TypeValueInstantiation;
8885ffd83dbSDimitry Andric   for (const auto *C : {E->getLHS(), E->getRHS()}) {
8895ffd83dbSDimitry Andric     if (C)
8905ffd83dbSDimitry Andric       D |= C->getDependence() & ~ExprDependence::UnexpandedPack;
8915ffd83dbSDimitry Andric   }
8925ffd83dbSDimitry Andric   return D;
8935ffd83dbSDimitry Andric }
8945ffd83dbSDimitry Andric 
895bdd1243dSDimitry Andric ExprDependence clang::computeDependence(CXXParenListInitExpr *E) {
896bdd1243dSDimitry Andric   auto D = ExprDependence::None;
897bdd1243dSDimitry Andric   for (const auto *A : E->getInitExprs())
898bdd1243dSDimitry Andric     D |= A->getDependence();
899bdd1243dSDimitry Andric   return D;
900bdd1243dSDimitry Andric }
901bdd1243dSDimitry Andric 
9025ffd83dbSDimitry Andric ExprDependence clang::computeDependence(TypeTraitExpr *E) {
9035ffd83dbSDimitry Andric   auto D = ExprDependence::None;
9045ffd83dbSDimitry Andric   for (const auto *A : E->getArgs())
9053b7f365eSDimitry Andric     D |= toExprDependenceAsWritten(A->getType()->getDependence()) &
9063b7f365eSDimitry Andric          ~ExprDependence::Type;
9075ffd83dbSDimitry Andric   return D;
9085ffd83dbSDimitry Andric }
9095ffd83dbSDimitry Andric 
9105ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ConceptSpecializationExpr *E,
9115ffd83dbSDimitry Andric                                         bool ValueDependent) {
9125ffd83dbSDimitry Andric   auto TA = TemplateArgumentDependence::None;
9135ffd83dbSDimitry Andric   const auto InterestingDeps = TemplateArgumentDependence::Instantiation |
9145ffd83dbSDimitry Andric                                TemplateArgumentDependence::UnexpandedPack;
9155ffd83dbSDimitry Andric   for (const TemplateArgumentLoc &ArgLoc :
9165ffd83dbSDimitry Andric        E->getTemplateArgsAsWritten()->arguments()) {
9175ffd83dbSDimitry Andric     TA |= ArgLoc.getArgument().getDependence() & InterestingDeps;
9185ffd83dbSDimitry Andric     if (TA == InterestingDeps)
9195ffd83dbSDimitry Andric       break;
9205ffd83dbSDimitry Andric   }
9215ffd83dbSDimitry Andric 
9225ffd83dbSDimitry Andric   ExprDependence D =
9235ffd83dbSDimitry Andric       ValueDependent ? ExprDependence::Value : ExprDependence::None;
924bdd1243dSDimitry Andric   auto Res = D | toExprDependence(TA);
925bdd1243dSDimitry Andric   if(!ValueDependent && E->getSatisfaction().ContainsErrors)
926bdd1243dSDimitry Andric     Res |= ExprDependence::Error;
927bdd1243dSDimitry Andric   return Res;
9285ffd83dbSDimitry Andric }
9295ffd83dbSDimitry Andric 
9305ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ObjCArrayLiteral *E) {
9315ffd83dbSDimitry Andric   auto D = ExprDependence::None;
9325ffd83dbSDimitry Andric   Expr **Elements = E->getElements();
9335ffd83dbSDimitry Andric   for (unsigned I = 0, N = E->getNumElements(); I != N; ++I)
9345ffd83dbSDimitry Andric     D |= turnTypeToValueDependence(Elements[I]->getDependence());
9355ffd83dbSDimitry Andric   return D;
9365ffd83dbSDimitry Andric }
9375ffd83dbSDimitry Andric 
9385ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ObjCDictionaryLiteral *E) {
9395ffd83dbSDimitry Andric   auto Deps = ExprDependence::None;
9405ffd83dbSDimitry Andric   for (unsigned I = 0, N = E->getNumElements(); I < N; ++I) {
9415ffd83dbSDimitry Andric     auto KV = E->getKeyValueElement(I);
9425ffd83dbSDimitry Andric     auto KVDeps = turnTypeToValueDependence(KV.Key->getDependence() |
9435ffd83dbSDimitry Andric                                             KV.Value->getDependence());
9445ffd83dbSDimitry Andric     if (KV.EllipsisLoc.isValid())
9455ffd83dbSDimitry Andric       KVDeps &= ~ExprDependence::UnexpandedPack;
9465ffd83dbSDimitry Andric     Deps |= KVDeps;
9475ffd83dbSDimitry Andric   }
9485ffd83dbSDimitry Andric   return Deps;
9495ffd83dbSDimitry Andric }
9505ffd83dbSDimitry Andric 
9515ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ObjCMessageExpr *E) {
9525ffd83dbSDimitry Andric   auto D = ExprDependence::None;
9535ffd83dbSDimitry Andric   if (auto *R = E->getInstanceReceiver())
9545ffd83dbSDimitry Andric     D |= R->getDependence();
9555ffd83dbSDimitry Andric   else
9563b7f365eSDimitry Andric     D |= toExprDependenceForImpliedType(E->getType()->getDependence());
9575ffd83dbSDimitry Andric   for (auto *A : E->arguments())
9585ffd83dbSDimitry Andric     D |= A->getDependence();
9595ffd83dbSDimitry Andric   return D;
9605ffd83dbSDimitry Andric }
961