[flang-commits] [flang] 3bbdbb2 - [flang] Fix parsing time explosion (#76533)

via flang-commits flang-commits at lists.llvm.org
Tue Jan 2 08:54:15 PST 2024


Author: Peter Klausler
Date: 2024-01-02T08:54:10-08:00
New Revision: 3bbdbb22a50705a78ea2668d4ab227889cabdc84

URL: https://github.com/llvm/llvm-project/commit/3bbdbb22a50705a78ea2668d4ab227889cabdc84
DIFF: https://github.com/llvm/llvm-project/commit/3bbdbb22a50705a78ea2668d4ab227889cabdc84.diff

LOG: [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.

Added: 
    

Modified: 
    flang/lib/Parser/Fortran-parsers.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Parser/Fortran-parsers.cpp b/flang/lib/Parser/Fortran-parsers.cpp
index c070bc1de37352..0dd95d69d3c662 100644
--- a/flang/lib/Parser/Fortran-parsers.cpp
+++ b/flang/lib/Parser/Fortran-parsers.cpp
@@ -1151,8 +1151,9 @@ TYPE_PARSER(construct<PartRef>(name,
 
 // R913 structure-component -> data-ref
 // The final part-ref in the data-ref is not allowed to have subscripts.
-TYPE_PARSER(construct<StructureComponent>(
-    construct<DataRef>(some(Parser<PartRef>{} / percentOrDot)), name))
+TYPE_CONTEXT_PARSER("component"_en_US,
+    construct<StructureComponent>(
+        construct<DataRef>(some(Parser<PartRef>{} / percentOrDot)), name))
 
 // R919 subscript -> scalar-int-expr
 constexpr auto subscript{scalarIntExpr};


        


More information about the flang-commits mailing list