[PATCH] D26664: [ObjC] Prevent infinite loops when iterating over redeclaration of a method that was declared in an invalid interface

Alex Lorenz via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 21 03:26:24 PST 2016


This revision was automatically updated to reflect the committed changes.
arphaman marked 6 inline comments as done.
Closed by commit rL287530: [ObjC] Prevent infinite loops when iterating over redeclaration (authored by arphaman).

Changed prior to commit:
  https://reviews.llvm.org/D26664?vs=77980&id=78699#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26664

Files:
  cfe/trunk/lib/AST/DeclObjC.cpp
  cfe/trunk/test/SemaObjC/method-redecls-invalid-interface.m


Index: cfe/trunk/lib/AST/DeclObjC.cpp
===================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp
+++ cfe/trunk/lib/AST/DeclObjC.cpp
@@ -870,6 +870,12 @@
     }
   }
 
+  // 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(),
Index: cfe/trunk/test/SemaObjC/method-redecls-invalid-interface.m
===================================================================
--- cfe/trunk/test/SemaObjC/method-redecls-invalid-interface.m
+++ cfe/trunk/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
+
+ 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26664.78699.patch
Type: text/x-patch
Size: 1401 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161121/c79ddbff/attachment.bin>


More information about the cfe-commits mailing list