r328654 - [Sema] Avoid crash for category implementation without interface
Shoaib Meenai via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 27 11:58:28 PDT 2018
Author: smeenai
Date: Tue Mar 27 11:58:28 2018
New Revision: 328654
URL: http://llvm.org/viewvc/llvm-project?rev=328654&view=rev
Log:
[Sema] Avoid crash for category implementation without interface
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
Added:
cfe/trunk/test/SemaObjC/undef-class-property-error.m
Modified:
cfe/trunk/lib/Sema/SemaExprMember.cpp
Modified: cfe/trunk/lib/Sema/SemaExprMember.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprMember.cpp?rev=328654&r1=328653&r2=328654&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprMember.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprMember.cpp Tue Mar 27 11:58:28 2018
@@ -1568,6 +1568,9 @@ static ExprResult LookupMemberExpr(Sema
// 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.
Added: cfe/trunk/test/SemaObjC/undef-class-property-error.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/undef-class-property-error.m?rev=328654&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/undef-class-property-error.m (added)
+++ cfe/trunk/test/SemaObjC/undef-class-property-error.m Tue Mar 27 11:58:28 2018
@@ -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
More information about the cfe-commits
mailing list