]> granicus.if.org Git - clang/commitdiff
[Sema] Avoid crash for category implementation without interface
authorShoaib Meenai <smeenai@fb.com>
Tue, 27 Mar 2018 18:58:28 +0000 (18:58 +0000)
committerShoaib Meenai <smeenai@fb.com>
Tue, 27 Mar 2018 18:58:28 +0000 (18:58 +0000)
When we have a category implementation without a corresponding interface
(which is an error by itself), semantic checks for property accesses
will attempt to access a null interface declaration and then segfault.
Error out in such cases instead.

Differential Revision: https://reviews.llvm.org/D44916

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@328654 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExprMember.cpp
test/SemaObjC/undef-class-property-error.m [new file with mode: 0644]

index d0542742892cc01cef4e52d6c8249349fe9dfcbd..522e4bbe07492c958a8eadae3779d2e4f3559e57 100644 (file)
@@ -1568,6 +1568,9 @@ static ExprResult LookupMemberExpr(Sema &S, LookupResult &R,
       // Also must look for a getter name which uses property syntax.
       Selector Sel = S.PP.getSelectorTable().getNullarySelector(Member);
       ObjCInterfaceDecl *IFace = MD->getClassInterface();
+      if (!IFace)
+        goto fail;
+
       ObjCMethodDecl *Getter;
       if ((Getter = IFace->lookupClassMethod(Sel))) {
         // Check the use of this method.
diff --git a/test/SemaObjC/undef-class-property-error.m b/test/SemaObjC/undef-class-property-error.m
new file mode 100644 (file)
index 0000000..e7e5db4
--- /dev/null
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+@implementation I (C) // expected-error {{cannot find interface declaration for 'I'}}
+
++ (void)f {
+  self.m; // expected-error {{member reference base type 'Class' is not a structure or union}}
+}
+
+@end