[PATCH] D151523: [ASTStructuralEquivalence] Fix crash when ObjCCategoryDecl doesn't have corresponding ObjCInterfaceDecl.
Volodymyr Sapsai via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 9 17:10:07 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2e16df352c7a: [ASTStructuralEquivalence] Fix crash when ObjCCategoryDecl doesn't haveā¦ (authored by vsapsai).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D151523/new/
https://reviews.llvm.org/D151523
Files:
clang/lib/AST/ASTStructuralEquivalence.cpp
clang/unittests/AST/StructuralEquivalenceTest.cpp
Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===================================================================
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -1143,6 +1143,18 @@
EXPECT_FALSE(testStructuralMatch(t));
}
+TEST_F(StructuralEquivalenceObjCCategoryTest, CategoriesWithoutInterfaces) {
+ auto t = makeDecls<ObjCCategoryDecl>(" @interface A(X) @end",
+ "@interface A @end @interface A(X) @end",
+ Lang_OBJC, objcCategoryDecl());
+ EXPECT_FALSE(testStructuralMatch(t));
+
+ auto t2 = makeDecls<ObjCCategoryDecl>("@interface A(X) @end",
+ "@interface A(X) @end",
+ Lang_OBJC, objcCategoryDecl());
+ EXPECT_TRUE(testStructuralMatch(t2));
+}
+
TEST_F(StructuralEquivalenceObjCCategoryTest, CategoryAndExtension) {
auto t = makeDecls<ObjCCategoryDecl>("@interface A @end @interface A(X) @end",
"@interface A @end @interface A() @end",
Index: clang/lib/AST/ASTStructuralEquivalence.cpp
===================================================================
--- clang/lib/AST/ASTStructuralEquivalence.cpp
+++ clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -2057,8 +2057,13 @@
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 @@
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(),
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151523.530121.patch
Type: text/x-patch
Size: 2386 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230610/ad4483be/attachment-0001.bin>
More information about the cfe-commits
mailing list