Patch fixes PR21932 crash on invalid code. Using
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 20 Jan 2015 16:53:34 +0000 (16:53 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 20 Jan 2015 16:53:34 +0000 (16:53 +0000)
property-dot syntax on 'super' with no super
class. Patch by Jason Haslam.

llvm-svn: 226578

clang/lib/Sema/SemaExprObjC.cpp
clang/test/SemaObjC/super-property-notation.m

index 9c3b51c623d38b9fde97baaf028e27e12797fd03..8bdd18ea20e3a5a7afd226e488eb54eb455f9a58 100644 (file)
@@ -1751,29 +1751,30 @@ ActOnClassPropertyRefExpr(IdentifierInfo &receiverName,
       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 = CurMethod->getClassInterface()->getSuperClass();
+          // Otherwise, if this is a class method, try dispatching to our
+          // superclass.
+          IFace = Class->getSuperClass();
+        }
       }
     }
 
index 2b13a5c0f87c248a437a4e123e5ae8ab73c344aa..7d7b84deb7cdb6bdb0646b4321a5ffe3f78d9f9e 100644 (file)
@@ -50,3 +50,9 @@ __attribute__((objc_root_class)) @interface ClassBase
   [super setFoo:foo]; // works with no warning
 }
 @end
+
+@implementation IFaceNotFound (Foo) // expected-error {{cannot find interface declaration for 'IFaceNotFound'}}
+-(int) foo {
+  return super.foo; // expected-error {{expected identifier or '('}}
+}
+@end