[PATCH] D75395: [clang][Modules] Add -fsystem-module flag

2020-03-03 Thread Michael Spencer via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG27a3ecee4558: [clang][Modules] Add -fsystem-module flag 
(authored by Bigcheese).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75395/new/

https://reviews.llvm.org/D75395

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Modules/fsystem-module.m


Index: clang/test/Modules/fsystem-module.m
===
--- /dev/null
+++ clang/test/Modules/fsystem-module.m
@@ -0,0 +1,18 @@
+// RUN: rm -rf %t.dir
+// RUN: mkdir %t.dir
+
+// -fsystem-module requires -emit-module
+// RUN: not %clang_cc1 -fsyntax-only -fsystem-module %s 2>&1 | grep 
"-emit-module"
+
+// RUN: not %clang_cc1 -fmodules -I %S/Inputs \
+// RUN:   -emit-module -fmodule-name=warning -pedantic -Werror \
+// RUN:   %S/Inputs/module.map -o %t.dir/warning.pcm
+
+// RUN: %clang_cc1 -fmodules -I %S/Inputs \
+// RUN:   -emit-module -fmodule-name=warning -pedantic -Werror \
+// RUN:   %S/Inputs/module.map -o %t.dir/warning-system.pcm -fsystem-module
+
+// RUN: not %clang_cc1 -fmodules -I %S/Inputs \
+// RUN:   -emit-module -fmodule-name=warning -pedantic -Werror \
+// RUN:   %S/Inputs/module.map -o %t.dir/warning-system.pcm -fsystem-module \
+// RUN:   -Wsystem-headers
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1905,6 +1905,11 @@
   Opts.ModulesEmbedAllFiles = Args.hasArg(OPT_fmodules_embed_all_files);
   Opts.IncludeTimestamps = !Args.hasArg(OPT_fno_pch_timestamp);
   Opts.UseTemporary = !Args.hasArg(OPT_fno_temp_file);
+  Opts.IsSystemModule = Args.hasArg(OPT_fsystem_module);
+
+  if (Opts.ProgramAction != frontend::GenerateModule && Opts.IsSystemModule)
+Diags.Report(diag::err_drv_argument_only_allowed_with) << "-fsystem-module"
+   << "-emit-module";
 
   Opts.CodeCompleteOpts.IncludeMacros
 = Args.hasArg(OPT_code_completion_macros);
@@ -2061,12 +2066,16 @@
 DashX = IK;
 }
 
+bool IsSystem = false;
+
 // The -emit-module action implicitly takes a module map.
 if (Opts.ProgramAction == frontend::GenerateModule &&
-IK.getFormat() == InputKind::Source)
+IK.getFormat() == InputKind::Source) {
   IK = IK.withFormat(InputKind::ModuleMap);
+  IsSystem = Opts.IsSystemModule;
+}
 
-Opts.Inputs.emplace_back(std::move(Inputs[i]), IK);
+Opts.Inputs.emplace_back(std::move(Inputs[i]), IK, IsSystem);
   }
 
   return DashX;
Index: clang/include/clang/Frontend/FrontendOptions.h
===
--- clang/include/clang/Frontend/FrontendOptions.h
+++ clang/include/clang/Frontend/FrontendOptions.h
@@ -297,6 +297,9 @@
   /// Should a temporary file be used during compilation.
   unsigned UseTemporary : 1;
 
+  /// When using -emit-module, treat the modulemap as a system module.
+  unsigned IsSystemModule : 1;
+
   CodeCompleteOptions CodeCompleteOpts;
 
   /// Specifies the output format of the AST.
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1445,6 +1445,8 @@
 def fmodule_name : Separate<["-"], "fmodule-name">, Alias;
 def fmodule_implementation_of : Separate<["-"], "fmodule-implementation-of">,
   Flags<[CC1Option]>, Alias;
+def fsystem_module : Flag<["-"], "fsystem-module">, Flags<[CC1Option]>,
+  HelpText<"Build this module as a system module. Only used with 
-emit-module">;
 def fmodule_map_file : Joined<["-"], "fmodule-map-file=">,
   Group, Flags<[DriverOption,CC1Option]>, MetaVarName<"">,
   HelpText<"Load this module map file">;


