<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [Modules] Auto loading of modulemap in subdirectories"
   href="https://bugs.llvm.org/show_bug.cgi?id=37878">37878</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[Modules] Auto loading of modulemap in subdirectories
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Modules
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>yukatkh@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=20450" name="attach_20450" title="Reproducer">attachment 20450</a> <a href="attachment.cgi?id=20450&action=edit" title="Reproducer">[details]</a></span>
Reproducer

$ tar xvf subdirectory.tar
$ cd module
$ sudo cp input/module.modulemap /usr/include/foobar
$ ~/llvm-build/bin/clang -fmodules -fmodule-name Foo -I input main.cxx

I get:
/usr/include/foobar/module.modulemap:1:8: error: redefinition of module 'a'
module a { header "a.h" }
       ^
input/module.modulemap:1:8: note: previously defined here
module a { header "a.h" }
       ^
/usr/include/foobar/module.modulemap:2:8: error: redefinition of module 'b'
module b { header "b.h" }
       ^
input/module.modulemap:2:8: note: previously defined here
module b { header "b.h" }
       ^
2 errors generated.


In clang/lib/Lex/HeaderSearch.cpp HeaderSearch::lookupModule(StringRef
ModuleName, StringRef SearchName), if it couldn't find ModuleName in search
paths, it comes to this line
 283     // Load all module maps in the immediate subdirectories of this search
 284     // directory.
 285     loadSubdirectoryModuleMaps(SearchDirs[Idx]);
Which results in iterating over all files in the search path subdirectories for
example "/usr/include/foobar" in this case. I think user don't expect Clang to
load modulemaps in subdirectories implicitly.

I could fix this error if I remove 285. Maybe we should add branch here like:
if (LangOpts.ObjC || LangOpts.ObjCpp) ?</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>