[PATCH] D132388: [pseudo] Fix HeadsPartition is not initialized correctly.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 23 06:10:07 PDT 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGedb8fb265990: [pseudo] Fix HeadsPartition is not initialized correctly. (authored by hokein).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D132388/new/
https://reviews.llvm.org/D132388
Files:
clang-tools-extra/pseudo/lib/GLR.cpp
clang-tools-extra/pseudo/unittests/GLRTest.cpp
Index: clang-tools-extra/pseudo/unittests/GLRTest.cpp
===================================================================
--- clang-tools-extra/pseudo/unittests/GLRTest.cpp
+++ clang-tools-extra/pseudo/unittests/GLRTest.cpp
@@ -652,6 +652,31 @@
"[ 1, end) └─word := <opaque>\n");
}
+TEST_F(GLRTest, RecoveryFromStartOfInput) {
+ build(R"bnf(
+ _ := start [recover=Fallback] EOF
+
+ start := IDENTIFIER
+ )bnf");
+ TestLang.Table = LRTable::buildSLR(TestLang.G);
+ bool fallback_recovered = false;
+ auto fallback = [&](Token::Index Start, const TokenStream & Code) {
+ fallback_recovered = true;
+ return Code.tokens().size();
+ };
+ TestLang.RecoveryStrategies.try_emplace(
+ extensionID("Fallback"),
+ fallback);
+ clang::LangOptions LOptions;
+ TokenStream Tokens = cook(lex("?", LOptions), LOptions);
+
+ const ForestNode &Parsed =
+ glrParse({Tokens, Arena, GSStack}, id("start"), TestLang);
+ EXPECT_TRUE(fallback_recovered);
+ EXPECT_EQ(Parsed.dumpRecursive(TestLang.G),
+ "[ 0, end) start := <opaque>\n");
+}
+
TEST_F(GLRTest, RepeatedRecovery) {
// We require multiple steps of recovery at eof and then a reduction in order
// to successfully parse.
Index: clang-tools-extra/pseudo/lib/GLR.cpp
===================================================================
--- clang-tools-extra/pseudo/lib/GLR.cpp
+++ clang-tools-extra/pseudo/lib/GLR.cpp
@@ -31,7 +31,6 @@
const TokenStream &Tokens,
const Language &Lang) {
assert(Strategy != 0);
- assert(Begin > 0);
if (auto S = Lang.RecoveryStrategies.lookup(Strategy))
return S(Begin, Tokens);
return Token::Invalid;
@@ -614,7 +613,7 @@
// Invariant: Heads is partitioned by source: {shifted | reduced}.
// HeadsPartition is the index of the first head formed by reduction.
// We use this to discard and recreate the reduced heads during recovery.
- unsigned HeadsPartition = 0;
+ unsigned HeadsPartition = Heads.size();
std::vector<const GSS::Node *> NextHeads;
auto MaybeGC = [&, Roots(std::vector<const GSS::Node *>{}), I(0u)]() mutable {
assert(NextHeads.empty() && "Running GC at the wrong time!");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132388.454815.patch
Type: text/x-patch
Size: 2242 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220823/482df51a/attachment.bin>
More information about the cfe-commits
mailing list