[cfe-dev] clang omits a part of the code

Peter Collingbourne peter at pcc.me.uk
Fri Mar 25 06:50:56 PDT 2011


On Fri, Mar 25, 2011 at 11:31:08AM +0000, Nir Pluderman wrote:
> Thank you for your quick response Peter,
> 
> I did as you said, and this is the output I got:
> 
>     Stack dump:
>     0.    /usr/include/stdio.h:34:3: current parser token 'include'

This is not a standard diagnostic but part of Clang's output if it
segfaults/asserts.  Since you received the segfault/assert at the point
where a diagnostic should be emitted, I suspect it is because you did
not create the Diagnostic object correctly.  This is how I normally
build a Diagnostic object and point it to a TextDiagnosticPrinter
(which should just print the diagnostics to standard error):

  clang::TextDiagnosticPrinter *DiagClient =
    new clang::TextDiagnosticPrinter(errs(), clang::DiagnosticOptions());
  IntrusiveRefCntPtr<clang::DiagnosticIDs> DiagID(new clang::DiagnosticIDs());
  clang::Diagnostic *Diag = new clang::Diagnostic(DiagID, DiagClient);

> note:
>     In both cases the problematic line in these standard library headers is: 
>         #include <stddef.h>

This means that Clang could not find its stddef.h header, because
HeaderSearchOptions::ResourceDir (i.e. headerSearchOpts->ResourceDir)
was not set correctly.  You should set it to something like

LLVM_PREFIX "/lib/clang/" CLANG_VERSION_STRING

where LLVM_PREFIX is your LLVM build directory and CLANG_VERSION_STRING
is a macro defined in clang/Basic/Version.h.

Thanks,
-- 
Peter



More information about the cfe-dev mailing list