From: Benjamin Kramer Date: Fri, 15 Feb 2013 15:17:50 +0000 (+0000) Subject: Sema: Unnest early exit and remove an unnecessary bad cast. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=25c0510690ddd354a550096abe7370bd8079defb;p=platform%2Fupstream%2Fllvm.git Sema: Unnest early exit and remove an unnecessary bad cast. cast doesn't look through sugar, getAs does. Fixes PR15257. llvm-svn: 175272 --- diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 0ed460c..933105e 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/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()) { - 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(); + + // 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(Type), + Method = S.LookupMethodInQualifiedType(IsEqualSel, Type, /*instance=*/true); } } diff --git a/clang/test/SemaObjC/objc-literal-comparison.m b/clang/test/SemaObjC/objc-literal-comparison.m index 0a10582..95ebfb3 100644 --- a/clang/test/SemaObjC/objc-literal-comparison.m +++ b/clang/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}} +}