aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/ASTStructuralEquivalence.cpp
diff options
context:
space:
mode:
authorVolodymyr Sapsai <vsapsai@apple.com>2023-05-25 18:09:11 -0700
committerVolodymyr Sapsai <vsapsai@apple.com>2023-06-09 17:09:28 -0700
commit2e16df352c7acb910313c80ac90b650ad9c14a3d (patch)
tree3a82d8918779ff2ec4ce2c15fe41905d6aa5b667 /clang/lib/AST/ASTStructuralEquivalence.cpp
parent261b693afd82b7dc935bbbafa44b16f591a38daf (diff)
downloadllvm-2e16df352c7acb910313c80ac90b650ad9c14a3d.zip
llvm-2e16df352c7acb910313c80ac90b650ad9c14a3d.tar.gz
llvm-2e16df352c7acb910313c80ac90b650ad9c14a3d.tar.bz2
[ASTStructuralEquivalence] Fix crash when ObjCCategoryDecl doesn't have corresponding ObjCInterfaceDecl.
When this happens, it is invalid code and there is diagnostic ``` error: cannot find interface declaration for '...' ``` But clang shouldn't crash even if code is invalid. Though subsequent diagnostic can be imperfect because without ObjCInterfaceDecl we don't have a type for error messages. rdar://108818430 Differential Revision: https://reviews.llvm.org/D151523
Diffstat (limited to 'clang/lib/AST/ASTStructuralEquivalence.cpp')
-rw-r--r--clang/lib/AST/ASTStructuralEquivalence.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp b/clang/lib/AST/ASTStructuralEquivalence.cpp
index a947078..f867b6b 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -2057,8 +2057,13 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
if (!IsStructurallyEquivalent(D1->getIdentifier(), D2->getIdentifier()))
return false;
- if (!IsStructurallyEquivalent(D1->getClassInterface()->getIdentifier(),
- D2->getClassInterface()->getIdentifier()))
+ const ObjCInterfaceDecl *Intf1 = D1->getClassInterface(),
+ *Intf2 = D2->getClassInterface();
+ if ((!Intf1 || !Intf2) && (Intf1 != Intf2))
+ return false;
+
+ if (Intf1 &&
+ !IsStructurallyEquivalent(Intf1->getIdentifier(), Intf2->getIdentifier()))
return false;
// Compare protocols.
@@ -2077,7 +2082,8 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
return false;
// Compare ivars.
- QualType D2Type = Context.ToCtx.getObjCInterfaceType(D2->getClassInterface());
+ QualType D2Type =
+ Intf2 ? Context.ToCtx.getObjCInterfaceType(Intf2) : QualType();
ObjCCategoryDecl::ivar_iterator Ivar2 = D2->ivar_begin(),
Ivar2End = D2->ivar_end();
for (ObjCCategoryDecl::ivar_iterator Ivar1 = D1->ivar_begin(),