From ca703c8877743001468f96eb01eeccb2a5dc2a20 Mon Sep 17 00:00:00 2001 From: Steven Perron Date: Tue, 19 Nov 2019 09:44:53 -0500 Subject: [PATCH] Kill the id-to-func map after wrap-opkill (#3055) Wrap-opkill will create a new function, invalidating the id-to-func map. The preserved analyses for the pass have been updated to reflect that. Also adding consistency check for the id-to-func map. With this new check, old tests identify this problem. No new tests are needed. Fixes #3038 --- source/opt/ir_context.cpp | 9 +++++++++ source/opt/wrap_opkill.h | 3 +-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/source/opt/ir_context.cpp b/source/opt/ir_context.cpp index d940180da..7bca29b20 100644 --- a/source/opt/ir_context.cpp +++ b/source/opt/ir_context.cpp @@ -273,6 +273,14 @@ bool IRContext::IsConsistent() { } } + if (AreAnalysesValid(kAnalysisIdToFuncMapping)) { + for (auto& fn : *module_) { + if (id_to_func_[fn.result_id()] != &fn) { + return false; + } + } + } + if (AreAnalysesValid(kAnalysisInstrToBlockMapping)) { for (auto& func : *module()) { for (auto& block : func) { @@ -818,6 +826,7 @@ bool IRContext::ProcessCallTreeFromRoots(ProcessFunction& pfn, roots->pop(); if (done.insert(fi).second) { Function* fn = GetFunction(fi); + assert(fn && "Trying to process a function that does not exist."); modified = pfn(fn) || modified; AddCalls(fn, roots); } diff --git a/source/opt/wrap_opkill.h b/source/opt/wrap_opkill.h index 87a5d692c..09f2dfafd 100644 --- a/source/opt/wrap_opkill.h +++ b/source/opt/wrap_opkill.h @@ -34,8 +34,7 @@ class WrapOpKill : public Pass { IRContext::kAnalysisInstrToBlockMapping | IRContext::kAnalysisDecorations | IRContext::kAnalysisCombinators | IRContext::kAnalysisNameMap | IRContext::kAnalysisBuiltinVarId | - IRContext::kAnalysisIdToFuncMapping | IRContext::kAnalysisConstants | - IRContext::kAnalysisTypes; + IRContext::kAnalysisConstants | IRContext::kAnalysisTypes; } private: