[PATCH] D44916: [Sema] Avoid crash for category implementation without interface

Shoaib Meenai via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 26 19:25:12 PDT 2018


smeenai created this revision.
smeenai added reviewers: doug.gregor, rjmccall, rsmith.

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.

I'm not sure if it's best to add the null check where I've added it or
if it should be fixed further up the stack.


Repository:
  rC Clang

https://reviews.llvm.org/D44916

Files:
  lib/Sema/SemaExprMember.cpp
  test/SemaObjC/undef-class-property-error.m


Index: test/SemaObjC/undef-class-property-error.m
===================================================================
--- /dev/null
+++ test/SemaObjC/undef-class-property-error.m
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+ at 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}}
+}
+
+ at end
Index: lib/Sema/SemaExprMember.cpp
===================================================================
--- lib/Sema/SemaExprMember.cpp
+++ lib/Sema/SemaExprMember.cpp
@@ -1568,6 +1568,9 @@
       // 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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44916.139878.patch
Type: text/x-patch
Size: 1013 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180327/caad7c7f/attachment.bin>


More information about the cfe-commits mailing list