Author: Akira Hatanaka Date: 2022-10-05T10:38:25-07:00 New Revision: 65a961f719a7ad6db9b608c323a21ed50b4e36ed
URL: https://github.com/llvm/llvm-project/commit/65a961f719a7ad6db9b608c323a21ed50b4e36ed DIFF: https://github.com/llvm/llvm-project/commit/65a961f719a7ad6db9b608c323a21ed50b4e36ed.diff LOG: [Sema][ObjC] Fix assertion failure in getCommonNonSugarTypeNode Instead of checking that the protocols of both types are all equal, check that the canonical decls are equal. Added: Modified: clang/lib/AST/ASTContext.cpp clang/test/SemaObjCXX/crash.mm Removed: ################################################################################ diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 461a108915c3a..b9d12e203feef 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -12672,7 +12672,13 @@ static QualType getCommonNonSugarTypeNode(ASTContext &Ctx, const Type *X, } case Type::ObjCObject: { const auto *OX = cast<ObjCObjectType>(X), *OY = cast<ObjCObjectType>(Y); - assert(llvm::equal(OX->getProtocols(), OY->getProtocols())); + assert( + std::equal(OX->getProtocols().begin(), OX->getProtocols().end(), + OY->getProtocols().begin(), OY->getProtocols().end(), + [](const ObjCProtocolDecl *P0, const ObjCProtocolDecl *P1) { + return P0->getCanonicalDecl() == P1->getCanonicalDecl(); + }) && + "protocol lists must be the same"); auto TAs = getCommonTypes(Ctx, OX->getTypeArgsAsWritten(), OY->getTypeArgsAsWritten()); return Ctx.getObjCObjectType( diff --git a/clang/test/SemaObjCXX/crash.mm b/clang/test/SemaObjCXX/crash.mm index 6a7f0fbfc6600..cf55b5733a7bd 100644 --- a/clang/test/SemaObjCXX/crash.mm +++ b/clang/test/SemaObjCXX/crash.mm @@ -60,3 +60,11 @@ @protocol InvalidProperties // expected-error@-3 {{cannot declare variable inside @interface or @protocol}} @end + +// This used to crash. +@protocol Property0; +@protocol Property0; +id<Property0> x; +@protocol Property0; +id<Property0> y; +id<Property0> z = true ? x : y; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits