r287530 - [ObjC] Prevent infinite loops when iterating over redeclaration
Alex Lorenz via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 21 03:16:31 PST 2016
Author: arphaman
Date: Mon Nov 21 05:16:30 2016
New Revision: 287530
URL: http://llvm.org/viewvc/llvm-project?rev=287530&view=rev
Log:
[ObjC] Prevent infinite loops when iterating over redeclaration
of a method that was declared in an invalid interface
This commit fixes an infinite loop that occurs when clang tries to iterate over
redeclaration of a method that was declared in an invalid @interface. The
existing validity checks don't catch this as that @interface is a duplicate of
a previously declared valid @interface declaration, so we have to verify that
the found redeclaration is in a valid declaration context.
rdar://29220965
Differential Revision: https://reviews.llvm.org/D26664
Added:
cfe/trunk/test/SemaObjC/method-redecls-invalid-interface.m
Modified:
cfe/trunk/lib/AST/DeclObjC.cpp
Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=287530&r1=287529&r2=287530&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Mon Nov 21 05:16:30 2016
@@ -870,6 +870,12 @@ ObjCMethodDecl *ObjCMethodDecl::getNextR
}
}
+ // Ensure that the discovered method redeclaration has a valid declaration
+ // context. Used to prevent infinite loops when iterating redeclarations in
+ // a partially invalid AST.
+ if (Redecl && cast<Decl>(Redecl->getDeclContext())->isInvalidDecl())
+ Redecl = nullptr;
+
if (!Redecl && isRedeclaration()) {
// This is the last redeclaration, go back to the first method.
return cast<ObjCContainerDecl>(CtxD)->getMethod(getSelector(),
Added: cfe/trunk/test/SemaObjC/method-redecls-invalid-interface.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/method-redecls-invalid-interface.m?rev=287530&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/method-redecls-invalid-interface.m (added)
+++ cfe/trunk/test/SemaObjC/method-redecls-invalid-interface.m Mon Nov 21 05:16:30 2016
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wdocumentation -Wno-objc-root-class %s
+// rdar://29220965
+
+ at interface InvalidInterface { // expected-note {{previous definition is here}}
+ int *_property;
+}
+
+ at end
+
+/*!
+ */
+
+ at interface InvalidInterface // expected-error {{duplicate interface definition for class 'InvalidInterface'}}
+ at property int *property;
+
+-(void) method;
+ at end
+
+ at implementation InvalidInterface
+-(void) method { }
+ at end
More information about the cfe-commits
mailing list