[cfe-dev] InitHeaderSearch replacement ?

Parijat Banerjee parijat.pcr at gmail.com
Mon Sep 20 03:18:04 PDT 2010


This is my code which I have used to initialize the parser

llvm::raw_ostream *os = NULL;

 llvm::raw_ostream *ps = NULL;



 const DiagnosticOptions diagop;

 bool OwnsOutputStream=false;

 TextDiagnosticPrinter diagClient(*os,diagop,OwnsOutputStream);

 Diagnostic diags(&diagClient);

 LangOptions opts;

 TargetOptions to;

 const std::string& triple = LLVM_HOSTTRIPLE;

 to.ABI="";

 to.CXXABI="itanium";

 to.CPU="";

 to.Features.clear();

 to.Triple=triple;

 TargetInfo* target = TargetInfo::CreateTargetInfo(diags,to);

 SourceManager sm(diags);

 FileManager fm;

 HeaderSearch headers(fm);




 HeaderSearchOptions hso;

 hso.ResourceDir="/u/parijat/llvm2/llvm/Release/lib/clang/2.8";

 hso.AddPath(llvm::StringRef("/usr/local/include"),clang::frontend::Angled,true,false,false);

 hso.AddPath(llvm::StringRef("/usr/include"),clang::frontend::Angled,true,false,false);

 ApplyHeaderSearchOptions(headers,hso,opts,llvm::Triple(llvm::sys::getHostTriple()));

 Preprocessor pp(diags,opts,*target,sm,headers);


 PreprocessorOptions ppo;

 FrontendOptions feo;

 InitializePreprocessor(pp,ppo,hso,feo);



const FileEntry* File=fm.getFile(argv_[1]);

 if(!File)

   {printf("File doesn't exist!");

    return 0;

  }


   sm.createMainFileID(File);

   Builtin::Context builtins(*target);

   unsigned size;

   ASTConsumer ac;

   ASTContext
acx(opts,sm,*target,pp.getIdentifierTable(),pp.getSelectorTable(),pp.getBuiltinInfo(),10000);

   ParseAST(pp,&ac,acx,false);


The above program segfaults out at ParseAST when it runs across a #include (
with stdio or anything else) in the test file. It works fine when no headers
are included .

Can someone please shed some light on where I might be going wrong .

Thanks a lot in advance
Parijat

On Mon, Sep 20, 2010 at 11:48 AM, Parijat Banerjee <parijat.pcr at gmail.com>wrote:

> I am having problems parsing programs which include standard header files
> in my own parser using clang libraries . After v2.6 the InitHeaderSearch and
> InitPreprocessor header files seem to have been replaced. Can someone tell
> me how do i initialize the preprocessor and headersearch in the current
> branch (2.8) so that my parser doesn't segfault out when it runs across a
> standard header inclusion in a test file ?
>
> Thanks and Regards,
> Parijat
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100920/d98e438e/attachment.html>


More information about the cfe-dev mailing list