| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | #include "clang/Sema/Overload.h" |
| 13 | #include "clang/AST/ASTLambda.h" |
| 14 | #include "clang/AST/DeclCXX.h" |
| 15 | #include "clang/AST/DeclObjC.h" |
| 16 | #include "clang/AST/DeclTemplate.h" |
| 17 | #include "clang/AST/ExprCXX.h" |
| 18 | #include "clang/AST/ExprObjC.h" |
| 19 | #include "clang/Lex/Preprocessor.h" |
| 20 | #include "clang/Sema/Lookup.h" |
| 21 | #include "clang/Sema/Scope.h" |
| 22 | #include "clang/Sema/ScopeInfo.h" |
| 23 | #include "clang/Sema/SemaInternal.h" |
| 24 | |
| 25 | using namespace clang; |
| 26 | using namespace sema; |
| 27 | |
| 28 | typedef llvm::SmallPtrSet<const CXXRecordDecl*, 4> BaseSet; |
| 29 | |
| 30 | |
| 31 | |
| 32 | static bool isProvablyNotDerivedFrom(Sema &SemaRef, CXXRecordDecl *Record, |
| 33 | const BaseSet &Bases) { |
| 34 | auto BaseIsNotInSet = [&Bases](const CXXRecordDecl *Base) { |
| 35 | return !Bases.count(Base->getCanonicalDecl()); |
| 36 | }; |
| 37 | return BaseIsNotInSet(Record) && Record->forallBases(BaseIsNotInSet); |
| 38 | } |
| 39 | |
| 40 | enum IMAKind { |
| 41 | |
| 42 | IMA_Static, |
| 43 | |
| 44 | |
| 45 | IMA_Mixed, |
| 46 | |
| 47 | |
| 48 | |
| 49 | IMA_Mixed_StaticContext, |
| 50 | |
| 51 | |
| 52 | |
| 53 | IMA_Mixed_Unrelated, |
| 54 | |
| 55 | |
| 56 | IMA_Instance, |
| 57 | |
| 58 | |
| 59 | IMA_Unresolved, |
| 60 | |
| 61 | |
| 62 | IMA_Abstract, |
| 63 | |
| 64 | |
| 65 | |
| 66 | IMA_Unresolved_StaticContext, |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | IMA_Field_Uneval_Context, |
| 72 | |
| 73 | |
| 74 | |
| 75 | IMA_Error_StaticContext, |
| 76 | |
| 77 | |
| 78 | |
| 79 | IMA_Error_Unrelated |
| 80 | }; |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | static IMAKind ClassifyImplicitMemberAccess(Sema &SemaRef, |
| 89 | const LookupResult &R) { |
| 90 | isCXXClassMember()", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaExprMember.cpp", 90, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!R.empty() && (*R.begin())->isCXXClassMember()); |
| 91 | |
| 92 | DeclContext *DC = SemaRef.getFunctionLevelDeclContext(); |
| 93 | |
| 94 | bool isStaticContext = SemaRef.CXXThisTypeOverride.isNull() && |
| 95 | (!isa<CXXMethodDecl>(DC) || cast<CXXMethodDecl>(DC)->isStatic()); |
| 96 | |
| 97 | if (R.isUnresolvableResult()) |
| 98 | return isStaticContext ? IMA_Unresolved_StaticContext : IMA_Unresolved; |
| 99 | |
| 100 | |
| 101 | bool hasNonInstance = false; |
| 102 | bool isField = false; |
| 103 | BaseSet Classes; |
| 104 | for (NamedDecl *D : R) { |
| 105 | |
| 106 | D = D->getUnderlyingDecl(); |
| 107 | |
| 108 | if (D->isCXXInstanceMember()) { |
| 109 | isField |= isa<FieldDecl>(D) || isa<MSPropertyDecl>(D) || |
| 110 | isa<IndirectFieldDecl>(D); |
| 111 | |
| 112 | CXXRecordDecl *R = cast<CXXRecordDecl>(D->getDeclContext()); |
| 113 | Classes.insert(R->getCanonicalDecl()); |
| 114 | } else |
| 115 | hasNonInstance = true; |
| 116 | } |
| 117 | |
| 118 | |
| 119 | |
| 120 | if (Classes.empty()) |
| 121 | return IMA_Static; |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | IMAKind AbstractInstanceResult = IMA_Static; |
| 133 | assert(!AbstractInstanceResult); |
| 134 | switch (SemaRef.ExprEvalContexts.back().Context) { |
| 135 | case Sema::ExpressionEvaluationContext::Unevaluated: |
| 136 | case Sema::ExpressionEvaluationContext::UnevaluatedList: |
| 137 | if (isField && SemaRef.getLangOpts().CPlusPlus11) |
| 138 | AbstractInstanceResult = IMA_Field_Uneval_Context; |
| 139 | break; |
| 140 | |
| 141 | case Sema::ExpressionEvaluationContext::UnevaluatedAbstract: |
| 142 | AbstractInstanceResult = IMA_Abstract; |
| 143 | break; |
| 144 | |
| 145 | case Sema::ExpressionEvaluationContext::DiscardedStatement: |
| 146 | case Sema::ExpressionEvaluationContext::ConstantEvaluated: |
| 147 | case Sema::ExpressionEvaluationContext::PotentiallyEvaluated: |
| 148 | case Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed: |
| 149 | break; |
| 150 | } |
| 151 | |
| 152 | |
| 153 | |
| 154 | if (isStaticContext) { |
| 155 | if (hasNonInstance) |
| 156 | return IMA_Mixed_StaticContext; |
| 157 | |
| 158 | return AbstractInstanceResult ? AbstractInstanceResult |
| 159 | : IMA_Error_StaticContext; |
| 160 | } |
| 161 | |
| 162 | CXXRecordDecl *contextClass; |
| 163 | if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC)) |
| 164 | contextClass = MD->getParent()->getCanonicalDecl(); |
| 165 | else |
| 166 | contextClass = cast<CXXRecordDecl>(DC); |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | if (R.getNamingClass() && |
| 175 | contextClass->getCanonicalDecl() != |
| 176 | R.getNamingClass()->getCanonicalDecl()) { |
| 177 | |
| 178 | |
| 179 | |
| 180 | Classes.clear(); |
| 181 | Classes.insert(R.getNamingClass()->getCanonicalDecl()); |
| 182 | } |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | if (isProvablyNotDerivedFrom(SemaRef, contextClass, Classes)) |
| 188 | return hasNonInstance ? IMA_Mixed_Unrelated : |
| 189 | AbstractInstanceResult ? AbstractInstanceResult : |
| 190 | IMA_Error_Unrelated; |
| 191 | |
| 192 | return (hasNonInstance ? IMA_Mixed : IMA_Instance); |
| 193 | } |
| 194 | |
| 195 | |
| 196 | static void diagnoseInstanceReference(Sema &SemaRef, |
| 197 | const CXXScopeSpec &SS, |
| 198 | NamedDecl *Rep, |
| 199 | const DeclarationNameInfo &nameInfo) { |
| 200 | SourceLocation Loc = nameInfo.getLoc(); |
| 201 | SourceRange Range(Loc); |
| 202 | if (SS.isSet()) Range.setBegin(SS.getRange().getBegin()); |
| 203 | |
| 204 | |
| 205 | Rep = Rep->getUnderlyingDecl(); |
| 206 | |
| 207 | DeclContext *FunctionLevelDC = SemaRef.getFunctionLevelDeclContext(); |
| 208 | CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(FunctionLevelDC); |
| 209 | CXXRecordDecl *ContextClass = Method ? Method->getParent() : nullptr; |
| 210 | CXXRecordDecl *RepClass = dyn_cast<CXXRecordDecl>(Rep->getDeclContext()); |
| 211 | |
| 212 | bool InStaticMethod = Method && Method->isStatic(); |
| 213 | bool IsField = isa<FieldDecl>(Rep) || isa<IndirectFieldDecl>(Rep); |
| 214 | |
| 215 | if (IsField && InStaticMethod) |
| 216 | |
| 217 | SemaRef.Diag(Loc, diag::err_invalid_member_use_in_static_method) |
| 218 | << Range << nameInfo.getName(); |
| 219 | else if (ContextClass && RepClass && SS.isEmpty() && !InStaticMethod && |
| 220 | !RepClass->Equals(ContextClass) && RepClass->Encloses(ContextClass)) |
| 221 | |
| 222 | |
| 223 | SemaRef.Diag(Loc, diag::err_nested_non_static_member_use) |
| 224 | << IsField << RepClass << nameInfo.getName() << ContextClass << Range; |
| 225 | else if (IsField) |
| 226 | SemaRef.Diag(Loc, diag::err_invalid_non_static_member_use) |
| 227 | << nameInfo.getName() << Range; |
| 228 | else |
| 229 | SemaRef.Diag(Loc, diag::err_member_call_without_object) |
| 230 | << Range; |
| 231 | } |
| 232 | |
| 233 | |
| 234 | ExprResult |
| 235 | Sema::BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS, |
| 236 | SourceLocation TemplateKWLoc, |
| 237 | LookupResult &R, |
| 238 | const TemplateArgumentListInfo *TemplateArgs, |
| 239 | const Scope *S) { |
| 240 | switch (ClassifyImplicitMemberAccess(*this, R)) { |
| 241 | case IMA_Instance: |
| 242 | return BuildImplicitMemberExpr(SS, TemplateKWLoc, R, TemplateArgs, true, S); |
| 243 | |
| 244 | case IMA_Mixed: |
| 245 | case IMA_Mixed_Unrelated: |
| 246 | case IMA_Unresolved: |
| 247 | return BuildImplicitMemberExpr(SS, TemplateKWLoc, R, TemplateArgs, false, |
| 248 | S); |
| 249 | |
| 250 | case IMA_Field_Uneval_Context: |
| 251 | Diag(R.getNameLoc(), diag::warn_cxx98_compat_non_static_member_use) |
| 252 | << R.getLookupNameInfo().getName(); |
| 253 | LLVM_FALLTHROUGH; |
| 254 | case IMA_Static: |
| 255 | case IMA_Abstract: |
| 256 | case IMA_Mixed_StaticContext: |
| 257 | case IMA_Unresolved_StaticContext: |
| 258 | if (TemplateArgs || TemplateKWLoc.isValid()) |
| 259 | return BuildTemplateIdExpr(SS, TemplateKWLoc, R, false, TemplateArgs); |
| 260 | return BuildDeclarationNameExpr(SS, R, false); |
| 261 | |
| 262 | case IMA_Error_StaticContext: |
| 263 | case IMA_Error_Unrelated: |
| 264 | diagnoseInstanceReference(*this, SS, R.getRepresentativeDecl(), |
| 265 | R.getLookupNameInfo()); |
| 266 | return ExprError(); |
| 267 | } |
| 268 | |
| 269 | llvm_unreachable("unexpected instance member access kind"); |
| 270 | } |
| 271 | |
| 272 | |
| 273 | static bool |
| 274 | IsRGBA(char c) { |
| 275 | switch (c) { |
| 276 | case 'r': |
| 277 | case 'g': |
| 278 | case 'b': |
| 279 | case 'a': |
| 280 | return true; |
| 281 | default: |
| 282 | return false; |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 | static bool IsValidOpenCLComponentSwizzleLength(unsigned len) |
| 290 | { |
| 291 | return (len >= 1 && len <= 4) || len == 8 || len == 16; |
| 292 | } |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | |
| 298 | static QualType |
| 299 | CheckExtVectorComponent(Sema &S, QualType baseType, ExprValueKind &VK, |
| 300 | SourceLocation OpLoc, const IdentifierInfo *CompName, |
| 301 | SourceLocation CompLoc) { |
| 302 | |
| 303 | |
| 304 | |
| 305 | |
| 306 | |
| 307 | const ExtVectorType *vecType = baseType->getAs<ExtVectorType>(); |
| 308 | |
| 309 | |
| 310 | const char *compStr = CompName->getNameStart(); |
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 | bool HalvingSwizzle = false; |
| 316 | |
| 317 | |
| 318 | |
| 319 | bool HexSwizzle = (*compStr == 's' || *compStr == 'S') && compStr[1]; |
| 320 | |
| 321 | bool HasRepeated = false; |
| 322 | bool HasIndex[16] = {}; |
| 323 | |
| 324 | int Idx; |
| 325 | |
| 326 | |
| 327 | |
| 328 | if (!strcmp(compStr, "hi") || !strcmp(compStr, "lo") || |
| 329 | !strcmp(compStr, "even") || !strcmp(compStr, "odd")) { |
| 330 | HalvingSwizzle = true; |
| 331 | } else if (!HexSwizzle && |
| 332 | (Idx = vecType->getPointAccessorIdx(*compStr)) != -1) { |
| 333 | bool HasRGBA = IsRGBA(*compStr); |
| 334 | do { |
| 335 | |
| 336 | if (HasRGBA != IsRGBA(*compStr)) |
| 337 | break; |
| 338 | if (HasIndex[Idx]) HasRepeated = true; |
| 339 | HasIndex[Idx] = true; |
| 340 | compStr++; |
| 341 | } while (*compStr && (Idx = vecType->getPointAccessorIdx(*compStr)) != -1); |
| 342 | |
| 343 | |
| 344 | if (HasRGBA || (*compStr && IsRGBA(*compStr))) { |
| 345 | if (S.getLangOpts().OpenCL && S.getLangOpts().OpenCLVersion < 220) { |
| 346 | const char *DiagBegin = HasRGBA ? CompName->getNameStart() : compStr; |
| 347 | S.Diag(OpLoc, diag::ext_opencl_ext_vector_type_rgba_selector) |
| 348 | << StringRef(DiagBegin, 1) |
| 349 | << S.getLangOpts().OpenCLVersion << SourceRange(CompLoc); |
| 350 | } |
| 351 | } |
| 352 | } else { |
| 353 | if (HexSwizzle) compStr++; |
| 354 | while ((Idx = vecType->getNumericAccessorIdx(*compStr)) != -1) { |
| 355 | if (HasIndex[Idx]) HasRepeated = true; |
| 356 | HasIndex[Idx] = true; |
| 357 | compStr++; |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | if (!HalvingSwizzle && *compStr) { |
| 362 | |
| 363 | |
| 364 | S.Diag(OpLoc, diag::err_ext_vector_component_name_illegal) |
| 365 | << StringRef(compStr, 1) << SourceRange(CompLoc); |
| 366 | return QualType(); |
| 367 | } |
| 368 | |
| 369 | |
| 370 | |
| 371 | if (!HalvingSwizzle) { |
| 372 | compStr = CompName->getNameStart(); |
| 373 | |
| 374 | if (HexSwizzle) |
| 375 | compStr++; |
| 376 | |
| 377 | while (*compStr) { |
| 378 | if (!vecType->isAccessorWithinNumElements(*compStr++, HexSwizzle)) { |
| 379 | S.Diag(OpLoc, diag::err_ext_vector_component_exceeds_length) |
| 380 | << baseType << SourceRange(CompLoc); |
| 381 | return QualType(); |
| 382 | } |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | |
| 387 | |
| 388 | if (S.getLangOpts().OpenCL && !HalvingSwizzle) { |
| 389 | unsigned SwizzleLength = CompName->getLength(); |
| 390 | |
| 391 | if (HexSwizzle) |
| 392 | SwizzleLength--; |
| 393 | |
| 394 | if (IsValidOpenCLComponentSwizzleLength(SwizzleLength) == false) { |
| 395 | S.Diag(OpLoc, diag::err_opencl_ext_vector_component_invalid_length) |
| 396 | << SwizzleLength << SourceRange(CompLoc); |
| 397 | return QualType(); |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | |
| 402 | |
| 403 | |
| 404 | |
| 405 | |
| 406 | unsigned CompSize = HalvingSwizzle ? (vecType->getNumElements() + 1) / 2 |
| 407 | : CompName->getLength(); |
| 408 | if (HexSwizzle) |
| 409 | CompSize--; |
| 410 | |
| 411 | if (CompSize == 1) |
| 412 | return vecType->getElementType(); |
| 413 | |
| 414 | if (HasRepeated) VK = VK_RValue; |
| 415 | |
| 416 | QualType VT = S.Context.getExtVectorType(vecType->getElementType(), CompSize); |
| 417 | |
| 418 | |
| 419 | for (Sema::ExtVectorDeclsType::iterator |
| 420 | I = S.ExtVectorDecls.begin(S.getExternalSource()), |
| 421 | E = S.ExtVectorDecls.end(); |
| 422 | I != E; ++I) { |
| 423 | if ((*I)->getUnderlyingType() == VT) |
| 424 | return S.Context.getTypedefType(*I); |
| 425 | } |
| 426 | |
| 427 | return VT; |
| 428 | } |
| 429 | |
| 430 | static Decl *FindGetterSetterNameDeclFromProtocolList(const ObjCProtocolDecl*PDecl, |
| 431 | IdentifierInfo *Member, |
| 432 | const Selector &Sel, |
| 433 | ASTContext &Context) { |
| 434 | if (Member) |
| 435 | if (ObjCPropertyDecl *PD = PDecl->FindPropertyDeclaration( |
| 436 | Member, ObjCPropertyQueryKind::OBJC_PR_query_instance)) |
| 437 | return PD; |
| 438 | if (ObjCMethodDecl *OMD = PDecl->getInstanceMethod(Sel)) |
| 439 | return OMD; |
| 440 | |
| 441 | for (const auto *I : PDecl->protocols()) { |
| 442 | if (Decl *D = FindGetterSetterNameDeclFromProtocolList(I, Member, Sel, |
| 443 | Context)) |
| 444 | return D; |
| 445 | } |
| 446 | return nullptr; |
| 447 | } |
| 448 | |
| 449 | static Decl *FindGetterSetterNameDecl(const ObjCObjectPointerType *QIdTy, |
| 450 | IdentifierInfo *Member, |
| 451 | const Selector &Sel, |
| 452 | ASTContext &Context) { |
| 453 | |
| 454 | Decl *GDecl = nullptr; |
| 455 | for (const auto *I : QIdTy->quals()) { |
| 456 | if (Member) |
| 457 | if (ObjCPropertyDecl *PD = I->FindPropertyDeclaration( |
| 458 | Member, ObjCPropertyQueryKind::OBJC_PR_query_instance)) { |
| 459 | GDecl = PD; |
| 460 | break; |
| 461 | } |
| 462 | |
| 463 | if (ObjCMethodDecl *OMD = I->getInstanceMethod(Sel)) { |
| 464 | GDecl = OMD; |
| 465 | break; |
| 466 | } |
| 467 | } |
| 468 | if (!GDecl) { |
| 469 | for (const auto *I : QIdTy->quals()) { |
| 470 | |
| 471 | GDecl = FindGetterSetterNameDeclFromProtocolList(I, Member, Sel, Context); |
| 472 | if (GDecl) |
| 473 | return GDecl; |
| 474 | } |
| 475 | } |
| 476 | return GDecl; |
| 477 | } |
| 478 | |
| 479 | ExprResult |
| 480 | Sema::ActOnDependentMemberExpr(Expr *BaseExpr, QualType BaseType, |
| 481 | bool IsArrow, SourceLocation OpLoc, |
| 482 | const CXXScopeSpec &SS, |
| 483 | SourceLocation TemplateKWLoc, |
| 484 | NamedDecl *FirstQualifierInScope, |
| 485 | const DeclarationNameInfo &NameInfo, |
| 486 | const TemplateArgumentListInfo *TemplateArgs) { |
| 487 | |
| 488 | |
| 489 | |
| 490 | |
| 491 | |
| 492 | |
| 493 | |
| 494 | |
| 495 | |
| 496 | if (!IsArrow) { |
| 497 | const PointerType *PT = BaseType->getAs<PointerType>(); |
| 498 | if (PT && (!getLangOpts().ObjC || |
| 499 | PT->getPointeeType()->isRecordType())) { |
| 500 | (0) . __assert_fail ("BaseExpr && \"cannot happen with implicit member accesses\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaExprMember.cpp", 500, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(BaseExpr && "cannot happen with implicit member accesses"); |
| 501 | Diag(OpLoc, diag::err_typecheck_member_reference_struct_union) |
| 502 | << BaseType << BaseExpr->getSourceRange() << NameInfo.getSourceRange(); |
| 503 | return ExprError(); |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | isDependentType() || NameInfo.getName().isDependentName() || isDependentScopeSpecifier(SS)", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaExprMember.cpp", 509, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(BaseType->isDependentType() || |
| 508 | isDependentType() || NameInfo.getName().isDependentName() || isDependentScopeSpecifier(SS)", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaExprMember.cpp", 509, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> NameInfo.getName().isDependentName() || |
| 509 | isDependentType() || NameInfo.getName().isDependentName() || isDependentScopeSpecifier(SS)", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaExprMember.cpp", 509, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> isDependentScopeSpecifier(SS)); |
| 510 | |
| 511 | |
| 512 | |
| 513 | return CXXDependentScopeMemberExpr::Create( |
| 514 | Context, BaseExpr, BaseType, IsArrow, OpLoc, |
| 515 | SS.getWithLocInContext(Context), TemplateKWLoc, FirstQualifierInScope, |
| 516 | NameInfo, TemplateArgs); |
| 517 | } |
| 518 | |
| 519 | |
| 520 | |
| 521 | |
| 522 | static void DiagnoseQualifiedMemberReference(Sema &SemaRef, |
| 523 | Expr *BaseExpr, |
| 524 | QualType BaseType, |
| 525 | const CXXScopeSpec &SS, |
| 526 | NamedDecl *rep, |
| 527 | const DeclarationNameInfo &nameInfo) { |
| 528 | |
| 529 | |
| 530 | if (!BaseExpr) |
| 531 | return diagnoseInstanceReference(SemaRef, SS, rep, nameInfo); |
| 532 | |
| 533 | SemaRef.Diag(nameInfo.getLoc(), diag::err_qualified_member_of_unrelated) |
| 534 | << SS.getRange() << rep << BaseType; |
| 535 | } |
| 536 | |
| 537 | |
| 538 | |
| 539 | |
| 540 | |
| 541 | |
| 542 | |
| 543 | |
| 544 | |
| 545 | |
| 546 | |
| 547 | |
| 548 | |
| 549 | bool Sema::CheckQualifiedMemberReference(Expr *BaseExpr, |
| 550 | QualType BaseType, |
| 551 | const CXXScopeSpec &SS, |
| 552 | const LookupResult &R) { |
| 553 | CXXRecordDecl *BaseRecord = |
| 554 | cast_or_null<CXXRecordDecl>(computeDeclContext(BaseType)); |
| 555 | if (!BaseRecord) { |
| 556 | |
| 557 | |
| 558 | isDependentType()", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaExprMember.cpp", 558, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(BaseType->isDependentType()); |
| 559 | return false; |
| 560 | } |
| 561 | |
| 562 | for (LookupResult::iterator I = R.begin(), E = R.end(); I != E; ++I) { |
| 563 | |
| 564 | |
| 565 | if (!BaseExpr && !(*I)->isCXXInstanceMember()) |
| 566 | return false; |
| 567 | |
| 568 | |
| 569 | DeclContext *DC = (*I)->getDeclContext(); |
| 570 | while (DC->isTransparentContext()) |
| 571 | DC = DC->getParent(); |
| 572 | |
| 573 | if (!DC->isRecord()) |
| 574 | continue; |
| 575 | |
| 576 | CXXRecordDecl *MemberRecord = cast<CXXRecordDecl>(DC)->getCanonicalDecl(); |
| 577 | if (BaseRecord->getCanonicalDecl() == MemberRecord || |
| 578 | !BaseRecord->isProvablyNotDerivedFrom(MemberRecord)) |
| 579 | return false; |
| 580 | } |
| 581 | |
| 582 | DiagnoseQualifiedMemberReference(*this, BaseExpr, BaseType, SS, |
| 583 | R.getRepresentativeDecl(), |
| 584 | R.getLookupNameInfo()); |
| 585 | return true; |
| 586 | } |
| 587 | |
| 588 | namespace { |
| 589 | |
| 590 | |
| 591 | |
| 592 | |
| 593 | class RecordMemberExprValidatorCCC final : public CorrectionCandidateCallback { |
| 594 | public: |
| 595 | explicit RecordMemberExprValidatorCCC(const RecordType *RTy) |
| 596 | : Record(RTy->getDecl()) { |
| 597 | |
| 598 | |
| 599 | WantTypeSpecifiers = false; |
| 600 | WantExpressionKeywords = false; |
| 601 | WantCXXNamedCasts = false; |
| 602 | WantFunctionLikeCasts = false; |
| 603 | WantRemainingKeywords = false; |
| 604 | } |
| 605 | |
| 606 | bool ValidateCandidate(const TypoCorrection &candidate) override { |
| 607 | NamedDecl *ND = candidate.getCorrectionDecl(); |
| 608 | |
| 609 | |
| 610 | if (!ND || !(isa<ValueDecl>(ND) || isa<FunctionTemplateDecl>(ND))) |
| 611 | return false; |
| 612 | |
| 613 | |
| 614 | if (Record->containsDecl(ND)) |
| 615 | return true; |
| 616 | |
| 617 | if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(Record)) { |
| 618 | |
| 619 | for (const auto &BS : RD->bases()) { |
| 620 | if (const RecordType *BSTy = |
| 621 | dyn_cast_or_null<RecordType>(BS.getType().getTypePtrOrNull())) { |
| 622 | if (BSTy->getDecl()->containsDecl(ND)) |
| 623 | return true; |
| 624 | } |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | return false; |
| 629 | } |
| 630 | |
| 631 | std::unique_ptr<CorrectionCandidateCallback> clone() override { |
| 632 | return llvm::make_unique<RecordMemberExprValidatorCCC>(*this); |
| 633 | } |
| 634 | |
| 635 | private: |
| 636 | const RecordDecl *const Record; |
| 637 | }; |
| 638 | |
| 639 | } |
| 640 | |
| 641 | static bool LookupMemberExprInRecord(Sema &SemaRef, LookupResult &R, |
| 642 | Expr *BaseExpr, |
| 643 | const RecordType *RTy, |
| 644 | SourceLocation OpLoc, bool IsArrow, |
| 645 | CXXScopeSpec &SS, bool HasTemplateArgs, |
| 646 | SourceLocation TemplateKWLoc, |
| 647 | TypoExpr *&TE) { |
| 648 | SourceRange BaseRange = BaseExpr ? BaseExpr->getSourceRange() : SourceRange(); |
| 649 | RecordDecl *RDecl = RTy->getDecl(); |
| 650 | if (!SemaRef.isThisOutsideMemberFunctionBody(QualType(RTy, 0)) && |
| 651 | SemaRef.RequireCompleteType(OpLoc, QualType(RTy, 0), |
| 652 | diag::err_typecheck_incomplete_tag, |
| 653 | BaseRange)) |
| 654 | return true; |
| 655 | |
| 656 | if (HasTemplateArgs || TemplateKWLoc.isValid()) { |
| 657 | |
| 658 | QualType ObjectType = SS.isSet() ? QualType() : QualType(RTy, 0); |
| 659 | |
| 660 | bool MOUS; |
| 661 | return SemaRef.LookupTemplateName(R, nullptr, SS, ObjectType, false, MOUS, |
| 662 | TemplateKWLoc); |
| 663 | } |
| 664 | |
| 665 | DeclContext *DC = RDecl; |
| 666 | if (SS.isSet()) { |
| 667 | |
| 668 | |
| 669 | DC = SemaRef.computeDeclContext(SS, false); |
| 670 | |
| 671 | if (SemaRef.RequireCompleteDeclContext(SS, DC)) { |
| 672 | SemaRef.Diag(SS.getRange().getEnd(), diag::err_typecheck_incomplete_tag) |
| 673 | << SS.getRange() << DC; |
| 674 | return true; |
| 675 | } |
| 676 | |
| 677 | (0) . __assert_fail ("DC && \"Cannot handle non-computable dependent contexts in lookup\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaExprMember.cpp", 677, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(DC && "Cannot handle non-computable dependent contexts in lookup"); |
| 678 | |
| 679 | if (!isa<TypeDecl>(DC)) { |
| 680 | SemaRef.Diag(R.getNameLoc(), diag::err_qualified_member_nonclass) |
| 681 | << DC << SS.getRange(); |
| 682 | return true; |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | |
| 687 | SemaRef.LookupQualifiedName(R, DC, SS); |
| 688 | |
| 689 | if (!R.empty()) |
| 690 | return false; |
| 691 | |
| 692 | DeclarationName Typo = R.getLookupName(); |
| 693 | SourceLocation TypoLoc = R.getNameLoc(); |
| 694 | |
| 695 | struct QueryState { |
| 696 | Sema &SemaRef; |
| 697 | DeclarationNameInfo NameInfo; |
| 698 | Sema::LookupNameKind LookupKind; |
| 699 | Sema::RedeclarationKind Redecl; |
| 700 | }; |
| 701 | QueryState Q = {R.getSema(), R.getLookupNameInfo(), R.getLookupKind(), |
| 702 | R.redeclarationKind()}; |
| 703 | RecordMemberExprValidatorCCC CCC(RTy); |
| 704 | TE = SemaRef.CorrectTypoDelayed( |
| 705 | R.getLookupNameInfo(), R.getLookupKind(), nullptr, &SS, CCC, |
| 706 | [=, &SemaRef](const TypoCorrection &TC) { |
| 707 | if (TC) { |
| 708 | (0) . __assert_fail ("!TC.isKeyword() && \"Got a keyword as a correction for a member!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaExprMember.cpp", 709, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!TC.isKeyword() && |
| 709 | (0) . __assert_fail ("!TC.isKeyword() && \"Got a keyword as a correction for a member!\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaExprMember.cpp", 709, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Got a keyword as a correction for a member!"); |
| 710 | bool DroppedSpecifier = |
| 711 | TC.WillReplaceSpecifier() && |
| 712 | Typo.getAsString() == TC.getAsString(SemaRef.getLangOpts()); |
| 713 | SemaRef.diagnoseTypo(TC, SemaRef.PDiag(diag::err_no_member_suggest) |
| 714 | << Typo << DC << DroppedSpecifier |
| 715 | << SS.getRange()); |
| 716 | } else { |
| 717 | SemaRef.Diag(TypoLoc, diag::err_no_member) << Typo << DC << BaseRange; |
| 718 | } |
| 719 | }, |
| 720 | [=](Sema &SemaRef, TypoExpr *TE, TypoCorrection TC) mutable { |
| 721 | LookupResult R(Q.SemaRef, Q.NameInfo, Q.LookupKind, Q.Redecl); |
| 722 | R.clear(); |
| 723 | R.suppressDiagnostics(); |
| 724 | R.setLookupName(TC.getCorrection()); |
| 725 | for (NamedDecl *ND : TC) |
| 726 | R.addDecl(ND); |
| 727 | R.resolveKind(); |
| 728 | return SemaRef.BuildMemberReferenceExpr( |
| 729 | BaseExpr, BaseExpr->getType(), OpLoc, IsArrow, SS, SourceLocation(), |
| 730 | nullptr, R, nullptr, nullptr); |
| 731 | }, |
| 732 | Sema::CTK_ErrorRecovery, DC); |
| 733 | |
| 734 | return false; |
| 735 | } |
| 736 | |
| 737 | static ExprResult LookupMemberExpr(Sema &S, LookupResult &R, |
| 738 | ExprResult &BaseExpr, bool &IsArrow, |
| 739 | SourceLocation OpLoc, CXXScopeSpec &SS, |
| 740 | Decl *ObjCImpDecl, bool HasTemplateArgs, |
| 741 | SourceLocation TemplateKWLoc); |
| 742 | |
| 743 | ExprResult |
| 744 | Sema::(Expr *Base, QualType BaseType, |
| 745 | SourceLocation OpLoc, bool IsArrow, |
| 746 | CXXScopeSpec &SS, |
| 747 | SourceLocation TemplateKWLoc, |
| 748 | NamedDecl *FirstQualifierInScope, |
| 749 | const DeclarationNameInfo &NameInfo, |
| 750 | const TemplateArgumentListInfo *TemplateArgs, |
| 751 | const Scope *S, |
| 752 | ActOnMemberAccessExtraArgs *) { |
| 753 | if (BaseType->isDependentType() || |
| 754 | (SS.isSet() && isDependentScopeSpecifier(SS))) |
| 755 | return ActOnDependentMemberExpr(Base, BaseType, |
| 756 | IsArrow, OpLoc, |
| 757 | SS, TemplateKWLoc, FirstQualifierInScope, |
| 758 | NameInfo, TemplateArgs); |
| 759 | |
| 760 | LookupResult R(*this, NameInfo, LookupMemberName); |
| 761 | |
| 762 | |
| 763 | if (!Base) { |
| 764 | TypoExpr *TE = nullptr; |
| 765 | QualType RecordTy = BaseType; |
| 766 | if (IsArrow) RecordTy = RecordTy->getAs<PointerType>()->getPointeeType(); |
| 767 | if (LookupMemberExprInRecord( |
| 768 | *this, R, nullptr, RecordTy->getAs<RecordType>(), OpLoc, IsArrow, |
| 769 | SS, TemplateArgs != nullptr, TemplateKWLoc, TE)) |
| 770 | return ExprError(); |
| 771 | if (TE) |
| 772 | return TE; |
| 773 | |
| 774 | |
| 775 | } else { |
| 776 | ExprResult BaseResult = Base; |
| 777 | ExprResult Result = |
| 778 | LookupMemberExpr(*this, R, BaseResult, IsArrow, OpLoc, SS, |
| 779 | ExtraArgs ? ExtraArgs->ObjCImpDecl : nullptr, |
| 780 | TemplateArgs != nullptr, TemplateKWLoc); |
| 781 | |
| 782 | if (BaseResult.isInvalid()) |
| 783 | return ExprError(); |
| 784 | Base = BaseResult.get(); |
| 785 | |
| 786 | if (Result.isInvalid()) |
| 787 | return ExprError(); |
| 788 | |
| 789 | if (Result.get()) |
| 790 | return Result; |
| 791 | |
| 792 | |
| 793 | BaseType = Base->getType(); |
| 794 | } |
| 795 | |
| 796 | return BuildMemberReferenceExpr(Base, BaseType, |
| 797 | OpLoc, IsArrow, SS, TemplateKWLoc, |
| 798 | FirstQualifierInScope, R, TemplateArgs, S, |
| 799 | false, ExtraArgs); |
| 800 | } |
| 801 | |
| 802 | ExprResult |
| 803 | Sema::BuildAnonymousStructUnionMemberReference(const CXXScopeSpec &SS, |
| 804 | SourceLocation loc, |
| 805 | IndirectFieldDecl *indirectField, |
| 806 | DeclAccessPair foundDecl, |
| 807 | Expr *baseObjectExpr, |
| 808 | SourceLocation opLoc) { |
| 809 | |
| 810 | |
| 811 | |
| 812 | VarDecl *baseVariable = indirectField->getVarDecl(); |
| 813 | CXXScopeSpec EmptySS; |
| 814 | if (baseVariable) { |
| 815 | getType()->isRecordType()", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaExprMember.cpp", 815, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(baseVariable->getType()->isRecordType()); |
| 816 | |
| 817 | |
| 818 | |
| 819 | |
| 820 | |
| 821 | |
| 822 | (0) . __assert_fail ("!baseObjectExpr && \"anonymous struct/union is static data member?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaExprMember.cpp", 822, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!baseObjectExpr && "anonymous struct/union is static data member?"); |
| 823 | |
| 824 | DeclarationNameInfo baseNameInfo(DeclarationName(), loc); |
| 825 | |
| 826 | ExprResult result |
| 827 | = BuildDeclarationNameExpr(EmptySS, baseNameInfo, baseVariable); |
| 828 | if (result.isInvalid()) return ExprError(); |
| 829 | |
| 830 | baseObjectExpr = result.get(); |
| 831 | } |
| 832 | |
| 833 | (0) . __assert_fail ("(baseVariable || baseObjectExpr) && \"referencing anonymous struct/union without a base variable or \" \"expression\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaExprMember.cpp", 835, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert((baseVariable || baseObjectExpr) && |
| 834 | (0) . __assert_fail ("(baseVariable || baseObjectExpr) && \"referencing anonymous struct/union without a base variable or \" \"expression\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaExprMember.cpp", 835, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "referencing anonymous struct/union without a base variable or " |
| 835 | (0) . __assert_fail ("(baseVariable || baseObjectExpr) && \"referencing anonymous struct/union without a base variable or \" \"expression\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaExprMember.cpp", 835, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "expression"); |
| 836 | |
| 837 | |
| 838 | |
| 839 | Expr *result = baseObjectExpr; |
| 840 | IndirectFieldDecl::chain_iterator |
| 841 | FI = indirectField->chain_begin(), FEnd = indirectField->chain_end(); |
| 842 | |
| 843 | |
| 844 | |
| 845 | if (!baseVariable) { |
| 846 | FieldDecl *field = cast<FieldDecl>(*FI); |
| 847 | |
| 848 | bool baseObjectIsPointer = baseObjectExpr->getType()->isPointerType(); |
| 849 | |
| 850 | |
| 851 | DeclarationNameInfo memberNameInfo(field->getDeclName(), loc); |
| 852 | |
| 853 | |
| 854 | result = |
| 855 | BuildFieldReferenceExpr(result, baseObjectIsPointer, SourceLocation(), |
| 856 | SS, field, foundDecl, memberNameInfo) |
| 857 | .get(); |
| 858 | if (!result) |
| 859 | return ExprError(); |
| 860 | } |
| 861 | |
| 862 | |
| 863 | ++FI; |
| 864 | |
| 865 | while (FI != FEnd) { |
| 866 | FieldDecl *field = cast<FieldDecl>(*FI++); |
| 867 | |
| 868 | |
| 869 | DeclarationNameInfo memberNameInfo(field->getDeclName(), loc); |
| 870 | DeclAccessPair fakeFoundDecl = |
| 871 | DeclAccessPair::make(field, field->getAccess()); |
| 872 | |
| 873 | result = |
| 874 | BuildFieldReferenceExpr(result, false, SourceLocation(), |
| 875 | (FI == FEnd ? SS : EmptySS), field, |
| 876 | fakeFoundDecl, memberNameInfo) |
| 877 | .get(); |
| 878 | } |
| 879 | |
| 880 | return result; |
| 881 | } |
| 882 | |
| 883 | static ExprResult |
| 884 | BuildMSPropertyRefExpr(Sema &S, Expr *BaseExpr, bool IsArrow, |
| 885 | const CXXScopeSpec &SS, |
| 886 | MSPropertyDecl *PD, |
| 887 | const DeclarationNameInfo &NameInfo) { |
| 888 | |
| 889 | |
| 890 | return new (S.Context) MSPropertyRefExpr(BaseExpr, PD, IsArrow, |
| 891 | S.Context.PseudoObjectTy, VK_LValue, |
| 892 | SS.getWithLocInContext(S.Context), |
| 893 | NameInfo.getLoc()); |
| 894 | } |
| 895 | |
| 896 | |
| 897 | static MemberExpr *BuildMemberExpr( |
| 898 | Sema &SemaRef, ASTContext &C, Expr *Base, bool isArrow, |
| 899 | SourceLocation OpLoc, const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
| 900 | ValueDecl *Member, DeclAccessPair FoundDecl, |
| 901 | const DeclarationNameInfo &MemberNameInfo, QualType Ty, ExprValueKind VK, |
| 902 | ExprObjectKind OK, const TemplateArgumentListInfo *TemplateArgs = nullptr) { |
| 903 | base must be a pointer rvalue") ? static_cast (0) . __assert_fail ("(!isArrow || Base->isRValue()) && \"-> base must be a pointer rvalue\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaExprMember.cpp", 903, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert((!isArrow || Base->isRValue()) && "-> base must be a pointer rvalue"); |
| 904 | MemberExpr *E = MemberExpr::Create( |
| 905 | C, Base, isArrow, OpLoc, SS.getWithLocInContext(C), TemplateKWLoc, Member, |
| 906 | FoundDecl, MemberNameInfo, TemplateArgs, Ty, VK, OK); |
| 907 | SemaRef.MarkMemberReferenced(E); |
| 908 | return E; |
| 909 | } |
| 910 | |
| 911 | |
| 912 | static bool IsInFnTryBlockHandler(const Scope *S) { |
| 913 | |
| 914 | |
| 915 | |
| 916 | for (; S != S->getFnParent(); S = S->getParent()) { |
| 917 | if (S->getFlags() & Scope::FnTryCatchScope) |
| 918 | return (S->getFlags() & Scope::TryScope) != Scope::TryScope; |
| 919 | } |
| 920 | return false; |
| 921 | } |
| 922 | |
| 923 | static VarDecl * |
| 924 | getVarTemplateSpecialization(Sema &S, VarTemplateDecl *VarTempl, |
| 925 | const TemplateArgumentListInfo *TemplateArgs, |
| 926 | const DeclarationNameInfo &MemberNameInfo, |
| 927 | SourceLocation TemplateKWLoc) { |
| 928 | if (!TemplateArgs) { |
| 929 | S.diagnoseMissingTemplateArguments(TemplateName(VarTempl), |
| 930 | MemberNameInfo.getBeginLoc()); |
| 931 | return nullptr; |
| 932 | } |
| 933 | |
| 934 | DeclResult VDecl = S.CheckVarTemplateId( |
| 935 | VarTempl, TemplateKWLoc, MemberNameInfo.getLoc(), *TemplateArgs); |
| 936 | if (VDecl.isInvalid()) |
| 937 | return nullptr; |
| 938 | VarDecl *Var = cast<VarDecl>(VDecl.get()); |
| 939 | if (!Var->getTemplateSpecializationKind()) |
| 940 | Var->setTemplateSpecializationKind(TSK_ImplicitInstantiation, |
| 941 | MemberNameInfo.getLoc()); |
| 942 | return Var; |
| 943 | } |
| 944 | |
| 945 | ExprResult |
| 946 | Sema::(Expr *BaseExpr, QualType BaseExprType, |
| 947 | SourceLocation OpLoc, bool IsArrow, |
| 948 | const CXXScopeSpec &SS, |
| 949 | SourceLocation TemplateKWLoc, |
| 950 | NamedDecl *FirstQualifierInScope, |
| 951 | LookupResult &R, |
| 952 | const TemplateArgumentListInfo *TemplateArgs, |
| 953 | const Scope *S, |
| 954 | bool SuppressQualifierCheck, |
| 955 | ActOnMemberAccessExtraArgs *) { |
| 956 | QualType BaseType = BaseExprType; |
| 957 | if (IsArrow) { |
| 958 | isPointerType()", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaExprMember.cpp", 958, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(BaseType->isPointerType()); |
| 959 | BaseType = BaseType->castAs<PointerType>()->getPointeeType(); |
| 960 | } |
| 961 | R.setBaseObjectType(BaseType); |
| 962 | |
| 963 | |
| 964 | |
| 965 | if (!IsArrow && BaseExpr && BaseExpr->isRValue()) { |
| 966 | ExprResult Converted = TemporaryMaterializationConversion(BaseExpr); |
| 967 | if (Converted.isInvalid()) |
| 968 | return ExprError(); |
| 969 | BaseExpr = Converted.get(); |
| 970 | } |
| 971 | |
| 972 | |
| 973 | const DeclarationNameInfo &MemberNameInfo = R.getLookupNameInfo(); |
| 974 | DeclarationName MemberName = MemberNameInfo.getName(); |
| 975 | SourceLocation MemberLoc = MemberNameInfo.getLoc(); |
| 976 | |
| 977 | if (R.isAmbiguous()) |
| 978 | return ExprError(); |
| 979 | |
| 980 | |
| 981 | |
| 982 | |
| 983 | const auto *FD = getCurFunctionDecl(); |
| 984 | if (S && BaseExpr && FD && |
| 985 | (isa<CXXDestructorDecl>(FD) || isa<CXXConstructorDecl>(FD)) && |
| 986 | isa<CXXThisExpr>(BaseExpr->IgnoreImpCasts()) && |
| 987 | IsInFnTryBlockHandler(S)) |
| 988 | Diag(MemberLoc, diag::warn_cdtor_function_try_handler_mem_expr) |
| 989 | << isa<CXXDestructorDecl>(FD); |
| 990 | |
| 991 | if (R.empty()) { |
| 992 | |
| 993 | DeclContext *DC = (SS.isSet() |
| 994 | ? computeDeclContext(SS, false) |
| 995 | : BaseType->getAs<RecordType>()->getDecl()); |
| 996 | |
| 997 | if (ExtraArgs) { |
| 998 | ExprResult RetryExpr; |
| 999 | if (!IsArrow && BaseExpr) { |
| 1000 | SFINAETrap Trap(*this, true); |
| 1001 | ParsedType ObjectType; |
| 1002 | bool MayBePseudoDestructor = false; |
| 1003 | RetryExpr = ActOnStartCXXMemberReference(getCurScope(), BaseExpr, |
| 1004 | OpLoc, tok::arrow, ObjectType, |
| 1005 | MayBePseudoDestructor); |
| 1006 | if (RetryExpr.isUsable() && !Trap.hasErrorOccurred()) { |
| 1007 | CXXScopeSpec TempSS(SS); |
| 1008 | RetryExpr = ActOnMemberAccessExpr( |
| 1009 | ExtraArgs->S, RetryExpr.get(), OpLoc, tok::arrow, TempSS, |
| 1010 | TemplateKWLoc, ExtraArgs->Id, ExtraArgs->ObjCImpDecl); |
| 1011 | } |
| 1012 | if (Trap.hasErrorOccurred()) |
| 1013 | RetryExpr = ExprError(); |
| 1014 | } |
| 1015 | if (RetryExpr.isUsable()) { |
| 1016 | Diag(OpLoc, diag::err_no_member_overloaded_arrow) |
| 1017 | << MemberName << DC << FixItHint::CreateReplacement(OpLoc, "->"); |
| 1018 | return RetryExpr; |
| 1019 | } |
| 1020 | } |
| 1021 | |
| 1022 | Diag(R.getNameLoc(), diag::err_no_member) |
| 1023 | << MemberName << DC |
| 1024 | << (BaseExpr ? BaseExpr->getSourceRange() : SourceRange()); |
| 1025 | return ExprError(); |
| 1026 | } |
| 1027 | |
| 1028 | |
| 1029 | |
| 1030 | |
| 1031 | |
| 1032 | |
| 1033 | |
| 1034 | |
| 1035 | if ((SS.isSet() || !BaseExpr || |
| 1036 | (isa<CXXThisExpr>(BaseExpr) && |
| 1037 | cast<CXXThisExpr>(BaseExpr)->isImplicit())) && |
| 1038 | !SuppressQualifierCheck && |
| 1039 | CheckQualifiedMemberReference(BaseExpr, BaseType, SS, R)) |
| 1040 | return ExprError(); |
| 1041 | |
| 1042 | |
| 1043 | |
| 1044 | if (R.isOverloadedResult() || R.isUnresolvableResult()) { |
| 1045 | |
| 1046 | |
| 1047 | R.suppressDiagnostics(); |
| 1048 | |
| 1049 | UnresolvedMemberExpr *MemExpr |
| 1050 | = UnresolvedMemberExpr::Create(Context, R.isUnresolvableResult(), |
| 1051 | BaseExpr, BaseExprType, |
| 1052 | IsArrow, OpLoc, |
| 1053 | SS.getWithLocInContext(Context), |
| 1054 | TemplateKWLoc, MemberNameInfo, |
| 1055 | TemplateArgs, R.begin(), R.end()); |
| 1056 | |
| 1057 | return MemExpr; |
| 1058 | } |
| 1059 | |
| 1060 | assert(R.isSingleResult()); |
| 1061 | DeclAccessPair FoundDecl = R.begin().getPair(); |
| 1062 | NamedDecl *MemberDecl = R.getFoundDecl(); |
| 1063 | |
| 1064 | |
| 1065 | |
| 1066 | |
| 1067 | |
| 1068 | |
| 1069 | if (MemberDecl->isInvalidDecl()) |
| 1070 | return ExprError(); |
| 1071 | |
| 1072 | |
| 1073 | if (!BaseExpr) { |
| 1074 | |
| 1075 | if (!MemberDecl->isCXXInstanceMember()) { |
| 1076 | |
| 1077 | |
| 1078 | |
| 1079 | |
| 1080 | (0) . __assert_fail ("(!TemplateArgs || isa(MemberDecl)) && \"How did we get template arguments here sans a variable template\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaExprMember.cpp", 1081, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert((!TemplateArgs || isa<VarTemplateDecl>(MemberDecl)) && |
| 1081 | (0) . __assert_fail ("(!TemplateArgs || isa(MemberDecl)) && \"How did we get template arguments here sans a variable template\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaExprMember.cpp", 1081, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "How did we get template arguments here sans a variable template"); |
| 1082 | if (isa<VarTemplateDecl>(MemberDecl)) { |
| 1083 | MemberDecl = getVarTemplateSpecialization( |
| 1084 | *this, cast<VarTemplateDecl>(MemberDecl), TemplateArgs, |
| 1085 | R.getLookupNameInfo(), TemplateKWLoc); |
| 1086 | if (!MemberDecl) |
| 1087 | return ExprError(); |
| 1088 | } |
| 1089 | return BuildDeclarationNameExpr(SS, R.getLookupNameInfo(), MemberDecl, |
| 1090 | FoundDecl, TemplateArgs); |
| 1091 | } |
| 1092 | SourceLocation Loc = R.getNameLoc(); |
| 1093 | if (SS.getRange().isValid()) |
| 1094 | Loc = SS.getRange().getBegin(); |
| 1095 | CheckCXXThisCapture(Loc); |
| 1096 | BaseExpr = new (Context) CXXThisExpr(Loc, BaseExprType,); |
| 1097 | } |
| 1098 | |
| 1099 | |
| 1100 | if (DiagnoseUseOfDecl(MemberDecl, MemberLoc)) |
| 1101 | return ExprError(); |
| 1102 | |
| 1103 | if (FieldDecl *FD = dyn_cast<FieldDecl>(MemberDecl)) |
| 1104 | return BuildFieldReferenceExpr(BaseExpr, IsArrow, OpLoc, SS, FD, FoundDecl, |
| 1105 | MemberNameInfo); |
| 1106 | |
| 1107 | if (MSPropertyDecl *PD = dyn_cast<MSPropertyDecl>(MemberDecl)) |
| 1108 | return BuildMSPropertyRefExpr(*this, BaseExpr, IsArrow, SS, PD, |
| 1109 | MemberNameInfo); |
| 1110 | |
| 1111 | if (IndirectFieldDecl *FD = dyn_cast<IndirectFieldDecl>(MemberDecl)) |
| 1112 | |
| 1113 | |
| 1114 | return BuildAnonymousStructUnionMemberReference(SS, MemberLoc, FD, |
| 1115 | FoundDecl, BaseExpr, |
| 1116 | OpLoc); |
| 1117 | |
| 1118 | if (VarDecl *Var = dyn_cast<VarDecl>(MemberDecl)) { |
| 1119 | return BuildMemberExpr(*this, Context, BaseExpr, IsArrow, OpLoc, SS, |
| 1120 | TemplateKWLoc, Var, FoundDecl, MemberNameInfo, |
| 1121 | Var->getType().getNonReferenceType(), VK_LValue, |
| 1122 | OK_Ordinary); |
| 1123 | } |
| 1124 | |
| 1125 | if (CXXMethodDecl *MemberFn = dyn_cast<CXXMethodDecl>(MemberDecl)) { |
| 1126 | ExprValueKind valueKind; |
| 1127 | QualType type; |
| 1128 | if (MemberFn->isInstance()) { |
| 1129 | valueKind = VK_RValue; |
| 1130 | type = Context.BoundMemberTy; |
| 1131 | } else { |
| 1132 | valueKind = VK_LValue; |
| 1133 | type = MemberFn->getType(); |
| 1134 | } |
| 1135 | |
| 1136 | return BuildMemberExpr(*this, Context, BaseExpr, IsArrow, OpLoc, SS, |
| 1137 | TemplateKWLoc, MemberFn, FoundDecl, MemberNameInfo, |
| 1138 | type, valueKind, OK_Ordinary); |
| 1139 | } |
| 1140 | (0) . __assert_fail ("!isa(MemberDecl) && \"member function not C++ method?\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaExprMember.cpp", 1140, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!isa<FunctionDecl>(MemberDecl) && "member function not C++ method?"); |
| 1141 | |
| 1142 | if (EnumConstantDecl *Enum = dyn_cast<EnumConstantDecl>(MemberDecl)) { |
| 1143 | return BuildMemberExpr(*this, Context, BaseExpr, IsArrow, OpLoc, SS, |
| 1144 | TemplateKWLoc, Enum, FoundDecl, MemberNameInfo, |
| 1145 | Enum->getType(), VK_RValue, OK_Ordinary); |
| 1146 | } |
| 1147 | if (VarTemplateDecl *VarTempl = dyn_cast<VarTemplateDecl>(MemberDecl)) { |
| 1148 | if (VarDecl *Var = getVarTemplateSpecialization( |
| 1149 | *this, VarTempl, TemplateArgs, MemberNameInfo, TemplateKWLoc)) |
| 1150 | return BuildMemberExpr(*this, Context, BaseExpr, IsArrow, OpLoc, SS, |
| 1151 | TemplateKWLoc, Var, FoundDecl, MemberNameInfo, |
| 1152 | Var->getType().getNonReferenceType(), VK_LValue, |
| 1153 | OK_Ordinary); |
| 1154 | return ExprError(); |
| 1155 | } |
| 1156 | |
| 1157 | |
| 1158 | if (isa<TypeDecl>(MemberDecl)) |
| 1159 | Diag(MemberLoc, diag::err_typecheck_member_reference_type) |
| 1160 | << MemberName << BaseType << int(IsArrow); |
| 1161 | else |
| 1162 | Diag(MemberLoc, diag::err_typecheck_member_reference_unknown) |
| 1163 | << MemberName << BaseType << int(IsArrow); |
| 1164 | |
| 1165 | Diag(MemberDecl->getLocation(), diag::note_member_declared_here) |
| 1166 | << MemberName; |
| 1167 | R.suppressDiagnostics(); |
| 1168 | return ExprError(); |
| 1169 | } |
| 1170 | |
| 1171 | |
| 1172 | |
| 1173 | |
| 1174 | |
| 1175 | |
| 1176 | |
| 1177 | static bool ShouldTryAgainWithRedefinitionType(Sema &S, ExprResult &base) { |
| 1178 | const ObjCObjectPointerType *opty |
| 1179 | = base.get()->getType()->getAs<ObjCObjectPointerType>(); |
| 1180 | if (!opty) return false; |
| 1181 | |
| 1182 | const ObjCObjectType *ty = opty->getObjectType(); |
| 1183 | |
| 1184 | QualType redef; |
| 1185 | if (ty->isObjCId()) { |
| 1186 | redef = S.Context.getObjCIdRedefinitionType(); |
| 1187 | } else if (ty->isObjCClass()) { |
| 1188 | redef = S.Context.getObjCClassRedefinitionType(); |
| 1189 | } else { |
| 1190 | return false; |
| 1191 | } |
| 1192 | |
| 1193 | |
| 1194 | |
| 1195 | opty = redef->getAs<ObjCObjectPointerType>(); |
| 1196 | if (opty && !opty->getObjectType()->getInterface()) |
| 1197 | return false; |
| 1198 | |
| 1199 | base = S.ImpCastExprToType(base.get(), redef, CK_BitCast); |
| 1200 | return true; |
| 1201 | } |
| 1202 | |
| 1203 | static bool isRecordType(QualType T) { |
| 1204 | return T->isRecordType(); |
| 1205 | } |
| 1206 | static bool isPointerToRecordType(QualType T) { |
| 1207 | if (const PointerType *PT = T->getAs<PointerType>()) |
| 1208 | return PT->getPointeeType()->isRecordType(); |
| 1209 | return false; |
| 1210 | } |
| 1211 | |
| 1212 | |
| 1213 | ExprResult |
| 1214 | Sema::PerformMemberExprBaseConversion(Expr *Base, bool IsArrow) { |
| 1215 | if (IsArrow && !Base->getType()->isFunctionType()) |
| 1216 | return DefaultFunctionArrayLvalueConversion(Base); |
| 1217 | |
| 1218 | return CheckPlaceholderExpr(Base); |
| 1219 | } |
| 1220 | |
| 1221 | |
| 1222 | |
| 1223 | |
| 1224 | |
| 1225 | |
| 1226 | |
| 1227 | |
| 1228 | |
| 1229 | |
| 1230 | |
| 1231 | static ExprResult LookupMemberExpr(Sema &S, LookupResult &R, |
| 1232 | ExprResult &BaseExpr, bool &IsArrow, |
| 1233 | SourceLocation OpLoc, CXXScopeSpec &SS, |
| 1234 | Decl *ObjCImpDecl, bool HasTemplateArgs, |
| 1235 | SourceLocation TemplateKWLoc) { |
| 1236 | (0) . __assert_fail ("BaseExpr.get() && \"no base expression\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaExprMember.cpp", 1236, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(BaseExpr.get() && "no base expression"); |
| 1237 | |
| 1238 | |
| 1239 | BaseExpr = S.PerformMemberExprBaseConversion(BaseExpr.get(), IsArrow); |
| 1240 | if (BaseExpr.isInvalid()) |
| 1241 | return ExprError(); |
| 1242 | |
| 1243 | QualType BaseType = BaseExpr.get()->getType(); |
| 1244 | isDependentType()", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaExprMember.cpp", 1244, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!BaseType->isDependentType()); |
| 1245 | |
| 1246 | DeclarationName MemberName = R.getLookupName(); |
| 1247 | SourceLocation MemberLoc = R.getNameLoc(); |
| 1248 | |
| 1249 | |
| 1250 | |
| 1251 | |
| 1252 | |
| 1253 | if (IsArrow) { |
| 1254 | if (const PointerType *Ptr = BaseType->getAs<PointerType>()) |
| 1255 | BaseType = Ptr->getPointeeType(); |
| 1256 | else if (const ObjCObjectPointerType *Ptr |
| 1257 | = BaseType->getAs<ObjCObjectPointerType>()) |
| 1258 | BaseType = Ptr->getPointeeType(); |
| 1259 | else if (BaseType->isRecordType()) { |
| 1260 | |
| 1261 | |
| 1262 | |
| 1263 | |
| 1264 | |
| 1265 | |
| 1266 | |
| 1267 | if (!S.getLangOpts().CPlusPlus) { |
| 1268 | S.Diag(OpLoc, diag::err_typecheck_member_reference_suggestion) |
| 1269 | << BaseType << int(IsArrow) << BaseExpr.get()->getSourceRange() |
| 1270 | << FixItHint::CreateReplacement(OpLoc, "."); |
| 1271 | } |
| 1272 | IsArrow = false; |
| 1273 | } else if (BaseType->isFunctionType()) { |
| 1274 | goto fail; |
| 1275 | } else { |
| 1276 | S.Diag(MemberLoc, diag::err_typecheck_member_reference_arrow) |
| 1277 | << BaseType << BaseExpr.get()->getSourceRange(); |
| 1278 | return ExprError(); |
| 1279 | } |
| 1280 | } |
| 1281 | |
| 1282 | |
| 1283 | if (const RecordType *RTy = BaseType->getAs<RecordType>()) { |
| 1284 | TypoExpr *TE = nullptr; |
| 1285 | if (LookupMemberExprInRecord(S, R, BaseExpr.get(), RTy, OpLoc, IsArrow, SS, |
| 1286 | HasTemplateArgs, TemplateKWLoc, TE)) |
| 1287 | return ExprError(); |
| 1288 | |
| 1289 | |
| 1290 | |
| 1291 | |
| 1292 | |
| 1293 | return ExprResult(TE); |
| 1294 | } |
| 1295 | |
| 1296 | |
| 1297 | if (const ObjCObjectType *OTy = BaseType->getAs<ObjCObjectType>()) { |
| 1298 | if (!SS.isEmpty() && !SS.isInvalid()) { |
| 1299 | S.Diag(SS.getRange().getBegin(), diag::err_qualified_objc_access) |
| 1300 | << 1 << SS.getScopeRep() |
| 1301 | << FixItHint::CreateRemoval(SS.getRange()); |
| 1302 | SS.clear(); |
| 1303 | } |
| 1304 | |
| 1305 | IdentifierInfo *Member = MemberName.getAsIdentifierInfo(); |
| 1306 | |
| 1307 | |
| 1308 | |
| 1309 | |
| 1310 | |
| 1311 | ObjCInterfaceDecl *IDecl = OTy->getInterface(); |
| 1312 | if (!IDecl) { |
| 1313 | if (S.getLangOpts().ObjCAutoRefCount && |
| 1314 | (OTy->isObjCId() || OTy->isObjCClass())) |
| 1315 | goto fail; |
| 1316 | |
| 1317 | |
| 1318 | |
| 1319 | if (OTy->isObjCId() && Member->isStr("isa")) |
| 1320 | return new (S.Context) ObjCIsaExpr(BaseExpr.get(), IsArrow, MemberLoc, |
| 1321 | OpLoc, S.Context.getObjCClassType()); |
| 1322 | if (ShouldTryAgainWithRedefinitionType(S, BaseExpr)) |
| 1323 | return LookupMemberExpr(S, R, BaseExpr, IsArrow, OpLoc, SS, |
| 1324 | ObjCImpDecl, HasTemplateArgs, TemplateKWLoc); |
| 1325 | goto fail; |
| 1326 | } |
| 1327 | |
| 1328 | if (S.RequireCompleteType(OpLoc, BaseType, |
| 1329 | diag::err_typecheck_incomplete_tag, |
| 1330 | BaseExpr.get())) |
| 1331 | return ExprError(); |
| 1332 | |
| 1333 | ObjCInterfaceDecl *ClassDeclared = nullptr; |
| 1334 | ObjCIvarDecl *IV = IDecl->lookupInstanceVariable(Member, ClassDeclared); |
| 1335 | |
| 1336 | if (!IV) { |
| 1337 | |
| 1338 | DeclFilterCCC<ObjCIvarDecl> Validator{}; |
| 1339 | Validator.IsObjCIvarLookup = IsArrow; |
| 1340 | if (TypoCorrection Corrected = S.CorrectTypo( |
| 1341 | R.getLookupNameInfo(), Sema::LookupMemberName, nullptr, nullptr, |
| 1342 | Validator, Sema::CTK_ErrorRecovery, IDecl)) { |
| 1343 | IV = Corrected.getCorrectionDeclAs<ObjCIvarDecl>(); |
| 1344 | S.diagnoseTypo( |
| 1345 | Corrected, |
| 1346 | S.PDiag(diag::err_typecheck_member_reference_ivar_suggest) |
| 1347 | << IDecl->getDeclName() << MemberName); |
| 1348 | |
| 1349 | |
| 1350 | assert(!ClassDeclared); |
| 1351 | |
| 1352 | Decl *D = cast<Decl>(IV->getDeclContext()); |
| 1353 | if (auto *Category = dyn_cast<ObjCCategoryDecl>(D)) |
| 1354 | D = Category->getClassInterface(); |
| 1355 | |
| 1356 | if (auto *Implementation = dyn_cast<ObjCImplementationDecl>(D)) |
| 1357 | ClassDeclared = Implementation->getClassInterface(); |
| 1358 | else if (auto *Interface = dyn_cast<ObjCInterfaceDecl>(D)) |
| 1359 | ClassDeclared = Interface; |
| 1360 | |
| 1361 | (0) . __assert_fail ("ClassDeclared && \"cannot query interface\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaExprMember.cpp", 1361, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(ClassDeclared && "cannot query interface"); |
| 1362 | } else { |
| 1363 | if (IsArrow && |
| 1364 | IDecl->FindPropertyDeclaration( |
| 1365 | Member, ObjCPropertyQueryKind::OBJC_PR_query_instance)) { |
| 1366 | S.Diag(MemberLoc, diag::err_property_found_suggest) |
| 1367 | << Member << BaseExpr.get()->getType() |
| 1368 | << FixItHint::CreateReplacement(OpLoc, "."); |
| 1369 | return ExprError(); |
| 1370 | } |
| 1371 | |
| 1372 | S.Diag(MemberLoc, diag::err_typecheck_member_reference_ivar) |
| 1373 | << IDecl->getDeclName() << MemberName |
| 1374 | << BaseExpr.get()->getSourceRange(); |
| 1375 | return ExprError(); |
| 1376 | } |
| 1377 | } |
| 1378 | |
| 1379 | assert(ClassDeclared); |
| 1380 | |
| 1381 | |
| 1382 | |
| 1383 | |
| 1384 | if (IV->isInvalidDecl()) |
| 1385 | return ExprError(); |
| 1386 | |
| 1387 | |
| 1388 | if (S.DiagnoseUseOfDecl(IV, MemberLoc)) |
| 1389 | return ExprError(); |
| 1390 | if (IV->getAccessControl() != ObjCIvarDecl::Public && |
| 1391 | IV->getAccessControl() != ObjCIvarDecl::Package) { |
| 1392 | ObjCInterfaceDecl *ClassOfMethodDecl = nullptr; |
| 1393 | if (ObjCMethodDecl *MD = S.getCurMethodDecl()) |
| 1394 | ClassOfMethodDecl = MD->getClassInterface(); |
| 1395 | else if (ObjCImpDecl && S.getCurFunctionDecl()) { |
| 1396 | |
| 1397 | |
| 1398 | |
| 1399 | |
| 1400 | |
| 1401 | |
| 1402 | if (ObjCImplementationDecl *IMPD = |
| 1403 | dyn_cast<ObjCImplementationDecl>(ObjCImpDecl)) |
| 1404 | ClassOfMethodDecl = IMPD->getClassInterface(); |
| 1405 | else if (ObjCCategoryImplDecl* CatImplClass = |
| 1406 | dyn_cast<ObjCCategoryImplDecl>(ObjCImpDecl)) |
| 1407 | ClassOfMethodDecl = CatImplClass->getClassInterface(); |
| 1408 | } |
| 1409 | if (!S.getLangOpts().DebuggerSupport) { |
| 1410 | if (IV->getAccessControl() == ObjCIvarDecl::Private) { |
| 1411 | if (!declaresSameEntity(ClassDeclared, IDecl) || |
| 1412 | !declaresSameEntity(ClassOfMethodDecl, ClassDeclared)) |
| 1413 | S.Diag(MemberLoc, diag::err_private_ivar_access) |
| 1414 | << IV->getDeclName(); |
| 1415 | } else if (!IDecl->isSuperClassOf(ClassOfMethodDecl)) |
| 1416 | |
| 1417 | S.Diag(MemberLoc, diag::err_protected_ivar_access) |
| 1418 | << IV->getDeclName(); |
| 1419 | } |
| 1420 | } |
| 1421 | bool warn = true; |
| 1422 | if (S.getLangOpts().ObjCWeak) { |
| 1423 | Expr *BaseExp = BaseExpr.get()->IgnoreParenImpCasts(); |
| 1424 | if (UnaryOperator *UO = dyn_cast<UnaryOperator>(BaseExp)) |
| 1425 | if (UO->getOpcode() == UO_Deref) |
| 1426 | BaseExp = UO->getSubExpr()->IgnoreParenCasts(); |
| 1427 | |
| 1428 | if (DeclRefExpr *DE = dyn_cast<DeclRefExpr>(BaseExp)) |
| 1429 | if (DE->getType().getObjCLifetime() == Qualifiers::OCL_Weak) { |
| 1430 | S.Diag(DE->getLocation(), diag::err_arc_weak_ivar_access); |
| 1431 | warn = false; |
| 1432 | } |
| 1433 | } |
| 1434 | if (warn) { |
| 1435 | if (ObjCMethodDecl *MD = S.getCurMethodDecl()) { |
| 1436 | ObjCMethodFamily MF = MD->getMethodFamily(); |
| 1437 | warn = (MF != OMF_init && MF != OMF_dealloc && |
| 1438 | MF != OMF_finalize && |
| 1439 | !S.IvarBacksCurrentMethodAccessor(IDecl, MD, IV)); |
| 1440 | } |
| 1441 | if (warn) |
| 1442 | S.Diag(MemberLoc, diag::warn_direct_ivar_access) << IV->getDeclName(); |
| 1443 | } |
| 1444 | |
| 1445 | ObjCIvarRefExpr *Result = new (S.Context) ObjCIvarRefExpr( |
| 1446 | IV, IV->getUsageType(BaseType), MemberLoc, OpLoc, BaseExpr.get(), |
| 1447 | IsArrow); |
| 1448 | |
| 1449 | if (IV->getType().getObjCLifetime() == Qualifiers::OCL_Weak) { |
| 1450 | if (!S.isUnevaluatedContext() && |
| 1451 | !S.Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, MemberLoc)) |
| 1452 | S.getCurFunction()->recordUseOfWeak(Result); |
| 1453 | } |
| 1454 | |
| 1455 | return Result; |
| 1456 | } |
| 1457 | |
| 1458 | |
| 1459 | const ObjCObjectPointerType *OPT; |
| 1460 | if (!IsArrow && (OPT = BaseType->getAs<ObjCObjectPointerType>())) { |
| 1461 | if (!SS.isEmpty() && !SS.isInvalid()) { |
| 1462 | S.Diag(SS.getRange().getBegin(), diag::err_qualified_objc_access) |
| 1463 | << 0 << SS.getScopeRep() << FixItHint::CreateRemoval(SS.getRange()); |
| 1464 | SS.clear(); |
| 1465 | } |
| 1466 | |
| 1467 | |
| 1468 | BaseExpr = S.DefaultLvalueConversion(BaseExpr.get()); |
| 1469 | if (BaseExpr.isInvalid()) |
| 1470 | return ExprError(); |
| 1471 | |
| 1472 | getType())", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaExprMember.cpp", 1473, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(S.Context.hasSameUnqualifiedType(BaseType, |
| 1473 | getType())", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaExprMember.cpp", 1473, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> BaseExpr.get()->getType())); |
| 1474 | |
| 1475 | IdentifierInfo *Member = MemberName.getAsIdentifierInfo(); |
| 1476 | |
| 1477 | const ObjCObjectType *OT = OPT->getObjectType(); |
| 1478 | |
| 1479 | |
| 1480 | if (OT->isObjCId()) { |
| 1481 | |
| 1482 | Selector Sel = S.PP.getSelectorTable().getNullarySelector(Member); |
| 1483 | if (Decl *PMDecl = |
| 1484 | FindGetterSetterNameDecl(OPT, Member, Sel, S.Context)) { |
| 1485 | if (ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(PMDecl)) { |
| 1486 | |
| 1487 | if (S.DiagnoseUseOfDecl(PD, MemberLoc)) |
| 1488 | return ExprError(); |
| 1489 | |
| 1490 | return new (S.Context) |
| 1491 | ObjCPropertyRefExpr(PD, S.Context.PseudoObjectTy, VK_LValue, |
| 1492 | OK_ObjCProperty, MemberLoc, BaseExpr.get()); |
| 1493 | } |
| 1494 | |
| 1495 | if (ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(PMDecl)) { |
| 1496 | Selector SetterSel = |
| 1497 | SelectorTable::constructSetterSelector(S.PP.getIdentifierTable(), |
| 1498 | S.PP.getSelectorTable(), |
| 1499 | Member); |
| 1500 | ObjCMethodDecl *SMD = nullptr; |
| 1501 | if (Decl *SDecl = FindGetterSetterNameDecl(OPT, |
| 1502 | nullptr, |
| 1503 | SetterSel, S.Context)) |
| 1504 | SMD = dyn_cast<ObjCMethodDecl>(SDecl); |
| 1505 | |
| 1506 | return new (S.Context) |
| 1507 | ObjCPropertyRefExpr(OMD, SMD, S.Context.PseudoObjectTy, VK_LValue, |
| 1508 | OK_ObjCProperty, MemberLoc, BaseExpr.get()); |
| 1509 | } |
| 1510 | } |
| 1511 | |
| 1512 | |
| 1513 | if (IsArrow && ShouldTryAgainWithRedefinitionType(S, BaseExpr)) |
| 1514 | return LookupMemberExpr(S, R, BaseExpr, IsArrow, OpLoc, SS, |
| 1515 | ObjCImpDecl, HasTemplateArgs, TemplateKWLoc); |
| 1516 | |
| 1517 | return ExprError(S.Diag(MemberLoc, diag::err_property_not_found) |
| 1518 | << MemberName << BaseType); |
| 1519 | } |
| 1520 | |
| 1521 | |
| 1522 | if (OT->isObjCClass()) { |
| 1523 | |
| 1524 | ObjCMethodDecl *MD = S.getCurMethodDecl(); |
| 1525 | if (!MD) { |
| 1526 | if (ShouldTryAgainWithRedefinitionType(S, BaseExpr)) |
| 1527 | return LookupMemberExpr(S, R, BaseExpr, IsArrow, OpLoc, SS, |
| 1528 | ObjCImpDecl, HasTemplateArgs, TemplateKWLoc); |
| 1529 | |
| 1530 | goto fail; |
| 1531 | } |
| 1532 | |
| 1533 | |
| 1534 | Selector Sel = S.PP.getSelectorTable().getNullarySelector(Member); |
| 1535 | ObjCInterfaceDecl *IFace = MD->getClassInterface(); |
| 1536 | if (!IFace) |
| 1537 | goto fail; |
| 1538 | |
| 1539 | ObjCMethodDecl *Getter; |
| 1540 | if ((Getter = IFace->lookupClassMethod(Sel))) { |
| 1541 | |
| 1542 | if (S.DiagnoseUseOfDecl(Getter, MemberLoc)) |
| 1543 | return ExprError(); |
| 1544 | } else |
| 1545 | Getter = IFace->lookupPrivateMethod(Sel, false); |
| 1546 | |
| 1547 | |
| 1548 | Selector SetterSel = |
| 1549 | SelectorTable::constructSetterSelector(S.PP.getIdentifierTable(), |
| 1550 | S.PP.getSelectorTable(), |
| 1551 | Member); |
| 1552 | ObjCMethodDecl *Setter = IFace->lookupClassMethod(SetterSel); |
| 1553 | if (!Setter) { |
| 1554 | |
| 1555 | |
| 1556 | Setter = IFace->lookupPrivateMethod(SetterSel, false); |
| 1557 | } |
| 1558 | |
| 1559 | if (Setter && S.DiagnoseUseOfDecl(Setter, MemberLoc)) |
| 1560 | return ExprError(); |
| 1561 | |
| 1562 | if (Getter || Setter) { |
| 1563 | return new (S.Context) ObjCPropertyRefExpr( |
| 1564 | Getter, Setter, S.Context.PseudoObjectTy, VK_LValue, |
| 1565 | OK_ObjCProperty, MemberLoc, BaseExpr.get()); |
| 1566 | } |
| 1567 | |
| 1568 | if (ShouldTryAgainWithRedefinitionType(S, BaseExpr)) |
| 1569 | return LookupMemberExpr(S, R, BaseExpr, IsArrow, OpLoc, SS, |
| 1570 | ObjCImpDecl, HasTemplateArgs, TemplateKWLoc); |
| 1571 | |
| 1572 | return ExprError(S.Diag(MemberLoc, diag::err_property_not_found) |
| 1573 | << MemberName << BaseType); |
| 1574 | } |
| 1575 | |
| 1576 | |
| 1577 | return S.HandleExprPropertyRefExpr(OPT, BaseExpr.get(), OpLoc, MemberName, |
| 1578 | MemberLoc, SourceLocation(), QualType(), |
| 1579 | false); |
| 1580 | } |
| 1581 | |
| 1582 | |
| 1583 | if (BaseType->isExtVectorType()) { |
| 1584 | |
| 1585 | IdentifierInfo *Member = MemberName.getAsIdentifierInfo(); |
| 1586 | ExprValueKind VK; |
| 1587 | if (IsArrow) |
| 1588 | VK = VK_LValue; |
| 1589 | else { |
| 1590 | if (PseudoObjectExpr *POE = dyn_cast<PseudoObjectExpr>(BaseExpr.get())) |
| 1591 | VK = POE->getSyntacticForm()->getValueKind(); |
| 1592 | else |
| 1593 | VK = BaseExpr.get()->getValueKind(); |
| 1594 | } |
| 1595 | |
| 1596 | QualType ret = CheckExtVectorComponent(S, BaseType, VK, OpLoc, |
| 1597 | Member, MemberLoc); |
| 1598 | if (ret.isNull()) |
| 1599 | return ExprError(); |
| 1600 | Qualifiers BaseQ = |
| 1601 | S.Context.getCanonicalType(BaseExpr.get()->getType()).getQualifiers(); |
| 1602 | ret = S.Context.getQualifiedType(ret, BaseQ); |
| 1603 | |
| 1604 | return new (S.Context) |
| 1605 | ExtVectorElementExpr(ret, VK, BaseExpr.get(), *Member, MemberLoc); |
| 1606 | } |
| 1607 | |
| 1608 | |
| 1609 | |
| 1610 | if (IsArrow && BaseType->isSpecificBuiltinType(BuiltinType::ObjCSel) && |
| 1611 | !S.Context.getObjCSelRedefinitionType()->isObjCSelType()) { |
| 1612 | BaseExpr = S.ImpCastExprToType( |
| 1613 | BaseExpr.get(), S.Context.getObjCSelRedefinitionType(), CK_BitCast); |
| 1614 | return LookupMemberExpr(S, R, BaseExpr, IsArrow, OpLoc, SS, |
| 1615 | ObjCImpDecl, HasTemplateArgs, TemplateKWLoc); |
| 1616 | } |
| 1617 | |
| 1618 | |
| 1619 | fail: |
| 1620 | |
| 1621 | |
| 1622 | |
| 1623 | |
| 1624 | |
| 1625 | |
| 1626 | |
| 1627 | |
| 1628 | if (const PointerType *Ptr = BaseType->getAs<PointerType>()) { |
| 1629 | if (!IsArrow && Ptr->getPointeeType()->isRecordType() && |
| 1630 | MemberName.getNameKind() != DeclarationName::CXXDestructorName) { |
| 1631 | S.Diag(OpLoc, diag::err_typecheck_member_reference_suggestion) |
| 1632 | << BaseType << int(IsArrow) << BaseExpr.get()->getSourceRange() |
| 1633 | << FixItHint::CreateReplacement(OpLoc, "->"); |
| 1634 | |
| 1635 | |
| 1636 | IsArrow = true; |
| 1637 | return LookupMemberExpr(S, R, BaseExpr, IsArrow, OpLoc, SS, |
| 1638 | ObjCImpDecl, HasTemplateArgs, TemplateKWLoc); |
| 1639 | } |
| 1640 | } |
| 1641 | |
| 1642 | |
| 1643 | |
| 1644 | if (S.tryToRecoverWithCall( |
| 1645 | BaseExpr, S.PDiag(diag::err_member_reference_needs_call), |
| 1646 | false, |
| 1647 | IsArrow ? &isPointerToRecordType : &isRecordType)) { |
| 1648 | if (BaseExpr.isInvalid()) |
| 1649 | return ExprError(); |
| 1650 | BaseExpr = S.DefaultFunctionArrayConversion(BaseExpr.get()); |
| 1651 | return LookupMemberExpr(S, R, BaseExpr, IsArrow, OpLoc, SS, |
| 1652 | ObjCImpDecl, HasTemplateArgs, TemplateKWLoc); |
| 1653 | } |
| 1654 | |
| 1655 | S.Diag(OpLoc, diag::err_typecheck_member_reference_struct_union) |
| 1656 | << BaseType << BaseExpr.get()->getSourceRange() << MemberLoc; |
| 1657 | |
| 1658 | return ExprError(); |
| 1659 | } |
| 1660 | |
| 1661 | |
| 1662 | |
| 1663 | |
| 1664 | |
| 1665 | |
| 1666 | |
| 1667 | |
| 1668 | |
| 1669 | |
| 1670 | |
| 1671 | ExprResult Sema::ActOnMemberAccessExpr(Scope *S, Expr *Base, |
| 1672 | SourceLocation OpLoc, |
| 1673 | tok::TokenKind OpKind, |
| 1674 | CXXScopeSpec &SS, |
| 1675 | SourceLocation TemplateKWLoc, |
| 1676 | UnqualifiedId &Id, |
| 1677 | Decl *ObjCImpDecl) { |
| 1678 | if (SS.isSet() && SS.isInvalid()) |
| 1679 | return ExprError(); |
| 1680 | |
| 1681 | |
| 1682 | if (getLangOpts().MicrosoftExt && |
| 1683 | Id.getKind() == UnqualifiedIdKind::IK_ConstructorName) |
| 1684 | Diag(Id.getSourceRange().getBegin(), |
| 1685 | diag::ext_ms_explicit_constructor_call); |
| 1686 | |
| 1687 | TemplateArgumentListInfo TemplateArgsBuffer; |
| 1688 | |
| 1689 | |
| 1690 | DeclarationNameInfo NameInfo; |
| 1691 | const TemplateArgumentListInfo *TemplateArgs; |
| 1692 | DecomposeUnqualifiedId(Id, TemplateArgsBuffer, |
| 1693 | NameInfo, TemplateArgs); |
| 1694 | |
| 1695 | DeclarationName Name = NameInfo.getName(); |
| 1696 | bool IsArrow = (OpKind == tok::arrow); |
| 1697 | |
| 1698 | NamedDecl *FirstQualifierInScope |
| 1699 | = (!SS.isSet() ? nullptr : FindFirstQualifierInScope(S, SS.getScopeRep())); |
| 1700 | |
| 1701 | |
| 1702 | ExprResult Result = MaybeConvertParenListExprToParenExpr(S, Base); |
| 1703 | if (Result.isInvalid()) return ExprError(); |
| 1704 | Base = Result.get(); |
| 1705 | |
| 1706 | if (Base->getType()->isDependentType() || Name.isDependentName() || |
| 1707 | isDependentScopeSpecifier(SS)) { |
| 1708 | return ActOnDependentMemberExpr(Base, Base->getType(), IsArrow, OpLoc, SS, |
| 1709 | TemplateKWLoc, FirstQualifierInScope, |
| 1710 | NameInfo, TemplateArgs); |
| 1711 | } |
| 1712 | |
| 1713 | ActOnMemberAccessExtraArgs = {S, Id, ObjCImpDecl}; |
| 1714 | ExprResult Res = BuildMemberReferenceExpr( |
| 1715 | Base, Base->getType(), OpLoc, IsArrow, SS, TemplateKWLoc, |
| 1716 | FirstQualifierInScope, NameInfo, TemplateArgs, S, &ExtraArgs); |
| 1717 | |
| 1718 | if (!Res.isInvalid() && isa<MemberExpr>(Res.get())) |
| 1719 | CheckMemberAccessOfNoDeref(cast<MemberExpr>(Res.get())); |
| 1720 | |
| 1721 | return Res; |
| 1722 | } |
| 1723 | |
| 1724 | void Sema::CheckMemberAccessOfNoDeref(const MemberExpr *E) { |
| 1725 | QualType ResultTy = E->getType(); |
| 1726 | |
| 1727 | |
| 1728 | |
| 1729 | if (isa<ArrayType>(ResultTy)) |
| 1730 | return; |
| 1731 | |
| 1732 | if (E->isArrow()) { |
| 1733 | if (const auto *Ptr = dyn_cast<PointerType>( |
| 1734 | E->getBase()->getType().getDesugaredType(Context))) { |
| 1735 | if (Ptr->getPointeeType()->hasAttr(attr::NoDeref)) |
| 1736 | ExprEvalContexts.back().PossibleDerefs.insert(E); |
| 1737 | } |
| 1738 | } |
| 1739 | } |
| 1740 | |
| 1741 | ExprResult |
| 1742 | Sema::BuildFieldReferenceExpr(Expr *BaseExpr, bool IsArrow, |
| 1743 | SourceLocation OpLoc, const CXXScopeSpec &SS, |
| 1744 | FieldDecl *Field, DeclAccessPair FoundDecl, |
| 1745 | const DeclarationNameInfo &MemberNameInfo) { |
| 1746 | |
| 1747 | |
| 1748 | |
| 1749 | |
| 1750 | ExprValueKind VK = VK_LValue; |
| 1751 | ExprObjectKind OK = OK_Ordinary; |
| 1752 | if (!IsArrow) { |
| 1753 | if (BaseExpr->getObjectKind() == OK_Ordinary) |
| 1754 | VK = BaseExpr->getValueKind(); |
| 1755 | else |
| 1756 | VK = VK_RValue; |
| 1757 | } |
| 1758 | if (VK != VK_RValue && Field->isBitField()) |
| 1759 | OK = OK_BitField; |
| 1760 | |
| 1761 | |
| 1762 | QualType MemberType = Field->getType(); |
| 1763 | if (const ReferenceType *Ref = MemberType->getAs<ReferenceType>()) { |
| 1764 | MemberType = Ref->getPointeeType(); |
| 1765 | VK = VK_LValue; |
| 1766 | } else { |
| 1767 | QualType BaseType = BaseExpr->getType(); |
| 1768 | if (IsArrow) BaseType = BaseType->getAs<PointerType>()->getPointeeType(); |
| 1769 | |
| 1770 | Qualifiers BaseQuals = BaseType.getQualifiers(); |
| 1771 | |
| 1772 | |
| 1773 | BaseQuals.removeObjCGCAttr(); |
| 1774 | |
| 1775 | |
| 1776 | |
| 1777 | if (Field->isMutable()) BaseQuals.removeConst(); |
| 1778 | |
| 1779 | Qualifiers MemberQuals = |
| 1780 | Context.getCanonicalType(MemberType).getQualifiers(); |
| 1781 | |
| 1782 | assert(!MemberQuals.hasAddressSpace()); |
| 1783 | |
| 1784 | Qualifiers Combined = BaseQuals + MemberQuals; |
| 1785 | if (Combined != MemberQuals) |
| 1786 | MemberType = Context.getQualifiedType(MemberType, Combined); |
| 1787 | } |
| 1788 | |
| 1789 | auto *CurMethod = dyn_cast<CXXMethodDecl>(CurContext); |
| 1790 | if (!(CurMethod && CurMethod->isDefaulted())) |
| 1791 | UnusedPrivateFields.remove(Field); |
| 1792 | |
| 1793 | ExprResult Base = PerformObjectMemberConversion(BaseExpr, SS.getScopeRep(), |
| 1794 | FoundDecl, Field); |
| 1795 | if (Base.isInvalid()) |
| 1796 | return ExprError(); |
| 1797 | |
| 1798 | |
| 1799 | |
| 1800 | if (getLangOpts().OpenMP && IsArrow && |
| 1801 | !CurContext->isDependentContext() && |
| 1802 | isa<CXXThisExpr>(Base.get()->IgnoreParenImpCasts())) { |
| 1803 | if (auto *PrivateCopy = isOpenMPCapturedDecl(Field)) { |
| 1804 | return getOpenMPCapturedExpr(PrivateCopy, VK, OK, |
| 1805 | MemberNameInfo.getLoc()); |
| 1806 | } |
| 1807 | } |
| 1808 | |
| 1809 | return BuildMemberExpr(*this, Context, Base.get(), IsArrow, OpLoc, SS, |
| 1810 | (), Field, FoundDecl, |
| 1811 | MemberNameInfo, MemberType, VK, OK); |
| 1812 | } |
| 1813 | |
| 1814 | |
| 1815 | |
| 1816 | |
| 1817 | |
| 1818 | ExprResult |
| 1819 | Sema::BuildImplicitMemberExpr(const CXXScopeSpec &SS, |
| 1820 | SourceLocation TemplateKWLoc, |
| 1821 | LookupResult &R, |
| 1822 | const TemplateArgumentListInfo *TemplateArgs, |
| 1823 | bool IsKnownInstance, const Scope *S) { |
| 1824 | assert(!R.empty() && !R.isAmbiguous()); |
| 1825 | |
| 1826 | SourceLocation loc = R.getNameLoc(); |
| 1827 | |
| 1828 | |
| 1829 | |
| 1830 | |
| 1831 | QualType ThisTy = getCurrentThisType(); |
| 1832 | (0) . __assert_fail ("!ThisTy.isNull() && \"didn't correctly pre-flight capture of 'this'\"", "/home/seafit/code_projects/clang_source/clang/lib/Sema/SemaExprMember.cpp", 1832, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!ThisTy.isNull() && "didn't correctly pre-flight capture of 'this'"); |
| 1833 | |
| 1834 | Expr *baseExpr = nullptr; |
| 1835 | if (IsKnownInstance) { |
| 1836 | SourceLocation Loc = R.getNameLoc(); |
| 1837 | if (SS.getRange().isValid()) |
| 1838 | Loc = SS.getRange().getBegin(); |
| 1839 | CheckCXXThisCapture(Loc); |
| 1840 | baseExpr = new (Context) CXXThisExpr(loc, ThisTy, ); |
| 1841 | } |
| 1842 | |
| 1843 | return BuildMemberReferenceExpr(baseExpr, ThisTy, |
| 1844 | SourceLocation(), |
| 1845 | true, |
| 1846 | SS, TemplateKWLoc, |
| 1847 | nullptr, |
| 1848 | R, TemplateArgs, S); |
| 1849 | } |
| 1850 | |