This repository was archived by the owner on Nov 1, 2021. It is now read-only.
File tree 4 files changed +41
-4
lines changed
4 files changed +41
-4
lines changed Original file line number Diff line number Diff line change @@ -3951,9 +3951,33 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) {
3951
3951
DI->EmitImportDecl (*Import);
3952
3952
}
3953
3953
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
+ }
3957
3981
break ;
3958
3982
}
3959
3983
Original file line number Diff line number Diff line change @@ -420,6 +420,10 @@ class CodeGenModule : public CodeGenTypeCache {
420
420
// / \brief The complete set of modules that has been imported.
421
421
llvm::SetVector<clang::Module *> ImportedModules;
422
422
423
+ // / \brief The set of modules for which the module initializers
424
+ // / have been emitted.
425
+ llvm::SmallPtrSet<clang::Module *, 16 > EmittedModuleInitializers;
426
+
423
427
// / \brief A vector of metadata strings.
424
428
SmallVector<llvm::Metadata *, 16 > LinkerOptionsMetadata;
425
429
Original file line number Diff line number Diff line change 1
1
module X {
2
- header "X.h"
2
+ module T {
3
+ header "X.h"
4
+ export *
5
+ }
3
6
export *
4
7
}
Original file line number Diff line number Diff line change 1
1
// RUN: rm -rf %t
2
2
// 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
3
4
// CHECK: kSimDeviceIOGetInterface = internal constant {{.*}} bitcast
4
5
6
+ #ifdef IMPORT_TOP
7
+ @import X;
8
+ #else
5
9
#import < X.h>
10
+ #endif
11
+
6
12
void test2 (const NSString *);
7
13
void test () {
8
14
test2 (kSimDeviceIOGetInterface );
You can’t perform that action at this time.
0 commit comments