From 7c2bdcb4d30f2d370b4367664e6a11b075ce2cb3 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Mon, 18 Apr 2011 21:16:59 +0000 Subject: [PATCH] Fix a bug in calculation of composite type of conditional expressions of objc pointer types where one type is the immediate base type of the other. // rdar://9296866 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129718 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ASTContext.cpp | 6 +++--- test/SemaObjC/conditional-expr-8.m | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 test/SemaObjC/conditional-expr-8.m diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index f723f2a8b7..524a7563e6 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -4963,10 +4963,10 @@ QualType ASTContext::areCommonBaseCompatible( const ObjCObjectType *RHS = Rptr->getObjectType(); const ObjCInterfaceDecl* LDecl = LHS->getInterface(); const ObjCInterfaceDecl* RDecl = RHS->getInterface(); - if (!LDecl || !RDecl) + if (!LDecl || !RDecl || (LDecl == RDecl)) return QualType(); - while ((LDecl = LDecl->getSuperClass())) { + do { LHS = cast(getObjCInterfaceType(LDecl)); if (canAssignObjCInterfaces(LHS, RHS)) { llvm::SmallVector Protocols; @@ -4978,7 +4978,7 @@ QualType ASTContext::areCommonBaseCompatible( Result = getObjCObjectPointerType(Result); return Result; } - } + } while ((LDecl = LDecl->getSuperClass())); return QualType(); } diff --git a/test/SemaObjC/conditional-expr-8.m b/test/SemaObjC/conditional-expr-8.m new file mode 100644 index 0000000000..6799983e3b --- /dev/null +++ b/test/SemaObjC/conditional-expr-8.m @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// rdar://9296866 + +@interface NSResponder +@end + + +@interface NSView : NSResponder +@end + +@interface WebView : NSView +@end + +@protocol WebDocumentView +@end + +@implementation NSView + +- (void) FUNC : (id)s { + WebView *m_webView; + NSView *documentView; + NSView *coordinateView = s ? documentView : m_webView; +} +@end + -- 2.50.1