From db15b485c49e0db24bdb4b0c8d2d96537c256f8c Mon Sep 17 00:00:00 2001 From: Daniel Sanders Date: Tue, 24 Oct 2017 18:11:54 +0000 Subject: [PATCH] [globalisel][tablegen] Fix future undefined behaviour in r316463. I missed a dereference of `Matched` that preceeded the new check. Thanks to Justin Bogner for spotting it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316480 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/TableGen/GlobalISelEmitter.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/utils/TableGen/GlobalISelEmitter.cpp b/utils/TableGen/GlobalISelEmitter.cpp index e472c8c43bf..f75456db870 100644 --- a/utils/TableGen/GlobalISelEmitter.cpp +++ b/utils/TableGen/GlobalISelEmitter.cpp @@ -1758,13 +1758,16 @@ private: /// True if the instruction can be built solely by mutating the opcode. bool canMutate(RuleMatcher &Rule) const { + if (!Matched) + return false; + if (OperandRenderers.size() != Matched->getNumOperands()) return false; for (const auto &Renderer : enumerate(OperandRenderers)) { if (const auto *Copy = dyn_cast(&*Renderer.value())) { const OperandMatcher &OM = Rule.getOperandMatcher(Copy->getSymbolicName()); - if ((Matched != nullptr && Matched != &OM.getInstructionMatcher()) || + if (Matched != &OM.getInstructionMatcher() || OM.getOperandIndex() != Renderer.index()) return false; } else -- 2.50.1