<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Thanks! That also fixed it for me.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">-Silviu<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> metafoo@gmail.com [mailto:metafoo@gmail.com]
<b>On Behalf Of </b>Richard Smith<br>
<b>Sent:</b> 28 April 2016 19:33<br>
<b>To:</b> Silviu Baranga<br>
<b>Cc:</b> nd; cfe-dev@lists.llvm.org Developers<br>
<b>Subject:</b> Re: [cfe-dev] r267802 - [modules] When diagnosing a missing module import, suggest adding a #include if<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">Thanks, it turns out this was a pre-existing bug that was exposed by my change. Should be fixed in r267914.<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On Thu, Apr 28, 2016 at 4:04 AM, Silviu Baranga via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:<o:p></o:p></p>
<p class="MsoNormal">Hi Richard,<br>
<br>
I believe this commit is causing the failure at<br>
<a href="http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/12319/steps/check-clang%20msan/logs/stdio" target="_blank">http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/12319/steps/check-clang%20msan/logs/stdio</a><br>
<br>
I can also see this failure on my box. Reverting it solves the problem for me.<br>
<br>
Thanks,<br>
Silviu<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal"><br>
> -----Original Message-----<br>
> From: cfe-commits [mailto:<a href="mailto:cfe-commits-bounces@lists.llvm.org">cfe-commits-bounces@lists.llvm.org</a>] On Behalf<br>
> Of Richard Smith via cfe-commits<br>
> Sent: 27 April 2016 22:57<br>
> To: <a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
> Subject: r267802 - [modules] When diagnosing a missing module import,<br>
> suggest adding a #include if<br>
><br>
> Author: rsmith<br>
> Date: Wed Apr 27 16:57:05 2016<br>
> New Revision: 267802<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=267802&view=rev" target="_blank">
http://llvm.org/viewvc/llvm-project?rev=267802&view=rev</a><br>
> Log:<br>
> [modules] When diagnosing a missing module import, suggest adding a<br>
> #include if the current language doesn't have an import syntax and we can<br>
> figure out a suitable file to include.<br>
><br>
> Added:<br>
>     cfe/trunk/test/Modules/Inputs/suggest-include/<br>
>     cfe/trunk/test/Modules/Inputs/suggest-include/empty.h<br>
>     cfe/trunk/test/Modules/Inputs/suggest-include/module.modulemap<br>
>     cfe/trunk/test/Modules/Inputs/suggest-include/private1.h<br>
>     cfe/trunk/test/Modules/Inputs/suggest-include/private2.h<br>
>     cfe/trunk/test/Modules/Inputs/suggest-include/private3.h<br>
>     cfe/trunk/test/Modules/Inputs/suggest-include/textual1.h<br>
>     cfe/trunk/test/Modules/Inputs/suggest-include/textual2.h<br>
>     cfe/trunk/test/Modules/Inputs/suggest-include/textual3.h<br>
>     cfe/trunk/test/Modules/Inputs/suggest-include/textual4.h<br>
>     cfe/trunk/test/Modules/Inputs/suggest-include/textual5.h<br>
>     cfe/trunk/test/Modules/Inputs/suggest-include/useprivate1.h<br>
>     cfe/trunk/test/Modules/Inputs/suggest-include/useprivate3.h<br>
>     cfe/trunk/test/Modules/Inputs/suggest-include/usetextual1.h<br>
>     cfe/trunk/test/Modules/Inputs/suggest-include/usetextual2.h<br>
>     cfe/trunk/test/Modules/Inputs/suggest-include/usetextual3.h<br>
>     cfe/trunk/test/Modules/Inputs/suggest-include/usetextual4.h<br>
>     cfe/trunk/test/Modules/Inputs/suggest-include/usetextual5.h<br>
>     cfe/trunk/test/Modules/suggest-include.cpp<br>
> Modified:<br>
>     cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td<br>
>     cfe/trunk/include/clang/Lex/HeaderSearch.h<br>
>     cfe/trunk/include/clang/Lex/ModuleMap.h<br>
>     cfe/trunk/include/clang/Lex/Preprocessor.h<br>
>     cfe/trunk/lib/Lex/HeaderSearch.cpp<br>
>     cfe/trunk/lib/Lex/ModuleMap.cpp<br>
>     cfe/trunk/lib/Lex/PPDirectives.cpp<br>
>     cfe/trunk/lib/Sema/SemaLookup.cpp<br>
><br>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td<br>
> URL: <a href="http://llvm.org/viewvc/llvm-" target="_blank">http://llvm.org/viewvc/llvm-</a><br>
> project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=267802&<br>
> r1=267801&r2=267802&view=diff<br>
> ==========================================================<br>
> ====================<br>
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)<br>
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Apr 27<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal">> +++ 16:57:05 2016<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal">> @@ -8262,6 +8262,10 @@ def err_module_private_local_class : Err  def<br>
> err_module_unimported_use : Error<<br>
>    "%select{declaration|definition|default argument}0 of %1 must be<br>
> imported "<br>
>    "from module '%2' before it is required">;<br>
> +def err_module_unimported_use_header : Error<<br>
> +  "missing '#include %3'; "<br>
> +  "%select{declaration|definition|default argument}0 of %1 must be<br>
> imported "<br>
> +  "from module '%2' before it is required">;<br>
>  def err_module_unimported_use_multiple : Error<<br>
>    "%select{declaration|definition|default argument}0 of %1 must be<br>
> imported "<br>
>    "from one of the following modules before it is required:%2">;<br>
><br>
> Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-" target="_blank">http://llvm.org/viewvc/llvm-</a><br>
> project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=267802&r1=26780<br>
> 1&r2=267802&view=diff<br>
> ==========================================================<br>
> ====================<br>
> --- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)<br>
> +++ cfe/trunk/include/clang/Lex/HeaderSearch.h Wed Apr 27 16:57:05 2016<br>
> @@ -634,13 +634,18 @@ public:<br>
>    /// \brief Retrieve a uniqued framework name.<br>
>    StringRef getUniqueFrameworkName(StringRef Framework);<br>
><br>
> +  /// \brief Suggest a path by which the specified file could be found,<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal">> + for  /// use in diagnostics to suggest a #include.<br>
> +  ///<br>
> +  /// \param IsSystem If non-null, filled in to indicate whether the suggested<br>
> +  ///        path is relative to a system header directory.<br>
> +  std::string suggestPathToFileForDiagnostics(const FileEntry *File,<br>
> +                                              bool *IsSystem =<br>
> + nullptr);<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal">> +<br>
>    void PrintStats();<br>
><br>
>    size_t getTotalMemory() const;<br>
><br>
> -  static std::string NormalizeDashIncludePath(StringRef File,<br>
> -                                              FileManager &FileMgr);<br>
> -<br>
>  private:<br>
>    /// \brief Describes what happened when we tried to load a module map<br>
> file.<br>
>    enum LoadModuleMapResult {<br>
><br>
> Modified: cfe/trunk/include/clang/Lex/ModuleMap.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-" target="_blank">http://llvm.org/viewvc/llvm-</a><br>
> project/cfe/trunk/include/clang/Lex/ModuleMap.h?rev=267802&r1=267801<br>
> &r2=267802&view=diff<br>
> ==========================================================<br>
> ====================<br>
> --- cfe/trunk/include/clang/Lex/ModuleMap.h (original)<br>
> +++ cfe/trunk/include/clang/Lex/ModuleMap.h Wed Apr 27 16:57:05 2016<br>
> @@ -130,6 +130,12 @@ public:<br>
>        return getModule()->isAvailable();<br>
>      }<br>
><br>
> +    /// \brief Whether this header is accessible from the specified module.<br>
> +    bool isAccessibleFrom(Module *M) const {<br>
> +      return !(getRole() & PrivateHeader) ||<br>
> +             (M && M->getTopLevelModule() == getModule()-<br>
> >getTopLevelModule());<br>
> +    }<br>
> +<br>
>      // \brief Whether this known header is valid (i.e., it has an<br>
>      // associated module).<br>
>      explicit operator bool() const {<br>
><br>
> Modified: cfe/trunk/include/clang/Lex/Preprocessor.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-" target="_blank">http://llvm.org/viewvc/llvm-</a><br>
> project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=267802&r1=267801<br>
> &r2=267802&view=diff<br>
> ==========================================================<br>
> ====================<br>
> --- cfe/trunk/include/clang/Lex/Preprocessor.h (original)<br>
> +++ cfe/trunk/include/clang/Lex/Preprocessor.h Wed Apr 27 16:57:05 2016<br>
> @@ -1891,6 +1891,19 @@ public:<br>
>    /// directly or indirectly.<br>
>    Module *getModuleContainingLocation(SourceLocation Loc);<br>
><br>
> +  /// \brief We want to produce a diagnostic at location IncLoc<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal">> + concerning a  /// missing module import.<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal">> +  ///<br>
> +  /// \param IncLoc The location at which the missing import was detected.<br>
> +  /// \param MLoc A location within the desired module at which some<br>
> desired<br>
> +  ///        effect occurred (eg, where a desired entity was declared).<br>
> +  ///<br>
> +  /// \return A file that can be #included to import a module containing<br>
> MLoc.<br>
> +  ///         Null if no such file could be determined or if a #include is not<br>
> +  ///         appropriate.<br>
> +  const FileEntry<br>
> *getModuleHeaderToIncludeForDiagnostics(SourceLocation IncLoc,<br>
> +<br>
> + SourceLocation MLoc);<br>
> +<br>
>  private:<br>
>    // Macro handling.<br>
>    void HandleDefineDirective(Token &Tok, bool<br>
> ImmediatelyAfterTopLevelIfndef);<br>
><br>
> Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-" target="_blank">http://llvm.org/viewvc/llvm-</a><br>
> project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=267802&r1=267801&r2=26<br>
> 7802&view=diff<br>
> ==========================================================<br>
> ====================<br>
> --- cfe/trunk/lib/Lex/HeaderSearch.cpp (original)<br>
> +++ cfe/trunk/lib/Lex/HeaderSearch.cpp Wed Apr 27 16:57:05 2016<br>
> @@ -1419,3 +1419,54 @@ void HeaderSearch::loadSubdirectoryModul<br>
><br>
>    SearchDir.setSearchedAllModuleMaps(true);<br>
>  }<br>
> +<br>
> +std::string HeaderSearch::suggestPathToFileForDiagnostics(const FileEntry<br>
> *File,<br>
> +                                                          bool<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal">> +*IsSystem) {<br>
> +  // FIXME: We assume that the path name currently cached in the<br>
> +FileEntry is<br>
> +  // the most appropriate one for this analysis (and that it's spelled<br>
> +the same<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal">> +  // way as the corresponding header search path).<br>
> +  const char *Name = File->getName();<br>
> +<br>
> +  unsigned BestPrefixLength = 0;<br>
> +  unsigned BestSearchDir;<br>
> +<br>
> +  for (unsigned I = 0; I != SearchDirs.size(); ++I) {<br>
> +    // FIXME: Support this search within frameworks and header maps.<br>
> +    if (!SearchDirs[I].isNormalDir())<br>
> +      continue;<br>
> +<br>
> +    const char *Dir = SearchDirs[I].getDir()->getName();<br>
> +    for (auto NI = llvm::sys::path::begin(Name),<br>
> +              NE = llvm::sys::path::end(Name),<br>
> +              DI = llvm::sys::path::begin(Dir),<br>
> +              DE = llvm::sys::path::end(Dir);<br>
> +         /*termination condition in loop*/; ++NI, ++DI) {<br>
> +      // '.' components in Name are ignored.<br>
> +      while (NI != NE && *NI == ".")<br>
> +        ++NI;<br>
> +      if (NI == NE)<br>
> +        break;<br>
> +<br>
> +      // '.' components in Dir are ignored.<br>
> +      while (DI != DE && *DI == ".")<br>
> +        ++DI;<br>
> +      if (DI == DE) {<br>
> +        // Dir is a prefix of Name, up to '.' components and choice of path<br>
> +        // separators.<br>
> +        unsigned PrefixLength = NI - llvm::sys::path::begin(Name);<br>
> +        if (PrefixLength > BestPrefixLength) {<br>
> +          BestPrefixLength = PrefixLength;<br>
> +          BestSearchDir = I;<br>
> +        }<br>
> +        break;<br>
> +      }<br>
> +<br>
> +      if (*NI != *DI)<br>
> +        break;<br>
> +    }<br>
> +  }<br>
> +<br>
> +  if (IsSystem)<br>
> +    *IsSystem = BestPrefixLength ? BestSearchDir >= SystemDirIdx :<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal">> +false;<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal">> +  return Name + BestPrefixLength;<br>
> +}<br>
><br>
> Modified: cfe/trunk/lib/Lex/ModuleMap.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-" target="_blank">http://llvm.org/viewvc/llvm-</a><br>
> project/cfe/trunk/lib/Lex/ModuleMap.cpp?rev=267802&r1=267801&r2=2678<br>
> 02&view=diff<br>
> ==========================================================<br>
> ====================<br>
> --- cfe/trunk/lib/Lex/ModuleMap.cpp (original)<br>
> +++ cfe/trunk/lib/Lex/ModuleMap.cpp Wed Apr 27 16:57:05 2016<br>
> @@ -209,29 +209,25 @@ ModuleMap::findHeaderInUmbrellaDirs(cons<br>
><br>
>  static bool violatesPrivateInclude(Module *RequestingModule,<br>
>                                     const FileEntry *IncFileEnt,<br>
> -                                   ModuleMap::ModuleHeaderRole Role,<br>
> -                                   Module *RequestedModule) {<br>
> -  bool IsPrivateRole = Role & ModuleMap::PrivateHeader;<br>
> +                                   ModuleMap::KnownHeader Header) {<br>
>  #ifndef NDEBUG<br>
> -  if (IsPrivateRole) {<br>
> +  if (Header.getRole() & ModuleMap::PrivateHeader) {<br>
>      // Check for consistency between the module header role<br>
>      // as obtained from the lookup and as obtained from the module.<br>
>      // This check is not cheap, so enable it only for debugging.<br>
>      bool IsPrivate = false;<br>
>      SmallVectorImpl<Module::Header> *HeaderList[] = {<br>
> -        &RequestedModule->Headers[Module::HK_Private],<br>
> -        &RequestedModule->Headers[Module::HK_PrivateTextual]};<br>
> +        &Header.getModule()->Headers[Module::HK_Private],<br>
> +        &Header.getModule()->Headers[Module::HK_PrivateTextual]};<br>
>      for (auto *Hs : HeaderList)<br>
>        IsPrivate |=<br>
>            std::find_if(Hs->begin(), Hs->end(), [&](const Module::Header &H) {<br>
>              return H.Entry == IncFileEnt;<br>
>            }) != Hs->end();<br>
> -    assert((!IsPrivateRole || IsPrivate) && "inconsistent headers and roles");<br>
> +    assert(IsPrivate && "inconsistent headers and roles");<br>
>    }<br>
>  #endif<br>
> -  return IsPrivateRole && (!RequestingModule ||<br>
> -                           RequestedModule->getTopLevelModule() !=<br>
> -                               RequestingModule->getTopLevelModule());<br>
> +  return !Header.isAccessibleFrom(RequestingModule);<br>
>  }<br>
><br>
>  static Module *getTopLevelOrNull(Module *M) { @@ -259,8 +255,7 @@<br>
> void ModuleMap::diagnoseHeaderInclusion(<br>
>    if (Known != Headers.end()) {<br>
>      for (const KnownHeader &Header : Known->second) {<br>
>        // Remember private headers for later printing of a diagnostic.<br>
> -      if (violatesPrivateInclude(RequestingModule, File, Header.getRole(),<br>
> -                                 Header.getModule())) {<br>
> +      if (violatesPrivateInclude(RequestingModule, File, Header)) {<br>
>          Private = Header.getModule();<br>
>          continue;<br>
>        }<br>
><br>
> Modified: cfe/trunk/lib/Lex/PPDirectives.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-" target="_blank">http://llvm.org/viewvc/llvm-</a><br>
> project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=267802&r1=267801&r2=2678<br>
> 02&view=diff<br>
> ==========================================================<br>
> ====================<br>
> --- cfe/trunk/lib/Lex/PPDirectives.cpp (original)<br>
> +++ cfe/trunk/lib/Lex/PPDirectives.cpp Wed Apr 27 16:57:05 2016<br>
> @@ -597,6 +597,62 @@ Module *Preprocessor::getModuleContainin<br>
>        FullSourceLoc(Loc, SourceMgr));<br>
>  }<br>
><br>
> +const FileEntry *<br>
> +Preprocessor::getModuleHeaderToIncludeForDiagnostics(SourceLocation<br>
> IncLoc,<br>
> +                                                     SourceLocation<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal">> +Loc) {<br>
> +  // If we have a module import syntax, we shouldn't include a header<br>
> +to<br>
> +  // make a particular module visible.<br>
> +  if (getLangOpts().ObjC2)<br>
> +    return nullptr;<br>
> +<br>
> +  // Figure out which module we'd want to import.<br>
> +  Module *M = getModuleContainingLocation(Loc);  if (!M)<br>
> +    return nullptr;<br>
> +<br>
> +  Module *TopM = M->getTopLevelModule();  Module *IncM =<br>
> + getModuleForLocation(IncLoc);<br>
> +<br>
> +  // Walk up through the include stack, looking through textual headers<br>
> + of M  // until we hit a non-textual header that we can #include. (We<br>
> + assume textual  // headers of a module with non-textual headers aren't<br>
> + meant to be used to  // import entities from the module.)  auto &SM =<br>
> + getSourceManager();  while (!Loc.isInvalid() && !SM.isInMainFile(Loc))<br>
> + {<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal">> +    auto ID = SM.getFileID(SM.getExpansionLoc(Loc));<br>
> +    auto *FE = SM.getFileEntryForID(ID);<br>
> +<br>
> +    bool InTextualHeader = false;<br>
> +    for (auto Header :<br>
> HeaderInfo.getModuleMap().findAllModulesForHeader(FE)) {<br>
> +      if (!Header.getModule()->isSubModuleOf(TopM))<br>
> +        continue;<br>
> +<br>
> +      if (!(Header.getRole() & ModuleMap::TextualHeader)) {<br>
> +        // If this is an accessible, non-textual header of M's top-level module<br>
> +        // that transitively includes the given location and makes the<br>
> +        // corresponding module visible, this is the thing to #include.<br>
> +        if (Header.isAccessibleFrom(IncM))<br>
> +          return FE;<br>
> +<br>
> +        // It's in a private header; we can't #include it.<br>
> +        // FIXME: If there's a public header in some module that re-exports it,<br>
> +        // then we could suggest including that, but it's not clear that's the<br>
> +        // expected way to make this entity visible.<br>
> +        continue;<br>
> +      }<br>
> +<br>
> +      InTextualHeader = true;<br>
> +    }<br>
> +<br>
> +    if (!InTextualHeader)<br>
> +      break;<br>
> +<br>
> +    Loc = SM.getIncludeLoc(ID);<br>
> +  }<br>
> +<br>
> +  return nullptr;<br>
> +}<br>
> +<br>
>  const FileEntry *Preprocessor::LookupFile(<br>
>      SourceLocation FilenameLoc,<br>
>      StringRef Filename,<br>
><br>
> Modified: cfe/trunk/lib/Sema/SemaLookup.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-" target="_blank">http://llvm.org/viewvc/llvm-</a><br>
> project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=267802&r1=267801&r2=2<br>
> 67802&view=diff<br>
> ==========================================================<br>
> ====================<br>
> --- cfe/trunk/lib/Sema/SemaLookup.cpp (original)<br>
> +++ cfe/trunk/lib/Sema/SemaLookup.cpp Wed Apr 27 16:57:05 2016<br>
> @@ -4929,6 +4929,16 @@ void Sema::diagnoseMissingImport(SourceL<br>
>                          Recover);<br>
>  }<br>
><br>
> +/// \brief Get a "quoted.h" or <angled.h> include path to use in a<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal">> +diagnostic /// suggesting the addition of a #include of the specified file.<br>
> +static std::string getIncludeStringForHeader(Preprocessor &PP,<br>
> +                                             const FileEntry *E) {<br>
> +  bool IsSystem;<br>
> +  auto Path =<br>
> +      PP.getHeaderSearchInfo().suggestPathToFileForDiagnostics(E,<br>
> +&IsSystem);<br>
> +  return (IsSystem ? '<' : '"') + Path + (IsSystem ? '>' : '"'); }<br>
> +<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal">>  void Sema::diagnoseMissingImport(SourceLocation UseLoc, NamedDecl<br>
> *Decl,<br>
>                                   SourceLocation DeclLoc,<br>
>                                   ArrayRef<Module *> Modules, @@ -4949,6 +4959,16 @@<br>
> void Sema::diagnoseMissingImport(SourceL<br>
><br>
>      Diag(UseLoc, diag::err_module_unimported_use_multiple)<br>
>        << (int)MIK << Decl << ModuleList;<br>
> +  } else if (const FileEntry *E =<br>
> +                 PP.getModuleHeaderToIncludeForDiagnostics(UseLoc, DeclLoc)) {<br>
> +    // The right way to make the declaration visible is to include a header;<br>
> +    // suggest doing so.<br>
> +    //<br>
> +    // FIXME: Find a smart place to suggest inserting a #include, and add<br>
> +    // a FixItHint there.<br>
> +    Diag(UseLoc, diag::err_module_unimported_use_header)<br>
> +      << (int)MIK << Decl << Modules[0]->getFullModuleName()<br>
> +      << getIncludeStringForHeader(PP, E);<br>
>    } else {<br>
>      Diag(UseLoc, diag::err_module_unimported_use)<br>
>        << (int)MIK << Decl << Modules[0]->getFullModuleName();<br>
><br>
> Added: cfe/trunk/test/Modules/Inputs/suggest-include/empty.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-" target="_blank">http://llvm.org/viewvc/llvm-</a><br>
> project/cfe/trunk/test/Modules/Inputs/suggest-<br>
> include/empty.h?rev=267802&view=auto<br>
> ==========================================================<br>
> ====================<br>
>     (empty)<br>
><br>
> Added: cfe/trunk/test/Modules/Inputs/suggest-<br>
> include/module.modulemap<br>
> URL: <a href="http://llvm.org/viewvc/llvm-" target="_blank">http://llvm.org/viewvc/llvm-</a><br>
> project/cfe/trunk/test/Modules/Inputs/suggest-<br>
> include/module.modulemap?rev=267802&view=auto<br>
> ==========================================================<br>
> ====================<br>
> --- cfe/trunk/test/Modules/Inputs/suggest-include/module.modulemap<br>
> (added)<br>
> +++ cfe/trunk/test/Modules/Inputs/suggest-include/module.modulemap<br>
> Wed<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal">> +++ Apr 27 16:57:05 2016<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal">> @@ -0,0 +1,22 @@<br>
> +module X {<br>
> +  module Empty { header "empty.h" }<br>
> +<br>
> +  exclude header "textual1.h"<br>
> +  textual header "textual2.h"<br>
> +  textual header "textual3.h"<br>
> +<br>
> +  module A { header "usetextual1.h" }<br>
> +  module B { header "usetextual2.h" }<br>
> +  module C { header "usetextual3.h" }<br>
> +  module D { header "usetextual4.h" }<br>
> +  module E { header "usetextual5.h" }<br>
> +<br>
> +  module P { private header "private1.h" }<br>
> +  module Q { private header "private2.h" }<br>
> +  module R { private header "private3.h" }<br>
> +  module S { header "useprivate1.h" export * }<br>
> +  module T { header "useprivate3.h" }<br>
> +}<br>
> +<br>
> +module Other { textual header "textual4.h" }<br>
> +<br>
><br>
> Added: cfe/trunk/test/Modules/Inputs/suggest-include/private1.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-" target="_blank">http://llvm.org/viewvc/llvm-</a><br>
> project/cfe/trunk/test/Modules/Inputs/suggest-<br>
> include/private1.h?rev=267802&view=auto<br>
> ==========================================================<br>
> ====================<br>
> --- cfe/trunk/test/Modules/Inputs/suggest-include/private1.h (added)<br>
> +++ cfe/trunk/test/Modules/Inputs/suggest-include/private1.h Wed Apr 27<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal">> +++ 16:57:05 2016<br>
> @@ -0,0 +1 @@<br>
> +extern int private1;<br>
><br>
> Added: cfe/trunk/test/Modules/Inputs/suggest-include/private2.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-" target="_blank">http://llvm.org/viewvc/llvm-</a><br>
> project/cfe/trunk/test/Modules/Inputs/suggest-<br>
> include/private2.h?rev=267802&view=auto<br>
> ==========================================================<br>
> ====================<br>
> --- cfe/trunk/test/Modules/Inputs/suggest-include/private2.h (added)<br>
> +++ cfe/trunk/test/Modules/Inputs/suggest-include/private2.h Wed Apr 27<br>
> +++ 16:57:05 2016<br>
> @@ -0,0 +1 @@<br>
> +extern int private2;<br>
><br>
> Added: cfe/trunk/test/Modules/Inputs/suggest-include/private3.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-" target="_blank">http://llvm.org/viewvc/llvm-</a><br>
> project/cfe/trunk/test/Modules/Inputs/suggest-<br>
> include/private3.h?rev=267802&view=auto<br>
> ==========================================================<br>
> ====================<br>
> --- cfe/trunk/test/Modules/Inputs/suggest-include/private3.h (added)<br>
> +++ cfe/trunk/test/Modules/Inputs/suggest-include/private3.h Wed Apr 27<br>
> +++ 16:57:05 2016<br>
> @@ -0,0 +1 @@<br>
> +extern int private3;<br>
><br>
> Added: cfe/trunk/test/Modules/Inputs/suggest-include/textual1.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-" target="_blank">http://llvm.org/viewvc/llvm-</a><br>
> project/cfe/trunk/test/Modules/Inputs/suggest-<br>
> include/textual1.h?rev=267802&view=auto<br>
> ==========================================================<br>
> ====================<br>
> --- cfe/trunk/test/Modules/Inputs/suggest-include/textual1.h (added)<br>
> +++ cfe/trunk/test/Modules/Inputs/suggest-include/textual1.h Wed Apr 27<br>
> +++ 16:57:05 2016<br>
> @@ -0,0 +1 @@<br>
> +#define FOO(X) X<br>
><br>
> Added: cfe/trunk/test/Modules/Inputs/suggest-include/textual2.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-" target="_blank">http://llvm.org/viewvc/llvm-</a><br>
> project/cfe/trunk/test/Modules/Inputs/suggest-<br>
> include/textual2.h?rev=267802&view=auto<br>
> ==========================================================<br>
> ====================<br>
> --- cfe/trunk/test/Modules/Inputs/suggest-include/textual2.h (added)<br>
> +++ cfe/trunk/test/Modules/Inputs/suggest-include/textual2.h Wed Apr 27<br>
> +++ 16:57:05 2016<br>
> @@ -0,0 +1 @@<br>
> +EXPAND_MACRO<br>
><br>
> Added: cfe/trunk/test/Modules/Inputs/suggest-include/textual3.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-" target="_blank">http://llvm.org/viewvc/llvm-</a><br>
> project/cfe/trunk/test/Modules/Inputs/suggest-<br>
> include/textual3.h?rev=267802&view=auto<br>
> ==========================================================<br>
> ====================<br>
> --- cfe/trunk/test/Modules/Inputs/suggest-include/textual3.h (added)<br>
> +++ cfe/trunk/test/Modules/Inputs/suggest-include/textual3.h Wed Apr 27<br>
> +++ 16:57:05 2016<br>
> @@ -0,0 +1 @@<br>
> +extern int textual3;<br>
><br>
> Added: cfe/trunk/test/Modules/Inputs/suggest-include/textual4.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-" target="_blank">http://llvm.org/viewvc/llvm-</a><br>
> project/cfe/trunk/test/Modules/Inputs/suggest-<br>
> include/textual4.h?rev=267802&view=auto<br>
> ==========================================================<br>
> ====================<br>
> --- cfe/trunk/test/Modules/Inputs/suggest-include/textual4.h (added)<br>
> +++ cfe/trunk/test/Modules/Inputs/suggest-include/textual4.h Wed Apr 27<br>
> +++ 16:57:05 2016<br>
> @@ -0,0 +1 @@<br>
> +extern int textual4;<br>
><br>
> Added: cfe/trunk/test/Modules/Inputs/suggest-include/textual5.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-" target="_blank">http://llvm.org/viewvc/llvm-</a><br>
> project/cfe/trunk/test/Modules/Inputs/suggest-<br>
> include/textual5.h?rev=267802&view=auto<br>
> ==========================================================<br>
> ====================<br>
> --- cfe/trunk/test/Modules/Inputs/suggest-include/textual5.h (added)<br>
> +++ cfe/trunk/test/Modules/Inputs/suggest-include/textual5.h Wed Apr 27<br>
> +++ 16:57:05 2016<br>
> @@ -0,0 +1 @@<br>
> +extern int textual5;<br>
><br>
> Added: cfe/trunk/test/Modules/Inputs/suggest-include/useprivate1.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-" target="_blank">http://llvm.org/viewvc/llvm-</a><br>
> project/cfe/trunk/test/Modules/Inputs/suggest-<br>
> include/useprivate1.h?rev=267802&view=auto<br>
> ==========================================================<br>
> ====================<br>
> --- cfe/trunk/test/Modules/Inputs/suggest-include/useprivate1.h (added)<br>
> +++ cfe/trunk/test/Modules/Inputs/suggest-include/useprivate1.h Wed Apr<br>
> +++ 27 16:57:05 2016<br>
> @@ -0,0 +1 @@<br>
> +#include "private1.h"<br>
><br>
> Added: cfe/trunk/test/Modules/Inputs/suggest-include/useprivate3.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-" target="_blank">http://llvm.org/viewvc/llvm-</a><br>
> project/cfe/trunk/test/Modules/Inputs/suggest-<br>
> include/useprivate3.h?rev=267802&view=auto<br>
> ==========================================================<br>
> ====================<br>
> --- cfe/trunk/test/Modules/Inputs/suggest-include/useprivate3.h (added)<br>
> +++ cfe/trunk/test/Modules/Inputs/suggest-include/useprivate3.h Wed Apr<br>
> +++ 27 16:57:05 2016<br>
> @@ -0,0 +1 @@<br>
> +#include "private3.h"<br>
><br>
> Added: cfe/trunk/test/Modules/Inputs/suggest-include/usetextual1.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-" target="_blank">http://llvm.org/viewvc/llvm-</a><br>
> project/cfe/trunk/test/Modules/Inputs/suggest-<br>
> include/usetextual1.h?rev=267802&view=auto<br>
> ==========================================================<br>
> ====================<br>
> --- cfe/trunk/test/Modules/Inputs/suggest-include/usetextual1.h (added)<br>
> +++ cfe/trunk/test/Modules/Inputs/suggest-include/usetextual1.h Wed Apr<br>
> +++ 27 16:57:05 2016<br>
> @@ -0,0 +1,2 @@<br>
> +#include "textual1.h"<br>
> +FOO(extern int usetextual1;)<br>
><br>
> Added: cfe/trunk/test/Modules/Inputs/suggest-include/usetextual2.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-" target="_blank">http://llvm.org/viewvc/llvm-</a><br>
> project/cfe/trunk/test/Modules/Inputs/suggest-<br>
> include/usetextual2.h?rev=267802&view=auto<br>
> ==========================================================<br>
> ====================<br>
> --- cfe/trunk/test/Modules/Inputs/suggest-include/usetextual2.h (added)<br>
> +++ cfe/trunk/test/Modules/Inputs/suggest-include/usetextual2.h Wed Apr<br>
> +++ 27 16:57:05 2016<br>
> @@ -0,0 +1,2 @@<br>
> +#define EXPAND_MACRO extern int usetextual2; #include "textual2.h"<br>
><br>
> Added: cfe/trunk/test/Modules/Inputs/suggest-include/usetextual3.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-" target="_blank">http://llvm.org/viewvc/llvm-</a><br>
> project/cfe/trunk/test/Modules/Inputs/suggest-<br>
> include/usetextual3.h?rev=267802&view=auto<br>
> ==========================================================<br>
> ====================<br>
> --- cfe/trunk/test/Modules/Inputs/suggest-include/usetextual3.h (added)<br>
> +++ cfe/trunk/test/Modules/Inputs/suggest-include/usetextual3.h Wed Apr<br>
> +++ 27 16:57:05 2016<br>
> @@ -0,0 +1 @@<br>
> +#include "textual3.h"<br>
><br>
> Added: cfe/trunk/test/Modules/Inputs/suggest-include/usetextual4.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-" target="_blank">http://llvm.org/viewvc/llvm-</a><br>
> project/cfe/trunk/test/Modules/Inputs/suggest-<br>
> include/usetextual4.h?rev=267802&view=auto<br>
> ==========================================================<br>
> ====================<br>
> --- cfe/trunk/test/Modules/Inputs/suggest-include/usetextual4.h (added)<br>
> +++ cfe/trunk/test/Modules/Inputs/suggest-include/usetextual4.h Wed Apr<br>
> +++ 27 16:57:05 2016<br>
> @@ -0,0 +1 @@<br>
> +#include "textual4.h"<br>
><br>
> Added: cfe/trunk/test/Modules/Inputs/suggest-include/usetextual5.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-" target="_blank">http://llvm.org/viewvc/llvm-</a><br>
> project/cfe/trunk/test/Modules/Inputs/suggest-<br>
> include/usetextual5.h?rev=267802&view=auto<br>
> ==========================================================<br>
> ====================<br>
> --- cfe/trunk/test/Modules/Inputs/suggest-include/usetextual5.h (added)<br>
> +++ cfe/trunk/test/Modules/Inputs/suggest-include/usetextual5.h Wed Apr<br>
> +++ 27 16:57:05 2016<br>
> @@ -0,0 +1 @@<br>
> +#include "textual5.h"<br>
><br>
> Added: cfe/trunk/test/Modules/suggest-include.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/suggest-" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/suggest-</a><br>
> include.cpp?rev=267802&view=auto<br>
> ==========================================================<br>
> ====================<br>
> --- cfe/trunk/test/Modules/suggest-include.cpp (added)<br>
> +++ cfe/trunk/test/Modules/suggest-include.cpp Wed Apr 27 16:57:05 2016<br>
> @@ -0,0 +1,33 @@<br>
> +// RUN: rm -rf %t<br>
> +// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t<br>
> +-fimplicit-module-maps -I%S/Inputs/suggest-include %s -verify<br>
> +<br>
> +#include "empty.h" // import the module file<br>
> +<br>
> +// expected-note@usetextual1.h:2 {{previous}} //<br>
> +expected-note@textual2.h:1 {{previous}} // expected-note@textual3.h:1<br>
> +{{previous}} // expected-note@textual4.h:1 {{previous}} //<br>
> +expected-note@textual5.h:1 {{previous}} // expected-note@private1.h:1<br>
> +{{previous}} // expected-note@private2.h:1 {{previous}} //<br>
> +expected-note@private3.h:1 {{previous}}<br>
> +<br>
> +void f() {<br>
> +  (void)::usetextual1; // expected-error {{missing '#include<br>
> +"usetextual1.h"'}}<br>
> +  (void)::usetextual2; // expected-error {{missing '#include<br>
> +"usetextual2.h"'}}<br>
> +  (void)::textual3; // expected-error-re {{{{^}}missing '#include<br>
> +"usetextual3.h"'}}<br>
> +  // Don't suggest a #include that includes the entity via a path that<br>
> +leaves<br>
> +  // the module. In that case we can't be sure that we've picked the right<br>
> header.<br>
> +  (void)::textual4; // expected-error-re {{{{^}}declaration of<br>
> +'textual4'}}<br>
> +  (void)::textual5; // expected-error-re {{{{^}}declaration of<br>
> +'textual5'}}<br>
> +<br>
> +  // Don't suggest #including a private header.<br>
> +  // FIXME: We could suggest including "useprivate1.h" here, as it's<br>
> +the only<br>
> +  // public way to get at this declaration.<br>
> +  (void)::private1; // expected-error-re {{{{^}}declaration of<br>
> +'private1'}}<br>
> +  // FIXME: Should we be suggesting an import at all here? Should<br>
> +declarations<br>
> +  // in private headers be visible when the surrounding module is imported?<br>
> +  (void)::private2; // expected-error-re {{{{^}}declaration of<br>
> +'private2'}}<br>
> +  // Even if we suggest an include for private1, we should not do so here.<br>
> +  (void)::private3; // expected-error-re {{{{^}}declaration of<br>
> +'private3'}} }<br>
><br>
><br>
> _______________________________________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" target="_blank">
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</div>
</body>
</html>