<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">To be clear, my patch does not involve decluse, so not quite the same. Also (by way of review), I think this patch doesn’t handle umbrella directories correctly, since it only looks for known headers.<div><br></div><div>Ben</div><div><br><div><div>On Apr 14, 2014, at 11:42 AM, Richard Smith <<a href="mailto:richard@metafoo.co.uk">richard@metafoo.co.uk</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">Why is this a -f option rather than a diagnostic? Why is it coupled to -fmodules-decluse? See also Ben Langmuir's patch that does the same thing for framework modules (also, oddly, with a language option).</div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Apr 11, 2014 at 4:47 AM, Daniel Jasper <span dir="ltr"><<a href="mailto:djasper@google.com" target="_blank">djasper@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: djasper<br>
Date: Fri Apr 11 06:47:45 2014<br>
New Revision: 206027<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=206027&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=206027&view=rev</a><br>
Log:<br>
Add -fmodules-strict-decluse to check that all headers are in modules<br>
<br>
Review: <a href="http://reviews.llvm.org/D3335" target="_blank">http://reviews.llvm.org/D3335</a><br>
<br>
Added:<br>
cfe/trunk/test/Modules/strict-decluse.cpp<br>
Modified:<br>
cfe/trunk/include/clang/Basic/LangOptions.def<br>
cfe/trunk/include/clang/Driver/Options.td<br>
cfe/trunk/lib/Driver/Tools.cpp<br>
cfe/trunk/lib/Frontend/CompilerInvocation.cpp<br>
cfe/trunk/lib/Lex/ModuleMap.cpp<br>
<br>
Modified: cfe/trunk/include/clang/Basic/LangOptions.def<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.def?rev=206027&r1=206026&r2=206027&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.def?rev=206027&r1=206026&r2=206027&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Basic/LangOptions.def (original)<br>
+++ cfe/trunk/include/clang/Basic/LangOptions.def Fri Apr 11 06:47:45 2014<br>
@@ -96,6 +96,7 @@ LANGOPT(MathErrno , 1, 1, "errno<br>
BENIGN_LANGOPT(HeinousExtensions , 1, 0, "Extensions that we really don't like and may be ripped out at any time")<br>
LANGOPT(Modules , 1, 0, "modules extension to C")<br>
LANGOPT(ModulesDeclUse , 1, 0, "require declaration of module uses")<br>
+LANGOPT(ModulesStrictDeclUse, 1, 0, "require declaration of module uses and all headers to be in modules")<br>
LANGOPT(Optimize , 1, 0, "__OPTIMIZE__ predefined macro")<br>
LANGOPT(OptimizeSize , 1, 0, "__OPTIMIZE_SIZE__ predefined macro")<br>
LANGOPT(Static , 1, 0, "__STATIC__ predefined macro (as opposed to __DYNAMIC__)")<br>
<br>
Modified: cfe/trunk/include/clang/Driver/Options.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=206027&r1=206026&r2=206027&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=206027&r1=206026&r2=206027&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Driver/Options.td (original)<br>
+++ cfe/trunk/include/clang/Driver/Options.td Fri Apr 11 06:47:45 2014<br>
@@ -607,6 +607,9 @@ def fmodules_ignore_macro : Joined<["-"]<br>
def fmodules_decluse : Flag <["-"], "fmodules-decluse">, Group<f_Group>,<br>
Flags<[DriverOption,CC1Option]>,<br>
HelpText<"Require declaration of modules used within a module">;<br>
+def fmodules_strict_decluse : Flag <["-"], "fmodules-strict-decluse">, Group<f_Group>,<br>
+ Flags<[DriverOption,CC1Option]>,<br>
+ HelpText<"Like -fmodules-decluse but requires all headers to be in modules">;<br>
def fretain_comments_from_system_headers : Flag<["-"], "fretain-comments-from-system-headers">, Group<f_Group>, Flags<[CC1Option]>;<br>
<br>
def fmudflapth : Flag<["-"], "fmudflapth">, Group<f_Group>;<br>
@@ -666,6 +669,8 @@ def fno_module_maps : Flag <["-"], "fno-<br>
Flags<[DriverOption]>;<br>
def fno_modules_decluse : Flag <["-"], "fno-modules-decluse">, Group<f_Group>,<br>
Flags<[DriverOption]>;<br>
+def fno_modules_strict_decluse : Flag <["-"], "fno-strict-modules-decluse">, Group<f_Group>,<br>
+ Flags<[DriverOption]>;<br>
def fno_ms_extensions : Flag<["-"], "fno-ms-extensions">, Group<f_Group>;<br>
def fno_ms_compatibility : Flag<["-"], "fno-ms-compatibility">, Group<f_Group>;<br>
def fno_delayed_template_parsing : Flag<["-"], "fno-delayed-template-parsing">, Group<f_Group>;<br>
<br>
Modified: cfe/trunk/lib/Driver/Tools.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=206027&r1=206026&r2=206027&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=206027&r1=206026&r2=206027&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Driver/Tools.cpp (original)<br>
+++ cfe/trunk/lib/Driver/Tools.cpp Fri Apr 11 06:47:45 2014<br>
@@ -3469,6 +3469,14 @@ void Clang::ConstructJob(Compilation &C,<br>
CmdArgs.push_back("-fmodules-decluse");<br>
}<br>
<br>
+ // -fmodules-strict-decluse is like -fmodule-decluse, but also checks that<br>
+ // all #included headers are part of modules.<br>
+ if (Args.hasFlag(options::OPT_fmodules_strict_decluse,<br>
+ options::OPT_fno_modules_strict_decluse,<br>
+ false)) {<br>
+ CmdArgs.push_back("-fmodules-strict-decluse");<br>
+ }<br>
+<br>
// -fmodule-name specifies the module that is currently being built (or<br>
// used for header checking by -fmodule-maps).<br>
if (Arg *A = Args.getLastArg(options::OPT_fmodule_name)) {<br>
<br>
Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=206027&r1=206026&r2=206027&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=206027&r1=206026&r2=206027&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)<br>
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Fri Apr 11 06:47:45 2014<br>
@@ -1343,7 +1343,9 @@ static void ParseLangArgs(LangOptions &O<br>
Opts.Blocks = Args.hasArg(OPT_fblocks);<br>
Opts.BlocksRuntimeOptional = Args.hasArg(OPT_fblocks_runtime_optional);<br>
Opts.Modules = Args.hasArg(OPT_fmodules);<br>
- Opts.ModulesDeclUse = Args.hasArg(OPT_fmodules_decluse);<br>
+ Opts.ModulesStrictDeclUse = Args.hasArg(OPT_fmodules_strict_decluse);<br>
+ Opts.ModulesDeclUse =<br>
+ Args.hasArg(OPT_fmodules_decluse) || Opts.ModulesStrictDeclUse;<br>
Opts.CharIsSigned = Opts.OpenCL || !Args.hasArg(OPT_fno_signed_char);<br>
Opts.WChar = Opts.CPlusPlus && !Args.hasArg(OPT_fno_wchar);<br>
Opts.ShortWChar = Args.hasFlag(OPT_fshort_wchar, OPT_fno_short_wchar, false);<br>
<br>
Modified: cfe/trunk/lib/Lex/ModuleMap.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/ModuleMap.cpp?rev=206027&r1=206026&r2=206027&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/ModuleMap.cpp?rev=206027&r1=206026&r2=206027&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Lex/ModuleMap.cpp (original)<br>
+++ cfe/trunk/lib/Lex/ModuleMap.cpp Fri Apr 11 06:47:45 2014<br>
@@ -243,8 +243,12 @@ void ModuleMap::diagnoseHeaderInclusion(<br>
resolveUses(RequestingModule, /*Complain=*/false);<br>
<br>
HeadersMap::iterator Known = findKnownHeader(File);<br>
- if (Known == Headers.end())<br>
+ if (Known == Headers.end()) {<br>
+ if (LangOpts.ModulesStrictDeclUse)<br>
+ Diags.Report(FilenameLoc, diag::error_undeclared_use_of_module)<br>
+ << RequestingModule->getFullModuleName() << Filename;<br>
return;<br>
+ }<br>
<br>
Module *Private = NULL;<br>
Module *NotUsed = NULL;<br>
<br>
Added: cfe/trunk/test/Modules/strict-decluse.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/strict-decluse.cpp?rev=206027&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/strict-decluse.cpp?rev=206027&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/Modules/strict-decluse.cpp (added)<br>
+++ cfe/trunk/test/Modules/strict-decluse.cpp Fri Apr 11 06:47:45 2014<br>
@@ -0,0 +1,9 @@<br>
+// RUN: rm -rf %t<br>
+// RUN: %clang_cc1 -fmodule-maps -fmodules-cache-path=%t -fmodules-strict-decluse -fmodule-name=XG -I %S/Inputs/declare-use %s -verify<br>
+<br>
+#include "g.h"<br>
+#include "e.h"<br>
+#include "f.h" // expected-error {{module XG does not depend on a module exporting 'f.h'}}<br>
+#include "i.h" // expected-error {{module XG does not depend on a module exporting 'i.h'}}<br>
+<br>
+const int g2 = g1 + e + f + aux_i;<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>
</blockquote></div><br></div></body></html>