[cfe-dev] CompilerInstance problems

Nikola Smiljanic popizdeh at gmail.com
Thu Mar 5 14:57:12 PST 2015


Trunk is always "the next version", 3.6 is whatever is built from 3.6
branch.

On Wed, Mar 4, 2015 at 3:07 PM, Robert Ankeney <rrankene at gmail.com> wrote:

> I'm updating a project from Clang 3.4 to the latest version of Clang, and
> am having problems getting it to work. It's a Qt-based project with a
> RecursiveASTVisitor, running on Windows with MinGW-32. Everything seems to
> go well until I get to the destructor of the CompilerInstance. The code
> looks something like:
> {
>   CompilerInstance compiler;
>   DiagnosticOptions &diagOpts = compiler.getDiagnosticOpts();
>   string verr_string;
>   raw_string_ostream vErr(verr_string);
>
>   TextDiagnosticPrinter *pTextDiagnosticPrinter =
>                          new TextDiagnosticPrinter(vErr, &diagOpts);
>   compiler.createDiagnostics(pTextDiagnosticPrinter);
>
>   // Create an invocation that passes any flags to preprocessor
>   unique_ptr<CompilerInvocation> Invocation(new CompilerInvocation);
>   CompilerInvocation::CreateFromArgs(*Invocation, argv + 1, argv + argc,
>                                       compiler.getDiagnostics());
>
>   Invocation->setLangDefaults(compiler.getLangOpts(),
>                               clang::IK_CXX,
>                              options.langStandard);
>
>   compiler.setInvocation(Invocation.release());
>
>   // Set default target triple
>   shared_ptr<TargetOptions> pto( new TargetOptions());
>   pto->Triple = llvm::sys::getDefaultTargetTriple();
>   shared_ptr<TargetInfo>
>     pti(TargetInfo::CreateTargetInfo(compiler.getDiagnostics(), pto));
>   compiler.setTarget(pti.get());
>
>   compiler.createFileManager();
>   compiler.createSourceManager(compiler.getFileManager());
>
>   compiler.createPreprocessor(TU_Module);
>   compiler.getPreprocessorOpts().UsePredefines = false;
>
>   compiler.createASTContext();
>
>   SourceManager &sourceMgr = compiler.getSourceManager();
>
>   // Initialize rewriter
>   Rewriter Rewrite;
>   Rewrite.setSourceMgr(sourceMgr, compiler.getLangOpts());
>
>   // Get filename
>   string fileName(argv[argc - 1]);
>
>   const FileEntry *pFile = compiler.getFileManager().getFile(fileName);
>   sourceMgr.setMainFileID(sourceMgr.createFileID(pFile, SourceLocation(),
> SrcMgr::C_User));
>   if (pFile == NULL)
>   {
>       // File not found
>       return false;
>   }
>
>   compiler.getDiagnosticClient().BeginSourceFile(compiler.getLangOpts(),
>                                            &compiler.getPreprocessor());
>
>   MyASTConsumer astConsumer(Rewrite);
>
>   try {
>     // Parse the AST
>     ParseAST(compiler.getPreprocessor(),
>              &astConsumer,
>              compiler.getASTContext());
>   } catch(exception &e)
>   {
>     return false;
>   }
>
>   compiler.getDiagnosticClient().EndSourceFile();
>
>   return true;  // Return success
> }
>
> Everything works fine till the return, when it crashes with:
>
> libstdc++-6!_ZNSs4_Rep10_M_destroyERKSaIcE
> C:\Qt\Qt5.4.1\5.4\mingw491_32\bin\libstdc++-6.dll
> clang::DiagnosticsEngine::~DiagnosticsEngine
> clang::CompilerInstance::~CompilerInstance
>
> Any ideas what I did wrong? This is with:
> clang version 3.7.0 (trunk 230884)
> Target: i686-pc-windows-gnu
> Thread model: posix
>
> BTW, why is the current build calling itself 3.7.0? Since 3.6 was just
> released, it seems it should be called 3.6.0 or something less confusing.
>
> Thanks!
> Robert
>
>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150306/947f488c/attachment.html>


More information about the cfe-dev mailing list