<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Tue, Apr 17, 2018 at 8:02 PM Milian Wolff via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hey all,<br>
<br>
how does clangd or other users of the libclang handle situations where you <br>
want to parse code that is dependent on a certain other compiler or compiler <br>
environment? The most common scenario being embedded projects that rely on the <br>
compiler-builtin defines and include paths to find the sysroot include paths <br>
and such.<br></blockquote><div><br></div><div>I'm not sure I understand what you mean - do you mean the compiler has builtins that clang doesn't provide and relies on their existence?</div><div><br></div><div>Generally, you'll want to use the builtin defines and includes from clang (at the point at which you compiled libclang), but the standard library and so forth that the system is using. Clang should be able to find that given the right flags.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
For KDevelop, which is using libclang, we have tried to build a sort of <br>
emulation layer that originally yielded good results. The approach is as <br>
followed:<br>
<br>
1) We use the actual compiler that is used to compile a given project, e.g. <br>
gcc, arm-none-eabi-gcc, ...<br>
<br>
2) We take this compiler and query it for its builtin defines:<br>
/usr/bin/gcc -xc++ -std=c++11 -dM -E - < /dev/null<br>
<br>
3) And also query the include paths:<br>
/usr/bin/gcc -xc++ -std=c++11 -v -E - < /dev/null<br>
<br>
4) Then for the libclang calls to clang_parseTranslationUnit2 we pass `-<br>
nostdinc -nostdinc++` followed by the defines and includes we got from 2) and <br>
3).<br>
<br>
Now, for simply things this actually worked quite well. But once you include a <br>
file that heavily relies on the compiler, such as all the SIMD intrinsic <br>
headers, you are easily drowning in parse errors. And once you have too many <br>
parse errors, clang will just give up. We have tried to workaround this via <br>
compatibility headers such as [1], but it keeps breaking.<br>
<br>
More recently, we now also got bug reports where the user system has clang3 <br>
and they use that to to compile the code, but then download a KDevelop <br>
AppImage built against libclang v5 (e.g. via AppImage). Once again this easily <br>
yields tons of parse errors when encountering system headers that are using <br>
intrinsics specific to clang v3.<br>
<br>
I am now thinking about removing the emulation layer described above. But then <br>
it will be essentially impossible to work on a lot of embedded projects which <br>
rely on the cross compiler defines and include paths...<br>
<br>
So, once again - how do other users of libclang handle this scenario? What is <br>
the plan for clangd in this regard?<br>
<br>
Thanks<br>
-- <br>
Milian Wolff<br>
<a href="mailto:mail@milianw.de" target="_blank">mail@milianw.de</a><br>
<a href="http://milianw.de" rel="noreferrer" target="_blank">http://milianw.de</a>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div></div>