<html>
<head>
<base href="https://llvm.org/bugs/" />
</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 --- - #include gets wrong file in presence of hardlinks"
href="https://llvm.org/bugs/show_bug.cgi?id=26579">26579</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>#include gets wrong file in presence of hardlinks
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</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>Frontend
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>jyknight@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>The following program demonstrates that clang fails to find the proper "current
file's directory" to use for resolving an #include filename, if FileManager has
somehow already learned about another file with the same inode, in a different
directory.
While this reproduction uses simple includes, this is a particularly bad
problem with modules -- where FileManager is informed about many more files
that aren't necessarily even included by the C file being built -- and when you
are compiling on a content-addressable-storage system, where all files with the
same content are always hardlinked.
==== reproduction case ====
mkdir dir1 dir2
echo '#include "other.h"' > dir1/a.h
cp dir1/a.h dir2/a.h
cat >> dir1/other.h <<EOF
#ifdef DIR1
#error included dir1/other.h twice!
#endif
#define DIR1
EOF
echo '' > dir2/other.h
cat >> main.c <<EOF
#include "dir1/a.h"
#include "dir2/a.h"
EOF
## Just to show that the program normally works fine, no error:
clang -E main.c
## Now, replace the copy with a hardlink...
rm dir2/a.h
ln dir1/a.h dir2/a.h
## And it fails with the #error, because the #include "other.h" from
## "dir2/a.h" incorrectly believes that the current file is actually
## "dir1/a.h"!
clang -E main.c</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>