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) { 29*3b7f365eSDimitry 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) { 42*3b7f365eSDimitry Andric ExprDependence Dep = 43*3b7f365eSDimitry Andric // FIXME: Do we need to look at the type? 44*3b7f365eSDimitry 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( 82*3b7f365eSDimitry 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) { 125*3b7f365eSDimitry Andric return toExprDependenceAsWritten( 126*3b7f365eSDimitry Andric E->getTypeSourceInfo()->getType()->getDependence()) | 127*3b7f365eSDimitry Andric toExprDependenceForImpliedType(E->getType()->getDependence()) | 1285ffd83dbSDimitry Andric turnTypeToValueDependence(E->getInitializer()->getDependence()); 1295ffd83dbSDimitry Andric } 1305ffd83dbSDimitry Andric 131*3b7f365eSDimitry Andric ExprDependence clang::computeDependence(ImplicitCastExpr *E) { 132*3b7f365eSDimitry Andric // We model implicit conversions as combining the dependence of their 133*3b7f365eSDimitry Andric // subexpression, apart from its type, with the semantic portion of the 134*3b7f365eSDimitry Andric // target type. 135*3b7f365eSDimitry Andric ExprDependence D = 136*3b7f365eSDimitry Andric toExprDependenceForImpliedType(E->getType()->getDependence()); 137*3b7f365eSDimitry Andric if (auto *S = E->getSubExpr()) 138*3b7f365eSDimitry Andric D |= S->getDependence() & ~ExprDependence::Type; 139*3b7f365eSDimitry Andric return D; 140*3b7f365eSDimitry Andric } 141*3b7f365eSDimitry Andric 142*3b7f365eSDimitry 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. 147*3b7f365eSDimitry Andric // 148*3b7f365eSDimitry Andric // Note that we also need to consider the dependence of the actual type here, 149*3b7f365eSDimitry Andric // because when the type as written is a deduced type, that type is not 150*3b7f365eSDimitry Andric // dependent, but it may be deduced as a dependent type. 151*3b7f365eSDimitry Andric ExprDependence D = 152*3b7f365eSDimitry Andric toExprDependenceAsWritten( 153*3b7f365eSDimitry Andric cast<ExplicitCastExpr>(E)->getTypeAsWritten()->getDependence()) | 154*3b7f365eSDimitry 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) { 178*3b7f365eSDimitry 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) { 194*3b7f365eSDimitry Andric auto D = toExprDependenceAsWritten( 195*3b7f365eSDimitry 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) { 227*3b7f365eSDimitry Andric auto D = toExprDependenceAsWritten( 228*3b7f365eSDimitry Andric E->getWrittenTypeInfo()->getType()->getDependence()) | 2295ffd83dbSDimitry Andric (E->getSubExpr()->getDependence() & ~ExprDependence::Type); 2305ffd83dbSDimitry Andric return D & ~ExprDependence::Value; 2315ffd83dbSDimitry Andric } 2325ffd83dbSDimitry Andric 2335ffd83dbSDimitry Andric ExprDependence clang::computeDependence(NoInitExpr *E) { 234*3b7f365eSDimitry 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) { 247*3b7f365eSDimitry 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) { 256*3b7f365eSDimitry Andric auto D = toExprDependenceForImpliedType(E->getType()->getDependence()); 2575ffd83dbSDimitry Andric if (E->getBlockDecl()->isDependentContext()) 2585ffd83dbSDimitry Andric D |= ExprDependence::Instantiation; 259*3b7f365eSDimitry Andric return D; 2605ffd83dbSDimitry Andric } 2615ffd83dbSDimitry Andric 2625ffd83dbSDimitry Andric ExprDependence clang::computeDependence(AsTypeExpr *E) { 263*3b7f365eSDimitry Andric // FIXME: AsTypeExpr doesn't store the type as written. Assume the expression 264*3b7f365eSDimitry Andric // type has identical sugar for now, so is a type-as-written. 265*3b7f365eSDimitry 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()); 278*3b7f365eSDimitry 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()) 285*3b7f365eSDimitry 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()) 303*3b7f365eSDimitry 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) 312*3b7f365eSDimitry Andric auto D = toExprDependenceForImpliedType(E->getType()->getDependence()); 3135ffd83dbSDimitry Andric assert(!(D & ExprDependence::UnexpandedPack)); 3145ffd83dbSDimitry Andric return D; 3155ffd83dbSDimitry Andric } 3165ffd83dbSDimitry Andric 3175ffd83dbSDimitry Andric ExprDependence clang::computeDependence(CXXThrowExpr *E) { 3185ffd83dbSDimitry Andric auto *Op = E->getSubExpr(); 3195ffd83dbSDimitry Andric if (!Op) 3205ffd83dbSDimitry Andric return ExprDependence::None; 3215ffd83dbSDimitry Andric return Op->getDependence() & ~ExprDependence::TypeValue; 3225ffd83dbSDimitry Andric } 3235ffd83dbSDimitry Andric 3245ffd83dbSDimitry Andric ExprDependence clang::computeDependence(CXXBindTemporaryExpr *E) { 3255ffd83dbSDimitry Andric return E->getSubExpr()->getDependence(); 3265ffd83dbSDimitry Andric } 3275ffd83dbSDimitry Andric 3285ffd83dbSDimitry Andric ExprDependence clang::computeDependence(CXXScalarValueInitExpr *E) { 329*3b7f365eSDimitry Andric auto D = toExprDependenceForImpliedType(E->getType()->getDependence()); 330*3b7f365eSDimitry Andric if (auto *TSI = E->getTypeSourceInfo()) 331*3b7f365eSDimitry Andric D |= toExprDependenceAsWritten(TSI->getType()->getDependence()); 332*3b7f365eSDimitry Andric return D; 3335ffd83dbSDimitry Andric } 3345ffd83dbSDimitry Andric 3355ffd83dbSDimitry Andric ExprDependence clang::computeDependence(CXXDeleteExpr *E) { 3365ffd83dbSDimitry Andric return turnTypeToValueDependence(E->getArgument()->getDependence()); 3375ffd83dbSDimitry Andric } 3385ffd83dbSDimitry Andric 3395ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ArrayTypeTraitExpr *E) { 340*3b7f365eSDimitry Andric auto D = toExprDependenceAsWritten(E->getQueriedType()->getDependence()); 3415ffd83dbSDimitry Andric if (auto *Dim = E->getDimensionExpression()) 3425ffd83dbSDimitry Andric D |= Dim->getDependence(); 3435ffd83dbSDimitry Andric return turnTypeToValueDependence(D); 3445ffd83dbSDimitry Andric } 3455ffd83dbSDimitry Andric 3465ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ExpressionTraitExpr *E) { 3475ffd83dbSDimitry Andric // Never type-dependent. 3485ffd83dbSDimitry Andric auto D = E->getQueriedExpression()->getDependence() & ~ExprDependence::Type; 3495ffd83dbSDimitry Andric // Value-dependent if the argument is type-dependent. 3505ffd83dbSDimitry Andric if (E->getQueriedExpression()->isTypeDependent()) 3515ffd83dbSDimitry Andric D |= ExprDependence::Value; 3525ffd83dbSDimitry Andric return D; 3535ffd83dbSDimitry Andric } 3545ffd83dbSDimitry Andric 3555ffd83dbSDimitry Andric ExprDependence clang::computeDependence(CXXNoexceptExpr *E, CanThrowResult CT) { 3565ffd83dbSDimitry Andric auto D = E->getOperand()->getDependence() & ~ExprDependence::TypeValue; 3575ffd83dbSDimitry Andric if (CT == CT_Dependent) 3585ffd83dbSDimitry Andric D |= ExprDependence::ValueInstantiation; 3595ffd83dbSDimitry Andric return D; 3605ffd83dbSDimitry Andric } 3615ffd83dbSDimitry Andric 3625ffd83dbSDimitry Andric ExprDependence clang::computeDependence(PackExpansionExpr *E) { 3635ffd83dbSDimitry Andric return (E->getPattern()->getDependence() & ~ExprDependence::UnexpandedPack) | 3645ffd83dbSDimitry Andric ExprDependence::TypeValueInstantiation; 3655ffd83dbSDimitry Andric } 3665ffd83dbSDimitry Andric 3675ffd83dbSDimitry Andric ExprDependence clang::computeDependence(SubstNonTypeTemplateParmExpr *E) { 3685ffd83dbSDimitry Andric return E->getReplacement()->getDependence(); 3695ffd83dbSDimitry Andric } 3705ffd83dbSDimitry Andric 3715ffd83dbSDimitry Andric ExprDependence clang::computeDependence(CoroutineSuspendExpr *E) { 3725ffd83dbSDimitry Andric if (auto *Resume = E->getResumeExpr()) 3735ffd83dbSDimitry Andric return (Resume->getDependence() & 3745ffd83dbSDimitry Andric (ExprDependence::TypeValue | ExprDependence::Error)) | 3755ffd83dbSDimitry Andric (E->getCommonExpr()->getDependence() & ~ExprDependence::TypeValue); 3765ffd83dbSDimitry Andric return E->getCommonExpr()->getDependence() | 3775ffd83dbSDimitry Andric ExprDependence::TypeValueInstantiation; 3785ffd83dbSDimitry Andric } 3795ffd83dbSDimitry Andric 3805ffd83dbSDimitry Andric ExprDependence clang::computeDependence(DependentCoawaitExpr *E) { 3815ffd83dbSDimitry Andric return E->getOperand()->getDependence() | 3825ffd83dbSDimitry Andric ExprDependence::TypeValueInstantiation; 3835ffd83dbSDimitry Andric } 3845ffd83dbSDimitry Andric 3855ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ObjCBoxedExpr *E) { 3865ffd83dbSDimitry Andric return E->getSubExpr()->getDependence(); 3875ffd83dbSDimitry Andric } 3885ffd83dbSDimitry Andric 3895ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ObjCEncodeExpr *E) { 390*3b7f365eSDimitry Andric return toExprDependenceAsWritten(E->getEncodedType()->getDependence()); 3915ffd83dbSDimitry Andric } 3925ffd83dbSDimitry Andric 3935ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ObjCIvarRefExpr *E) { 3945ffd83dbSDimitry Andric return turnTypeToValueDependence(E->getBase()->getDependence()); 3955ffd83dbSDimitry Andric } 3965ffd83dbSDimitry Andric 3975ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ObjCPropertyRefExpr *E) { 3985ffd83dbSDimitry Andric if (E->isObjectReceiver()) 3995ffd83dbSDimitry Andric return E->getBase()->getDependence() & ~ExprDependence::Type; 4005ffd83dbSDimitry Andric if (E->isSuperReceiver()) 401*3b7f365eSDimitry Andric return toExprDependenceForImpliedType( 402*3b7f365eSDimitry Andric E->getSuperReceiverType()->getDependence()) & 4035ffd83dbSDimitry Andric ~ExprDependence::TypeValue; 4045ffd83dbSDimitry Andric assert(E->isClassReceiver()); 4055ffd83dbSDimitry Andric return ExprDependence::None; 4065ffd83dbSDimitry Andric } 4075ffd83dbSDimitry Andric 4085ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ObjCSubscriptRefExpr *E) { 4095ffd83dbSDimitry Andric return E->getBaseExpr()->getDependence() | E->getKeyExpr()->getDependence(); 4105ffd83dbSDimitry Andric } 4115ffd83dbSDimitry Andric 4125ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ObjCIsaExpr *E) { 4135ffd83dbSDimitry Andric return E->getBase()->getDependence() & ~ExprDependence::Type & 4145ffd83dbSDimitry Andric ~ExprDependence::UnexpandedPack; 4155ffd83dbSDimitry Andric } 4165ffd83dbSDimitry Andric 4175ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ObjCIndirectCopyRestoreExpr *E) { 4185ffd83dbSDimitry Andric return E->getSubExpr()->getDependence(); 4195ffd83dbSDimitry Andric } 4205ffd83dbSDimitry Andric 4215ffd83dbSDimitry Andric ExprDependence clang::computeDependence(OMPArraySectionExpr *E) { 4225ffd83dbSDimitry Andric auto D = E->getBase()->getDependence(); 4235ffd83dbSDimitry Andric if (auto *LB = E->getLowerBound()) 4245ffd83dbSDimitry Andric D |= LB->getDependence(); 4255ffd83dbSDimitry Andric if (auto *Len = E->getLength()) 4265ffd83dbSDimitry Andric D |= Len->getDependence(); 4275ffd83dbSDimitry Andric return D; 4285ffd83dbSDimitry Andric } 4295ffd83dbSDimitry Andric 4305ffd83dbSDimitry Andric ExprDependence clang::computeDependence(OMPArrayShapingExpr *E) { 431*3b7f365eSDimitry Andric auto D = E->getBase()->getDependence(); 4325ffd83dbSDimitry Andric for (Expr *Dim: E->getDimensions()) 4335ffd83dbSDimitry Andric if (Dim) 434*3b7f365eSDimitry Andric D |= turnValueToTypeDependence(Dim->getDependence()); 4355ffd83dbSDimitry Andric return D; 4365ffd83dbSDimitry Andric } 4375ffd83dbSDimitry Andric 4385ffd83dbSDimitry Andric ExprDependence clang::computeDependence(OMPIteratorExpr *E) { 439*3b7f365eSDimitry Andric auto D = toExprDependenceForImpliedType(E->getType()->getDependence()); 4405ffd83dbSDimitry Andric for (unsigned I = 0, End = E->numOfIterators(); I < End; ++I) { 441*3b7f365eSDimitry Andric if (auto *DD = cast_or_null<DeclaratorDecl>(E->getIteratorDecl(I))) { 442*3b7f365eSDimitry Andric // If the type is omitted, it's 'int', and is not dependent in any way. 443*3b7f365eSDimitry Andric if (auto *TSI = DD->getTypeSourceInfo()) { 444*3b7f365eSDimitry Andric D |= toExprDependenceAsWritten(TSI->getType()->getDependence()); 445*3b7f365eSDimitry Andric } 446*3b7f365eSDimitry Andric } 4475ffd83dbSDimitry Andric OMPIteratorExpr::IteratorRange IR = E->getIteratorRange(I); 4485ffd83dbSDimitry Andric if (Expr *BE = IR.Begin) 4495ffd83dbSDimitry Andric D |= BE->getDependence(); 4505ffd83dbSDimitry Andric if (Expr *EE = IR.End) 4515ffd83dbSDimitry Andric D |= EE->getDependence(); 4525ffd83dbSDimitry Andric if (Expr *SE = IR.Step) 4535ffd83dbSDimitry Andric D |= SE->getDependence(); 4545ffd83dbSDimitry Andric } 4555ffd83dbSDimitry Andric return D; 4565ffd83dbSDimitry Andric } 4575ffd83dbSDimitry Andric 4585ffd83dbSDimitry Andric /// Compute the type-, value-, and instantiation-dependence of a 4595ffd83dbSDimitry Andric /// declaration reference 4605ffd83dbSDimitry Andric /// based on the declaration being referenced. 4615ffd83dbSDimitry Andric ExprDependence clang::computeDependence(DeclRefExpr *E, const ASTContext &Ctx) { 4625ffd83dbSDimitry Andric auto Deps = ExprDependence::None; 4635ffd83dbSDimitry Andric 4645ffd83dbSDimitry Andric if (auto *NNS = E->getQualifier()) 4655ffd83dbSDimitry Andric Deps |= toExprDependence(NNS->getDependence() & 4665ffd83dbSDimitry Andric ~NestedNameSpecifierDependence::Dependent); 4675ffd83dbSDimitry Andric 4685ffd83dbSDimitry Andric if (auto *FirstArg = E->getTemplateArgs()) { 4695ffd83dbSDimitry Andric unsigned NumArgs = E->getNumTemplateArgs(); 4705ffd83dbSDimitry Andric for (auto *Arg = FirstArg, *End = FirstArg + NumArgs; Arg < End; ++Arg) 4715ffd83dbSDimitry Andric Deps |= toExprDependence(Arg->getArgument().getDependence()); 4725ffd83dbSDimitry Andric } 4735ffd83dbSDimitry Andric 4745ffd83dbSDimitry Andric auto *Decl = E->getDecl(); 4755ffd83dbSDimitry Andric auto Type = E->getType(); 4765ffd83dbSDimitry Andric 4775ffd83dbSDimitry Andric if (Decl->isParameterPack()) 4785ffd83dbSDimitry Andric Deps |= ExprDependence::UnexpandedPack; 479*3b7f365eSDimitry Andric Deps |= toExprDependenceForImpliedType(Type->getDependence()) & 480*3b7f365eSDimitry Andric ExprDependence::Error; 4815ffd83dbSDimitry Andric 482e8d8bef9SDimitry Andric // C++ [temp.dep.expr]p3: 4835ffd83dbSDimitry Andric // An id-expression is type-dependent if it contains: 4845ffd83dbSDimitry Andric 485e8d8bef9SDimitry Andric // - an identifier associated by name lookup with one or more declarations 486e8d8bef9SDimitry Andric // declared with a dependent type 487e8d8bef9SDimitry Andric // 488e8d8bef9SDimitry Andric // [The "or more" case is not modeled as a DeclRefExpr. There are a bunch 489e8d8bef9SDimitry Andric // more bullets here that we handle by treating the declaration as having a 490e8d8bef9SDimitry Andric // dependent type if they involve a placeholder type that can't be deduced.] 4915ffd83dbSDimitry Andric if (Type->isDependentType()) 4925ffd83dbSDimitry Andric return Deps | ExprDependence::TypeValueInstantiation; 4935ffd83dbSDimitry Andric else if (Type->isInstantiationDependentType()) 4945ffd83dbSDimitry Andric Deps |= ExprDependence::Instantiation; 4955ffd83dbSDimitry Andric 496e8d8bef9SDimitry Andric // - a conversion-function-id that specifies a dependent type 4975ffd83dbSDimitry Andric if (Decl->getDeclName().getNameKind() == 4985ffd83dbSDimitry Andric DeclarationName::CXXConversionFunctionName) { 4995ffd83dbSDimitry Andric QualType T = Decl->getDeclName().getCXXNameType(); 5005ffd83dbSDimitry Andric if (T->isDependentType()) 5015ffd83dbSDimitry Andric return Deps | ExprDependence::TypeValueInstantiation; 5025ffd83dbSDimitry Andric 5035ffd83dbSDimitry Andric if (T->isInstantiationDependentType()) 5045ffd83dbSDimitry Andric Deps |= ExprDependence::Instantiation; 5055ffd83dbSDimitry Andric } 5065ffd83dbSDimitry Andric 507e8d8bef9SDimitry Andric // - a template-id that is dependent, 508e8d8bef9SDimitry Andric // - a nested-name-specifier or a qualified-id that names a member of an 509e8d8bef9SDimitry Andric // unknown specialization 510e8d8bef9SDimitry Andric // [These are not modeled as DeclRefExprs.] 511e8d8bef9SDimitry Andric 512e8d8bef9SDimitry Andric // or if it names a dependent member of the current instantiation that is a 513e8d8bef9SDimitry Andric // static data member of type "array of unknown bound of T" for some T 514e8d8bef9SDimitry Andric // [handled below]. 515e8d8bef9SDimitry Andric 516e8d8bef9SDimitry Andric // C++ [temp.dep.constexpr]p2: 517e8d8bef9SDimitry Andric // An id-expression is value-dependent if: 518e8d8bef9SDimitry Andric 519e8d8bef9SDimitry Andric // - it is type-dependent [handled above] 520e8d8bef9SDimitry Andric 521e8d8bef9SDimitry Andric // - it is the name of a non-type template parameter, 5225ffd83dbSDimitry Andric if (isa<NonTypeTemplateParmDecl>(Decl)) 5235ffd83dbSDimitry Andric return Deps | ExprDependence::ValueInstantiation; 5245ffd83dbSDimitry Andric 525e8d8bef9SDimitry Andric // - it names a potentially-constant variable that is initialized with an 526e8d8bef9SDimitry Andric // expression that is value-dependent 527e8d8bef9SDimitry Andric if (const auto *Var = dyn_cast<VarDecl>(Decl)) { 528e8d8bef9SDimitry Andric if (Var->mightBeUsableInConstantExpressions(Ctx)) { 529e8d8bef9SDimitry Andric if (const Expr *Init = Var->getAnyInitializer()) { 530e8d8bef9SDimitry Andric if (Init->isValueDependent()) 5315ffd83dbSDimitry Andric Deps |= ExprDependence::ValueInstantiation; 532e8d8bef9SDimitry Andric if (Init->containsErrors()) 533e8d8bef9SDimitry Andric Deps |= ExprDependence::Error; 5345ffd83dbSDimitry Andric } 5355ffd83dbSDimitry Andric } 5365ffd83dbSDimitry Andric 537e8d8bef9SDimitry Andric // - it names a static data member that is a dependent member of the 538e8d8bef9SDimitry Andric // current instantiation and is not initialized in a member-declarator, 5395ffd83dbSDimitry Andric if (Var->isStaticDataMember() && 540e8d8bef9SDimitry Andric Var->getDeclContext()->isDependentContext() && 541e8d8bef9SDimitry Andric !Var->getFirstDecl()->hasInit()) { 542e8d8bef9SDimitry Andric const VarDecl *First = Var->getFirstDecl(); 543e8d8bef9SDimitry Andric TypeSourceInfo *TInfo = First->getTypeSourceInfo(); 544e8d8bef9SDimitry Andric if (TInfo->getType()->isIncompleteArrayType()) { 545e8d8bef9SDimitry Andric Deps |= ExprDependence::TypeValueInstantiation; 546e8d8bef9SDimitry Andric } else if (!First->hasInit()) { 5475ffd83dbSDimitry Andric Deps |= ExprDependence::ValueInstantiation; 548e8d8bef9SDimitry Andric } 5495ffd83dbSDimitry Andric } 5505ffd83dbSDimitry Andric 5515ffd83dbSDimitry Andric return Deps; 5525ffd83dbSDimitry Andric } 5535ffd83dbSDimitry Andric 554e8d8bef9SDimitry Andric // - it names a static member function that is a dependent member of the 555e8d8bef9SDimitry Andric // current instantiation 556e8d8bef9SDimitry Andric // 557e8d8bef9SDimitry Andric // FIXME: It's unclear that the restriction to static members here has any 558e8d8bef9SDimitry Andric // effect: any use of a non-static member function name requires either 559e8d8bef9SDimitry Andric // forming a pointer-to-member or providing an object parameter, either of 560e8d8bef9SDimitry Andric // which makes the overall expression value-dependent. 561e8d8bef9SDimitry Andric if (auto *MD = dyn_cast<CXXMethodDecl>(Decl)) { 562e8d8bef9SDimitry Andric if (MD->isStatic() && Decl->getDeclContext()->isDependentContext()) 5635ffd83dbSDimitry Andric Deps |= ExprDependence::ValueInstantiation; 564e8d8bef9SDimitry Andric } 565e8d8bef9SDimitry Andric 5665ffd83dbSDimitry Andric return Deps; 5675ffd83dbSDimitry Andric } 5685ffd83dbSDimitry Andric 5695ffd83dbSDimitry Andric ExprDependence clang::computeDependence(RecoveryExpr *E) { 5705ffd83dbSDimitry Andric // RecoveryExpr is 5715ffd83dbSDimitry Andric // - always value-dependent, and therefore instantiation dependent 5725ffd83dbSDimitry Andric // - contains errors (ExprDependence::Error), by definition 5735ffd83dbSDimitry Andric // - type-dependent if we don't know the type (fallback to an opaque 5745ffd83dbSDimitry Andric // dependent type), or the type is known and dependent, or it has 5755ffd83dbSDimitry Andric // type-dependent subexpressions. 576*3b7f365eSDimitry Andric auto D = toExprDependenceForImpliedType(E->getType()->getDependence()) | 577e8d8bef9SDimitry Andric ExprDependence::ErrorDependent; 5785ffd83dbSDimitry Andric // FIXME: remove the type-dependent bit from subexpressions, if the 5795ffd83dbSDimitry Andric // RecoveryExpr has a non-dependent type. 5805ffd83dbSDimitry Andric for (auto *S : E->subExpressions()) 5815ffd83dbSDimitry Andric D |= S->getDependence(); 5825ffd83dbSDimitry Andric return D; 5835ffd83dbSDimitry Andric } 5845ffd83dbSDimitry Andric 585fe6060f1SDimitry Andric ExprDependence clang::computeDependence(SYCLUniqueStableNameExpr *E) { 586*3b7f365eSDimitry Andric return toExprDependenceAsWritten( 587*3b7f365eSDimitry Andric E->getTypeSourceInfo()->getType()->getDependence()); 588fe6060f1SDimitry Andric } 589fe6060f1SDimitry Andric 5905ffd83dbSDimitry Andric ExprDependence clang::computeDependence(PredefinedExpr *E) { 591*3b7f365eSDimitry Andric return toExprDependenceForImpliedType(E->getType()->getDependence()); 5925ffd83dbSDimitry Andric } 5935ffd83dbSDimitry Andric 5945ffd83dbSDimitry Andric ExprDependence clang::computeDependence(CallExpr *E, 5955ffd83dbSDimitry Andric llvm::ArrayRef<Expr *> PreArgs) { 5965ffd83dbSDimitry Andric auto D = E->getCallee()->getDependence(); 5975ffd83dbSDimitry Andric for (auto *A : llvm::makeArrayRef(E->getArgs(), E->getNumArgs())) { 5985ffd83dbSDimitry Andric if (A) 5995ffd83dbSDimitry Andric D |= A->getDependence(); 6005ffd83dbSDimitry Andric } 6015ffd83dbSDimitry Andric for (auto *A : PreArgs) 6025ffd83dbSDimitry Andric D |= A->getDependence(); 6035ffd83dbSDimitry Andric return D; 6045ffd83dbSDimitry Andric } 6055ffd83dbSDimitry Andric 6065ffd83dbSDimitry Andric ExprDependence clang::computeDependence(OffsetOfExpr *E) { 607*3b7f365eSDimitry Andric auto D = turnTypeToValueDependence(toExprDependenceAsWritten( 608*3b7f365eSDimitry Andric E->getTypeSourceInfo()->getType()->getDependence())); 6095ffd83dbSDimitry Andric for (unsigned I = 0, N = E->getNumExpressions(); I < N; ++I) 6105ffd83dbSDimitry Andric D |= turnTypeToValueDependence(E->getIndexExpr(I)->getDependence()); 6115ffd83dbSDimitry Andric return D; 6125ffd83dbSDimitry Andric } 6135ffd83dbSDimitry Andric 6145ffd83dbSDimitry Andric ExprDependence clang::computeDependence(MemberExpr *E) { 6155ffd83dbSDimitry Andric auto *MemberDecl = E->getMemberDecl(); 6165ffd83dbSDimitry Andric auto D = E->getBase()->getDependence(); 6175ffd83dbSDimitry Andric if (FieldDecl *FD = dyn_cast<FieldDecl>(MemberDecl)) { 6185ffd83dbSDimitry Andric DeclContext *DC = MemberDecl->getDeclContext(); 6195ffd83dbSDimitry Andric // dyn_cast_or_null is used to handle objC variables which do not 6205ffd83dbSDimitry Andric // have a declaration context. 6215ffd83dbSDimitry Andric CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(DC); 6225ffd83dbSDimitry Andric if (RD && RD->isDependentContext() && RD->isCurrentInstantiation(DC)) { 6235ffd83dbSDimitry Andric if (!E->getType()->isDependentType()) 6245ffd83dbSDimitry Andric D &= ~ExprDependence::Type; 6255ffd83dbSDimitry Andric } 6265ffd83dbSDimitry Andric 6275ffd83dbSDimitry Andric // Bitfield with value-dependent width is type-dependent. 6285ffd83dbSDimitry Andric if (FD && FD->isBitField() && FD->getBitWidth()->isValueDependent()) { 6295ffd83dbSDimitry Andric D |= ExprDependence::Type; 6305ffd83dbSDimitry Andric } 6315ffd83dbSDimitry Andric } 6325ffd83dbSDimitry Andric // FIXME: move remaining dependence computation from MemberExpr::Create() 6335ffd83dbSDimitry Andric return D; 6345ffd83dbSDimitry Andric } 6355ffd83dbSDimitry Andric 6365ffd83dbSDimitry Andric ExprDependence clang::computeDependence(InitListExpr *E) { 6375ffd83dbSDimitry Andric auto D = ExprDependence::None; 6385ffd83dbSDimitry Andric for (auto *A : E->inits()) 6395ffd83dbSDimitry Andric D |= A->getDependence(); 6405ffd83dbSDimitry Andric return D; 6415ffd83dbSDimitry Andric } 6425ffd83dbSDimitry Andric 6435ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ShuffleVectorExpr *E) { 644*3b7f365eSDimitry Andric auto D = toExprDependenceForImpliedType(E->getType()->getDependence()); 6455ffd83dbSDimitry Andric for (auto *C : llvm::makeArrayRef(E->getSubExprs(), E->getNumSubExprs())) 6465ffd83dbSDimitry Andric D |= C->getDependence(); 6475ffd83dbSDimitry Andric return D; 6485ffd83dbSDimitry Andric } 6495ffd83dbSDimitry Andric 6505ffd83dbSDimitry Andric ExprDependence clang::computeDependence(GenericSelectionExpr *E, 6515ffd83dbSDimitry Andric bool ContainsUnexpandedPack) { 6525ffd83dbSDimitry Andric auto D = ContainsUnexpandedPack ? ExprDependence::UnexpandedPack 6535ffd83dbSDimitry Andric : ExprDependence::None; 6545ffd83dbSDimitry Andric for (auto *AE : E->getAssocExprs()) 6555ffd83dbSDimitry Andric D |= AE->getDependence() & ExprDependence::Error; 6565ffd83dbSDimitry Andric D |= E->getControllingExpr()->getDependence() & ExprDependence::Error; 6575ffd83dbSDimitry Andric 6585ffd83dbSDimitry Andric if (E->isResultDependent()) 6595ffd83dbSDimitry Andric return D | ExprDependence::TypeValueInstantiation; 6605ffd83dbSDimitry Andric return D | (E->getResultExpr()->getDependence() & 6615ffd83dbSDimitry Andric ~ExprDependence::UnexpandedPack); 6625ffd83dbSDimitry Andric } 6635ffd83dbSDimitry Andric 6645ffd83dbSDimitry Andric ExprDependence clang::computeDependence(DesignatedInitExpr *E) { 6655ffd83dbSDimitry Andric auto Deps = E->getInit()->getDependence(); 6665ffd83dbSDimitry Andric for (auto D : E->designators()) { 6675ffd83dbSDimitry Andric auto DesignatorDeps = ExprDependence::None; 6685ffd83dbSDimitry Andric if (D.isArrayDesignator()) 6695ffd83dbSDimitry Andric DesignatorDeps |= E->getArrayIndex(D)->getDependence(); 6705ffd83dbSDimitry Andric else if (D.isArrayRangeDesignator()) 6715ffd83dbSDimitry Andric DesignatorDeps |= E->getArrayRangeStart(D)->getDependence() | 6725ffd83dbSDimitry Andric E->getArrayRangeEnd(D)->getDependence(); 6735ffd83dbSDimitry Andric Deps |= DesignatorDeps; 6745ffd83dbSDimitry Andric if (DesignatorDeps & ExprDependence::TypeValue) 6755ffd83dbSDimitry Andric Deps |= ExprDependence::TypeValueInstantiation; 6765ffd83dbSDimitry Andric } 6775ffd83dbSDimitry Andric return Deps; 6785ffd83dbSDimitry Andric } 6795ffd83dbSDimitry Andric 6805ffd83dbSDimitry Andric ExprDependence clang::computeDependence(PseudoObjectExpr *O) { 6815ffd83dbSDimitry Andric auto D = O->getSyntacticForm()->getDependence(); 6825ffd83dbSDimitry Andric for (auto *E : O->semantics()) 6835ffd83dbSDimitry Andric D |= E->getDependence(); 6845ffd83dbSDimitry Andric return D; 6855ffd83dbSDimitry Andric } 6865ffd83dbSDimitry Andric 6875ffd83dbSDimitry Andric ExprDependence clang::computeDependence(AtomicExpr *A) { 6885ffd83dbSDimitry Andric auto D = ExprDependence::None; 6895ffd83dbSDimitry Andric for (auto *E : llvm::makeArrayRef(A->getSubExprs(), A->getNumSubExprs())) 6905ffd83dbSDimitry Andric D |= E->getDependence(); 6915ffd83dbSDimitry Andric return D; 6925ffd83dbSDimitry Andric } 6935ffd83dbSDimitry Andric 6945ffd83dbSDimitry Andric ExprDependence clang::computeDependence(CXXNewExpr *E) { 695*3b7f365eSDimitry Andric auto D = toExprDependenceAsWritten( 696*3b7f365eSDimitry Andric E->getAllocatedTypeSourceInfo()->getType()->getDependence()); 697*3b7f365eSDimitry Andric D |= toExprDependenceForImpliedType(E->getAllocatedType()->getDependence()); 6985ffd83dbSDimitry Andric auto Size = E->getArraySize(); 6995ffd83dbSDimitry Andric if (Size.hasValue() && *Size) 7005ffd83dbSDimitry Andric D |= turnTypeToValueDependence((*Size)->getDependence()); 7015ffd83dbSDimitry Andric if (auto *I = E->getInitializer()) 7025ffd83dbSDimitry Andric D |= turnTypeToValueDependence(I->getDependence()); 7035ffd83dbSDimitry Andric for (auto *A : E->placement_arguments()) 7045ffd83dbSDimitry Andric D |= turnTypeToValueDependence(A->getDependence()); 7055ffd83dbSDimitry Andric return D; 7065ffd83dbSDimitry Andric } 7075ffd83dbSDimitry Andric 7085ffd83dbSDimitry Andric ExprDependence clang::computeDependence(CXXPseudoDestructorExpr *E) { 7095ffd83dbSDimitry Andric auto D = E->getBase()->getDependence(); 710*3b7f365eSDimitry Andric if (auto *TSI = E->getDestroyedTypeInfo()) 711*3b7f365eSDimitry Andric D |= toExprDependenceAsWritten(TSI->getType()->getDependence()); 7125ffd83dbSDimitry Andric if (auto *ST = E->getScopeTypeInfo()) 7135ffd83dbSDimitry Andric D |= turnTypeToValueDependence( 714*3b7f365eSDimitry Andric toExprDependenceAsWritten(ST->getType()->getDependence())); 7155ffd83dbSDimitry Andric if (auto *Q = E->getQualifier()) 7165ffd83dbSDimitry Andric D |= toExprDependence(Q->getDependence() & 7175ffd83dbSDimitry Andric ~NestedNameSpecifierDependence::Dependent); 7185ffd83dbSDimitry Andric return D; 7195ffd83dbSDimitry Andric } 7205ffd83dbSDimitry Andric 7215ffd83dbSDimitry Andric static inline ExprDependence getDependenceInExpr(DeclarationNameInfo Name) { 7225ffd83dbSDimitry Andric auto D = ExprDependence::None; 7235ffd83dbSDimitry Andric if (Name.isInstantiationDependent()) 7245ffd83dbSDimitry Andric D |= ExprDependence::Instantiation; 7255ffd83dbSDimitry Andric if (Name.containsUnexpandedParameterPack()) 7265ffd83dbSDimitry Andric D |= ExprDependence::UnexpandedPack; 7275ffd83dbSDimitry Andric return D; 7285ffd83dbSDimitry Andric } 7295ffd83dbSDimitry Andric 7305ffd83dbSDimitry Andric ExprDependence 7315ffd83dbSDimitry Andric clang::computeDependence(OverloadExpr *E, bool KnownDependent, 7325ffd83dbSDimitry Andric bool KnownInstantiationDependent, 7335ffd83dbSDimitry Andric bool KnownContainsUnexpandedParameterPack) { 7345ffd83dbSDimitry Andric auto Deps = ExprDependence::None; 7355ffd83dbSDimitry Andric if (KnownDependent) 7365ffd83dbSDimitry Andric Deps |= ExprDependence::TypeValue; 7375ffd83dbSDimitry Andric if (KnownInstantiationDependent) 7385ffd83dbSDimitry Andric Deps |= ExprDependence::Instantiation; 7395ffd83dbSDimitry Andric if (KnownContainsUnexpandedParameterPack) 7405ffd83dbSDimitry Andric Deps |= ExprDependence::UnexpandedPack; 7415ffd83dbSDimitry Andric Deps |= getDependenceInExpr(E->getNameInfo()); 7425ffd83dbSDimitry Andric if (auto *Q = E->getQualifier()) 7435ffd83dbSDimitry Andric Deps |= toExprDependence(Q->getDependence() & 7445ffd83dbSDimitry Andric ~NestedNameSpecifierDependence::Dependent); 7455ffd83dbSDimitry Andric for (auto *D : E->decls()) { 7465ffd83dbSDimitry Andric if (D->getDeclContext()->isDependentContext() || 7475ffd83dbSDimitry Andric isa<UnresolvedUsingValueDecl>(D)) 7485ffd83dbSDimitry Andric Deps |= ExprDependence::TypeValueInstantiation; 7495ffd83dbSDimitry Andric } 7505ffd83dbSDimitry Andric // If we have explicit template arguments, check for dependent 7515ffd83dbSDimitry Andric // template arguments and whether they contain any unexpanded pack 7525ffd83dbSDimitry Andric // expansions. 7535ffd83dbSDimitry Andric for (auto A : E->template_arguments()) 7545ffd83dbSDimitry Andric Deps |= toExprDependence(A.getArgument().getDependence()); 7555ffd83dbSDimitry Andric return Deps; 7565ffd83dbSDimitry Andric } 7575ffd83dbSDimitry Andric 7585ffd83dbSDimitry Andric ExprDependence clang::computeDependence(DependentScopeDeclRefExpr *E) { 7595ffd83dbSDimitry Andric auto D = ExprDependence::TypeValue; 7605ffd83dbSDimitry Andric D |= getDependenceInExpr(E->getNameInfo()); 7615ffd83dbSDimitry Andric if (auto *Q = E->getQualifier()) 7625ffd83dbSDimitry Andric D |= toExprDependence(Q->getDependence()); 7635ffd83dbSDimitry Andric for (auto A : E->template_arguments()) 7645ffd83dbSDimitry Andric D |= toExprDependence(A.getArgument().getDependence()); 7655ffd83dbSDimitry Andric return D; 7665ffd83dbSDimitry Andric } 7675ffd83dbSDimitry Andric 7685ffd83dbSDimitry Andric ExprDependence clang::computeDependence(CXXConstructExpr *E) { 769*3b7f365eSDimitry Andric ExprDependence D = 770*3b7f365eSDimitry Andric toExprDependenceForImpliedType(E->getType()->getDependence()); 7715ffd83dbSDimitry Andric for (auto *A : E->arguments()) 7725ffd83dbSDimitry Andric D |= A->getDependence() & ~ExprDependence::Type; 7735ffd83dbSDimitry Andric return D; 7745ffd83dbSDimitry Andric } 7755ffd83dbSDimitry Andric 776*3b7f365eSDimitry Andric ExprDependence clang::computeDependence(CXXTemporaryObjectExpr *E) { 777*3b7f365eSDimitry Andric CXXConstructExpr *BaseE = E; 778*3b7f365eSDimitry Andric return toExprDependenceAsWritten( 779*3b7f365eSDimitry Andric E->getTypeSourceInfo()->getType()->getDependence()) | 780*3b7f365eSDimitry Andric computeDependence(BaseE); 781*3b7f365eSDimitry Andric } 782*3b7f365eSDimitry Andric 783e8d8bef9SDimitry Andric ExprDependence clang::computeDependence(CXXDefaultInitExpr *E) { 784e8d8bef9SDimitry Andric return E->getExpr()->getDependence(); 785e8d8bef9SDimitry Andric } 786e8d8bef9SDimitry Andric 787fe6060f1SDimitry Andric ExprDependence clang::computeDependence(CXXDefaultArgExpr *E) { 788fe6060f1SDimitry Andric return E->getExpr()->getDependence(); 789fe6060f1SDimitry Andric } 790fe6060f1SDimitry Andric 7915ffd83dbSDimitry Andric ExprDependence clang::computeDependence(LambdaExpr *E, 7925ffd83dbSDimitry Andric bool ContainsUnexpandedParameterPack) { 793*3b7f365eSDimitry Andric auto D = toExprDependenceForImpliedType(E->getType()->getDependence()); 7945ffd83dbSDimitry Andric if (ContainsUnexpandedParameterPack) 7955ffd83dbSDimitry Andric D |= ExprDependence::UnexpandedPack; 7965ffd83dbSDimitry Andric return D; 7975ffd83dbSDimitry Andric } 7985ffd83dbSDimitry Andric 7995ffd83dbSDimitry Andric ExprDependence clang::computeDependence(CXXUnresolvedConstructExpr *E) { 8005ffd83dbSDimitry Andric auto D = ExprDependence::ValueInstantiation; 801*3b7f365eSDimitry Andric D |= toExprDependenceAsWritten(E->getTypeAsWritten()->getDependence()); 802*3b7f365eSDimitry Andric D |= toExprDependenceForImpliedType(E->getType()->getDependence()); 8035ffd83dbSDimitry Andric for (auto *A : E->arguments()) 8045ffd83dbSDimitry Andric D |= A->getDependence() & 8055ffd83dbSDimitry Andric (ExprDependence::UnexpandedPack | ExprDependence::Error); 8065ffd83dbSDimitry Andric return D; 8075ffd83dbSDimitry Andric } 8085ffd83dbSDimitry Andric 8095ffd83dbSDimitry Andric ExprDependence clang::computeDependence(CXXDependentScopeMemberExpr *E) { 8105ffd83dbSDimitry Andric auto D = ExprDependence::TypeValueInstantiation; 8115ffd83dbSDimitry Andric if (!E->isImplicitAccess()) 8125ffd83dbSDimitry Andric D |= E->getBase()->getDependence(); 8135ffd83dbSDimitry Andric if (auto *Q = E->getQualifier()) 8145ffd83dbSDimitry Andric D |= toExprDependence(Q->getDependence()); 8155ffd83dbSDimitry Andric D |= getDependenceInExpr(E->getMemberNameInfo()); 8165ffd83dbSDimitry Andric for (auto A : E->template_arguments()) 8175ffd83dbSDimitry Andric D |= toExprDependence(A.getArgument().getDependence()); 8185ffd83dbSDimitry Andric return D; 8195ffd83dbSDimitry Andric } 8205ffd83dbSDimitry Andric 8215ffd83dbSDimitry Andric ExprDependence clang::computeDependence(MaterializeTemporaryExpr *E) { 8225ffd83dbSDimitry Andric return E->getSubExpr()->getDependence(); 8235ffd83dbSDimitry Andric } 8245ffd83dbSDimitry Andric 8255ffd83dbSDimitry Andric ExprDependence clang::computeDependence(CXXFoldExpr *E) { 8265ffd83dbSDimitry Andric auto D = ExprDependence::TypeValueInstantiation; 8275ffd83dbSDimitry Andric for (const auto *C : {E->getLHS(), E->getRHS()}) { 8285ffd83dbSDimitry Andric if (C) 8295ffd83dbSDimitry Andric D |= C->getDependence() & ~ExprDependence::UnexpandedPack; 8305ffd83dbSDimitry Andric } 8315ffd83dbSDimitry Andric return D; 8325ffd83dbSDimitry Andric } 8335ffd83dbSDimitry Andric 8345ffd83dbSDimitry Andric ExprDependence clang::computeDependence(TypeTraitExpr *E) { 8355ffd83dbSDimitry Andric auto D = ExprDependence::None; 8365ffd83dbSDimitry Andric for (const auto *A : E->getArgs()) 837*3b7f365eSDimitry Andric D |= toExprDependenceAsWritten(A->getType()->getDependence()) & 838*3b7f365eSDimitry Andric ~ExprDependence::Type; 8395ffd83dbSDimitry Andric return D; 8405ffd83dbSDimitry Andric } 8415ffd83dbSDimitry Andric 8425ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ConceptSpecializationExpr *E, 8435ffd83dbSDimitry Andric bool ValueDependent) { 8445ffd83dbSDimitry Andric auto TA = TemplateArgumentDependence::None; 8455ffd83dbSDimitry Andric const auto InterestingDeps = TemplateArgumentDependence::Instantiation | 8465ffd83dbSDimitry Andric TemplateArgumentDependence::UnexpandedPack; 8475ffd83dbSDimitry Andric for (const TemplateArgumentLoc &ArgLoc : 8485ffd83dbSDimitry Andric E->getTemplateArgsAsWritten()->arguments()) { 8495ffd83dbSDimitry Andric TA |= ArgLoc.getArgument().getDependence() & InterestingDeps; 8505ffd83dbSDimitry Andric if (TA == InterestingDeps) 8515ffd83dbSDimitry Andric break; 8525ffd83dbSDimitry Andric } 8535ffd83dbSDimitry Andric 8545ffd83dbSDimitry Andric ExprDependence D = 8555ffd83dbSDimitry Andric ValueDependent ? ExprDependence::Value : ExprDependence::None; 8565ffd83dbSDimitry Andric return D | toExprDependence(TA); 8575ffd83dbSDimitry Andric } 8585ffd83dbSDimitry Andric 8595ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ObjCArrayLiteral *E) { 8605ffd83dbSDimitry Andric auto D = ExprDependence::None; 8615ffd83dbSDimitry Andric Expr **Elements = E->getElements(); 8625ffd83dbSDimitry Andric for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) 8635ffd83dbSDimitry Andric D |= turnTypeToValueDependence(Elements[I]->getDependence()); 8645ffd83dbSDimitry Andric return D; 8655ffd83dbSDimitry Andric } 8665ffd83dbSDimitry Andric 8675ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ObjCDictionaryLiteral *E) { 8685ffd83dbSDimitry Andric auto Deps = ExprDependence::None; 8695ffd83dbSDimitry Andric for (unsigned I = 0, N = E->getNumElements(); I < N; ++I) { 8705ffd83dbSDimitry Andric auto KV = E->getKeyValueElement(I); 8715ffd83dbSDimitry Andric auto KVDeps = turnTypeToValueDependence(KV.Key->getDependence() | 8725ffd83dbSDimitry Andric KV.Value->getDependence()); 8735ffd83dbSDimitry Andric if (KV.EllipsisLoc.isValid()) 8745ffd83dbSDimitry Andric KVDeps &= ~ExprDependence::UnexpandedPack; 8755ffd83dbSDimitry Andric Deps |= KVDeps; 8765ffd83dbSDimitry Andric } 8775ffd83dbSDimitry Andric return Deps; 8785ffd83dbSDimitry Andric } 8795ffd83dbSDimitry Andric 8805ffd83dbSDimitry Andric ExprDependence clang::computeDependence(ObjCMessageExpr *E) { 8815ffd83dbSDimitry Andric auto D = ExprDependence::None; 8825ffd83dbSDimitry Andric if (auto *R = E->getInstanceReceiver()) 8835ffd83dbSDimitry Andric D |= R->getDependence(); 8845ffd83dbSDimitry Andric else 885*3b7f365eSDimitry Andric D |= toExprDependenceForImpliedType(E->getType()->getDependence()); 8865ffd83dbSDimitry Andric for (auto *A : E->arguments()) 8875ffd83dbSDimitry Andric D |= A->getDependence(); 8885ffd83dbSDimitry Andric return D; 8895ffd83dbSDimitry Andric } 890