[cfe-dev] Possible bug when model-parsing multiple source files

Manuel Freiberger via cfe-dev cfe-dev at lists.llvm.org
Fri Apr 21 12:51:01 PDT 2017


Hi all,

I'm toying around with libTooling and think there is a bug in 
CompilerInstance::ExecuteAction(FrontendAction &Act)
when FrontendAction::isModelParsingAction() is true.

The issue is that ExecuteAction() loops over all input source files and
executes FrontendAction::BeginSourceFile(), FrontendAction::Execute() and
FrontendAction::EndSourceFile() on them.

For model-parsing actions, no new AST context is created in BeginSourceFile() because
it re-uses the existing one. However, EndSourceFile() unconditionally resets the 
AST-context in the CompilerInstance (either via CI.resetAndLeakASTContext() or 
CI.setASTContext(nullptr) --- depending on DisableFree) even if the action is a 
model-parsing one.

So when the second source file is processed, the CompilerInstance no longer has an
AST which leads to a crash as soon as the new sema instance is to be created.

To fix this, at least the CompilerInstance's AST must not be reset in EndSourceFile()
when isModelParsingAction() is true. I'm not completely sure if other parts of the
CompilerInstance should survive too.

IMHO it would also be nice, if FrontendAction::BeginSourceFile() and 
FrontendAction::EndSourceFile() were virtual (probably FrontendAction::Execute() as
well). This would greatly simplify the setup of a CompilerInstance when one needs
to parse into an already existing AST context.

Thanks,
Manuel



More information about the cfe-dev mailing list