From 6d3c11627c1288e5b865763070709e30a95013db Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Thu, 25 Mar 2021 00:42:04 +0100 Subject: [PATCH] compiler: fix use of global context: llvm.Int32Type() This patch fixes a use of the global context. I've seen a few instances of crashes in the llvm.ConstInt function when called from makeStructTypeFields, which I believe are caused by this bug. --- compiler/interface.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/interface.go b/compiler/interface.go index 535e7650..b4bf4cd0 100644 --- a/compiler/interface.go +++ b/compiler/interface.go @@ -103,8 +103,8 @@ func (c *compilerContext) makeStructTypeFields(typ *types.Struct) llvm.Value { fieldName.SetLinkage(llvm.PrivateLinkage) fieldName.SetUnnamedAddr(true) fieldName = llvm.ConstGEP(fieldName, []llvm.Value{ - llvm.ConstInt(llvm.Int32Type(), 0, false), - llvm.ConstInt(llvm.Int32Type(), 0, false), + llvm.ConstInt(c.ctx.Int32Type(), 0, false), + llvm.ConstInt(c.ctx.Int32Type(), 0, false), }) fieldGlobalValue = llvm.ConstInsertValue(fieldGlobalValue, fieldName, []uint32{1}) if typ.Tag(i) != "" { @@ -112,8 +112,8 @@ func (c *compilerContext) makeStructTypeFields(typ *types.Struct) llvm.Value { fieldTag.SetLinkage(llvm.PrivateLinkage) fieldTag.SetUnnamedAddr(true) fieldTag = llvm.ConstGEP(fieldTag, []llvm.Value{ - llvm.ConstInt(llvm.Int32Type(), 0, false), - llvm.ConstInt(llvm.Int32Type(), 0, false), + llvm.ConstInt(c.ctx.Int32Type(), 0, false), + llvm.ConstInt(c.ctx.Int32Type(), 0, false), }) fieldGlobalValue = llvm.ConstInsertValue(fieldGlobalValue, fieldTag, []uint32{2}) }