r226578 - Patch fixes PR21932 crash on invalid code. Using

Fariborz Jahanian fjahanian at apple.com
Tue Jan 20 08:53:34 PST 2015


Author: fjahanian
Date: Tue Jan 20 10:53:34 2015
New Revision: 226578

URL: http://llvm.org/viewvc/llvm-project?rev=226578&view=rev
Log:
Patch fixes PR21932 crash on invalid code. Using
property-dot syntax on 'super' with no super
class. Patch by Jason Haslam.

Modified:
    cfe/trunk/lib/Sema/SemaExprObjC.cpp
    cfe/trunk/test/SemaObjC/super-property-notation.m

Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=226578&r1=226577&r2=226578&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Tue Jan 20 10:53:34 2015
@@ -1751,29 +1751,30 @@ ActOnClassPropertyRefExpr(IdentifierInfo
       IsSuper = true;
 
       if (ObjCMethodDecl *CurMethod = tryCaptureObjCSelf(receiverNameLoc)) {
-        if (CurMethod->isInstanceMethod()) {
-          ObjCInterfaceDecl *Super =
-            CurMethod->getClassInterface()->getSuperClass();
-          if (!Super) {
-            // The current class does not have a superclass.
-            Diag(receiverNameLoc, diag::error_root_class_cannot_use_super)
-            << CurMethod->getClassInterface()->getIdentifier();
-            return ExprError();
+        if (ObjCInterfaceDecl *Class = CurMethod->getClassInterface()) {
+          if (CurMethod->isInstanceMethod()) {
+            ObjCInterfaceDecl *Super = Class->getSuperClass();
+            if (!Super) {
+              // The current class does not have a superclass.
+              Diag(receiverNameLoc, diag::error_root_class_cannot_use_super)
+              << Class->getIdentifier();
+              return ExprError();
+            }
+            QualType T = Context.getObjCInterfaceType(Super);
+            T = Context.getObjCObjectPointerType(T);
+
+            return HandleExprPropertyRefExpr(T->getAsObjCInterfacePointerType(),
+                                             /*BaseExpr*/nullptr,
+                                             SourceLocation()/*OpLoc*/,
+                                             &propertyName,
+                                             propertyNameLoc,
+                                             receiverNameLoc, T, true);
           }
-          QualType T = Context.getObjCInterfaceType(Super);
-          T = Context.getObjCObjectPointerType(T);
 
-          return HandleExprPropertyRefExpr(T->getAsObjCInterfacePointerType(),
-                                           /*BaseExpr*/nullptr,
-                                           SourceLocation()/*OpLoc*/, 
-                                           &propertyName,
-                                           propertyNameLoc,
-                                           receiverNameLoc, T, true);
+          // Otherwise, if this is a class method, try dispatching to our
+          // superclass.
+          IFace = Class->getSuperClass();
         }
-
-        // Otherwise, if this is a class method, try dispatching to our
-        // superclass.
-        IFace = CurMethod->getClassInterface()->getSuperClass();
       }
     }
 

Modified: cfe/trunk/test/SemaObjC/super-property-notation.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/super-property-notation.m?rev=226578&r1=226577&r2=226578&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/super-property-notation.m (original)
+++ cfe/trunk/test/SemaObjC/super-property-notation.m Tue Jan 20 10:53:34 2015
@@ -50,3 +50,9 @@ __attribute__((objc_root_class)) @interf
   [super setFoo:foo]; // works with no warning
 }
 @end
+
+ at implementation IFaceNotFound (Foo) // expected-error {{cannot find interface declaration for 'IFaceNotFound'}}
+-(int) foo {
+  return super.foo; // expected-error {{expected identifier or '('}}
+}
+ at end





More information about the cfe-commits mailing list