[cfe-dev] libclang crash when parsing MS-style inline assembly

William Ledoux william.ledoux at gmail.com
Wed Oct 30 04:50:28 PDT 2013


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: http://clang-developers.42468.n3.nabble.com/libclang-crash-when-parsing-MS-style-inline-assembly-tp4035432.html
Sent from the Clang Developers mailing list archive at Nabble.com.



More information about the cfe-dev mailing list