<div dir="ltr">The message you see is a diagnostic message from your C library warning you that the value passed in to free() (via this "delete CI" statement) is not a pointer to something that was allocated by malloc() (via new or otherwise).<div><br></div><div>A common cause for this kind of problem is some kind of heap or stack corruption. Best to build your code with many warnings enabled and consider also using ASan (Address Sanitizer). It's great at quickly identifying the root cause of problems like this. If warnings and ASan don't quickly identify the issue, decrease the scope [delete/disable code] until you find the critical scope necessary to cause the problem and you will at least have a smaller area to search for bugs.</div><div><br></div><div>Also, as an aside (it won't help fix the problem that you reported) -- consider using a smart pointer like std::unique_ptr for something like this "CI" variable. For example, in this code, 'CI' leaks if the call to InitializeSourceManager() fails.</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Sat, Nov 24, 2018 at 11:15 PM Kihong Heo via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br>
<br>
I have the following code. The process works well but finally crashes at the last minute (delete CI) with "free(): invalid pointer”.<br>
<br>
I appreciate any help you can give me.<br>
<br>
bool run(std::string InputFileName, Action *R) {<br>
CI = new clang::CompilerInstance();<br>
assert(CI);<br>
<br>
CI->createDiagnostics();<br>
clang::TargetOptions &TO = CI->getTargetOpts();<br>
TO.Triple = llvm::sys::getDefaultTargetTriple();<br>
clang::TargetInfo *Target = clang::TargetInfo::CreateTargetInfo(<br>
CI->getDiagnostics(), CI->getInvocation().TargetOpts);<br>
CI->setTarget(Target);<br>
<br>
CI->createFileManager();<br>
CI->createSourceManager(CI->getFileManager());<br>
CI->createPreprocessor(clang::TU_Complete);<br>
CI->createASTContext();<br>
CI->setASTConsumer(std::unique_ptr<clang::ASTConsumer>(R));<br>
clang::Preprocessor &PP = CI->getPreprocessor();<br>
PP.getBuiltinInfo().initializeBuiltins(PP.getIdentifierTable(),<br>
PP.getLangOpts());<br>
<br>
if (!CI->InitializeSourceManager(<br>
clang::FrontendInputFile(InputFileName, clang::InputKind::C))) {<br>
return false;<br>
}<br>
<br>
CI->createSema(clang::TU_Complete, 0);<br>
clang::DiagnosticsEngine &Diag = CI->getDiagnostics();<br>
Diag.setSuppressAllDiagnostics(true);<br>
Diag.setIgnoreAllWarnings(true);<br>
<br>
ParseAST(CI->getSema());<br>
<br>
CI->getDiagnosticClient().EndSourceFile();<br>
<br>
delete CI; // abort<br>
return true;<br>
}<br>
<br>
Thanks,<br>
Kihong<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">-Brian</div>