r175272 - Sema: Unnest early exit and remove an unnecessary bad cast.

Benjamin Kramer benny.kra at googlemail.com
Fri Feb 15 07:17:50 PST 2013


Author: d0k
Date: Fri Feb 15 09:17:50 2013
New Revision: 175272

URL: http://llvm.org/viewvc/llvm-project?rev=175272&view=rev
Log:
Sema: Unnest early exit and remove an unnecessary bad cast.

cast<ObjCObjectPointerType> doesn't look through sugar, getAs does.
Fixes PR15257.

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaObjC/objc-literal-comparison.m

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=175272&r1=175271&r2=175272&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Feb 15 09:17:50 2013
@@ -6846,18 +6846,18 @@ static bool isObjCObjectLiteral(ExprResu
 }
 
 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, co
                                                   /*warn=*/false);
     } else {
       // Check protocols.
-      Method = S.LookupMethodInQualifiedType(IsEqualSel,
-                                             cast<ObjCObjectPointerType>(Type),
+      Method = S.LookupMethodInQualifiedType(IsEqualSel, Type,
                                              /*instance=*/true);
     }
   }

Modified: cfe/trunk/test/SemaObjC/objc-literal-comparison.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/objc-literal-comparison.m?rev=175272&r1=175271&r2=175272&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/objc-literal-comparison.m (original)
+++ cfe/trunk/test/SemaObjC/objc-literal-comparison.m Fri Feb 15 09:17:50 2013
@@ -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}}
+}





More information about the cfe-commits mailing list