From 6dc4e613eb8c3da6f1b83e4b121560ce7f197698 Mon Sep 17 00:00:00 2001 From: Ben Langmuir <blangmuir@apple.com> Date: Mon, 18 Aug 2014 19:32:45 +0000 Subject: [PATCH] Fix the rececl chain for redeclarations of predefined decls Predefined decls like 'Protocol' in objc are not loaded from AST files, so we cannot rely on loading the canonical decl to complete the redecl chain for redeclarations of these decls. The broken redecl chain was non-circular, so looping over redecls() would hang. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@215929 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Serialization/ASTReaderDecl.cpp | 2 ++ test/Index/Inputs/declare-objc-predef.h | 3 +++ test/Index/reparse-predef-objc-protocol.m | 9 +++++++++ 3 files changed, 14 insertions(+) create mode 100644 test/Index/Inputs/declare-objc-predef.h create mode 100644 test/Index/reparse-predef-objc-protocol.m diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index 05d3bab9a7d..3e24145075e 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -2019,6 +2019,8 @@ void ASTDeclReader::mergeRedeclarable(Redeclarable<T> *DBase, T *D = static_cast<T*>(DBase); T *DCanon = D->getCanonicalDecl(); if (D != DCanon && + // IDs < NUM_PREDEF_DECL_IDS are not loaded from an AST file. + Redecl.getFirstID() >= NUM_PREDEF_DECL_IDS && (!Reader.getContext().getLangOpts().Modules || Reader.getOwningModuleFile(DCanon) == Reader.getOwningModuleFile(D))) { // All redeclarations between this declaration and its originally-canonical diff --git a/test/Index/Inputs/declare-objc-predef.h b/test/Index/Inputs/declare-objc-predef.h new file mode 100644 index 00000000000..6a03c4f88d2 --- /dev/null +++ b/test/Index/Inputs/declare-objc-predef.h @@ -0,0 +1,3 @@ +@class Protocol; +typedef struct objc_class *Class +@class id; diff --git a/test/Index/reparse-predef-objc-protocol.m b/test/Index/reparse-predef-objc-protocol.m new file mode 100644 index 00000000000..fc9d8572e0c --- /dev/null +++ b/test/Index/reparse-predef-objc-protocol.m @@ -0,0 +1,9 @@ +// RUN: env CINDEXTEST_EDITING=1 c-index-test -test-load-source-reparse 3 local %s -I %S/Inputs +#import "declare-objc-predef.h" +// PR20633 + +// CHECK: declare-objc-predef.h:1:8: ObjCInterfaceDecl=Protocol:1:8 Extent=[1:1 - 1:16] +// CHECK: declare-objc-predef.h:1:8: ObjCClassRef=Protocol:1:8 Extent=[1:8 - 1:16] +// CHECK: declare-objc-predef.h:2:16: StructDecl=objc_class:2:16 Extent=[2:9 - 2:26] +// CHECK: declare-objc-predef.h:2:28: TypedefDecl=Class:2:28 (Definition) Extent=[2:1 - 2:33] +// CHECK: declare-objc-predef.h:2:16: TypeRef=struct objc_class:2:16 Extent=[2:16 - 2:26] -- GitLab