summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Lorenz <arphaman@gmail.com>2016-11-21 11:16:30 +0000
committerAlex Lorenz <arphaman@gmail.com>2016-11-21 11:16:30 +0000
commitff6c34b30ddc2339a32ce8bc7e294f76c7640ab5 (patch)
treede2d1efd96220e4ef479aaf08604cb0741a1450c
parent9229d332bfc4521d6213d3cc9b485e70f812f1ee (diff)
downloadbcm5719-llvm-ff6c34b30ddc2339a32ce8bc7e294f76c7640ab5.tar.gz
bcm5719-llvm-ff6c34b30ddc2339a32ce8bc7e294f76c7640ab5.zip
[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 llvm-svn: 287530
-rw-r--r--clang/lib/AST/DeclObjC.cpp6
-rw-r--r--clang/test/SemaObjC/method-redecls-invalid-interface.m21
2 files changed, 27 insertions, 0 deletions
diff --git a/clang/lib/AST/DeclObjC.cpp b/clang/lib/AST/DeclObjC.cpp
index 72e0fcea7bd..60d05f682e6 100644
--- a/clang/lib/AST/DeclObjC.cpp
+++ b/clang/lib/AST/DeclObjC.cpp
@@ -870,6 +870,12 @@ ObjCMethodDecl *ObjCMethodDecl::getNextRedeclarationImpl() {
}
}
+ // 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(),
diff --git a/clang/test/SemaObjC/method-redecls-invalid-interface.m b/clang/test/SemaObjC/method-redecls-invalid-interface.m
new file mode 100644
index 00000000000..235d6fe5e9d
--- /dev/null
+++ b/clang/test/SemaObjC/method-redecls-invalid-interface.m
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wdocumentation -Wno-objc-root-class %s
+// rdar://29220965
+
+@interface InvalidInterface { // expected-note {{previous definition is here}}
+ int *_property;
+}
+
+@end
+
+/*!
+ */
+
+@interface InvalidInterface // expected-error {{duplicate interface definition for class 'InvalidInterface'}}
+@property int *property;
+
+-(void) method;
+@end
+
+@implementation InvalidInterface
+-(void) method { }
+@end
OpenPOWER on IntegriCloud