From d975ed9373a6386e78d654562b3178ec99cf8200 Mon Sep 17 00:00:00 2001 From: Jaden Weiss Date: Thu, 12 Sep 2019 16:33:14 -0400 Subject: [PATCH] fix incorrect typing of globals bitmap --- compiler/gc.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/compiler/gc.go b/compiler/gc.go index d9679efca..421f11bd6 100644 --- a/compiler/gc.go +++ b/compiler/gc.go @@ -398,10 +398,21 @@ func (c *Compiler) addGlobalsBitmap() bool { for i, b := range bitmapBytes { bitmapValues[len(bitmapBytes)-i-1] = llvm.ConstInt(c.ctx.Int8Type(), uint64(b), false) } - bitmapArray := llvm.ConstArray(llvm.ArrayType(c.ctx.Int8Type(), len(bitmapBytes)), bitmapValues) + bitmapArray := llvm.ConstArray(c.ctx.Int8Type(), bitmapValues) bitmapNew := llvm.AddGlobal(c.mod, bitmapArray.Type(), "runtime.trackedGlobalsBitmap.tmp") bitmapOld := c.mod.NamedGlobal("runtime.trackedGlobalsBitmap") - bitmapOld.ReplaceAllUsesWith(bitmapNew) + for _, inst := range getUses(bitmapOld) { + c.builder.SetInsertPointBefore(inst) + bc := c.builder.CreateBitCast(bitmapNew, bitmapOld.Type(), "runtime.trackedGlobalsBitmap.cast") + for i := 0; i < inst.OperandsCount(); i++ { + if inst.Operand(i) == bitmapOld { + inst.SetOperand(i, bc) + } + } + } + if len(getUses(bitmapOld)) > 0 { + panic("failed to eliminate tracked globals bitmap representation") + } bitmapNew.SetInitializer(bitmapArray) bitmapNew.SetName("runtime.trackedGlobalsBitmap")