summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2009-10-27 23:02:38 +0000
committerFariborz Jahanian <fjahanian@apple.com>2009-10-27 23:02:38 +0000
commitef8b8ce2074bd868bf338e297f6feacca8f2bb1f (patch)
tree8fac56adc0d8f3cb91cd4cf7d3e6e943dbca3d49 /clang/lib
parent5607d2cb5410c2e0059d25dc066fb8d2049e9a81 (diff)
downloadbcm5719-llvm-ef8b8ce2074bd868bf338e297f6feacca8f2bb1f.tar.gz
bcm5719-llvm-ef8b8ce2074bd868bf338e297f6feacca8f2bb1f.zip
Type of a conditional expression with two distinct objective-c
class pointer is the most derived common class of the two. This is <rdar://problem/7334235>. llvm-svn: 85337
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/AST/ASTContext.cpp22
-rw-r--r--clang/lib/Sema/SemaExpr.cpp5
2 files changed, 26 insertions, 1 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 6c63c524b40..eb6d39225b8 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -3846,6 +3846,28 @@ bool ASTContext::canAssignObjCInterfaces(const ObjCObjectPointerType *LHSOPT,
return false;
}
+/// areCommonBaseCompatible - Returns common base class of the two classes if
+/// one found. Note that this is O'2 algorithm. But it will be called as the
+/// last type comparison in a ?-exp of ObjC pointer types before a
+/// warning is issued. So, its invokation is extremely rare.
+QualType ASTContext::areCommonBaseCompatible(
+ const ObjCObjectPointerType *LHSOPT,
+ const ObjCObjectPointerType *RHSOPT) {
+ const ObjCInterfaceType* LHS = LHSOPT->getInterfaceType();
+ const ObjCInterfaceType* RHS = RHSOPT->getInterfaceType();
+ if (!LHS || !RHS)
+ return QualType();
+
+ while (const ObjCInterfaceDecl *LHSIDecl = LHS->getDecl()->getSuperClass()) {
+ QualType LHSTy = getObjCInterfaceType(LHSIDecl);
+ LHS = LHSTy->getAs<ObjCInterfaceType>();
+ if (canAssignObjCInterfaces(LHS, RHS))
+ return getObjCObjectPointerType(LHSTy);
+ }
+
+ return QualType();
+}
+
bool ASTContext::canAssignObjCInterfaces(const ObjCInterfaceType *LHS,
const ObjCInterfaceType *RHS) {
// Verify that the base decls are compatible: the RHS must be a subclass of
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index f4e58f07f8c..12f1f513d4f 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -3525,7 +3525,10 @@ QualType Sema::CheckConditionalOperands(Expr *&Cond, Expr *&LHS, Expr *&RHS,
compositeType = Context.getObjCIdType();
} else if (LHSTy->isObjCIdType() || RHSTy->isObjCIdType()) {
compositeType = Context.getObjCIdType();
- } else {
+ } else if (!(compositeType =
+ Context.areCommonBaseCompatible(LHSOPT, RHSOPT)).isNull())
+ ;
+ else {
Diag(QuestionLoc, diag::ext_typecheck_cond_incompatible_operands)
<< LHSTy << RHSTy
<< LHS->getSourceRange() << RHS->getSourceRange();
OpenPOWER on IntegriCloud