[cfe-dev] Error parsing files with AST Matcher tool

Han Wang wanghan02 at gmail.com
Mon Jul 13 05:38:03 PDT 2015


Thanks Ben,

The initialisations do work! Thank you very much.

I still have 1 question. What are the differences between these 2 forms?

1. use clang to compile a file: clang++ -c test.cpp
2. use clang tooling to parse a file ./foo.out test.cpp -- clang++ -c
test.cpp

Best regards,
Han

On Mon, Jul 13, 2015 at 2:02 PM, Benjamin Kramer <benny.kra at gmail.com>
wrote:

> On Mon, Jul 13, 2015 at 12:20 PM, Han Wang <wanghan02 at gmail.com> wrote:
> > Hi,
> >
> > I have a simple file containing some Microsoft style inline asm. I can
> > compile this file with -fms-extensions.
> >
> > clang++ -fms-extensions -c test.cpp
> >
> > No problem for this.
> >
> > But when I write a simple AST Matcher tool (foo.out) to parse this file,
> I
> > got errors.
> >
> > ./foo.out test.cpp -- clang++ -fms-extensions -c test.cpp
> > test.cpp:19:3: error: MS-style inline assembly is not available: Unable
> to
> > find target for this triple (no targets are registered)
> >   __asm {
> >   ^
> > test.cpp:28:3: error: MS-style inline assembly is not available: Unable
> to
> > find target for this triple (no targets are registered)
> >   __asm mov a1, 2
> >   ^
> > 2 errors generated.
> > Error while processing test.cpp.
>
> This is most likely due to missing target initialization in your tool.
> MS-style asm is special as it has to be parsed by clang, requiring
> target support. GCC-style asm is parsed much later.
>
> Solving it should be as simple as putting
>
> llvm::InitializeAllTargets();
> llvm::InitializeAllTargetMCs();
> llvm::InitializeAllAsmPrinters();
> llvm::InitializeAllAsmParsers();
>
> in your main() function (or wherever the rest of clang is initialized).
>
> > There are also some other problems when parsing test.cpp. For example if
> I
> > #include <string>, I have to use -- clang++ -I<path-to-string> to
> identify
> > the system header file path. I'm not sure what makes it different then
> the
> > normal clang compile.
>
> Mainline clang doesn't use headers from xcode.app. The easiest way
> around that is just checking out libc++ into your LLVM tree.
>
> - Ben
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150713/a427faf1/attachment.html>


More information about the cfe-dev mailing list