<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Wed, Apr 18, 2018 at 9:37 PM Milian Wolff <<a href="mailto:mail@milianw.de">mail@milianw.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Mittwoch, 18. April 2018 12:25:40 CEST Manuel Klimek wrote:<br>
> On Tue, Apr 17, 2018 at 8:02 PM Milian Wolff via cfe-dev <<br>
> <br>
> <a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:<br>
> > 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<br>
> > compiler<br>
> > environment? The most common scenario being embedded projects that rely on<br>
> > the<br>
> > compiler-builtin defines and include paths to find the sysroot include<br>
> > paths<br>
> > and such.<br>
> <br>
> I'm not sure I understand what you mean - do you mean the compiler has<br>
> builtins that clang doesn't provide and relies on their existence?<br>
<br>
Take this example code:<br>
<br>
```<br>
#ifndef __arm__<br>
#error unsupported platform<br>
#endif<br>
<br>
#include <foobar.h><br>
<br>
static_assert(sizeof(void*) == 4);<br>
```<br>
<br>
How can I parse this with libclang, such that it emulates my arm-none-eabi-<br>
gcc? </blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
- __arm__ should be defined, but not __x86_64__<br>
- foobar.h should be found in the default include paths for the arm-none-eabi-<br>
gcc compiler, not in the default include paths of libclang<br>
- it should be 32bit by default<br></blockquote><div><br></div><div>Using clang -target arm-eabi seems to do the trick?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Now, we can get there to some degree via -nostdinc and -nostdinc++. But once <br>
you do that for all compilers, you get into nasty issues when you replace the <br>
libclang builtin headers with headers from a different clang version or even a <br>
different compiler like GCC. They will be compiler specific and not portable, <br>
thus not parsable by libclang.<br>
<br>
> Generally, you'll want to use the builtin defines and includes from clang<br>
> (at the point at which you compiled libclang), but the standard library and<br>
> so forth that the system is using. Clang should be able to find that given<br>
> the right flags.<br>
<br>
Can you tell us what the right flags would be? I just looked at the man page <br>
again and found -nostdlibinc, which may resolve this partially - I'll check.<br></blockquote><div><br></div><div>Again, there are multiple levels of builtin includes. If you want the right ones for a target platform, you'll need to select that target platform - if that doesn't work with clangd, we need to fix it :)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Cheers<br>
<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></blockquote></div></div>