<div dir="ltr">Hi Alp,<div><br></div><div>Thanks for helping !</div><div><br></div><div>1] Is there a way I could tell libclang which target to initialize without modifying it ?</div><div>2] How does it work for gcc style assembly, is there a similar error message or does it work without the need of any targets ?</div>

<div>3] Since you decided to diagnose this, you might also want to check the case were the target have been initialized, but not the used function pointers of this target</div><div><br></div><div>William.</div></div><div class="gmail_extra">

<br><br><div class="gmail_quote">On Wed, Oct 30, 2013 at 3:53 PM, Alp Toker <span dir="ltr"><<a href="mailto:alp@nuanti.com" target="_blank">alp@nuanti.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


  
    
  
  <div bgcolor="#FFFFFF" text="#000000">
    Hello William,<br>
    <br>
    I've landed a fix in r193685 to diagnose this instead of crashing:<br>
    <br>
    <code>clang/test/Index/ms-asm-no-target.cpp:8:3: error: MS-style
      inline assembly is not available: Unable to find target for this
      triple (no targets are registered)</code><br>
    <br>
    It's up to the embedder to decide what targets are linked in, so how
    the API exposes that is still an open question.<br>
    <br>
    Alp.<div><div class="h5"><br>
    <br>
    <br>
    <div>On 30/10/2013 11:50, William Ledoux
      wrote:<br>
    </div>
    <blockquote type="cite">
      <pre>Hello,

The following minimal code that contain MS-style inline assembly will
compile fine with clang, but libclang fails to parse it
(clang_parseTranslationUnit will return NULL).

   void Break(){ __asm { int 3 } }

In yesterday's llvm and clang sources, the problem occurs in
ParseMicrosoftAsmStatement.
In the code below, because no target have been registered, the first line
will set TheTarget to NULL, and the second line will dereference TheTarget,
thus causing the problem.
 
   const llvm::Target *TheTarget = llvm::TargetRegistry::lookupTarget(TT,
Error);
   OwningPtr<llvm::MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TT));

For what I understood, clang, in cc1_main, will initialize targets and
targets' functions with the following 4 lines, whereas libclang won't.

  llvm::InitializeAllTargets();
  llvm::InitializeAllTargetMCs();
  llvm::InitializeAllAsmPrinters();
  llvm::InitializeAllAsmParsers();

Just for testing purpose, adding those 4 lines somewhere in
clang_createIndex fixes the problem. I know this is probably wrong, but did
it just to see if more problems were hiding behind.

So my questions are:
  1] Is it wanted that libclang doesn't initialize any target ? 
  2] if yes, how shloud it behave with MS inline assembly ?
  3] if no, what is the proper way to make it initialize targets ?

Many thanks for you work !
William




--
View this message in context: <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>
Sent from the Clang Developers mailing list archive at Nabble.com.
_______________________________________________
cfe-dev mailing list
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a>
</pre>
    </blockquote>
    <br>
    </div></div><span class="HOEnZb"><font color="#888888"><pre cols="72">-- 
<a href="http://www.nuanti.com" target="_blank">http://www.nuanti.com</a>
the browser experts
</pre>
  </font></span></div>

</blockquote></div><br></div>