diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index cc98713241395..090a54eedaa07 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -1050,10 +1050,10 @@ static void handleDiagnoseAsBuiltinAttr(Sema &S, Decl *D, FunctionDecl *AttrFD = [&]() -> FunctionDecl * { if (!AL.isArgExpr(0)) return nullptr; - auto *F = dyn_cast_or_null(AL.getArgAsExpr(0)); + auto *F = dyn_cast_if_present(AL.getArgAsExpr(0)); if (!F) return nullptr; - return dyn_cast_or_null(F->getFoundDecl()); + return dyn_cast_if_present(F->getFoundDecl()); }(); if (!AttrFD || !AttrFD->getBuiltinID(true)) { @@ -1452,7 +1452,7 @@ static void handlePreferredName(Sema &S, Decl *D, const ParsedAttr &AL) { if (!T.hasQualifiers() && T->isTypedefNameType()) { // Find the template name, if this type names a template specialization. const TemplateDecl *Template = nullptr; - if (const auto *CTSD = dyn_cast_or_null( + if (const auto *CTSD = dyn_cast_if_present( T->getAsCXXRecordDecl())) { Template = CTSD->getSpecializedTemplate(); } else if (const auto *TST = T->getAs()) { @@ -2643,10 +2643,11 @@ static void handleAvailabilityAttr(Sema &S, Decl *D, const ParsedAttr &AL) { bool IsUnavailable = AL.getUnavailableLoc().isValid(); bool IsStrict = AL.getStrictLoc().isValid(); StringRef Str; - if (const auto *SE = dyn_cast_or_null(AL.getMessageExpr())) + if (const auto *SE = dyn_cast_if_present(AL.getMessageExpr())) Str = SE->getString(); StringRef Replacement; - if (const auto *SE = dyn_cast_or_null(AL.getReplacementExpr())) + if (const auto *SE = + dyn_cast_if_present(AL.getReplacementExpr())) Replacement = SE->getString(); if (II->isStr("swift")) { @@ -2863,14 +2864,14 @@ static void handleExternalSourceSymbolAttr(Sema &S, Decl *D, return; StringRef Language; - if (const auto *SE = dyn_cast_or_null(AL.getArgAsExpr(0))) + if (const auto *SE = dyn_cast_if_present(AL.getArgAsExpr(0))) Language = SE->getString(); StringRef DefinedIn; - if (const auto *SE = dyn_cast_or_null(AL.getArgAsExpr(1))) + if (const auto *SE = dyn_cast_if_present(AL.getArgAsExpr(1))) DefinedIn = SE->getString(); bool IsGeneratedDeclaration = AL.getArgAsIdent(2) != nullptr; StringRef USR; - if (const auto *SE = dyn_cast_or_null(AL.getArgAsExpr(3))) + if (const auto *SE = dyn_cast_if_present(AL.getArgAsExpr(3))) USR = SE->getString(); D->addAttr(::new (S.Context) ExternalSourceSymbolAttr( @@ -6148,7 +6149,7 @@ static void handleObjCRequiresSuperAttr(Sema &S, Decl *D, const auto *Method = cast(D); const DeclContext *DC = Method->getDeclContext(); - if (const auto *PDecl = dyn_cast_or_null(DC)) { + if (const auto *PDecl = dyn_cast_if_present(DC)) { S.Diag(D->getBeginLoc(), diag::warn_objc_requires_super_protocol) << Attrs << 0; S.Diag(PDecl->getLocation(), diag::note_protocol_decl);