<div dir="ltr">Thanks Ben, <div><br></div><div>The initialisations do work! Thank you very much. </div><div><br></div><div>I still have 1 question. What are the differences between these 2 forms? </div><div><br></div><div>1. use clang to compile a file: <span style="background-color:rgb(255,242,204)">clang++ -c test.cpp</span></div><div>2. use clang tooling to parse a file ./foo.out test.cpp -- <span style="background-color:rgb(255,242,204)">clang++ -c test.cpp</span></div><div><span style="background-color:rgb(255,242,204)"><br></span></div>Best regards,<br>Han</div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 13, 2015 at 2:02 PM, Benjamin Kramer <span dir="ltr"><<a href="mailto:benny.kra@gmail.com" target="_blank">benny.kra@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Mon, Jul 13, 2015 at 12:20 PM, Han Wang <<a href="mailto:wanghan02@gmail.com">wanghan02@gmail.com</a>> wrote:<br>
> Hi,<br>
><br>
> I have a simple file containing some Microsoft style inline asm. I can<br>
> compile this file with -fms-extensions.<br>
><br>
> clang++ -fms-extensions -c test.cpp<br>
><br>
> No problem for this.<br>
><br>
> But when I write a simple AST Matcher tool (foo.out) to parse this file, I<br>
> got errors.<br>
><br>
> ./foo.out test.cpp -- clang++ -fms-extensions -c test.cpp<br>
> test.cpp:19:3: error: MS-style inline assembly is not available: Unable to<br>
> find target for this triple (no targets are registered)<br>
> __asm {<br>
> ^<br>
> test.cpp:28:3: error: MS-style inline assembly is not available: Unable to<br>
> find target for this triple (no targets are registered)<br>
> __asm mov a1, 2<br>
> ^<br>
> 2 errors generated.<br>
> Error while processing test.cpp.<br>
<br>
</span>This is most likely due to missing target initialization in your tool.<br>
MS-style asm is special as it has to be parsed by clang, requiring<br>
target support. GCC-style asm is parsed much later.<br>
<br>
Solving it should be as simple as putting<br>
<br>
llvm::InitializeAllTargets();<br>
llvm::InitializeAllTargetMCs();<br>
llvm::InitializeAllAsmPrinters();<br>
llvm::InitializeAllAsmParsers();<br>
<br>
in your main() function (or wherever the rest of clang is initialized).<br>
<span class=""><br>
> There are also some other problems when parsing test.cpp. For example if I<br>
> #include <string>, I have to use -- clang++ -I<path-to-string> to identify<br>
> the system header file path. I'm not sure what makes it different then the<br>
> normal clang compile.<br>
<br>
</span>Mainline clang doesn't use headers from xcode.app. The easiest way<br>
around that is just checking out libc++ into your LLVM tree.<br>
<br>
- Ben<br>
</blockquote></div><br></div>