]> granicus.if.org Git - clang/commitdiff
Add -fmodules-autolink/-fno-modules-autolink (defaults to on) so that
authorDouglas Gregor <dgregor@apple.com>
Wed, 16 Jan 2013 01:23:41 +0000 (01:23 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 16 Jan 2013 01:23:41 +0000 (01:23 +0000)
users can explicitly enable/disable modules autolinking.

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

include/clang/Driver/Options.td
include/clang/Frontend/CodeGenOptions.def
lib/CodeGen/CodeGenModule.cpp
lib/Driver/Tools.cpp
lib/Frontend/CompilerInvocation.cpp
test/Driver/modules.m
test/Modules/autolink.m

index 1b8084927f4b0a57af43b909a79d4b9f3523b2ec..2d8b17f0e1400e2c06e33ee96561ef0065fcb69d 100644 (file)
@@ -485,6 +485,10 @@ def fmodule_cache_path : Separate<["-"], "fmodule-cache-path">, Group<i_Group>,
   HelpText<"Specify the module cache path">;
 def fmodules : Flag <["-"], "fmodules">, Group<f_Group>, Flags<[NoForward,CC1Option]>,
   HelpText<"Enable the 'modules' language feature">;
+def fmodules_autolink : Flag <["-"], "fmodules-autolink">, Group<f_Group>, Flags<[NoForward,CC1Option]>,
+  HelpText<"Enable autolinking of the libraries for imported modules">;
+def fno_modules_autolink : Flag <["-"], "fno-modules-autolink">, Group<f_Group>,
+  HelpText<"Disable autolinking of the libraries for imported modules">;
 def fretain_comments_from_system_headers : Flag<["-"], "fretain-comments-from-system-headers">, Group<f_Group>, Flags<[CC1Option]>;
 
 def fmudflapth : Flag<["-"], "fmudflapth">, Group<f_Group>;
index 97551279c48e916bcf828b7b27b6326aa0a48c7b..5e87dabbf39cf71f1fdc2c53eb35455a14c0d47a 100644 (file)
@@ -111,6 +111,8 @@ VALUE_CODEGENOPT(StackAlignment    , 32, 0) ///< Overrides default stack
 CODEGENOPT(DebugColumnInfo, 1, 0) ///< Whether or not to use column information
                                   ///< in debug info.
 
+CODEGENOPT(ModulesAutolink, 1, 0) ///< Whether to auto-link imported modules
+
 /// The user specified number of registers to be used for integral arguments,
 /// or 0 if unspecified.
 VALUE_CODEGENOPT(NumRegisterParameters, 32, 0)
index b1bdc0fb7a263816a56cdf0e4f316eb8a5d12612..38f457ada69a8ccef98ffa0165ae5292d39f24c4 100644 (file)
@@ -173,7 +173,10 @@ void CodeGenModule::Release() {
   EmitCtorList(GlobalDtors, "llvm.global_dtors");
   EmitGlobalAnnotations();
   EmitLLVMUsed();
-  EmitModuleLinkOptions();
+
+  if (CodeGenOpts.ModulesAutolink) {
+    EmitModuleLinkOptions();
+  }
 
   SimplifyPersonality();
 
index 9ef346906b1edf50758af142df487192bbd8ecac..547d45c2d8f67151324b90efbc16a7ae356dcd84 100644 (file)
@@ -2622,12 +2622,24 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
   // -fmodules enables modules (off by default). However, for C++/Objective-C++,
   // users must also pass -fcxx-modules. The latter flag will disappear once the
   // modules implementation is solid for C++/Objective-C++ programs as well.
+  bool HaveModules = false;
   if (Args.hasFlag(options::OPT_fmodules, options::OPT_fno_modules, false)) {
     bool AllowedInCXX = Args.hasFlag(options::OPT_fcxx_modules, 
                                      options::OPT_fno_cxx_modules, 
                                      false);
-    if (AllowedInCXX || !types::isCXX(InputType))
+    if (AllowedInCXX || !types::isCXX(InputType)) {
       CmdArgs.push_back("-fmodules");
+      HaveModules = true;
+    }
+  }
+
+  // -fmodules-autolink (on by default when modules is enabled) automatically
+  // links against libraries for imported modules.
+  if (HaveModules &&
+      Args.hasFlag(options::OPT_fmodules_autolink,
+                   options::OPT_fno_modules_autolink,
+                   true)) {
+    CmdArgs.push_back("-fmodules-autolink");
   }
 
   // -faccess-control is default.
index 20def5e480c95240167a0143e52e84ff541e2bad..e810a22dce0652d2a391d0043fa10e6471793f44 100644 (file)
@@ -332,6 +332,7 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
   }
   Opts.DebugColumnInfo = Args.hasArg(OPT_dwarf_column_info);
 
+  Opts.ModulesAutolink = Args.hasArg(OPT_fmodules_autolink);
   Opts.DisableLLVMOpts = Args.hasArg(OPT_disable_llvm_optzns);
   Opts.DisableRedZone = Args.hasArg(OPT_disable_red_zone);
   Opts.ForbidGuardVariables = Args.hasArg(OPT_fforbid_guard_variables);
index b93054dbf87f5e2b50a418354e64164169ead9f5..7752e22b7eb3953e0668769c19aa744997cc1644 100644 (file)
@@ -4,3 +4,9 @@
 // RUN: %clang -fmodules -fno-modules -fmodules -### %s 2>&1 | FileCheck -check-prefix=CHECK-HAS-MODULES %s
 // CHECK-HAS-MODULES: -fmodules
 
+// RUN: %clang -fmodules -fno-modules -fmodules -### %s 2>&1 | FileCheck -check-prefix=CHECK-HAS-AUTOLINK %s
+// CHECK-HAS-AUTOLINK: -fmodules-autolink
+
+// RUN: %clang -fmodules -fno-modules -fno-modules-autolink -fmodules -### %s 2>&1 | FileCheck -check-prefix=CHECK-NO-AUTOLINK %s
+// CHECK-NO-AUTOLINK-NOT: -fmodules-autolink
+
index e1a240bd5b1e8fee79f7e322a65c240910b6ac24..8dce12b21bddb3534a9112889e6bbb8532d15be3 100644 (file)
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -emit-llvm -o - -fmodule-cache-path %t -fmodules -F %S/Inputs -I %S/Inputs %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -o - -fmodule-cache-path %t -fmodules -fmodules-autolink -F %S/Inputs -I %S/Inputs %s | FileCheck %s
 
 @import autolink.sub2;