This is an archive of the discontinued LLVM Phabricator instance.

[ASTMatchers] Avoid pathological traversal over nested lambdas
ClosedPublic

Authored by steveire on Jan 27 2021, 3:51 PM.

Diff Detail

Event Timeline

steveire requested review of this revision.Jan 27 2021, 3:51 PM
steveire created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJan 27 2021, 3:51 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
alexfh accepted this revision.Jan 28 2021, 4:06 AM
alexfh added a subscriber: alexfh.

This fixes the issue with exponential traversal times for deeply nested lambdas. Please add a test though. For example, this one:

void f() {
  [] {
  [] {
  [] {
  [] {
  [] {
  [] {
  [] {
  [] {
  [] {
  [] {
  [] {
  [] {
  [] {
  [] {
  [] {
  [] {
  [] {
  [] {
  [] {
  [] {
  [] {
  [] {
  [] {
  [] {
  [] {
  [] {
  [] {
  [] {
  [] {
  }();
  }();
  }();
  }();
  }();
  }();
  }();
  }();
  }();
  }();
  }();
  }();
  }();
  }();
  }();
  }();
  }();
  }();
  }();
  }();
  }();
  }();
  }();
  }();
  }();
  }();
  }();
  }();
  }();
}
This revision is now accepted and ready to land.Jan 28 2021, 4:06 AM

Thanks for the prompt fix, btw!

clang/include/clang/AST/RecursiveASTVisitor.h
2064

Please specify the type explicitly here.

This revision was landed with ongoing or failed builds.Jan 28 2021, 12:46 PM
This revision was automatically updated to reflect the committed changes.
rsmith added a subscriber: rsmith.Jan 28 2021, 2:54 PM
rsmith added inline comments.
clang/include/clang/AST/RecursiveASTVisitor.h
2063–2065

This is incorrectly skipping the bodies of all other lambda member functions (default ctor, copy ctor, destructor, implicit conversion to function pointer type), not only the "body" of the lambda itself (the definition of the operator()).

steveire added inline comments.Jan 28 2021, 3:45 PM
clang/include/clang/AST/RecursiveASTVisitor.h
2063–2065

Since the 12 branch has been cut, I've added a blocking bug to get this fixed in some form: https://bugs.llvm.org/show_bug.cgi?id=48935

@rsmith I've assigned it to you to make a call about whether to cherrypick this patch, this patch+followup, or revert the original change on the branch.
(@steveire is a revert really an option here, or is there already more stuff relying on this?)