Skip to content

Commit e9ad5ab

Browse files
devajithvshahnjo
authored andcommitted
[cling] Skip invalid TopLevelStmtDecls in dumps
Skip dumping TopLevelStmt if they are invalid. The change llvm/llvm-project@4b70d17bcf caused an invalid `TopLevelStatement` to be added to the AST, which can trigger assertions when dumping.
1 parent 672d447 commit e9ad5ab

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

interpreter/cling/lib/Interpreter/ClangInternalState.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ namespace cling {
160160
}
161161

162162
builtinNames.push_back(".*__builtin.*");
163+
// Ignore TopLevelStmt for now, an invalid TopLevelStmt can still exist
164+
// after a failed statement (introduced by llvm/llvm-project@4b70d17bcf)
165+
builtinNames.push_back("StoredDeclsMap TopLevelStmt");
163166

164167
differentContent(m_LookupTablesFile, m_DiffPair->m_LookupTablesFile,
165168
"lookup tables", verbose, &builtinNames);
@@ -302,7 +305,17 @@ namespace cling {
302305
bool PrintInstantiation = false;
303306
std::string ErrMsg;
304307
clang::PrintingPolicy policy = C.getPrintingPolicy();
305-
TU->print(Out, policy, Indentation, PrintInstantiation);
308+
for (Decl* D : TU->decls()) {
309+
if (auto* TLSD = dyn_cast<TopLevelStmtDecl>(D)) {
310+
if (!TLSD->getStmt()) {
311+
// Skip invalid TopLevelStmt. The change llvm/llvm-project@4b70d17bcf
312+
// caused an invalid TopLevelStatement to be added to the AST, which
313+
// can trigger assertions when dumping.
314+
continue;
315+
}
316+
}
317+
D->print(Out, policy, Indentation, PrintInstantiation);
318+
}
306319
// TODO: For future when we relpace the bump allocation with slab.
307320
//
308321
//Out << "Allocated memory: " << C.getAllocatedMemory();

0 commit comments

Comments
 (0)