summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorManman Ren <manman.ren@gmail.com>2016-05-06 19:35:02 +0000
committerManman Ren <manman.ren@gmail.com>2016-05-06 19:35:02 +0000
commitc46f7d1883144b3c94f008ed902d6bc4c81a21f8 (patch)
treea74f1f523a861f2a93b69eb02883c5d4fae2d695 /clang/lib
parentf0b6b40fa4f0ef91ae8ababc88663abdafcffab2 (diff)
downloadbcm5719-llvm-c46f7d1883144b3c94f008ed902d6bc4c81a21f8.tar.gz
bcm5719-llvm-c46f7d1883144b3c94f008ed902d6bc4c81a21f8.zip
ObjC kindof: set the type of a conditional expression when involving kindof.
When either LHS or RHS is a kindof type, we return a kindof type. rdar://problem/20513780 llvm-svn: 268781
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/AST/ASTContext.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 7a09b0b93bb..f1aa16adba9 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -7163,6 +7163,11 @@ QualType ASTContext::areCommonBaseCompatible(
if (!LDecl || !RDecl)
return QualType();
+ // When either LHS or RHS is a kindof type, we should return a kindof type.
+ // For example, for common base of kindof(ASub1) and kindof(ASub2), we return
+ // kindof(A).
+ bool anyKindOf = LHS->isKindOfType() || RHS->isKindOfType();
+
// Follow the left-hand side up the class hierarchy until we either hit a
// root or find the RHS. Record the ancestors in case we don't find it.
llvm::SmallDenseMap<const ObjCInterfaceDecl *, const ObjCObjectType *, 4>
@@ -7197,10 +7202,12 @@ QualType ASTContext::areCommonBaseCompatible(
anyChanges = true;
// If anything in the LHS will have changed, build a new result type.
- if (anyChanges) {
+ // If we need to return a kindof type but LHS is not a kindof type, we
+ // build a new result type.
+ if (anyChanges || LHS->isKindOfType() != anyKindOf) {
QualType Result = getObjCInterfaceType(LHS->getInterface());
Result = getObjCObjectType(Result, LHSTypeArgs, Protocols,
- LHS->isKindOfType());
+ anyKindOf || LHS->isKindOfType());
return getObjCObjectPointerType(Result);
}
@@ -7245,10 +7252,12 @@ QualType ASTContext::areCommonBaseCompatible(
if (!Protocols.empty())
anyChanges = true;
- if (anyChanges) {
+ // If we need to return a kindof type but RHS is not a kindof type, we
+ // build a new result type.
+ if (anyChanges || RHS->isKindOfType() != anyKindOf) {
QualType Result = getObjCInterfaceType(RHS->getInterface());
Result = getObjCObjectType(Result, RHSTypeArgs, Protocols,
- RHS->isKindOfType());
+ anyKindOf || RHS->isKindOfType());
return getObjCObjectPointerType(Result);
}
OpenPOWER on IntegriCloud