diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2013-02-15 15:17:50 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2013-02-15 15:17:50 +0000 |
commit | 2e85e743dc3d5b2f7ee6cd94a0c35fbc2e40e829 (patch) | |
tree | 8ba5031c2ebee7a02cc38a3f875320b68a052b68 | |
parent | 0f9827f5d6248d7008063768eb5f2c3e6ba83e94 (diff) |
Sema: Unnest early exit and remove an unnecessary bad cast.
cast<ObjCObjectPointerType> doesn't look through sugar, getAs does.
Fixes PR15257.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175272 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 25 | ||||
-rw-r--r-- | test/SemaObjC/objc-literal-comparison.m | 3 |
2 files changed, 15 insertions, 13 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 0ed460cc5e..933105e628 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -6846,18 +6846,18 @@ static bool isObjCObjectLiteral(ExprResult &E) { } static bool hasIsEqualMethod(Sema &S, const Expr *LHS, const Expr *RHS) { - // Get the LHS object's interface type. - QualType Type = LHS->getType(); - QualType InterfaceType; - if (const ObjCObjectPointerType *PTy = Type->getAs<ObjCObjectPointerType>()) { - InterfaceType = PTy->getPointeeType(); - if (const ObjCObjectType *iQFaceTy = - InterfaceType->getAsObjCQualifiedInterfaceType()) - InterfaceType = iQFaceTy->getBaseType(); - } else { - // If this is not actually an Objective-C object, bail out. + const ObjCObjectPointerType *Type = + LHS->getType()->getAs<ObjCObjectPointerType>(); + + // If this is not actually an Objective-C object, bail out. + if (!Type) return false; - } + + // Get the LHS object's interface type. + QualType InterfaceType = Type->getPointeeType(); + if (const ObjCObjectType *iQFaceTy = + InterfaceType->getAsObjCQualifiedInterfaceType()) + InterfaceType = iQFaceTy->getBaseType(); // If the RHS isn't an Objective-C object, bail out. if (!RHS->getType()->isObjCObjectPointerType()) @@ -6876,8 +6876,7 @@ static bool hasIsEqualMethod(Sema &S, const Expr *LHS, const Expr *RHS) { /*warn=*/false); } else { // Check protocols. - Method = S.LookupMethodInQualifiedType(IsEqualSel, - cast<ObjCObjectPointerType>(Type), + Method = S.LookupMethodInQualifiedType(IsEqualSel, Type, /*instance=*/true); } } diff --git a/test/SemaObjC/objc-literal-comparison.m b/test/SemaObjC/objc-literal-comparison.m index 0a1058291e..95ebfb397b 100644 --- a/test/SemaObjC/objc-literal-comparison.m +++ b/test/SemaObjC/objc-literal-comparison.m @@ -98,3 +98,6 @@ void testNilComparison() { RETURN_IF_NIL(@(1+1)); } +void PR15257(Class c) { + return c == @""; // expected-warning{{direct comparison of a string literal has undefined behavior}} +} |