[llvm-bugs] [Bug 44193] New: the -isysroot parameter causes -I directories to be ignored

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Dec 1 05:10:04 PST 2019


            Bug ID: 44193
           Summary: the -isysroot parameter causes -I directories to be
           Product: clang
           Version: unspecified
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: Piers.Walter at ilink.de
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

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:

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,
clang -E -isysroot sdk -Isdk/usr/include -Iusr/include -Iopt/local/include

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

clang -v
Apple clang version 11.0.0 (clang-1100.0.33.12)
Target: x86_64-apple-darwin18.7.0
Thread model: posix

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191201/e7559451/attachment.html>

More information about the llvm-bugs mailing list