[all-commits] [llvm/llvm-project] 3bbdbb: [flang] Fix parsing time explosion (#76533)

Peter Klausler via All-commits all-commits at lists.llvm.org
Tue Jan 2 08:54:23 PST 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 3bbdbb22a50705a78ea2668d4ab227889cabdc84
      https://github.com/llvm/llvm-project/commit/3bbdbb22a50705a78ea2668d4ab227889cabdc84
  Author: Peter Klausler <35819229+klausler at users.noreply.github.com>
  Date:   2024-01-02 (Tue, 02 Jan 2024)

  Changed paths:
    M flang/lib/Parser/Fortran-parsers.cpp

  Log Message:
  -----------
  [flang] Fix parsing time explosion (#76533)

When parsing a deeply-nested expression like
  A1(A2(A3(A4(A5(A6(...A99(i)...))))))
the parser can get into an exponential state due to the need to consider
the possibility that each "An(...)" might be the beginning of a
reference to a procedure component ("An(...)%PROC(...)") so that
alternative has to be attempted first before proceeding to try parsing
"An(...)" as a function reference or as an array element designator. The
parser for a structure component, which is used by the procedure
designator parser, was not protected with the usual failure memoization
technique, leading to exponentially bad behavior parsing a deeply-nested
expression. Fix by exploiting the instrumented() parser combinator so
that failed structure component parsers aren't repeated.

Fixes https://github.com/llvm/llvm-project/issues/76477.




More information about the All-commits mailing list