<div><div>Hello cfe-dev,</div><div><br></div><div>I’m using clang libTooling for creating a GUI developer tool, currently with clang 6.0. The tool makes use of the local system headers when analyzing source code. From my local compiler I get these system header paths:</div><div><br></div><div>    $ clang++ -x c++ -v -E /dev/null</div><div>    ...</div><div>    #include <...> search starts here:</div><div>     /usr/local/include</div><div>     /opt/local/include</div><div>     /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1</div><div>     /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.1.0/include</div><div>     /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include</div><div>     /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include</div><div>     /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks (framework directory)</div><div>    …</div><div><br></div><div><br></div><div>My local toolchain is based on Xcode:</div><div><br></div><div>    $ clang++ -v</div><div>    clang version 5.0.1 (http://llvm.org/git/clang.git 232230afd349ceeb784720d2266e2288523d871f) (http://llvm.org/git/llvm.git cbc2c76b286c38a1fd006543b6b224c06cd96df1)</div><div>    Target: x86_64-apple-darwin17.5.0</div><div>    Thread model: posix</div><div>    InstalledDir: /usr/local/bin</div><div><br></div><div><br></div><div>My tool usually works fine, and most source code can be analysed without problems. But sometimes there are errors like this one:</div><div><br></div><div>    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.1.0/include/emmintrin.h:2261:19: fatal error: use of undeclared identifier '__builtin_ia32_pavgb128'</div><div>      return (__m128i)__builtin_ia32_pavgb128((__v16qi)__a, (__v16qi)__b);</div><div>                      ^</div><div>    error: use of undeclared identifier ‘__builtin_ia32_pavgb128'</div><div><br></div><div><br></div><div>I found out that this problem might be related to the preprocessor definitions of my tool. My tool either uses the wrong ones or misses some. I can get a list from my local compiler and make my tool use them:</div><div><br></div><div>    $ clang++ -x c++ -E -dM /dev/null</div><div>    #define OBJC_NEW_PROPERTIES 1</div><div>    #define _LP64 1</div><div>    #define __APPLE_CC__ 6000</div><div>    #define __APPLE__ 1</div><div>    #define __ATOMIC_ACQUIRE 2</div><div>    #define __ATOMIC_ACQ_REL 4</div><div>    #define __ATOMIC_CONSUME 1</div><div>    #define __ATOMIC_RELAXED 0</div><div>    #define __ATOMIC_RELEASE 3</div><div>    …</div><div><br></div><div><br></div><div>But that just switches the problem to some other location:</div><div><br></div><div>    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/stdlib.h:162:54: fatal error: redefinition of parameter 'restrict'</div><div>    size_t   mbstowcs(wchar_t * __restrict , const char * __restrict, size_t);</div><div>                                                          ^</div><div>    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/sys/cdefs.h:209:20: note: expanded from macro '__restrict'</div><div>    #define __restrict      restrict</div><div>                            ^</div><div>    error: redefinition of parameter ‘restrict’</div><div><br></div><div><br></div><div>I couldn’t find a good resource explaining me this situation yet. What am I doing wrong here?</div><div>Is this a problem of wrong/missing preprocessor definitions?</div><div>Or does my clang 6.0 tool not match with my local clang 5.0.1 toolchain’s system headers?</div><div>Do I need to ship certain system headers with my tool?</div><div><br></div><div>Thank you,</div><div>Eberhard Gräther</div><div><br></div></div><div><div><br></div></div>