[cfe-dev] Tentatively parsing a parameter-declaration-clause
Louis Dionne via cfe-dev
cfe-dev at lists.llvm.org
Fri Aug 2 10:57:53 PDT 2019
[CC: key people having touched that code]
Dear cfe-dev,
I'm working on fixing https://llvm.org/PR42851, a segfault that manifests when parsing a lambda with a default argument that's a lambda:
int main() {
auto apply = [](auto, void(*)() = []{}) { };
apply(1); // ^^^^ BOOM
}
Long story short, what's happening is that when we parse the parameter-declaration-clause of the lambda, we don't record that we're in a dependent context, i.e. that we're basically parsing a template for the closure type's operator(). We don't know that we're in a template until we actually hit the first parameter declared with 'auto', but by then we've already done some things wrong (e.g. we've injected declarations into a parse scope that is not marked as being a template).
So what I've come to believe is that we should "tentatively parse" the parameter-declaration-clause of the lambda and try to determine whether it's going to be a generic lambda before we actually go ahead and parse it "for real", with a parse scope that's correctly marked as being dependent (or not). However, we must do that tentative parsing without calling into Sema, because calling into Sema has side effects that we can't undo easily. This means I can't reuse most of the existing machinery for parsing a parameter-declaration-clause.
I found TentativeParsingAction and I'm aware of a few tentative parsing functions in ParseTentative.cpp (like TryParseParameterDeclarationClause, which doesn't do quite what I need). However, before I invest any more time down that path, I'd like to know whether others think I'm going down the right path.
Any insights welcome,
Louis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190802/1a0df4a5/attachment.html>
More information about the cfe-dev
mailing list