Index: clang/test/Modules/fsystem-module.m
===
--- /dev/null
+++ clang/test/Modules/fsystem-module.m
@@ -0,0 +1,18 @@
+// RUN: rm -rf %t.dir
+// RUN: mkdir %t.dir
+
+// -fsystem-module requires -emit-module
+// RUN: not %clang_cc1 -fsyntax-only -fsystem-module %s 2>&1 | grep "-emit-module"
+
+// RUN: not %clang_cc1 -fmodules -I %S/Inputs \
+// RUN:   -emit-module -fmodule-name=warning -pedantic -Werror \
+// RUN:   %S/Inputs/module.map -o %t.dir/warning.pcm
+
+// RUN: %clang_cc1 -fmodules -I %S/Inputs \
+// RUN:   -emit-module -fmodule-name=warning -pedantic -Werror \
+// RUN:   %S/Inputs/module.map -o %t.dir/warning-system.pcm -fsystem-module
+
+// RUN: not %clang_cc1 -fmodules -I %S/Inputs \
+// RUN:   -emit-module -fmodule-name=warning -pedantic -Werror \
+// RUN:   %S/Inputs/module.map -o %t.dir/warning-system.pcm -fsystem-module \
+// RUN:   -Wsystem-headers
Index: 

[PATCH] D75395: [clang][Modules] Add -fsystem-module flag

2020-03-03 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno accepted this revision.
bruno added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75395/new/

https://reviews.llvm.org/D75395



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75395: [clang][Modules] Add -fsystem-module flag

2020-03-02 Thread Michael Spencer via Phabricator via cfe-commits
Bigcheese updated this revision to Diff 247755.
Bigcheese added a comment.

Cleaned up the test to not reference unused paths.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75395/new/

https://reviews.llvm.org/D75395

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Modules/fsystem-module.m


Index: clang/test/Modules/fsystem-module.m
===
--- /dev/null
+++ clang/test/Modules/fsystem-module.m
@@ -0,0 +1,18 @@
+// RUN: rm -rf %t.dir
+// RUN: mkdir %t.dir
+
+// -fsystem-module requires -emit-module
+// RUN: not %clang_cc1 -fsyntax-only -fsystem-module %s 2>&1 | grep 
"-emit-module"
+
+// RUN: not %clang_cc1 -fmodules -I %S/Inputs \
+// RUN:   -emit-module -fmodule-name=warning -pedantic -Werror \
+// RUN:   %S/Inputs/module.map -o %t.dir/warning.pcm
+
+// RUN: %clang_cc1 -fmodules -I %S/Inputs \
+// RUN:   -emit-module -fmodule-name=warning -pedantic -Werror \
+// RUN:   %S/Inputs/module.map -o %t.dir/warning-system.pcm -fsystem-module
+
+// RUN: not %clang_cc1 -fmodules -I %S/Inputs \
+// RUN:   -emit-module -fmodule-name=warning -pedantic -Werror \
+// RUN:   %S/Inputs/module.map -o %t.dir/warning-system.pcm -fsystem-module \
+// RUN:   -Wsystem-headers
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1905,6 +1905,11 @@
   Opts.ModulesEmbedAllFiles = Args.hasArg(OPT_fmodules_embed_all_files);
   Opts.IncludeTimestamps = !Args.hasArg(OPT_fno_pch_timestamp);
   Opts.UseTemporary = !Args.hasArg(OPT_fno_temp_file);
+  Opts.IsSystemModule = Args.hasArg(OPT_fsystem_module);
+
+  if (Opts.ProgramAction != frontend::GenerateModule && Opts.IsSystemModule)
+Diags.Report(diag::err_drv_argument_only_allowed_with) << "-fsystem-module"
+   << "-emit-module";
 
   Opts.CodeCompleteOpts.IncludeMacros
 = Args.hasArg(OPT_code_completion_macros);
@@ -2061,12 +2066,16 @@
 DashX = IK;
 }
 
+bool IsSystem = false;
+
 // The -emit-module action implicitly takes a module map.
 if (Opts.ProgramAction == frontend::GenerateModule &&
-IK.getFormat() == InputKind::Source)
+IK.getFormat() == InputKind::Source) {
   IK = IK.withFormat(InputKind::ModuleMap);
+  IsSystem = Opts.IsSystemModule;
+}
 
-Opts.Inputs.emplace_back(std::move(Inputs[i]), IK);
+Opts.Inputs.emplace_back(std::move(Inputs[i]), IK, IsSystem);
   }
 
   return DashX;
Index: clang/include/clang/Frontend/FrontendOptions.h
===
--- clang/include/clang/Frontend/FrontendOptions.h
+++ clang/include/clang/Frontend/FrontendOptions.h
@@ -297,6 +297,9 @@
   /// Should a temporary file be used during compilation.
   unsigned UseTemporary : 1;
 
+  /// When using -emit-module, treat the modulemap as a system module.
+  unsigned IsSystemModule : 1;
+
   CodeCompleteOptions CodeCompleteOpts;
 
   /// Specifies the output format of the AST.
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1445,6 +1445,8 @@
 def fmodule_name : Separate<["-"], "fmodule-name">, Alias;
 def fmodule_implementation_of : Separate<["-"], "fmodule-implementation-of">,
   Flags<[CC1Option]>, Alias;
+def fsystem_module : Flag<["-"], "fsystem-module">, Flags<[CC1Option]>,
+  HelpText<"Build this module as a system module. Only used with 
-emit-module">;
 def fmodule_map_file : Joined<["-"], "fmodule-map-file=">,
   Group, Flags<[DriverOption,CC1Option]>, MetaVarName<"">,
   HelpText<"Load this module map file">;


Index: clang/test/Modules/fsystem-module.m
===
--- /dev/null
+++ clang/test/Modules/fsystem-module.m
@@ -0,0 +1,18 @@
+// RUN: rm -rf %t.dir
+// RUN: mkdir %t.dir
+
+// -fsystem-module requires -emit-module
+// RUN: not %clang_cc1 -fsyntax-only -fsystem-module %s 2>&1 | grep "-emit-module"
+
+// RUN: not %clang_cc1 -fmodules -I %S/Inputs \
+// RUN:   -emit-module -fmodule-name=warning -pedantic -Werror \
+// RUN:   %S/Inputs/module.map -o %t.dir/warning.pcm
+
+// RUN: %clang_cc1 -fmodules -I %S/Inputs \
+// RUN:   -emit-module -fmodule-name=warning -pedantic -Werror \
+// RUN:   %S/Inputs/module.map -o %t.dir/warning-system.pcm -fsystem-module
+
+// RUN: not %clang_cc1 -fmodules -I %S/Inputs \
+// RUN:   -emit-module -fmodule-name=warning -pedantic -Werror \
+// RUN:   %S/Inputs/module.map -o %t.dir/warning-system.pcm -fsystem-module \
+// RUN:   -Wsystem-headers
Index: clang/lib/Frontend/CompilerInvocation.cpp

[PATCH] D75395: [clang][Modules] Add -fsystem-module flag

2020-03-02 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

In D75395#1901859 , @Bigcheese wrote:

> In D75395#1901778 , @dexonsmith 
> wrote:
>
> > > This is used when
> > >  converting an implicit build to an explicit build to match the
> > >  systemness the implicit build would have had for a given module.
> >
> > I had another thought.  What if for the explicitly built "system" modules:
> >
> > - If `-Wsystem-headers` is on, leave them as user modules in the explicit 
> > build.
> > - If `-Wsystem-headers` is off, turn off all diagnostics in the explicit 
> > build.
> >
> >   Does that give the right semantics, or is there something subtly 
> > different?
>
>
> I considered this, but decided against it because I wanted the implicit and 
> explicit builds to be as similar as possible, and reduce the amount of 
> changes made to the original command line. There's a lot of code in Clang 
> dealing with system files, and I'm not 100% sure that -Wno-everything would 
> be equivalent.


Okay, SGTM.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75395/new/

https://reviews.llvm.org/D75395



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75395: [clang][Modules] Add -fsystem-module flag

2020-03-02 Thread Michael Spencer via Phabricator via cfe-commits
Bigcheese added a comment.

In D75395#1901778 , @dexonsmith wrote:

> > This is used when
> >  converting an implicit build to an explicit build to match the
> >  systemness the implicit build would have had for a given module.
>
> I had another thought.  What if for the explicitly built "system" modules:
>
> - If `-Wsystem-headers` is on, leave them as user modules in the explicit 
> build.
> - If `-Wsystem-headers` is off, turn off all diagnostics in the explicit 
> build.
>
>   Does that give the right semantics, or is there something subtly different?


I considered this, but decided against it because I wanted the implicit and 
explicit builds to be as similar as possible, and reduce the amount of changes 
made to the original command line. There's a lot of code in Clang dealing with 
system files, and I'm not 100% sure that -Wno-everything would be equivalent.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75395/new/

https://reviews.llvm.org/D75395



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75395: [clang][Modules] Add -fsystem-module flag

2020-03-02 Thread Michael Spencer via Phabricator via cfe-commits
Bigcheese marked 2 inline comments as done.
Bigcheese added inline comments.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:1912
+Diags.Report(diag::err_drv_argument_only_allowed_with) << "-fsystem-module"
+   << "-emit-module";
 

bruno wrote:
> What happens when we use this with implicit modules? It will just be ignored? 
> If so, users might think that using `-fsystem-module` might help them get rid 
> of some warnings/errors, when in fact it won't.
It's an error unless you also pass -emit-module. If you also have implicit 
modules enabled while explicitly building a module then those modules will be 
treated as normal, but I don't think there's a huge cause for confusion there. 
The only way to use it is when explicitly building a module, so it's clear 
which module it applies to.



Comment at: clang/test/Modules/fsystem-module.m:1
+// RUN: rm -rf %t
+// RUN: rm -rf %t-saved

bruno wrote:
> Is this really needed given you are only using `%t-saved` below?
It's not, that's a leftover from the test I based this one on. I'll clean it up.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75395/new/

https://reviews.llvm.org/D75395



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75395: [clang][Modules] Add -fsystem-module flag

2020-03-02 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added inline comments.



Comment at: clang/include/clang/Driver/Options.td:1448
   Flags<[CC1Option]>, Alias;
+def fsystem_module : Flag<["-"], "fsystem-module">, Flags<[CC1Option]>,
+  HelpText<"Build this module as a system module. Only used with 
-emit-module">;

bruno wrote:
> I wonder if `-isystem-module` wouldn't be better since it's kinda similar 
> with `-isystem` for headers, but for modules.
FWIW, I prefer `-fsystem-module`.  I would expect `-i*` to be modifying search 
paths, and this option does not do that.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75395/new/

https://reviews.llvm.org/D75395



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75395: [clang][Modules] Add -fsystem-module flag

2020-03-02 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

> This is used when
>  converting an implicit build to an explicit build to match the
>  systemness the implicit build would have had for a given module.

I had another thought.  What if for the explicitly built "system" modules:

- If `-Wsystem-headers` is on, leave them as user modules in the explicit build.
- If `-Wsystem-headers` is off, turn off all diagnostics in the explicit build.

Does that give the right semantics, or is there something subtly different?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75395/new/

https://reviews.llvm.org/D75395



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75395: [clang][Modules] Add -fsystem-module flag

2020-03-02 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added a comment.

Hi Michael, thanks for improving this.




Comment at: clang/include/clang/Driver/Options.td:1448
   Flags<[CC1Option]>, Alias;
+def fsystem_module : Flag<["-"], "fsystem-module">, Flags<[CC1Option]>,
+  HelpText<"Build this module as a system module. Only used with 
-emit-module">;

I wonder if `-isystem-module` wouldn't be better since it's kinda similar with 
`-isystem` for headers, but for modules.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:1912
+Diags.Report(diag::err_drv_argument_only_allowed_with) << "-fsystem-module"
+   << "-emit-module";
 

What happens when we use this with implicit modules? It will just be ignored? 
If so, users might think that using `-fsystem-module` might help them get rid 
of some warnings/errors, when in fact it won't.



Comment at: clang/test/Modules/fsystem-module.m:1
+// RUN: rm -rf %t
+// RUN: rm -rf %t-saved

Is this really needed given you are only using `%t-saved` below?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75395/new/

https://reviews.llvm.org/D75395



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75395: [clang][Modules] Add -fsystem-module flag

2020-02-28 Thread Michael Spencer via Phabricator via cfe-commits
Bigcheese created this revision.
Bigcheese added reviewers: rsmith, bruno.
Bigcheese added a project: clang.
Herald added a subscriber: dexonsmith.

The -fsystem-module flag is used when explicitly building a module. It
forces the module to be treated as a system module. This is used when
converting an implicit build to an explicit build to match the
systemness the implicit build would have had for a given module.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75395

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Modules/fsystem-module.m


