From 8cceefac395d476114b3d4ecd7e969b2e1c9271d Mon Sep 17 00:00:00 2001
From: Argyrios Kyrtzidis <akyrtzi@gmail.com>
Date: Fri, 24 Feb 2012 01:12:38 +0000
Subject: [PATCH] [PCH] When keeping track of top-level decls for "targeted
 deserialization" make sure we don't mistake ParmVarDecls for top-level decls.

Fixes rdar://10920009.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@151330 91177308-0d34-0410-b5e6-96231b3b80d8
---
 lib/Serialization/ASTWriter.cpp | 3 +++
 test/Index/targeted-cursor.m    | 6 ++++++
 test/Index/targeted-cursor.m.h  | 7 +++++++
 3 files changed, 16 insertions(+)
 create mode 100644 test/Index/targeted-cursor.m
 create mode 100644 test/Index/targeted-cursor.m.h

diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp
index 8dbd6e44715..66e5d6a625e 100644
--- a/lib/Serialization/ASTWriter.cpp
+++ b/lib/Serialization/ASTWriter.cpp
@@ -3860,6 +3860,9 @@ void ASTWriter::associateDeclWithFile(const Decl *D, DeclID ID) {
   // We only keep track of the file-level declarations of each file.
   if (!D->getLexicalDeclContext()->isFileContext())
     return;
+  // FIXME: We should never have ParmVarDecls with TU as context.
+  if (isa<ParmVarDecl>(D))
+    return;
 
   SourceManager &SM = Context->getSourceManager();
   SourceLocation FileLoc = SM.getFileLoc(Loc);
diff --git a/test/Index/targeted-cursor.m b/test/Index/targeted-cursor.m
new file mode 100644
index 00000000000..94c62e8964b
--- /dev/null
+++ b/test/Index/targeted-cursor.m
@@ -0,0 +1,6 @@
+
+// rdar://10920009
+// RUN: c-index-test -write-pch %t.h.pch -x objective-c-header %S/targeted-cursor.m.h -Xclang -detailed-preprocessing-record
+// RUN: c-index-test -cursor-at=%S/targeted-cursor.m.h:5:13 %s -include %t.h | FileCheck %s
+
+// CHECK: ObjCClassRef=I:2:12
diff --git a/test/Index/targeted-cursor.m.h b/test/Index/targeted-cursor.m.h
new file mode 100644
index 00000000000..735c7bd08f2
--- /dev/null
+++ b/test/Index/targeted-cursor.m.h
@@ -0,0 +1,7 @@
+
+@interface I
+
+-(void)mm:(void (^)(I*))block;
+-(void)mm2:(I*)i;
+
+@end
-- 
GitLab