]> granicus.if.org Git - clang/commitdiff
Module: Do not add any link flags when an implementation TU of a module imports
authorManman Ren <manman.ren@gmail.com>
Wed, 11 Jan 2017 18:47:38 +0000 (18:47 +0000)
committerManman Ren <manman.ren@gmail.com>
Wed, 11 Jan 2017 18:47:38 +0000 (18:47 +0000)
a header of that same module.

This fixes a regression caused by r280409.
rdar://problem/29930553

This is an updated version for r291628 (which was reverted in r291688).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@291689 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenModule.cpp
test/Modules/Inputs/module-impl-with-link/foo.h [new file with mode: 0644]
test/Modules/Inputs/module-impl-with-link/module.modulemap [new file with mode: 0644]
test/Modules/module-impl-with-link.c [new file with mode: 0644]

index ab29d2dbb566b5db512762b0b6fd061e849e742e..36005430ae4c3c9640bc6a75083b27b75c83a8b5 100644 (file)
@@ -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/test/Modules/Inputs/module-impl-with-link/foo.h b/test/Modules/Inputs/module-impl-with-link/foo.h
new file mode 100644 (file)
index 0000000..90fe1bc
--- /dev/null
@@ -0,0 +1 @@
+//empty
diff --git a/test/Modules/Inputs/module-impl-with-link/module.modulemap b/test/Modules/Inputs/module-impl-with-link/module.modulemap
new file mode 100644 (file)
index 0000000..b85f8b6
--- /dev/null
@@ -0,0 +1,4 @@
+module Clib {
+  header "foo.h"
+  link "Clib"
+}
diff --git a/test/Modules/module-impl-with-link.c b/test/Modules/module-impl-with-link.c
new file mode 100644 (file)
index 0000000..5e5ca83
--- /dev/null
@@ -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]] = !{}