Skip to content

Commit b2bbf69

Browse files
committed
[clang][Sema][NFC] _or_null -> _if_present
1 parent 0f05096 commit b2bbf69

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,10 +1050,10 @@ static void handleDiagnoseAsBuiltinAttr(Sema &S, Decl *D,
10501050
FunctionDecl *AttrFD = [&]() -> FunctionDecl * {
10511051
if (!AL.isArgExpr(0))
10521052
return nullptr;
1053-
auto *F = dyn_cast_or_null<DeclRefExpr>(AL.getArgAsExpr(0));
1053+
auto *F = dyn_cast_if_present<DeclRefExpr>(AL.getArgAsExpr(0));
10541054
if (!F)
10551055
return nullptr;
1056-
return dyn_cast_or_null<FunctionDecl>(F->getFoundDecl());
1056+
return dyn_cast_if_present<FunctionDecl>(F->getFoundDecl());
10571057
}();
10581058

10591059
if (!AttrFD || !AttrFD->getBuiltinID(true)) {
@@ -1452,7 +1452,7 @@ static void handlePreferredName(Sema &S, Decl *D, const ParsedAttr &AL) {
14521452
if (!T.hasQualifiers() && T->isTypedefNameType()) {
14531453
// Find the template name, if this type names a template specialization.
14541454
const TemplateDecl *Template = nullptr;
1455-
if (const auto *CTSD = dyn_cast_or_null<ClassTemplateSpecializationDecl>(
1455+
if (const auto *CTSD = dyn_cast_if_present<ClassTemplateSpecializationDecl>(
14561456
T->getAsCXXRecordDecl())) {
14571457
Template = CTSD->getSpecializedTemplate();
14581458
} else if (const auto *TST = T->getAs<TemplateSpecializationType>()) {
@@ -2643,10 +2643,11 @@ static void handleAvailabilityAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
26432643
bool IsUnavailable = AL.getUnavailableLoc().isValid();
26442644
bool IsStrict = AL.getStrictLoc().isValid();
26452645
StringRef Str;
2646-
if (const auto *SE = dyn_cast_or_null<StringLiteral>(AL.getMessageExpr()))
2646+
if (const auto *SE = dyn_cast_if_present<StringLiteral>(AL.getMessageExpr()))
26472647
Str = SE->getString();
26482648
StringRef Replacement;
2649-
if (const auto *SE = dyn_cast_or_null<StringLiteral>(AL.getReplacementExpr()))
2649+
if (const auto *SE =
2650+
dyn_cast_if_present<StringLiteral>(AL.getReplacementExpr()))
26502651
Replacement = SE->getString();
26512652

26522653
if (II->isStr("swift")) {
@@ -2863,14 +2864,14 @@ static void handleExternalSourceSymbolAttr(Sema &S, Decl *D,
28632864
return;
28642865

28652866
StringRef Language;
2866-
if (const auto *SE = dyn_cast_or_null<StringLiteral>(AL.getArgAsExpr(0)))
2867+
if (const auto *SE = dyn_cast_if_present<StringLiteral>(AL.getArgAsExpr(0)))
28672868
Language = SE->getString();
28682869
StringRef DefinedIn;
2869-
if (const auto *SE = dyn_cast_or_null<StringLiteral>(AL.getArgAsExpr(1)))
2870+
if (const auto *SE = dyn_cast_if_present<StringLiteral>(AL.getArgAsExpr(1)))
28702871
DefinedIn = SE->getString();
28712872
bool IsGeneratedDeclaration = AL.getArgAsIdent(2) != nullptr;
28722873
StringRef USR;
2873-
if (const auto *SE = dyn_cast_or_null<StringLiteral>(AL.getArgAsExpr(3)))
2874+
if (const auto *SE = dyn_cast_if_present<StringLiteral>(AL.getArgAsExpr(3)))
28742875
USR = SE->getString();
28752876

28762877
D->addAttr(::new (S.Context) ExternalSourceSymbolAttr(
@@ -6148,7 +6149,7 @@ static void handleObjCRequiresSuperAttr(Sema &S, Decl *D,
61486149
const auto *Method = cast<ObjCMethodDecl>(D);
61496150

61506151
const DeclContext *DC = Method->getDeclContext();
6151-
if (const auto *PDecl = dyn_cast_or_null<ObjCProtocolDecl>(DC)) {
6152+
if (const auto *PDecl = dyn_cast_if_present<ObjCProtocolDecl>(DC)) {
61526153
S.Diag(D->getBeginLoc(), diag::warn_objc_requires_super_protocol) << Attrs
61536154
<< 0;
61546155
S.Diag(PDecl->getLocation(), diag::note_protocol_decl);

0 commit comments

Comments
 (0)