diff options
author | Alon Zakai <azakai@google.com> | 2019-05-17 13:06:24 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-17 13:06:24 -0700 |
commit | d8c46cf57840eadc3d59ef8bffb2d1b3d4438daf (patch) | |
tree | 0fcade56085e9a195d3cbdf23f16f8e5f98061ac /src/passes/AvoidReinterprets.cpp | |
parent | 9c637288cf3b1c7505fa7d8edc1536b6e64d5967 (diff) | |
download | binaryen-d8c46cf57840eadc3d59ef8bffb2d1b3d4438daf.tar.gz binaryen-d8c46cf57840eadc3d59ef8bffb2d1b3d4438daf.tar.bz2 binaryen-d8c46cf57840eadc3d59ef8bffb2d1b3d4438daf.zip |
Fix an infinite loop in avoid-reinterprets in unreachable code with loops of gets (#2118)
In unreachable code, a get may have a single set that assigns to it, and that set may be assigned to by that very get.
Diffstat (limited to 'src/passes/AvoidReinterprets.cpp')
-rw-r--r-- | src/passes/AvoidReinterprets.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/passes/AvoidReinterprets.cpp b/src/passes/AvoidReinterprets.cpp index d79645dc6..823de53ba 100644 --- a/src/passes/AvoidReinterprets.cpp +++ b/src/passes/AvoidReinterprets.cpp @@ -28,6 +28,8 @@ namespace wasm { static Load* getSingleLoad(LocalGraph* localGraph, GetLocal* get) { + std::set<GetLocal*> seen; + seen.insert(get); while (1) { auto& sets = localGraph->getSetses[get]; if (sets.size() != 1) { @@ -39,7 +41,12 @@ static Load* getSingleLoad(LocalGraph* localGraph, GetLocal* get) { } auto* value = Properties::getFallthrough(set->value); if (auto* parentGet = value->dynCast<GetLocal>()) { + if (seen.count(parentGet)) { + // We are in a cycle of gets, in unreachable code. + return nullptr; + } get = parentGet; + seen.insert(get); continue; } if (auto* load = value->dynCast<Load>()) { |