Lines Matching +full:diag +full:- +full:version

1 //===--- SemaAvailability.cpp - Availability attribute handling -----------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
34 IdentifierInfo *IIEnvironment = AA->getEnvironment(); in hasMatchingEnvironmentOrNone()
40 AvailabilityAttr::getEnvironmentType(IIEnvironment->getName()); in hasMatchingEnvironmentOrNone()
53 D = FTD->getTemplatedDecl(); in getAttrForPlatform()
54 for (const auto *A : D->attrs()) { in getAttrForPlatform()
57 // de-duplicate. in getAttrForPlatform()
61 StringRef ActualPlatform = Avail->getPlatform()->getName(); in getAttrForPlatform()
87 /// \param Message If non-null, this will be populated with the message from
95 AvailabilityResult Result = D->getAvailability(Message); in ShouldDiagnoseAvailabilityOfDecl()
101 if (const auto *TT = TD->getUnderlyingType()->getAs<TagType>()) { in ShouldDiagnoseAvailabilityOfDecl()
102 D = TT->getDecl(); in ShouldDiagnoseAvailabilityOfDecl()
103 Result = D->getAvailability(Message); in ShouldDiagnoseAvailabilityOfDecl()
112 D = ADecl->getTemplatedDecl(); in ShouldDiagnoseAvailabilityOfDecl()
113 Result = D->getAvailability(Message); in ShouldDiagnoseAvailabilityOfDecl()
118 if (IDecl->getDefinition()) { in ShouldDiagnoseAvailabilityOfDecl()
119 D = IDecl->getDefinition(); in ShouldDiagnoseAvailabilityOfDecl()
120 Result = D->getAvailability(Message); in ShouldDiagnoseAvailabilityOfDecl()
126 const DeclContext *DC = ECD->getDeclContext(); in ShouldDiagnoseAvailabilityOfDecl()
128 Result = TheEnumDecl->getAvailability(Message); in ShouldDiagnoseAvailabilityOfDecl()
133 // For +new, infer availability from -init. in ShouldDiagnoseAvailabilityOfDecl()
136 ObjCMethodDecl *Init = ClassReceiver->lookupInstanceMethod( in ShouldDiagnoseAvailabilityOfDecl()
137 S.ObjC().NSAPIObj->getInitSelector()); in ShouldDiagnoseAvailabilityOfDecl()
138 if (Init && Result == AR_Available && MD->isClassMethod() && in ShouldDiagnoseAvailabilityOfDecl()
139 MD->getSelector() == S.ObjC().NSAPIObj->getNewSelector() && in ShouldDiagnoseAvailabilityOfDecl()
140 MD->definedInNSObject(S.getASTContext())) { in ShouldDiagnoseAvailabilityOfDecl()
141 Result = Init->getAvailability(Message); in ShouldDiagnoseAvailabilityOfDecl()
160 auto DeclLoc = Ctx->getBeginLoc(); in ShouldDiagnoseAvailabilityInContext()
172 // strict (-fhlsl-strict-availability), or if the target is library and the in ShouldDiagnoseAvailabilityInContext()
189 if (AA->getIntroduced() >= DeclVersion && in ShouldDiagnoseAvailabilityInContext()
190 AA->getEnvironment() == DeclEnv) in ShouldDiagnoseAvailabilityInContext()
193 if (C->isDeprecated()) in ShouldDiagnoseAvailabilityInContext()
196 // It is perfectly fine to refer to an 'unavailable' Objective-C method in ShouldDiagnoseAvailabilityInContext()
201 if (MD->getClassInterface() == Impl->getClassInterface()) in ShouldDiagnoseAvailabilityInContext()
207 if (C->isUnavailable()) in ShouldDiagnoseAvailabilityInContext()
219 if (MethodD->isClassMethod() && in ShouldDiagnoseAvailabilityInContext()
220 MethodD->getSelector().getAsString() == "load") in ShouldDiagnoseAvailabilityInContext()
224 if (const ObjCInterfaceDecl *Interface = CatOrImpl->getClassInterface()) in ShouldDiagnoseAvailabilityInContext()
230 if (const ObjCInterfaceDecl *Interface = CatD->getClassInterface()) in ShouldDiagnoseAvailabilityInContext()
233 } while ((Ctx = cast_or_null<Decl>(Ctx->getDeclContext()))); in ShouldDiagnoseAvailabilityInContext()
244 // For iOS, emit the diagnostic even if -Wunguarded-availability is in getAvailabilityDiagnosticKind()
261 // (-fhlsl-strict-availability) and as warnings in relaxed diagnostic in getAvailabilityDiagnosticKind()
262 // mode (-Wno-error=hlsl-availability) in getAvailabilityDiagnosticKind()
264 return HasMatchingEnv ? diag::warn_hlsl_availability in getAvailabilityDiagnosticKind()
265 : diag::warn_hlsl_availability_unavailable; in getAvailabilityDiagnosticKind()
271 : VersionTuple(/*Major=*/(unsigned)-1, (unsigned)-1); in getAvailabilityDiagnosticKind()
275 return HasMatchingEnv ? diag::warn_unguarded_availability_new in getAvailabilityDiagnosticKind()
276 : diag::warn_unguarded_availability_unavailable_new; in getAvailabilityDiagnosticKind()
277 return HasMatchingEnv ? diag::warn_unguarded_availability in getAvailabilityDiagnosticKind()
278 : diag::warn_unguarded_availability_unavailable; in getAvailabilityDiagnosticKind()
283 Ctx = cast_or_null<Decl>(Ctx->getDeclContext())) { in findEnclosingDeclToAnnotate()
288 return Imp->getClassInterface(); in findEnclosingDeclToAnnotate()
304 return {" ", D->getEndLoc(), ""}; in createInsertionAfter()
310 return {"", D->getBeginLoc(), "\n"}; in createInsertionBefore()
327 // Accept replacements starting with - or + as valid ObjC method names. in tryParseObjCMethodName()
328 if (!Name.empty() && (Name.front() == '-' || Name.front() == '+')) in tryParseObjCMethodName()
340 // Not a valid method name, just a colon-separated string. in tryParseObjCMethodName()
363 if (MD->hasBody()) in createAttributeInsertion()
369 Lexer::getLocForEndOfToken(TD->getInnerLocStart(), 0, SM, LangOpts); in createAttributeInsertion()
397 unsigned diag, diag_message, diag_fwdclass_message; in DoEmitAvailabilityWarning() local
398 unsigned diag_available_here = diag::note_availability_specified_here; in DoEmitAvailabilityWarning()
399 SourceLocation NoteLocation = OffendingDecl->getLocation(); in DoEmitAvailabilityWarning()
401 // Matches 'diag::note_property_attribute' options. in DoEmitAvailabilityWarning()
404 // Matches diag::note_availability_specified_here. in DoEmitAvailabilityWarning()
411 DeclVersion = AA->getIntroduced(); in DoEmitAvailabilityWarning()
412 IIEnv = AA->getEnvironment(); in DoEmitAvailabilityWarning()
423 if (AA && AA->isInherited()) { in DoEmitAvailabilityWarning()
424 for (const Decl *Redecl = OffendingDecl->getMostRecentDecl(); Redecl; in DoEmitAvailabilityWarning()
425 Redecl = Redecl->getPreviousDecl()) { in DoEmitAvailabilityWarning()
428 if (AForRedecl && !AForRedecl->isInherited()) { in DoEmitAvailabilityWarning()
431 NoteLocation = Redecl->getLocation(); in DoEmitAvailabilityWarning()
439 // We would like to emit the diagnostic even if -Wunguarded-availability is in DoEmitAvailabilityWarning()
444 VersionTuple Introduced = AA->getIntroduced(); in DoEmitAvailabilityWarning()
454 AA->getEnvironment() ? AA->getEnvironment()->getName() : ""; in DoEmitAvailabilityWarning()
462 S.Diag(Loc, DiagKind) << OffendingDecl << PlatformName in DoEmitAvailabilityWarning()
466 S.Diag(OffendingDecl->getLocation(), in DoEmitAvailabilityWarning()
467 diag::note_partial_availability_specified_here) in DoEmitAvailabilityWarning()
478 if (TD->getDeclName().isEmpty()) { in DoEmitAvailabilityWarning()
479 S.Diag(TD->getLocation(), in DoEmitAvailabilityWarning()
480 diag::note_decl_unguarded_availability_silence) in DoEmitAvailabilityWarning()
481 << /*Anonymous*/ 1 << TD->getKindName(); in DoEmitAvailabilityWarning()
485 S.Diag(Enclosing->getLocation(), in DoEmitAvailabilityWarning()
486 diag::note_decl_unguarded_availability_silence) in DoEmitAvailabilityWarning()
489 if (Enclosing->hasAttr<AvailabilityAttr>()) in DoEmitAvailabilityWarning()
502 OffendingDecl->getVersionIntroduced().getAsString(); in DoEmitAvailabilityWarning()
504 Insertion->Loc, in DoEmitAvailabilityWarning()
505 (llvm::Twine(Insertion->Prefix) + "API_AVAILABLE(" + PlatformName + in DoEmitAvailabilityWarning()
506 "(" + Introduced + "))" + Insertion->Suffix) in DoEmitAvailabilityWarning()
512 diag = !ObjCPropertyAccess ? diag::warn_deprecated in DoEmitAvailabilityWarning()
513 : diag::warn_property_method_deprecated; in DoEmitAvailabilityWarning()
514 diag_message = diag::warn_deprecated_message; in DoEmitAvailabilityWarning()
515 diag_fwdclass_message = diag::warn_deprecated_fwdclass_message; in DoEmitAvailabilityWarning()
518 if (const auto *AL = OffendingDecl->getAttr<DeprecatedAttr>()) in DoEmitAvailabilityWarning()
519 NoteLocation = AL->getLocation(); in DoEmitAvailabilityWarning()
523 diag = !ObjCPropertyAccess ? diag::err_unavailable in DoEmitAvailabilityWarning()
524 : diag::err_property_method_unavailable; in DoEmitAvailabilityWarning()
525 diag_message = diag::err_unavailable_message; in DoEmitAvailabilityWarning()
526 diag_fwdclass_message = diag::warn_unavailable_fwdclass_message; in DoEmitAvailabilityWarning()
530 if (auto AL = OffendingDecl->getAttr<UnavailableAttr>()) { in DoEmitAvailabilityWarning()
531 if (AL->isImplicit() && AL->getImplicitReason()) { in DoEmitAvailabilityWarning()
537 OffendingDecl->getLocation())) in DoEmitAvailabilityWarning()
538 diag = diag::err_unavailable_in_arc; in DoEmitAvailabilityWarning()
541 switch (AL->getImplicitReason()) { in DoEmitAvailabilityWarning()
546 diag_available_here = diag::note_arc_forbidden_type; in DoEmitAvailabilityWarning()
551 diag_available_here = diag::note_arc_weak_disabled; in DoEmitAvailabilityWarning()
553 diag_available_here = diag::note_arc_weak_no_runtime; in DoEmitAvailabilityWarning()
558 diag_available_here = diag::note_performs_forbidden_arc_conversion; in DoEmitAvailabilityWarning()
563 diag_available_here = diag::note_arc_init_returns_unrelated; in DoEmitAvailabilityWarning()
568 diag_available_here = diag::note_arc_field_with_ownership; in DoEmitAvailabilityWarning()
582 if (auto AL = OffendingDecl->getAttr<DeprecatedAttr>()) in DoEmitAvailabilityWarning()
583 Replacement = AL->getReplacement(); in DoEmitAvailabilityWarning()
585 Replacement = AL->getReplacement(); in DoEmitAvailabilityWarning()
593 Selector Sel = MethodDecl->getSelector(); in DoEmitAvailabilityWarning()
640 S.Diag(Loc, diag_message) << ReferringDecl << Message << FixIts; in DoEmitAvailabilityWarning()
642 S.Diag(ObjCProperty->getLocation(), diag::note_property_attribute) in DoEmitAvailabilityWarning()
643 << ObjCProperty->getDeclName() << property_note_select; in DoEmitAvailabilityWarning()
645 S.Diag(Loc, diag) << ReferringDecl << FixIts; in DoEmitAvailabilityWarning()
647 S.Diag(ObjCProperty->getLocation(), diag::note_property_attribute) in DoEmitAvailabilityWarning()
648 << ObjCProperty->getDeclName() << property_note_select; in DoEmitAvailabilityWarning()
650 S.Diag(Loc, diag_fwdclass_message) << ReferringDecl << FixIts; in DoEmitAvailabilityWarning()
651 S.Diag(UnknownObjCClass->getLocation(), diag::note_forward_class); in DoEmitAvailabilityWarning()
654 S.Diag(NoteLocation, diag_available_here) in DoEmitAvailabilityWarning()
695 /// Returns true if the given statement can be a body-like child of \p Parent.
697 switch (Parent->getStmtClass()) { in isBodyLikeChildStmt()
699 return cast<IfStmt>(Parent)->getThen() == S || in isBodyLikeChildStmt()
700 cast<IfStmt>(Parent)->getElse() == S; in isBodyLikeChildStmt()
702 return cast<WhileStmt>(Parent)->getBody() == S; in isBodyLikeChildStmt()
704 return cast<DoStmt>(Parent)->getBody() == S; in isBodyLikeChildStmt()
706 return cast<ForStmt>(Parent)->getBody() == S; in isBodyLikeChildStmt()
708 return cast<CXXForRangeStmt>(Parent)->getBody() == S; in isBodyLikeChildStmt()
710 return cast<ObjCForCollectionStmt>(Parent)->getBody() == S; in isBodyLikeChildStmt()
713 return cast<SwitchCase>(Parent)->getSubStmt() == S; in isBodyLikeChildStmt()
740 if (DRE->getDecl() == D) in VisitDeclRefExpr()
749 for (const Stmt *S : llvm::reverse(Scope->body())) { in findLastStmtThatUsesDecl()
757 /// This class implements -Wunguarded-availability.
761 /// form: \c if(@available(...)), we use the version from the condition to visit
799 bool TraverseCaseStmt(CaseStmt *CS) { return TraverseStmt(CS->getSubStmt()); } in TraverseCaseStmt()
804 if (ObjCMethodDecl *D = Msg->getMethodDecl()) { in VisitObjCMessageExpr()
806 QualType ReceiverTy = Msg->getClassReceiver(); in VisitObjCMessageExpr()
807 if (!ReceiverTy.isNull() && ReceiverTy->getAsObjCInterfaceType()) in VisitObjCMessageExpr()
808 ID = ReceiverTy->getAsObjCInterfaceType()->getInterface(); in VisitObjCMessageExpr()
811 D, SourceRange(Msg->getSelectorStartLoc(), Msg->getEndLoc()), ID); in VisitObjCMessageExpr()
817 DiagnoseDeclAvailability(DRE->getDecl(), in VisitDeclRefExpr()
818 SourceRange(DRE->getBeginLoc(), DRE->getEndLoc())); in VisitDeclRefExpr()
823 DiagnoseDeclAvailability(ME->getMemberDecl(), in VisitMemberExpr()
824 SourceRange(ME->getBeginLoc(), ME->getEndLoc())); in VisitMemberExpr()
829 SemaRef.Diag(E->getBeginLoc(), diag::warn_at_available_unchecked_use) in VisitObjCAvailabilityCheckExpr()
854 VersionTuple Introduced = AA->getIntroduced(); in DiagnoseDeclAvailability()
862 AA->getEnvironment(), Ctx, in DiagnoseDeclAvailability()
871 AA->getEnvironment() ? AA->getEnvironment()->getName() : ""; in DiagnoseDeclAvailability()
880 SemaRef.Diag(Range.getBegin(), DiagKind) in DiagnoseDeclAvailability()
884 SemaRef.Diag(OffendingDecl->getLocation(), in DiagnoseDeclAvailability()
885 diag::note_partial_availability_specified_here) in DiagnoseDeclAvailability()
895 SemaRef.Diag(Range.getBegin(), diag::note_unguarded_available_silence) in DiagnoseDeclAvailability()
920 for (const Decl *D : cast<DeclStmt>(StmtOfUse)->decls()) { in DiagnoseDeclAvailability()
930 SM.getExpansionLoc(StmtOfUse->getBeginLoc()); in DiagnoseDeclAvailability()
933 (LastStmtOfUse ? LastStmtOfUse : StmtOfUse)->getEndLoc()) in DiagnoseDeclAvailability()
974 TagDecl *TD = TT->getDecl(); in VisitTypeLoc()
978 TypedefNameDecl *D = TD->getDecl(); in VisitTypeLoc()
982 if (NamedDecl *D = ObjCO->getInterface()) in VisitTypeLoc()
991 if (auto *E = dyn_cast<ObjCAvailabilityCheckExpr>(If->getCond())) { in TraverseIfStmt()
992 CondVersion = E->getVersion(); in TraverseIfStmt()
995 // use the enclosing version to check both branches. in TraverseIfStmt()
997 return TraverseStmt(If->getThen()) && TraverseStmt(If->getElse()); in TraverseIfStmt()
1004 bool ShouldContinue = TraverseStmt(If->getThen()); in TraverseIfStmt()
1007 return ShouldContinue && TraverseStmt(If->getElse()); in TraverseIfStmt()
1015 if (auto *FD = D->getAsFunction()) { in DiagnoseUnguardedAvailabilityViolations()
1016 Body = FD->getBody(); in DiagnoseUnguardedAvailabilityViolations()
1019 for (const CXXCtorInitializer *CI : CD->inits()) in DiagnoseUnguardedAvailabilityViolations()
1020 DiagnoseUnguardedAvailability(*this, D).IssueDiagnostics(CI->getInit()); in DiagnoseUnguardedAvailabilityViolations()
1023 Body = MD->getBody(); in DiagnoseUnguardedAvailabilityViolations()
1025 Body = BD->getBody(); in DiagnoseUnguardedAvailabilityViolations()
1066 Context->HasPotentialAvailabilityViolations = true; in DiagnoseAvailabilityOfDecl()
1073 if (const ObjCPropertyDecl *PD = MD->findPropertyDecl()) { in DiagnoseAvailabilityOfDecl()
1074 AvailabilityResult PDeclResult = PD->getAvailability(nullptr); in DiagnoseAvailabilityOfDecl()