<div dir="ltr"><div>Hi Chad,</div><div><br></div><div>Thanks, yes it makes perfect sense, </div><div>I guess it is one reason why clang is quite strict about inline asm ( <a href="http://clang.llvm.org/compatibility.html#inline-asm">http://clang.llvm.org/compatibility.html#inline-asm</a> )</div>
<div><br></div><div>So now I understand that there is no way to parse MS-style inline assembly without a target asm parser.</div><div>But I still need to figure out if I can and how to tell libclang to initialize a specific target.</div>
<div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Oct 30, 2013 at 4:27 PM, <span dir="ltr"><<a href="mailto:mcrosier@codeaurora.org" target="_blank">mcrosier@codeaurora.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi William,<br>
I can answer your second question. GCC style inline assembly does not<br>
require a target AsmParser. MS-style inline assembly requires a parser<br>
because this is how we discover the constraints. Hope this helps.<br>
<br>
Chad<br>
<div><div class="h5"><br>
> Hi Alp,<br>
><br>
> Thanks for helping !<br>
><br>
> 1] Is there a way I could tell libclang which target to initialize without<br>
> modifying it ?<br>
> 2] How does it work for gcc style assembly, is there a similar error<br>
> message or does it work without the need of any targets ?<br>
> 3] Since you decided to diagnose this, you might also want to check the<br>
> case were the target have been initialized, but not the used function<br>
> pointers of this target<br>
><br>
> William.<br>
><br>
><br>
> On Wed, Oct 30, 2013 at 3:53 PM, Alp Toker <<a href="mailto:alp@nuanti.com">alp@nuanti.com</a>> wrote:<br>
><br>
>> Hello William,<br>
>><br>
>> I've landed a fix in r193685 to diagnose this instead of crashing:<br>
>><br>
>> clang/test/Index/ms-asm-no-target.cpp:8:3: error: MS-style inline<br>
>> assembly<br>
>> is not available: Unable to find target for this triple (no targets are<br>
>> registered)<br>
>><br>
>> It's up to the embedder to decide what targets are linked in, so how the<br>
>> API exposes that is still an open question.<br>
>><br>
>> Alp.<br>
>><br>
>><br>
>><br>
>> On 30/10/2013 11:50, William Ledoux wrote:<br>
>><br>
>> Hello,<br>
>><br>
>> The following minimal code that contain MS-style inline assembly will<br>
>> compile fine with clang, but libclang fails to parse it<br>
>> (clang_parseTranslationUnit will return NULL).<br>
>><br>
>> void Break(){ __asm { int 3 } }<br>
>><br>
>> In yesterday's llvm and clang sources, the problem occurs in<br>
>> ParseMicrosoftAsmStatement.<br>
>> In the code below, because no target have been registered, the first<br>
>> line<br>
>> will set TheTarget to NULL, and the second line will dereference<br>
>> TheTarget,<br>
>> thus causing the problem.<br>
>><br>
>> const llvm::Target *TheTarget =<br>
>> llvm::TargetRegistry::lookupTarget(TT,<br>
>> Error);<br>
>> OwningPtr<llvm::MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TT));<br>
>><br>
>> For what I understood, clang, in cc1_main, will initialize targets and<br>
>> targets' functions with the following 4 lines, whereas libclang won't.<br>
>><br>
>> llvm::InitializeAllTargets();<br>
>> llvm::InitializeAllTargetMCs();<br>
>> llvm::InitializeAllAsmPrinters();<br>
>> llvm::InitializeAllAsmParsers();<br>
>><br>
>> Just for testing purpose, adding those 4 lines somewhere in<br>
>> clang_createIndex fixes the problem. I know this is probably wrong, but<br>
>> did<br>
>> it just to see if more problems were hiding behind.<br>
>><br>
>> So my questions are:<br>
>> 1] Is it wanted that libclang doesn't initialize any target ?<br>
>> 2] if yes, how shloud it behave with MS inline assembly ?<br>
>> 3] if no, what is the proper way to make it initialize targets ?<br>
>><br>
>> Many thanks for you work !<br>
>> William<br>
>><br>
>><br>
>><br>
>><br>
>> --<br>
>> View this message in context:<br>
>> <a href="http://clang-developers.42468.n3.nabble.com/libclang-crash-when-parsing-MS-style-inline-assembly-tp4035432.html" target="_blank">http://clang-developers.42468.n3.nabble.com/libclang-crash-when-parsing-MS-style-inline-assembly-tp4035432.html</a><br>
>> Sent from the Clang Developers mailing list archive at Nabble.com.<br>
>> _______________________________________________<br>
>> cfe-dev mailing<br>
</div></div>>> listcfe-dev@cs.uiuc.eduhttp://<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<div class="HOEnZb"><div class="h5">>><br>
>><br>
>> -- <a href="http://www.nuanti.com" target="_blank">http://www.nuanti.com</a><br>
>> the browser experts<br>
>><br>
>><br>
> _______________________________________________<br>
> cfe-dev mailing list<br>
> <a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
><br>
<br>
<br>
</div></div></blockquote></div><br></div>