[cfe-dev] invalid free for CompilerInstance
Kihong Heo via cfe-dev
cfe-dev at lists.llvm.org
Sat Nov 24 21:15:01 PST 2018
Hi all,
I have the following code. The process works well but finally crashes at the last minute (delete CI) with "free(): invalid pointer”.
I appreciate any help you can give me.
bool run(std::string InputFileName, Action *R) {
CI = new clang::CompilerInstance();
assert(CI);
CI->createDiagnostics();
clang::TargetOptions &TO = CI->getTargetOpts();
TO.Triple = llvm::sys::getDefaultTargetTriple();
clang::TargetInfo *Target = clang::TargetInfo::CreateTargetInfo(
CI->getDiagnostics(), CI->getInvocation().TargetOpts);
CI->setTarget(Target);
CI->createFileManager();
CI->createSourceManager(CI->getFileManager());
CI->createPreprocessor(clang::TU_Complete);
CI->createASTContext();
CI->setASTConsumer(std::unique_ptr<clang::ASTConsumer>(R));
clang::Preprocessor &PP = CI->getPreprocessor();
PP.getBuiltinInfo().initializeBuiltins(PP.getIdentifierTable(),
PP.getLangOpts());
if (!CI->InitializeSourceManager(
clang::FrontendInputFile(InputFileName, clang::InputKind::C))) {
return false;
}
CI->createSema(clang::TU_Complete, 0);
clang::DiagnosticsEngine &Diag = CI->getDiagnostics();
Diag.setSuppressAllDiagnostics(true);
Diag.setIgnoreAllWarnings(true);
ParseAST(CI->getSema());
CI->getDiagnosticClient().EndSourceFile();
delete CI; // abort
return true;
}
Thanks,
Kihong
More information about the cfe-dev
mailing list