<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 - modulemap umbrella directory iteration order led to compile failures"
href="https://bugs.llvm.org/show_bug.cgi?id=45169">45169</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>modulemap umbrella directory iteration order led to compile failures
</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>All
</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>Frontend
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>drodrigueztroitino@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>A modulemap file including a directive like `umbrella "."` might led to
different include orders, and led to compilation errors in different OS or the
same OS and different file systems.
It is possible to create a modulemap file with the so-called "umbrella
directory declaration" pointing to a directory. Because how the contents of the
directory are iterated, the interpretation of such module might be different in
different in different systems, even if the contents of the directory are
exactly the same.
The problem happens because in
<a href="https://github.com/llvm/llvm-project/blob/4a0267e3ad8c4d47f267d7d960f127e099fb4818/clang/lib/Frontend/FrontendAction.cpp#L367">https://github.com/llvm/llvm-project/blob/4a0267e3ad8c4d47f267d7d960f127e099fb4818/clang/lib/Frontend/FrontendAction.cpp#L367</a>
llvm::vfs::recursive_directory_iterator is used. Under the hood the
recursive_directory_iterator will use readdir
(<a href="https://github.com/llvm/llvm-project/blob/47ec8702cbc6f607b2e5cc25270a560eb9e02710/llvm/lib/Support/Unix/Path.inc#L876-L891">https://github.com/llvm/llvm-project/blob/47ec8702cbc6f607b2e5cc25270a560eb9e02710/llvm/lib/Support/Unix/Path.inc#L876-L891</a>).
In my manual documentation of readdir, one can read "Note that the order of the
directory entries vended by readdir() is not specified. Some filesystems may
return entries in lexicographic sort order and others may not." (macOS
10.14.6).
Since the order of iteration is not specific, the headers that work in one
system might be reordered in the next system, and might fail to compile.
There seems to be backwards compatibility hack in
<a href="https://github.com/llvm/llvm-project/blob/47ec8702cbc6f607b2e5cc25270a560eb9e02710/clang/lib/Lex/ModuleMap.cpp#L2416-L2439">https://github.com/llvm/llvm-project/blob/47ec8702cbc6f607b2e5cc25270a560eb9e02710/clang/lib/Lex/ModuleMap.cpp#L2416-L2439</a>
for some cases, but it is commented with "Although iterating over the directory
is relatively expensive, in practice this only applies to the uncommonly used
Tcl module on Darwin platforms.".
What I am asking is that all the umbrella directory declarations should provide
a consistent output given a consistent input, and should try to discard the
effects of the OS or the file system.
As a workaround, providing manually all the headers in lexicographical order in
the modulemap works, and provides a consistent compilation.</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>