hokein created this revision.
hokein added a reviewer: sammccall.
Herald added a project: All.
hokein requested review of this revision.
Herald added a subscriber: alextsao1999.
Herald added a project: clang-tools-extra.

We accidently define two identical rules for user-defined-string-literal
(one left recursive and the other one is right recursive), it explodes
states when parsing a long long "" "" "" string literal.

TEST on a huge file which contains ~2.6w "" string literal:

before this patch: more than minutes
after this patch: < 1s


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D125794

Files:
  clang-tools-extra/pseudo/lib/cxx.bnf


Index: clang-tools-extra/pseudo/lib/cxx.bnf
===================================================================
--- clang-tools-extra/pseudo/lib/cxx.bnf
+++ clang-tools-extra/pseudo/lib/cxx.bnf
@@ -713,7 +713,7 @@
 #! so it doesn't belong to the grammar. However, we extend the grammar to
 #! support it, to make the pseudoparser fully functional on practical code.
 string-literal := string-literal-chunk
-string-literal := string-literal string-literal-chunk
+string-literal := string-literal-chunk string-literal
 user-defined-literal := user-defined-integer-literal
 user-defined-literal := user-defined-floating-point-literal
 user-defined-literal := user-defined-string-literal
@@ -726,7 +726,6 @@
 user-defined-string-literal-chunk := UTF32_STRING_LITERAL
 user-defined-string-literal := user-defined-string-literal-chunk
 user-defined-string-literal := string-literal-chunk user-defined-string-literal
-user-defined-string-literal := user-defined-string-literal string-literal-chunk
 user-defined-floating-point-literal := NUMERIC_CONSTANT
 user-defined-character-literal := CHAR_CONSTANT
 user-defined-character-literal := WIDE_CHAR_CONSTANT


Index: clang-tools-extra/pseudo/lib/cxx.bnf
===================================================================
--- clang-tools-extra/pseudo/lib/cxx.bnf
+++ clang-tools-extra/pseudo/lib/cxx.bnf
@@ -713,7 +713,7 @@
 #! so it doesn't belong to the grammar. However, we extend the grammar to
 #! support it, to make the pseudoparser fully functional on practical code.
 string-literal := string-literal-chunk
-string-literal := string-literal string-literal-chunk
+string-literal := string-literal-chunk string-literal
 user-defined-literal := user-defined-integer-literal
 user-defined-literal := user-defined-floating-point-literal
 user-defined-literal := user-defined-string-literal
@@ -726,7 +726,6 @@
 user-defined-string-literal-chunk := UTF32_STRING_LITERAL
 user-defined-string-literal := user-defined-string-literal-chunk
 user-defined-string-literal := string-literal-chunk user-defined-string-literal
-user-defined-string-literal := user-defined-string-literal string-literal-chunk
 user-defined-floating-point-literal := NUMERIC_CONSTANT
 user-defined-character-literal := CHAR_CONSTANT
 user-defined-character-literal := WIDE_CHAR_CONSTANT
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to