Index: clang/test/Modules/fsystem-module.m
===
--- /dev/null
+++ clang/test/Modules/fsystem-module.m
@@ -0,0 +1,19 @@
+// RUN: rm -rf %t
+// RUN: rm -rf %t-saved
+// RUN: mkdir %t-saved
+
+// -fsystem-module requires -emit-module
+// RUN: not %clang_cc1 -fsyntax-only -fsystem-module %s 2>&1 | grep 
"-emit-module"
+
+// RUN: not %clang_cc1 -fmodules -I %S/Inputs \
+// RUN:   -emit-module -fmodule-name=warning -pedantic -Werror \
+// RUN:   %S/Inputs/module.map -o %t-saved/warning.pcm
+
+// RUN: %clang_cc1 -fmodules -I %S/Inputs \
+// RUN:   -emit-module -fmodule-name=warning -pedantic -Werror \
+// RUN:   %S/Inputs/module.map -o %t-saved/warning-system.pcm -fsystem-module
+
+// RUN: not %clang_cc1 -fmodules -I %S/Inputs \
+// RUN:   -emit-module -fmodule-name=warning -pedantic -Werror \
+// RUN:   %S/Inputs/module.map -o %t-saved/warning-system.pcm -fsystem-module \
+// RUN:   -Wsystem-headers
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1905,6 +1905,11 @@
   Opts.ModulesEmbedAllFiles = Args.hasArg(OPT_fmodules_embed_all_files);
   Opts.IncludeTimestamps = !Args.hasArg(OPT_fno_pch_timestamp);
   Opts.UseTemporary = !Args.hasArg(OPT_fno_temp_file);
+  Opts.IsSystemModule = Args.hasArg(OPT_fsystem_module);
+
+  if (Opts.ProgramAction != frontend::GenerateModule && Opts.IsSystemModule)
+Diags.Report(diag::err_drv_argument_only_allowed_with) << "-fsystem-module"
+   << "-emit-module";
 
   Opts.CodeCompleteOpts.IncludeMacros
 = Args.hasArg(OPT_code_completion_macros);
@@ -2061,12 +2066,16 @@
 DashX = IK;
 }
 
+bool IsSystem = false;
+
 // The -emit-module action implicitly takes a module map.
 if (Opts.ProgramAction == frontend::GenerateModule &&
-IK.getFormat() == InputKind::Source)
+IK.getFormat() == InputKind::Source) {
   IK = IK.withFormat(InputKind::ModuleMap);
+  IsSystem = Opts.IsSystemModule;
+}
 
-Opts.Inputs.emplace_back(std::move(Inputs[i]), IK);
+Opts.Inputs.emplace_back(std::move(Inputs[i]), IK, IsSystem);
   }
 
   return DashX;
Index: clang/include/clang/Frontend/FrontendOptions.h
===
--- clang/include/clang/Frontend/FrontendOptions.h
+++ clang/include/clang/Frontend/FrontendOptions.h
@@ -297,6 +297,9 @@
   /// Should a temporary file be used during compilation.
   unsigned UseTemporary : 1;
 
+  /// When using -emit-module, treat the modulemap as a system module.
+  unsigned IsSystemModule : 1;
+
   CodeCompleteOptions CodeCompleteOpts;
 
   /// Specifies the output format of the AST.
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1445,6 +1445,8 @@
 def fmodule_name : Separate<["-"], "fmodule-name">, Alias;
 def fmodule_implementation_of : Separate<["-"], "fmodule-implementation-of">,
   Flags<[CC1Option]>, Alias;
+def fsystem_module : Flag<["-"], "fsystem-module">, Flags<[CC1Option]>,
+  HelpText<"Build this module as a system module. Only used with 
-emit-module">;
 def fmodule_map_file : Joined<["-"], "fmodule-map-file=">,
   Group, Flags<[DriverOption,CC1Option]>, MetaVarName<"">,
   HelpText<"Load this module map file">;


Index: clang/test/Modules/fsystem-module.m
===
--- /dev/null
+++ clang/test/Modules/fsystem-module.m
@@ -0,0 +1,19 @@
+// RUN: rm -rf %t
+// RUN: rm -rf %t-saved
+// RUN: mkdir %t-saved
+
+// -fsystem-module requires -emit-module
+// RUN: not %clang_cc1 -fsyntax-only -fsystem-module %s 2>&1 | grep "-emit-module"
+
+// RUN: not %clang_cc1 -fmodules -I %S/Inputs \
+// RUN:   -emit-module -fmodule-name=warning -pedantic -Werror \
+// RUN:   %S/Inputs/module.map -o %t-saved/warning.pcm
+
+// RUN: %clang_cc1 -fmodules -I %S/Inputs \
+// RUN:   -emit-module -fmodule-name=warning -pedantic -Werror \
+// RUN:   %S/Inputs/module.map -o %t-saved/warning-system.pcm -fsystem-module
+
+// RUN: not