Possible bug when model-parsing multiple source files

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Possible bug when model-parsing multiple source files

Romanenkov Kirill via cfe-dev
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
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev