]> granicus.if.org Git - clang/commitdiff
[libclang] Make sure we don't crash when trying to index code that
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 23 Mar 2012 23:24:18 +0000 (23:24 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 23 Mar 2012 23:24:18 +0000 (23:24 +0000)
managed to insert an @interface as top level decl contained by another
@interface.

A commit to also not allow this as valid code will be coming.

rdar://11105114.

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

test/Index/index-decls.m
tools/libclang/IndexDecl.cpp
tools/libclang/IndexingContext.h

index dc808ea51373ad37691f76bf7e1f9b367366ffb0..9e4e620497fe65e6b2eecf9d038b5f2247b4d479 100644 (file)
 @synthesize prop = _prop;
 @end
 
-// RUN: c-index-test -index-file %s | FileCheck %s
+rdar://11015325
+@interface I1
+__attribute__((something)) @interface I2 @end
+@end
+
+// RUN: c-index-test -index-file %s > %t
+// RUN: FileCheck %s -input-file=%t
 // CHECK: [indexDeclaration]: kind: objc-class | name: I | {{.*}} | loc: 1:12
 // CHECK: [indexDeclaration]: kind: objc-instance-method | name: prop | {{.*}} | loc: 3:2
 // CHECK: [indexDeclaration]: kind: objc-property | name: prop | {{.*}} | loc: 2:25
index 3f2c8b57101ad96fc53b086b82ae9adee26cc789..c257c342aa72892b7210de9a42f0bc6543454bce 100644 (file)
@@ -328,7 +328,9 @@ void IndexingContext::indexDeclGroupRef(DeclGroupRef DG) {
 }
 
 void IndexingContext::indexTUDeclsInObjCContainer() {
-  for (unsigned i = 0, e = TUDeclsInObjCContainer.size(); i != e; ++i)
-    indexDeclGroupRef(TUDeclsInObjCContainer[i]);
-  TUDeclsInObjCContainer.clear();
+  while (!TUDeclsInObjCContainer.empty()) {
+    DeclGroupRef DG = TUDeclsInObjCContainer.front();
+    TUDeclsInObjCContainer.pop_front();
+    indexDeclGroupRef(DG);
+  }
 }
index d828b17ca5c230d871480a6e8542b7cf30dade6a..93d4718e27c27b519a658cb034574871b54b0b1c 100644 (file)
@@ -13,6 +13,7 @@
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DeclGroup.h"
 #include "llvm/ADT/DenseSet.h"
+#include <deque>
 
 namespace clang {
   class FileEntry;
@@ -285,7 +286,7 @@ class IndexingContext {
 
   llvm::DenseSet<RefFileOccurence> RefFileOccurences;
 
-  SmallVector<DeclGroupRef, 8> TUDeclsInObjCContainer;
+  std::deque<DeclGroupRef> TUDeclsInObjCContainer;
   
   llvm::BumpPtrAllocator StrScratch;
   unsigned StrAdapterCount;