<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 - the -isysroot parameter causes -I directories to be ignored"
   href="https://bugs.llvm.org/show_bug.cgi?id=44193">44193</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>the -isysroot parameter causes -I directories to be ignored
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Macintosh
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>MacOS X
          </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>-New Bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>Piers.Walter@ilink.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I'm using Xcode on macOS and have analyzed a problem where a wrong header file
is included into my code. I think that I have located the root cause in clang
which does not always seem to adhere to the header file search path order when
the -isysroot parameter is used (as it is by Xcode).

My understanding is that the preprocessor searches the header file search
directories for a file to include in the order in which they were specified
with -I parameters. So if header files with the same name are located in
different header file search directories, clang will go through the directories
in the order in which they were specified with -I parameters and will import
the file from the first directory in which it is found.

This works fine until the -isysroot parameter is used as well. In this case, a
-I directory that is located within the new root seems to be ignored, so that
the include file is taken from a different dictionary than expected.

I do not understand why using the -isysroot parameter would cause header search
directories to be ignored. To me this seems to be a bug.


To reproduce:

Setup:
mkdir -p sdk/usr/include opt/local/include usr/include
echo "VERSION=1" > sdk/usr/include/version.h
echo "VERSION=2" > opt/local/include/version.h
echo "VERSION=3" > usr/include/version.h
echo "
#include <version.h>

main() {
}
" > test.c


Test 1 (the expected file is included, VERSION=1):
clang -E -Isdk/usr/include -Iopt/local/include test.c


Test 2 (added -isysroot. The wrong file is included, VERSION=2):
clang -E -isysroot sdk -Isdk/usr/include -Iopt/local/include test.c


Test 3 (inserted another directory in the middle. The wrong file is included,
VERSION=3):
clang -E -isysroot sdk -Isdk/usr/include -Iusr/include -Iopt/local/include
test.c


Test 4 (it's not the first folder after the -isysroot parameter that is
ignored. The wrong file is included, VERSION=3):
clang -E -isysroot sdk -Iusr/include -Isdk/usr/include -Iopt/local/include
test.c


clang -v
Apple clang version 11.0.0 (clang-1100.0.33.12)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin</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>