diff options
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/AST/ASTContext.cpp | 24 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 7 |
2 files changed, 27 insertions, 4 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index deb80900bb3..f4266fb90d1 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -2036,14 +2036,30 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS) { if (LHSClass != RHSClass) { // ID is compatible with all qualified id types. if (LHS->isObjCQualifiedIdType()) { - if (const PointerType *PT = RHS->getAsPointerType()) - if (isObjCIdType(PT->getPointeeType())) + if (const PointerType *PT = RHS->getAsPointerType()) { + QualType pType = PT->getPointeeType(); + if (isObjCIdType(pType)) return LHS; + // FIXME: need to use ObjCQualifiedIdTypesAreCompatible(LHS, RHS, true). + // Unfortunately, this API is part of Sema (which we don't have access + // to. Need to refactor. The following check is insufficient, since we + // need to make sure the class implements the protocol. + if (pType->isObjCInterfaceType()) + return LHS; + } } if (RHS->isObjCQualifiedIdType()) { - if (const PointerType *PT = LHS->getAsPointerType()) - if (isObjCIdType(PT->getPointeeType())) + if (const PointerType *PT = LHS->getAsPointerType()) { + QualType pType = PT->getPointeeType(); + if (isObjCIdType(pType)) return RHS; + // FIXME: need to use ObjCQualifiedIdTypesAreCompatible(LHS, RHS, true). + // Unfortunately, this API is part of Sema (which we don't have access + // to. Need to refactor. The following check is insufficient, since we + // need to make sure the class implements the protocol. + if (pType->isObjCInterfaceType()) + return RHS; + } } // C99 6.7.2.2p4: Each enumerated type shall be compatible with char, diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 563718ccc8d..1f885165cd9 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -2061,6 +2061,13 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation loc, } if ((lType->isObjCQualifiedIdType() || rType->isObjCQualifiedIdType())) { + if ((lType->isPointerType() || rType->isPointerType()) && + !Context.typesAreCompatible(lType, rType)) { + Diag(loc, diag::ext_typecheck_comparison_of_distinct_pointers, + lType.getAsString(), rType.getAsString(), + lex->getSourceRange(), rex->getSourceRange()); + return QualType(); + } if (ObjCQualifiedIdTypesAreCompatible(lType, rType, true)) { ImpCastExprToType(rex, lType); return Context.IntTy; |

