summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp8
-rw-r--r--clang/test/Modules/Inputs/module-impl-with-link/foo.h1
-rw-r--r--clang/test/Modules/Inputs/module-impl-with-link/module.modulemap4
-rw-r--r--clang/test/Modules/module-impl-with-link.c7
4 files changed, 19 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index ab29d2dbb56..36005430ae4 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1243,9 +1243,15 @@ void CodeGenModule::EmitModuleLinkOptions() {
SmallVector<clang::Module *, 16> Stack;
// Seed the stack with imported modules.
- for (Module *M : ImportedModules)
+ for (Module *M : ImportedModules) {
+ // Do not add any link flags when an implementation TU of a module imports
+ // a header of that same module.
+ if (M->getTopLevelModuleName() == getLangOpts().CurrentModule &&
+ !getLangOpts().isCompilingModule())
+ continue;
if (Visited.insert(M).second)
Stack.push_back(M);
+ }
// Find all of the modules to import, making a little effort to prune
// non-leaf modules.
diff --git a/clang/test/Modules/Inputs/module-impl-with-link/foo.h b/clang/test/Modules/Inputs/module-impl-with-link/foo.h
new file mode 100644
index 00000000000..90fe1bcc585
--- /dev/null
+++ b/clang/test/Modules/Inputs/module-impl-with-link/foo.h
@@ -0,0 +1 @@
+//empty
diff --git a/clang/test/Modules/Inputs/module-impl-with-link/module.modulemap b/clang/test/Modules/Inputs/module-impl-with-link/module.modulemap
new file mode 100644
index 00000000000..b85f8b6fe80
--- /dev/null
+++ b/clang/test/Modules/Inputs/module-impl-with-link/module.modulemap
@@ -0,0 +1,4 @@
+module Clib {
+ header "foo.h"
+ link "Clib"
+}
diff --git a/clang/test/Modules/module-impl-with-link.c b/clang/test/Modules/module-impl-with-link.c
new file mode 100644
index 00000000000..5e5ca83aafd
--- /dev/null
+++ b/clang/test/Modules/module-impl-with-link.c
@@ -0,0 +1,7 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -fmodule-name=Clib %s -I %S/Inputs/module-impl-with-link -emit-llvm -o -
+#include "foo.h"
+// CHECK: !{{[0-9]+}} = !{i32 6, !"Linker Options", ![[LINK_OPTIONS:[0-9]+]]}
+// Make sure we don't generate linker option for module Clib since this TU is
+// an implementation of Clib.
+// CHECK: ![[LINK_OPTIONS]] = !{}
OpenPOWER on IntegriCloud