1 //===- ComputeDependence.cpp ----------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "clang/AST/ComputeDependence.h" 10 #include "clang/AST/Attr.h" 11 #include "clang/AST/DeclCXX.h" 12 #include "clang/AST/DeclarationName.h" 13 #include "clang/AST/DependenceFlags.h" 14 #include "clang/AST/Expr.h" 15 #include "clang/AST/ExprCXX.h" 16 #include "clang/AST/ExprConcepts.h" 17 #include "clang/AST/ExprObjC.h" 18 #include "clang/AST/ExprOpenMP.h" 19 #include "clang/Basic/ExceptionSpecificationType.h" 20 #include "llvm/ADT/ArrayRef.h" 21 22 using namespace clang; 23 24 ExprDependence clang::computeDependence(FullExpr *E) { 25 return E->getSubExpr()->getDependence(); 26 } 27 28 ExprDependence clang::computeDependence(OpaqueValueExpr *E) { 29 auto D = toExprDependence(E->getType()->getDependence()); 30 if (auto *S = E->getSourceExpr()) 31 D |= S->getDependence(); 32 assert(!(D & ExprDependence::UnexpandedPack)); 33 return D; 34 } 35 36 ExprDependence clang::computeDependence(ParenExpr *E) { 37 return E->getSubExpr()->getDependence(); 38 } 39 40 ExprDependence clang::computeDependence(UnaryOperator *E) { 41 return toExprDependence(E->getType()->getDependence()) | 42 E->getSubExpr()->getDependence(); 43 } 44 45 ExprDependence clang::computeDependence(UnaryExprOrTypeTraitExpr *E) { 46 // Never type-dependent (C++ [temp.dep.expr]p3). 47 // Value-dependent if the argument is type-dependent. 48 if (E->isArgumentType()) 49 return turnTypeToValueDependence( 50 toExprDependence(E->getArgumentType()->getDependence())); 51 52 auto ArgDeps = E->getArgumentExpr()->getDependence(); 53 auto Deps = ArgDeps & ~ExprDependence::TypeValue; 54 // Value-dependent if the argument is type-dependent. 55 if (ArgDeps & ExprDependence::Type) 56 Deps |= ExprDependence::Value; 57 // Check to see if we are in the situation where alignof(decl) should be 58 // dependent because decl's alignment is dependent. 59 auto ExprKind = E->getKind(); 60 if (ExprKind != UETT_AlignOf && ExprKind != UETT_PreferredAlignOf) 61 return Deps; 62 if ((Deps & ExprDependence::Value) && (Deps & ExprDependence::Instantiation)) 63 return Deps; 64 65 auto *NoParens = E->getArgumentExpr()->IgnoreParens(); 66 const ValueDecl *D = nullptr; 67 if (const auto *DRE = dyn_cast<DeclRefExpr>(NoParens)) 68 D = DRE->getDecl(); 69 else if (const auto *ME = dyn_cast<MemberExpr>(NoParens)) 70 D = ME->getMemberDecl(); 71 if (!D) 72 return Deps; 73 for (const auto *I : D->specific_attrs<AlignedAttr>()) { 74 if (I->isAlignmentErrorDependent()) 75 Deps |= ExprDependence::Error; 76 if (I->isAlignmentDependent()) 77 Deps |= ExprDependence::ValueInstantiation; 78 } 79 return Deps; 80 } 81 82 ExprDependence clang::computeDependence(ArraySubscriptExpr *E) { 83 return E->getLHS()->getDependence() | E->getRHS()->getDependence(); 84 } 85 86 ExprDependence clang::computeDependence(CompoundLiteralExpr *E) { 87 return toExprDependence(E->getTypeSourceInfo()->getType()->getDependence()) | 88 turnTypeToValueDependence(E->getInitializer()->getDependence()); 89 } 90 91 ExprDependence clang::computeDependence(CastExpr *E) { 92 // Cast expressions are type-dependent if the type is 93 // dependent (C++ [temp.dep.expr]p3). 94 // Cast expressions are value-dependent if the type is 95 // dependent or if the subexpression is value-dependent. 96 auto D = toExprDependence(E->getType()->getDependence()); 97 if (E->getStmtClass() == Stmt::ImplicitCastExprClass) { 98 // An implicit cast expression doesn't (lexically) contain an 99 // unexpanded pack, even if its target type does. 100 D &= ~ExprDependence::UnexpandedPack; 101 } 102 if (auto *S = E->getSubExpr()) 103 D |= S->getDependence() & ~ExprDependence::Type; 104 return D; 105 } 106 107 ExprDependence clang::computeDependence(BinaryOperator *E) { 108 return E->getLHS()->getDependence() | E->getRHS()->getDependence(); 109 } 110 111 ExprDependence clang::computeDependence(ConditionalOperator *E) { 112 // The type of the conditional operator depends on the type of the conditional 113 // to support the GCC vector conditional extension. Additionally, 114 // [temp.dep.expr] does specify state that this should be dependent on ALL sub 115 // expressions. 116 return E->getCond()->getDependence() | E->getLHS()->getDependence() | 117 E->getRHS()->getDependence(); 118 } 119 120 ExprDependence clang::computeDependence(BinaryConditionalOperator *E) { 121 return E->getCommon()->getDependence() | E->getFalseExpr()->getDependence(); 122 } 123 124 ExprDependence clang::computeDependence(StmtExpr *E, unsigned TemplateDepth) { 125 // FIXME: why is unexpanded-pack not propagated? 126 auto D = toExprDependence(E->getType()->getDependence()) & 127 ~ExprDependence::UnexpandedPack; 128 // Note: we treat a statement-expression in a dependent context as always 129 // being value- and instantiation-dependent. This matches the behavior of 130 // lambda-expressions and GCC. 131 if (TemplateDepth) 132 D |= ExprDependence::ValueInstantiation; 133 return D; 134 } 135 136 ExprDependence clang::computeDependence(ConvertVectorExpr *E) { 137 auto D = toExprDependence(E->getType()->getDependence()) | 138 E->getSrcExpr()->getDependence(); 139 if (!E->getType()->isDependentType()) 140 D &= ~ExprDependence::Type; 141 return D; 142 } 143 144 ExprDependence clang::computeDependence(ChooseExpr *E) { 145 if (E->isConditionDependent()) 146 return ExprDependence::TypeValueInstantiation | 147 E->getCond()->getDependence() | E->getLHS()->getDependence() | 148 E->getRHS()->getDependence(); 149 150 auto Cond = E->getCond()->getDependence(); 151 auto Active = E->getLHS()->getDependence(); 152 auto Inactive = E->getRHS()->getDependence(); 153 if (!E->isConditionTrue()) 154 std::swap(Active, Inactive); 155 // Take type- and value- dependency from the active branch. Propagate all 156 // other flags from all branches. 157 return (Active & ExprDependence::TypeValue) | 158 ((Cond | Active | Inactive) & ~ExprDependence::TypeValue); 159 } 160 161 ExprDependence clang::computeDependence(ParenListExpr *P) { 162 auto D = ExprDependence::None; 163 for (auto *E : P->exprs()) 164 D |= E->getDependence(); 165 return D; 166 } 167 168 ExprDependence clang::computeDependence(VAArgExpr *E) { 169 auto D = 170 toExprDependence(E->getWrittenTypeInfo()->getType()->getDependence()) | 171 (E->getSubExpr()->getDependence() & ~ExprDependence::Type); 172 return D & ~ExprDependence::Value; 173 } 174 175 ExprDependence clang::computeDependence(NoInitExpr *E) { 176 return toExprDependence(E->getType()->getDependence()) & 177 (ExprDependence::Instantiation | ExprDependence::Error); 178 } 179 180 ExprDependence clang::computeDependence(ArrayInitLoopExpr *E) { 181 auto D = E->getCommonExpr()->getDependence() | 182 E->getSubExpr()->getDependence() | ExprDependence::Instantiation; 183 if (!E->getType()->isInstantiationDependentType()) 184 D &= ~ExprDependence::Instantiation; 185 return turnTypeToValueDependence(D); 186 } 187 188 ExprDependence clang::computeDependence(ImplicitValueInitExpr *E) { 189 return toExprDependence(E->getType()->getDependence()) & 190 ExprDependence::Instantiation; 191 } 192 193 ExprDependence clang::computeDependence(ExtVectorElementExpr *E) { 194 return E->getBase()->getDependence(); 195 } 196 197 ExprDependence clang::computeDependence(BlockExpr *E) { 198 auto D = toExprDependence(E->getType()->getDependence()); 199 if (E->getBlockDecl()->isDependentContext()) 200 D |= ExprDependence::Instantiation; 201 return D & ~ExprDependence::UnexpandedPack; 202 } 203 204 ExprDependence clang::computeDependence(AsTypeExpr *E) { 205 auto D = toExprDependence(E->getType()->getDependence()) | 206 E->getSrcExpr()->getDependence(); 207 if (!E->getType()->isDependentType()) 208 D &= ~ExprDependence::Type; 209 return D; 210 } 211 212 ExprDependence clang::computeDependence(CXXRewrittenBinaryOperator *E) { 213 return E->getSemanticForm()->getDependence(); 214 } 215 216 ExprDependence clang::computeDependence(CXXStdInitializerListExpr *E) { 217 auto D = turnTypeToValueDependence(E->getSubExpr()->getDependence()); 218 D |= toExprDependence(E->getType()->getDependence()) & 219 (ExprDependence::Type | ExprDependence::Error); 220 return D; 221 } 222 223 ExprDependence clang::computeDependence(CXXTypeidExpr *E) { 224 auto D = ExprDependence::None; 225 if (E->isTypeOperand()) 226 D = toExprDependence( 227 E->getTypeOperandSourceInfo()->getType()->getDependence()); 228 else 229 D = turnTypeToValueDependence(E->getExprOperand()->getDependence()); 230 // typeid is never type-dependent (C++ [temp.dep.expr]p4) 231 return D & ~ExprDependence::Type; 232 } 233 234 ExprDependence clang::computeDependence(MSPropertyRefExpr *E) { 235 return E->getBaseExpr()->getDependence() & ~ExprDependence::Type; 236 } 237 238 ExprDependence clang::computeDependence(MSPropertySubscriptExpr *E) { 239 return E->getIdx()->getDependence(); 240 } 241 242 ExprDependence clang::computeDependence(CXXUuidofExpr *E) { 243 if (E->isTypeOperand()) 244 return turnTypeToValueDependence(toExprDependence( 245 E->getTypeOperandSourceInfo()->getType()->getDependence())); 246 247 return turnTypeToValueDependence(E->getExprOperand()->getDependence()); 248 } 249 250 ExprDependence clang::computeDependence(CXXThisExpr *E) { 251 // 'this' is type-dependent if the class type of the enclosing 252 // member function is dependent (C++ [temp.dep.expr]p2) 253 auto D = toExprDependence(E->getType()->getDependence()); 254 assert(!(D & ExprDependence::UnexpandedPack)); 255 return D; 256 } 257 258 ExprDependence clang::computeDependence(CXXThrowExpr *E) { 259 auto *Op = E->getSubExpr(); 260 if (!Op) 261 return ExprDependence::None; 262 return Op->getDependence() & ~ExprDependence::TypeValue; 263 } 264 265 ExprDependence clang::computeDependence(CXXBindTemporaryExpr *E) { 266 return E->getSubExpr()->getDependence(); 267 } 268 269 ExprDependence clang::computeDependence(CXXScalarValueInitExpr *E) { 270 return toExprDependence(E->getType()->getDependence()) & 271 ~ExprDependence::TypeValue; 272 } 273 274 ExprDependence clang::computeDependence(CXXDeleteExpr *E) { 275 return turnTypeToValueDependence(E->getArgument()->getDependence()); 276 } 277 278 ExprDependence clang::computeDependence(ArrayTypeTraitExpr *E) { 279 auto D = toExprDependence(E->getQueriedType()->getDependence()); 280 if (auto *Dim = E->getDimensionExpression()) 281 D |= Dim->getDependence(); 282 return turnTypeToValueDependence(D); 283 } 284 285 ExprDependence clang::computeDependence(ExpressionTraitExpr *E) { 286 // Never type-dependent. 287 auto D = E->getQueriedExpression()->getDependence() & ~ExprDependence::Type; 288 // Value-dependent if the argument is type-dependent. 289 if (E->getQueriedExpression()->isTypeDependent()) 290 D |= ExprDependence::Value; 291 return D; 292 } 293 294 ExprDependence clang::computeDependence(CXXNoexceptExpr *E, CanThrowResult CT) { 295 auto D = E->getOperand()->getDependence() & ~ExprDependence::TypeValue; 296 if (CT == CT_Dependent) 297 D |= ExprDependence::ValueInstantiation; 298 return D; 299 } 300 301 ExprDependence clang::computeDependence(PackExpansionExpr *E) { 302 return (E->getPattern()->getDependence() & ~ExprDependence::UnexpandedPack) | 303 ExprDependence::TypeValueInstantiation; 304 } 305 306 ExprDependence clang::computeDependence(SubstNonTypeTemplateParmExpr *E) { 307 return E->getReplacement()->getDependence(); 308 } 309 310 ExprDependence clang::computeDependence(CoroutineSuspendExpr *E) { 311 if (auto *Resume = E->getResumeExpr()) 312 return (Resume->getDependence() & 313 (ExprDependence::TypeValue | ExprDependence::Error)) | 314 (E->getCommonExpr()->getDependence() & ~ExprDependence::TypeValue); 315 return E->getCommonExpr()->getDependence() | 316 ExprDependence::TypeValueInstantiation; 317 } 318 319 ExprDependence clang::computeDependence(DependentCoawaitExpr *E) { 320 return E->getOperand()->getDependence() | 321 ExprDependence::TypeValueInstantiation; 322 } 323 324 ExprDependence clang::computeDependence(ObjCBoxedExpr *E) { 325 return E->getSubExpr()->getDependence(); 326 } 327 328 ExprDependence clang::computeDependence(ObjCEncodeExpr *E) { 329 return toExprDependence(E->getEncodedType()->getDependence()); 330 } 331 332 ExprDependence clang::computeDependence(ObjCIvarRefExpr *E) { 333 return turnTypeToValueDependence(E->getBase()->getDependence()); 334 } 335 336 ExprDependence clang::computeDependence(ObjCPropertyRefExpr *E) { 337 if (E->isObjectReceiver()) 338 return E->getBase()->getDependence() & ~ExprDependence::Type; 339 if (E->isSuperReceiver()) 340 return toExprDependence(E->getSuperReceiverType()->getDependence()) & 341 ~ExprDependence::TypeValue; 342 assert(E->isClassReceiver()); 343 return ExprDependence::None; 344 } 345 346 ExprDependence clang::computeDependence(ObjCSubscriptRefExpr *E) { 347 return E->getBaseExpr()->getDependence() | E->getKeyExpr()->getDependence(); 348 } 349 350 ExprDependence clang::computeDependence(ObjCIsaExpr *E) { 351 return E->getBase()->getDependence() & ~ExprDependence::Type & 352 ~ExprDependence::UnexpandedPack; 353 } 354 355 ExprDependence clang::computeDependence(ObjCIndirectCopyRestoreExpr *E) { 356 return E->getSubExpr()->getDependence(); 357 } 358 359 ExprDependence clang::computeDependence(OMPArraySectionExpr *E) { 360 auto D = E->getBase()->getDependence(); 361 if (auto *LB = E->getLowerBound()) 362 D |= LB->getDependence(); 363 if (auto *Len = E->getLength()) 364 D |= Len->getDependence(); 365 return D; 366 } 367 368 ExprDependence clang::computeDependence(OMPArrayShapingExpr *E) { 369 auto D = E->getBase()->getDependence() | 370 toExprDependence(E->getType()->getDependence()); 371 for (Expr *Dim: E->getDimensions()) 372 if (Dim) 373 D |= Dim->getDependence(); 374 return D; 375 } 376 377 ExprDependence clang::computeDependence(OMPIteratorExpr *E) { 378 auto D = toExprDependence(E->getType()->getDependence()); 379 for (unsigned I = 0, End = E->numOfIterators(); I < End; ++I) { 380 if (auto *VD = cast_or_null<ValueDecl>(E->getIteratorDecl(I))) 381 D |= toExprDependence(VD->getType()->getDependence()); 382 OMPIteratorExpr::IteratorRange IR = E->getIteratorRange(I); 383 if (Expr *BE = IR.Begin) 384 D |= BE->getDependence(); 385 if (Expr *EE = IR.End) 386 D |= EE->getDependence(); 387 if (Expr *SE = IR.Step) 388 D |= SE->getDependence(); 389 } 390 return D; 391 } 392 393 /// Compute the type-, value-, and instantiation-dependence of a 394 /// declaration reference 395 /// based on the declaration being referenced. 396 ExprDependence clang::computeDependence(DeclRefExpr *E, const ASTContext &Ctx) { 397 auto Deps = ExprDependence::None; 398 399 if (auto *NNS = E->getQualifier()) 400 Deps |= toExprDependence(NNS->getDependence() & 401 ~NestedNameSpecifierDependence::Dependent); 402 403 if (auto *FirstArg = E->getTemplateArgs()) { 404 unsigned NumArgs = E->getNumTemplateArgs(); 405 for (auto *Arg = FirstArg, *End = FirstArg + NumArgs; Arg < End; ++Arg) 406 Deps |= toExprDependence(Arg->getArgument().getDependence()); 407 } 408 409 auto *Decl = E->getDecl(); 410 auto Type = E->getType(); 411 412 if (Decl->isParameterPack()) 413 Deps |= ExprDependence::UnexpandedPack; 414 Deps |= toExprDependence(Type->getDependence()) & ExprDependence::Error; 415 416 // (TD) C++ [temp.dep.expr]p3: 417 // An id-expression is type-dependent if it contains: 418 // 419 // and 420 // 421 // (VD) C++ [temp.dep.constexpr]p2: 422 // An identifier is value-dependent if it is: 423 424 // (TD) - an identifier that was declared with dependent type 425 // (VD) - a name declared with a dependent type, 426 if (Type->isDependentType()) 427 return Deps | ExprDependence::TypeValueInstantiation; 428 else if (Type->isInstantiationDependentType()) 429 Deps |= ExprDependence::Instantiation; 430 431 // (TD) - a conversion-function-id that specifies a dependent type 432 if (Decl->getDeclName().getNameKind() == 433 DeclarationName::CXXConversionFunctionName) { 434 QualType T = Decl->getDeclName().getCXXNameType(); 435 if (T->isDependentType()) 436 return Deps | ExprDependence::TypeValueInstantiation; 437 438 if (T->isInstantiationDependentType()) 439 Deps |= ExprDependence::Instantiation; 440 } 441 442 // (VD) - the name of a non-type template parameter, 443 if (isa<NonTypeTemplateParmDecl>(Decl)) 444 return Deps | ExprDependence::ValueInstantiation; 445 446 // (VD) - a constant with integral or enumeration type and is 447 // initialized with an expression that is value-dependent. 448 // (VD) - a constant with literal type and is initialized with an 449 // expression that is value-dependent [C++11]. 450 // (VD) - FIXME: Missing from the standard: 451 // - an entity with reference type and is initialized with an 452 // expression that is value-dependent [C++11] 453 if (VarDecl *Var = dyn_cast<VarDecl>(Decl)) { 454 if ((Ctx.getLangOpts().CPlusPlus11 455 ? Var->getType()->isLiteralType(Ctx) 456 : Var->getType()->isIntegralOrEnumerationType()) && 457 (Var->getType().isConstQualified() || 458 Var->getType()->isReferenceType())) { 459 if (const Expr *Init = Var->getAnyInitializer()) 460 if (Init->isValueDependent()) { 461 Deps |= ExprDependence::ValueInstantiation; 462 } 463 } 464 465 // (VD) - FIXME: Missing from the standard: 466 // - a member function or a static data member of the current 467 // instantiation 468 if (Var->isStaticDataMember() && 469 Var->getDeclContext()->isDependentContext()) { 470 Deps |= ExprDependence::ValueInstantiation; 471 TypeSourceInfo *TInfo = Var->getFirstDecl()->getTypeSourceInfo(); 472 if (TInfo->getType()->isIncompleteArrayType()) 473 Deps |= ExprDependence::Type; 474 } 475 476 return Deps; 477 } 478 479 // (VD) - FIXME: Missing from the standard: 480 // - a member function or a static data member of the current 481 // instantiation 482 if (isa<CXXMethodDecl>(Decl) && Decl->getDeclContext()->isDependentContext()) 483 Deps |= ExprDependence::ValueInstantiation; 484 return Deps; 485 } 486 487 ExprDependence clang::computeDependence(RecoveryExpr *E) { 488 // FIXME: drop type+value+instantiation once Error is sufficient to suppress 489 // bogus dianostics. 490 auto D = ExprDependence::TypeValueInstantiation | ExprDependence::Error; 491 for (auto *S : E->subExpressions()) 492 D |= S->getDependence(); 493 return D; 494 } 495 496 ExprDependence clang::computeDependence(PredefinedExpr *E) { 497 return toExprDependence(E->getType()->getDependence()) & 498 ~ExprDependence::UnexpandedPack; 499 } 500 501 ExprDependence clang::computeDependence(CallExpr *E, 502 llvm::ArrayRef<Expr *> PreArgs) { 503 auto D = E->getCallee()->getDependence(); 504 for (auto *A : llvm::makeArrayRef(E->getArgs(), E->getNumArgs())) { 505 if (A) 506 D |= A->getDependence(); 507 } 508 for (auto *A : PreArgs) 509 D |= A->getDependence(); 510 return D; 511 } 512 513 ExprDependence clang::computeDependence(OffsetOfExpr *E) { 514 auto D = turnTypeToValueDependence( 515 toExprDependence(E->getTypeSourceInfo()->getType()->getDependence())); 516 for (unsigned I = 0, N = E->getNumExpressions(); I < N; ++I) 517 D |= turnTypeToValueDependence(E->getIndexExpr(I)->getDependence()); 518 return D; 519 } 520 521 ExprDependence clang::computeDependence(MemberExpr *E) { 522 auto *MemberDecl = E->getMemberDecl(); 523 auto D = E->getBase()->getDependence(); 524 if (FieldDecl *FD = dyn_cast<FieldDecl>(MemberDecl)) { 525 DeclContext *DC = MemberDecl->getDeclContext(); 526 // dyn_cast_or_null is used to handle objC variables which do not 527 // have a declaration context. 528 CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(DC); 529 if (RD && RD->isDependentContext() && RD->isCurrentInstantiation(DC)) { 530 if (!E->getType()->isDependentType()) 531 D &= ~ExprDependence::Type; 532 } 533 534 // Bitfield with value-dependent width is type-dependent. 535 if (FD && FD->isBitField() && FD->getBitWidth()->isValueDependent()) { 536 D |= ExprDependence::Type; 537 } 538 } 539 // FIXME: move remaining dependence computation from MemberExpr::Create() 540 return D; 541 } 542 543 ExprDependence clang::computeDependence(InitListExpr *E) { 544 auto D = ExprDependence::None; 545 for (auto *A : E->inits()) 546 D |= A->getDependence(); 547 return D; 548 } 549 550 ExprDependence clang::computeDependence(ShuffleVectorExpr *E) { 551 auto D = toExprDependence(E->getType()->getDependence()); 552 for (auto *C : llvm::makeArrayRef(E->getSubExprs(), E->getNumSubExprs())) 553 D |= C->getDependence(); 554 return D; 555 } 556 557 ExprDependence clang::computeDependence(GenericSelectionExpr *E, 558 bool ContainsUnexpandedPack) { 559 auto D = ContainsUnexpandedPack ? ExprDependence::UnexpandedPack 560 : ExprDependence::None; 561 for (auto *AE : E->getAssocExprs()) 562 D |= AE->getDependence() & ExprDependence::Error; 563 D |= E->getControllingExpr()->getDependence() & ExprDependence::Error; 564 565 if (E->isResultDependent()) 566 return D | ExprDependence::TypeValueInstantiation; 567 return D | (E->getResultExpr()->getDependence() & 568 ~ExprDependence::UnexpandedPack); 569 } 570 571 ExprDependence clang::computeDependence(DesignatedInitExpr *E) { 572 auto Deps = E->getInit()->getDependence(); 573 for (auto D : E->designators()) { 574 auto DesignatorDeps = ExprDependence::None; 575 if (D.isArrayDesignator()) 576 DesignatorDeps |= E->getArrayIndex(D)->getDependence(); 577 else if (D.isArrayRangeDesignator()) 578 DesignatorDeps |= E->getArrayRangeStart(D)->getDependence() | 579 E->getArrayRangeEnd(D)->getDependence(); 580 Deps |= DesignatorDeps; 581 if (DesignatorDeps & ExprDependence::TypeValue) 582 Deps |= ExprDependence::TypeValueInstantiation; 583 } 584 return Deps; 585 } 586 587 ExprDependence clang::computeDependence(PseudoObjectExpr *O) { 588 auto D = O->getSyntacticForm()->getDependence(); 589 for (auto *E : O->semantics()) 590 D |= E->getDependence(); 591 return D; 592 } 593 594 ExprDependence clang::computeDependence(AtomicExpr *A) { 595 auto D = ExprDependence::None; 596 for (auto *E : llvm::makeArrayRef(A->getSubExprs(), A->getNumSubExprs())) 597 D |= E->getDependence(); 598 return D; 599 } 600 601 ExprDependence clang::computeDependence(CXXNewExpr *E) { 602 auto D = toExprDependence(E->getType()->getDependence()); 603 auto Size = E->getArraySize(); 604 if (Size.hasValue() && *Size) 605 D |= turnTypeToValueDependence((*Size)->getDependence()); 606 if (auto *I = E->getInitializer()) 607 D |= turnTypeToValueDependence(I->getDependence()); 608 for (auto *A : E->placement_arguments()) 609 D |= turnTypeToValueDependence(A->getDependence()); 610 return D; 611 } 612 613 ExprDependence clang::computeDependence(CXXPseudoDestructorExpr *E) { 614 auto D = E->getBase()->getDependence(); 615 if (!E->getDestroyedType().isNull()) 616 D |= toExprDependence(E->getDestroyedType()->getDependence()); 617 if (auto *ST = E->getScopeTypeInfo()) 618 D |= turnTypeToValueDependence( 619 toExprDependence(ST->getType()->getDependence())); 620 if (auto *Q = E->getQualifier()) 621 D |= toExprDependence(Q->getDependence() & 622 ~NestedNameSpecifierDependence::Dependent); 623 return D; 624 } 625 626 static inline ExprDependence getDependenceInExpr(DeclarationNameInfo Name) { 627 auto D = ExprDependence::None; 628 if (Name.isInstantiationDependent()) 629 D |= ExprDependence::Instantiation; 630 if (Name.containsUnexpandedParameterPack()) 631 D |= ExprDependence::UnexpandedPack; 632 return D; 633 } 634 635 ExprDependence 636 clang::computeDependence(OverloadExpr *E, bool KnownDependent, 637 bool KnownInstantiationDependent, 638 bool KnownContainsUnexpandedParameterPack) { 639 auto Deps = ExprDependence::None; 640 if (KnownDependent) 641 Deps |= ExprDependence::TypeValue; 642 if (KnownInstantiationDependent) 643 Deps |= ExprDependence::Instantiation; 644 if (KnownContainsUnexpandedParameterPack) 645 Deps |= ExprDependence::UnexpandedPack; 646 Deps |= getDependenceInExpr(E->getNameInfo()); 647 if (auto *Q = E->getQualifier()) 648 Deps |= toExprDependence(Q->getDependence() & 649 ~NestedNameSpecifierDependence::Dependent); 650 for (auto *D : E->decls()) { 651 if (D->getDeclContext()->isDependentContext() || 652 isa<UnresolvedUsingValueDecl>(D)) 653 Deps |= ExprDependence::TypeValueInstantiation; 654 } 655 // If we have explicit template arguments, check for dependent 656 // template arguments and whether they contain any unexpanded pack 657 // expansions. 658 for (auto A : E->template_arguments()) 659 Deps |= toExprDependence(A.getArgument().getDependence()); 660 return Deps; 661 } 662 663 ExprDependence clang::computeDependence(DependentScopeDeclRefExpr *E) { 664 auto D = ExprDependence::TypeValue; 665 D |= getDependenceInExpr(E->getNameInfo()); 666 if (auto *Q = E->getQualifier()) 667 D |= toExprDependence(Q->getDependence()); 668 for (auto A : E->template_arguments()) 669 D |= toExprDependence(A.getArgument().getDependence()); 670 return D; 671 } 672 673 ExprDependence clang::computeDependence(CXXConstructExpr *E) { 674 auto D = toExprDependence(E->getType()->getDependence()); 675 for (auto *A : E->arguments()) 676 D |= A->getDependence() & ~ExprDependence::Type; 677 return D; 678 } 679 680 ExprDependence clang::computeDependence(LambdaExpr *E, 681 bool ContainsUnexpandedParameterPack) { 682 auto D = toExprDependence(E->getType()->getDependence()); 683 if (ContainsUnexpandedParameterPack) 684 D |= ExprDependence::UnexpandedPack; 685 return D; 686 } 687 688 ExprDependence clang::computeDependence(CXXUnresolvedConstructExpr *E) { 689 auto D = ExprDependence::ValueInstantiation; 690 D |= toExprDependence(E->getType()->getDependence()); 691 if (E->getType()->getContainedDeducedType()) 692 D |= ExprDependence::Type; 693 for (auto *A : E->arguments()) 694 D |= A->getDependence() & 695 (ExprDependence::UnexpandedPack | ExprDependence::Error); 696 return D; 697 } 698 699 ExprDependence clang::computeDependence(CXXDependentScopeMemberExpr *E) { 700 auto D = ExprDependence::TypeValueInstantiation; 701 if (!E->isImplicitAccess()) 702 D |= E->getBase()->getDependence(); 703 if (auto *Q = E->getQualifier()) 704 D |= toExprDependence(Q->getDependence()); 705 D |= getDependenceInExpr(E->getMemberNameInfo()); 706 for (auto A : E->template_arguments()) 707 D |= toExprDependence(A.getArgument().getDependence()); 708 return D; 709 } 710 711 ExprDependence clang::computeDependence(MaterializeTemporaryExpr *E) { 712 return E->getSubExpr()->getDependence(); 713 } 714 715 ExprDependence clang::computeDependence(CXXFoldExpr *E) { 716 auto D = ExprDependence::TypeValueInstantiation; 717 for (const auto *C : {E->getLHS(), E->getRHS()}) { 718 if (C) 719 D |= C->getDependence() & ~ExprDependence::UnexpandedPack; 720 } 721 return D; 722 } 723 724 ExprDependence clang::computeDependence(TypeTraitExpr *E) { 725 auto D = ExprDependence::None; 726 for (const auto *A : E->getArgs()) 727 D |= 728 toExprDependence(A->getType()->getDependence()) & ~ExprDependence::Type; 729 return D; 730 } 731 732 ExprDependence clang::computeDependence(ConceptSpecializationExpr *E, 733 bool ValueDependent) { 734 auto TA = TemplateArgumentDependence::None; 735 const auto InterestingDeps = TemplateArgumentDependence::Instantiation | 736 TemplateArgumentDependence::UnexpandedPack; 737 for (const TemplateArgumentLoc &ArgLoc : 738 E->getTemplateArgsAsWritten()->arguments()) { 739 TA |= ArgLoc.getArgument().getDependence() & InterestingDeps; 740 if (TA == InterestingDeps) 741 break; 742 } 743 744 ExprDependence D = 745 ValueDependent ? ExprDependence::Value : ExprDependence::None; 746 return D | toExprDependence(TA); 747 } 748 749 ExprDependence clang::computeDependence(ObjCArrayLiteral *E) { 750 auto D = ExprDependence::None; 751 Expr **Elements = E->getElements(); 752 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) 753 D |= turnTypeToValueDependence(Elements[I]->getDependence()); 754 return D; 755 } 756 757 ExprDependence clang::computeDependence(ObjCDictionaryLiteral *E) { 758 auto Deps = ExprDependence::None; 759 for (unsigned I = 0, N = E->getNumElements(); I < N; ++I) { 760 auto KV = E->getKeyValueElement(I); 761 auto KVDeps = turnTypeToValueDependence(KV.Key->getDependence() | 762 KV.Value->getDependence()); 763 if (KV.EllipsisLoc.isValid()) 764 KVDeps &= ~ExprDependence::UnexpandedPack; 765 Deps |= KVDeps; 766 } 767 return Deps; 768 } 769 770 ExprDependence clang::computeDependence(ObjCMessageExpr *E) { 771 auto D = ExprDependence::None; 772 if (auto *R = E->getInstanceReceiver()) 773 D |= R->getDependence(); 774 else 775 D |= toExprDependence(E->getType()->getDependence()); 776 for (auto *A : E->arguments()) 777 D |= A->getDependence(); 778 return D; 779 } 780