diff options
-rw-r--r-- | clang/include/clang/Serialization/ASTBitCodes.h | 10 | ||||
-rw-r--r-- | clang/include/clang/Serialization/ASTReader.h | 8 | ||||
-rw-r--r-- | clang/include/clang/Serialization/ASTWriter.h | 13 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTReader.cpp | 10 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTReaderDecl.cpp | 3 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTWriter.cpp | 6 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTWriterDecl.cpp | 14 | ||||
-rw-r--r-- | clang/test/Modules/Inputs/autolink-sub3.h | 1 | ||||
-rw-r--r-- | clang/test/Modules/Inputs/autolink-sub3.pch | 1 | ||||
-rw-r--r-- | clang/test/Modules/Inputs/module.map | 5 | ||||
-rw-r--r-- | clang/test/Modules/autolink.m | 12 |
11 files changed, 48 insertions, 35 deletions
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h b/clang/include/clang/Serialization/ASTBitCodes.h index 4bfa8b7b1e5..eccf7404ced 100644 --- a/clang/include/clang/Serialization/ASTBitCodes.h +++ b/clang/include/clang/Serialization/ASTBitCodes.h @@ -349,15 +349,15 @@ namespace clang { /// IDs). IDENTIFIER_TABLE = 5, - /// \brief Record code for the array of external definitions. + /// \brief Record code for the array of eagerly deserialized decls. /// - /// The AST file contains a list of all of the unnamed external - /// definitions present within the parsed headers, stored as an - /// array of declaration IDs. These external definitions will be + /// The AST file contains a list of all of the declarations that should be + /// eagerly deserialized present within the parsed headers, stored as an + /// array of declaration IDs. These declarations will be /// reported to the AST consumer after the AST file has been /// read, since their presence can affect the semantics of the /// program (e.g., for code generation). - EXTERNAL_DEFINITIONS = 6, + EAGERLY_DESERIALIZED_DECLS = 6, /// \brief Record code for the set of non-builtin, special /// types. diff --git a/clang/include/clang/Serialization/ASTReader.h b/clang/include/clang/Serialization/ASTReader.h index 9b92fd8ce3e..3cfd17ca027 100644 --- a/clang/include/clang/Serialization/ASTReader.h +++ b/clang/include/clang/Serialization/ASTReader.h @@ -610,10 +610,10 @@ private: /// \brief The IDs of all declarations that fulfill the criteria of /// "interesting" decls. /// - /// This contains the data loaded from all EXTERNAL_DEFINITIONS blocks in the - /// chain. The referenced declarations are deserialized and passed to the - /// consumer eagerly. - SmallVector<uint64_t, 16> ExternalDefinitions; + /// This contains the data loaded from all EAGERLY_DESERIALIZED_DECLS blocks + /// in the chain. The referenced declarations are deserialized and passed to + /// the consumer eagerly. + SmallVector<uint64_t, 16> EagerlyDeserializedDecls; /// \brief The IDs of all tentative definitions stored in the chain. /// diff --git a/clang/include/clang/Serialization/ASTWriter.h b/clang/include/clang/Serialization/ASTWriter.h index 66cab462578..cb2d83bbac5 100644 --- a/clang/include/clang/Serialization/ASTWriter.h +++ b/clang/include/clang/Serialization/ASTWriter.h @@ -297,16 +297,15 @@ private: /// \brief Declarations encountered that might be external /// definitions. /// - /// We keep track of external definitions (as well as tentative - /// definitions) as we are emitting declarations to the AST - /// file. The AST file contains a separate record for these external - /// definitions, which are provided to the AST consumer by the AST - /// reader. This is behavior is required to properly cope with, + /// We keep track of external definitions and other 'interesting' declarations + /// as we are emitting declarations to the AST file. The AST file contains a + /// separate record for these declarations, which are provided to the AST + /// consumer by the AST reader. This is behavior is required to properly cope with, /// e.g., tentative variable definitions that occur within /// headers. The declarations themselves are stored as declaration - /// IDs, since they will be written out to an EXTERNAL_DEFINITIONS + /// IDs, since they will be written out to an EAGERLY_DESERIALIZED_DECLS /// record. - SmallVector<uint64_t, 16> ExternalDefinitions; + SmallVector<uint64_t, 16> EagerlyDeserializedDecls; /// \brief DeclContexts that have received extensions since their serialized /// form. diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 10a182fe9e8..3a93804eab7 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -2256,9 +2256,9 @@ bool ASTReader::ReadASTBlock(ModuleFile &F) { break; } - case EXTERNAL_DEFINITIONS: + case EAGERLY_DESERIALIZED_DECLS: for (unsigned I = 0, N = Record.size(); I != N; ++I) - ExternalDefinitions.push_back(getGlobalDeclID(F, Record[I])); + EagerlyDeserializedDecls.push_back(getGlobalDeclID(F, Record[I])); break; case SPECIAL_TYPES: @@ -5985,12 +5985,12 @@ void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { if (!Consumer) return; - for (unsigned I = 0, N = ExternalDefinitions.size(); I != N; ++I) { + for (unsigned I = 0, N = EagerlyDeserializedDecls.size(); I != N; ++I) { // Force deserialization of this decl, which will cause it to be queued for // passing to the consumer. - GetDecl(ExternalDefinitions[I]); + GetDecl(EagerlyDeserializedDecls[I]); } - ExternalDefinitions.clear(); + EagerlyDeserializedDecls.clear(); PassInterestingDeclsToConsumer(); } diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index a9ff8a0b731..943328b9cdc 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -1984,7 +1984,8 @@ static bool isConsumerInterestedIn(Decl *D, bool HasBody) { if (isa<FileScopeAsmDecl>(D) || isa<ObjCProtocolDecl>(D) || - isa<ObjCImplDecl>(D)) + isa<ObjCImplDecl>(D) || + isa<ImportDecl>(D)) return true; if (VarDecl *Var = dyn_cast<VarDecl>(D)) return Var->isFileVarDecl() && diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index e931a7eeb2a..18d83cfe6ae 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -813,7 +813,7 @@ void ASTWriter::WriteBlockInfoBlock() { RECORD(DECL_OFFSET); RECORD(IDENTIFIER_OFFSET); RECORD(IDENTIFIER_TABLE); - RECORD(EXTERNAL_DEFINITIONS); + RECORD(EAGERLY_DESERIALIZED_DECLS); RECORD(SPECIAL_TYPES); RECORD(STATISTICS); RECORD(TENTATIVE_DEFINITIONS); @@ -4192,8 +4192,8 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, Stream.EmitRecord(SPECIAL_TYPES, SpecialTypes); // Write the record containing external, unnamed definitions. - if (!ExternalDefinitions.empty()) - Stream.EmitRecord(EXTERNAL_DEFINITIONS, ExternalDefinitions); + if (!EagerlyDeserializedDecls.empty()) + Stream.EmitRecord(EAGERLY_DESERIALIZED_DECLS, EagerlyDeserializedDecls); // Write the record containing tentative definitions. if (!TentativeDefinitions.empty()) diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp index 89f9b4885fa..5d5e4bb428f 100644 --- a/clang/lib/Serialization/ASTWriterDecl.cpp +++ b/clang/lib/Serialization/ASTWriterDecl.cpp @@ -1817,8 +1817,10 @@ static bool isRequiredDecl(const Decl *D, ASTContext &Context) { // An ObjCMethodDecl is never considered as "required" because its // implementation container always is. - // File scoped assembly or obj-c implementation must be seen. - if (isa<FileScopeAsmDecl>(D) || isa<ObjCImplDecl>(D)) + // File scoped assembly or obj-c implementation must be seen. ImportDecl is + // used by codegen to determine the set of imported modules to search for + // inputs for automatic linking. + if (isa<FileScopeAsmDecl>(D) || isa<ObjCImplDecl>(D) || isa<ImportDecl>(D)) return true; return Context.DeclMustBeEmitted(D); @@ -1906,10 +1908,8 @@ void ASTWriter::WriteDecl(ASTContext &Context, Decl *D) { // Flush C++ base specifiers, if there are any. FlushCXXBaseSpecifiers(); - // Note "external" declarations so that we can add them to a record in the - // AST file later. - // - // FIXME: This should be renamed, the predicate is much more complicated. + // Note declarations that should be deserialized eagerly so that we can add + // them to a record in the AST file later. if (isRequiredDecl(D, Context)) - ExternalDefinitions.push_back(ID); + EagerlyDeserializedDecls.push_back(ID); } diff --git a/clang/test/Modules/Inputs/autolink-sub3.h b/clang/test/Modules/Inputs/autolink-sub3.h new file mode 100644 index 00000000000..132c72976cd --- /dev/null +++ b/clang/test/Modules/Inputs/autolink-sub3.h @@ -0,0 +1 @@ +int autolink_sub3(void); diff --git a/clang/test/Modules/Inputs/autolink-sub3.pch b/clang/test/Modules/Inputs/autolink-sub3.pch new file mode 100644 index 00000000000..f63b2d5b25b --- /dev/null +++ b/clang/test/Modules/Inputs/autolink-sub3.pch @@ -0,0 +1 @@ +@import autolink.sub3; diff --git a/clang/test/Modules/Inputs/module.map b/clang/test/Modules/Inputs/module.map index cf8a298ccee..c0cdf76cdc3 100644 --- a/clang/test/Modules/Inputs/module.map +++ b/clang/test/Modules/Inputs/module.map @@ -166,6 +166,11 @@ module autolink { header "autolink-sub2.h" link framework "autolink_framework" } + + explicit module sub3 { + header "autolink-sub3.h" + link "autolink_from_pch" + } } module weird_objc { diff --git a/clang/test/Modules/autolink.m b/clang/test/Modules/autolink.m index 077aac5374a..883a2f52e50 100644 --- a/clang/test/Modules/autolink.m +++ b/clang/test/Modules/autolink.m @@ -1,6 +1,7 @@ // RUN: rm -rf %t -// RUN: %clang_cc1 -emit-llvm -o - -fmodules-cache-path=%t -fmodules -F %S/Inputs -I %S/Inputs %s | FileCheck %s -// RUN: %clang_cc1 -emit-llvm -fno-autolink -o - -fmodules-cache-path=%t -fmodules -F %S/Inputs -I %S/Inputs %s | FileCheck --check-prefix=CHECK-AUTOLINK-DISABLED %s +// RUN: %clang_cc1 -emit-pch -fmodules-cache-path=%t -fmodules -o %t.pch -I %S/Inputs -x objective-c-header %S/Inputs/autolink-sub3.pch +// RUN: %clang_cc1 -emit-llvm -o - -fmodules-cache-path=%t -fmodules -F %S/Inputs -I %S/Inputs -include-pch %t.pch %s | FileCheck %s +// RUN: %clang_cc1 -emit-llvm -fno-autolink -o - -fmodules-cache-path=%t -fmodules -F %S/Inputs -I %S/Inputs -include-pch %t.pch %s | FileCheck --check-prefix=CHECK-AUTOLINK-DISABLED %s @import autolink.sub2; @@ -29,11 +30,16 @@ int use_no_umbrella() { return no_umbrella_A; } +int use_autolink_sub3() { + return autolink_sub3(); +} + // NOTE: "autolink_sub" is intentionally not linked. // CHECK: !llvm.module.flags = !{!0, !1, !2, !3, !4} // CHECK: !4 = metadata !{i32 6, metadata !"Linker Options", metadata ![[AUTOLINK_OPTIONS:[0-9]+]]} -// CHECK: ![[AUTOLINK_OPTIONS]] = metadata !{metadata ![[AUTOLINK_FRAMEWORK:[0-9]+]], metadata ![[AUTOLINK:[0-9]+]], metadata ![[DEPENDSONMODULE:[0-9]+]], metadata ![[MODULE:[0-9]+]], metadata ![[NOUMBRELLA:[0-9]+]]} +// CHECK: ![[AUTOLINK_OPTIONS]] = metadata !{metadata ![[AUTOLINK_PCH:[0-9]+]], metadata ![[AUTOLINK_FRAMEWORK:[0-9]+]], metadata ![[AUTOLINK:[0-9]+]], metadata ![[DEPENDSONMODULE:[0-9]+]], metadata ![[MODULE:[0-9]+]], metadata ![[NOUMBRELLA:[0-9]+]]} +// CHECK: ![[AUTOLINK_PCH]] = metadata !{metadata !"{{(-l|/DEFAULTLIB:)}}autolink_from_pch{{(\.lib)?}}"} // CHECK: ![[AUTOLINK_FRAMEWORK]] = metadata !{metadata !"-framework", metadata !"autolink_framework"} // CHECK: ![[AUTOLINK]] = metadata !{metadata !"{{(-l|/DEFAULTLIB:)}}autolink{{(\.lib)?}}"} // CHECK: ![[DEPENDSONMODULE]] = metadata !{metadata !"-framework", metadata !"DependsOnModule"} |