Hi doug.gregor,
This patch adds an option to disable module loading. The intent is that the
module maps are all still interpreted, but the AST files are not read or
written.
The intent is to enable header inclusion testing when merged with the module
private header patch.
This patch is incomplete, as it does not provide any documentation. The intent
is to get feedback on the direction.
http://llvm-reviews.chandlerc.com/D963
Files:
lib/Parse/Parser.cpp
lib/Frontend/CompilerInvocation.cpp
lib/Sema/SemaCodeComplete.cpp
lib/Lex/PPDirectives.cpp
lib/Lex/Preprocessor.cpp
test/Modules/noload.cpp
test/Modules/Inputs/private0/common.h
test/Modules/Inputs/private1/private1.h
test/Modules/Inputs/private1/module.map
test/Modules/Inputs/private1/public1.h
test/Modules/Inputs/private2/module.map
test/Modules/Inputs/private2/private2.h
test/Modules/Inputs/private2/public2.h
include/clang/Driver/Options.td
include/clang/Basic/LangOptions.def
include/clang/Basic/DiagnosticCommonKinds.td
Index: lib/Parse/Parser.cpp
===================================================================
--- lib/Parse/Parser.cpp
+++ lib/Parse/Parser.cpp
@@ -1891,7 +1891,11 @@
return DeclGroupPtrTy();
}
- DeclResult Import = Actions.ActOnModuleImport(AtLoc, ImportLoc, Path);
+ DeclResult Import;
+ if (getLangOpts().Modules_noload)
+ Diags.Report(Path[0].second, diag::err_module_load_off) << Path[0].first;
+ else
+ Import = Actions.ActOnModuleImport(AtLoc, ImportLoc, Path);
ExpectAndConsumeSemi(diag::err_module_expected_semi);
if (Import.isInvalid())
return DeclGroupPtrTy();
Index: lib/Frontend/CompilerInvocation.cpp
===================================================================
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1237,6 +1237,7 @@
Opts.Blocks = Args.hasArg(OPT_fblocks);
Opts.BlocksRuntimeOptional = Args.hasArg(OPT_fblocks_runtime_optional);
Opts.Modules = Args.hasArg(OPT_fmodules);
+ Opts.Modules_noload = Args.hasArg(OPT_fmodules_noload);
Opts.CharIsSigned = !Args.hasArg(OPT_fno_signed_char);
Opts.WChar = Opts.CPlusPlus && !Args.hasArg(OPT_fno_wchar);
Opts.ShortWChar = Args.hasArg(OPT_fshort_wchar);
Index: lib/Sema/SemaCodeComplete.cpp
===================================================================
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -3188,7 +3188,7 @@
? CXAvailability_Available
: CXAvailability_NotAvailable));
}
- } else {
+ } else if (!getLangOpts().Modules_noload) {
// Load the named module.
Module *Mod = PP.getModuleLoader().loadModule(ImportLoc, Path,
Module::AllVisible,
Index: lib/Lex/PPDirectives.cpp
===================================================================
--- lib/Lex/PPDirectives.cpp
+++ lib/Lex/PPDirectives.cpp
@@ -1410,7 +1410,7 @@
}
}
- if (!SuggestedModule) {
+ if (!SuggestedModule || getLangOpts().Modules_noload) {
// Notify the callback object that we've seen an inclusion directive.
Callbacks->InclusionDirective(HashLoc, IncludeTok, Filename, isAngled,
FilenameRange, File,
@@ -1446,7 +1446,7 @@
// If we are supposed to import a module rather than including the header,
// do so now.
- if (SuggestedModule) {
+ if (SuggestedModule && !getLangOpts().Modules_noload) {
// Compute the module access path corresponding to this module.
// FIXME: Should we have a second loadModule() overload to avoid this
// extra lookup step?
@@ -1545,7 +1545,7 @@
}
}
- if (Callbacks && SuggestedModule) {
+ if (Callbacks && SuggestedModule && !getLangOpts().Modules_noload) {
// We didn't notify the callback object that we've seen an inclusion
// directive before. Now that we are parsing the include normally and not
// turning it to a module import, notify the callback object.
Index: lib/Lex/Preprocessor.cpp
===================================================================
--- lib/Lex/Preprocessor.cpp
+++ lib/Lex/Preprocessor.cpp
@@ -734,7 +734,7 @@
}
// If we have a non-empty module path, load the named module.
- if (!ModuleImportPath.empty()) {
+ if (!ModuleImportPath.empty() && !getLangOpts().Modules_noload) {
Module *Imported = TheModuleLoader.loadModule(ModuleImportLoc,
ModuleImportPath,
Module::MacrosVisible,
Index: test/Modules/noload.cpp
===================================================================
--- test/Modules/noload.cpp
+++ test/Modules/noload.cpp
@@ -0,0 +1,15 @@
+// RUN: rm -rf %t/NOLOAD
+// RUN: mkdir -p %t/NOLOAD
+// RUN: chmod -rwx %t/NOLOAD
+// RUN: %clang_cc1 -x objective-c -fmodules-cache-path=%t/NOLOAD -fmodules -fmodules-noload -I %S/Inputs/private0 -I %S/Inputs/private1 -I %S/Inputs/private2 %s -verify
+
+#include "common.h"
+@import libPrivate1; // expected-error {{module loading is off}}
+#include "private1.h"
+#include "public2.h"
+#include "private2.h"
+
+struct use_this1 client_variable1;
+struct use_this2 client_variable2;
+struct mitts_off1 client_variable3;
+struct mitts_off2 client_variable4;
Index: test/Modules/Inputs/private0/common.h
===================================================================
--- test/Modules/Inputs/private0/common.h
+++ test/Modules/Inputs/private0/common.h
@@ -0,0 +1,6 @@
+#ifndef COMMON_H
+#define COMMON_H
+
+typedef int common;
+
+#endif
Index: test/Modules/Inputs/private1/private1.h
===================================================================
--- test/Modules/Inputs/private1/private1.h
+++ test/Modules/Inputs/private1/private1.h
@@ -0,0 +1,9 @@
+#ifndef PRIVATE1_H
+#define PRIVATE1_H
+
+#include "common.h"
+
+struct mitts_off1 { common field; };
+struct mitts_off1 hidden_variable1;
+
+#endif
Index: test/Modules/Inputs/private1/module.map
===================================================================
--- test/Modules/Inputs/private1/module.map
+++ test/Modules/Inputs/private1/module.map
@@ -0,0 +1,4 @@
+module libPrivate1 {
+ header "public1.h"
+ private header "private1.h"
+}
Index: test/Modules/Inputs/private1/public1.h
===================================================================
--- test/Modules/Inputs/private1/public1.h
+++ test/Modules/Inputs/private1/public1.h
@@ -0,0 +1,9 @@
+#ifndef PUBLIC1_H
+#define PUBLIC1_H
+
+#include "private1.h"
+
+struct use_this1 { struct mitts_off1 field; };
+struct use_this1 public_variable1;
+
+#endif
Index: test/Modules/Inputs/private2/module.map
===================================================================
--- test/Modules/Inputs/private2/module.map
+++ test/Modules/Inputs/private2/module.map
@@ -0,0 +1,4 @@
+module libPrivate2 {
+ header "public2.h"
+ private header "private2.h"
+}
Index: test/Modules/Inputs/private2/private2.h
===================================================================
--- test/Modules/Inputs/private2/private2.h
+++ test/Modules/Inputs/private2/private2.h
@@ -0,0 +1,9 @@
+#ifndef PRIVATE2_H
+#define PRIVATE2_H
+
+#include "common.h"
+
+struct mitts_off2 { common field; };
+struct mitts_off2 hidden_variable2;
+
+#endif
Index: test/Modules/Inputs/private2/public2.h
===================================================================
--- test/Modules/Inputs/private2/public2.h
+++ test/Modules/Inputs/private2/public2.h
@@ -0,0 +1,9 @@
+#ifndef PUBLIC2_H
+#define PUBLIC2_H
+
+#include "private2.h"
+
+struct use_this2 { struct mitts_off2 field; };
+struct use_this2 public_variable2;
+
+#endif
Index: include/clang/Driver/Options.td
===================================================================
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -517,6 +517,8 @@
HelpText<"Specify the interval (in seconds) after which a module file will be considered unused">;
def fmodules : Flag <["-"], "fmodules">, Group<f_Group>, Flags<[NoForward,CC1Option]>,
HelpText<"Enable the 'modules' language feature">;
+def fmodules_noload : Flag <["-"], "fmodules-noload">, Group<f_Group>, Flags<[NoForward,CC1Option]>,
+ HelpText<"Disable the loading of 'modules'">;
def fmodules_ignore_macro : Joined<["-"], "fmodules-ignore-macro=">, Group<f_Group>, Flags<[CC1Option]>,
HelpText<"Ignore the definition of the given macro when building and loading modules">;
def fretain_comments_from_system_headers : Flag<["-"], "fretain-comments-from-system-headers">, Group<f_Group>, Flags<[CC1Option]>;
@@ -573,6 +575,7 @@
def fno_merge_all_constants : Flag<["-"], "fno-merge-all-constants">, Group<f_Group>,
Flags<[CC1Option]>, HelpText<"Disallow merging of constants">;
def fno_modules : Flag <["-"], "fno-modules">, Group<f_Group>, Flags<[NoForward]>;
+def fno_modules_noload : Flag <["-"], "fno-modules-noload">, Group<f_Group>, Flags<[NoForward]>;
def fno_ms_extensions : Flag<["-"], "fno-ms-extensions">, Group<f_Group>;
def fno_ms_compatibility : Flag<["-"], "fno-ms-compatibility">, Group<f_Group>;
def fno_delayed_template_parsing : Flag<["-"], "fno-delayed-template-parsing">, Group<f_Group>;
Index: include/clang/Basic/LangOptions.def
===================================================================
--- include/clang/Basic/LangOptions.def
+++ include/clang/Basic/LangOptions.def
@@ -93,6 +93,7 @@
LANGOPT(MathErrno , 1, 1, "errno support for math functions")
BENIGN_LANGOPT(HeinousExtensions , 1, 0, "Extensions that we really don't like and may be ripped out at any time")
LANGOPT(Modules , 1, 0, "modules extension to C")
+LANGOPT(Modules_noload , 1, 0, "disable loading of modules")
LANGOPT(Optimize , 1, 0, "__OPTIMIZE__ predefined macro")
LANGOPT(OptimizeSize , 1, 0, "__OPTIMIZE_SIZE__ predefined macro")
LANGOPT(Static , 1, 0, "__STATIC__ predefined macro (as opposed to __DYNAMIC__)")
Index: include/clang/Basic/DiagnosticCommonKinds.td
===================================================================
--- include/clang/Basic/DiagnosticCommonKinds.td
+++ include/clang/Basic/DiagnosticCommonKinds.td
@@ -78,6 +78,7 @@
"only functions can have deleted definitions">;
def err_module_not_found : Error<"module '%0' not found">, DefaultFatal;
def err_module_not_built : Error<"could not build module '%0'">, DefaultFatal;
+def err_module_load_off : Error<"module loading is off '%0'">, DefaultFatal;
def err_module_cycle : Error<"cyclic dependency in module '%0': %1">,
DefaultFatal;
def note_pragma_entered_here : Note<"#pragma entered here">;
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits