[cfe-dev] clangd/libclang: how to emulate other compilers?
Manuel Klimek via cfe-dev
cfe-dev at lists.llvm.org
Thu Apr 19 03:25:00 PDT 2018
On Wed, Apr 18, 2018 at 9:37 PM Milian Wolff <mail at milianw.de> wrote:
> On Mittwoch, 18. April 2018 12:25:40 CEST Manuel Klimek wrote:
> > On Tue, Apr 17, 2018 at 8:02 PM Milian Wolff via cfe-dev <
> > cfe-dev at lists.llvm.org> wrote:
> > > Hey all,
> > >
> > > how does clangd or other users of the libclang handle situations where
> > > want to parse code that is dependent on a certain other compiler or
> > > compiler
> > > environment? The most common scenario being embedded projects that
> rely on
> > > the
> > > compiler-builtin defines and include paths to find the sysroot include
> > > paths
> > > and such.
> > 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?
> Take this example code:
> #ifndef __arm__
> #error unsupported platform
> #include <foobar.h>
> static_assert(sizeof(void*) == 4);
> How can I parse this with libclang, such that it emulates my arm-none-eabi-
> - __arm__ should be defined, but not __x86_64__
> - foobar.h should be found in the default include paths for the
> gcc compiler, not in the default include paths of libclang
> - it should be 32bit by default
Using clang -target arm-eabi seems to do the trick?
> Now, we can get there to some degree via -nostdinc and -nostdinc++. But
> you do that for all compilers, you get into nasty issues when you replace
> libclang builtin headers with headers from a different clang version or
> even a
> different compiler like GCC. They will be compiler specific and not
> thus not parsable by libclang.
> > 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
> > so forth that the system is using. Clang should be able to find that
> > the right flags.
> Can you tell us what the right flags would be? I just looked at the man
> again and found -nostdlibinc, which may resolve this partially - I'll
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 :)
> Milian Wolff
> mail at milianw.de
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cfe-dev