]> granicus.if.org Git - clang/commitdiff
In the driver, -fmodules enables modules for C/Objective-C but one
authorDouglas Gregor <dgregor@apple.com>
Wed, 18 Jan 2012 15:19:58 +0000 (15:19 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 18 Jan 2012 15:19:58 +0000 (15:19 +0000)
also needs -fcxx-modules to enable modules for C++/Objective-C++.

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

include/clang/Driver/Options.td
lib/Driver/Tools.cpp
test/Driver/modules.mm [new file with mode: 0644]

index 4aaf1a0a4e71b899032e2afe37ca7b652b1d79a6..876fb577ef6dd7872fed6638cb391a4a0c678f5d 100644 (file)
@@ -296,6 +296,7 @@ def fconstexpr_backtrace_limit_EQ : Joined<"-fconstexpr-backtrace-limit=">,
                                     Group<f_Group>;
 def fcreate_profile : Flag<"-fcreate-profile">, Group<f_Group>;
 def fcxx_exceptions: Flag<"-fcxx-exceptions">, Group<f_Group>;
+def fcxx_modules : Flag <"-fcxx-modules">, Group<f_Group>, Flags<[NoForward]>;
 def fdebug_pass_arguments : Flag<"-fdebug-pass-arguments">, Group<f_Group>;
 def fdebug_pass_structure : Flag<"-fdebug-pass-structure">, Group<f_Group>;
 def fdiagnostics_fixit_info : Flag<"-fdiagnostics-fixit-info">, Group<f_clang_Group>;
@@ -401,6 +402,7 @@ def fno_color_diagnostics : Flag<"-fno-color-diagnostics">, Group<f_Group>;
 def fno_common : Flag<"-fno-common">, Group<f_Group>;
 def fno_constant_cfstrings : Flag<"-fno-constant-cfstrings">, Group<f_Group>;
 def fno_cxx_exceptions: Flag<"-fno-cxx-exceptions">, Group<f_Group>;
+def fno_cxx_modules : Flag <"-fno-cxx-modules">, Group<f_Group>, Flags<[NoForward]>;
 def fno_diagnostics_fixit_info : Flag<"-fno-diagnostics-fixit-info">, Group<f_Group>;
 def fno_diagnostics_show_name : Flag<"-fno-diagnostics-show-name">, Group<f_Group>;
 def fno_diagnostics_show_option : Flag<"-fno-diagnostics-show-option">, Group<f_Group>;
index 39868c82366c160f168afa4c94717061761b5d86..9c50ae54eecc44898f4f51ce0cf5a53658b3cd96 100644 (file)
@@ -2029,8 +2029,16 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
       CmdArgs.push_back("-fblocks-runtime-optional");
   }
 
-  if (Args.hasFlag(options::OPT_fmodules, options::OPT_fno_modules, false))
-    CmdArgs.push_back("-fmodules");
+  // -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.
+  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))
+      CmdArgs.push_back("-fmodules");
+  }
 
   // -faccess-control is default.
   if (Args.hasFlag(options::OPT_fno_access_control,
diff --git a/test/Driver/modules.mm b/test/Driver/modules.mm
new file mode 100644 (file)
index 0000000..b2948c4
--- /dev/null
@@ -0,0 +1,6 @@
+// RUN: %clang -fmodules -### %s 2>&1 | FileCheck -check-prefix=CHECK-NO-MODULES %s
+// RUN: %clang -fcxx-modules -### %s 2>&1 | FileCheck -check-prefix=CHECK-NO-MODULES %s
+// CHECK-NO-MODULES-NOT: -fmodules
+
+// RUN: %clang -fcxx-modules -fmodules -### %s 2>&1 | FileCheck -check-prefix=CHECK-HAS-MODULES %s
+// CHECK-HAS-MODULES: -fmodules