]> granicus.if.org Git - clang/commitdiff
[ObjC] Prevent infinite loops when iterating over redeclaration
authorAlex Lorenz <arphaman@gmail.com>
Mon, 21 Nov 2016 11:16:30 +0000 (11:16 +0000)
committerAlex Lorenz <arphaman@gmail.com>
Mon, 21 Nov 2016 11:16:30 +0000 (11:16 +0000)
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

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

lib/AST/DeclObjC.cpp
test/SemaObjC/method-redecls-invalid-interface.m [new file with mode: 0644]

index 72e0fcea7bdd5111891cfe79f79a41a00e81d8ea..60d05f682e6e0f3341a081f97f30f59e9f758afb 100644 (file)
@@ -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/test/SemaObjC/method-redecls-invalid-interface.m b/test/SemaObjC/method-redecls-invalid-interface.m
new file mode 100644 (file)
index 0000000..235d6fe
--- /dev/null
@@ -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