DeclExtractor: exit early if there is nothing to do

In LLVM 9, the `CompoundStmt::replaceStmts()` call seems to write to an invalid
memory location if the body was empty. This may happen after a parse error and
might end up corrupting the program state.

This patch makes `DeclExtractor` to exit early if there is nothing to do, which
solves the aforementioned problem.
This commit is contained in:
Javier Lopez-Gomez 2021-02-16 15:11:37 +01:00 committed by jenkins
parent dad7ed462e
commit b5348025ef

View File

@ -117,6 +117,9 @@ namespace cling {
Scope* TUScope = m_Sema->TUScope;
llvm::SmallVector<Stmt*, 4> Stmts;
if (CS->body_empty())
return FD;
for (CompoundStmt::body_iterator I = CS->body_begin(), EI = CS->body_end();
I != EI; ++I) {
DeclStmt* DS = dyn_cast<DeclStmt>(*I);