From bf9d62fe9839a17922f3c8998f2316707ba361ec Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Mon, 5 Nov 2018 13:33:01 +0100 Subject: [PATCH] interp: fix GEP with const value in a local variable --- interp/frame.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/interp/frame.go b/interp/frame.go index 9e75f8f6..8c1e4c1e 100644 --- a/interp/frame.go +++ b/interp/frame.go @@ -114,14 +114,15 @@ func (fr *frame) evalBasicBlock(bb, incoming llvm.BasicBlock, indent string) (re llvmIndices[i] = inst.Operand(i + 1) } indices := make([]uint32, len(llvmIndices)) - for i, operand := range llvmIndices { + for i, llvmIndex := range llvmIndices { + operand := fr.getLocal(llvmIndex) if !operand.IsConstant() { - // not a constant operation, emit a low-level GEP - gep := fr.builder.CreateGEP(value.Value(), llvmIndices, inst.Name()) - fr.locals[inst] = &LocalValue{fr.Eval, gep} - continue + // Not a constant operation. + // This should be detected by the scanner, but isn't at the + // moment. + panic("todo: non-const gep") } - indices[i] = uint32(operand.ZExtValue()) + indices[i] = uint32(operand.Value().ZExtValue()) } result := value.GetElementPtr(indices) if result.Type() != inst.Type() {