On Mon, Feb 2, 2015 at 1:56 PM, Ben Langmuir <[email protected]> wrote:
> Author: benlangmuir > Date: Mon Feb 2 15:56:15 2015 > New Revision: 227868 > > URL: http://llvm.org/viewvc/llvm-project?rev=227868&view=rev > Log: > Add cc1 option '-fmodule-feature' to add custom values for 'requires' decls > > This allows clang-based tools to specify custom features that can be > tested by the 'requires' declaration in a module map file. > Hi Ben, It looks like this isn't getting added to the module hash, nor even checked when we pull a module out of the cache. > Modified: > cfe/trunk/include/clang/Basic/LangOptions.h > cfe/trunk/include/clang/Driver/CC1Options.td > cfe/trunk/lib/Basic/Module.cpp > cfe/trunk/lib/Frontend/CompilerInvocation.cpp > cfe/trunk/test/Modules/Inputs/DependsOnModule.framework/module.map > cfe/trunk/test/Modules/requires.m > > Modified: cfe/trunk/include/clang/Basic/LangOptions.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.h?rev=227868&r1=227867&r2=227868&view=diff > > ============================================================================== > --- cfe/trunk/include/clang/Basic/LangOptions.h (original) > +++ cfe/trunk/include/clang/Basic/LangOptions.h Mon Feb 2 15:56:15 2015 > @@ -92,6 +92,10 @@ public: > /// treat this as the CurrentModule. > std::string ImplementationOfModule; > > + /// \brief The names of any features to enable in module 'requires' > decls > + /// in addition to the hard-coded list in Module.cpp and the target > features. > + std::vector<std::string> ModuleFeatures; > + > /// \brief Options for parsing comments. > CommentOptions CommentOpts; > > > Modified: cfe/trunk/include/clang/Driver/CC1Options.td > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=227868&r1=227867&r2=227868&view=diff > > ============================================================================== > --- cfe/trunk/include/clang/Driver/CC1Options.td (original) > +++ cfe/trunk/include/clang/Driver/CC1Options.td Mon Feb 2 15:56:15 2015 > @@ -342,6 +342,9 @@ def fmodule_implementation_of : Separate > def fmodule_map_file_home_is_cwd : Flag<["-"], > "fmodule-map-file-home-is-cwd">, > HelpText<"Use the current working directory as the home directory of " > "module maps specified by -fmodule-map-file=<FILE>">; > +def fmodule_feature : Separate<["-"], "fmodule-feature">, > + MetaVarName<"<feature>">, > + HelpText<"Enable <feature> in module map requires declarations">; > > let Group = Action_Group in { > > > Modified: cfe/trunk/lib/Basic/Module.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Module.cpp?rev=227868&r1=227867&r2=227868&view=diff > > ============================================================================== > --- cfe/trunk/lib/Basic/Module.cpp (original) > +++ cfe/trunk/lib/Basic/Module.cpp Mon Feb 2 15:56:15 2015 > @@ -58,16 +58,21 @@ Module::~Module() { > /// language options has the given feature. > static bool hasFeature(StringRef Feature, const LangOptions &LangOpts, > const TargetInfo &Target) { > - return llvm::StringSwitch<bool>(Feature) > - .Case("altivec", LangOpts.AltiVec) > - .Case("blocks", LangOpts.Blocks) > - .Case("cplusplus", LangOpts.CPlusPlus) > - .Case("cplusplus11", LangOpts.CPlusPlus11) > - .Case("objc", LangOpts.ObjC1) > - .Case("objc_arc", LangOpts.ObjCAutoRefCount) > - .Case("opencl", LangOpts.OpenCL) > - .Case("tls", Target.isTLSSupported()) > - .Default(Target.hasFeature(Feature)); > + bool HasFeature = llvm::StringSwitch<bool>(Feature) > + .Case("altivec", LangOpts.AltiVec) > + .Case("blocks", LangOpts.Blocks) > + .Case("cplusplus", LangOpts.CPlusPlus) > + .Case("cplusplus11", LangOpts.CPlusPlus11) > + .Case("objc", LangOpts.ObjC1) > + .Case("objc_arc", LangOpts.ObjCAutoRefCount) > + .Case("opencl", LangOpts.OpenCL) > + .Case("tls", Target.isTLSSupported()) > + .Default(Target.hasFeature(Feature)); > + if (!HasFeature) > + HasFeature = std::find(LangOpts.ModuleFeatures.begin(), > + LangOpts.ModuleFeatures.end(), > + Feature) != LangOpts.ModuleFeatures.end(); > + return HasFeature; > } > > bool Module::isAvailable(const LangOptions &LangOpts, const TargetInfo > &Target, > > Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=227868&r1=227867&r2=227868&view=diff > > ============================================================================== > --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original) > +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Mon Feb 2 15:56:15 2015 > @@ -1568,6 +1568,7 @@ static void ParseLangArgs(LangOptions &O > Opts.CurrentModule = Args.getLastArgValue(OPT_fmodule_name); > Opts.ImplementationOfModule = > Args.getLastArgValue(OPT_fmodule_implementation_of); > + Opts.ModuleFeatures = Args.getAllArgValues(OPT_fmodule_feature); > Opts.NativeHalfType = Opts.NativeHalfType; > Opts.HalfArgsAndReturns = > Args.hasArg(OPT_fallow_half_arguments_and_returns); > Opts.GNUAsm = !Args.hasArg(OPT_fno_gnu_inline_asm); > > Modified: > cfe/trunk/test/Modules/Inputs/DependsOnModule.framework/module.map > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/DependsOnModule.framework/module.map?rev=227868&r1=227867&r2=227868&view=diff > > ============================================================================== > --- cfe/trunk/test/Modules/Inputs/DependsOnModule.framework/module.map > (original) > +++ cfe/trunk/test/Modules/Inputs/DependsOnModule.framework/module.map Mon > Feb 2 15:56:15 2015 > @@ -16,6 +16,12 @@ framework module DependsOnModule { > requires !objc > header "not_objc.h" > } > + explicit module CustomReq1 { > + requires custom_req1 > + } > + explicit module CustomReq2 { > + requires custom_req2 > + } > > explicit framework module SubFramework { > umbrella header "SubFramework.h" > > Modified: cfe/trunk/test/Modules/requires.m > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/requires.m?rev=227868&r1=227867&r2=227868&view=diff > > ============================================================================== > --- cfe/trunk/test/Modules/requires.m (original) > +++ cfe/trunk/test/Modules/requires.m Mon Feb 2 15:56:15 2015 > @@ -1,6 +1,8 @@ > // RUN: rm -rf %t > -// RUN: %clang_cc1 -Wauto-import -fmodules-cache-path=%t -fmodules -F > %S/Inputs %s -verify > +// RUN: %clang_cc1 -Wauto-import -fmodules-cache-path=%t -fmodules -F > %S/Inputs %s -verify -fmodule-feature custom_req1 > > @import DependsOnModule.CXX; // expected-error{{module > 'DependsOnModule.CXX' requires feature 'cplusplus'}} > @import DependsOnModule.NotCXX; > @import DependsOnModule.NotObjC; // expected-error{{module > 'DependsOnModule.NotObjC' is incompatible with feature 'objc'}} > +@import DependsOnModule.CustomReq1; // OK > +@import DependsOnModule.CustomReq2; // expected-error{{module > 'DependsOnModule.CustomReq2' requires feature 'custom_req2'}} > > > _______________________________________________ > cfe-commits mailing list > [email protected] > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits >
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
