Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 6b826f1

Browse files
committed
Module: emit initializers in submodules when importing the parent module.
When importing the parent module, module initializers in submodules should be emitted. rdar://28740482 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@284263 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 8cddf5a commit 6b826f1

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

Diff for: lib/CodeGen/CodeGenModule.cpp

+27-3
Original file line numberDiff line numberDiff line change
@@ -3951,9 +3951,33 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) {
39513951
DI->EmitImportDecl(*Import);
39523952
}
39533953

3954-
// Emit the module initializers.
3955-
for (auto *D : Context.getModuleInitializers(Import->getImportedModule()))
3956-
EmitTopLevelDecl(D);
3954+
// Find all of the submodules and emit the module initializers.
3955+
llvm::SmallPtrSet<clang::Module *, 16> Visited;
3956+
SmallVector<clang::Module *, 16> Stack;
3957+
Visited.insert(Import->getImportedModule());
3958+
Stack.push_back(Import->getImportedModule());
3959+
3960+
while (!Stack.empty()) {
3961+
clang::Module *Mod = Stack.pop_back_val();
3962+
if (!EmittedModuleInitializers.insert(Mod).second)
3963+
continue;
3964+
3965+
for (auto *D : Context.getModuleInitializers(Mod))
3966+
EmitTopLevelDecl(D);
3967+
3968+
// Visit the submodules of this module.
3969+
for (clang::Module::submodule_iterator Sub = Mod->submodule_begin(),
3970+
SubEnd = Mod->submodule_end();
3971+
Sub != SubEnd; ++Sub) {
3972+
// Skip explicit children; they need to be explicitly imported to emit
3973+
// the initializers.
3974+
if ((*Sub)->IsExplicit)
3975+
continue;
3976+
3977+
if (Visited.insert(*Sub).second)
3978+
Stack.push_back(*Sub);
3979+
}
3980+
}
39573981
break;
39583982
}
39593983

Diff for: lib/CodeGen/CodeGenModule.h

+4
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,10 @@ class CodeGenModule : public CodeGenTypeCache {
420420
/// \brief The complete set of modules that has been imported.
421421
llvm::SetVector<clang::Module *> ImportedModules;
422422

423+
/// \brief The set of modules for which the module initializers
424+
/// have been emitted.
425+
llvm::SmallPtrSet<clang::Module *, 16> EmittedModuleInitializers;
426+
423427
/// \brief A vector of metadata strings.
424428
SmallVector<llvm::Metadata *, 16> LinkerOptionsMetadata;
425429

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
module X {
2-
header "X.h"
2+
module T {
3+
header "X.h"
4+
export *
5+
}
36
export *
47
}

Diff for: test/Modules/objc-initializer.m

+6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
// RUN: rm -rf %t
22
// RUN: %clang_cc1 -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -I %S/Inputs/objc-initializer %s -emit-llvm -o - -fobjc-arc | FileCheck %s
3+
// RUN: %clang_cc1 -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -I %S/Inputs/objc-initializer %s -emit-llvm -o - -fobjc-arc -DIMPORT_TOP | FileCheck %s
34
// CHECK: kSimDeviceIOGetInterface = internal constant {{.*}} bitcast
45

6+
#ifdef IMPORT_TOP
7+
@import X;
8+
#else
59
#import <X.h>
10+
#endif
11+
612
void test2(const NSString*);
713
void test() {
814
test2(kSimDeviceIOGetInterface);

0 commit comments

Comments
 (0)