From c60437fb89fee2bd595887ae5346938b62c53a71 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 16 Jan 2013 01:23:41 +0000 Subject: [PATCH] Add -fmodules-autolink/-fno-modules-autolink (defaults to on) so that users can explicitly enable/disable modules autolinking. llvm-svn: 172592 --- clang/include/clang/Driver/Options.td | 4 ++++ clang/include/clang/Frontend/CodeGenOptions.def | 2 ++ clang/lib/CodeGen/CodeGenModule.cpp | 5 ++++- clang/lib/Driver/Tools.cpp | 14 +++++++++++++- clang/lib/Frontend/CompilerInvocation.cpp | 1 + clang/test/Driver/modules.m | 6 ++++++ clang/test/Modules/autolink.m | 2 +- 7 files changed, 31 insertions(+), 3 deletions(-) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 1b80849..2d8b17f 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -485,6 +485,10 @@ def fmodule_cache_path : Separate<["-"], "fmodule-cache-path">, Group, HelpText<"Specify the module cache path">; def fmodules : Flag <["-"], "fmodules">, Group, Flags<[NoForward,CC1Option]>, HelpText<"Enable the 'modules' language feature">; +def fmodules_autolink : Flag <["-"], "fmodules-autolink">, Group, Flags<[NoForward,CC1Option]>, + HelpText<"Enable autolinking of the libraries for imported modules">; +def fno_modules_autolink : Flag <["-"], "fno-modules-autolink">, Group, + HelpText<"Disable autolinking of the libraries for imported modules">; def fretain_comments_from_system_headers : Flag<["-"], "fretain-comments-from-system-headers">, Group, Flags<[CC1Option]>; def fmudflapth : Flag<["-"], "fmudflapth">, Group; diff --git a/clang/include/clang/Frontend/CodeGenOptions.def b/clang/include/clang/Frontend/CodeGenOptions.def index 97551279..5e87dab 100644 --- a/clang/include/clang/Frontend/CodeGenOptions.def +++ b/clang/include/clang/Frontend/CodeGenOptions.def @@ -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) diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index b1bdc0f..38f457a 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -173,7 +173,10 @@ void CodeGenModule::Release() { EmitCtorList(GlobalDtors, "llvm.global_dtors"); EmitGlobalAnnotations(); EmitLLVMUsed(); - EmitModuleLinkOptions(); + + if (CodeGenOpts.ModulesAutolink) { + EmitModuleLinkOptions(); + } SimplifyPersonality(); diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index 9ef3469..547d45c 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -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. diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 20def5e..e810a22 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -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); diff --git a/clang/test/Driver/modules.m b/clang/test/Driver/modules.m index b93054d..7752e22 100644 --- a/clang/test/Driver/modules.m +++ b/clang/test/Driver/modules.m @@ -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 + diff --git a/clang/test/Modules/autolink.m b/clang/test/Modules/autolink.m index e1a240b..8dce12b 100644 --- a/clang/test/Modules/autolink.m +++ b/clang/test/Modules/autolink.m @@ -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; -- 2.7.4